tuweni / org.apache.tuweni.kademlia / KademliaRoutingTable

KademliaRoutingTable

class KademliaRoutingTable<T> : Set<T> (source)

A Kademlia Routing Table

Constructors

<init>

Create a new routing table.

KademliaRoutingTable(selfId: ByteArray, k: Int, maxReplacements: Int = k, nodeId: (T) -> ByteArray, distanceToSelf: (T) -> Int = { nodeId(it) xorDist selfId })

Properties

size

Provides the size of the table as the sum of the size of the buckets

val size: Int

Functions

add

Add a node to the table.

fun add(node: T): T?

clear

Clear all nodes (and replacements) from the table.

fun clear(): Unit

contains

fun contains(element: T): Boolean

containsAll

fun containsAll(elements: Collection<T>): Boolean

evict

Remove a node from the table, potentially adding an alternative from the replacement cache.

fun evict(node: T): Boolean

getRandom

Provides a peer at random

fun getRandom(): T

isEmpty

fun isEmpty(): Boolean

iterator

fun iterator(): Iterator<T>

logDistToSelf

Provides the distance between our identity and the peer

fun logDistToSelf(node: T): Int

nearest

Return the nearest nodes to a target id, in order from closest to furthest.

fun nearest(targetId: ByteArray, limit: Int): List<T>

peersOfDistance

Returns all peers at a given distance of the original ID.

fun peersOfDistance(value: Int): List<T>

Companion Object Functions

create

Create a new routing table.

fun <T> create(selfId: ByteArray, k: Int, nodeId: Function<T, ByteArray>, distanceToSelf: Function<T, Int>): KademliaRoutingTable<T>
fun <T> create(selfId: ByteArray, k: Int, maxReplacements: Int, nodeId: Function<T, ByteArray>, distanceToSelf: Function<T, Int>): KademliaRoutingTable<T>