@@ -12,23 +12,34 @@ pub enum PeerSource {
1212 Tracker ( Tracker ) ,
1313}
1414
15- /// A centralized variant of a [`Peersource`](crate::tracker::PeerSource).
15+ /// A Bittorrent rendezvous server for peers to find one another.
16+ ///
17+ /// This is usually parsed directly from a [`TorrentFile`](crate::torrent_file::TorrentFile)
18+ /// or a [`MagnetLink`](crate::magnet::MagnetLink).
1619#[ derive( Clone , Debug , PartialEq ) ]
1720pub struct Tracker {
21+ /// Tracker URL scheme (usually `ws`, `http(s)`, or `udp`)
1822 scheme : TrackerScheme ,
23+ /// Complete tracker URL
1924 url : Uri < String > ,
2025}
2126
2227impl Tracker {
2328 /// Generate a new Tracker from a given string URL.
29+ ///
30+ /// Will fail if scheme is not "http", "https", "wss" or "udp", unless
31+ /// the `unknown_tracker_scheme` crate feature is enabled.
32+ ///
33+ /// Will also fail if the provided URL is url-encoded.
2434 pub fn new ( url : & str ) -> Result < Tracker , TrackerError > {
2535 let url = Uri :: parse ( url. to_string ( ) ) ?;
2636 Tracker :: from_url ( & url)
2737 }
2838
2939 /// Generate a new Tracker from a parsed URL.
3040 ///
31- /// Will fail if scheme is not "http", "https", "wss" or "udp".
41+ /// Will fail if scheme is not "http", "https", "wss" or "udp", unless
42+ /// the `unknown_tracker_scheme` crate feature is enabled.
3243 pub fn from_url ( url : & Uri < String > ) -> Result < Tracker , TrackerError > {
3344 Ok ( Tracker {
3445 scheme : TrackerScheme :: from_str ( url. scheme ( ) . as_str ( ) ) ?,
@@ -120,7 +131,14 @@ impl FromStr for TrackerScheme {
120131/// Error occurred during parsing a [`Tracker`](crate::tracker::Tracker).
121132#[ derive( Clone , Debug , PartialEq ) ]
122133pub enum TrackerError {
134+ /// Tracker URL could not be parsed because it is malformed.
135+ ///
136+ /// I'm not sure under what circumstances this could happen.
123137 InvalidURL { source : UriParseError } ,
138+ /// Tracker scheme is not a known variant.
139+ ///
140+ /// This error does not exist when the `unknown_tracker_scheme` crate
141+ /// feature is enabled.
124142 InvalidScheme { scheme : String } ,
125143}
126144
0 commit comments