aboutsummaryrefslogtreecommitdiff
path: root/src/server.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-02-21 16:43:17 +0100
committerAlex Auvolat <alex@adnab.me>2022-02-21 16:43:17 +0100
commit8858c9428936534ef2b62d73283cd800f4b838d6 (patch)
treee3569aaabad79f14093b1e140c88770676840dea /src/server.rs
parent96a3cc1e1f5c0c4e73ad1036a7e0add19d9a197e (diff)
downloadnetapp-8858c9428936534ef2b62d73283cd800f4b838d6.tar.gz
netapp-8858c9428936534ef2b62d73283cd800f4b838d6.zip
Implement version tag for application as well
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs13
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 {