Merge pull request #72 from jabedude/bep52-magnet-support

Add support for BTv2 magnet links
This commit is contained in:
Igor Katson 2024-01-08 11:27:27 +00:00 committed by GitHub
commit c8189de3d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 236 additions and 157 deletions

View file

@ -548,7 +548,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<()> {
@ -753,10 +753,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
@ -764,7 +762,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),