query

suspend fun query(host: String, port: Int, build: (ByteArray) -> Entry): DhtMessage.Response?

Send the query build produced (a bencodable Entry envelope from DhtMessage.build*Query(transactionId, …)) to host:port, then suspend until the matching response arrives or timeoutMillis elapses.

The caller does not supply the transaction id: query mints a fresh unused one, hands it to build, and uses the same bytes as the map key. That is exactly the rpc_manager::invoke contract where the manager, not the algorithm, owns t.

Return

the matching DhtMessage.Response, or null on timeout. A protocol error reply is surfaced as a thrown DhtProtocolException so a null unambiguously means "no answer".

Parameters

build

given the freshly-minted 2-byte transaction id, returns the full query Entry (e.g. { tid -> DhtMessage.buildGetPeersQuery(tid, myId, ih) }).

Throws

if the peer answered with a KRPC error.