close #169
This commit is contained in:
@@ -275,6 +275,30 @@ impl BucketEntryInner {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn exists_in_routing_domain(
|
||||
&self,
|
||||
rti: &RoutingTableInner,
|
||||
routing_domain: RoutingDomain,
|
||||
) -> bool {
|
||||
// Check node info
|
||||
if self.has_node_info(routing_domain.into()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check connections
|
||||
let connection_manager = rti.network_manager().connection_manager();
|
||||
let last_connections = self.last_connections(
|
||||
rti,
|
||||
Some(NodeRefFilter::new().with_routing_domain(routing_domain)),
|
||||
);
|
||||
for lc in last_connections {
|
||||
if connection_manager.get_connection(lc.0).is_some() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn node_info(&self, routing_domain: RoutingDomain) -> Option<&NodeInfo> {
|
||||
let opt_current_sni = match routing_domain {
|
||||
RoutingDomain::LocalNetwork => &self.local_network.signed_node_info,
|
||||
@@ -304,8 +328,10 @@ impl BucketEntryInner {
|
||||
|
||||
pub fn best_routing_domain(
|
||||
&self,
|
||||
rti: &RoutingTableInner,
|
||||
routing_domain_set: RoutingDomainSet,
|
||||
) -> Option<RoutingDomain> {
|
||||
// Check node info
|
||||
for routing_domain in routing_domain_set {
|
||||
let opt_current_sni = match routing_domain {
|
||||
RoutingDomain::LocalNetwork => &self.local_network.signed_node_info,
|
||||
@@ -315,7 +341,27 @@ impl BucketEntryInner {
|
||||
return Some(routing_domain);
|
||||
}
|
||||
}
|
||||
None
|
||||
// Check connections
|
||||
let mut best_routing_domain: Option<RoutingDomain> = None;
|
||||
let connection_manager = rti.network_manager().connection_manager();
|
||||
let last_connections = self.last_connections(
|
||||
rti,
|
||||
Some(NodeRefFilter::new().with_routing_domain_set(routing_domain_set)),
|
||||
);
|
||||
for lc in last_connections {
|
||||
if connection_manager.get_connection(lc.0).is_some() {
|
||||
if let Some(rd) = rti.routing_domain_for_address(lc.0.remote_address().address()) {
|
||||
if let Some(brd) = best_routing_domain {
|
||||
if rd < brd {
|
||||
best_routing_domain = Some(rd);
|
||||
}
|
||||
} else {
|
||||
best_routing_domain = Some(rd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
best_routing_domain
|
||||
}
|
||||
|
||||
fn descriptor_to_key(&self, last_connection: ConnectionDescriptor) -> LastConnectionKey {
|
||||
|
||||
@@ -457,17 +457,6 @@ impl RoutingTable {
|
||||
.get_entry_count(routing_domain_set, min_state)
|
||||
}
|
||||
|
||||
pub fn get_nodes_needing_updates(
|
||||
&self,
|
||||
routing_domain: RoutingDomain,
|
||||
cur_ts: u64,
|
||||
all: bool,
|
||||
) -> Vec<NodeRef> {
|
||||
self.inner
|
||||
.read()
|
||||
.get_nodes_needing_updates(self.clone(), routing_domain, cur_ts, all)
|
||||
}
|
||||
|
||||
pub fn get_nodes_needing_ping(
|
||||
&self,
|
||||
routing_domain: RoutingDomain,
|
||||
|
||||
@@ -87,8 +87,9 @@ pub trait NodeRefBase: Sized {
|
||||
}
|
||||
|
||||
fn best_routing_domain(&self) -> Option<RoutingDomain> {
|
||||
self.operate(|_rti, e| {
|
||||
self.operate(|rti, e| {
|
||||
e.best_routing_domain(
|
||||
rti,
|
||||
self.common()
|
||||
.filter
|
||||
.as_ref()
|
||||
|
||||
@@ -23,7 +23,6 @@ pub struct RoutingDomainEditor {
|
||||
routing_table: RoutingTable,
|
||||
routing_domain: RoutingDomain,
|
||||
changes: Vec<RoutingDomainChange>,
|
||||
send_node_info_updates: bool,
|
||||
}
|
||||
|
||||
impl RoutingDomainEditor {
|
||||
@@ -32,13 +31,8 @@ impl RoutingDomainEditor {
|
||||
routing_table,
|
||||
routing_domain,
|
||||
changes: Vec::new(),
|
||||
send_node_info_updates: true,
|
||||
}
|
||||
}
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub fn disable_node_info_updates(&mut self) {
|
||||
self.send_node_info_updates = false;
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub fn clear_dial_info_details(&mut self) {
|
||||
@@ -199,7 +193,7 @@ impl RoutingDomainEditor {
|
||||
}
|
||||
});
|
||||
if changed {
|
||||
// Allow signed node info updates at same timestamp from dead nodes if our network has changed
|
||||
// Allow signed node info updates at same timestamp for otherwise dead nodes if our network has changed
|
||||
inner.reset_all_updated_since_last_network_change();
|
||||
}
|
||||
}
|
||||
@@ -210,12 +204,5 @@ impl RoutingDomainEditor {
|
||||
rss.reset();
|
||||
}
|
||||
}
|
||||
// Send our updated node info to all the nodes in the routing table
|
||||
if changed && self.send_node_info_updates {
|
||||
let network_manager = self.routing_table.unlocked_inner.network_manager.clone();
|
||||
network_manager
|
||||
.send_node_info_updates(self.routing_domain, true)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ impl RoutingTableInner {
|
||||
let mut count = 0usize;
|
||||
let cur_ts = get_timestamp();
|
||||
self.with_entries(cur_ts, min_state, |rti, _, e| {
|
||||
if e.with(rti, |_rti, e| e.best_routing_domain(routing_domain_set))
|
||||
if e.with(rti, |rti, e| e.best_routing_domain(rti, routing_domain_set))
|
||||
.is_some()
|
||||
{
|
||||
count += 1;
|
||||
@@ -487,29 +487,6 @@ impl RoutingTableInner {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_nodes_needing_updates(
|
||||
&self,
|
||||
outer_self: RoutingTable,
|
||||
routing_domain: RoutingDomain,
|
||||
cur_ts: u64,
|
||||
all: bool,
|
||||
) -> Vec<NodeRef> {
|
||||
let mut node_refs = Vec::<NodeRef>::with_capacity(self.bucket_entry_count);
|
||||
self.with_entries(cur_ts, BucketEntryState::Unreliable, |rti, k, v| {
|
||||
// Only update nodes that haven't seen our node info yet
|
||||
if all || !v.with(rti, |_rti, e| e.has_seen_our_node_info(routing_domain)) {
|
||||
node_refs.push(NodeRef::new(
|
||||
outer_self.clone(),
|
||||
k,
|
||||
v,
|
||||
Some(NodeRefFilter::new().with_routing_domain(routing_domain)),
|
||||
));
|
||||
}
|
||||
Option::<()>::None
|
||||
});
|
||||
node_refs
|
||||
}
|
||||
|
||||
pub fn get_nodes_needing_ping(
|
||||
&self,
|
||||
outer_self: RoutingTable,
|
||||
@@ -525,9 +502,22 @@ impl RoutingTableInner {
|
||||
// Collect all entries that are 'needs_ping' and have some node info making them reachable somehow
|
||||
let mut node_refs = Vec::<NodeRef>::with_capacity(self.bucket_entry_count);
|
||||
self.with_entries(cur_ts, BucketEntryState::Unreliable, |rti, k, v| {
|
||||
if v.with(rti, |_rti, e| {
|
||||
e.has_node_info(routing_domain.into())
|
||||
&& e.needs_ping(cur_ts, opt_relay_id == Some(k))
|
||||
if v.with(rti, |rti, e| {
|
||||
// If this isn't in the routing domain we are checking, don't include it
|
||||
if !e.exists_in_routing_domain(rti, routing_domain) {
|
||||
return false;
|
||||
}
|
||||
// If we need a ping via the normal timing mechanism, then do it
|
||||
if e.needs_ping(cur_ts, opt_relay_id == Some(k)) {
|
||||
return true;
|
||||
}
|
||||
// If we need a ping because this node hasn't seen our latest node info, then do it
|
||||
if let Some(own_node_info_ts) = own_node_info_ts {
|
||||
if !e.has_seen_our_node_info_ts(routing_domain, own_node_info_ts) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}) {
|
||||
node_refs.push(NodeRef::new(
|
||||
outer_self.clone(),
|
||||
|
||||
Reference in New Issue
Block a user