Skip to content

Commit 541eba3

Browse files
refactor(identify): simplify reply handling
A `ConnectionHandler` is bound to a single peer. There is no need to embed the `PeerId` in the event that we report to the behaviour, it already knows which peer the event relates to. Pull-Request: #3895.
1 parent 5a867c8 commit 541eba3

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

protocols/identify/src/behaviour.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ impl NetworkBehaviour for Behaviour {
300300
score: AddressScore::Finite(1),
301301
});
302302
}
303-
handler::Event::Identification(peer) => {
303+
handler::Event::Identification => {
304304
self.events
305-
.push_back(ToSwarm::GenerateEvent(Event::Sent { peer_id: peer }));
305+
.push_back(ToSwarm::GenerateEvent(Event::Sent { peer_id }));
306306
}
307307
handler::Event::IdentificationPushed => {
308308
self.events

protocols/identify/src/handler.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct Handler {
5555
>,
5656

5757
/// Pending identification replies, awaiting being sent.
58-
pending_replies: FuturesUnordered<BoxFuture<'static, Result<PeerId, UpgradeError>>>,
58+
pending_replies: FuturesUnordered<BoxFuture<'static, Result<(), UpgradeError>>>,
5959

6060
/// Future that fires when we need to identify the node again.
6161
trigger_next_identify: Delay,
@@ -96,7 +96,7 @@ pub enum Event {
9696
/// We obtained identification information from the remote.
9797
Identified(Info),
9898
/// We replied to an identification request from the remote.
99-
Identification(PeerId),
99+
Identification,
100100
/// We actively pushed our identification information to the remote.
101101
IdentificationPushed,
102102
/// Failed to identify the remote, or to reply to an identification request.
@@ -144,14 +144,10 @@ impl Handler {
144144
) {
145145
match output {
146146
future::Either::Left(substream) => {
147-
let peer_id = self.remote_peer_id;
148147
let info = self.build_info();
149148

150-
self.pending_replies.push(Box::pin(async move {
151-
crate::protocol::send(substream, info).await?;
152-
153-
Ok(peer_id)
154-
}));
149+
self.pending_replies
150+
.push(crate::protocol::send(substream, info).boxed());
155151
}
156152
future::Either::Right(fut) => {
157153
if self.inbound_identify_push.replace(fut).is_some() {
@@ -320,7 +316,7 @@ impl ConnectionHandler for Handler {
320316
// Check for pending replies to send.
321317
if let Poll::Ready(Some(result)) = self.pending_replies.poll_next_unpin(cx) {
322318
let event = result
323-
.map(Event::Identification)
319+
.map(|()| Event::Identification)
324320
.unwrap_or_else(|err| Event::IdentificationError(StreamUpgradeError::Apply(err)));
325321

326322
return Poll::Ready(ConnectionHandlerEvent::Custom(event));

0 commit comments

Comments
 (0)