Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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