mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 09:11:34 +00:00
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.
This commit is contained in:
@ -222,6 +222,13 @@ where
|
||||
Self::with_config(id, store, Default::default())
|
||||
}
|
||||
|
||||
/// Get the protocol name of this kademlia instance.
|
||||
pub fn protocol_name(&self) -> &[u8] {
|
||||
self.protocol_name_override
|
||||
.as_ref()
|
||||
.map_or(crate::protocol::DEFAULT_PROTO_NAME.as_ref(), AsRef::as_ref)
|
||||
}
|
||||
|
||||
/// Creates a new `Kademlia` network behaviour with the given configuration.
|
||||
pub fn with_config(id: PeerId, store: TStore, config: KademliaConfig) -> Self {
|
||||
let local_key = kbucket::Key::new(id.clone());
|
||||
|
@ -65,6 +65,7 @@ pub use behaviour::{
|
||||
GetProvidersOk,
|
||||
GetProvidersError,
|
||||
};
|
||||
pub use query::QueryId;
|
||||
pub use protocol::KadConnectionType;
|
||||
pub use record::{store, Record, ProviderRecord};
|
||||
|
||||
|
@ -40,6 +40,9 @@ use std::{io, iter};
|
||||
use unsigned_varint::codec;
|
||||
use wasm_timer::Instant;
|
||||
|
||||
/// The protocol name used for negotiating with multistream-select.
|
||||
pub const DEFAULT_PROTO_NAME: &[u8] = b"/ipfs/kad/1.0.0";
|
||||
|
||||
/// Status of our connection to a node reported by the Kademlia protocol.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum KadConnectionType {
|
||||
@ -152,7 +155,7 @@ impl KademliaProtocolConfig {
|
||||
impl Default for KademliaProtocolConfig {
|
||||
fn default() -> Self {
|
||||
KademliaProtocolConfig {
|
||||
protocol_name: Cow::Borrowed(b"/ipfs/kad/1.0.0"),
|
||||
protocol_name: Cow::Borrowed(DEFAULT_PROTO_NAME)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user