mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-30 21:22:16 +00:00
Add public key to buckets WIP
This commit is contained in:
parent
783ff2575e
commit
619ed94e64
@ -23,7 +23,7 @@ use smallvec::SmallVec;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// A non-empty list of (unique) addresses of a peer in the routing table.
|
/// A non-empty list of (unique) addresses of a peer in the routing table.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct Addresses {
|
pub struct Addresses {
|
||||||
addrs: SmallVec<[Multiaddr; 6]>,
|
addrs: SmallVec<[Multiaddr; 6]>,
|
||||||
}
|
}
|
||||||
|
@ -620,8 +620,9 @@ where
|
|||||||
let key = kbucket::Key::new(peer.clone());
|
let key = kbucket::Key::new(peer.clone());
|
||||||
match self.kbuckets.entry(&key) {
|
match self.kbuckets.entry(&key) {
|
||||||
kbucket::Entry::Present(mut entry, old_status) => {
|
kbucket::Entry::Present(mut entry, old_status) => {
|
||||||
if let Some(address) = address {
|
if let Some(contact) = contact {
|
||||||
if entry.value().insert(address) {
|
if *entry.value() != contact { // TODO: what about public key change?
|
||||||
|
*entry.value() = contact; // TODO: is there a better way to do that?
|
||||||
self.queued_events.push_back(NetworkBehaviourAction::GenerateEvent(
|
self.queued_events.push_back(NetworkBehaviourAction::GenerateEvent(
|
||||||
KademliaEvent::RoutingUpdated {
|
KademliaEvent::RoutingUpdated {
|
||||||
peer,
|
peer,
|
||||||
@ -637,8 +638,8 @@ where
|
|||||||
},
|
},
|
||||||
|
|
||||||
kbucket::Entry::Pending(mut entry, old_status) => {
|
kbucket::Entry::Pending(mut entry, old_status) => {
|
||||||
if let Some(address) = address {
|
if let Some(contact) = contact {
|
||||||
entry.value().insert(address);
|
*entry.value() = contact;
|
||||||
}
|
}
|
||||||
if old_status != new_status {
|
if old_status != new_status {
|
||||||
entry.update(new_status);
|
entry.update(new_status);
|
||||||
@ -649,11 +650,11 @@ where
|
|||||||
// Only connected nodes with a known address are newly inserted.
|
// Only connected nodes with a known address are newly inserted.
|
||||||
if new_status == NodeStatus::Connected {
|
if new_status == NodeStatus::Connected {
|
||||||
if let Some(contact) = contact {
|
if let Some(contact) = contact {
|
||||||
match entry.insert(contact, new_status) {
|
match entry.insert(contact.clone(), new_status) {
|
||||||
kbucket::InsertResult::Inserted => {
|
kbucket::InsertResult::Inserted => {
|
||||||
let event = KademliaEvent::RoutingUpdated {
|
let event = KademliaEvent::RoutingUpdated {
|
||||||
peer: peer.clone(),
|
peer: peer.clone(),
|
||||||
addresses: contact.addresses.clone(),
|
addresses: contact.addresses,
|
||||||
old_peer: None,
|
old_peer: None,
|
||||||
};
|
};
|
||||||
self.queued_events.push_back(
|
self.queued_events.push_back(
|
||||||
@ -1103,15 +1104,17 @@ where
|
|||||||
ConnectedPoint::Listener { .. } => None,
|
ConnectedPoint::Listener { .. } => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let contact = self.queries.iter().find_map(|q| q.inner.contacts.get(&peer));
|
let contact = self.queries
|
||||||
let contact = match (address, public_key) {
|
.iter()
|
||||||
(Some(addr), Some(pk)) => Contact::new(Addresses::new(addr), pk.clone()),
|
.find_map(|q| q.inner.contacts.get(&peer)) // Option<&Contact>
|
||||||
_ => None
|
.as_mut() // &mut Option<&Contact>
|
||||||
};
|
.and_then(|c|
|
||||||
|
new_address.map(|addr| { c.insert(addr); c }) // insert(&mut self)
|
||||||
|
)
|
||||||
|
.cloned(); // Option<&Contact>
|
||||||
|
|
||||||
|
// Need Option<Contact> here
|
||||||
|
self.connection_updated(peer.clone(), contact, NodeStatus::Connected);
|
||||||
self.connection_updated(peer.clone(), address, NodeStatus::Connected);
|
|
||||||
self.connected_peers.insert(peer);
|
self.connected_peers.insert(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ use libp2p_core::identity::ed25519::PublicKey;
|
|||||||
use crate::protocol::KadPeer;
|
use crate::protocol::KadPeer;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct Contact {
|
pub struct Contact {
|
||||||
pub addresses: Addresses,
|
pub addresses: Addresses,
|
||||||
pub public_key: PublicKey
|
pub public_key: PublicKey
|
||||||
|
Loading…
x
Reference in New Issue
Block a user