This commit is contained in:
Christien Rioux
2023-09-04 13:33:27 -04:00
parent 1b5934dad4
commit 80b2e7b9da
4 changed files with 223 additions and 308 deletions

View File

@@ -1,7 +1,10 @@
use super::*;
enum RoutingDomainChange {
ClearDialInfoDetails,
ClearDialInfoDetails {
address_type: Option<AddressType>,
protocol_type: Option<ProtocolType>,
},
ClearRelayNode,
SetRelayNode {
relay_node: NodeRef,
@@ -39,8 +42,16 @@ impl RoutingDomainEditor {
}
#[instrument(level = "debug", skip(self))]
pub fn clear_dial_info_details(&mut self) -> &mut Self {
self.changes.push(RoutingDomainChange::ClearDialInfoDetails);
pub fn clear_dial_info_details(
&mut self,
address_type: Option<AddressType>,
protocol_type: Option<ProtocolType>,
) -> &mut Self {
self.changes
.push(RoutingDomainChange::ClearDialInfoDetails {
address_type,
protocol_type,
});
self
}
#[instrument(level = "debug", skip(self))]
@@ -125,9 +136,17 @@ impl RoutingDomainEditor {
inner.with_routing_domain_mut(self.routing_domain, |detail| {
for change in self.changes.drain(..) {
match change {
RoutingDomainChange::ClearDialInfoDetails => {
debug!("[{:?}] cleared dial info details", self.routing_domain);
detail.common_mut().clear_dial_info_details();
RoutingDomainChange::ClearDialInfoDetails {
address_type,
protocol_type,
} => {
debug!(
"[{:?}] cleared dial info details: at={:?} pt={:?}",
self.routing_domain, address_type, protocol_type
);
detail
.common_mut()
.clear_dial_info_details(address_type, protocol_type);
changed = true;
}
RoutingDomainChange::ClearRelayNode => {

View File

@@ -103,8 +103,21 @@ impl RoutingDomainDetailCommon {
pub fn dial_info_details(&self) -> &Vec<DialInfoDetail> {
&self.dial_info_details
}
pub(super) fn clear_dial_info_details(&mut self) {
self.dial_info_details.clear();
pub(super) fn clear_dial_info_details(&mut self, address_type: Option<AddressType>, protocol_type: Option<ProtocolType>) {
self.dial_info_details.retain_mut(|e| {
let mut remove = true;
if let Some(pt) = protocol_type {
if pt != e.dial_info.protocol_type() {
remove = false;
}
}
if let Some(at) = address_type {
if at != e.dial_info.address_type() {
remove = false;
}
}
!remove
});
self.clear_cache();
}
pub(super) fn add_dial_info_detail(&mut self, did: DialInfoDetail) {