receiver.rs

Overview

This file defines the asynchronous message receiving logic of the network communication layer. It handles incoming messages on a network connection, deserializes them, collects metrics related to message transfer, and forwards them to a processing queue. The primary purpose is to continuously listen for incoming network packets, transform raw data into structured messages, and deliver them downstream while monitoring for errors and shutdown signals.

The file focuses on safe and efficient message reception, integrating with metrics and connection management components, and supports orderly shutdown through Tokio's watch channels.

Detailed Description of Components

Functions


pub async fn receiver<Connection>(...) -> anyhow::Result<()>


async fn receive_message<Connection>(...)


Important Implementation Details

Interaction with Other System Components

Diagram: Structure of receiver.rs

flowchart TD
A[receiver function] -->|calls| B[receive_message function]
B --> C{connection.connection.recv()}
C -->|Ok| D[Deserialize NetMessage]
D --> E[Send IncomingMessage via incoming_tx]
E -->|channel closed| F[Signal receiver_stop_tx]
C -->|Err| G[Log error and Signal receiver_stop_tx]
A -->|listens to| H[shutdown_rx & receiver_stop_rx]
H -->|signal received| I[Break loop & finish]

This flowchart illustrates the main workflow of the receiver loop, the message reception, deserialization, forwarding, and the coordination of shutdown signals.