Class RoutingTable
Kademlia distributed hash table.
Namespace: Libplanet.Net.Protocols
Assembly: Libplanet.dll
Syntax
public class RoutingTable : object
Constructors
| Improve this Doc View SourceRoutingTable(Address, Int32, Int32)
Creates a Kademlia distributed hash table instance.
Declaration
public RoutingTable(Address address, int tableSize = null, int bucketSize = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Address | address | Address of this peer. |
| Int32 | tableSize | The number of buckets in the table. |
| Int32 | bucketSize | The size of a single bucket. |
Properties
| Improve this Doc View SourceBucketSize
The size of a single bucket.
Declaration
public int BucketSize { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Count
The number of peers in the table.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Peers
An
Declaration
public IReadOnlyList<BoundPeer> Peers { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<BoundPeer> |
PeerStates
An
Declaration
public IReadOnlyList<PeerState> PeerStates { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<PeerState> |
TableSize
The number of buckets in the table.
Declaration
public int TableSize { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Methods
| Improve this Doc View SourceAddPeer(BoundPeer)
Adds the peer to the table.
Declaration
public void AddPeer(BoundPeer peer)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundPeer | peer | The BoundPeer to add. |
Check(BoundPeer, DateTimeOffset, DateTimeOffset)
Marks peer checked and refreshes last checked time of the peer.
Declaration
public void Check(BoundPeer peer, DateTimeOffset start, DateTimeOffset end)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundPeer | peer | The Peer to check. |
| DateTimeOffset | start | |
| DateTimeOffset | end |
Clear()
Removes all peers in the table. This method does not affect static peers.
Declaration
public void Clear()
Contains(BoundPeer)
Determines whether the RoutingTable contains the specified key.
Declaration
public bool Contains(BoundPeer peer)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundPeer | peer | Key to locate in the RoutingTable. |
Returns
| Type | Description |
|---|---|
| Boolean | true if the RoutingTable contains an element with the specified key; otherwise, false. |
GetPeer(Address)
Declaration
public BoundPeer GetPeer(Address addr)
Parameters
| Type | Name | Description |
|---|---|---|
| Address | addr | The Address to search. |
Returns
| Type | Description |
|---|---|
| BoundPeer |
Neighbors(Address, Int32, Boolean)
Returns at most 2 * k (2 * k + 1 if
includeTarget is true) nearest peers to given parameter peer
from routing table. Return value is sorted with respect to target.
SortByDistance(IEnumerable<BoundPeer>, Address)
Declaration
public IReadOnlyList<BoundPeer> Neighbors(Address target, int k, bool includeTarget)
Parameters
| Type | Name | Description |
|---|---|---|
| Address | target | Address to look up. |
| Int32 | k | Number of peers to return. |
| Boolean | includeTarget | A boolean value indicates to include a peer with
Address of |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<BoundPeer> | An enumerable of BoundPeer. |
Neighbors(Peer, Int32, Boolean)
Returns k nearest peers to given parameter peer from routing table.
Return value is already sorted with respect to target.
Declaration
public IReadOnlyList<BoundPeer> Neighbors(Peer target, int k, bool includeTarget)
Parameters
| Type | Name | Description |
|---|---|---|
| Peer | target | Peer to look up. |
| Int32 | k | Number of peers to return. |
| Boolean | includeTarget | A boolean value indicates to include a peer with
Address of |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<BoundPeer> | An enumerable of BoundPeer. |
RemovePeer(BoundPeer)
Declaration
public bool RemovePeer(BoundPeer peer)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundPeer | peer |
Returns
| Type | Description |
|---|---|
| Boolean |