#peer-id #bittorrent #parser #client #registry #track #format

tdyne-peer-id-registry

A library for parsing and (soon) encoding BitTorrent peer IDs. Tracks all known BitTorrent implementations and their peer ID formats.

1 unstable release

0.1.1 Oct 7, 2023
0.1.0 Oct 7, 2023

#864 in Parser implementations

Download history 164/week @ 2023-12-18 162/week @ 2023-12-25 355/week @ 2024-01-01 312/week @ 2024-01-08 328/week @ 2024-01-15 492/week @ 2024-01-22 590/week @ 2024-01-29 148/week @ 2024-02-05 180/week @ 2024-02-12 375/week @ 2024-02-19 184/week @ 2024-02-26 42/week @ 2024-03-04 295/week @ 2024-03-11 570/week @ 2024-03-18 365/week @ 2024-03-25 242/week @ 2024-04-01

1,477 downloads per month

MIT/Apache

85KB
2K SLoC

BitTorrent peer ID registry/parser/(soon) encoder

By convention, BitTorrent clients identify themselves and their versions in peer IDs they send to trackers and other clients. Unfortunately, there is no single client/version encoding, so over time different clients adopted different conventions, which made parsing peer IDs difficult. This crate provides a comprehensive peer ID parser and a registry of all known BitTorrent clients.

Peer ID encoding is one of immediate goals, see "Roadmap" below for details.

This crate uses tdyne_peer_id to encode peer IDs.

Example:

use tdyne_peer_id::PeerId;
use tdyne_peer_id_registry::parse;

let peer_id = PeerId::from(b"-TR404Z-*\x00\x01d7xkqq04n");

let parsed = parse(peer_id).expect("recognised peer ID");
assert_eq!(parsed.client, "Transmission");

let version = parsed.version
    .expect("valid version encoding")
    .expect("Transmission does encode a version in its peer ID");
assert_eq!(version, "4.0.4 (Dev)");

Current status

  • used in production on TORRENTDYNE
  • test parity with Webtorrent's bittorrent-peerid, the most popular JS implementation of BitTorrent peer ID parsing
  • improves on bittorrent-peerid by recognising more clients and versions
  • regularly fuzzed to verify absence of panics

Roadmap

Encoding peer IDs

A peer ID formatting API that only accepts known clients (in release mode) and takes choices out of peer ID formatting would help the ecosystem to stay more consistent.

Test parity with Transmission

Transmission has an extensive peer ID parser. Right now the Venn diagram of clients that tdyne_peer_id_registry and Transmission can handle is two intersecting circles. It needs to get closer to two concentric rings.

Structured allocation-free API

tdyne_peer_id_registry is designed to parse into an allocation-free tree of structs and enums. In the current version the tree is not exposed as it is not stable yet and changing it would be a breaking change. Instead, the API immediately turns the tree into strings, the lowest common denominator. However, exposing the tree directly would help projects that need to act on the information from the peer ID, as they would be able to work directly with the structures instead of re-parsing strings.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~145KB