From 5df6812dd2254b871eb773dc626b89646ca87495 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Wed, 22 May 2024 18:02:51 +0200 Subject: p2p: monitor system use core::EventSys instead of pubsub pattern --- p2p/src/discovery/lookup.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'p2p/src/discovery/lookup.rs') diff --git a/p2p/src/discovery/lookup.rs b/p2p/src/discovery/lookup.rs index cff4610..613c3cd 100644 --- a/p2p/src/discovery/lookup.rs +++ b/p2p/src/discovery/lookup.rs @@ -134,7 +134,7 @@ impl LookupService { pub async fn start_lookup(&self, endpoint: &Endpoint, peer_id: Option) -> Result<()> { trace!("Lookup started {endpoint}"); self.monitor - .notify(&DiscoveryEvent::LookupStarted(endpoint.clone()).into()) + .notify(DiscoveryEvent::LookupStarted(endpoint.clone())) .await; let mut random_peers = vec![]; @@ -143,7 +143,7 @@ impl LookupService { .await { self.monitor - .notify(&DiscoveryEvent::LookupFailed(endpoint.clone()).into()) + .notify(DiscoveryEvent::LookupFailed(endpoint.clone())) .await; return Err(err); }; @@ -166,7 +166,10 @@ impl LookupService { drop(table); self.monitor - .notify(&DiscoveryEvent::LookupSucceeded(endpoint.clone(), peer_buffer.len()).into()) + .notify(DiscoveryEvent::LookupSucceeded( + endpoint.clone(), + peer_buffer.len(), + )) .await; Ok(()) @@ -230,10 +233,14 @@ impl LookupService { target_peer_id: &PeerID, ) -> Result> { let conn = self.connector.connect(&endpoint, &peer_id).await?; + self.monitor + .notify(DiscoveryEvent::Conn(ConnEvent::Connected(endpoint.clone()))) + .await; + let result = self.handle_outbound(conn, target_peer_id).await; self.monitor - .notify(&ConnEvent::Disconnected(endpoint).into()) + .notify(DiscoveryEvent::Conn(ConnEvent::Disconnected(endpoint))) .await; self.outbound_slots.remove().await; -- cgit v1.2.3