mod.rs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /// Protocol for address and get-address messages. Implements how nodes exchange
  2. /// connection information about other nodes on the network. Address and
  3. /// get-address messages are exchanged continually alongside ping-pong messages
  4. /// as part of a network connection.
  5. ///
  6. /// Protocol starts by creating a subscription to address and get address
  7. /// messages. Then the protocol sends out a get address message and waits for an
  8. /// address message. Upon receiving an address messages, nodes add the
  9. /// address information to their local store.
  10. pub mod protocol_address;
  11. /// Manages the tasks for the network protocol. Used by other connection
  12. /// protocols to handle asynchronous task execution across the network. Runs all
  13. /// tasks that are handed to it on an executor that has stopping functionality.
  14. pub mod protocol_jobs_manager;
  15. /// Protocol for ping-pong keep-alive messages. Implements ping message and pong
  16. /// response. These messages are like the network heartbeat- they are sent
  17. /// continually between nodes, to ensure each node is still alive and active.
  18. /// Ping-pong messages ensure that the network doesn't
  19. /// time out.
  20. ///
  21. /// Protocol starts by creating a subscription to ping and pong messages. Then
  22. /// it starts a loop with a timer and runs ping-pong in the task manager. It
  23. /// sends out a ping and waits for pong reply. Then waits for ping and replies
  24. /// with a pong.
  25. pub mod protocol_ping;
  26. /// Seed server protocol. Seed server is used when connecting to the network for
  27. /// the first time. Returns a list of IP addresses that nodes can connect to.
  28. ///
  29. /// To start the seed protocol, we create a subscription to the address message,
  30. /// and send our address to the seed server. Then we send a get-address message
  31. /// and receive an address message. We add these addresses to our internal
  32. /// store.
  33. pub mod protocol_seed;
  34. /// Protocol for version information handshake between nodes at the start of a
  35. /// connection. Implements the process for exchanging version information
  36. /// between nodes. This is the first step when establishing a p2p connection.
  37. ///
  38. /// The version protocol starts of by instantiating the protocol and creating a
  39. /// new subscription to version and version acknowledgement messages. Then we
  40. /// run the protocol. Nodes send a version message and wait for a version
  41. /// acknowledgement, while asynchronously waiting for version info from the
  42. /// other node and sending the version acknowledgement.
  43. pub mod protocol_version;
  44. pub mod protocol_base;
  45. pub mod protocol_registry;
  46. pub use protocol_address::ProtocolAddress;
  47. pub use protocol_jobs_manager::{ProtocolJobsManager, ProtocolJobsManagerPtr};
  48. pub use protocol_ping::ProtocolPing;
  49. pub use protocol_seed::ProtocolSeed;
  50. pub use protocol_version::ProtocolVersion;
  51. pub use protocol_base::{ProtocolBase, ProtocolBasePtr};
  52. pub use protocol_registry::ProtocolRegistry;
  53. use crate::net::{
  54. session::{SESSION_ALL, SESSION_SEED},
  55. P2pPtr,
  56. };
  57. pub async fn register_default_protocols(p2p: P2pPtr) {
  58. let registry = p2p.protocol_registry();
  59. registry.register(SESSION_ALL, ProtocolPing::new2).await;
  60. registry.register(!SESSION_SEED, ProtocolAddress::new2).await;
  61. registry.register(SESSION_SEED, ProtocolSeed::new2).await;
  62. }