From d27d16f2a7970c048f2e2350039248b61e6ba5c1 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 2 Apr 2021 12:49:44 +0200 Subject: [PATCH 1/2] protocols/identify: Emit Push event after successful identification push --- protocols/identify/CHANGELOG.md | 3 +++ protocols/identify/src/handler.rs | 5 ++++- protocols/identify/src/identify.rs | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index e652fd8eeef..1312c54743b 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -8,6 +8,9 @@ cf. https://github.com/libp2p/specs/tree/master/identify#identifypush [PR 1999](https://github.com/libp2p/rust-libp2p/pull/1999) +- Emit `IdentifyEvent::Pushed` event after successfully pushing identification + information to peer. + # 0.28.0 [2021-03-17] - Update `libp2p-swarm`. diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 9fd397c0fbc..0f541a86587 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -79,6 +79,8 @@ pub struct IdentifyHandler { pub enum IdentifyHandlerEvent { /// We obtained identification information from the remote. Identified(IdentifyInfo), + /// We actively pushed our identification information to the remote. + IdentificationPushed, /// We received a request for identification. Identify(ReplySubstream), /// Failed to identify the remote. @@ -149,7 +151,8 @@ impl ProtocolsHandler for IdentifyHandler { IdentifyHandlerEvent::Identified(remote_info))); self.keep_alive = KeepAlive::No; } - EitherOutput::Second(()) => {} + EitherOutput::Second(()) => self.events.push( + ProtocolsHandlerEvent::Custom(IdentifyHandlerEvent::IdentificationPushed)) } } diff --git a/protocols/identify/src/identify.rs b/protocols/identify/src/identify.rs index 7430cb3a134..51336879940 100644 --- a/protocols/identify/src/identify.rs +++ b/protocols/identify/src/identify.rs @@ -266,6 +266,13 @@ impl NetworkBehaviour for Identify { score: AddressScore::Finite(1), }); } + IdentifyHandlerEvent::IdentificationPushed => { + self.events.push_back( + NetworkBehaviourAction::GenerateEvent( + IdentifyEvent::Pushed { + peer_id, + })); + } IdentifyHandlerEvent::Identify(sender) => { let observed = self.connected.get(&peer_id) .and_then(|addrs| addrs.get(&connection)) @@ -390,18 +397,25 @@ impl NetworkBehaviour for Identify { /// Event emitted by the `Identify` behaviour. #[derive(Debug)] pub enum IdentifyEvent { - /// Identifying information has been received from a peer. + /// Identification information has been received from a peer. Received { /// The peer that has been identified. peer_id: PeerId, /// The information provided by the peer. 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 { /// The peer that the information has been sent to. 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 { /// The peer with whom the error originated. From ab2a831cd871497fa78dbd3248154bbe8b2a5be0 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 2 Apr 2021 12:52:43 +0200 Subject: [PATCH 2/2] protocols/identify/CHANGELOG: Link pull request --- protocols/identify/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 1312c54743b..9ac05692f5a 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -9,7 +9,8 @@ [PR 1999](https://github.com/libp2p/rust-libp2p/pull/1999) - Emit `IdentifyEvent::Pushed` event after successfully pushing identification - information to peer. + information to peer [PR + 2030](https://github.com/libp2p/rust-libp2p/pull/2030). # 0.28.0 [2021-03-17]