Skip to main content

Module dispatch

Module dispatch 

Source
Expand description

§Inbound RPC dispatch loop

The hot path of the server: a single async loop that drains IncomingRequests from the transport’s mpsc::Receiver, decodes each packet via [hashiverse_lib::protocol::rpc::rpc_request::RpcRequestPacketRx], and routes by [hashiverse_lib::protocol::payload::payload::PayloadRequestKind] to the correct per-op handler (bootstrap, announce, get/submit/heal/cache post bundles, get/submit/heal/cache feedback, fetch URL preview, trending hashtags, ping).

Per-request safety checks happen before any real work:

  • PoW verification — the packet’s PoW must be sufficient for this server’s identity. Anything under-powered or stale is dropped immediately.
  • Replay protection — a short-lived salt cache rejects salts we’ve already seen, so a valid signed request can’t be replayed from another network vantage.
  • Peer upgrade — if the caller’s embedded [hashiverse_lib::protocol::peer::Peer] carries a stronger PoW than what we have in the tracker, the tracker is upgraded in place.

The loop respects a CancellationToken so graceful shutdown drains in-flight work and stops accepting new requests cleanly.