NodeEntry

class NodeEntry

One node in the DHT routing table: the pure-Kotlin port of libtorrent's node_entry (include/libtorrent/kademlia/node_entry.hpp, src/kademlia/node_entry.cpp).

libtorrent stores the endpoint as a union_endpoint (a Boost.Asio address+port). KiteTorrent's commonMain has no socket types, so per the DHT module's contract the endpoint is carried as a host String plus an Int. The host is additionally parsed once into a PeerAddress (addr) so the routing table can do the things that genuinely need the numeric address: the BEP 42 verified check and per-IP de-duplication.

Counters & flags (ported verbatim):

  • rtt: the smoothed round-trip time in milliseconds; 0xffff means "unknown". updateRtt applies libtorrent's rtt*2/3 + new/3 EWMA.

  • timeoutCount: consecutive failed requests. The sentinel 0xff means "never pinged" (see pinged); 0 means "confirmed up" (see confirmed).

  • verified: the node id matches its IP per BEP 42 (verifyId). The "which node is better" ordering (isBetterThan) uses it as the primary key.

This is a mutable value object (libtorrent mutates entries in place inside the buckets), so it is a plain class with var fields rather than a data class.

Constructors

Link copied to clipboard
constructor(id: Sha1Hash, host: String, port: Int, rtt: Int = RTT_UNKNOWN, pinged: Boolean = false)

Full constructor: port of node_entry(node_id const&, udp::endpoint const&, int rtt, bool pinged).

constructor(host: String, port: Int)

Endpoint-only constructor with an unknown (all-zero) id: port of explicit node_entry(udp::endpoint const& ep). Such an entry is "not pinged" and "not verified".

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The numeric form of host, or null if host was not a parseable IP literal. The routing table treats un-parseable hosts as having no IP identity (they can't be verified and don't participate in IP de-dup).

Link copied to clipboard

The endpoint host literal (IPv4 dotted-quad or IPv6 colon-hex), as given.

Link copied to clipboard

The node's 160-bit id. Defaults to all-zeroes (node_id{nullptr}).

Link copied to clipboard
val port: Int

The endpoint UDP port.

Link copied to clipboard
var rtt: Int

Smoothed round-trip time in ms; 0xffff (= RTT_UNKNOWN) means unknown.

Link copied to clipboard

Consecutive failures. 0xff (= NOT_PINGED) is the special "we have not pinged this node yet" sentinel; otherwise it counts timeouts in a row.

Link copied to clipboard

true if the node id is BEP-42-valid for its IP (verify_id).

Functions

Link copied to clipboard

true if the node has been pinged and has zero failures (confirmed).

Link copied to clipboard
fun failCount(): Int

Number of consecutive failures, or 0 if never pinged (fail_count).

Link copied to clipboard

"Smaller is better" ordering from bool operator<(node_entry const&):

Link copied to clipboard

true once we've ever pinged this node (timeout_count != 0xff).

Link copied to clipboard

Reset the fail counter to 0 if the node has been pinged (reset_fail_count).

Link copied to clipboard
fun sameEndpoint(otherHost: String, otherPort: Int): Boolean

Endpoints match iff both host and port are equal (used by find_node(ep)).

Link copied to clipboard
fun setPinged()

Mark the node as pinged if it wasn't already (set_pinged).

Link copied to clipboard
fun timedOut()

Record a timed-out request (timed_out): bump the fail counter, capped.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun updateRtt(newRtt: Int)

Update the smoothed rtt with a fresh sample. Port of node_entry::update_rtt(int):