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

#7 in #comms

Download history 34/week @ 2023-11-01 23/week @ 2023-11-08 31/week @ 2023-11-15 29/week @ 2023-11-22 28/week @ 2023-11-29 22/week @ 2023-12-06 30/week @ 2023-12-13 30/week @ 2023-12-20 24/week @ 2023-12-27 12/week @ 2024-01-03 20/week @ 2024-01-10 29/week @ 2024-01-17 22/week @ 2024-01-24 18/week @ 2024-01-31 61/week @ 2024-02-07 111/week @ 2024-02-14

229 downloads per month
Used in 5 crates

BSD-3-Clause

2.5MB
49K 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

~45–61MB
~1M SLoC