diff --git a/Cargo.lock b/Cargo.lock index 300395f..771a814 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1035,7 +1035,7 @@ dependencies = [ [[package]] name = "dkn-compute" -version = "0.1.7" +version = "0.1.8" dependencies = [ "async-trait", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 5a22708..fe5ec59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dkn-compute" -version = "0.1.7" +version = "0.1.8" edition = "2021" license = "Apache-2.0" readme = "README.md" diff --git a/src/p2p/client.rs b/src/p2p/client.rs index e270d90..ff29a4c 100644 --- a/src/p2p/client.rs +++ b/src/p2p/client.rs @@ -255,13 +255,14 @@ impl P2PClient { let addr = info.observed_addr; // check protocol string - // TODO: take the prefixes from a shared const - let protocol_ok = self.check_version_with_prefix(&info.protocol_version, "dria/"); + let protocol_ok = + self.check_version_with_prefix(&info.protocol_version, P2P_IDENTITY_PREFIX!()); if !protocol_ok { log::warn!( - "Identify: Peer {} has different Identify protocol: (have {}, want {})", + "Identify: Peer {} has different Identify protocol: (have {}, want {}{})", peer_id, info.protocol_version, + P2P_IDENTITY_PREFIX!(), self.version ); return; @@ -271,9 +272,10 @@ impl P2PClient { if let Some(kad_protocol) = info .protocols .iter() - .find(|p| p.to_string().starts_with("/dria/kad/")) + .find(|p| p.to_string().starts_with(P2P_KADEMLIA_PREFIX!())) { - let protocol_ok = self.check_version_with_prefix(kad_protocol.as_ref(), "/dria/kad/"); + let protocol_ok = + self.check_version_with_prefix(kad_protocol.as_ref(), P2P_KADEMLIA_PREFIX!()); // if it matches our protocol, add it to the Kademlia routing table if protocol_ok { @@ -290,9 +292,10 @@ impl P2PClient { .add_address(&peer_id, addr); } else { log::warn!( - "Identify: Peer {} has different Kademlia version: (have {}, want {})", + "Identify: Peer {} has different Kademlia version: (have {}, want {}{})", peer_id, kad_protocol, + P2P_KADEMLIA_PREFIX!(), self.version ); } diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 3ed3740..023f770 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1,12 +1,35 @@ use libp2p::StreamProtocol; +/// Kademlia protocol prefix, as a macro so that it can be used in const macros. +macro_rules! P2P_KADEMLIA_PREFIX { + () => { + "/dria/kad/" + }; +} + +/// Kademlia protocol prefix, as a macro so that it can be used in const macros. +macro_rules! P2P_IDENTITY_PREFIX { + () => { + "dria/" + }; +} + /// Kademlia protocol version, in the form of `/dria/kad/`. /// Notice the `/` at the start. -pub(crate) const P2P_KADEMLIA_PROTOCOL: StreamProtocol = - StreamProtocol::new(concat!("/dria/kad/", env!("CARGO_PKG_VERSION"))); +pub(crate) const P2P_KADEMLIA_PROTOCOL: StreamProtocol = StreamProtocol::new(concat!( + P2P_KADEMLIA_PREFIX!(), + env!("CARGO_PKG_VERSION_MAJOR"), + ".", + env!("CARGO_PKG_VERSION_MINOR") +)); /// Protocol string, checked by Identify protocol -pub(crate) const P2P_PROTOCOL_STRING: &str = concat!("dria/", env!("CARGO_PKG_VERSION")); +pub(crate) const P2P_PROTOCOL_STRING: &str = concat!( + P2P_IDENTITY_PREFIX!(), + env!("CARGO_PKG_VERSION_MAJOR"), + ".", + env!("CARGO_PKG_VERSION_MINOR") +); mod behaviour; pub use behaviour::{DriaBehaviour, DriaBehaviourEvent};