Crate tari_comms_dht

Crate tari_comms_dht 

Source
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 InboundMessage and 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 BroadcastStrategy from the received DhtOutboundRequest message. The next_service is called for each resulting message.
  • message logger layer.
  • serialization: wraps the body in a DhtOutboundMessage, serializes the result, constructs an OutboundMessage and calls next_service. Typically, next_service will be a SinkMiddleware which 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§

DHTCommsHashDomain
A hashing domain instance
DedupLayer
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
DhtConnectivityConfig
DhtDiscoveryRequester
DhtRequester
DHT actor requester
MetricsCollectorHandle
NetworkDiscoveryConfig

Enums§

BootstrapMethod
DhtActorError
Error type for the DHT actor
DhtDiscoveryError
DhtEncryptError
DhtInitializationError
DhtProtocolVersion
Versions for the DHT protocol
DhtRequest
Request type for the DHT actor
DiscoveryPhase

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