Skip to content

Commit

Permalink
protocols/identify: Emit Push event after successful identification p…
Browse files Browse the repository at this point in the history
…ush (#2030)
  • Loading branch information
mxinden authored Apr 10, 2021
1 parent 6fdfb44 commit 7cf8ac0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions protocols/identify/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
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 [PR
2030](https://github.com/libp2p/rust-libp2p/pull/2030).

# 0.28.0 [2021-03-17]

- Update `libp2p-swarm`.
Expand Down
5 changes: 4 additions & 1 deletion protocols/identify/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NegotiatedSubstream>),
/// Failed to identify the remote.
Expand Down Expand Up @@ -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))
}
}

Expand Down
18 changes: 16 additions & 2 deletions protocols/identify/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7cf8ac0

Please sign in to comment.