-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kademlia): Forbid to use Provider API #1466
Conversation
NET-345 Forbid to use Provider API in rust-libp2p Kademlia
If it's impossible without forking rust-libp2p, then cancel this task |
c0c840d
to
ceffafc
Compare
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you determine this then? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have defined a correct poll method here.
loop {
match self.kademlia.poll(cx, params) {
Pending => return Pending,
Ready(GenerateEvent(e)) => self.inject_kad_event(e),
Ready(Dial { opts, handler }) => return Ready(Dial { opts, handler }),
Ready(NotifyHandler { peer_id, handler, event }) => return Ready(NotifyHandler { peer_id, handler, event }),
Ready(ReportObservedAddr { address, score }) => return Ready(ReportObservedAddr { address, score }),
Ready(CloseConnection { peer_id, connection }) => return Ready(CloseConnection { peer_id, connection })
}
}
We are interested in GenerateEvent type and inject_kad_event doesn't have any logic for the InboundRequest
match event {
KademliaEvent::OutboundQueryProgressed { id, result, .. } => match result {
QueryResult::GetClosestPeers(result) => self.closest_finished(id, result),
QueryResult::Bootstrap(result) => self.bootstrap_finished(id, result),
_ => {}
},
KademliaEvent::UnroutablePeer { .. } => {}
KademliaEvent::RoutingUpdated {
peer, addresses, ..
} => self.peer_discovered(peer, addresses.into_vec()),
KademliaEvent::RoutablePeer { peer, address }
| KademliaEvent::PendingRoutablePeer { peer, address } => {
self.peer_discovered(peer, vec![address])
}
KademliaEvent::InboundRequest { .. } => {}
}
InboundRequest is an enum we are interested in
/// Information about a received and handled inbound request.
#[derive(Debug, Clone)]
pub enum InboundRequest {
/// Request for the list of nodes whose IDs are the closest to `key`.
FindNode { num_closer_peers: usize },
/// Same as `FindNode`, but should also return the entries of the local
/// providers list for this key.
GetProvider {
num_closer_peers: usize,
num_provider_peers: usize,
},
/// A peer sent a [`KademliaHandlerIn::AddProvider`] request.
/// If filtering [`KademliaStoreInserts::FilterBoth`] is enabled, the [`ProviderRecord`] is
/// included.
///
/// See [`KademliaStoreInserts`] and [`KademliaConfig::set_record_filtering`] for details..
AddProvider { record: Option<ProviderRecord> },
/// Request to retrieve a record.
GetRecord {
num_closer_peers: usize,
present_locally: bool,
},
/// A peer sent a [`KademliaHandlerIn::PutRecord`] request.
/// If filtering [`KademliaStoreInserts::FilterBoth`] is enabled, the [`Record`] is included.
///
/// See [`KademliaStoreInserts`] and [`KademliaConfig::set_record_filtering`].
PutRecord {
source: PeerId,
connection: ConnectionId,
record: Option<Record>,
},
}
ceffafc
to
86cb789
Compare
No description provided.