Skip to content

Commit bd31deb

Browse files
committed
fix kademlia version
1 parent 7ab68fd commit bd31deb

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dkn-compute"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
edition = "2021"
55
license = "Apache-2.0"
66
readme = "README.md"

src/p2p/client.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,14 @@ impl P2PClient {
255255
let addr = info.observed_addr;
256256

257257
// check protocol string
258-
// TODO: take the prefixes from a shared const
259-
let protocol_ok = self.check_version_with_prefix(&info.protocol_version, "dria/");
258+
let protocol_ok =
259+
self.check_version_with_prefix(&info.protocol_version, P2P_IDENTITY_PREFIX!());
260260
if !protocol_ok {
261261
log::warn!(
262-
"Identify: Peer {} has different Identify protocol: (have {}, want {})",
262+
"Identify: Peer {} has different Identify protocol: (have {}, want {}{})",
263263
peer_id,
264264
info.protocol_version,
265+
P2P_IDENTITY_PREFIX!(),
265266
self.version
266267
);
267268
return;
@@ -271,9 +272,10 @@ impl P2PClient {
271272
if let Some(kad_protocol) = info
272273
.protocols
273274
.iter()
274-
.find(|p| p.to_string().starts_with("/dria/kad/"))
275+
.find(|p| p.to_string().starts_with(P2P_KADEMLIA_PREFIX!()))
275276
{
276-
let protocol_ok = self.check_version_with_prefix(kad_protocol.as_ref(), "/dria/kad/");
277+
let protocol_ok =
278+
self.check_version_with_prefix(kad_protocol.as_ref(), P2P_KADEMLIA_PREFIX!());
277279

278280
// if it matches our protocol, add it to the Kademlia routing table
279281
if protocol_ok {
@@ -290,9 +292,10 @@ impl P2PClient {
290292
.add_address(&peer_id, addr);
291293
} else {
292294
log::warn!(
293-
"Identify: Peer {} has different Kademlia version: (have {}, want {})",
295+
"Identify: Peer {} has different Kademlia version: (have {}, want {}{})",
294296
peer_id,
295297
kad_protocol,
298+
P2P_KADEMLIA_PREFIX!(),
296299
self.version
297300
);
298301
}

src/p2p/mod.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
use libp2p::StreamProtocol;
22

3+
/// Kademlia protocol prefix, as a macro so that it can be used in const macros.
4+
macro_rules! P2P_KADEMLIA_PREFIX {
5+
() => {
6+
"/dria/kad/"
7+
};
8+
}
9+
10+
/// Kademlia protocol prefix, as a macro so that it can be used in const macros.
11+
macro_rules! P2P_IDENTITY_PREFIX {
12+
() => {
13+
"dria/"
14+
};
15+
}
16+
317
/// Kademlia protocol version, in the form of `/dria/kad/<version>`.
418
/// Notice the `/` at the start.
5-
pub(crate) const P2P_KADEMLIA_PROTOCOL: StreamProtocol =
6-
StreamProtocol::new(concat!("/dria/kad/", env!("CARGO_PKG_VERSION")));
19+
pub(crate) const P2P_KADEMLIA_PROTOCOL: StreamProtocol = StreamProtocol::new(concat!(
20+
P2P_KADEMLIA_PREFIX!(),
21+
env!("CARGO_PKG_VERSION_MAJOR"),
22+
".",
23+
env!("CARGO_PKG_VERSION_MINOR")
24+
));
725

826
/// Protocol string, checked by Identify protocol
9-
pub(crate) const P2P_PROTOCOL_STRING: &str = concat!("dria/", env!("CARGO_PKG_VERSION"));
27+
pub(crate) const P2P_PROTOCOL_STRING: &str = concat!(
28+
P2P_IDENTITY_PREFIX!(),
29+
env!("CARGO_PKG_VERSION_MAJOR"),
30+
".",
31+
env!("CARGO_PKG_VERSION_MINOR")
32+
);
1033

1134
mod behaviour;
1235
pub use behaviour::{DriaBehaviour, DriaBehaviourEvent};

0 commit comments

Comments
 (0)