Skip to content
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

Merged
merged 1 commit into from
Feb 14, 2023
Merged

Conversation

gurinderu
Copy link
Contributor

No description provided.

@linear
Copy link

linear bot commented Feb 14, 2023

NET-345 Forbid to use Provider API in rust-libp2p Kademlia

If it's impossible without forking rust-libp2p, then cancel this task

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
Copy link
Member

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? 🤔

Copy link
Contributor Author

@gurinderu gurinderu Feb 14, 2023

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>,
    },
}

@gurinderu gurinderu marked this pull request as ready for review February 14, 2023 13:37
@gurinderu gurinderu enabled auto-merge (squash) February 14, 2023 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants