Skip to content

Commit

Permalink
feat(kademlia): Forbid to use Provider API (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurinderu authored Feb 14, 2023
1 parent e45655b commit 2eb068f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/kademlia/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use libp2p::core::connection::ConnectionId;
use libp2p::core::transport::ListenerId;
use libp2p::core::ConnectedPoint;
use libp2p::kad::kbucket::Key;
use libp2p::kad::KademliaStoreInserts;
use libp2p::swarm::behaviour::{
ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredExternalAddr, ExpiredListenAddr,
FromSwarm, ListenFailure, ListenerClosed, ListenerError, NewExternalAddr, NewListenAddr,
Expand Down Expand Up @@ -130,7 +131,13 @@ impl Kademlia {
let timer = Delay::new(config.query_timeout);

let store = MemoryStore::new(config.peer_id);
let kademlia = kad::Kademlia::with_config(config.peer_id, store, config.as_libp2p());
let mut kad_config = config.as_libp2p();
// By default, all records from peers are automatically stored.
// `FilterBoth` means it's the Kademlia behaviour handler's responsibility
// to determine whether or not Provider records and KV records ("both") get stored,
// where we implement logic to validate/prune incoming records.
kad_config.set_record_filtering(KademliaStoreInserts::FilterBoth);
let kademlia = kad::Kademlia::with_config(config.peer_id, store, kad_config);

let (outlet, commands) = mpsc::unbounded();
let api = KademliaApi { outlet };
Expand Down

0 comments on commit 2eb068f

Please sign in to comment.