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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.