C# Class Kademlia.BucketList

A list of contacts. Also responsible for storing last lookup times for buckets, so we can refresh them. Not thread safe for multiple people writing at once, since you can't enforce preconditions.
Show file Open project: zencoders/sambatyon

Public Methods

Method Description
Blocker ( ID toAdd ) : Contact

Returns what contact is blocking insertion (least promoted), or null if no contact is.

BucketList ( ID ourID ) : System

Make a new bucket list, for holding node contacts.

CloseContacts ( ID target, ID excluded ) : List

Return a list of the BUCKET_SIZE contacts with IDs closest to target, not containing any contacts with the excluded ID.

CloseContacts ( int count, ID target, ID excluded ) : List

Returns a list of the specified number of contacts with IDs closest to the given key, excluding the excluded ID.

Contains ( ID toCheck ) : bool

See if we have a contact with the given ID.

Get ( ID toGet ) : Contact

Return the contact with the given ID, or null if it's not found.

GetCount ( ) : int

Return how many contacts are cached.

IDsForRefresh ( System.TimeSpan tooOld ) : IList

Gets a list of IDs that fall in buckets that haven't been written to in tooOld.

NodesToKey ( ID key ) : int

Return the number of nodes in the network closer to the key than us. This is a guess as described at http://xlattice.sourceforge.net/components/protocol/kademlia/specs.html

Promote ( ID toPromote ) : void

Move the contact with the given ID to the front of its bucket.

Put ( Contact toAdd ) : void

Add the given contact at the end of its bucket.

Remove ( ID toRemove ) : void

Remove a contact.

ToString ( ) : string

A ToString for debugging.

Touch ( ID key ) : void

Report that a lookup was done for the given key. Key must not match our ID.

Private Methods

Method Description
BucketFor ( ID id ) : int

Returns what bucket an ID maps to. PRECONDITION: ourID not passed.

ForBucket ( int bucket ) : ID

Return an ID that belongs in the given bucket.

Method Details

Blocker() public method

Returns what contact is blocking insertion (least promoted), or null if no contact is.
public Blocker ( ID toAdd ) : Contact
toAdd ID The node to add
return Contact

BucketList() public method

Make a new bucket list, for holding node contacts.
public BucketList ( ID ourID ) : System
ourID ID The ID to center the list on.
return System

CloseContacts() public method

Return a list of the BUCKET_SIZE contacts with IDs closest to target, not containing any contacts with the excluded ID.
public CloseContacts ( ID target, ID excluded ) : List
target ID The target to find the close node to
excluded ID The excluded ID
return List

CloseContacts() public method

Returns a list of the specified number of contacts with IDs closest to the given key, excluding the excluded ID.
public CloseContacts ( int count, ID target, ID excluded ) : List
count int The number of contacts to found
target ID The target node
excluded ID The excluded node
return List

Contains() public method

See if we have a contact with the given ID.
public Contains ( ID toCheck ) : bool
toCheck ID The ID to find into the structure
return bool

Get() public method

Return the contact with the given ID, or null if it's not found.
public Get ( ID toGet ) : Contact
toGet ID The ID of the contact to Get
return Contact

GetCount() public method

Return how many contacts are cached.
public GetCount ( ) : int
return int

IDsForRefresh() public method

Gets a list of IDs that fall in buckets that haven't been written to in tooOld.
public IDsForRefresh ( System.TimeSpan tooOld ) : IList
tooOld System.TimeSpan The timespan to discriminate
return IList

NodesToKey() public method

Return the number of nodes in the network closer to the key than us. This is a guess as described at http://xlattice.sourceforge.net/components/protocol/kademlia/specs.html
public NodesToKey ( ID key ) : int
key ID The key to analize
return int

Promote() public method

Move the contact with the given ID to the front of its bucket.
public Promote ( ID toPromote ) : void
toPromote ID The identificator of the contact to promote
return void

Put() public method

Add the given contact at the end of its bucket.
public Put ( Contact toAdd ) : void
toAdd Contact The new contact to add
return void

Remove() public method

Remove a contact.
public Remove ( ID toRemove ) : void
toRemove ID The identificator od the contact to remove
return void

ToString() public method

A ToString for debugging.
public ToString ( ) : string
return string

Touch() public method

Report that a lookup was done for the given key. Key must not match our ID.
public Touch ( ID key ) : void
key ID The bucket that refer the bucket to touch
return void