Struct rustydht_lib::common::Id [−][src]
pub struct Id { /* fields omitted */ }
Expand description
Represents the id of a Node or a BitTorrent info-hash. Basically, it’s a 20-byte identifier.
Implementations
Create a new Id from some bytes. Returns Err if bytes
is not of length
ID_SIZE.
Generates a random Id for a mainline DHT node with the provided IP address. The generated Id will be valid with respect to BEP0042.
Generates a completely random Id. The returned Id is not guaranteed to be valid with respect to BEP0042.
Copies the byes that make up the Id and returns them in a Vec
Evaluates the Id and decides if it’s a valid Id for a DHT node with the provided IP address (based on BEP0042). Note: the current implementation does not handle non-globally-routable address space properly. It will likely return false for non-routable IPv4 address space (against the spec).
Returns the number of bits of prefix that the two ids have in common.
Consider two Ids with binary values 10100000
and 10100100
. This function
would return 5
because the Ids share the common 5-bit prefix 10100
.
Creates an Id from a hex string.
For example: let id = Id::from_hex("88ffb73943354a00dc2dadd14c54d28020a513c8").unwrap();
Computes the exclusive or (XOR) of this Id with another. The BitTorrent DHT uses XOR as its distance metric.
Example: let distance_between_nodes = id.xor(other_id);
Makes a new id that’s similar to this one.
identical_bytes
specifies how many bytes of the resulting Id should be the same as this
.
identical_bytes
must be in the range (0, ID_SIZE) otherwise Err
is returned.
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more