Kaynağa Gözat

chore: fix typo in codes

Yujia Qiao 4 yıl önce
ebeveyn
işleme
f1fed7e2cf
4 değiştirilmiş dosya ile 11 ekleme ve 10 silme
  1. 5 5
      src/client.rs
  2. 3 2
      src/helper.rs
  3. 2 2
      src/protocol.rs
  4. 1 1
      src/server.rs

+ 5 - 5
src/client.rs

@@ -4,7 +4,7 @@ use crate::helper::udp_connect;
 use crate::protocol::Hello::{self, *};
 use crate::protocol::{
     self, read_ack, read_control_cmd, read_data_cmd, read_hello, Ack, Auth, ControlChannelCmd,
-    DataChannelCmd, UdpTraffic, CURRENT_PROTO_VRESION, HASH_WIDTH_IN_BYTES,
+    DataChannelCmd, UdpTraffic, CURRENT_PROTO_VERSION, HASH_WIDTH_IN_BYTES,
 };
 use crate::transport::{TcpTransport, Transport};
 use anyhow::{anyhow, bail, Context, Result};
@@ -177,7 +177,7 @@ async fn do_data_channel_handshake<T: Transport>(
 
     // Send nonce
     let v: &[u8; HASH_WIDTH_IN_BYTES] = args.session_key[..].try_into().unwrap();
-    let hello = Hello::DataChannelHello(CURRENT_PROTO_VRESION, v.to_owned());
+    let hello = Hello::DataChannelHello(CURRENT_PROTO_VERSION, v.to_owned());
     conn.write_all(&bincode::serialize(&hello).unwrap()).await?;
 
     Ok(conn)
@@ -209,12 +209,12 @@ async fn run_data_channel_for_tcp<T: Transport>(
 
     let mut local = TcpStream::connect(local_addr)
         .await
-        .with_context(|| "Failed to conenct to local_addr")?;
+        .with_context(|| "Failed to connect to local_addr")?;
     let _ = copy_bidirectional(&mut conn, &mut local).await;
     Ok(())
 }
 
-// Things get a little tricker when it gets to UDP because it's connectionless.
+// Things get a little tricker when it gets to UDP because it's connection-less.
 // A UdpPortMap must be maintained for recent seen incoming address, giving them
 // each a local port, which is associated with a socket. So just the sender
 // to the socket will work fine for the map's value.
@@ -377,7 +377,7 @@ impl<T: 'static + Transport> ControlChannel<T> {
         // Send hello
         debug!("Sending hello");
         let hello_send =
-            Hello::ControlChannelHello(CURRENT_PROTO_VRESION, self.digest[..].try_into().unwrap());
+            Hello::ControlChannelHello(CURRENT_PROTO_VERSION, self.digest[..].try_into().unwrap());
         conn.write_all(&bincode::serialize(&hello_send).unwrap())
             .await?;
 

+ 3 - 2
src/helper.rs

@@ -11,7 +11,7 @@ use tokio::net::{TcpStream, ToSocketAddrs, UdpSocket};
 use tracing::error;
 
 // Tokio hesitates to expose this option...So we have to do it on our own :(
-// The good news is that using socket2 it can be easily done, without losing portablity.
+// The good news is that using socket2 it can be easily done, without losing portability.
 // See https://github.com/tokio-rs/tokio/issues/3082
 pub fn try_set_tcp_keepalive(conn: &TcpStream) -> Result<()> {
     let s = SockRef::from(conn);
@@ -45,6 +45,7 @@ pub async fn udp_connect<A: ToSocketAddrs>(addr: A) -> Result<UdpSocket> {
     Ok(s)
 }
 
+// FIXME: These functions are for the load balance for UDP. But not used for now.
 #[allow(dead_code)]
 pub fn hash_socket_addr(a: &SocketAddr) -> u64 {
     let mut hasher = DefaultHasher::new();
@@ -52,7 +53,7 @@ pub fn hash_socket_addr(a: &SocketAddr) -> u64 {
     hasher.finish()
 }
 
-// Wait for the stablization of https://doc.rust-lang.org/std/primitive.i64.html#method.log2
+// Wait for the stabilization of https://doc.rust-lang.org/std/primitive.i64.html#method.log2
 #[allow(dead_code)]
 fn log2_floor(x: usize) -> u8 {
     (x as f64).log2().floor() as u8

+ 2 - 2
src/protocol.rs

@@ -11,7 +11,7 @@ use tracing::trace;
 type ProtocolVersion = u8;
 const PROTO_V0: u8 = 0u8;
 
-pub const CURRENT_PROTO_VRESION: ProtocolVersion = PROTO_V0;
+pub const CURRENT_PROTO_VERSION: ProtocolVersion = PROTO_V0;
 
 pub type Digest = [u8; HASH_WIDTH_IN_BYTES];
 
@@ -151,7 +151,7 @@ impl PacketLength {
     pub fn new() -> PacketLength {
         let username = "default";
         let d = digest(username.as_bytes());
-        let hello = bincode::serialized_size(&Hello::ControlChannelHello(CURRENT_PROTO_VRESION, d))
+        let hello = bincode::serialized_size(&Hello::ControlChannelHello(CURRENT_PROTO_VERSION, d))
             .unwrap() as usize;
         let c_cmd =
             bincode::serialized_size(&ControlChannelCmd::CreateDataChannel).unwrap() as usize;

+ 1 - 1
src/server.rs

@@ -244,7 +244,7 @@ async fn do_control_channel_handshake<T: 'static + Transport>(
 
     // Send hello
     let hello_send = Hello::ControlChannelHello(
-        protocol::CURRENT_PROTO_VRESION,
+        protocol::CURRENT_PROTO_VERSION,
         nonce.clone().try_into().unwrap(),
     );
     conn.write_all(&bincode::serialize(&hello_send).unwrap())