rpc sender dialinfo

This commit is contained in:
John Smith
2022-03-24 22:07:55 -04:00
parent c276dd7796
commit cc715dfc96
4 changed files with 75 additions and 9 deletions

View File

@@ -30,6 +30,7 @@ pub enum BucketEntryState {
pub struct BucketEntry {
pub(super) ref_count: u32,
min_max_version: Option<(u8, u8)>,
seen_our_dial_info: bool,
last_connection: Option<(ConnectionDescriptor, u64)>,
dial_infos: Vec<DialInfo>,
latency_stats_accounting: LatencyStatsAccounting,
@@ -43,6 +44,7 @@ impl BucketEntry {
Self {
ref_count: 0,
min_max_version: None,
seen_our_dial_info: false,
last_connection: None,
dial_infos: Vec::new(),
latency_stats_accounting: LatencyStatsAccounting::new(),
@@ -132,6 +134,14 @@ impl BucketEntry {
self.peer_stats.node_info = Some(node_info);
}
pub fn set_seen_our_dial_info(&mut self, seen: bool) {
self.seen_our_dial_info = seen;
}
pub fn has_seen_our_dial_info(&self) -> bool {
self.seen_our_dial_info
}
///// stats methods
// called every ROLLING_TRANSFERS_INTERVAL_SECS seconds
pub(super) fn roll_transfers(&mut self, last_ts: u64, cur_ts: u64) {
@@ -168,8 +178,17 @@ impl BucketEntry {
}
}
// Check if this node needs a ping right now to validate it is still reachable
pub(super) fn needs_ping(&self, cur_ts: u64) -> bool {
// if we need a ping right now to validate us
// See which ping pattern we are to use
let mut state = self.state(cur_ts);
// If the current dial info hasn't been recognized,
// then we gotta ping regardless so treat the node as unreliable, briefly
if !self.seen_our_dial_info && matches!(state, BucketEntryState::Reliable) {
state = BucketEntryState::Unreliable;
}
match self.state(cur_ts) {
BucketEntryState::Reliable => {
// If we are in a reliable state, we need a ping on an exponential scale

View File

@@ -220,6 +220,11 @@ impl RoutingTable {
timestamp,
});
// Re-sort dial info to endure preference ordering
inner
.dial_info_details
.sort_by(|a, b| a.dial_info.cmp(&b.dial_info));
info!(
"{}Dial Info: {}",
if dial_info.is_local() {
@@ -257,6 +262,14 @@ impl RoutingTable {
}
fn trigger_changed_dial_info(inner: &mut RoutingTableInner) {
// Clear 'seen dial info' bits on routing table entries so we know to ping them
for b in inner.buckets {
for e in b.entries_mut() {
e.1.set_seen_our_dial_info(false);
}
}
// Release any waiters
let mut new_eventual = Eventual::new();
core::mem::swap(&mut inner.eventual_changed_dial_info, &mut new_eventual);
spawn(new_eventual.resolve()).detach();
@@ -454,11 +467,12 @@ impl RoutingTable {
let rpc_processor = self.rpc_processor();
let res = rpc_processor
.clone()
.rpc_call_find_node(
Destination::Direct(node_ref.clone()),
node_id,
None,
RespondTo::Sender,
rpc_processor.get_respond_to_sender(node_ref.clone()),
)
.await
.map_err(map_to_string)

View File

@@ -35,9 +35,9 @@ impl NodeRef {
self.node_id
}
// pub fn dial_info_filter(&self) -> DialInfoFilter {
// self.dial_info_filter.clone()
// }
pub fn dial_info_filter(&self) -> &DialInfoFilter {
&self.dial_info_filter
}
pub fn operate<T, F>(&self, f: F) -> T
where
@@ -46,6 +46,16 @@ impl NodeRef {
self.routing_table.operate_on_bucket_entry(self.node_id, f)
}
// Returns if this node has seen and acknowledged our node's dial info yet
pub fn has_seen_our_dial_info(&self) -> bool {
let nm = self.routing_table.network_manager();
self.operate(|e| e.has_seen_our_dial_info())
}
pub fn set_seen_our_dial_info(&self) {
let nm = self.routing_table.network_manager();
self.operate(|e| e.set_seen_our_dial_info(true));
}
// Returns the best dial info to attempt a connection to this node
pub fn best_dial_info(&self) -> Option<DialInfo> {
let nm = self.routing_table.network_manager();