torrust-tracker
torrust-tracker copied to clipboard
Tracker Checker: Support different types of tracker addresses
Parent issue: https://github.com/torrust/torrust-tracker/issues/669
Currently, you can run the Tracker Checker with this input:
TORRUST_CHECKER_CONFIG='{
"udp_trackers": ["144.126.245.19:6969"],
"http_trackers": ["https://tracker.torrust-demo.com"],
"health_checks": ["https://tracker.torrust-demo.com/health_check"]
}' cargo run --bin tracker_checker
And with some restrictions.
- URLs for UDP trackers must be a socket address:
144.126.245.19:6969without the scheme. - URLs for HTTP trackers must be:
http://domain:porthttps://domain:port- You cannot include the
/or the/announceat the end.
- URLs for health checks have no restrictions. It has to be a valid URL (GET endpoint).
We should be more flexible and allow these input formats:
UDP URL
Valid:
11.22.33.4411.22.33.44:696911.22.33.44:6969/udp://11.22.33.44:6969udp://11.22.33.44:6969/
Also valid but the Tracker Checker makes scrape request too:
11.22.33.44:6969/announceudp://11.22.33.44:6969/announce
HTTP URL
Valid:
tracker.torrust-demotracker.torrust-demo:6969tracker.torrust-demo:6969/udp://tracker.torrust-demo:6969udp://tracker.torrust-demo:6969/
Also valid but the Tracker Checker makes scrape request too:
tracker.torrust-demo:6969/announceudp://tracker.torrust-demo:6969/announce
NOTES
We allow the suffix announce because it's very common to get tracker lists with that suffix.
See https://github.com/torrust/torrust-tracker/discussions/650
We should normalize the URL and internally store the canonical one (full URL without path):
http://[domain|ip][:port]https://[domain|ip][:port]udp://[domain|ip][:port]
Notice that it might be necessary to resolve the domain to an IP with DNS for the UDP tracker in order to make the request because the UdpClient does not accept a URL:
#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
pub struct UdpClient {
/// The socket to connect to
pub socket: Arc<UdpSocket>,
/// Timeout for sending and receiving packets
pub timeout: Duration,
}
It only accepts a socket address. Example:
use std::net::ToSocketAddrs;
fn main() -> std::io::Result<()> {
let addresses = "example.com:80".to_socket_addrs()?;
for addr in addresses {
println!("{}", addr);
}
Ok(())
}
Finally, we should support URLs for UDP trackers because they could have dynamic IPs.