fix bugs and lints
This commit is contained in:
@@ -50,7 +50,6 @@ 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;
|
||||
let relay_node = netman.relay_node();
|
||||
PeerInfo {
|
||||
node_id: NodeId::new(self.node_id()),
|
||||
|
@@ -187,17 +187,36 @@ impl RoutingTable {
|
||||
|
||||
pub fn first_filtered_dial_info_detail(
|
||||
&self,
|
||||
domain: RoutingDomain,
|
||||
domain: Option<RoutingDomain>,
|
||||
filter: &DialInfoFilter,
|
||||
) -> Option<DialInfoDetail> {
|
||||
let inner = self.inner.lock();
|
||||
Self::with_routing_domain(&*inner, domain, |rd| {
|
||||
for did in rd.dial_info_details {
|
||||
if did.matches_filter(filter) {
|
||||
return Some(did.clone());
|
||||
// Prefer local network first if it isn't filtered out
|
||||
if domain == None || domain == Some(RoutingDomain::LocalNetwork) {
|
||||
Self::with_routing_domain(&*inner, RoutingDomain::LocalNetwork, |rd| {
|
||||
for did in &rd.dial_info_details {
|
||||
if did.matches_filter(filter) {
|
||||
return Some(did.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.or_else(|| {
|
||||
if domain == None || domain == Some(RoutingDomain::PublicInternet) {
|
||||
Self::with_routing_domain(&*inner, RoutingDomain::PublicInternet, |rd| {
|
||||
for did in &rd.dial_info_details {
|
||||
if did.matches_filter(filter) {
|
||||
return Some(did.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -211,7 +230,7 @@ impl RoutingTable {
|
||||
|
||||
if domain == None || domain == Some(RoutingDomain::LocalNetwork) {
|
||||
Self::with_routing_domain(&*inner, RoutingDomain::LocalNetwork, |rd| {
|
||||
for did in rd.dial_info_details {
|
||||
for did in &rd.dial_info_details {
|
||||
if did.matches_filter(filter) {
|
||||
ret.push(did.clone());
|
||||
}
|
||||
@@ -220,7 +239,7 @@ impl RoutingTable {
|
||||
}
|
||||
if domain == None || domain == Some(RoutingDomain::PublicInternet) {
|
||||
Self::with_routing_domain(&*inner, RoutingDomain::PublicInternet, |rd| {
|
||||
for did in rd.dial_info_details {
|
||||
for did in &rd.dial_info_details {
|
||||
if did.matches_filter(filter) {
|
||||
ret.push(did.clone());
|
||||
}
|
||||
|
@@ -46,11 +46,12 @@ impl NodeRef {
|
||||
// Returns true if some protocols can still pass the filter and false if no protocols remain
|
||||
pub fn filter_protocols(&mut self, protocol_set: ProtocolSet) -> bool {
|
||||
if protocol_set != ProtocolSet::all() {
|
||||
let mut dif = self.filter.unwrap_or_default();
|
||||
let mut dif = self.filter.clone().unwrap_or_default();
|
||||
dif.protocol_set &= protocol_set;
|
||||
self.filter = Some(dif);
|
||||
}
|
||||
self.filter
|
||||
.as_ref()
|
||||
.map(|f| !f.protocol_set.is_empty())
|
||||
.unwrap_or(true)
|
||||
}
|
||||
@@ -79,13 +80,12 @@ impl NodeRef {
|
||||
self.operate(|e| e.node_info().outbound_protocols)
|
||||
}
|
||||
pub fn relay(&self) -> Option<NodeRef> {
|
||||
let target_rpi = self.operate(|e| e.node_info().relay_peer_info)?;
|
||||
|
||||
let target_rpi = self.operate(|e| e.node_info().relay_peer_info.clone())?;
|
||||
self.routing_table
|
||||
.register_node_with_node_info(target_rpi.node_id.key, target_rpi.node_info)
|
||||
.map_err(logthru_rtab!(error))
|
||||
.ok()
|
||||
.map(|nr| {
|
||||
.map(|mut nr| {
|
||||
nr.set_filter(self.filter_ref().cloned());
|
||||
nr
|
||||
})
|
||||
@@ -95,16 +95,20 @@ impl NodeRef {
|
||||
routing_domain: Option<RoutingDomain>,
|
||||
) -> Option<DialInfoDetail> {
|
||||
self.operate(|e| {
|
||||
// Prefer local dial info first unless it is filtered out
|
||||
if (routing_domain == None || routing_domain == Some(RoutingDomain::LocalNetwork))
|
||||
&& matches!(
|
||||
self.filter.map(|f| f.peer_scope).unwrap_or(PeerScope::All),
|
||||
self.filter
|
||||
.as_ref()
|
||||
.map(|f| f.peer_scope)
|
||||
.unwrap_or(PeerScope::All),
|
||||
PeerScope::All | PeerScope::Local
|
||||
)
|
||||
{
|
||||
e.local_node_info()
|
||||
.first_filtered_dial_info(|di| {
|
||||
if let Some(filter) = self.filter {
|
||||
di.matches_filter(&filter)
|
||||
if let Some(filter) = self.filter.as_ref() {
|
||||
di.matches_filter(filter)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
@@ -119,13 +123,16 @@ impl NodeRef {
|
||||
.or_else(|| {
|
||||
if (routing_domain == None || routing_domain == Some(RoutingDomain::PublicInternet))
|
||||
&& matches!(
|
||||
self.filter.map(|f| f.peer_scope).unwrap_or(PeerScope::All),
|
||||
self.filter
|
||||
.as_ref()
|
||||
.map(|f| f.peer_scope)
|
||||
.unwrap_or(PeerScope::All),
|
||||
PeerScope::All | PeerScope::Global
|
||||
)
|
||||
{
|
||||
e.node_info().first_filtered_dial_info_detail(|did| {
|
||||
if let Some(filter) = self.filter {
|
||||
did.matches_filter(&filter)
|
||||
if let Some(filter) = self.filter.as_ref() {
|
||||
did.matches_filter(filter)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
@@ -143,15 +150,19 @@ impl NodeRef {
|
||||
) -> Vec<DialInfoDetail> {
|
||||
let mut out = Vec::new();
|
||||
self.operate(|e| {
|
||||
// Prefer local dial info first unless it is filtered out
|
||||
if (routing_domain == None || routing_domain == Some(RoutingDomain::LocalNetwork))
|
||||
&& matches!(
|
||||
self.filter.map(|f| f.peer_scope).unwrap_or(PeerScope::All),
|
||||
self.filter
|
||||
.as_ref()
|
||||
.map(|f| f.peer_scope)
|
||||
.unwrap_or(PeerScope::All),
|
||||
PeerScope::All | PeerScope::Local
|
||||
)
|
||||
{
|
||||
for di in e.local_node_info().all_filtered_dial_info(|di| {
|
||||
if let Some(filter) = self.filter {
|
||||
di.matches_filter(&filter)
|
||||
if let Some(filter) = self.filter.as_ref() {
|
||||
di.matches_filter(filter)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
@@ -164,13 +175,16 @@ impl NodeRef {
|
||||
}
|
||||
if (routing_domain == None || routing_domain == Some(RoutingDomain::PublicInternet))
|
||||
&& matches!(
|
||||
self.filter.map(|f| f.peer_scope).unwrap_or(PeerScope::All),
|
||||
self.filter
|
||||
.as_ref()
|
||||
.map(|f| f.peer_scope)
|
||||
.unwrap_or(PeerScope::All),
|
||||
PeerScope::All | PeerScope::Global
|
||||
)
|
||||
{
|
||||
out.append(&mut e.node_info().all_filtered_dial_info_details(|did| {
|
||||
if let Some(filter) = self.filter {
|
||||
did.matches_filter(&filter)
|
||||
if let Some(filter) = self.filter.as_ref() {
|
||||
did.matches_filter(filter)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
Reference in New Issue
Block a user