mod.rs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #[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. /// Port mapping protocols (UPnP, NAT-PMP, PCP)
  54. #[cfg(feature = "upnp-igd")]
  55. pub mod upnp;
  56. /// Hosts are a list of network addresses used when establishing outbound
  57. /// connections.
  58. ///
  59. /// Hosts are shared across the network through the address protocol.
  60. /// When attempting to connect, a node will loop through addresses in the
  61. /// hosts store until it finds ones to connect to.
  62. pub mod hosts;
  63. /// Async channel that handles the sending of messages across the network.
  64. /// Public interface is used to create new channels, to stop and start a
  65. /// channel, and to send messages.
  66. pub mod channel;
  67. pub use channel::ChannelPtr;
  68. /// P2P provides all core functionality to interact with the P2P network.
  69. ///
  70. /// Used to create a network, to start and run it, to broadcast messages
  71. /// across all channels, and to manage the channel store.
  72. ///
  73. /// The channel store is a hashmap of channel addresses that we can use
  74. /// to add and remove channels or check whether a channel is already in
  75. /// the store.
  76. pub mod p2p;
  77. pub use p2p::{P2p, P2pPtr};
  78. /// Defines the networking protocol used at each stage in a connection.
  79. /// Consists of a series of messages that are sent across the network at
  80. /// the different connection stages.
  81. ///
  82. /// When a node connects to a network for the first time, it must follow
  83. /// a seed protocol, which provides it with a list of network hosts to
  84. /// connect to. To establish a connection to another node, nodes must send
  85. /// version and version acknowledgement messages. During a connection, nodes
  86. /// continually get address and get-address messages to inform each other
  87. /// about what nodes are on the network. Nodes also send out a ping and pong
  88. /// message which keeps the network from shutting down.
  89. ///
  90. /// Protocol submodule also implements a jobs manager that handles the
  91. /// asynchronous execution of the protocols.
  92. pub mod protocol;
  93. pub use protocol::{
  94. protocol_base::{ProtocolBase, ProtocolBasePtr},
  95. protocol_jobs_manager::{ProtocolJobsManager, ProtocolJobsManagerPtr},
  96. };
  97. /// Defines the interaction between nodes during a connection.
  98. ///
  99. /// Consists of an inbound session, which describes how to set up an
  100. /// incoming connection, and an outbound session, which describes setting
  101. /// up an outbound connection. Also describes the sesd session, which is
  102. /// the type of connection used when a node connects to the network for
  103. /// the first time. Implements the `Session` trait which describes the
  104. /// common functions across all sessions.
  105. pub mod session;
  106. /// Handles the acceptance of inbound socket connections.
  107. /// Used to start listening on a local socket, to accept incoming connections,
  108. /// and to handle network errors.
  109. pub mod acceptor;
  110. /// Handles the creation of outbound connections.
  111. /// Used to establish an outbound connection.
  112. pub mod connector;
  113. /// Network configuration settings. This holds the configured P2P instance
  114. /// behaviour and is controlled by clients of this API.
  115. pub mod settings;
  116. pub use settings::{BanPolicy, Settings};
  117. /// Optional events based debug-notify subsystem. Off by default. Enabled in P2P instance,
  118. /// and then call `p2p.dnet_sub()` to start receiving events.
  119. #[macro_use]
  120. pub mod dnet;
  121. /// Metering related definitions.
  122. pub mod metering;