@@ -37,6 +37,68 @@ use crate::{
3737 types:: TimeToLive ,
3838} ;
3939
40+ trait SwarmEventExt {
41+ fn get_event_type ( & self ) -> ( & ' static str , & ' static str ) ;
42+ }
43+
44+ impl SwarmEventExt for SwarmEvent < ConfigurableBehaviourEvent > {
45+ fn get_event_type ( & self ) -> ( & ' static str , & ' static str ) {
46+ match self {
47+ SwarmEvent :: Behaviour ( ConfigurableBehaviourEvent :: Kademlia ( kad_event) ) => {
48+ match kad_event {
49+ kad:: Event :: RoutingUpdated { .. } => ( "Kademlia" , "RoutingUpdated" ) ,
50+ kad:: Event :: RoutablePeer { .. } => ( "Kademlia" , "RoutablePeer" ) ,
51+ kad:: Event :: UnroutablePeer { .. } => ( "Kademlia" , "UnroutablePeer" ) ,
52+ kad:: Event :: PendingRoutablePeer { .. } => ( "Kademlia" , "PendingRoutablePeer" ) ,
53+ kad:: Event :: InboundRequest { request } => match request {
54+ InboundRequest :: GetRecord { .. } => {
55+ ( "Kademlia" , "InboundRequest::GetRecord" )
56+ } ,
57+ InboundRequest :: PutRecord { .. } => {
58+ ( "Kademlia" , "InboundRequest::PutRecord" )
59+ } ,
60+ InboundRequest :: FindNode { .. } => ( "Kademlia" , "InboundRequest::FindNode" ) ,
61+ _ => ( "Kademlia" , "InboundRequest::Other" ) ,
62+ } ,
63+ kad:: Event :: ModeChanged { .. } => ( "Kademlia" , "ModeChanged" ) ,
64+ kad:: Event :: OutboundQueryProgressed { result, .. } => match result {
65+ QueryResult :: GetRecord ( _) => ( "Kademlia" , "Query::GetRecord" ) ,
66+ QueryResult :: GetClosestPeers ( _) => ( "Kademlia" , "Query::GetClosestPeers" ) ,
67+ QueryResult :: PutRecord ( _) => ( "Kademlia" , "Query::PutRecord" ) ,
68+ QueryResult :: Bootstrap ( _) => ( "Kademlia" , "Query::Bootstrap" ) ,
69+ _ => ( "Kademlia" , "Query::Other" ) ,
70+ } ,
71+ }
72+ } ,
73+ SwarmEvent :: Behaviour ( ConfigurableBehaviourEvent :: Identify ( identify_event) ) => {
74+ match identify_event {
75+ identify:: Event :: Received { .. } => ( "Identify" , "Received" ) ,
76+ identify:: Event :: Sent { .. } => ( "Identify" , "Sent" ) ,
77+ identify:: Event :: Pushed { .. } => ( "Identify" , "Pushed" ) ,
78+ identify:: Event :: Error { .. } => ( "Identify" , "Error" ) ,
79+ }
80+ } ,
81+ SwarmEvent :: Behaviour ( ConfigurableBehaviourEvent :: AutoNat ( autonat_event) ) => {
82+ match autonat_event {
83+ autonat:: Event :: InboundProbe ( _) => ( "AutoNat" , "InboundProbe" ) ,
84+ autonat:: Event :: OutboundProbe ( _) => ( "AutoNat" , "OutboundProbe" ) ,
85+ autonat:: Event :: StatusChanged { .. } => ( "AutoNat" , "StatusChanged" ) ,
86+ }
87+ } ,
88+ SwarmEvent :: Behaviour ( ConfigurableBehaviourEvent :: Ping ( _) ) => ( "Ping" , "Event" ) ,
89+ SwarmEvent :: NewListenAddr { .. } => ( "Swarm" , "NewListenAddr" ) ,
90+ SwarmEvent :: ConnectionClosed { .. } => ( "Swarm" , "ConnectionClosed" ) ,
91+ SwarmEvent :: IncomingConnection { .. } => ( "Swarm" , "IncomingConnection" ) ,
92+ SwarmEvent :: IncomingConnectionError { .. } => ( "Swarm" , "IncomingConnectionError" ) ,
93+ SwarmEvent :: ExternalAddrConfirmed { .. } => ( "Swarm" , "ExternalAddrConfirmed" ) ,
94+ SwarmEvent :: ConnectionEstablished { .. } => ( "Swarm" , "ConnectionEstablished" ) ,
95+ SwarmEvent :: OutgoingConnectionError { .. } => ( "Swarm" , "OutgoingConnectionError" ) ,
96+ SwarmEvent :: Dialing { .. } => ( "Swarm" , "Dialing" ) ,
97+ _ => ( "Swarm" , "Other" ) ,
98+ }
99+ }
100+ }
101+
40102struct EventLoopConfig {
41103 // Used for checking protocol version
42104 is_fat_client : bool ,
@@ -155,10 +217,11 @@ impl EventLoop {
155217 #[ cfg( not( target_arch = "wasm32" ) ) ]
156218 tokio:: select! {
157219 event = self . swarm. next( ) => {
158- self . handle_event( event. expect( "Swarm stream should be infinite" ) ) . await ;
220+ let event = event. expect( "Swarm stream should be infinite" ) ;
221+ let ( source, name) = event. get_event_type( ) ;
222+ self . handle_event( event) . await ;
159223 event_counter. add_event( ) ;
160-
161- _ = self . event_sender. send( OutputEvent :: Count ) ;
224+ _ = self . event_sender. send( OutputEvent :: Count { source, name } ) ;
162225 } ,
163226 command = self . command_receiver. recv( ) => match command {
164227 Some ( c) => _ = ( c) ( & mut self ) ,
@@ -169,7 +232,11 @@ impl EventLoop {
169232 } ,
170233 } ,
171234 _ = report_timer. tick( ) => {
172- debug!( "Events per {}s: {:.2}" , event_counter. duration_secs( ) , event_counter. count_events( ) ) ;
235+ info!(
236+ count = format!( "{:.2}" , event_counter. count_events( ) ) ,
237+ "Events per {}s" ,
238+ event_counter. duration_secs( )
239+ ) ;
173240 event_counter. reset_counter( ) ;
174241 } ,
175242 // if the shutdown was triggered,
@@ -186,10 +253,11 @@ impl EventLoop {
186253 #[ cfg( target_arch = "wasm32" ) ]
187254 tokio:: select! {
188255 event = self . swarm. next( ) => {
189- self . handle_event( event. expect( "Swarm stream should be infinite" ) ) . await ;
256+ let event = event. expect( "Swarm stream should be infinite" ) ;
257+ let ( source, name) = event. get_event_type( ) ;
258+ self . handle_event( event) . await ;
190259 event_counter. add_event( ) ;
191-
192- _ = self . event_sender. send( OutputEvent :: Count ) ;
260+ _ = self . event_sender. send( OutputEvent :: Count { source, name } ) ;
193261 } ,
194262 command = self . command_receiver. recv( ) => match command {
195263 Some ( c) => _ = ( c) ( & mut self ) ,
@@ -200,7 +268,11 @@ impl EventLoop {
200268 } ,
201269 } ,
202270 _ = tokio:: time:: sleep( next_tick. checked_duration_since( now) . unwrap_or_default( ) ) => {
203- debug!( "Events per {}s: {:.2}" , event_counter. duration_secs( ) , event_counter. count_events( ) ) ;
271+ info!(
272+ count = format!( "{:.2}" , event_counter. count_events( ) ) ,
273+ "Events per {}s" ,
274+ event_counter. duration_secs( )
275+ ) ;
204276 event_counter. reset_counter( ) ;
205277 next_tick += event_counter. report_interval;
206278 } ,
0 commit comments