Преглед изворни кода

documented protocol version behavior

rachel-rose пре 5 година
родитељ
комит
287e83d802
1 измењених фајлова са 9 додато и 4 уклоњено
  1. 9 4
      src/net/protocols/protocol_version.rs

+ 9 - 4
src/net/protocols/protocol_version.rs

@@ -9,7 +9,7 @@ use crate::net::messages;
 use crate::net::utility::sleep;
 use crate::net::utility::sleep;
 use crate::net::{ChannelPtr, SettingsPtr};
 use crate::net::{ChannelPtr, SettingsPtr};
 
 
-/// Version information sent between nodes at the start of a connection.
+/// Protocol for version information handshake between nodes at the start of a connection.
 pub struct ProtocolVersion {
 pub struct ProtocolVersion {
     channel: ChannelPtr,
     channel: ChannelPtr,
     version_sub: MessageSubscription<messages::VersionMessage>,
     version_sub: MessageSubscription<messages::VersionMessage>,
@@ -18,14 +18,17 @@ pub struct ProtocolVersion {
 }
 }
 
 
 impl ProtocolVersion {
 impl ProtocolVersion {
-    /// Create a new version instance.
+    /// Create a new version protocol. Makes a version and version acknowledgement subscription,
+    /// then adds them to a version protocol instance.
     pub async fn new(channel: ChannelPtr, settings: SettingsPtr) -> Arc<Self> {
     pub async fn new(channel: ChannelPtr, settings: SettingsPtr) -> Arc<Self> {
+        // Creates a version subscription.
         let version_sub = channel
         let version_sub = channel
             .clone()
             .clone()
             .subscribe_msg::<messages::VersionMessage>()
             .subscribe_msg::<messages::VersionMessage>()
             .await
             .await
             .expect("Missing version dispatcher!");
             .expect("Missing version dispatcher!");
 
 
+        // Creates a version acknowledgement subscription.
         let verack_sub = channel
         let verack_sub = channel
             .clone()
             .clone()
             .subscribe_msg::<messages::VerackMessage>()
             .subscribe_msg::<messages::VerackMessage>()
@@ -39,7 +42,8 @@ impl ProtocolVersion {
             settings,
             settings,
         })
         })
     }
     }
-    /// Start version information exchange.
+    /// Start version information exchange. Start the timer. Send version info and wait for version
+    /// acknowledgement. Wait for version info and send version acknowledgement. 
     pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
     pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
         debug!(target: "net", "ProtocolVersion::run() [START]");
         debug!(target: "net", "ProtocolVersion::run() [START]");
         // Start timer
         // Start timer
@@ -76,9 +80,10 @@ impl ProtocolVersion {
         debug!(target: "net", "ProtocolVersion::send_version() [END]");
         debug!(target: "net", "ProtocolVersion::send_version() [END]");
         Ok(())
         Ok(())
     }
     }
-    /// Recieve version info and send version acknowledgement.
+    /// Recieve version info, check the message is okay and send version acknowledgement.
     async fn recv_version(self: Arc<Self>) -> NetResult<()> {
     async fn recv_version(self: Arc<Self>) -> NetResult<()> {
         debug!(target: "net", "ProtocolVersion::recv_version() [START]");
         debug!(target: "net", "ProtocolVersion::recv_version() [START]");
+        // Rec
         let _version_msg = self.version_sub.receive().await?;
         let _version_msg = self.version_sub.receive().await?;
 
 
         // Check the message is OK
         // Check the message is OK