mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-03 19:51:33 +00:00
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:
@ -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(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user