9 releases

1.0.0-rc.5 Feb 9, 2024
0.8.1 Feb 3, 2021
0.2.5 Sep 1, 2020
0.2.3 Aug 18, 2020
0.0.10 Mar 30, 2020

#4 in #comms

Download history 12/week @ 2024-07-16 13/week @ 2024-07-23 4/week @ 2024-07-30 4/week @ 2024-08-06 2/week @ 2024-09-10 3/week @ 2024-09-17 13/week @ 2024-09-24 10/week @ 2024-10-01

110 downloads per month
Used in 5 crates

BSD-3-Clause

2.5MB
50K SLoC

Tari comms DHT module

The Tari network messaging library. See CommsBuilder for more information on using this library.


lib.rs:

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
  • SAF storage: stores certain messages for other peers in the SAF store.
  • message storage: forwards messages for other peers.
  • SAF message handler: handles SAF protocol messages (requests for SAF messages, SAF message responses).
  • 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.

Dependencies

~62MB
~1M SLoC