refactor checkpoint
This commit is contained in:
@@ -10,16 +10,24 @@ pub type FilterType = Box<dyn Fn(&(&DHTKey, Option<&mut BucketEntry>)) -> bool>;
|
||||
impl RoutingTable {
|
||||
// Retrieve the fastest nodes in the routing table with a particular kind of protocol and address type
|
||||
// Returns noderefs are are scoped to that address type only
|
||||
pub fn find_fast_nodes_filtered(&self, dial_info_filter: &DialInfoFilter) -> Vec<NodeRef> {
|
||||
pub fn find_fast_public_nodes_filtered(
|
||||
&self,
|
||||
dial_info_filter: &DialInfoFilter,
|
||||
) -> Vec<NodeRef> {
|
||||
let dial_info_filter1 = dial_info_filter.clone();
|
||||
self.find_fastest_nodes(
|
||||
// filter
|
||||
Some(Box::new(
|
||||
move |params: &(&DHTKey, Option<&mut BucketEntry>)| {
|
||||
params
|
||||
.1
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
let entry = params.1.as_ref().unwrap();
|
||||
|
||||
// skip nodes on our local network here
|
||||
if entry.local_node_info().has_dial_info() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// does it have matching public dial info?
|
||||
entry
|
||||
.node_info()
|
||||
.first_filtered_dial_info(|di| di.matches_filter(&dial_info_filter1))
|
||||
.is_some()
|
||||
@@ -30,6 +38,7 @@ impl RoutingTable {
|
||||
)
|
||||
}
|
||||
|
||||
// Get our own node's peer info (public node info) so we can share it with other nodes
|
||||
pub fn get_own_peer_info(&self) -> PeerInfo {
|
||||
let netman = self.network_manager();
|
||||
let enable_local_peer_scope = netman.config().get().network.enable_local_peer_scope;
|
||||
|
@@ -243,10 +243,20 @@ impl RoutingTable {
|
||||
) {
|
||||
let timestamp = get_timestamp();
|
||||
let enable_local_peer_scope = {
|
||||
let c = self.network_manager().config().get();
|
||||
let config = self.network_manager().config();
|
||||
let c = config.get();
|
||||
c.network.enable_local_peer_scope
|
||||
};
|
||||
|
||||
if !enable_local_peer_scope && dial_info.is_local() {
|
||||
error!("shouldn't be registering local addresses as public");
|
||||
return;
|
||||
}
|
||||
if !dial_info.is_valid() {
|
||||
error!("shouldn't be registering invalid addresses");
|
||||
return;
|
||||
}
|
||||
|
||||
let mut inner = self.inner.lock();
|
||||
|
||||
inner.public_dial_info_details.push(DialInfoDetail {
|
||||
@@ -276,12 +286,12 @@ impl RoutingTable {
|
||||
}
|
||||
|
||||
pub fn register_interface_dial_info(&self, dial_info: DialInfo, origin: DialInfoOrigin) {
|
||||
let timestamp = get_timestamp();
|
||||
let enable_local_peer_scope = {
|
||||
let c = self.network_manager().config().get();
|
||||
c.network.enable_local_peer_scope
|
||||
};
|
||||
if !dial_info.is_valid() {
|
||||
error!("shouldn't be registering invalid interface addresses");
|
||||
return;
|
||||
}
|
||||
|
||||
let timestamp = get_timestamp();
|
||||
let mut inner = self.inner.lock();
|
||||
|
||||
inner.interface_dial_info_details.push(DialInfoDetail {
|
||||
|
@@ -45,6 +45,9 @@ impl NodeRef {
|
||||
pub fn last_connection(&self) -> Option<ConnectionDescriptor> {
|
||||
self.operate(|e| e.last_connection())
|
||||
}
|
||||
pub fn has_any_dial_info(&self) -> bool {
|
||||
self.operate(|e| e.node_info().has_any_dial_info() || e.local_node_info().has_dial_info())
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for NodeRef {
|
||||
@@ -59,6 +62,14 @@ impl Clone for NodeRef {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for NodeRef {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.node_id == other.node_id
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for NodeRef {}
|
||||
|
||||
impl fmt::Debug for NodeRef {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.node_id.encode())
|
||||
|
Reference in New Issue
Block a user