mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
refactor(kad): rename to follow naming convention across repository
Renamed the following `kad::Kademlia` -> `kad::Behaviour` `kad::KademliaEvent` -> `kad::Event` `kad::KademliaBucketInserts` -> `kad::BucketInserts` `kad::KademliaStoreInserts` -> `kad::StoreInserts` `kad::KademliaConfig` -> `kad::Config` `kad::KademliaCaching` -> `kad::Caching` `kad::KademliaEvent` -> `kad::Event` `kad::KademliaConnectionType` -> `kad::ConnectionType` `KademliaHandler` -> `Handler` `KademliaHandlerEvent` -> `HandlerEvent` `KademliaProtocolConfig` -> `ProtocolConfig` `KademliaHandlerIn` -> `HandlerIn` `KademliaRequestId` -> `RequestId` `KademliaHandlerQueryErr` -> `HandlerQueryErr` Resolves: #4485 Pull-Request: #4547.
This commit is contained in:
committed by
GitHub
parent
fffd47b69f
commit
c8b5f49ec2
@ -21,8 +21,8 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
|
||||
use futures::StreamExt;
|
||||
use libp2p::kad;
|
||||
use libp2p::kad::record::store::MemoryStore;
|
||||
use libp2p::kad::{GetClosestPeersError, Kademlia, KademliaConfig, KademliaEvent, QueryResult};
|
||||
use libp2p::{
|
||||
development_transport, identity,
|
||||
swarm::{SwarmBuilder, SwarmEvent},
|
||||
@ -51,10 +51,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Create a swarm to manage peers and events.
|
||||
let mut swarm = {
|
||||
// Create a Kademlia behaviour.
|
||||
let mut cfg = KademliaConfig::default();
|
||||
let mut cfg = kad::Config::default();
|
||||
cfg.set_query_timeout(Duration::from_secs(5 * 60));
|
||||
let store = MemoryStore::new(local_peer_id);
|
||||
let mut behaviour = Kademlia::with_config(local_peer_id, store, cfg);
|
||||
let mut behaviour = kad::Behaviour::with_config(local_peer_id, store, cfg);
|
||||
|
||||
// Add the bootnodes to the local routing table. `libp2p-dns` built
|
||||
// into the `transport` resolves the `dnsaddr` when Kademlia tries
|
||||
@ -78,8 +78,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
loop {
|
||||
let event = swarm.select_next_some().await;
|
||||
if let SwarmEvent::Behaviour(KademliaEvent::OutboundQueryProgressed {
|
||||
result: QueryResult::GetClosestPeers(result),
|
||||
if let SwarmEvent::Behaviour(kad::Event::OutboundQueryProgressed {
|
||||
result: kad::QueryResult::GetClosestPeers(result),
|
||||
..
|
||||
}) = event
|
||||
{
|
||||
@ -93,7 +93,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
println!("Query finished with no closest peers.")
|
||||
}
|
||||
}
|
||||
Err(GetClosestPeersError::Timeout { peers, .. }) => {
|
||||
Err(kad::GetClosestPeersError::Timeout { peers, .. }) => {
|
||||
if !peers.is_empty() {
|
||||
println!("Query timed out with closest peers: {peers:#?}")
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user