Add support for BTv2 magnet links

This commit is contained in:
Joshua Abraham 2023-12-24 16:53:02 -06:00
parent 1157866152
commit 0836b651a7
21 changed files with 236 additions and 157 deletions

View file

@ -552,7 +552,7 @@ impl Session {
));
}
bail!("didn't find a matching torrent for {:?}", Id20(h.info_hash))
bail!("didn't find a matching torrent for {:?}", Id20::new(h.info_hash))
}
async fn task_tcp_listener(self: Arc<Self>, l: TcpListener) -> anyhow::Result<()> {
@ -757,10 +757,8 @@ impl Session {
let (info_hash, info, dht_rx, trackers, initial_peers) = match add {
AddTorrent::Url(magnet) if magnet.starts_with("magnet:") => {
let Magnet {
info_hash,
trackers,
} = Magnet::parse(&magnet).context("provided path is not a valid magnet URL")?;
let magnet = Magnet::parse(&magnet).context("provided path is not a valid magnet URL")?;
let info_hash = magnet.as_id20().context("magnet link didn't contain a BTv1 infohash")?;
let dht_rx = self
.dht
@ -768,7 +766,7 @@ impl Session {
.context("magnet links without DHT are not supported")?
.get_peers(info_hash, announce_port)?;
let trackers = trackers
let trackers = magnet.trackers
.into_iter()
.filter_map(|url| match reqwest::Url::parse(&url) {
Ok(url) => Some(url),