mod.rs 5.4 KB

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