Expand description
§Tari Comms DHT
§Overview
The tari_comms_dht crate adds DHT functionality to tari_comms.
It provides two sets of middleware (inbound and outbound) which
process incoming requests and outgoing messages respectively.
§Attaching to comms
In tari_comms, incoming and outgoing messages are connected using two mpsc sender/receiver pairs.
One for incoming messages (receiving InboundMessages) and one for outbound messages (sending OutboundMessages).
The DHT module consists of two middleware layers (as in tower_layer::Layer) which form
an inbound and outbound pipeline for augmenting messages.
§Inbound Message Flow
InboundMessages are received from the incoming comms channel (as in the receiver side of
of the mpsc channel which goes into CommsBuilder::new().incoming_message_sink(sender)).
Typically, a ServicePipeline from the tari_comms::middleware crate is used to connect
a stream from comms to the middleware service.
InboundMessage(comms) -> DHT Inbound Middleware -> DhtInboundMessage(domain)
The DHT inbound middleware consist of:
- metrics: monitors the number of inbound messages
- decryption: deserializes and decrypts the
InboundMessageand produces a DecryptedDhtMessage. - dedup: discards the message if previously received.
- logging: message logging
- DHT message handler: handles DHT protocol messages (discovery, join etc.)
§Outbound Message Flow
OutboundMessages are sent to the outgoing comms channel (as in the receiver side of
of the mpsc channel which goes into CommsBuilder::new().outgoing_message_stream(receiver)).
Typically, a ServicePipeline from the tari_comms::middleware crate is used to connect
a stream from the domain-level to the middleware service and a SinkMiddleware to connect
the middleware to the OMS in comms. Outbound requests to the DHT middleware are furnished by
the OutboundMessageRequester, obtained from the Dht::outbound_requester factory method.
DhtOutboundRequest (domain) -> DHT Outbound Middleware -> OutboundMessage (comms)
The DHT outbound middleware consist of:
- broadcast layer: produces multiple outbound messages according on the
BroadcastStrategyfrom the receivedDhtOutboundRequestmessage. Thenext_serviceis called for each resulting message. - message logger layer.
- serialization: wraps the body in a DhtOutboundMessage, serializes the
result, constructs an
OutboundMessageand callsnext_service. Typically,next_servicewill be aSinkMiddlewarewhich send the message to comms messaging.
Modules§
- broadcast_
strategy - Broadcast strategy
- domain_
message - envelope
- event
- inbound
- DHT middleware layers for inbound messages.
- outbound
- DHT middleware layers for outbound messages.
Structs§
- DHTComms
Hash Domain - A hashing domain instance
- Dedup
Layer - Dht
- Responsible for starting the DHT actor, building the DHT middleware stack and as a factory for producing DHT requesters.
- DhtBuilder
- Builder for the DHT.
- DhtConfig
- DhtConnectivity
Config - DhtDiscovery
Requester - DhtRequester
- DHT actor requester
- Metrics
Collector Handle - Network
Discovery Config
Enums§
- Bootstrap
Method - DhtActor
Error - Error type for the DHT actor
- DhtDiscovery
Error - DhtEncrypt
Error - DhtInitialization
Error - DhtProtocol
Version - Versions for the DHT protocol
- DhtRequest
- Request type for the DHT actor
- Discovery
Phase
Functions§
- comms_
dht_ hash_ domain_ challenge - Hash domain used to produce binding message hashes
- comms_
dht_ hash_ domain_ key_ mask - Hash domain used for message encryption key masking
- comms_
dht_ hash_ domain_ key_ message - Hash domain used for message encryption keys
- comms_
dht_ hash_ domain_ message_ signature - Hash domain used for message signing