File tree 4 files changed +41
-1
lines changed 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
1
## 0.5.1
2
2
3
- - Allow setting Peer IDs for bypassing limit check.
3
+ - Allow setting Peer IDs for bypassing limit check.
4
4
Connections to the specified peers won't be counted toward limits.
5
5
See [ PR 5720] ( https://github.com/libp2p/rust-libp2p/pull/5720 ) .
6
6
Original file line number Diff line number Diff line change @@ -658,6 +658,37 @@ mod tests {
658
658
)
659
659
}
660
660
661
+ #[ tokio:: test]
662
+ async fn incoming_connection_error_carries_peer_id ( ) {
663
+ let mut swarm1 = Swarm :: new_ephemeral_tokio ( |_| {
664
+ // Set max incoming connections to 0 to immediately deny all connections
665
+ Behaviour :: new ( ConnectionLimits :: default ( ) . with_max_established_incoming ( Some ( 0 ) ) )
666
+ } ) ;
667
+ let mut swarm2 =
668
+ Swarm :: new_ephemeral_tokio ( |_| Behaviour :: new ( ConnectionLimits :: default ( ) ) ) ;
669
+
670
+ let dialer_peer_id = * swarm2. local_peer_id ( ) ;
671
+
672
+ let ( listen_addr, _) = swarm1. listen ( ) . with_memory_addr_external ( ) . await ;
673
+
674
+ swarm2. dial ( listen_addr) . unwrap ( ) ;
675
+
676
+ tokio:: spawn ( swarm2. loop_on_next ( ) ) ;
677
+
678
+ let peer_id = swarm1
679
+ . wait ( |event| match event {
680
+ SwarmEvent :: IncomingConnectionError {
681
+ error : ListenError :: Denied { .. } ,
682
+ peer_id,
683
+ ..
684
+ } => peer_id,
685
+ _ => None ,
686
+ } )
687
+ . await ;
688
+
689
+ assert_eq ! ( Some ( dialer_peer_id) , Some ( peer_id) ) ;
690
+ }
691
+
661
692
#[ derive( libp2p_swarm_derive:: NetworkBehaviour ) ]
662
693
#[ behaviour( prelude = "libp2p_swarm::derive_prelude" ) ]
663
694
struct Behaviour {
Original file line number Diff line number Diff line change 9
9
certain upgrade.
10
10
See [ PR 5860] ( https://github.com/libp2p/rust-libp2p/pull/5860 ) .
11
11
12
+ - Expose ` Option<PeerId> ` in ` SwarmEvent::IncomingConnectionError ` .
13
+ This enables insight to which ` PeerId ` errored.
14
+ See [ PR 6032] ( https://github.com/libp2p/rust-libp2p/pull/6032 )
15
+
12
16
## 0.46.0
13
17
14
18
- Don't report ` NewExternalAddrCandidate ` for confirmed external addresses.
Original file line number Diff line number Diff line change @@ -221,6 +221,8 @@ pub enum SwarmEvent<TBehaviourOutEvent> {
221
221
send_back_addr : Multiaddr ,
222
222
/// The error that happened.
223
223
error : ListenError ,
224
+ /// If known, [`PeerId`] of the peer that tried to connect to us.
225
+ peer_id : Option < PeerId > ,
224
226
} ,
225
227
/// An error happened on an outbound connection.
226
228
OutgoingConnectionError {
@@ -756,6 +758,7 @@ where
756
758
send_back_addr,
757
759
local_addr,
758
760
error : listen_error,
761
+ peer_id : Some ( peer_id) ,
759
762
} ,
760
763
) ;
761
764
return ;
@@ -868,6 +871,7 @@ where
868
871
local_addr,
869
872
send_back_addr,
870
873
error,
874
+ peer_id : None ,
871
875
} ) ;
872
876
}
873
877
PoolEvent :: ConnectionClosed {
@@ -974,6 +978,7 @@ where
974
978
local_addr,
975
979
send_back_addr,
976
980
error : listen_error,
981
+ peer_id : None ,
977
982
} ) ;
978
983
return ;
979
984
}
You can’t perform that action at this time.
0 commit comments