Stub for torrent_file_from_info_and_bytes
This commit is contained in:
parent
e7c7543228
commit
cd0f38f0fb
3 changed files with 23 additions and 8 deletions
|
|
@ -16,7 +16,7 @@ use librqbit_core::hash_id::Id20;
|
||||||
pub enum ReadMetainfoResult<Rx> {
|
pub enum ReadMetainfoResult<Rx> {
|
||||||
Found {
|
Found {
|
||||||
info: TorrentMetaV1Info<ByteBufOwned>,
|
info: TorrentMetaV1Info<ByteBufOwned>,
|
||||||
bytes: ByteBufOwned,
|
info_bytes: ByteBufOwned,
|
||||||
rx: Rx,
|
rx: Rx,
|
||||||
seen: HashSet<SocketAddr>,
|
seen: HashSet<SocketAddr>,
|
||||||
},
|
},
|
||||||
|
|
@ -81,7 +81,7 @@ pub async fn read_metainfo_from_peer_receiver<A: Stream<Item = SocketAddr> + Unp
|
||||||
},
|
},
|
||||||
done = unordered.next(), if !unordered.is_empty() => {
|
done = unordered.next(), if !unordered.is_empty() => {
|
||||||
match done {
|
match done {
|
||||||
Some(Ok(info)) => return ReadMetainfoResult::Found { info: info.0, bytes: info.1, seen, rx: addrs },
|
Some(Ok((info, info_bytes))) => return ReadMetainfoResult::Found { info, info_bytes, seen, rx: addrs },
|
||||||
Some(Err(e)) => {
|
Some(Err(e)) => {
|
||||||
debug!("{:#}", e);
|
debug!("{:#}", e);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ pub(crate) async fn read_metainfo_from_peer(
|
||||||
peer_connection_options: Option<PeerConnectionOptions>,
|
peer_connection_options: Option<PeerConnectionOptions>,
|
||||||
spawner: BlockingSpawner,
|
spawner: BlockingSpawner,
|
||||||
connector: Arc<StreamConnector>,
|
connector: Arc<StreamConnector>,
|
||||||
) -> anyhow::Result<TorrentAndBytes> {
|
) -> anyhow::Result<TorrentAndInfoBytes> {
|
||||||
let (result_tx, result_rx) = tokio::sync::oneshot::channel::<
|
let (result_tx, result_rx) = tokio::sync::oneshot::channel::<
|
||||||
anyhow::Result<(TorrentMetaV1Info<ByteBufOwned>, ByteBufOwned)>,
|
anyhow::Result<(TorrentMetaV1Info<ByteBufOwned>, ByteBufOwned)>,
|
||||||
>();
|
>();
|
||||||
|
|
@ -136,13 +136,13 @@ impl HandlerLocked {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TorrentAndBytes = (TorrentMetaV1Info<ByteBufOwned>, ByteBufOwned);
|
pub type TorrentAndInfoBytes = (TorrentMetaV1Info<ByteBufOwned>, ByteBufOwned);
|
||||||
|
|
||||||
struct Handler {
|
struct Handler {
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
info_hash: Id20,
|
info_hash: Id20,
|
||||||
writer_tx: UnboundedSender<WriterRequest>,
|
writer_tx: UnboundedSender<WriterRequest>,
|
||||||
result_tx: Mutex<Option<tokio::sync::oneshot::Sender<anyhow::Result<TorrentAndBytes>>>>,
|
result_tx: Mutex<Option<tokio::sync::oneshot::Sender<anyhow::Result<TorrentAndInfoBytes>>>>,
|
||||||
locked: RwLock<Option<HandlerLocked>>,
|
locked: RwLock<Option<HandlerLocked>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -502,6 +502,15 @@ async fn create_tcp_listener(
|
||||||
bail!("no free TCP ports in range {port_range:?}");
|
bail!("no free TCP ports in range {port_range:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn torrent_file_from_info_and_bytes(
|
||||||
|
info: &TorrentMetaV1Info<ByteBufOwned>,
|
||||||
|
info_hash: &Id20,
|
||||||
|
info_bytes: &[u8],
|
||||||
|
trackers: &[String],
|
||||||
|
) -> Bytes {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) struct CheckedIncomingConnection {
|
pub(crate) struct CheckedIncomingConnection {
|
||||||
pub addr: SocketAddr,
|
pub addr: SocketAddr,
|
||||||
pub stream: tokio::net::TcpStream,
|
pub stream: tokio::net::TcpStream,
|
||||||
|
|
@ -986,16 +995,22 @@ impl Session {
|
||||||
{
|
{
|
||||||
ReadMetainfoResult::Found {
|
ReadMetainfoResult::Found {
|
||||||
info,
|
info,
|
||||||
bytes,
|
info_bytes,
|
||||||
rx,
|
rx,
|
||||||
seen,
|
seen,
|
||||||
} => {
|
} => {
|
||||||
debug!(?info, "received result from DHT");
|
debug!(?info, "received result from DHT");
|
||||||
|
let trackers = magnet.trackers.into_iter().unique().collect_vec();
|
||||||
InternalAddResult {
|
InternalAddResult {
|
||||||
info_hash,
|
info_hash,
|
||||||
|
torrent_bytes: torrent_file_from_info_and_bytes(
|
||||||
|
&info,
|
||||||
|
&info_hash,
|
||||||
|
&info_bytes,
|
||||||
|
&trackers,
|
||||||
|
),
|
||||||
info,
|
info,
|
||||||
torrent_bytes: Bytes::from(bytes.0),
|
trackers,
|
||||||
trackers: magnet.trackers.into_iter().unique().collect(),
|
|
||||||
peer_rx: Some(rx),
|
peer_rx: Some(rx),
|
||||||
initial_peers: seen.into_iter().collect(),
|
initial_peers: seen.into_iter().collect(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue