CompactNodes

Encode/decode of the compact nodes strings that BEP-5 queries return: the counterpart to libtorrent's write_nodes_entry and the inline decode loops in find_data / the routing table's read_nodes. The IPv4 form ("n4"/nodes, 26-byte records) and the IPv6 form ("n6"/nodes6, 38-byte records) are encoded here separately because the record width is fixed per family.

Properties

Link copied to clipboard
const val V4_NODE_SIZE: Int = 26

Width of one IPv4 compact node record: 20-byte id + 6-byte endpoint.

Link copied to clipboard
const val V6_NODE_SIZE: Int = 38

Width of one IPv6 compact node record: 20-byte id + 18-byte endpoint.

Functions

Link copied to clipboard

Decode a nodes string of fixed-width IPv4 records (26 bytes each). Any trailing partial record is ignored, matching libtorrent's while (end - in >= 26) style loops.

Link copied to clipboard

Decode a nodes6 string of fixed-width IPv6 records (38 bytes each). Any trailing partial record is ignored.

Link copied to clipboard

Concatenate the compact form of every node in nodes into one byte string: a direct port of write_nodes_entry. Each record is id || write_endpoint(ep). The nodes may freely mix v4/v6 (libtorrent keeps them in separate keys, but the encoding itself is just self-describing-width records).