Expand description
Resolve data identified by a fixed-length key by using the P2P network.
§Overview
The p2p module enables resolving data by fixed-length keys in a P2P network. Central to the
module is the peer actor which manages the fetch-request lifecycle. Its mailbox allows
initiation and cancellation of fetch requests via the Resolver interface.
The peer handles an arbitrarily large number of concurrent fetch requests by sending requests
to other peers and processing their responses. It selects peers based on performance, retrying
with another peer if one fails or provides invalid data. Requests persist until canceled or
fulfilled, delivering data to the Consumer for verification.
The Consumer checks data integrity and authenticity (critical in an adversarial environment)
and returns true if valid, completing the fetch, or false to retry.
The peer also serves data to other peers, forwarding network requests to the Producer. The
Producer provides data asynchronously (e.g., from storage). If it fails, the peer sends an
empty response, prompting the requester to retry elsewhere. Each message between peers contains
an ID. Each request is sent with a unique ID, and each response includes the ID of the request
it responds to.
§Targeting
Callers can restrict fetches to specific target peers using Resolver::fetch_targeted.
Only target peers are tried, there is no automatic fallback to other peers. Targets persist through
transient failures (timeout, “no data” response, send failure) since the peer might be slow or
receive the data later.
While a fetch is in progress, callers can modify targeting:
Resolver::fetch_targetedadds peers to the existing target set (only if the fetch already has targets, an “all” fetch remains unrestricted)Resolver::fetchclears all targets, allowing fallback to any peer
These modifications only apply to in-progress fetches. Once a fetch completes (success, cancel, or blocked peer), the targets for that key are cleared automatically.
§Performance Considerations
The peer supports arbitrarily many concurrent fetch requests, but resource usage generally depends on the rate-limiting configuration of the underlying P2P network.
Structs§
- Config
- Configuration for the peer actor.
- Engine
- Manages incoming and outgoing P2P requests, coordinating fetch and serve operations.
- Mailbox
- A way to send messages to the peer actor.
Traits§
- Producer
- Serves data requested by the network.