C# Class Kademlia.ID

Inheritance: IComparable
Show file Open project: zencoders/sambatyon Class Usage Examples

Public Methods

Method Description
CompareTo ( object obj ) : int

Compare ourselves to an object

DifferingBit ( ID other ) : int

Determines the least significant bit at which the given ID differs from this one, from 0 through 8 * ID_LENGTH - 1. PRECONDITION: IDs do not match.

Equals ( object obj ) : bool

Method used to verify if two objects are equals.

FromString ( string hash ) : ID

Method that generates an ID starting from a generic string. This is not hashing.

GetHashCode ( ) : int

Method used to get the hash code according to the algorithm: http://stackoverflow.com/questions/16340/how-do-i-generate-a-hashcode-from-a-byte-array-in-c/425184#425184

Hash ( string key ) : ID

Hash a string to produce an ID

HostID ( ) : ID

Get an ID that will be the same between different calls on the same machine by the same app run by the same user. If that ID is taken, returns a random ID.

ID ( byte data ) : System

Make a new ID from a byte array.

ID ( string new_id ) : System

Make a new ID starting from a string. Pay attention, the string is not hashed, it is simply translated to an ID object.

RandomID ( ) : ID

Produce a random ID.

RandomizeBeyond ( int bit ) : ID

Return a copy of ourselves that differs from us at the given bit and is random beyond that.

ToPathString ( ) : string

Returns this ID represented as a path-safe string.

ToString ( ) : string

Turn this ID into a string.

operator ( ) : ID

XOR operator. This is our distance metric in the DHT.

operator ( ) : bool

We need to compare these when measuring distance

Private Methods

Method Description
FlipBit ( byte data, int bit ) : void

Flips the given bit in the byte array. Byte array must be ID_LENGTH long.

IDInit ( byte data ) : void

This method initialize an id starting from a byte array.

Method Details

CompareTo() public method

Compare ourselves to an object
public CompareTo ( object obj ) : int
obj object An obect to compare to
return int

DifferingBit() public method

Determines the least significant bit at which the given ID differs from this one, from 0 through 8 * ID_LENGTH - 1. PRECONDITION: IDs do not match.
public DifferingBit ( ID other ) : int
other ID The ID to compare to
return int

Equals() public method

Method used to verify if two objects are equals.
public Equals ( object obj ) : bool
obj object The object to compare to
return bool

FromString() public static method

Method that generates an ID starting from a generic string. This is not hashing.
public static FromString ( string hash ) : ID
hash string The hash string originating an ID
return ID

GetHashCode() public method

Method used to get the hash code according to the algorithm: http://stackoverflow.com/questions/16340/how-do-i-generate-a-hashcode-from-a-byte-array-in-c/425184#425184
public GetHashCode ( ) : int
return int

Hash() public static method

Hash a string to produce an ID
public static Hash ( string key ) : ID
key string Key string to convert
return ID

HostID() public static method

Get an ID that will be the same between different calls on the same machine by the same app run by the same user. If that ID is taken, returns a random ID.
public static HostID ( ) : ID
return ID

ID() public method

Make a new ID from a byte array.
public ID ( byte data ) : System
data byte An array of exactly 20 bytes.
return System

ID() public method

Make a new ID starting from a string. Pay attention, the string is not hashed, it is simply translated to an ID object.
public ID ( string new_id ) : System
new_id string The string to translate
return System

RandomID() public static method

Produce a random ID.
public static RandomID ( ) : ID
return ID

RandomizeBeyond() public method

Return a copy of ourselves that differs from us at the given bit and is random beyond that.
public RandomizeBeyond ( int bit ) : ID
bit int the bit to start to launch random bits
return ID

ToPathString() public method

Returns this ID represented as a path-safe string.
public ToPathString ( ) : string
return string

ToString() public method

Turn this ID into a string.
public ToString ( ) : string
return string

operator() public static method

XOR operator. This is our distance metric in the DHT.
public static operator ( ) : ID
return ID

operator() public static method

We need to compare these when measuring distance
public static operator ( ) : bool
return bool