mod.rs 5.4 KB

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