From 2e73f1de0d0eeb0c8e20dfe88c4cd0336300bf91 Mon Sep 17 00:00:00 2001 From: Diva M Date: Thu, 18 Nov 2021 15:02:18 -0500 Subject: [PATCH 01/21] patch reporting on banned peer connections --- core/src/connection.rs | 2 ++ core/src/connection/pool.rs | 34 ++++++++++++++++++++++--- swarm/src/lib.rs | 50 ++++++++++++++++++++++++------------- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/core/src/connection.rs b/core/src/connection.rs index 961eb4abc0e..6a6ef2e776d 100644 --- a/core/src/connection.rs +++ b/core/src/connection.rs @@ -206,6 +206,8 @@ pub struct Connected { pub endpoint: ConnectedPoint, /// Information obtained from the transport. pub peer_id: PeerId, + /// If the connection was allowed by the network. + pub is_allowed: bool, } /// Event generated by a [`Connection`]. diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index 163da2178f6..e8c480f9a99 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -112,6 +112,8 @@ struct EstablishedConnectionInfo { /// [`PeerId`] of the remote peer. peer_id: PeerId, endpoint: ConnectedPoint, + /// Whether the connection was allowed. + is_allowed: bool, /// Channel endpoint to send commands to the task. sender: mpsc::Sender>, } @@ -690,8 +692,11 @@ where .established .get_mut(&peer_id) .expect("`Closed` event for established connection"); - let EstablishedConnectionInfo { endpoint, .. } = - connections.remove(&id).expect("Connection to be present"); + let EstablishedConnectionInfo { + endpoint, + is_allowed, + .. + } = connections.remove(&id).expect("Connection to be present"); self.counters.dec_established(&endpoint); let num_established = u32::try_from(connections.len()).unwrap(); if num_established == 0 { @@ -699,7 +704,11 @@ where } return Poll::Ready(PoolEvent::ConnectionClosed { id, - connected: Connected { endpoint, peer_id }, + connected: Connected { + endpoint, + peer_id, + is_allowed, + }, error, num_established, pool: self, @@ -855,16 +864,23 @@ where let (command_sender, command_receiver) = mpsc::channel(self.task_command_buffer_size); + // Any new connection is allowed by default. + let is_allowed = true; conns.insert( id, EstablishedConnectionInfo { peer_id, endpoint: endpoint.clone(), + is_allowed, sender: command_sender, }, ); - let connected = Connected { peer_id, endpoint }; + let connected = Connected { + peer_id, + endpoint, + is_allowed, + }; let connection = super::Connection::new(muxer, handler.into_handler(&connected)); @@ -1010,6 +1026,16 @@ impl EstablishedConnection<'_, TInEvent> { *self.entry.key() } + /// Return whether the connection was allowed from the network. + pub fn is_allowed(&self) -> bool { + self.entry.get().is_allowed + } + + /// Marks the connection as disallowed by the network. + pub fn disallow(&mut self) { + self.entry.get_mut().is_allowed = false; + } + /// (Asynchronously) sends an event to the connection handler. /// /// If the handler is not ready to receive the event, either because diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 0059a21a0cb..ebcbc9c7e0f 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -603,8 +603,16 @@ where Poll::Pending => network_not_ready = true, Poll::Ready(NetworkEvent::ConnectionEvent { connection, event }) => { let peer = connection.peer_id(); - let connection = connection.id(); - this.behaviour.inject_event(peer, connection, event); + let conn_id = connection.id(); + if connection.is_allowed() { + this.behaviour.inject_event(peer, conn_id, event); + } else { + log::debug!( + "Ignoring event from disallowed connection: {:?} {:?}.", + peer, + conn_id, + ); + } } Poll::Ready(NetworkEvent::AddressChange { connection, @@ -612,22 +620,26 @@ where old_endpoint, }) => { let peer = connection.peer_id(); - let connection = connection.id(); - this.behaviour.inject_address_change( - &peer, - &connection, - &old_endpoint, - &new_endpoint, - ); + let conn_id = connection.id(); + if connection.is_allowed() { + this.behaviour.inject_address_change( + &peer, + &conn_id, + &old_endpoint, + &new_endpoint, + ); + } } Poll::Ready(NetworkEvent::ConnectionEstablished { - connection, + mut connection, num_established, concurrent_dial_errors, }) => { let peer_id = connection.peer_id(); let endpoint = connection.endpoint().clone(); if this.banned_peers.contains(&peer_id) { + // Mark the connection for the banned peer as disallowed. + connection.disallow(); this.network .peer(peer_id) .into_connected() @@ -676,14 +688,16 @@ where } let peer_id = connected.peer_id; let endpoint = connected.endpoint; - this.behaviour.inject_connection_closed( - &peer_id, - &id, - &endpoint, - handler.into_protocols_handler(), - ); - if num_established == 0 { - this.behaviour.inject_disconnected(&peer_id); + if connected.is_allowed { + this.behaviour.inject_connection_closed( + &peer_id, + &id, + &endpoint, + handler.into_protocols_handler(), + ); + if num_established == 0 { + this.behaviour.inject_disconnected(&peer_id); + } } return Poll::Ready(SwarmEvent::ConnectionClosed { peer_id, From ba4df01b86405294bedc6872a64503a03922fd87 Mon Sep 17 00:00:00 2001 From: Diva M Date: Thu, 18 Nov 2021 16:08:32 -0500 Subject: [PATCH 02/21] unelegant test --- swarm/src/lib.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index ebcbc9c7e0f..001fbb1f373 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1803,4 +1803,58 @@ mod tests { } })) } + + #[test] + fn test_banning_respects_contract() { + let handler_proto = DummyProtocolsHandler { + keep_alive: KeepAlive::Yes, + }; + + let mut swarm1 = new_test_swarm::<_, ()>(handler_proto.clone()); + let mut swarm2 = new_test_swarm::<_, ()>(handler_proto); + + let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); + let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); + + swarm1.listen_on(addr1.clone().into()).unwrap(); + swarm2.listen_on(addr2.clone().into()).unwrap(); + + let swarm1_id = *swarm1.local_peer_id(); + + async fn poll( + id: usize, + swarm: &mut Swarm>>, + ) { + let ev = swarm.select_next_some().await; + log::info!("[{}] {:?}", id, ev); + } + + executor::block_on(async { + // Wait for the swarms to establish listeners + poll(1, &mut swarm1).await; + poll(2, &mut swarm2).await; + + swarm1.dial(addr2.clone()).unwrap(); + log::info!("Swarm 2 banning swarm 1\n\n"); + swarm2.ban_peer_id(swarm1_id); + + // Incoming connection + poll(2, &mut swarm2).await; + + // Connection established + poll(2, &mut swarm2).await; + // Connection established + poll(1, &mut swarm1).await; + + // Both see connections as closed + poll(1, &mut swarm1).await; + poll(2, &mut swarm2).await; + + // Check what swarm2's behaviour got + assert_eq!( + swarm2.behaviour.inject_connection_established, + swarm2.behaviour.inject_connection_closed + ); + }) + } } From 43edaa06853b1f9f17edfa8d3a309d2cd56aa1ba Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 19 Nov 2021 07:30:33 -0500 Subject: [PATCH 03/21] move banned connections logic to the swarm --- core/src/connection.rs | 2 -- core/src/connection/pool.rs | 34 ++++------------------------------ swarm/src/lib.rs | 15 ++++++++++----- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/core/src/connection.rs b/core/src/connection.rs index 6a6ef2e776d..961eb4abc0e 100644 --- a/core/src/connection.rs +++ b/core/src/connection.rs @@ -206,8 +206,6 @@ pub struct Connected { pub endpoint: ConnectedPoint, /// Information obtained from the transport. pub peer_id: PeerId, - /// If the connection was allowed by the network. - pub is_allowed: bool, } /// Event generated by a [`Connection`]. diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index e8c480f9a99..163da2178f6 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -112,8 +112,6 @@ struct EstablishedConnectionInfo { /// [`PeerId`] of the remote peer. peer_id: PeerId, endpoint: ConnectedPoint, - /// Whether the connection was allowed. - is_allowed: bool, /// Channel endpoint to send commands to the task. sender: mpsc::Sender>, } @@ -692,11 +690,8 @@ where .established .get_mut(&peer_id) .expect("`Closed` event for established connection"); - let EstablishedConnectionInfo { - endpoint, - is_allowed, - .. - } = connections.remove(&id).expect("Connection to be present"); + let EstablishedConnectionInfo { endpoint, .. } = + connections.remove(&id).expect("Connection to be present"); self.counters.dec_established(&endpoint); let num_established = u32::try_from(connections.len()).unwrap(); if num_established == 0 { @@ -704,11 +699,7 @@ where } return Poll::Ready(PoolEvent::ConnectionClosed { id, - connected: Connected { - endpoint, - peer_id, - is_allowed, - }, + connected: Connected { endpoint, peer_id }, error, num_established, pool: self, @@ -864,23 +855,16 @@ where let (command_sender, command_receiver) = mpsc::channel(self.task_command_buffer_size); - // Any new connection is allowed by default. - let is_allowed = true; conns.insert( id, EstablishedConnectionInfo { peer_id, endpoint: endpoint.clone(), - is_allowed, sender: command_sender, }, ); - let connected = Connected { - peer_id, - endpoint, - is_allowed, - }; + let connected = Connected { peer_id, endpoint }; let connection = super::Connection::new(muxer, handler.into_handler(&connected)); @@ -1026,16 +1010,6 @@ impl EstablishedConnection<'_, TInEvent> { *self.entry.key() } - /// Return whether the connection was allowed from the network. - pub fn is_allowed(&self) -> bool { - self.entry.get().is_allowed - } - - /// Marks the connection as disallowed by the network. - pub fn disallow(&mut self) { - self.entry.get_mut().is_allowed = false; - } - /// (Asynchronously) sends an event to the connection handler. /// /// If the handler is not ready to receive the event, either because diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 001fbb1f373..30a4043689b 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -275,6 +275,9 @@ where /// List of nodes for which we deny any incoming connection. banned_peers: HashSet, + /// Connections for which we withhold any reporting. These belong to banned peers. + banned_connections: HashSet, + /// Pending event to be delivered to connection handlers /// (or dropped if the peer disconnected) before the `behaviour` /// can be polled again. @@ -604,7 +607,7 @@ where Poll::Ready(NetworkEvent::ConnectionEvent { connection, event }) => { let peer = connection.peer_id(); let conn_id = connection.id(); - if connection.is_allowed() { + if !this.banned_connections.contains(&conn_id) { this.behaviour.inject_event(peer, conn_id, event); } else { log::debug!( @@ -621,7 +624,7 @@ where }) => { let peer = connection.peer_id(); let conn_id = connection.id(); - if connection.is_allowed() { + if !this.banned_connections.contains(&conn_id) { this.behaviour.inject_address_change( &peer, &conn_id, @@ -631,7 +634,7 @@ where } } Poll::Ready(NetworkEvent::ConnectionEstablished { - mut connection, + connection, num_established, concurrent_dial_errors, }) => { @@ -639,7 +642,7 @@ where let endpoint = connection.endpoint().clone(); if this.banned_peers.contains(&peer_id) { // Mark the connection for the banned peer as disallowed. - connection.disallow(); + this.banned_connections.insert(connection.id()); this.network .peer(peer_id) .into_connected() @@ -688,7 +691,7 @@ where } let peer_id = connected.peer_id; let endpoint = connected.endpoint; - if connected.is_allowed { + if !this.banned_connections.remove(&id) { this.behaviour.inject_connection_closed( &peer_id, &id, @@ -1267,6 +1270,7 @@ where listened_addrs: SmallVec::new(), external_addrs: Addresses::default(), banned_peers: HashSet::new(), + banned_connections: HashSet::new(), pending_event: None, substream_upgrade_protocol_override: self.substream_upgrade_protocol_override, } @@ -1855,6 +1859,7 @@ mod tests { swarm2.behaviour.inject_connection_established, swarm2.behaviour.inject_connection_closed ); + assert_eq!(swarm2.banned_connections.len(), 0); }) } } From 7aebe91142b0f1150c92ce400d7f34842814f98a Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 19 Nov 2021 10:40:04 -0500 Subject: [PATCH 04/21] Fix existing ban test. --- swarm/Cargo.toml | 1 + swarm/src/lib.rs | 93 ++++++++++------------------------------------- swarm/src/test.rs | 40 ++++++++++++++++++-- 3 files changed, 57 insertions(+), 77 deletions(-) diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 2c5da850070..6d3ee48caa4 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -19,6 +19,7 @@ smallvec = "1.6.1" void = "1" futures-timer = "3.0.2" instant = "0.1.11" +env_logger = "0.9" [dev-dependencies] libp2p = { path = "../", default-features = false, features = ["yamux", "plaintext"] } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 30a4043689b..3a62f8681c1 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1468,15 +1468,6 @@ mod tests { TBehaviour: NetworkBehaviour, <::Handler as ProtocolsHandler>::OutEvent: Clone, { - for s in &[swarm1, swarm2] { - if s.behaviour.inject_connection_established.len() > 0 { - assert_eq!(s.behaviour.inject_connected.len(), 1); - } else { - assert_eq!(s.behaviour.inject_connected.len(), 0); - } - assert!(s.behaviour.inject_connection_closed.is_empty()); - assert!(s.behaviour.inject_disconnected.is_empty()); - } [swarm1, swarm2] .iter() .all(|s| s.behaviour.inject_connection_established.len() == num_connections) @@ -1491,10 +1482,6 @@ mod tests { TBehaviour: NetworkBehaviour, <::Handler as ProtocolsHandler>::OutEvent: Clone { - for s in &[swarm1, swarm2] { - assert_eq!(s.behaviour.inject_connection_established.len(), 0); - assert_eq!(s.behaviour.inject_connected.len(), 0); - } [swarm1, swarm2] .iter() .all(|s| s.behaviour.inject_connection_closed.len() == num_connections) @@ -1508,7 +1495,12 @@ mod tests { /// /// The test expects both behaviours to be notified via pairs of /// inject_connected / inject_disconnected as well as - /// inject_connection_established / inject_connection_closed calls. + /// inject_connection_established / inject_connection_closed calls + /// while unbanned. + /// + /// While the ban is in effect, further dials occur. For these connections no + /// `inject_connected`, `inject_connection_established`, `inject_disconnected`, + /// `inject_connection_closed` calls should be registered. #[test] fn test_connect_disconnect_ban() { // Since the test does not try to open any substreams, we can @@ -1545,25 +1537,33 @@ mod tests { match state { State::Connecting => { if swarms_connected(&swarm1, &swarm2, num_connections) { - if banned { + // Behaviours get the notification of `num_connections` connections if: + // - They are connecting for the first time. Here neither banning nor + // unbanning has happened. + // - Banning has ocurred and unbanning too. If only banning has + // occurred, the behaviours should have not gotten connection + // notifications. + assert!(banned == unbanned); + if unbanned { return Poll::Ready(()); } swarm2.ban_peer_id(swarm1_id.clone()); - swarm1.behaviour.reset(); - swarm2.behaviour.reset(); banned = true; state = State::Disconnecting; } } State::Disconnecting => { if swarms_disconnected(&swarm1, &swarm2, num_connections) { + if banned { + swarm1.dial(addr2.clone()).unwrap(); + state = State::Connecting; + continue; + } if unbanned { return Poll::Ready(()); } // Unban the first peer and reconnect. swarm2.unban_peer_id(swarm1_id.clone()); - swarm1.behaviour.reset(); - swarm2.behaviour.reset(); unbanned = true; for _ in 0..num_connections { swarm2.dial(addr1.clone()).unwrap(); @@ -1807,59 +1807,4 @@ mod tests { } })) } - - #[test] - fn test_banning_respects_contract() { - let handler_proto = DummyProtocolsHandler { - keep_alive: KeepAlive::Yes, - }; - - let mut swarm1 = new_test_swarm::<_, ()>(handler_proto.clone()); - let mut swarm2 = new_test_swarm::<_, ()>(handler_proto); - - let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); - let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); - - swarm1.listen_on(addr1.clone().into()).unwrap(); - swarm2.listen_on(addr2.clone().into()).unwrap(); - - let swarm1_id = *swarm1.local_peer_id(); - - async fn poll( - id: usize, - swarm: &mut Swarm>>, - ) { - let ev = swarm.select_next_some().await; - log::info!("[{}] {:?}", id, ev); - } - - executor::block_on(async { - // Wait for the swarms to establish listeners - poll(1, &mut swarm1).await; - poll(2, &mut swarm2).await; - - swarm1.dial(addr2.clone()).unwrap(); - log::info!("Swarm 2 banning swarm 1\n\n"); - swarm2.ban_peer_id(swarm1_id); - - // Incoming connection - poll(2, &mut swarm2).await; - - // Connection established - poll(2, &mut swarm2).await; - // Connection established - poll(1, &mut swarm1).await; - - // Both see connections as closed - poll(1, &mut swarm1).await; - poll(2, &mut swarm2).await; - - // Check what swarm2's behaviour got - assert_eq!( - swarm2.behaviour.inject_connection_established, - swarm2.behaviour.inject_connection_closed - ); - assert_eq!(swarm2.banned_connections.len(), 0); - }) - } } diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 54a806ca6d2..c1984409b94 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -184,6 +184,13 @@ where } fn inject_connected(&mut self, peer: &PeerId) { + assert!( + self.inject_connection_established + .iter() + .find(|(peer_id, _, _)| peer_id == peer) + .is_some(), + "`inject_connected` is called after at least one `inject_connection_established`." + ); self.inject_connected.push(peer.clone()); self.inner.inject_connected(peer); } @@ -201,7 +208,14 @@ where } fn inject_disconnected(&mut self, peer: &PeerId) { - self.inject_disconnected.push(peer.clone()); + assert!( + self.inject_connection_closed + .iter() + .find(|(peer_id, _, _)| peer_id == peer) + .is_some(), + "`inject_disconnected` is called after at least one `inject_connection_closed`." + ); + self.inject_disconnected.push(*peer); self.inner.inject_disconnected(peer); } @@ -212,8 +226,13 @@ where e: &ConnectedPoint, handler: ::Handler, ) { - self.inject_connection_closed - .push((p.clone(), c.clone(), e.clone())); + let connection = (p.clone(), c.clone(), e.clone()); + assert!( + self.inject_connection_established.contains(&connection), + "`inject_connection_closed` is called only for connections for \ + which `inject_connection_established` was called first." + ); + self.inject_connection_closed.push(connection); self.inner.inject_connection_closed(p, c, e, handler); } @@ -223,6 +242,21 @@ where c: ConnectionId, e: <::Handler as ProtocolsHandler>::OutEvent, ) { + assert!( + self.inject_connection_established + .iter() + .find(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id) + .is_some(), + "`inject_event` is called for reported connections." + ); + assert!( + self.inject_connection_closed + .iter() + .find(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id) + .is_none(), + "`inject_event` is never called for closed connections." + ); + self.inject_event.push((p.clone(), c.clone(), e.clone())); self.inner.inject_event(p, c, e); } From f8ab8e0efb413e4a16d583a7f50029a7603e1405 Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 19 Nov 2021 13:26:56 -0500 Subject: [PATCH 05/21] checkpoint --- swarm/src/lib.rs | 149 ++++++++++++++++++++++++++++------------------ swarm/src/test.rs | 1 + 2 files changed, 93 insertions(+), 57 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 3a62f8681c1..cab513361da 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1509,6 +1509,7 @@ mod tests { keep_alive: KeepAlive::Yes, }; + env_logger::init(); let mut swarm1 = new_test_swarm::<_, ()>(handler_proto.clone()); let mut swarm2 = new_test_swarm::<_, ()>(handler_proto); @@ -1520,63 +1521,104 @@ mod tests { let swarm1_id = *swarm1.local_peer_id(); - let mut banned = false; - let mut unbanned = false; + enum Stage { + /// Waiting for the peers to connect. Banning has not occurred. + Connecting, + /// Ban occurred. + Banned, + // Ban is in place and a dial is ongoing. + BannedDial, + // Mid-ban dial was registered and the peer was unbanned. + Unbanned, + // There are dial attempts ongoing for the no longer banned peers. + Reconnecting, + } - let num_connections = 10; + let num_connections = 2; for _ in 0..num_connections { swarm1.dial(addr2.clone()).unwrap(); } - let mut state = State::Connecting; - executor::block_on(future::poll_fn(move |cx| { - loop { - let poll1 = Swarm::poll_next_event(Pin::new(&mut swarm1), cx); - let poll2 = Swarm::poll_next_event(Pin::new(&mut swarm2), cx); - match state { - State::Connecting => { - if swarms_connected(&swarm1, &swarm2, num_connections) { - // Behaviours get the notification of `num_connections` connections if: - // - They are connecting for the first time. Here neither banning nor - // unbanning has happened. - // - Banning has ocurred and unbanning too. If only banning has - // occurred, the behaviours should have not gotten connection - // notifications. - assert!(banned == unbanned); - if unbanned { - return Poll::Ready(()); - } - swarm2.ban_peer_id(swarm1_id.clone()); - banned = true; - state = State::Disconnecting; - } + let mut swarm1_expected_conns = num_connections; + let mut swarm2_expected_conns = num_connections; + + log::info!("Starting test"); + let mut stage = Stage::Connecting; + + executor::block_on(future::poll_fn(move |cx| loop { + let poll1 = Swarm::poll_next_event(Pin::new(&mut swarm1), cx); + let poll2 = Swarm::poll_next_event(Pin::new(&mut swarm2), cx); + match stage { + Stage::Connecting => { + if swarms_connected(&swarm1, &swarm2, num_connections) { + log::info!("1"); + // Setup to test that already established connections are correctly closed + // and reported as such after the peer in banned. + swarm2.ban_peer_id(swarm1_id.clone()); + stage = Stage::Banned; } - State::Disconnecting => { - if swarms_disconnected(&swarm1, &swarm2, num_connections) { - if banned { - swarm1.dial(addr2.clone()).unwrap(); - state = State::Connecting; - continue; - } - if unbanned { - return Poll::Ready(()); - } - // Unban the first peer and reconnect. - swarm2.unban_peer_id(swarm1_id.clone()); - unbanned = true; - for _ in 0..num_connections { - swarm2.dial(addr1.clone()).unwrap(); - } - state = State::Connecting; + } + Stage::Banned => { + if swarms_disconnected(&swarm1, &swarm2, num_connections) { + log::info!("2"); + // Setup to test that new connections of banned peers are not reported. + swarm1.dial(addr2.clone()).unwrap(); + swarm1_expected_conns += 1; + stage = Stage::BannedDial; + } + } + Stage::BannedDial => { + if swarm1.behaviour.inject_connection_established.len() == swarm1_expected_conns + && swarm2.network_info().num_peers() == 1 + { + log::info!("3"); + // The banned connection was established. Check that then banning swarm was + // not reported about the connection. + assert_eq!( + swarm2.behaviour.inject_connection_established.len(), swarm2_expected_conns, + "No additional closed connections should be reported for the banned peer" + ); + // Setup to test that the banned connection is not reported upon closing + // even if the peer is unbanned. + swarm2.unban_peer_id(swarm1_id); + stage = Stage::Unbanned; + } + } + Stage::Unbanned => { + if swarm2.network_info().num_peers() == 0 { + log::info!("4"); + // The banned connection has closed. Check that it was not reported. + assert_eq!( + swarm2.behaviour.inject_connection_closed.len(), swarm2_expected_conns, + "No additional closed connections should be reported for the banned peer" + ); + assert!(swarm2.banned_connections.is_empty()); + // Setup to test that a ban lifted does not affect future connections. + for _ in 0..num_connections { + swarm1.dial(addr2.clone()).unwrap(); } + swarm1_expected_conns += num_connections; + swarm2_expected_conns += num_connections; + stage = Stage::Reconnecting; } } - - if poll1.is_pending() && poll2.is_pending() { - return Poll::Pending; + Stage::Reconnecting => { + if swarm1.behaviour.inject_connection_established.len() == swarm1_expected_conns + { + log::info!("5"); + assert_eq!( + swarm2.behaviour.inject_connection_established.len(), + swarm2_expected_conns + ); + return Poll::Ready(()); + } } } + + if poll1.is_pending() && poll2.is_pending() { + return Poll::Pending; + } })) } @@ -1625,8 +1667,6 @@ mod tests { swarm2 .disconnect_peer_id(swarm1_id.clone()) .expect("Error disconnecting"); - swarm1.behaviour.reset(); - swarm2.behaviour.reset(); state = State::Disconnecting; } } @@ -1636,8 +1676,6 @@ mod tests { return Poll::Ready(()); } reconnected = true; - swarm1.behaviour.reset(); - swarm2.behaviour.reset(); for _ in 0..num_connections { swarm2.dial(addr1.clone()).unwrap(); } @@ -1701,8 +1739,6 @@ mod tests { connection: CloseConnection::All, }, ); - swarm1.behaviour.reset(); - swarm2.behaviour.reset(); state = State::Disconnecting; } } @@ -1712,8 +1748,6 @@ mod tests { return Poll::Ready(()); } reconnected = true; - swarm1.behaviour.reset(); - swarm2.behaviour.reset(); for _ in 0..num_connections { swarm2.dial(addr1.clone()).unwrap(); } @@ -1780,16 +1814,17 @@ mod tests { ); Some(conn_id) }; - swarm1.behaviour.reset(); - swarm2.behaviour.reset(); state = State::Disconnecting; } } State::Disconnecting => { for s in &[&swarm1, &swarm2] { assert_eq!(s.behaviour.inject_disconnected.len(), 0); - assert_eq!(s.behaviour.inject_connection_established.len(), 0); - assert_eq!(s.behaviour.inject_connected.len(), 0); + assert_eq!( + s.behaviour.inject_connection_established.len(), + num_connections + ); + assert_eq!(s.behaviour.inject_connected.len(), 1); } if [&swarm1, &swarm2] .iter() diff --git a/swarm/src/test.rs b/swarm/src/test.rs index c1984409b94..0bc6c0b7748 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -144,6 +144,7 @@ where } } + #[allow(dead_code)] pub fn reset(&mut self) { self.addresses_of_peer = Vec::new(); self.inject_connected = Vec::new(); From eefc25d5dffdb464afa5d30e94d7d0eaad42b73e Mon Sep 17 00:00:00 2001 From: Diva M Date: Fri, 19 Nov 2021 13:35:31 -0500 Subject: [PATCH 06/21] remove log init --- swarm/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index cab513361da..51027634dbf 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1509,7 +1509,6 @@ mod tests { keep_alive: KeepAlive::Yes, }; - env_logger::init(); let mut swarm1 = new_test_swarm::<_, ()>(handler_proto.clone()); let mut swarm2 = new_test_swarm::<_, ()>(handler_proto); From 2643b6ca5f92509a4133f30d3f2f81653d5b1ff7 Mon Sep 17 00:00:00 2001 From: Diva M Date: Sat, 20 Nov 2021 12:33:47 -0500 Subject: [PATCH 07/21] Deal with edge case and fix test --- core/src/connection.rs | 2 +- core/src/connection/pool.rs | 19 ++++--- core/src/network.rs | 8 +-- core/src/network/event.rs | 12 ++--- swarm/src/lib.rs | 101 ++++++++++++++++++++++++------------ swarm/src/test.rs | 2 +- 6 files changed, 89 insertions(+), 55 deletions(-) diff --git a/core/src/connection.rs b/core/src/connection.rs index 961eb4abc0e..f65830fa551 100644 --- a/core/src/connection.rs +++ b/core/src/connection.rs @@ -43,7 +43,7 @@ use substream::{Muxing, SubstreamEvent}; /// Connection identifier. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct ConnectionId(usize); +pub struct ConnectionId(pub usize); impl ConnectionId { /// Creates a `ConnectionId` from a non-negative integer. diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index 163da2178f6..a50fd84c6f3 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -45,7 +45,7 @@ use std::{ collections::{hash_map, HashMap}, convert::TryFrom as _, fmt, - num::{NonZeroU32, NonZeroU8}, + num::NonZeroU8, pin::Pin, task::Context, task::Poll, @@ -156,7 +156,7 @@ where /// A new connection has been established. ConnectionEstablished { connection: EstablishedConnection<'a, THandlerInEvent>, - num_established: NonZeroU32, + established_ids: Vec, /// [`Some`] when the new connection is an outgoing connection. /// Addresses are dialed in parallel. Contains the addresses and errors /// of dial attempts that failed before the one successful dial. @@ -183,8 +183,8 @@ where error: Option>>, /// A reference to the pool that used to manage the connection. pool: &'a mut Pool, - /// The remaining number of established connections to the same peer. - num_established: u32, + /// The remaining established connections to the same peer. + established_ids: Vec, handler: THandler::Handler, }, @@ -693,15 +693,15 @@ where let EstablishedConnectionInfo { endpoint, .. } = connections.remove(&id).expect("Connection to be present"); self.counters.dec_established(&endpoint); - let num_established = u32::try_from(connections.len()).unwrap(); - if num_established == 0 { + let established_ids: Vec = connections.keys().cloned().collect(); + if established_ids.is_empty() { self.established.remove(&peer_id); } return Poll::Ready(PoolEvent::ConnectionClosed { id, connected: Connected { endpoint, peer_id }, error, - num_established, + established_ids, pool: self, handler, }); @@ -849,8 +849,7 @@ where // Add the connection to the pool. let conns = self.established.entry(peer_id).or_default(); - let num_established = NonZeroU32::new(u32::try_from(conns.len() + 1).unwrap()) - .expect("n + 1 is always non-zero; qed"); + let established = conns.keys().cloned().collect(); self.counters.inc_established(&endpoint); let (command_sender, command_receiver) = @@ -883,7 +882,7 @@ where Some(PoolConnection::Established(connection)) => { return Poll::Ready(PoolEvent::ConnectionEstablished { connection, - num_established, + established_ids: established, concurrent_dial_errors, }) } diff --git a/core/src/network.rs b/core/src/network.rs index 3478680bc02..b0ff46f1830 100644 --- a/core/src/network.rs +++ b/core/src/network.rs @@ -396,11 +396,11 @@ where Poll::Pending => return Poll::Pending, Poll::Ready(PoolEvent::ConnectionEstablished { connection, - num_established, + established_ids, concurrent_dial_errors, }) => NetworkEvent::ConnectionEstablished { connection, - num_established, + established_ids, concurrent_dial_errors, }, Poll::Ready(PoolEvent::PendingOutboundConnectionError { @@ -435,13 +435,13 @@ where id, connected, error, - num_established, + established_ids, handler, .. }) => NetworkEvent::ConnectionClosed { id, connected, - num_established, + established_ids, error, handler, }, diff --git a/core/src/network/event.rs b/core/src/network/event.rs index 6e016e82159..b79fb41c289 100644 --- a/core/src/network/event.rs +++ b/core/src/network/event.rs @@ -29,7 +29,7 @@ use crate::{ transport::{Transport, TransportError}, Multiaddr, PeerId, }; -use std::{fmt, num::NonZeroU32}; +use std::fmt; /// Event that can happen on the `Network`. pub enum NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler> @@ -100,9 +100,9 @@ where ConnectionEstablished { /// The newly established connection. connection: EstablishedConnection<'a, TInEvent>, - /// The total number of established connections to the same peer, - /// including the one that has just been opened. - num_established: NonZeroU32, + /// The ids of the open connections for the peer, not including the open that was just + /// opened. + established_ids: Vec, /// [`Some`] when the new connection is an outgoing connection. /// Addresses are dialed in parallel. Contains the addresses and errors /// of dial attempts that failed before the one successful dial. @@ -128,8 +128,8 @@ where connected: Connected, /// The error that occurred. error: Option::Error>>, - /// The remaining number of established connections to the same peer. - num_established: u32, + /// The remaining established connections to the same peer. + established_ids: Vec, handler: THandler::Handler, }, diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 51027634dbf..4fee01b1595 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -97,6 +97,7 @@ use smallvec::SmallVec; use std::collections::HashSet; use std::num::{NonZeroU32, NonZeroU8, NonZeroUsize}; use std::{ + convert::TryFrom, error, fmt, io, pin::Pin, task::{Context, Poll}, @@ -276,7 +277,7 @@ where banned_peers: HashSet, /// Connections for which we withhold any reporting. These belong to banned peers. - banned_connections: HashSet, + banned_peer_connections: HashSet, /// Pending event to be delivered to connection handlers /// (or dropped if the peer disconnected) before the `behaviour` @@ -542,6 +543,7 @@ where /// This function has no effect if the peer is already banned. pub fn ban_peer_id(&mut self, peer_id: PeerId) { if self.banned_peers.insert(peer_id) { + log::info!("Banned peer {}", peer_id); if let Some(peer) = self.network.peer(peer_id).into_connected() { peer.disconnect(); } @@ -607,7 +609,7 @@ where Poll::Ready(NetworkEvent::ConnectionEvent { connection, event }) => { let peer = connection.peer_id(); let conn_id = connection.id(); - if !this.banned_connections.contains(&conn_id) { + if !this.banned_peer_connections.contains(&conn_id) { this.behaviour.inject_event(peer, conn_id, event); } else { log::debug!( @@ -624,7 +626,7 @@ where }) => { let peer = connection.peer_id(); let conn_id = connection.id(); - if !this.banned_connections.contains(&conn_id) { + if !this.banned_peer_connections.contains(&conn_id) { this.behaviour.inject_address_change( &peer, &conn_id, @@ -635,14 +637,19 @@ where } Poll::Ready(NetworkEvent::ConnectionEstablished { connection, - num_established, + established_ids, concurrent_dial_errors, }) => { let peer_id = connection.peer_id(); let endpoint = connection.endpoint().clone(); if this.banned_peers.contains(&peer_id) { // Mark the connection for the banned peer as disallowed. - this.banned_connections.insert(connection.id()); + log::info!( + "Register banned connection {} {}", + peer_id, + connection.id().0 + ); + this.banned_peer_connections.insert(connection.id()); this.network .peer(peer_id) .into_connected() @@ -650,11 +657,16 @@ where .disconnect(); return Poll::Ready(SwarmEvent::BannedPeer { peer_id, endpoint }); } else { - log::debug!( - "Connection established: {:?} {:?}; Total (peer): {}.", + let num_established = + NonZeroU32::new(u32::try_from(established_ids.len() + 1).unwrap()) + .expect("n + 1 is always non-zero; qed"); + + log::info!( + "Connection established: {} {} .", connection.peer_id(), - connection.endpoint(), - num_established + connection.id().0, + // connection.endpoint(), + // num_established ); let endpoint = connection.endpoint().clone(); let failed_addresses = concurrent_dial_errors @@ -666,7 +678,13 @@ where &endpoint, failed_addresses.as_ref(), ); - if num_established.get() == 1 { + // The peer is not banned, but there could be previous banned connections + // if the peer was just unbanned. Check if this is the first allowed + // connection. + let first_allowed = established_ids + .into_iter() + .all(|conn_id| this.banned_peer_connections.contains(&conn_id)); + if first_allowed { this.behaviour.inject_connected(&peer_id); } return Poll::Ready(SwarmEvent::ConnectionEstablished { @@ -681,25 +699,40 @@ where id, connected, error, - num_established, + established_ids, handler, }) => { if let Some(error) = error.as_ref() { log::debug!("Connection {:?} closed: {:?}", connected, error); } else { - log::debug!("Connection {:?} closed (active close).", connected); + log::warn!("Connection {:?} closed (active close).", connected); } let peer_id = connected.peer_id; let endpoint = connected.endpoint; - if !this.banned_connections.remove(&id) { + let num_established = u32::try_from(established_ids.len()).unwrap(); + let conn_was_informed = !this.banned_peer_connections.remove(&id); + if conn_was_informed { + log::info!("Closed normal connection {} {}", peer_id, id.0); this.behaviour.inject_connection_closed( &peer_id, &id, &endpoint, handler.into_protocols_handler(), ); - if num_established == 0 { - this.behaviour.inject_disconnected(&peer_id); + + // This connection was informed. Check if this is the last allowed + // connection for the peer. + let last_allowed = established_ids + .into_iter() + .all(|conn_id| this.banned_peer_connections.contains(&conn_id)); + + if last_allowed { + log::info!( + "Peer disconnected: {}. Last closed connection {}", + peer_id, + id.0, + ); + this.behaviour.inject_disconnected(&peer_id) } } return Poll::Ready(SwarmEvent::ConnectionClosed { @@ -1270,7 +1303,7 @@ where listened_addrs: SmallVec::new(), external_addrs: Addresses::default(), banned_peers: HashSet::new(), - banned_connections: HashSet::new(), + banned_peer_connections: HashSet::new(), pending_event: None, substream_upgrade_protocol_override: self.substream_upgrade_protocol_override, } @@ -1533,7 +1566,7 @@ mod tests { Reconnecting, } - let num_connections = 2; + let num_connections = 10; for _ in 0..num_connections { swarm1.dial(addr2.clone()).unwrap(); @@ -1542,7 +1575,6 @@ mod tests { let mut swarm1_expected_conns = num_connections; let mut swarm2_expected_conns = num_connections; - log::info!("Starting test"); let mut stage = Stage::Connecting; executor::block_on(future::poll_fn(move |cx| loop { @@ -1551,7 +1583,9 @@ mod tests { match stage { Stage::Connecting => { if swarms_connected(&swarm1, &swarm2, num_connections) { - log::info!("1"); + assert_eq!(swarm1.behaviour.inject_connected.len(), 1); + assert_eq!(swarm2.behaviour.inject_connected.len(), 1); + // Setup to test that already established connections are correctly closed // and reported as such after the peer in banned. swarm2.ban_peer_id(swarm1_id.clone()); @@ -1559,8 +1593,12 @@ mod tests { } } Stage::Banned => { - if swarms_disconnected(&swarm1, &swarm2, num_connections) { - log::info!("2"); + if swarm1.behaviour.inject_connection_closed.len() == swarm1_expected_conns + && swarm2.behaviour.inject_connection_closed.len() == swarm2_expected_conns + { + assert_eq!(swarm1.behaviour.inject_disconnected.len(), 1); + assert_eq!(swarm2.behaviour.inject_disconnected.len(), 1); + // Setup to test that new connections of banned peers are not reported. swarm1.dial(addr2.clone()).unwrap(); swarm1_expected_conns += 1; @@ -1568,16 +1606,14 @@ mod tests { } } Stage::BannedDial => { - if swarm1.behaviour.inject_connection_established.len() == swarm1_expected_conns - && swarm2.network_info().num_peers() == 1 - { - log::info!("3"); - // The banned connection was established. Check that then banning swarm was + if swarm2.network_info().num_peers() == 1 { + // The banned connection was established. Check that the banning swarm was // not reported about the connection. assert_eq!( swarm2.behaviour.inject_connection_established.len(), swarm2_expected_conns, "No additional closed connections should be reported for the banned peer" ); + // Setup to test that the banned connection is not reported upon closing // even if the peer is unbanned. swarm2.unban_peer_id(swarm1_id); @@ -1586,13 +1622,13 @@ mod tests { } Stage::Unbanned => { if swarm2.network_info().num_peers() == 0 { - log::info!("4"); // The banned connection has closed. Check that it was not reported. assert_eq!( swarm2.behaviour.inject_connection_closed.len(), swarm2_expected_conns, "No additional closed connections should be reported for the banned peer" ); - assert!(swarm2.banned_connections.is_empty()); + assert!(swarm2.banned_peer_connections.is_empty()); + // Setup to test that a ban lifted does not affect future connections. for _ in 0..num_connections { swarm1.dial(addr2.clone()).unwrap(); @@ -1604,12 +1640,11 @@ mod tests { } Stage::Reconnecting => { if swarm1.behaviour.inject_connection_established.len() == swarm1_expected_conns + && swarm2.behaviour.inject_connection_established.len() + == swarm2_expected_conns { - log::info!("5"); - assert_eq!( - swarm2.behaviour.inject_connection_established.len(), - swarm2_expected_conns - ); + assert_eq!(swarm2.behaviour.inject_connected.len(), 2); + assert_eq!(swarm1.behaviour.inject_connected.len(), 3); return Poll::Ready(()); } } diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 0bc6c0b7748..b1fb1f41d3b 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -91,7 +91,7 @@ where /// A `CallTraceBehaviour` is a `NetworkBehaviour` that tracks /// invocations of callback methods and their arguments, wrapping -/// around an inner behaviour. +/// around an inner behaviour. It ensures certain invariants are met. pub struct CallTraceBehaviour where TInner: NetworkBehaviour, From c92dff265bd0a87b58735f299ac74c040a99c958 Mon Sep 17 00:00:00 2001 From: Diva M Date: Sat, 20 Nov 2021 17:25:53 -0500 Subject: [PATCH 08/21] code improvements --- swarm/src/lib.rs | 35 ++++++++++++++--------------------- swarm/src/test.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 4fee01b1595..fdbc3753630 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1572,8 +1572,8 @@ mod tests { swarm1.dial(addr2.clone()).unwrap(); } - let mut swarm1_expected_conns = num_connections; - let mut swarm2_expected_conns = num_connections; + let mut s1_expected_conns = num_connections; + let mut s2_expected_conns = num_connections; let mut stage = Stage::Connecting; @@ -1582,10 +1582,9 @@ mod tests { let poll2 = Swarm::poll_next_event(Pin::new(&mut swarm2), cx); match stage { Stage::Connecting => { - if swarms_connected(&swarm1, &swarm2, num_connections) { - assert_eq!(swarm1.behaviour.inject_connected.len(), 1); - assert_eq!(swarm2.behaviour.inject_connected.len(), 1); - + if swarm1.behaviour.assert_connected(s1_expected_conns, 1) + && swarm2.behaviour.assert_connected(s2_expected_conns, 1) + { // Setup to test that already established connections are correctly closed // and reported as such after the peer in banned. swarm2.ban_peer_id(swarm1_id.clone()); @@ -1593,15 +1592,12 @@ mod tests { } } Stage::Banned => { - if swarm1.behaviour.inject_connection_closed.len() == swarm1_expected_conns - && swarm2.behaviour.inject_connection_closed.len() == swarm2_expected_conns + if swarm1.behaviour.assert_disconnected(s1_expected_conns, 1) + && swarm2.behaviour.assert_disconnected(s2_expected_conns, 1) { - assert_eq!(swarm1.behaviour.inject_disconnected.len(), 1); - assert_eq!(swarm2.behaviour.inject_disconnected.len(), 1); - // Setup to test that new connections of banned peers are not reported. swarm1.dial(addr2.clone()).unwrap(); - swarm1_expected_conns += 1; + s1_expected_conns += 1; stage = Stage::BannedDial; } } @@ -1610,7 +1606,7 @@ mod tests { // The banned connection was established. Check that the banning swarm was // not reported about the connection. assert_eq!( - swarm2.behaviour.inject_connection_established.len(), swarm2_expected_conns, + swarm2.behaviour.inject_connection_established.len(), s2_expected_conns, "No additional closed connections should be reported for the banned peer" ); @@ -1624,7 +1620,7 @@ mod tests { if swarm2.network_info().num_peers() == 0 { // The banned connection has closed. Check that it was not reported. assert_eq!( - swarm2.behaviour.inject_connection_closed.len(), swarm2_expected_conns, + swarm2.behaviour.inject_connection_closed.len(), s2_expected_conns, "No additional closed connections should be reported for the banned peer" ); assert!(swarm2.banned_peer_connections.is_empty()); @@ -1633,18 +1629,15 @@ mod tests { for _ in 0..num_connections { swarm1.dial(addr2.clone()).unwrap(); } - swarm1_expected_conns += num_connections; - swarm2_expected_conns += num_connections; + s1_expected_conns += num_connections; + s2_expected_conns += num_connections; stage = Stage::Reconnecting; } } Stage::Reconnecting => { - if swarm1.behaviour.inject_connection_established.len() == swarm1_expected_conns - && swarm2.behaviour.inject_connection_established.len() - == swarm2_expected_conns + if swarm1.behaviour.assert_connected(s1_expected_conns, 3) + && swarm2.behaviour.assert_connected(s2_expected_conns, 2) { - assert_eq!(swarm2.behaviour.inject_connected.len(), 2); - assert_eq!(swarm1.behaviour.inject_connected.len(), 3); return Poll::Ready(()); } } diff --git a/swarm/src/test.rs b/swarm/src/test.rs index b1fb1f41d3b..2de7b8d30de 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -164,6 +164,40 @@ where pub fn inner(&mut self) -> &mut TInner { &mut self.inner } + + /// Checks that when the expected number of closed connection notifications are received, a + /// given number of expected disconnections have been received as well. + /// + /// Returns if the first condition is met. + pub fn assert_disconnected( + &self, + expected_closed_connections: usize, + expected_disconnections: usize, + ) -> bool { + if self.inject_connection_closed.len() == expected_closed_connections { + assert_eq!(self.inject_disconnected.len(), expected_disconnections); + return true; + } + + false + } + + /// Checks that when the expected number of established connection notifications are received, + /// a given number of expected connections have been received as well. + /// + /// Returns if the first condition is met. + pub fn assert_connected( + &self, + expected_established_connections: usize, + expected_connections: usize, + ) -> bool { + if self.inject_connection_established.len() == expected_established_connections { + assert_eq!(self.inject_connected.len(), expected_connections); + return true; + } + + false + } } impl NetworkBehaviour for CallTraceBehaviour From fd0dd48d370a9fa9550e58a38f19779cb884794c Mon Sep 17 00:00:00 2001 From: Diva M Date: Sat, 20 Nov 2021 17:52:21 -0500 Subject: [PATCH 09/21] remove race condition from test --- swarm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index fdbc3753630..64e766884d8 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1635,7 +1635,7 @@ mod tests { } } Stage::Reconnecting => { - if swarm1.behaviour.assert_connected(s1_expected_conns, 3) + if swarm1.behaviour.inject_connection_established.len() == s1_expected_conns && swarm2.behaviour.assert_connected(s2_expected_conns, 2) { return Poll::Ready(()); From bdf0ff1162df4876652a7f80799490b0f38415f0 Mon Sep 17 00:00:00 2001 From: Diva M Date: Sat, 20 Nov 2021 18:10:48 -0500 Subject: [PATCH 10/21] address some clippy lints --- swarm/src/lib.rs | 24 ++++++++++++------------ swarm/src/test.rs | 15 ++++++--------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 64e766884d8..114b8e921cc 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1548,8 +1548,8 @@ mod tests { let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); - swarm1.listen_on(addr1.clone().into()).unwrap(); - swarm2.listen_on(addr2.clone().into()).unwrap(); + swarm1.listen_on(addr1.clone()).unwrap(); + swarm2.listen_on(addr2.clone()).unwrap(); let swarm1_id = *swarm1.local_peer_id(); @@ -1587,7 +1587,7 @@ mod tests { { // Setup to test that already established connections are correctly closed // and reported as such after the peer in banned. - swarm2.ban_peer_id(swarm1_id.clone()); + swarm2.ban_peer_id(swarm1_id); stage = Stage::Banned; } } @@ -1669,8 +1669,8 @@ mod tests { let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); - swarm1.listen_on(addr1.clone().into()).unwrap(); - swarm2.listen_on(addr2.clone().into()).unwrap(); + swarm1.listen_on(addr1.clone()).unwrap(); + swarm2.listen_on(addr2.clone()).unwrap(); let swarm1_id = *swarm1.local_peer_id(); @@ -1692,7 +1692,7 @@ mod tests { return Poll::Ready(()); } swarm2 - .disconnect_peer_id(swarm1_id.clone()) + .disconnect_peer_id(swarm1_id) .expect("Error disconnecting"); state = State::Disconnecting; } @@ -1738,8 +1738,8 @@ mod tests { let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); - swarm1.listen_on(addr1.clone().into()).unwrap(); - swarm2.listen_on(addr2.clone().into()).unwrap(); + swarm1.listen_on(addr1.clone()).unwrap(); + swarm2.listen_on(addr2.clone()).unwrap(); let swarm1_id = *swarm1.local_peer_id(); @@ -1762,7 +1762,7 @@ mod tests { } swarm2.behaviour.inner().next_action.replace( NetworkBehaviourAction::CloseConnection { - peer_id: swarm1_id.clone(), + peer_id: swarm1_id, connection: CloseConnection::All, }, ); @@ -1810,8 +1810,8 @@ mod tests { let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::()).into(); - swarm1.listen_on(addr1.clone().into()).unwrap(); - swarm2.listen_on(addr2.clone().into()).unwrap(); + swarm1.listen_on(addr1.clone()).unwrap(); + swarm2.listen_on(addr2.clone()).unwrap(); let swarm1_id = *swarm1.local_peer_id(); @@ -1835,7 +1835,7 @@ mod tests { .1; swarm2.behaviour.inner().next_action.replace( NetworkBehaviourAction::CloseConnection { - peer_id: swarm1_id.clone(), + peer_id: swarm1_id, connection: CloseConnection::One(conn_id), }, ); diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 2de7b8d30de..22f7a51fa9b 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -222,8 +222,7 @@ where assert!( self.inject_connection_established .iter() - .find(|(peer_id, _, _)| peer_id == peer) - .is_some(), + .any(|(peer_id, _, _)| peer_id == peer), "`inject_connected` is called after at least one `inject_connection_established`." ); self.inject_connected.push(peer.clone()); @@ -246,8 +245,7 @@ where assert!( self.inject_connection_closed .iter() - .find(|(peer_id, _, _)| peer_id == peer) - .is_some(), + .any(|(peer_id, _, _)| peer_id == peer), "`inject_disconnected` is called after at least one `inject_connection_closed`." ); self.inject_disconnected.push(*peer); @@ -280,15 +278,14 @@ where assert!( self.inject_connection_established .iter() - .find(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id) - .is_some(), + .any(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id), "`inject_event` is called for reported connections." ); assert!( - self.inject_connection_closed + !self + .inject_connection_closed .iter() - .find(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id) - .is_none(), + .any(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id), "`inject_event` is never called for closed connections." ); From 3ccad986fe0663ab2324da23aff6885df6c7b7e0 Mon Sep 17 00:00:00 2001 From: Diva M Date: Sat, 20 Nov 2021 18:22:18 -0500 Subject: [PATCH 11/21] remove debug code --- core/src/connection.rs | 2 +- swarm/Cargo.toml | 2 +- swarm/src/lib.rs | 19 +++---------------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/core/src/connection.rs b/core/src/connection.rs index f65830fa551..961eb4abc0e 100644 --- a/core/src/connection.rs +++ b/core/src/connection.rs @@ -43,7 +43,7 @@ use substream::{Muxing, SubstreamEvent}; /// Connection identifier. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct ConnectionId(pub usize); +pub struct ConnectionId(usize); impl ConnectionId { /// Creates a `ConnectionId` from a non-negative integer. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 6d3ee48caa4..ab8191c5557 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -19,7 +19,7 @@ smallvec = "1.6.1" void = "1" futures-timer = "3.0.2" instant = "0.1.11" -env_logger = "0.9" +env_logger = "0.9.0" [dev-dependencies] libp2p = { path = "../", default-features = false, features = ["yamux", "plaintext"] } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 114b8e921cc..7cf26e5f861 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -543,7 +543,6 @@ where /// This function has no effect if the peer is already banned. pub fn ban_peer_id(&mut self, peer_id: PeerId) { if self.banned_peers.insert(peer_id) { - log::info!("Banned peer {}", peer_id); if let Some(peer) = self.network.peer(peer_id).into_connected() { peer.disconnect(); } @@ -644,11 +643,6 @@ where let endpoint = connection.endpoint().clone(); if this.banned_peers.contains(&peer_id) { // Mark the connection for the banned peer as disallowed. - log::info!( - "Register banned connection {} {}", - peer_id, - connection.id().0 - ); this.banned_peer_connections.insert(connection.id()); this.network .peer(peer_id) @@ -662,11 +656,10 @@ where .expect("n + 1 is always non-zero; qed"); log::info!( - "Connection established: {} {} .", + "Connection established: {:?} {:?}; Total (peer): {}.", connection.peer_id(), - connection.id().0, - // connection.endpoint(), - // num_established + connection.endpoint(), + num_established ); let endpoint = connection.endpoint().clone(); let failed_addresses = concurrent_dial_errors @@ -712,7 +705,6 @@ where let num_established = u32::try_from(established_ids.len()).unwrap(); let conn_was_informed = !this.banned_peer_connections.remove(&id); if conn_was_informed { - log::info!("Closed normal connection {} {}", peer_id, id.0); this.behaviour.inject_connection_closed( &peer_id, &id, @@ -727,11 +719,6 @@ where .all(|conn_id| this.banned_peer_connections.contains(&conn_id)); if last_allowed { - log::info!( - "Peer disconnected: {}. Last closed connection {}", - peer_id, - id.0, - ); this.behaviour.inject_disconnected(&peer_id) } } From 5e7750ff7d9bc2b76ac92eb681ee48ad81a5d365 Mon Sep 17 00:00:00 2001 From: Diva M Date: Sun, 21 Nov 2021 06:12:30 -0500 Subject: [PATCH 12/21] self review updates --- core/src/connection/pool.rs | 4 ++-- core/src/network/event.rs | 2 +- swarm/Cargo.toml | 1 - swarm/src/lib.rs | 10 ++++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index a50fd84c6f3..0f082d7328b 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -849,7 +849,7 @@ where // Add the connection to the pool. let conns = self.established.entry(peer_id).or_default(); - let established = conns.keys().cloned().collect(); + let established_ids = conns.keys().cloned().collect(); self.counters.inc_established(&endpoint); let (command_sender, command_receiver) = @@ -882,7 +882,7 @@ where Some(PoolConnection::Established(connection)) => { return Poll::Ready(PoolEvent::ConnectionEstablished { connection, - established_ids: established, + established_ids, concurrent_dial_errors, }) } diff --git a/core/src/network/event.rs b/core/src/network/event.rs index b79fb41c289..726d7b55ff5 100644 --- a/core/src/network/event.rs +++ b/core/src/network/event.rs @@ -100,7 +100,7 @@ where ConnectionEstablished { /// The newly established connection. connection: EstablishedConnection<'a, TInEvent>, - /// The ids of the open connections for the peer, not including the open that was just + /// The ids of the open connections for the peer, not including the one that has just been /// opened. established_ids: Vec, /// [`Some`] when the new connection is an outgoing connection. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index ab8191c5557..2c5da850070 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -19,7 +19,6 @@ smallvec = "1.6.1" void = "1" futures-timer = "3.0.2" instant = "0.1.11" -env_logger = "0.9.0" [dev-dependencies] libp2p = { path = "../", default-features = false, features = ["yamux", "plaintext"] } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 7cf26e5f861..cc492de2918 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -608,11 +608,13 @@ where Poll::Ready(NetworkEvent::ConnectionEvent { connection, event }) => { let peer = connection.peer_id(); let conn_id = connection.id(); - if !this.banned_peer_connections.contains(&conn_id) { + if !this.banned_peer_connections.contains(&conn_id) + || this.banned_peers.contains(&peer) + { this.behaviour.inject_event(peer, conn_id, event); } else { log::debug!( - "Ignoring event from disallowed connection: {:?} {:?}.", + "Ignoring event from disallowed connection or peer: {:?} {:?}.", peer, conn_id, ); @@ -655,7 +657,7 @@ where NonZeroU32::new(u32::try_from(established_ids.len() + 1).unwrap()) .expect("n + 1 is always non-zero; qed"); - log::info!( + log::debug!( "Connection established: {:?} {:?}; Total (peer): {}.", connection.peer_id(), connection.endpoint(), @@ -698,7 +700,7 @@ where if let Some(error) = error.as_ref() { log::debug!("Connection {:?} closed: {:?}", connected, error); } else { - log::warn!("Connection {:?} closed (active close).", connected); + log::debug!("Connection {:?} closed (active close).", connected); } let peer_id = connected.peer_id; let endpoint = connected.endpoint; From 48a993b1d1cef3bc3cf1adeb00060f6e3a8151b8 Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 22 Nov 2021 07:45:17 -0500 Subject: [PATCH 13/21] review suggestions for clarity --- core/src/connection/pool.rs | 7 +++++-- core/src/network.rs | 6 +++--- core/src/network/event.rs | 11 ++++++----- swarm/src/lib.rs | 36 ++++++++++++++++++------------------ 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index 0f082d7328b..7ab6275b560 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -156,7 +156,10 @@ where /// A new connection has been established. ConnectionEstablished { connection: EstablishedConnection<'a, THandlerInEvent>, - established_ids: Vec, + /// List of other connections to the same peer. + /// + /// Note: Does not include the connection reported through this event. + other_established_connection_ids: Vec, /// [`Some`] when the new connection is an outgoing connection. /// Addresses are dialed in parallel. Contains the addresses and errors /// of dial attempts that failed before the one successful dial. @@ -882,7 +885,7 @@ where Some(PoolConnection::Established(connection)) => { return Poll::Ready(PoolEvent::ConnectionEstablished { connection, - established_ids, + other_established_connection_ids: established_ids, concurrent_dial_errors, }) } diff --git a/core/src/network.rs b/core/src/network.rs index b0ff46f1830..b9b334a3523 100644 --- a/core/src/network.rs +++ b/core/src/network.rs @@ -396,11 +396,11 @@ where Poll::Pending => return Poll::Pending, Poll::Ready(PoolEvent::ConnectionEstablished { connection, - established_ids, + other_established_connection_ids: established_ids, concurrent_dial_errors, }) => NetworkEvent::ConnectionEstablished { connection, - established_ids, + other_established_connection_ids: established_ids, concurrent_dial_errors, }, Poll::Ready(PoolEvent::PendingOutboundConnectionError { @@ -441,7 +441,7 @@ where }) => NetworkEvent::ConnectionClosed { id, connected, - established_ids, + remaining_established_connection_ids: established_ids, error, handler, }, diff --git a/core/src/network/event.rs b/core/src/network/event.rs index 726d7b55ff5..b70cef8a888 100644 --- a/core/src/network/event.rs +++ b/core/src/network/event.rs @@ -100,9 +100,10 @@ where ConnectionEstablished { /// The newly established connection. connection: EstablishedConnection<'a, TInEvent>, - /// The ids of the open connections for the peer, not including the one that has just been - /// opened. - established_ids: Vec, + /// List of other connections to the same peer. + /// + /// Note: Does not include the connection reported through this event. + other_established_connection_ids: Vec, /// [`Some`] when the new connection is an outgoing connection. /// Addresses are dialed in parallel. Contains the addresses and errors /// of dial attempts that failed before the one successful dial. @@ -128,8 +129,8 @@ where connected: Connected, /// The error that occurred. error: Option::Error>>, - /// The remaining established connections to the same peer. - established_ids: Vec, + /// List of remaining established connections to the same peer. + remaining_established_connection_ids: Vec, handler: THandler::Handler, }, diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index cc492de2918..22c4f35b8b0 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -277,6 +277,9 @@ where banned_peers: HashSet, /// Connections for which we withhold any reporting. These belong to banned peers. + /// + /// Note: Connections to a peer that are established at the time of banning that peer + /// are not added here. Instead they are simply closed. banned_peer_connections: HashSet, /// Pending event to be delivered to connection handlers @@ -613,11 +616,7 @@ where { this.behaviour.inject_event(peer, conn_id, event); } else { - log::debug!( - "Ignoring event from disallowed connection or peer: {:?} {:?}.", - peer, - conn_id, - ); + log::debug!("Ignoring event from banned peer: {} {:?}.", peer, conn_id); } } Poll::Ready(NetworkEvent::AddressChange { @@ -638,13 +637,14 @@ where } Poll::Ready(NetworkEvent::ConnectionEstablished { connection, - established_ids, + other_established_connection_ids: established_ids, concurrent_dial_errors, }) => { let peer_id = connection.peer_id(); let endpoint = connection.endpoint().clone(); if this.banned_peers.contains(&peer_id) { - // Mark the connection for the banned peer as disallowed. + // Mark the connection for the banned peer as banned, thus withholding any + // future events from the connection to the behaviour. this.banned_peer_connections.insert(connection.id()); this.network .peer(peer_id) @@ -674,12 +674,12 @@ where failed_addresses.as_ref(), ); // The peer is not banned, but there could be previous banned connections - // if the peer was just unbanned. Check if this is the first allowed + // if the peer was just unbanned. Check if this is the first non-banned // connection. - let first_allowed = established_ids + let first_non_banned = established_ids .into_iter() .all(|conn_id| this.banned_peer_connections.contains(&conn_id)); - if first_allowed { + if first_non_banned { this.behaviour.inject_connected(&peer_id); } return Poll::Ready(SwarmEvent::ConnectionEstablished { @@ -694,7 +694,7 @@ where id, connected, error, - established_ids, + remaining_established_connection_ids: established_ids, handler, }) => { if let Some(error) = error.as_ref() { @@ -714,13 +714,13 @@ where handler.into_protocols_handler(), ); - // This connection was informed. Check if this is the last allowed - // connection for the peer. - let last_allowed = established_ids + // This connection was reported as open to the behaviour. Check if this is + // the last non-banned connection for the peer. + let last_non_banned = established_ids .into_iter() .all(|conn_id| this.banned_peer_connections.contains(&conn_id)); - if last_allowed { + if last_non_banned { this.behaviour.inject_disconnected(&peer_id) } } @@ -1575,7 +1575,7 @@ mod tests { && swarm2.behaviour.assert_connected(s2_expected_conns, 1) { // Setup to test that already established connections are correctly closed - // and reported as such after the peer in banned. + // and reported as such after the peer is banned. swarm2.ban_peer_id(swarm1_id); stage = Stage::Banned; } @@ -1592,8 +1592,8 @@ mod tests { } Stage::BannedDial => { if swarm2.network_info().num_peers() == 1 { - // The banned connection was established. Check that the banning swarm was - // not reported about the connection. + // The banned connection was established. Check that it was not reported to + // the behaviour of the banning swarm. assert_eq!( swarm2.behaviour.inject_connection_established.len(), s2_expected_conns, "No additional closed connections should be reported for the banned peer" From 89979979c3f3ff428942d28921002f1c59d1c1aa Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 22 Nov 2021 07:48:13 -0500 Subject: [PATCH 14/21] last review suggestion --- swarm/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 22c4f35b8b0..5dbe9a54072 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -705,8 +705,8 @@ where let peer_id = connected.peer_id; let endpoint = connected.endpoint; let num_established = u32::try_from(established_ids.len()).unwrap(); - let conn_was_informed = !this.banned_peer_connections.remove(&id); - if conn_was_informed { + let conn_was_reported = !this.banned_peer_connections.remove(&id); + if conn_was_reported { this.behaviour.inject_connection_closed( &peer_id, &id, From 10f7c188813da20147e6c84f114352f7170b8e19 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 22 Nov 2021 14:55:38 +0100 Subject: [PATCH 15/21] *: Bump libp2p-core to v0.31.0 --- CHANGELOG.md | 4 +++ Cargo.toml | 44 ++++++++++++------------- core/CHANGELOG.md | 7 ++++ core/Cargo.toml | 2 +- misc/metrics/CHANGELOG.md | 4 +++ misc/metrics/Cargo.toml | 14 ++++---- misc/peer-id-generator/Cargo.toml | 2 +- muxers/mplex/CHANGELOG.md | 4 +++ muxers/mplex/Cargo.toml | 4 +-- muxers/yamux/CHANGELOG.md | 4 +++ muxers/yamux/Cargo.toml | 4 +-- protocols/floodsub/CHANGELOG.md | 4 +++ protocols/floodsub/Cargo.toml | 6 ++-- protocols/gossipsub/CHANGELOG.md | 4 +++ protocols/gossipsub/Cargo.toml | 6 ++-- protocols/identify/CHANGELOG.md | 4 +++ protocols/identify/Cargo.toml | 6 ++-- protocols/kad/CHANGELOG.md | 4 +++ protocols/kad/Cargo.toml | 6 ++-- protocols/mdns/CHANGELOG.md | 4 +++ protocols/mdns/Cargo.toml | 6 ++-- protocols/ping/CHANGELOG.md | 4 +++ protocols/ping/Cargo.toml | 6 ++-- protocols/relay/CHANGELOG.md | 4 +++ protocols/relay/Cargo.toml | 6 ++-- protocols/rendezvous/CHANGELOG.md | 4 +++ protocols/rendezvous/Cargo.toml | 6 ++-- protocols/request-response/CHANGELOG.md | 4 +++ protocols/request-response/Cargo.toml | 6 ++-- swarm/CHANGELOG.md | 4 +++ swarm/Cargo.toml | 4 +-- transports/deflate/CHANGELOG.md | 4 +++ transports/deflate/Cargo.toml | 4 +-- transports/dns/CHANGELOG.md | 4 +++ transports/dns/Cargo.toml | 4 +-- transports/noise/CHANGELOG.md | 4 +++ transports/noise/Cargo.toml | 4 +-- transports/plaintext/CHANGELOG.md | 4 +++ transports/plaintext/Cargo.toml | 4 +-- transports/tcp/CHANGELOG.md | 4 +++ transports/tcp/Cargo.toml | 4 +-- transports/uds/Cargo.toml | 2 +- transports/wasm-ext/CHANGELOG.md | 4 +++ transports/wasm-ext/Cargo.toml | 4 +-- transports/websocket/CHANGELOG.md | 4 +++ transports/websocket/Cargo.toml | 4 +-- 46 files changed, 170 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3112024c21..05dd888a947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.42.0 [unreleased] + +- Update dependencies. + # Individual crates ## Main APIs diff --git a/Cargo.toml b/Cargo.toml index 7a013d18843..64f61ec3b0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p" edition = "2018" description = "Peer-to-peer networking library" -version = "0.41.1" +version = "0.42.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -71,25 +71,25 @@ futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` featu getrandom = "0.2.3" # Explicit dependency to be used in `wasm-bindgen` feature instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature lazy_static = "1.2" -libp2p-core = { version = "0.30.0", path = "core", default-features = false } -libp2p-floodsub = { version = "0.32.0", path = "protocols/floodsub", optional = true } -libp2p-gossipsub = { version = "0.34.0", path = "./protocols/gossipsub", optional = true } -libp2p-identify = { version = "0.32.0", path = "protocols/identify", optional = true } -libp2p-kad = { version = "0.33.0", path = "protocols/kad", optional = true } -libp2p-metrics = { version = "0.2.0", path = "misc/metrics", optional = true } -libp2p-mplex = { version = "0.30.0", path = "muxers/mplex", optional = true } -libp2p-noise = { version = "0.33.0", path = "transports/noise", optional = true } -libp2p-ping = { version = "0.32.0", path = "protocols/ping", optional = true } -libp2p-plaintext = { version = "0.30.0", path = "transports/plaintext", optional = true } +libp2p-core = { version = "0.31.0", path = "core", default-features = false } +libp2p-floodsub = { version = "0.33.0", path = "protocols/floodsub", optional = true } +libp2p-gossipsub = { version = "0.35.0", path = "./protocols/gossipsub", optional = true } +libp2p-identify = { version = "0.33.0", path = "protocols/identify", optional = true } +libp2p-kad = { version = "0.34.0", path = "protocols/kad", optional = true } +libp2p-metrics = { version = "0.3.0", path = "misc/metrics", optional = true } +libp2p-mplex = { version = "0.31.0", path = "muxers/mplex", optional = true } +libp2p-noise = { version = "0.34.0", path = "transports/noise", optional = true } +libp2p-ping = { version = "0.33.0", path = "protocols/ping", optional = true } +libp2p-plaintext = { version = "0.31.0", path = "transports/plaintext", optional = true } libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true } -libp2p-relay = { version = "0.5.0", path = "protocols/relay", optional = true } -libp2p-rendezvous = { version = "0.2.0", path = "protocols/rendezvous", optional = true } -libp2p-request-response = { version = "0.14.0", path = "protocols/request-response", optional = true } -libp2p-swarm = { version = "0.32.0", path = "swarm" } +libp2p-relay = { version = "0.6.0", path = "protocols/relay", optional = true } +libp2p-rendezvous = { version = "0.3.0", path = "protocols/rendezvous", optional = true } +libp2p-request-response = { version = "0.15.0", path = "protocols/request-response", optional = true } +libp2p-swarm = { version = "0.33.0", path = "swarm" } libp2p-swarm-derive = { version = "0.26.1", path = "swarm-derive" } libp2p-uds = { version = "0.30.0", path = "transports/uds", optional = true } -libp2p-wasm-ext = { version = "0.30.0", path = "transports/wasm-ext", default-features = false, optional = true } -libp2p-yamux = { version = "0.34.0", path = "muxers/yamux", optional = true } +libp2p-wasm-ext = { version = "0.31.0", path = "transports/wasm-ext", default-features = false, optional = true } +libp2p-yamux = { version = "0.35.0", path = "muxers/yamux", optional = true } multiaddr = { version = "0.13.0" } parking_lot = "0.11.0" pin-project = "1.0.0" @@ -97,11 +97,11 @@ rand = "0.7.3" # Explicit dependency to be used in `wasm-bindgen` feature smallvec = "1.6.1" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] -libp2p-deflate = { version = "0.30.0", path = "transports/deflate", optional = true } -libp2p-dns = { version = "0.30.0", path = "transports/dns", optional = true, default-features = false } -libp2p-mdns = { version = "0.33.0", path = "protocols/mdns", optional = true } -libp2p-tcp = { version = "0.30.0", path = "transports/tcp", default-features = false, optional = true } -libp2p-websocket = { version = "0.32.0", path = "transports/websocket", optional = true } +libp2p-deflate = { version = "0.31.0", path = "transports/deflate", optional = true } +libp2p-dns = { version = "0.31.0", path = "transports/dns", optional = true, default-features = false } +libp2p-mdns = { version = "0.34.0", path = "protocols/mdns", optional = true } +libp2p-tcp = { version = "0.31.0", path = "transports/tcp", default-features = false, optional = true } +libp2p-websocket = { version = "0.33.0", path = "transports/websocket", optional = true } [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index dae6e442b36..e57eb6d3bf2 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.31.0 [unreleased] + +- Report concrete connection IDs in `NetworkEvent::ConnectionEstablished` and + `NetworkEvent::ConnectionClosed` (see [PR 2350]). + +[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350/ + # 0.30.1 [2021-11-16] - Use `instant` instead of `wasm-timer` (see [PR 2245]). diff --git a/core/Cargo.toml b/core/Cargo.toml index 8573f45cf7c..f34fb0c9b9e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core" edition = "2018" description = "Core traits and structs of libp2p" -version = "0.30.1" +version = "0.31.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/misc/metrics/CHANGELOG.md b/misc/metrics/CHANGELOG.md index e50aacfc4b3..49c5d2f4190 100644 --- a/misc/metrics/CHANGELOG.md +++ b/misc/metrics/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.3.0 [unreleased] + +- Update dependencies. + # 0.2.0 [2021-11-16] - Include gossipsub metrics (see [PR 2316]). diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index 86e5d042d6f..7ffd5d5d8be 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-metrics" edition = "2018" description = "Metrics for libp2p" -version = "0.2.0" +version = "0.3.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,12 +16,12 @@ kad = ["libp2p-kad"] ping = ["libp2p-ping"] [dependencies] -libp2p-core = { version = "0.30.0", path = "../../core" } -libp2p-gossipsub = { version = "0.34.0", path = "../../protocols/gossipsub", optional = true } -libp2p-identify = { version = "0.32.0", path = "../../protocols/identify", optional = true } -libp2p-kad = { version = "0.33.0", path = "../../protocols/kad", optional = true } -libp2p-ping = { version = "0.32.0", path = "../../protocols/ping", optional = true } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core" } +libp2p-gossipsub = { version = "0.35.0", path = "../../protocols/gossipsub", optional = true } +libp2p-identify = { version = "0.33.0", path = "../../protocols/identify", optional = true } +libp2p-kad = { version = "0.34.0", path = "../../protocols/kad", optional = true } +libp2p-ping = { version = "0.33.0", path = "../../protocols/ping", optional = true } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } open-metrics-client = "0.12.0" [dev-dependencies] diff --git a/misc/peer-id-generator/Cargo.toml b/misc/peer-id-generator/Cargo.toml index da1cad6ba91..beeefc2755b 100644 --- a/misc/peer-id-generator/Cargo.toml +++ b/misc/peer-id-generator/Cargo.toml @@ -11,5 +11,5 @@ categories = ["network-programming", "asynchronous"] publish = false [dependencies] -libp2p-core = { path = "../../core", default-features = false } +libp2p-core = { path = "../../core", default-features = false, version = "0.31.0"} num_cpus = "1.8" diff --git a/muxers/mplex/CHANGELOG.md b/muxers/mplex/CHANGELOG.md index 90573fd513f..05a5c85e399 100644 --- a/muxers/mplex/CHANGELOG.md +++ b/muxers/mplex/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 285fe386517..92a57173051 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-mplex" edition = "2018" description = "Mplex multiplexing protocol for libp2p" -version = "0.30.0" +version = "0.31.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] bytes = "1" futures = "0.3.1" asynchronous-codec = "0.6" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } log = "0.4" nohash-hasher = "0.2" parking_lot = "0.11" diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index 671b6082327..3f0198f2f30 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.35.0 [unreleased] + +- Update dependencies. + # 0.34.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index c9984b6514a..cf23cb0b6b1 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-yamux" edition = "2018" description = "Yamux multiplexing protocol for libp2p" -version = "0.34.0" +version = "0.35.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } parking_lot = "0.11" thiserror = "1.0" yamux = "0.9.0" diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index a183efb88fc..b36a8527743 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.33.0 [unreleased] + +- Update dependencies. + # 0.32.0 [2021-11-16] - Update dependencies. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 1679e6133d5..17452c165c7 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-floodsub" edition = "2018" description = "Floodsub protocol for libp2p" -version = "0.32.0" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"] cuckoofilter = "0.5.0" fnv = "1.0" futures = "0.3.1" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } log = "0.4" prost = "0.9" rand = "0.7" diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index d999bca901e..9df11a94913 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.35.0 [unreleased] + +- Update dependencies. + # 0.34.0 [2021-11-16] - Add topic and mesh metrics (see [PR 2316]). diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 1d496f2cac7..bfb1d3a4cd8 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-gossipsub" edition = "2018" description = "Gossipsub protocol for libp2p" -version = "0.34.0" +version = "0.35.0" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,8 +10,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } bytes = "1.0" byteorder = "1.3.4" fnv = "1.0.7" diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index a70f7de677f..4cf2f32838d 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.33.0 [unreleased] + +- Update dependencies. + # 0.32.0 [2021-11-16] - Use `futures-timer` instead of `wasm-timer` (see [PR 2245]). diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 53bca1ff489..47cc25fc1f4 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-identify" edition = "2018" description = "Nodes identifcation protocol for libp2p" -version = "0.32.0" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,8 +12,8 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" futures-timer = "3.0.2" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } log = "0.4.1" lru = "0.6" prost = "0.9" diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index eae7f458f60..1d234eb005b 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.34.0 [unreleased] + +- Update dependencies. + # 0.33.0 [2021-11-16] - Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 76b4084eb4d..ad3e63040d1 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-kad" edition = "2018" description = "Kademlia protocol for libp2p" -version = "0.33.0" +version = "0.34.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,8 +17,8 @@ fnv = "1.0" asynchronous-codec = "0.6" futures = "0.3.1" log = "0.4" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } prost = "0.9" rand = "0.7.2" sha2 = "0.9.1" diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 54004fd5611..8183e5900a6 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.34.0 [unreleased] + +- Update dependencies. + # 0.33.0 [2021-11-16] - Update dependencies. diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 4fb7eaf08bf..d0fc168e770 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-mdns" edition = "2018" -version = "0.33.0" +version = "0.34.0" description = "Implementation of the libp2p mDNS discovery method" authors = ["Parity Technologies "] license = "MIT" @@ -16,8 +16,8 @@ dns-parser = "0.8.0" futures = "0.3.13" if-watch = "0.2.0" lazy_static = "1.4.0" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index be04a22d33e..a951a64db92 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.33.0 [unreleased] + +- Update dependencies. + # 0.32.0 [2021-11-16] - Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 4bbd70f9324..6d9d09bb7d6 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-ping" edition = "2018" description = "Ping protocol for libp2p" -version = "0.32.0" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"] futures = "0.3.1" futures-timer = "3.0.2" instant = "0.1.11" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } log = "0.4.1" rand = "0.7.2" void = "1.0" diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 8e3f9f082cf..b3c086acafc 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.6.0 [unreleased] + +- Update dependencies. + # 0.5.0 [2021-11-16] - Use `instant` instead of `wasm-timer` (see [PR 2245]). diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index d9d618a61e2..870f044d23d 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-relay" edition = "2018" description = "Communications relaying for libp2p" -version = "0.5.0" +version = "0.6.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -15,8 +15,8 @@ bytes = "1" futures = "0.3.1" futures-timer = "3" instant = "0.1.11" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } log = "0.4" pin-project = "1" prost = "0.9" diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index f8cb7da2120..b8f06f479f6 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.3.0 [unreleased] + +- Update dependencies. + # 0.2.0 [2021-11-16] - Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index c0cba9cd709..6bce91b651f 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-rendezvous" edition = "2018" description = "Rendezvous protocol for libp2p" -version = "0.2.0" +version = "0.3.0" authors = ["The COMIT guys "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"] [dependencies] asynchronous-codec = "0.6" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } prost = "0.9" void = "1" log = "0.4" diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 447ca8c2dbc..932079d1447 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.15.0 [unreleased] + +- Update dependencies. + # 0.14.0 [2021-11-16] - Use `instant` instead of `wasm-timer` (see [PR 2245]). diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 9d18836fd91..6579c20dbc4 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-request-response" edition = "2018" description = "Generic Request/Response Protocols" -version = "0.14.0" +version = "0.15.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,8 +14,8 @@ async-trait = "0.1" bytes = "1" futures = "0.3.1" instant = "0.1.11" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.32.0", path = "../../swarm" } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.33.0", path = "../../swarm" } log = "0.4.11" lru = "0.7" rand = "0.7" diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 5835e8a6e33..bbe4b6b149c 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.33.0 [unreleased] + +- Update dependencies. + # 0.32.0 [2021-11-16] - Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 2c5da850070..a1d1116126d 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.32.0" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] either = "1.6.0" futures = "0.3.1" -libp2p-core = { version = "0.30.0", path = "../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../core", default-features = false } log = "0.4" rand = "0.7" smallvec = "1.6.1" diff --git a/transports/deflate/CHANGELOG.md b/transports/deflate/CHANGELOG.md index b97c911c11c..21fcf062c20 100644 --- a/transports/deflate/CHANGELOG.md +++ b/transports/deflate/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/transports/deflate/Cargo.toml b/transports/deflate/Cargo.toml index 3ce579f0dea..089eca9d66d 100644 --- a/transports/deflate/Cargo.toml +++ b/transports/deflate/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-deflate" edition = "2018" description = "Deflate encryption protocol for libp2p" -version = "0.30.0" +version = "0.31.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } flate2 = "1.0" [dev-dependencies] diff --git a/transports/dns/CHANGELOG.md b/transports/dns/CHANGELOG.md index 08cd3384be0..32e4ef04ca7 100644 --- a/transports/dns/CHANGELOG.md +++ b/transports/dns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 51c9a8fadd1..baea5316795 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-dns" edition = "2018" description = "DNS transport implementation for libp2p" -version = "0.30.0" +version = "0.31.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,7 +10,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } log = "0.4.1" futures = "0.3.1" trust-dns-resolver = { version = "0.20", default-features = false, features = ["system-config"] } diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index cde71a82e46..90729470e87 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.34.0 [unreleased] + +- Update dependencies. + # 0.33.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 680902427d2..9c22752aa4d 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-noise" description = "Cryptographic handshake protocol using the noise framework." -version = "0.33.0" +version = "0.34.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,7 +12,7 @@ bytes = "1" curve25519-dalek = "3.0.0" futures = "0.3.1" lazy_static = "1.2" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } log = "0.4" prost = "0.9" rand = "0.8.3" diff --git a/transports/plaintext/CHANGELOG.md b/transports/plaintext/CHANGELOG.md index 56c8e4c2663..2ce6e439642 100644 --- a/transports/plaintext/CHANGELOG.md +++ b/transports/plaintext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index f09c60b607c..7e3d386a20a 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-plaintext" edition = "2018" description = "Plaintext encryption dummy protocol for libp2p" -version = "0.30.0" +version = "0.31.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] bytes = "1" futures = "0.3.1" asynchronous-codec = "0.6" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } log = "0.4.8" prost = "0.9" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index aa04e30aa40..d091a39f0fb 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 7e56026a628..1970e21478e 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-tcp" edition = "2018" description = "TCP/IP transport protocol for libp2p" -version = "0.30.0" +version = "0.31.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,7 +17,7 @@ if-watch = { version = "0.2.0", optional = true } if-addrs = { version = "0.6.4", optional = true } ipnet = "2.0.0" libc = "0.2.80" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } log = "0.4.11" socket2 = { version = "0.4.0", features = ["all"] } tokio-crate = { package = "tokio", version = "1.0.1", default-features = false, features = ["net"], optional = true } diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index 84aca6450a1..4fe1b4334f4 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [target.'cfg(all(unix, not(target_os = "emscripten")))'.dependencies] async-std = { version = "1.6.2", optional = true } -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } log = "0.4.1" futures = "0.3.1" tokio = { version = "1.0.1", default-features = false, features = ["net"], optional = true } diff --git a/transports/wasm-ext/CHANGELOG.md b/transports/wasm-ext/CHANGELOG.md index eb73938eb20..ea66e34dee9 100644 --- a/transports/wasm-ext/CHANGELOG.md +++ b/transports/wasm-ext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.0 [2021-11-01] - Make default features of `libp2p-core` optional. diff --git a/transports/wasm-ext/Cargo.toml b/transports/wasm-ext/Cargo.toml index d5d0139ba03..2695629ced5 100644 --- a/transports/wasm-ext/Cargo.toml +++ b/transports/wasm-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-wasm-ext" -version = "0.30.0" +version = "0.31.0" authors = ["Pierre Krieger "] edition = "2018" description = "Allows passing in an external transport in a WASM environment" @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" js-sys = "0.3.50" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } parity-send-wrapper = "0.1.0" wasm-bindgen = "0.2.42" wasm-bindgen-futures = "0.4.4" diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index 07f86fdaaff..f387b7b8cc0 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.33.0 [unreleased] + +- Update dependencies. + # v0.32.0 [2021-11-16] - Handle websocket CLOSE with reason code (see [PR 2085]). diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index b82edb388f9..23876b1e761 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-websocket" edition = "2018" description = "WebSocket transport for libp2p" -version = "0.32.0" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] futures-rustls = "0.22" either = "1.5.3" futures = "0.3.1" -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-core = { version = "0.31.0", path = "../../core", default-features = false } log = "0.4.8" quicksink = "0.1" rw-stream-sink = "0.2.0" From 8b2aa9b56901401ef0284064f1bd767ad655e230 Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 22 Nov 2021 09:08:11 -0500 Subject: [PATCH 16/21] remove established_ids everywhere --- core/src/connection/pool.rs | 13 +++++++------ core/src/network.rs | 8 ++++---- swarm/src/lib.rs | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index 7ab6275b560..59d41908f3a 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -187,7 +187,7 @@ where /// A reference to the pool that used to manage the connection. pool: &'a mut Pool, /// The remaining established connections to the same peer. - established_ids: Vec, + remaining_established_connection_ids: Vec, handler: THandler::Handler, }, @@ -696,15 +696,16 @@ where let EstablishedConnectionInfo { endpoint, .. } = connections.remove(&id).expect("Connection to be present"); self.counters.dec_established(&endpoint); - let established_ids: Vec = connections.keys().cloned().collect(); - if established_ids.is_empty() { + let remaining_established_connection_ids: Vec = + connections.keys().cloned().collect(); + if remaining_established_connection_ids.is_empty() { self.established.remove(&peer_id); } return Poll::Ready(PoolEvent::ConnectionClosed { id, connected: Connected { endpoint, peer_id }, error, - established_ids, + remaining_established_connection_ids, pool: self, handler, }); @@ -852,7 +853,7 @@ where // Add the connection to the pool. let conns = self.established.entry(peer_id).or_default(); - let established_ids = conns.keys().cloned().collect(); + let other_established_connection_ids = conns.keys().cloned().collect(); self.counters.inc_established(&endpoint); let (command_sender, command_receiver) = @@ -885,7 +886,7 @@ where Some(PoolConnection::Established(connection)) => { return Poll::Ready(PoolEvent::ConnectionEstablished { connection, - other_established_connection_ids: established_ids, + other_established_connection_ids, concurrent_dial_errors, }) } diff --git a/core/src/network.rs b/core/src/network.rs index b9b334a3523..00946bc96c0 100644 --- a/core/src/network.rs +++ b/core/src/network.rs @@ -396,11 +396,11 @@ where Poll::Pending => return Poll::Pending, Poll::Ready(PoolEvent::ConnectionEstablished { connection, - other_established_connection_ids: established_ids, + other_established_connection_ids, concurrent_dial_errors, }) => NetworkEvent::ConnectionEstablished { connection, - other_established_connection_ids: established_ids, + other_established_connection_ids, concurrent_dial_errors, }, Poll::Ready(PoolEvent::PendingOutboundConnectionError { @@ -435,13 +435,13 @@ where id, connected, error, - established_ids, + remaining_established_connection_ids, handler, .. }) => NetworkEvent::ConnectionClosed { id, connected, - remaining_established_connection_ids: established_ids, + remaining_established_connection_ids, error, handler, }, diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 5dbe9a54072..1846b5eae6c 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -637,7 +637,7 @@ where } Poll::Ready(NetworkEvent::ConnectionEstablished { connection, - other_established_connection_ids: established_ids, + other_established_connection_ids, concurrent_dial_errors, }) => { let peer_id = connection.peer_id(); @@ -653,9 +653,10 @@ where .disconnect(); return Poll::Ready(SwarmEvent::BannedPeer { peer_id, endpoint }); } else { - let num_established = - NonZeroU32::new(u32::try_from(established_ids.len() + 1).unwrap()) - .expect("n + 1 is always non-zero; qed"); + let num_established = NonZeroU32::new( + u32::try_from(other_established_connection_ids.len() + 1).unwrap(), + ) + .expect("n + 1 is always non-zero; qed"); log::debug!( "Connection established: {:?} {:?}; Total (peer): {}.", @@ -676,7 +677,7 @@ where // The peer is not banned, but there could be previous banned connections // if the peer was just unbanned. Check if this is the first non-banned // connection. - let first_non_banned = established_ids + let first_non_banned = other_established_connection_ids .into_iter() .all(|conn_id| this.banned_peer_connections.contains(&conn_id)); if first_non_banned { @@ -694,7 +695,7 @@ where id, connected, error, - remaining_established_connection_ids: established_ids, + remaining_established_connection_ids, handler, }) => { if let Some(error) = error.as_ref() { @@ -704,7 +705,8 @@ where } let peer_id = connected.peer_id; let endpoint = connected.endpoint; - let num_established = u32::try_from(established_ids.len()).unwrap(); + let num_established = + u32::try_from(remaining_established_connection_ids.len()).unwrap(); let conn_was_reported = !this.banned_peer_connections.remove(&id); if conn_was_reported { this.behaviour.inject_connection_closed( @@ -716,7 +718,7 @@ where // This connection was reported as open to the behaviour. Check if this is // the last non-banned connection for the peer. - let last_non_banned = established_ids + let last_non_banned = remaining_established_connection_ids .into_iter() .all(|conn_id| this.banned_peer_connections.contains(&conn_id)); From e80cfff0b4149742551697f0be36fcbda2b5b317 Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 22 Nov 2021 09:09:46 -0500 Subject: [PATCH 17/21] add explanatory note to Swarm::ban_peer_id --- swarm/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 1846b5eae6c..46e5d8422b3 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -547,6 +547,10 @@ where pub fn ban_peer_id(&mut self, peer_id: PeerId) { if self.banned_peers.insert(peer_id) { if let Some(peer) = self.network.peer(peer_id).into_connected() { + // Note that established connections to the now banned peer are closed but not + // added to [`Swarm::banned_peer_connections`]. They have been previously reported + // as open to the behaviour and need be reported as closed once closing the + // connection finishes. peer.disconnect(); } } From 891a88b49ec91c45e685766dba517590c1ef49c2 Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 22 Nov 2021 09:14:11 -0500 Subject: [PATCH 18/21] add swarm's Changelog entry --- swarm/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index bbe4b6b149c..03c6a1a1708 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,7 +1,11 @@ # 0.33.0 [unreleased] +- Patch reporting on banned peers and their non-banned and banned connections (see [PR 2350]). + - Update dependencies. +[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350 + # 0.32.0 [2021-11-16] - Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). From 7c317c014e128e5109531cbe022dca7527851f80 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 24 Nov 2021 16:48:28 +0100 Subject: [PATCH 19/21] CHANGELOG: Move v0.42.0 section down replacing v0.41.1 --- CHANGELOG.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05dd888a947..4f815ab53eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,3 @@ -# 0.42.0 [unreleased] - -- Update dependencies. - # Individual crates ## Main APIs @@ -46,10 +42,32 @@ # `libp2p` facade crate -## Version 0.41.1 [unreleased] +## Version 0.42.0 [unreleased] - Update individual crates. + - `libp2p-core` + - `libp2p-deflate` + - `libp2p-dns` + - `libp2p-floodsub` + - `libp2p-gossipsub` + - `libp2p-identify` + - `libp2p-kad` + - `libp2p-mdns` + - `libp2p-metrics` + - `libp2p-mplex` + - `libp2p-noise` + - `libp2p-ping` + - `libp2p-plaintext` + - `libp2p-relay` + - `libp2p-rendezvous` + - `libp2p-request-response` - `libp2p-swarm-derive` + - `libp2p-swarm` + - `libp2p-tcp` + - `libp2p-uds` + - `libp2p-wasm-ext` + - `libp2p-websocket` + - `libp2p-yamux` ## Version 0.41.0 [2021-11-16] From 1c1ab6673ae92da92cb2701e2264b760ff3d798c Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 24 Nov 2021 14:50:43 -0500 Subject: [PATCH 20/21] DeMorgan is hard --- swarm/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 46e5d8422b3..4d49a70f7a6 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -615,12 +615,12 @@ where Poll::Ready(NetworkEvent::ConnectionEvent { connection, event }) => { let peer = connection.peer_id(); let conn_id = connection.id(); - if !this.banned_peer_connections.contains(&conn_id) + if this.banned_peer_connections.contains(&conn_id) || this.banned_peers.contains(&peer) { - this.behaviour.inject_event(peer, conn_id, event); - } else { log::debug!("Ignoring event from banned peer: {} {:?}.", peer, conn_id); + } else { + this.behaviour.inject_event(peer, conn_id, event); } } Poll::Ready(NetworkEvent::AddressChange { From b43a169294bf02ce4184d5449be1560001d27177 Mon Sep 17 00:00:00 2001 From: Diva M Date: Thu, 25 Nov 2021 11:50:05 -0500 Subject: [PATCH 21/21] address yet another lovely race condition --- swarm/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 4d49a70f7a6..c28bcee9dc4 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -615,9 +615,7 @@ where Poll::Ready(NetworkEvent::ConnectionEvent { connection, event }) => { let peer = connection.peer_id(); let conn_id = connection.id(); - if this.banned_peer_connections.contains(&conn_id) - || this.banned_peers.contains(&peer) - { + if this.banned_peer_connections.contains(&conn_id) { log::debug!("Ignoring event from banned peer: {} {:?}.", peer, conn_id); } else { this.behaviour.inject_event(peer, conn_id, event);