torrust-tracker icon indicating copy to clipboard operation
torrust-tracker copied to clipboard

Tracker Checker: Support different types of tracker addresses

Open josecelano opened this issue 1 year ago • 0 comments

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:6969 without the scheme.
  • URLs for HTTP trackers must be:
    • http://domain:port
    • https://domain:port
    • You cannot include the / or the /announce at 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.44
  • 11.22.33.44:6969
  • 11.22.33.44:6969/
  • udp://11.22.33.44:6969
  • udp://11.22.33.44:6969/

Also valid but the Tracker Checker makes scrape request too:

  • 11.22.33.44:6969/announce
  • udp://11.22.33.44:6969/announce

HTTP URL

Valid:

  • tracker.torrust-demo
  • tracker.torrust-demo:6969
  • tracker.torrust-demo:6969/
  • udp://tracker.torrust-demo:6969
  • udp://tracker.torrust-demo:6969/

Also valid but the Tracker Checker makes scrape request too:

  • tracker.torrust-demo:6969/announce
  • udp://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.

josecelano avatar Feb 02 '24 13:02 josecelano