Change tracker type to be url::Url in most places

This commit is contained in:
Igor Katson 2025-02-27 12:35:37 +00:00
parent 3eb1558451
commit d709557372
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
4 changed files with 27 additions and 24 deletions

View file

@ -1,3 +1,4 @@
use std::collections::HashSet;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
@ -91,7 +92,7 @@ impl TrackerComms {
pub fn start(
info_hash: Id20,
peer_id: Id20,
trackers: Vec<String>,
trackers: HashSet<Url>,
stats: Box<dyn TorrentStatsProvider>,
force_interval: Option<Duration>,
tcp_listen_port: Option<u16>,
@ -99,17 +100,11 @@ impl TrackerComms {
) -> Option<BoxStream<'static, SocketAddr>> {
let trackers = trackers
.into_iter()
.filter_map(|t| match Url::parse(&t) {
Ok(parsed) => match parsed.scheme() {
"http" | "https" => Some(SupportedTracker::Http(parsed)),
"udp" => Some(SupportedTracker::Udp(parsed)),
_ => {
debug!("unsuppoted tracker URL: {}", t);
None
}
},
Err(e) => {
debug!("error parsing tracker URL {}: {}", t, e);
.filter_map(|t| match t.scheme() {
"http" | "https" => Some(SupportedTracker::Http(t)),
"udp" => Some(SupportedTracker::Udp(t)),
_ => {
debug!("unsuppoted tracker URL: {}", t);
None
}
})