aboutsummaryrefslogtreecommitdiff
path: root/p2p/src
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-05-23 13:27:43 +0200
committerhozan23 <hozan23@karyontech.net>2024-05-23 13:27:43 +0200
commit681cfce4f412958dbb6dc8a1c07408826b4387a0 (patch)
tree9278976be1c59ce47f1833276007f5b45e99c2de /p2p/src
parentd51f212628f4996d754745b4904a1994ba39a2d0 (diff)
p2p: add peer pool logs and discovery logs to example/monitor.rs
Diffstat (limited to 'p2p/src')
-rw-r--r--p2p/src/discovery/lookup.rs6
-rw-r--r--p2p/src/discovery/refresh.rs16
-rw-r--r--p2p/src/monitor.rs2
3 files changed, 7 insertions, 17 deletions
diff --git a/p2p/src/discovery/lookup.rs b/p2p/src/discovery/lookup.rs
index 613c3cd..4a06083 100644
--- a/p2p/src/discovery/lookup.rs
+++ b/p2p/src/discovery/lookup.rs
@@ -234,14 +234,12 @@ impl LookupService {
) -> Result<Vec<PeerMsg>> {
let conn = self.connector.connect(&endpoint, &peer_id).await?;
self.monitor
- .notify(DiscoveryEvent::Conn(ConnEvent::Connected(endpoint.clone())))
+ .notify(ConnEvent::Connected(endpoint.clone()))
.await;
let result = self.handle_outbound(conn, target_peer_id).await;
- self.monitor
- .notify(DiscoveryEvent::Conn(ConnEvent::Disconnected(endpoint)))
- .await;
+ self.monitor.notify(ConnEvent::Disconnected(endpoint)).await;
self.outbound_slots.remove().await;
result
diff --git a/p2p/src/discovery/refresh.rs b/p2p/src/discovery/refresh.rs
index 430e749..745a5d5 100644
--- a/p2p/src/discovery/refresh.rs
+++ b/p2p/src/discovery/refresh.rs
@@ -211,15 +211,13 @@ impl RefreshService {
let conn = match udp::listen(&endpoint, Default::default(), RefreshMsgCodec {}).await {
Ok(c) => {
self.monitor
- .notify(DiscoveryEvent::Conn(ConnEvent::Listening(endpoint.clone())))
+ .notify(ConnEvent::Listening(endpoint.clone()))
.await;
c
}
Err(err) => {
self.monitor
- .notify(DiscoveryEvent::Conn(ConnEvent::ListenFailed(
- endpoint.clone(),
- )))
+ .notify(ConnEvent::ListenFailed(endpoint.clone()))
.await;
return Err(err.into());
}
@@ -230,9 +228,7 @@ impl RefreshService {
let res = self.listen_to_ping_msg(&conn).await;
if let Err(err) = res {
trace!("Failed to handle ping msg {err}");
- self.monitor
- .notify(DiscoveryEvent::Conn(ConnEvent::AcceptFailed))
- .await;
+ self.monitor.notify(ConnEvent::AcceptFailed).await;
}
}
}
@@ -241,7 +237,7 @@ impl RefreshService {
async fn listen_to_ping_msg(&self, conn: &udp::UdpConn<RefreshMsgCodec>) -> Result<()> {
let (msg, endpoint) = conn.recv().await?;
self.monitor
- .notify(DiscoveryEvent::Conn(ConnEvent::Accepted(endpoint.clone())))
+ .notify(ConnEvent::Accepted(endpoint.clone()))
.await;
match msg {
@@ -252,9 +248,7 @@ impl RefreshService {
RefreshMsg::Pong(_) => return Err(Error::InvalidMsg("Unexpected pong msg".into())),
}
- self.monitor
- .notify(DiscoveryEvent::Conn(ConnEvent::Disconnected(endpoint)))
- .await;
+ self.monitor.notify(ConnEvent::Disconnected(endpoint)).await;
Ok(())
}
diff --git a/p2p/src/monitor.rs b/p2p/src/monitor.rs
index 945c6aa..b7afb7c 100644
--- a/p2p/src/monitor.rs
+++ b/p2p/src/monitor.rs
@@ -107,7 +107,6 @@ pub enum PeerPoolEvent {
#[derive(Clone, Debug)]
pub enum DiscoveryEvent {
LookupStarted(Endpoint),
- Conn(ConnEvent),
LookupFailed(Endpoint),
LookupSucceeded(Endpoint, usize),
RefreshStarted,
@@ -143,7 +142,6 @@ impl fmt::Display for DiscoveryEvent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let val = match self {
DiscoveryEvent::LookupStarted(endpoint) => format!("LookupStarted: {endpoint}"),
- DiscoveryEvent::Conn(event) => format!("Connection event: {event}"),
DiscoveryEvent::LookupFailed(endpoint) => format!("LookupFailed: {endpoint}"),
DiscoveryEvent::LookupSucceeded(endpoint, len) => {
format!("LookupSucceeded: {endpoint} {len}")