diff options
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/server.rs b/src/server.rs index 31f6ad6..5465307 100644 --- a/src/server.rs +++ b/src/server.rs @@ -20,7 +20,7 @@ use tokio::select; use tokio::sync::{mpsc, watch}; use tokio_util::compat::*; -use futures::io::AsyncReadExt; +use futures::io::{AsyncReadExt, AsyncWriteExt}; use async_trait::async_trait; @@ -67,6 +67,7 @@ impl ServerConn { let remote_addr = socket.peer_addr()?; let mut socket = socket.compat(); + // Do handshake to authenticate client let handshake = handshake_server( &mut socket, netapp.netid.clone(), @@ -82,11 +83,17 @@ impl ServerConn { remote_addr ); + // Create BoxStream layer that encodes content let (read, write) = socket.split(); - - let (read, write) = + let (read, mut write) = BoxStream::from_handshake(read, write, handshake, 0x8000).split_read_write(); + // Before doing anything, send version tag, so that client + // can check and disconnect if version is wrong + write.write_all(&netapp.version_tag[..]).await?; + write.flush().await?; + + // Build and launch stuff that handles requests server-side let (resp_send, resp_recv) = mpsc::unbounded_channel(); let conn = Arc::new(ServerConn { |