From 8858c9428936534ef2b62d73283cd800f4b838d6 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 21 Feb 2022 16:43:17 +0100 Subject: Implement version tag for application as well --- src/netapp.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/netapp.rs') diff --git a/src/netapp.rs b/src/netapp.rs index acaed62..1ac5f37 100644 --- a/src/netapp.rs +++ b/src/netapp.rs @@ -24,6 +24,14 @@ use crate::proto::*; use crate::server::*; use crate::util::*; +/// Tag which is exchanged between client and server upon connection establishment +/// to check that they are running compatible versions of Netapp, +/// composed of 8 bytes for Netapp version and 8 bytes for client version +pub(crate) type VersionTag = [u8; 16]; + +/// Value of the Netapp version used in the version tag +pub(crate) const NETAPP_VERSION_TAG: u64 = 0x6e65746170700004; // netapp 0x0004 + #[derive(Serialize, Deserialize, Debug)] pub(crate) struct HelloMessage { pub server_addr: Option, @@ -48,6 +56,8 @@ type OnDisconnectHandler = Box; pub struct NetApp { listen_params: ArcSwapOption, + /// Version tag, 8 bytes for netapp version, 8 bytes for app version + pub version_tag: VersionTag, /// Network secret key pub netid: auth::Key, /// Our peer ID @@ -76,10 +86,15 @@ impl NetApp { /// using `.listen()` /// /// Our Peer ID is the public key associated to the secret key given here. - pub fn new(netid: auth::Key, privkey: ed25519::SecretKey) -> Arc { + pub fn new(app_version_tag: u64, netid: auth::Key, privkey: ed25519::SecretKey) -> Arc { + let mut version_tag = [0u8; 16]; + version_tag[0..8].copy_from_slice(&u64::to_be_bytes(NETAPP_VERSION_TAG)[..]); + version_tag[8..16].copy_from_slice(&u64::to_be_bytes(app_version_tag)[..]); + let id = privkey.public_key(); let netapp = Arc::new(Self { listen_params: ArcSwapOption::new(None), + version_tag, netid, id, privkey, -- cgit v1.2.3