Base type for BitTorrent peer IDs
tdyne_peer_id
is a newtype for BitTorrent peer IDs, represented as [u8; 20]
.
It's intentionally kept very minimalist to minimise the possibility of backwards-incompatible
changes.
[dependencies]
tdyne-peer-id = "1"
Example
use tdyne_peer_id::{PeerId, BadPeerIdLengthError};
fn main() {
let byte_array: &[u8; 20] = b"-TR0000-*\x00\x01d7xkqq04n";
let byte_slice: &[u8] = b"-TR0000-*\x00\x01d7xkqq04n";
let short_byte_slice: &[u8] = b"-TR0000-";
let peer_id = PeerId::from(b"-TR0000-*\x00\x01d7xkqq04n");
assert_eq!(peer_id.to_string(), "-TR0000-???d7xkqq04n".to_string());
_ = PeerId::try_from(byte_slice).expect("matching lengths");
let error = BadPeerIdLengthError(short_byte_slice.len());
assert_eq!(PeerId::try_from(short_byte_slice).expect_err("lengths don't match"), error);
}
Libraries and projects using tdyne_peer_id
tdyne_peer_id
is opensourced from TORRENTDYNE, a BitTorrent diagnostic service.
License