feat(identify): do not implicitly dial on push

Previously, we would implicitly establish a connection when the user wanted to push identify information to a peer. I believe that this is the wrong behaviour. Instead, I am suggesting to log a message that we are skipping the push to this peer.

Additionally, the way this is currently implemented does not make much sense. Dialing a peer takes time. In case we don't have a connection at all, it could be that we drop the push requests because there isn't an active handler and thus we would have unnecessarily established the connection.

Instead of fixing this - which would require buffering the push messages - I think we should just remove the implicit dial.

Pull-Request: #3843.
This commit is contained in:
Thomas Eizinger
2023-04-28 16:06:33 +02:00
committed by GitHub
parent 2f5270ba76
commit e3a1650933
4 changed files with 18 additions and 9 deletions

2
Cargo.lock generated
View File

@@ -2522,7 +2522,7 @@ dependencies = [
[[package]]
name = "libp2p-identify"
version = "0.42.1"
version = "0.42.2"
dependencies = [
"async-std",
"asynchronous-codec",

View File

@@ -1,3 +1,12 @@
## 0.42.2 - unreleased
- Do not implicitly dial a peer upon `identify::Behaviour::push`.
Previously, we would dial each peer in the provided list.
Now, we skip peers that we are not connected to.
See [PR 3843].
[PR 3843]: https://github.com/libp2p/rust-libp2p/pull/3843
## 0.42.1
- Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312].

View File

@@ -3,7 +3,7 @@ name = "libp2p-identify"
edition = "2021"
rust-version = "1.62.0"
description = "Nodes identifcation protocol for libp2p"
version = "0.42.1"
version = "0.42.2"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@@ -25,9 +25,8 @@ use libp2p_identity::PeerId;
use libp2p_identity::PublicKey;
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
use libp2p_swarm::{
dial_opts::DialOpts, AddressScore, ConnectionDenied, ConnectionHandlerUpgrErr, DialError,
ExternalAddresses, ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters,
THandlerInEvent, ToSwarm,
AddressScore, ConnectionDenied, ConnectionHandlerUpgrErr, DialError, ExternalAddresses,
ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters, THandlerInEvent, ToSwarm,
};
use libp2p_swarm::{ConnectionId, THandler, THandlerOutEvent};
use lru::LruCache;
@@ -193,16 +192,17 @@ impl Behaviour {
I: IntoIterator<Item = PeerId>,
{
for p in peers {
if !self.connected.contains_key(&p) {
log::debug!("Not pushing to {p} because we are not connected");
continue;
}
let request = Request {
peer_id: p,
protocol: Protocol::Push,
};
if !self.requests.contains(&request) {
self.requests.push(request);
self.events.push_back(ToSwarm::Dial {
opts: DialOpts::peer_id(p).build(),
});
}
}
}