darkfi/net/mod.rs
1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2026 Dyne.org foundation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#[cfg(test)]
20mod tests;
21
22/// Defines how to decode generic messages as well as implementing the
23/// common network messages that are sent between nodes as described
24/// by the [`protocol`] submodule.
25///
26/// Implements a type called `Packet` which is the base message type.
27/// Packets are converted into messages and passed to an event loop.
28pub mod message;
29pub use message::Message;
30
31/// Generic publish/subscribe class that can dispatch any kind of message
32/// to a subscribed list of dispatchers.
33///
34/// Dispatchers subscribe to a single message format of any type. This is
35/// a generalized version of the simple publish-subscribe class in
36/// system::Publisher.
37///
38/// Message Subsystem also enables the creation of new message subsystems,
39/// adding new dispatchers and clearing inactive channels.
40///
41/// Message Subsystem maintains a list of dispatchers, which is a generalized
42/// version of a publisher. Pub-sub is called on dispatchers through the
43/// functions `subscribe` and `notify`. Whereas system::Publisher only allows
44/// messages of a single type, dispatchers can handle any kind of message. This
45/// generic message is called a payload and is processed and decoded by the
46/// Message Dispatcher.
47///
48/// The Message Dispatcher is a class of publishers that implement a generic
49/// trait called Message Dispatcher Interface, which allows us to process any
50/// kind of payload as a message.
51pub mod message_publisher;
52pub use message_publisher::MessageSubscription;
53
54/// Network transports, holds implementations of pluggable transports.
55/// Exposes agnostic dialers and agnostic listeners.
56pub mod transport;
57
58/// Hosts are a list of network addresses used when establishing outbound
59/// connections.
60///
61/// Hosts are shared across the network through the address protocol.
62/// When attempting to connect, a node will loop through addresses in the
63/// hosts store until it finds ones to connect to.
64pub mod hosts;
65
66/// Async channel that handles the sending of messages across the network.
67/// Public interface is used to create new channels, to stop and start a
68/// channel, and to send messages.
69pub mod channel;
70pub use channel::ChannelPtr;
71
72/// P2P provides all core functionality to interact with the P2P network.
73///
74/// Used to create a network, to start and run it, to broadcast messages
75/// across all channels, and to manage the channel store.
76///
77/// The channel store is a hashmap of channel addresses that we can use
78/// to add and remove channels or check whether a channel is already in
79/// the store.
80pub mod p2p;
81pub use p2p::{P2p, P2pPtr};
82
83/// Defines the networking protocol used at each stage in a connection.
84/// Consists of a series of messages that are sent across the network at
85/// the different connection stages.
86///
87/// When a node connects to a network for the first time, it must follow
88/// a seed protocol, which provides it with a list of network hosts to
89/// connect to. To establish a connection to another node, nodes must send
90/// version and version acknowledgement messages. During a connection, nodes
91/// continually get address and get-address messages to inform each other
92/// about what nodes are on the network. Nodes also send out a ping and pong
93/// message which keeps the network from shutting down.
94///
95/// Protocol submodule also implements a jobs manager that handles the
96/// asynchronous execution of the protocols.
97pub mod protocol;
98pub use protocol::{
99 protocol_base::{ProtocolBase, ProtocolBasePtr},
100 protocol_jobs_manager::{ProtocolJobsManager, ProtocolJobsManagerPtr},
101};
102
103/// Defines the interaction between nodes during a connection.
104///
105/// Consists of an inbound session, which describes how to set up an
106/// incoming connection, and an outbound session, which describes setting
107/// up an outbound connection. Also describes the sesd session, which is
108/// the type of connection used when a node connects to the network for
109/// the first time. Implements the `Session` trait which describes the
110/// common functions across all sessions.
111pub mod session;
112
113/// Handles the acceptance of inbound socket connections.
114/// Used to start listening on a local socket, to accept incoming connections,
115/// and to handle network errors.
116pub mod acceptor;
117
118/// Handles the creation of outbound connections.
119/// Used to establish an outbound connection.
120pub mod connector;
121
122/// Network configuration settings. This holds the configured P2P instance
123/// behaviour and is controlled by clients of this API.
124pub mod settings;
125pub use settings::{BanPolicy, Settings};
126
127/// Optional events based debug-notify subsystem. Off by default. Enabled in P2P instance,
128/// and then call `p2p.dnet_sub()` to start receiving events.
129#[macro_use]
130pub mod dnet;
131
132/// Metering related definitions.
133pub mod metering;