@@ -223,8 +223,7 @@ pub enum SwarmEvent<TBehaviourOutEvent, THandlerErr> {
223
223
} ,
224
224
/// A new connection arrived on a listener and is in the process of protocol negotiation.
225
225
///
226
- /// A corresponding [`ConnectionEstablished`](SwarmEvent::ConnectionEstablished),
227
- /// [`BannedPeer`](SwarmEvent::BannedPeer), or
226
+ /// A corresponding [`ConnectionEstablished`](SwarmEvent::ConnectionEstablished) or
228
227
/// [`IncomingConnectionError`](SwarmEvent::IncomingConnectionError) event will later be
229
228
/// generated for this connection.
230
229
IncomingConnection {
@@ -256,14 +255,6 @@ pub enum SwarmEvent<TBehaviourOutEvent, THandlerErr> {
256
255
/// Error that has been encountered.
257
256
error : DialError ,
258
257
} ,
259
- /// We connected to a peer, but we immediately closed the connection because that peer is banned.
260
- #[ deprecated( note = "Use `libp2p::allow_block_list` instead." , since = "0.42.1" ) ]
261
- BannedPeer {
262
- /// Identity of the banned peer.
263
- peer_id : PeerId ,
264
- /// Endpoint of the connection that has been closed.
265
- endpoint : ConnectedPoint ,
266
- } ,
267
258
/// One of our listeners has reported a new local listening address.
268
259
NewListenAddr {
269
260
/// The listener that is listening on the new address.
@@ -349,9 +340,6 @@ where
349
340
/// similar mechanisms.
350
341
external_addrs : Addresses ,
351
342
352
- /// List of nodes for which we deny any incoming connection.
353
- banned_peers : HashSet < PeerId > ,
354
-
355
343
/// Pending event to be delivered to connection handlers
356
344
/// (or dropped if the peer disconnected) before the `behaviour`
357
345
/// can be polled again.
@@ -560,22 +548,6 @@ where
560
548
return Err ( e) ;
561
549
}
562
550
563
- if let Some ( peer_id) = peer_id {
564
- // Check if peer is banned.
565
- if self . banned_peers . contains ( & peer_id) {
566
- #[ allow( deprecated) ]
567
- let error = DialError :: Banned ;
568
- self . behaviour
569
- . on_swarm_event ( FromSwarm :: DialFailure ( DialFailure {
570
- peer_id : Some ( peer_id) ,
571
- error : & error,
572
- connection_id,
573
- } ) ) ;
574
-
575
- return Err ( error) ;
576
- }
577
- }
578
-
579
551
let addresses = {
580
552
let mut addresses_from_opts = dial_opts. get_addresses ( ) ;
581
553
@@ -742,27 +714,6 @@ where
742
714
}
743
715
}
744
716
745
- /// Bans a peer by its peer ID.
746
- ///
747
- /// Any incoming connection and any dialing attempt will immediately be rejected.
748
- /// This function has no effect if the peer is already banned.
749
- #[ deprecated( note = "Use `libp2p::allow_block_list` instead." , since = "0.42.1" ) ]
750
- pub fn ban_peer_id ( & mut self , peer_id : PeerId ) {
751
- if self . banned_peers . insert ( peer_id) {
752
- // Note that established connections to the now banned peer are closed but not
753
- // added to [`Swarm::banned_peer_connections`]. They have been previously reported
754
- // as open to the behaviour and need be reported as closed once closing the
755
- // connection finishes.
756
- self . pool . disconnect ( peer_id) ;
757
- }
758
- }
759
-
760
- /// Unbans a peer.
761
- #[ deprecated( note = "Use `libp2p::allow_block_list` instead." , since = "0.42.1" ) ]
762
- pub fn unban_peer_id ( & mut self , peer_id : PeerId ) {
763
- self . banned_peers . remove ( & peer_id) ;
764
- }
765
-
766
717
/// Disconnects a peer by its peer ID, closing all connections to said peer.
767
718
///
768
719
/// Returns `Ok(())` if there was one or more established connections to the peer.
@@ -818,11 +769,6 @@ where
818
769
concurrent_dial_errors,
819
770
established_in,
820
771
} => {
821
- if self . banned_peers . contains ( & peer_id) {
822
- #[ allow( deprecated) ]
823
- return Some ( SwarmEvent :: BannedPeer { peer_id, endpoint } ) ;
824
- }
825
-
826
772
let handler = match endpoint. clone ( ) {
827
773
ConnectedPoint :: Dialer {
828
774
address,
@@ -1715,7 +1661,6 @@ where
1715
1661
supported_protocols : Default :: default ( ) ,
1716
1662
listened_addrs : HashMap :: new ( ) ,
1717
1663
external_addrs : Addresses :: default ( ) ,
1718
- banned_peers : HashSet :: new ( ) ,
1719
1664
pending_event : None ,
1720
1665
}
1721
1666
}
@@ -1724,9 +1669,6 @@ where
1724
1669
/// Possible errors when trying to establish or upgrade an outbound connection.
1725
1670
#[ derive( Debug ) ]
1726
1671
pub enum DialError {
1727
- /// The peer is currently banned.
1728
- #[ deprecated( note = "Use `libp2p::allow_block_list` instead." , since = "0.42.1" ) ]
1729
- Banned ,
1730
1672
/// The configured limit for simultaneous outgoing connections
1731
1673
/// has been reached.
1732
1674
#[ deprecated(
@@ -1786,8 +1728,6 @@ impl fmt::Display for DialError {
1786
1728
f,
1787
1729
"Dial error: tried to dial local peer id at {endpoint:?}."
1788
1730
) ,
1789
- #[ allow( deprecated) ]
1790
- DialError :: Banned => write ! ( f, "Dial error: peer is banned." ) ,
1791
1731
DialError :: DialPeerConditionFalse ( c) => {
1792
1732
write ! ( f, "Dial error: condition {c:?} for dialing peer was false." )
1793
1733
}
@@ -1838,8 +1778,6 @@ impl error::Error for DialError {
1838
1778
DialError :: ConnectionLimit ( err) => Some ( err) ,
1839
1779
DialError :: LocalPeerId { .. } => None ,
1840
1780
DialError :: NoAddresses => None ,
1841
- #[ allow( deprecated) ]
1842
- DialError :: Banned => None ,
1843
1781
DialError :: DialPeerConditionFalse ( _) => None ,
1844
1782
DialError :: Aborted => None ,
1845
1783
DialError :: InvalidPeerId { .. } => None ,
@@ -2121,136 +2059,6 @@ mod tests {
2121
2059
&& !swarm2. is_connected ( swarm1. local_peer_id ( ) )
2122
2060
}
2123
2061
2124
- /// Establishes multiple connections between two peers,
2125
- /// after which one peer bans the other.
2126
- ///
2127
- /// The test expects both behaviours to be notified via calls to [`NetworkBehaviour::on_swarm_event`]
2128
- /// with pairs of [`FromSwarm::ConnectionEstablished`] / [`FromSwarm::ConnectionClosed`]
2129
- /// while unbanned.
2130
- ///
2131
- /// While the ban is in effect, further dials occur. For these connections no
2132
- /// [`FromSwarm::ConnectionEstablished`], [`FromSwarm::ConnectionClosed`]
2133
- /// calls should be registered.
2134
- #[ test]
2135
- #[ allow( deprecated) ]
2136
- fn test_connect_disconnect_ban ( ) {
2137
- let _ = env_logger:: try_init ( ) ;
2138
-
2139
- // Since the test does not try to open any substreams, we can
2140
- // use keep alive protocols handler.
2141
- let handler_proto = keep_alive:: ConnectionHandler ;
2142
-
2143
- let mut swarm1 = new_test_swarm :: < _ , ( ) > ( handler_proto. clone ( ) ) . build ( ) ;
2144
- let mut swarm2 = new_test_swarm :: < _ , ( ) > ( handler_proto) . build ( ) ;
2145
-
2146
- let addr1: Multiaddr = multiaddr:: Protocol :: Memory ( rand:: random :: < u64 > ( ) ) . into ( ) ;
2147
- let addr2: Multiaddr = multiaddr:: Protocol :: Memory ( rand:: random :: < u64 > ( ) ) . into ( ) ;
2148
-
2149
- swarm1. listen_on ( addr1) . unwrap ( ) ;
2150
- swarm2. listen_on ( addr2. clone ( ) ) . unwrap ( ) ;
2151
-
2152
- let swarm1_id = * swarm1. local_peer_id ( ) ;
2153
-
2154
- #[ derive( Debug ) ]
2155
- enum Stage {
2156
- /// Waiting for the peers to connect. Banning has not occurred.
2157
- Connecting ,
2158
- /// Ban occurred.
2159
- Banned ,
2160
- // Ban is in place and a dial is ongoing.
2161
- BannedDial ,
2162
- // Mid-ban dial was registered and the peer was unbanned.
2163
- Unbanned ,
2164
- // There are dial attempts ongoing for the no longer banned peers.
2165
- Reconnecting ,
2166
- }
2167
-
2168
- let num_connections = 10 ;
2169
-
2170
- for _ in 0 ..num_connections {
2171
- swarm1. dial ( addr2. clone ( ) ) . unwrap ( ) ;
2172
- }
2173
-
2174
- let mut s1_expected_conns = num_connections;
2175
- let mut s2_expected_conns = num_connections;
2176
-
2177
- let mut stage = Stage :: Connecting ;
2178
-
2179
- executor:: block_on ( future:: poll_fn ( move |cx| loop {
2180
- let poll1 = Swarm :: poll_next_event ( Pin :: new ( & mut swarm1) , cx) ;
2181
- let poll2 = Swarm :: poll_next_event ( Pin :: new ( & mut swarm2) , cx) ;
2182
- match stage {
2183
- Stage :: Connecting => {
2184
- if swarm1. behaviour . assert_connected ( s1_expected_conns, 1 )
2185
- && swarm2. behaviour . assert_connected ( s2_expected_conns, 1 )
2186
- {
2187
- // Setup to test that already established connections are correctly closed
2188
- // and reported as such after the peer is banned.
2189
- swarm2. ban_peer_id ( swarm1_id) ;
2190
- stage = Stage :: Banned ;
2191
- }
2192
- }
2193
- Stage :: Banned => {
2194
- if swarm1. behaviour . assert_disconnected ( s1_expected_conns, 1 )
2195
- && swarm2. behaviour . assert_disconnected ( s2_expected_conns, 1 )
2196
- {
2197
- // Setup to test that new connections of banned peers are not reported.
2198
- swarm1. dial ( addr2. clone ( ) ) . unwrap ( ) ;
2199
- s1_expected_conns += 1 ;
2200
- stage = Stage :: BannedDial ;
2201
- }
2202
- }
2203
- Stage :: BannedDial => {
2204
- if swarm1. behaviour . assert_disconnected ( s1_expected_conns, 2 ) {
2205
- // The banned connection was established. Given the ban, swarm2 closed the
2206
- // connection. Check that it was not reported to the behaviour of the
2207
- // banning swarm.
2208
- assert_eq ! (
2209
- swarm2. behaviour. on_connection_established. len( ) ,
2210
- s2_expected_conns,
2211
- "No additional closed connections should be reported for the banned peer"
2212
- ) ;
2213
-
2214
- // Setup to test that the banned connection is not reported upon closing
2215
- // even if the peer is unbanned.
2216
- swarm2. unban_peer_id ( swarm1_id) ;
2217
- stage = Stage :: Unbanned ;
2218
- }
2219
- }
2220
- Stage :: Unbanned => {
2221
- if swarm1. network_info ( ) . num_peers ( ) == 0
2222
- && swarm2. network_info ( ) . num_peers ( ) == 0
2223
- {
2224
- // The banned connection has closed. Check that it was not reported.
2225
- assert_eq ! (
2226
- swarm2. behaviour. on_connection_closed. len( ) , s2_expected_conns,
2227
- "No additional closed connections should be reported for the banned peer"
2228
- ) ;
2229
-
2230
- // Setup to test that a ban lifted does not affect future connections.
2231
- for _ in 0 ..num_connections {
2232
- swarm1. dial ( addr2. clone ( ) ) . unwrap ( ) ;
2233
- }
2234
- s1_expected_conns += num_connections;
2235
- s2_expected_conns += num_connections;
2236
- stage = Stage :: Reconnecting ;
2237
- }
2238
- }
2239
- Stage :: Reconnecting => {
2240
- if swarm1. behaviour . on_connection_established . len ( ) == s1_expected_conns
2241
- && swarm2. behaviour . assert_connected ( s2_expected_conns, 2 )
2242
- {
2243
- return Poll :: Ready ( ( ) ) ;
2244
- }
2245
- }
2246
- }
2247
-
2248
- if poll1. is_pending ( ) && poll2. is_pending ( ) {
2249
- return Poll :: Pending ;
2250
- }
2251
- } ) )
2252
- }
2253
-
2254
2062
/// Establishes multiple connections between two peers,
2255
2063
/// after which one peer disconnects the other using [`Swarm::disconnect_peer_id`].
2256
2064
///
0 commit comments