protocols/identify: Emit Push event after successful identification push (#2030)

This commit is contained in:
Max Inden 2021-04-10 19:46:57 +02:00 committed by GitHub
parent 6fdfb44a54
commit 7cf8ac0862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -8,6 +8,10 @@
cf. https://github.com/libp2p/specs/tree/master/identify#identifypush cf. https://github.com/libp2p/specs/tree/master/identify#identifypush
[PR 1999](https://github.com/libp2p/rust-libp2p/pull/1999) [PR 1999](https://github.com/libp2p/rust-libp2p/pull/1999)
- Emit `IdentifyEvent::Pushed` event after successfully pushing identification
information to peer [PR
2030](https://github.com/libp2p/rust-libp2p/pull/2030).
# 0.28.0 [2021-03-17] # 0.28.0 [2021-03-17]
- Update `libp2p-swarm`. - Update `libp2p-swarm`.

View File

@ -79,6 +79,8 @@ pub struct IdentifyHandler {
pub enum IdentifyHandlerEvent { pub enum IdentifyHandlerEvent {
/// We obtained identification information from the remote. /// We obtained identification information from the remote.
Identified(IdentifyInfo), Identified(IdentifyInfo),
/// We actively pushed our identification information to the remote.
IdentificationPushed,
/// We received a request for identification. /// We received a request for identification.
Identify(ReplySubstream<NegotiatedSubstream>), Identify(ReplySubstream<NegotiatedSubstream>),
/// Failed to identify the remote. /// Failed to identify the remote.
@ -149,7 +151,8 @@ impl ProtocolsHandler for IdentifyHandler {
IdentifyHandlerEvent::Identified(remote_info))); IdentifyHandlerEvent::Identified(remote_info)));
self.keep_alive = KeepAlive::No; self.keep_alive = KeepAlive::No;
} }
EitherOutput::Second(()) => {} EitherOutput::Second(()) => self.events.push(
ProtocolsHandlerEvent::Custom(IdentifyHandlerEvent::IdentificationPushed))
} }
} }

View File

@ -266,6 +266,13 @@ impl NetworkBehaviour for Identify {
score: AddressScore::Finite(1), score: AddressScore::Finite(1),
}); });
} }
IdentifyHandlerEvent::IdentificationPushed => {
self.events.push_back(
NetworkBehaviourAction::GenerateEvent(
IdentifyEvent::Pushed {
peer_id,
}));
}
IdentifyHandlerEvent::Identify(sender) => { IdentifyHandlerEvent::Identify(sender) => {
let observed = self.connected.get(&peer_id) let observed = self.connected.get(&peer_id)
.and_then(|addrs| addrs.get(&connection)) .and_then(|addrs| addrs.get(&connection))
@ -390,18 +397,25 @@ impl NetworkBehaviour for Identify {
/// Event emitted by the `Identify` behaviour. /// Event emitted by the `Identify` behaviour.
#[derive(Debug)] #[derive(Debug)]
pub enum IdentifyEvent { pub enum IdentifyEvent {
/// Identifying information has been received from a peer. /// Identification information has been received from a peer.
Received { Received {
/// The peer that has been identified. /// The peer that has been identified.
peer_id: PeerId, peer_id: PeerId,
/// The information provided by the peer. /// The information provided by the peer.
info: IdentifyInfo, info: IdentifyInfo,
}, },
/// Identifying information of the local node has been sent to a peer. /// Identification information of the local node has been sent to a peer in
/// response to an identification request.
Sent { Sent {
/// The peer that the information has been sent to. /// The peer that the information has been sent to.
peer_id: PeerId, peer_id: PeerId,
}, },
/// Identification information of the local node has been actively pushed to
/// a peer.
Pushed {
/// The peer that the information has been sent to.
peer_id: PeerId,
},
/// Error while attempting to identify the remote. /// Error while attempting to identify the remote.
Error { Error {
/// The peer with whom the error originated. /// The peer with whom the error originated.