Companion

object Companion

Properties

Link copied to clipboard
const val ERROR_PROTOCOL: Int = 203

Default KRPC error code used by incoming_error (protocol error).

Functions

Link copied to clipboard

Build a Query model directly into its bencoded Entry envelope.

Link copied to clipboard
fun buildAnnouncePeerQuery(transactionId: ByteArray, nodeId: Sha1Hash, infoHash: Sha1Hash, port: Int, token: ByteArray, impliedPort: Boolean = false, seed: Boolean = false, name: String? = null): Entry

Build an announce_peer query: a{id, info_hash, port, token, implied_port?, seed?, n?}. Port of the e["q"]="announce_peer" assembly in node::announce's callback.

Link copied to clipboard
fun buildError(transactionId: ByteArray, message: String, code: Int = ERROR_PROTOCOL): Entry

Build an error response: {t, y:"e", e:[code, message]}. Direct port of incoming_error(entry&, char const*, int).

Link copied to clipboard
fun buildFindNodeQuery(transactionId: ByteArray, nodeId: Sha1Hash, target: Sha1Hash): Entry

Build a find_node query: a{id, target}. (libtorrent issues this via refresh/bootstrap; the argument layout matches incoming_request's find_node schema.)

Link copied to clipboard
fun buildGetPeersQuery(transactionId: ByteArray, nodeId: Sha1Hash, infoHash: Sha1Hash, noseed: Boolean = false, scrape: Boolean = false): Entry

Build a get_peers query: a{id, info_hash, noseed?}. Port of get_peers::invoke: a["info_hash"]=…; if (noseed) a["noseed"]=1.

Link copied to clipboard
fun buildGetQuery(transactionId: ByteArray, nodeId: Sha1Hash, target: Sha1Hash, seq: Long? = null): Entry

Build a get query: a{id, target, seq?}. Port of get_item::invoke (a["target"]=target); seq is the optional BEP-44 read filter.

Link copied to clipboard
fun buildItemResponse(transactionId: ByteArray, nodeId: Sha1Hash, token: ByteArray?, item: DhtItem? = null, nodes: List<CompactNode> = emptyList(), nodes6: List<CompactNode> = emptyList(), includeValue: Boolean = true): Entry

Build a get (BEP-44) response: r{id, token, nodes?, nodes6?, [seq, v, k, sig]}. Port of the get branch of incoming_request plus dht_storage::get_mutable_item/get_immutable_item: an immutable item adds only v; a mutable item adds seq always and v/sig/k when filled.

Link copied to clipboard
fun buildNodesResponse(transactionId: ByteArray, nodeId: Sha1Hash, nodes: List<CompactNode> = emptyList(), nodes6: List<CompactNode> = emptyList()): Entry

Build a find_node-style response: r{id, nodes?, nodes6?}. Mirrors write_nodes_entries, which writes the compact list under the protocol's nodes/nodes6 key.

Link copied to clipboard
fun buildPeersResponse(transactionId: ByteArray, nodeId: Sha1Hash, token: ByteArray?, values: List<DhtEndpoint> = emptyList(), nodes: List<CompactNode> = emptyList(), nodes6: List<CompactNode> = emptyList()): Entry

Build a get_peers response: r{id, token, values?, nodes?, nodes6?}. Port of lookup_peers + write_nodes_entries: the values list holds one compact endpoint string per peer.

Link copied to clipboard
fun buildPingQuery(transactionId: ByteArray, nodeId: Sha1Hash): Entry

Build a ping query: {t, y:"q", q:"ping", a:{id}}. Mirrors the e["q"]="ping" branch of node::send_single_refresh.

Link copied to clipboard
fun buildPingResponse(transactionId: ByteArray, nodeId: Sha1Hash): Entry

Build a bare response carrying only id: {t, y:"r", r:{id}}. This is what ping/announce_peer reply with (incoming_request adds nothing beyond t and id).

Link copied to clipboard
fun buildPutQuery(transactionId: ByteArray, nodeId: Sha1Hash, token: ByteArray, item: DhtItem, cas: Long? = null): Entry

Build a put query: a{id, token, v, [k, seq, sig, salt, cas]}. Faithful to put_data::invoke: it splices the value in as its exact bencoding, so the signature still verifies, and it adds the mutable extras only for a MutableItem.

Link copied to clipboard

Parse a decoded KRPC envelope node into a typed DhtMessage, or null if the message is malformed (not a dict, missing/!string t or y, unknown y, missing payload, or a 20-byte-id violation).