subscribe handlers in init. log cleanup.

This commit is contained in:
Christien Rioux 2024-10-24 11:54:52 -04:00
parent 5dffb30603
commit 9042a7afd5
4 changed files with 44 additions and 26 deletions

View File

@ -373,6 +373,23 @@ impl NetworkManager {
*self.unlocked_inner.routing_table.write() = Some(routing_table.clone());
*self.unlocked_inner.address_filter.write() = Some(address_filter);
*self.unlocked_inner.update_callback.write() = Some(update_callback);
// Register event handlers
let this = self.clone();
self.event_bus().subscribe(move |evt| {
let this = this.clone();
Box::pin(async move {
this.peer_info_change_event_handler(evt);
})
});
let this = self.clone();
self.event_bus().subscribe(move |evt| {
let this = this.clone();
Box::pin(async move {
this.socket_address_change_event_handler(evt);
})
});
Ok(())
}
@ -444,22 +461,6 @@ impl NetworkManager {
rpc_processor.startup().await?;
receipt_manager.startup().await?;
// Register event handlers
let this = self.clone();
self.event_bus().subscribe(move |evt| {
let this = this.clone();
Box::pin(async move {
this.peer_info_change_event_handler(evt);
})
});
let this = self.clone();
self.event_bus().subscribe(move |evt| {
let this = this.clone();
Box::pin(async move {
this.socket_address_change_event_handler(evt);
})
});
log_net!("NetworkManager::internal_startup end");
Ok(StartupDisposition::Success)

View File

@ -161,6 +161,7 @@ impl RoutingDomainEditorCommonTrait for RoutingDomainEditorLocalNetwork {
info!(
"[LocalNetwork] removed dial info:\n{}",
indent_all_string(&removed_dial_info.to_multiline_string())
.strip_trailing_newline()
);
peer_info_changed = true;
}
@ -172,6 +173,7 @@ impl RoutingDomainEditorCommonTrait for RoutingDomainEditorLocalNetwork {
info!(
"[LocalNetwork] added dial info:\n{}",
indent_all_string(&added_dial_info.to_multiline_string())
.strip_trailing_newline()
);
peer_info_changed = true;
}
@ -188,35 +190,35 @@ impl RoutingDomainEditorCommonTrait for RoutingDomainEditorLocalNetwork {
}
if old_outbound_protocols != new_outbound_protocols {
info!(
"[LocalNetwork] changed network: outbound {:?}->{:?}\n",
"[LocalNetwork] changed network: outbound {:?}->{:?}",
old_outbound_protocols, new_outbound_protocols
);
peer_info_changed = true;
}
if old_inbound_protocols != new_inbound_protocols {
info!(
"[LocalNetwork] changed network: inbound {:?}->{:?}\n",
"[LocalNetwork] changed network: inbound {:?}->{:?}",
old_inbound_protocols, new_inbound_protocols,
);
peer_info_changed = true;
}
if old_address_types != new_address_types {
info!(
"[LocalNetwork] changed network: address types {:?}->{:?}\n",
"[LocalNetwork] changed network: address types {:?}->{:?}",
old_address_types, new_address_types,
);
peer_info_changed = true;
}
if old_capabilities != new_capabilities {
info!(
"[PublicInternet] changed network: capabilities {:?}->{:?}\n",
"[PublicInternet] changed network: capabilities {:?}->{:?}",
old_capabilities, new_capabilities
);
peer_info_changed = true;
}
if old_network_class != new_network_class {
info!(
"[LocalNetwork] changed network class: {:?}->{:?}\n",
"[LocalNetwork] changed network class: {:?}->{:?}",
old_network_class, new_network_class
);
peer_info_changed = true;

View File

@ -170,6 +170,7 @@ impl RoutingDomainEditorCommonTrait for RoutingDomainEditorPublicInternet {
info!(
"[PublicInternet] removed dial info:\n{}",
indent_all_string(&removed_dial_info.to_multiline_string())
.strip_trailing_newline()
);
peer_info_changed = true;
}
@ -181,6 +182,7 @@ impl RoutingDomainEditorCommonTrait for RoutingDomainEditorPublicInternet {
info!(
"[PublicInternet] added dial info:\n{}",
indent_all_string(&added_dial_info.to_multiline_string())
.strip_trailing_newline()
);
peer_info_changed = true;
}
@ -197,35 +199,35 @@ impl RoutingDomainEditorCommonTrait for RoutingDomainEditorPublicInternet {
}
if old_outbound_protocols != new_outbound_protocols {
info!(
"[PublicInternet] changed network: outbound {:?}->{:?}\n",
"[PublicInternet] changed network: outbound {:?}->{:?}",
old_outbound_protocols, new_outbound_protocols
);
peer_info_changed = true;
}
if old_inbound_protocols != new_inbound_protocols {
info!(
"[PublicInternet] changed network: inbound {:?}->{:?}\n",
"[PublicInternet] changed network: inbound {:?}->{:?}",
old_inbound_protocols, new_inbound_protocols,
);
peer_info_changed = true;
}
if old_address_types != new_address_types {
info!(
"[PublicInternet] changed network: address types {:?}->{:?}\n",
"[PublicInternet] changed network: address types {:?}->{:?}",
old_address_types, new_address_types,
);
peer_info_changed = true;
}
if old_capabilities != new_capabilities {
info!(
"[PublicInternet] changed network: capabilities {:?}->{:?}\n",
"[PublicInternet] changed network: capabilities {:?}->{:?}",
old_capabilities, new_capabilities
);
peer_info_changed = true;
}
if old_network_class != new_network_class {
info!(
"[PublicInternet] changed network class: {:?}->{:?}\n",
"[PublicInternet] changed network class: {:?}->{:?}",
old_network_class, new_network_class
);
peer_info_changed = true;

View File

@ -2321,3 +2321,16 @@ where
out
}
}
pub trait StripTrailingNewline {
fn strip_trailing_newline(&self) -> &str;
}
impl<T: AsRef<str>> StripTrailingNewline for T {
fn strip_trailing_newline(&self) -> &str {
self.as_ref()
.strip_suffix("\r\n")
.or(self.as_ref().strip_suffix("\n"))
.unwrap_or(self.as_ref())
}
}