litep2p/protocol/libp2p/kademlia/query/
find_many_nodes.rs

1// Copyright 2023 litep2p developers
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the "Software"),
5// to deal in the Software without restriction, including without limitation
6// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7// and/or sell copies of the Software, and to permit persons to whom the
8// Software is furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19// DEALINGS IN THE SOFTWARE.
20
21use crate::{
22    protocol::libp2p::kademlia::{
23        query::{QueryAction, QueryId},
24        types::KademliaPeer,
25    },
26    PeerId,
27};
28
29/// Context for multiple `FIND_NODE` queries.
30// TODO: implement finding nodes not present in the routing table,
31//       see https://github.com/paritytech/litep2p/issues/80.
32#[derive(Debug)]
33pub struct FindManyNodesContext {
34    /// Query ID.
35    pub query: QueryId,
36
37    /// The peers we are looking for.
38    pub peers_to_report: Vec<KademliaPeer>,
39}
40
41impl FindManyNodesContext {
42    /// Creates a new [`FindManyNodesContext`].
43    pub fn new(query: QueryId, peers_to_report: Vec<KademliaPeer>) -> Self {
44        Self {
45            query,
46            peers_to_report,
47        }
48    }
49
50    /// Register response failure for `peer`.
51    pub fn register_response_failure(&mut self, _peer: PeerId) {}
52
53    /// Register `FIND_NODE` response from `peer`.
54    pub fn register_response(&mut self, _peer: PeerId, _peers: Vec<KademliaPeer>) {}
55
56    /// Get next action for `peer`.
57    pub fn next_peer_action(&mut self, _peer: &PeerId) -> Option<QueryAction> {
58        None
59    }
60
61    /// Get next action for a `FIND_NODE` query.
62    pub fn next_action(&mut self) -> Option<QueryAction> {
63        Some(QueryAction::QuerySucceeded { query: self.query })
64    }
65}