Skip to content

Commit 2ea459d

Browse files
authored
kad: Export QueryId and add Kademlia::protocol_name. (#1469)
The `QueryId` type should be exported as it is used in the `NetworkBehaviour::ProtocolsHandler` type of `Kademlia`. `Kademlia::protocol_name` is added for convenience.
1 parent 688aa5b commit 2ea459d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

protocols/kad/src/behaviour.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ where
222222
Self::with_config(id, store, Default::default())
223223
}
224224

225+
/// Get the protocol name of this kademlia instance.
226+
pub fn protocol_name(&self) -> &[u8] {
227+
self.protocol_name_override
228+
.as_ref()
229+
.map_or(crate::protocol::DEFAULT_PROTO_NAME.as_ref(), AsRef::as_ref)
230+
}
231+
225232
/// Creates a new `Kademlia` network behaviour with the given configuration.
226233
pub fn with_config(id: PeerId, store: TStore, config: KademliaConfig) -> Self {
227234
let local_key = kbucket::Key::new(id.clone());

protocols/kad/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub use behaviour::{
6565
GetProvidersOk,
6666
GetProvidersError,
6767
};
68+
pub use query::QueryId;
6869
pub use protocol::KadConnectionType;
6970
pub use record::{store, Record, ProviderRecord};
7071

protocols/kad/src/protocol.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ use std::{io, iter};
4040
use unsigned_varint::codec;
4141
use wasm_timer::Instant;
4242

43+
/// The protocol name used for negotiating with multistream-select.
44+
pub const DEFAULT_PROTO_NAME: &[u8] = b"/ipfs/kad/1.0.0";
45+
4346
/// Status of our connection to a node reported by the Kademlia protocol.
4447
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
4548
pub enum KadConnectionType {
@@ -152,7 +155,7 @@ impl KademliaProtocolConfig {
152155
impl Default for KademliaProtocolConfig {
153156
fn default() -> Self {
154157
KademliaProtocolConfig {
155-
protocol_name: Cow::Borrowed(b"/ipfs/kad/1.0.0"),
158+
protocol_name: Cow::Borrowed(DEFAULT_PROTO_NAME)
156159
}
157160
}
158161
}

0 commit comments

Comments
 (0)