aboutsummaryrefslogtreecommitdiff
path: root/src/netapp.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/netapp.rs
parent96a3cc1e1f5c0c4e73ad1036a7e0add19d9a197e (diff)
downloadnetapp-8858c9428936534ef2b62d73283cd800f4b838d6.tar.gz
netapp-8858c9428936534ef2b62d73283cd800f4b838d6.zip
Implement version tag for application as well
Diffstat (limited to 'src/netapp.rs')
-rw-r--r--src/netapp.rs17
1 files changed, 16 insertions, 1 deletions
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<IpAddr>,
@@ -48,6 +56,8 @@ type OnDisconnectHandler = Box<dyn Fn(NodeID, bool) + Send + Sync>;
pub struct NetApp {
listen_params: ArcSwapOption<ListenParams>,
+ /// 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<Self> {
+ pub fn new(app_version_tag: u64, netid: auth::Key, privkey: ed25519::SecretKey) -> Arc<Self> {
+ 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,