create InteralAddResult
This commit is contained in:
parent
98b8fa153a
commit
5740d3ebe9
1 changed files with 30 additions and 25 deletions
|
|
@ -475,6 +475,14 @@ pub(crate) struct CheckedIncomingConnection {
|
||||||
pub handshake: Handshake<ByteBufOwned>,
|
pub handshake: Handshake<ByteBufOwned>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct InternalAddResult {
|
||||||
|
info_hash: Id20,
|
||||||
|
info: TorrentMetaV1Info<ByteBufOwned>,
|
||||||
|
trackers: Vec<String>,
|
||||||
|
peer_rx: Option<PeerStream>,
|
||||||
|
initial_peers: Vec<SocketAddr>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
/// Create a new session with default options.
|
/// Create a new session with default options.
|
||||||
/// The passed in folder will be used as a default unless overriden per torrent.
|
/// The passed in folder will be used as a default unless overriden per torrent.
|
||||||
|
|
@ -910,7 +918,7 @@ impl Session {
|
||||||
// into a torrent file by connecting to peers that support extended handshakes.
|
// into a torrent file by connecting to peers that support extended handshakes.
|
||||||
// So we must discover at least one peer and connect to it to be able to proceed further.
|
// So we must discover at least one peer and connect to it to be able to proceed further.
|
||||||
|
|
||||||
let (info_hash, info, trackers, peer_rx, initial_peers) = match add {
|
let add_res = match add {
|
||||||
AddTorrent::Url(magnet) if magnet.starts_with("magnet:") => {
|
AddTorrent::Url(magnet) if magnet.starts_with("magnet:") => {
|
||||||
let magnet = Magnet::parse(&magnet)
|
let magnet = Magnet::parse(&magnet)
|
||||||
.context("provided path is not a valid magnet URL")?;
|
.context("provided path is not a valid magnet URL")?;
|
||||||
|
|
@ -950,13 +958,13 @@ impl Session {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
debug!(?info, "received result from DHT");
|
debug!(?info, "received result from DHT");
|
||||||
(
|
InternalAddResult {
|
||||||
info_hash,
|
info_hash,
|
||||||
info,
|
info,
|
||||||
magnet.trackers.into_iter().unique().collect(),
|
trackers: magnet.trackers.into_iter().unique().collect(),
|
||||||
Some(peer_rx),
|
peer_rx: Some(peer_rx),
|
||||||
initial_peers,
|
initial_peers: initial_peers.into_iter().collect(),
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
let torrent = match other {
|
let torrent = match other {
|
||||||
|
|
@ -1004,29 +1012,22 @@ impl Session {
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
InternalAddResult {
|
||||||
torrent.info_hash,
|
info_hash: torrent.info_hash,
|
||||||
torrent.info,
|
info: torrent.info,
|
||||||
trackers,
|
trackers,
|
||||||
peer_rx,
|
peer_rx,
|
||||||
opts.initial_peers
|
initial_peers: opts
|
||||||
|
.initial_peers
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.main_torrent_info(
|
self.main_torrent_info(add_res, opts).await
|
||||||
info_hash,
|
|
||||||
info,
|
|
||||||
trackers,
|
|
||||||
peer_rx,
|
|
||||||
initial_peers.into_iter().collect(),
|
|
||||||
opts,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
@ -1060,13 +1061,17 @@ impl Session {
|
||||||
|
|
||||||
async fn main_torrent_info(
|
async fn main_torrent_info(
|
||||||
&self,
|
&self,
|
||||||
info_hash: Id20,
|
add_res: InternalAddResult,
|
||||||
info: TorrentMetaV1Info<ByteBufOwned>,
|
|
||||||
trackers: Vec<String>,
|
|
||||||
peer_rx: Option<PeerStream>,
|
|
||||||
initial_peers: Vec<SocketAddr>,
|
|
||||||
mut opts: AddTorrentOptions,
|
mut opts: AddTorrentOptions,
|
||||||
) -> anyhow::Result<AddTorrentResponse> {
|
) -> anyhow::Result<AddTorrentResponse> {
|
||||||
|
let InternalAddResult {
|
||||||
|
info,
|
||||||
|
info_hash,
|
||||||
|
trackers,
|
||||||
|
peer_rx,
|
||||||
|
initial_peers,
|
||||||
|
} = add_res;
|
||||||
|
|
||||||
debug!("Torrent info: {:#?}", &info);
|
debug!("Torrent info: {:#?}", &info);
|
||||||
|
|
||||||
let only_files = compute_only_files(
|
let only_files = compute_only_files(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue