Skip to content

Commit cb914da

Browse files
committed
feat: replace peer ID recognition with tdyne-peer-id-registry
1 parent 5ecdde5 commit cb914da

File tree

4 files changed

+73
-80
lines changed

4 files changed

+73
-80
lines changed

Cargo.lock

+63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ serde = { version = "1", features = ["derive"] }
5454
serde_bencode = "0"
5555
serde_json = "1"
5656
serde_with = "3"
57+
tdyne-peer-id = "1"
58+
tdyne-peer-id-registry = "0.1"
5759
thiserror = "1"
5860
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
5961
torrust-tracker-configuration = { version = "3.0.0-alpha.12-develop", path = "packages/configuration" }

src/servers/apis/v1/context/torrent/resources/peer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl From<tracker::peer::Id> for Id {
3939
fn from(peer_id: tracker::peer::Id) -> Self {
4040
Id {
4141
id: peer_id.to_hex_string(),
42-
client: peer_id.get_client_name().map(std::string::ToString::to_string),
42+
client: peer_id.get_client_name(),
4343
}
4444
}
4545
}

src/tracker/peer.rs

+7-79
Original file line numberDiff line numberDiff line change
@@ -252,81 +252,9 @@ impl Id {
252252
}
253253

254254
#[must_use]
255-
pub fn get_client_name(&self) -> Option<&'static str> {
256-
if self.0[0] == b'M' {
257-
return Some("BitTorrent");
258-
}
259-
if self.0[0] == b'-' {
260-
let name = match &self.0[1..3] {
261-
b"AG" | b"A~" => "Ares",
262-
b"AR" => "Arctic",
263-
b"AV" => "Avicora",
264-
b"AX" => "BitPump",
265-
b"AZ" => "Azureus",
266-
b"BB" => "BitBuddy",
267-
b"BC" => "BitComet",
268-
b"BF" => "Bitflu",
269-
b"BG" => "BTG (uses Rasterbar libtorrent)",
270-
b"BR" => "BitRocket",
271-
b"BS" => "BTSlave",
272-
b"BX" => "~Bittorrent X",
273-
b"CD" => "Enhanced CTorrent",
274-
b"CT" => "CTorrent",
275-
b"DE" => "DelugeTorrent",
276-
b"DP" => "Propagate Data Client",
277-
b"EB" => "EBit",
278-
b"ES" => "electric sheep",
279-
b"FT" => "FoxTorrent",
280-
b"FW" => "FrostWire",
281-
b"FX" => "Freebox BitTorrent",
282-
b"GS" => "GSTorrent",
283-
b"HL" => "Halite",
284-
b"HN" => "Hydranode",
285-
b"KG" => "KGet",
286-
b"KT" => "KTorrent",
287-
b"LH" => "LH-ABC",
288-
b"LP" => "Lphant",
289-
b"LT" => "libtorrent",
290-
b"lt" => "libTorrent",
291-
b"LW" => "LimeWire",
292-
b"MO" => "MonoTorrent",
293-
b"MP" => "MooPolice",
294-
b"MR" => "Miro",
295-
b"MT" => "MoonlightTorrent",
296-
b"NX" => "Net Transport",
297-
b"PD" => "Pando",
298-
b"qB" => "qBittorrent",
299-
b"QD" => "QQDownload",
300-
b"QT" => "Qt 4 Torrent example",
301-
b"RT" => "Retriever",
302-
b"S~" => "Shareaza alpha/beta",
303-
b"SB" => "~Swiftbit",
304-
b"SS" => "SwarmScope",
305-
b"ST" => "SymTorrent",
306-
b"st" => "sharktorrent",
307-
b"SZ" => "Shareaza",
308-
b"TN" => "TorrentDotNET",
309-
b"TR" => "Transmission",
310-
b"TS" => "Torrentstorm",
311-
b"TT" => "TuoTu",
312-
b"UL" => "uLeecher!",
313-
b"UT" => "µTorrent",
314-
b"UW" => "µTorrent Web",
315-
b"VG" => "Vagaa",
316-
b"WD" => "WebTorrent Desktop",
317-
b"WT" => "BitLet",
318-
b"WW" => "WebTorrent",
319-
b"WY" => "FireTorrent",
320-
b"XL" => "Xunlei",
321-
b"XT" => "XanTorrent",
322-
b"XX" => "Xtorrent",
323-
b"ZT" => "ZipTorrent",
324-
_ => return None,
325-
};
326-
Some(name)
327-
} else {
328-
None
329-
}
255+
pub fn get_client_name(&self) -> Option<String> {
256+
let peer_id = tdyne_peer_id::PeerId::from(self.0);
257+
tdyne_peer_id_registry::parse(peer_id).ok().map(|parsed| parsed.client)
330258
}
331259
}
332260

@@ -336,9 +264,9 @@ impl Serialize for Id {
336264
S: serde::Serializer,
337265
{
338266
#[derive(Serialize)]
339-
struct PeerIdInfo<'a> {
267+
struct PeerIdInfo {
340268
id: Option<String>,
341-
client: Option<&'a str>,
269+
client: Option<String>,
342270
}
343271

344272
let obj = PeerIdInfo {
@@ -476,7 +404,7 @@ mod test {
476404
#[test]
477405
fn it_should_be_serializable() {
478406
let torrent_peer = Peer {
479-
peer_id: peer::Id(*b"-qB00000000000000000"),
407+
peer_id: peer::Id(*b"-qB0000-000000000000"),
480408
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080),
481409
updated: Current::now(),
482410
uploaded: NumberOfBytes(0),
@@ -490,7 +418,7 @@ mod test {
490418
let expected_raw_json = r#"
491419
{
492420
"peer_id": {
493-
"id": "0x2d71423030303030303030303030303030303030",
421+
"id": "0x2d7142303030302d303030303030303030303030",
494422
"client": "qBittorrent"
495423
},
496424
"peer_addr":"126.0.0.1:8080",

0 commit comments

Comments
 (0)