@@ -170,6 +170,12 @@ impl NotificationSink {
170170/// Handle allowing the user protocol to interact with the notification protocol.
171171#[ derive( Debug ) ]
172172pub struct NotificationHandle {
173+ /// Protocol name served by this handle.
174+ protocol_name : ProtocolName ,
175+
176+ /// Configured synchronous channel size.
177+ sync_channel_size : usize ,
178+
173179 /// RX channel for receiving events from the notification protocol.
174180 event_rx : Receiver < InnerNotificationEvent > ,
175181
@@ -195,12 +201,16 @@ pub struct NotificationHandle {
195201impl NotificationHandle {
196202 /// Create new [`NotificationHandle`].
197203 pub ( crate ) fn new (
204+ protocol_name : ProtocolName ,
205+ sync_channel_size : usize ,
198206 event_rx : Receiver < InnerNotificationEvent > ,
199207 notif_rx : Receiver < ( PeerId , BytesMut ) > ,
200208 command_tx : Sender < NotificationCommand > ,
201209 handshake : Arc < RwLock < Vec < u8 > > > ,
202210 ) -> Self {
203211 Self {
212+ protocol_name,
213+ sync_channel_size,
204214 event_rx,
205215 notif_rx,
206216 command_tx,
@@ -401,9 +411,34 @@ impl NotificationHandle {
401411 Err ( error) => match error {
402412 NotificationError :: NoConnection => Err ( NotificationError :: NoConnection ) ,
403413 NotificationError :: ChannelClogged => {
404- let _ = self . clogged . insert ( peer) . then ( || {
405- self . command_tx . try_send ( NotificationCommand :: ForceClose { peer } )
406- } ) ;
414+ if self . clogged . insert ( peer) {
415+ match self . command_tx . try_send ( NotificationCommand :: ForceClose { peer } )
416+ {
417+ Ok ( ( ) ) => tracing:: warn!(
418+ target: LOG_TARGET ,
419+ ?peer,
420+ protocol = %self . protocol_name,
421+ sync_channel_size = self . sync_channel_size,
422+ "sync notification channel clogged, queueing force close" ,
423+ ) ,
424+ Err ( error) => tracing:: warn!(
425+ target: LOG_TARGET ,
426+ ?peer,
427+ protocol = %self . protocol_name,
428+ sync_channel_size = self . sync_channel_size,
429+ ?error,
430+ "sync notification channel clogged, failed to queue force close" ,
431+ ) ,
432+ }
433+ } else {
434+ tracing:: debug!(
435+ target: LOG_TARGET ,
436+ ?peer,
437+ protocol = %self . protocol_name,
438+ sync_channel_size = self . sync_channel_size,
439+ "sync notification channel still clogged, force close already queued" ,
440+ ) ;
441+ }
407442
408443 Err ( NotificationError :: ChannelClogged )
409444 }
@@ -479,7 +514,14 @@ impl Stream for NotificationHandle {
479514 }
480515 InnerNotificationEvent :: NotificationStreamClosed { peer } => {
481516 self . peers . remove ( & peer) ;
482- self . clogged . remove ( & peer) ;
517+ if self . clogged . remove ( & peer) {
518+ tracing:: debug!(
519+ target: LOG_TARGET ,
520+ ?peer,
521+ protocol = %self . protocol_name,
522+ "cleared clogged state after notification stream closed" ,
523+ ) ;
524+ }
483525
484526 return Poll :: Ready ( Some ( NotificationEvent :: NotificationStreamClosed {
485527 peer,
@@ -501,22 +543,24 @@ impl Stream for NotificationHandle {
501543 handshake,
502544 } ) ) ;
503545 }
504- InnerNotificationEvent :: NotificationStreamOpenFailure { peer, error } =>
546+ InnerNotificationEvent :: NotificationStreamOpenFailure { peer, error } => {
505547 return Poll :: Ready ( Some (
506548 NotificationEvent :: NotificationStreamOpenFailure { peer, error } ,
507- ) ) ,
549+ ) )
550+ }
508551 } ,
509552 }
510553
511554 match futures:: ready!( self . notif_rx. poll_recv( cx) ) {
512555 None => return Poll :: Ready ( None ) ,
513- Some ( ( peer, notification) ) =>
556+ Some ( ( peer, notification) ) => {
514557 if self . peers . contains_key ( & peer) {
515558 return Poll :: Ready ( Some ( NotificationEvent :: NotificationReceived {
516559 peer,
517560 notification,
518561 } ) ) ;
519- } ,
562+ }
563+ }
520564 }
521565 }
522566 }
0 commit comments