Package-level declarations

Types

Link copied to clipboard
class DhtNode(socket: DatagramTransport, nodeId: Sha1Hash, scope: CoroutineScope, val routingTable: RoutingTable = RoutingTable(nodeId, K_BUCKET), val storage: DhtStorage = DhtStorage(), tokens: DhtTokens = DhtTokens(), clock: () -> Long = { 0L }, enforceNodeId: Boolean = false, readOnly: Boolean = false, random: Random = Random.Default)

A live Kademlia DHT node (BEP-5). This is the networked half of the DHT. It wires the pure RoutingTable, DhtMessage, DhtStorage and DhtItem types to a UDP socket via DhtRpc and TraversalState. Port of dht::node, dht_tracker and the find_data and get_peers traversal algorithms.

Link copied to clipboard
class DhtProtocolException(val code: Int, message: String) : Exception

Raised when a DHT peer answers a query with a KRPC error (y:"e", e:[code, msg]), the read side of incoming_error. Carries the numeric code (201 generic, 203 protocol, 204 method-unknown, …) and the human-readable message.

Link copied to clipboard
class DhtRpc(socket: DatagramTransport, random: Random = Random.Default, timeoutMillis: Long = DEFAULT_TIMEOUT_MILLIS)

The live KRPC request and response manager. This is the coroutine port of libtorrent's rpc_manager (src/kademlia/rpc_manager.cpp) reduced to the one job that a commonMain engine can carry: match an outgoing query to its reply.

Link copied to clipboard
class DhtTokens(random: Random = Random.Default)

Write-token generation and verification for an inbound get_peers / announce_peer (and BEP-44 get/put) flow. This is the pure, network-free port of node::generate_token and node::verify_token (src/kademlia/node.cpp).

Link copied to clipboard
class TraversalState(val target: Sha1Hash, val resultsTarget: Int = DEFAULT_RESULTS_TARGET, val branchFactor: Int = DEFAULT_BRANCH_FACTOR)

The pure candidate bookkeeping of an iterative Kademlia lookup. This is the network-free core of libtorrent's traversal_algorithm (src/kademlia/traversal_algorithm.cpp). DhtNode.getPeers drives one of these: it seeds the state with the routing table's closest nodes, then repeatedly asks the state for the next batch to query (next), fires the actual get_peers/find_node RPCs, and feeds the returned closer nodes back in (add).

Functions

Link copied to clipboard

Order nodes nearest-first by XOR distance to target. This is the standalone form of the comparator TraversalState inserts under, exposed for callers (and tests) that just want a sorted snapshot of compact nodes. Stable on ties by id.