-
Notifications
You must be signed in to change notification settings - Fork 959
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
Add addresses field for closing listeners #1485
Changes from 1 commit
f154c81
7e347a0
2867fe8
cd53105
f268456
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -148,6 +148,8 @@ where | |||||
Closed { | ||||||
/// The ID of the listener that closed. | ||||||
listener_id: ListenerId, | ||||||
/// The addresses that the listener was listening on. | ||||||
addresses: SmallVec<[Multiaddr; 4]>, | ||||||
/// Reason for the closure. Contains `Ok(())` if the stream produced `None`, or `Err` | ||||||
/// if the stream produced an error. | ||||||
reason: Result<(), TTrans::Error>, | ||||||
|
@@ -283,12 +285,14 @@ where | |||||
Poll::Ready(None) => { | ||||||
return Poll::Ready(ListenersEvent::Closed { | ||||||
listener_id: *listener_project.id, | ||||||
addresses: listener.addresses.clone(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're destroying the listener, you don't need to clone.
Suggested change
(or, for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with a |
||||||
reason: Ok(()), | ||||||
}) | ||||||
} | ||||||
Poll::Ready(Some(Err(err))) => { | ||||||
return Poll::Ready(ListenersEvent::Closed { | ||||||
listener_id: *listener_project.id, | ||||||
addresses: listener.addresses.clone(), | ||||||
reason: Err(err), | ||||||
}) | ||||||
} | ||||||
|
@@ -351,9 +355,10 @@ where | |||||
.field("listener_id", listener_id) | ||||||
.field("local_addr", local_addr) | ||||||
.finish(), | ||||||
ListenersEvent::Closed { listener_id, reason } => f | ||||||
ListenersEvent::Closed { listener_id, addresses, reason } => f | ||||||
.debug_struct("ListenersEvent::Closed") | ||||||
.field("listener_id", listener_id) | ||||||
.field("addresses", addresses) | ||||||
.field("reason", reason) | ||||||
.finish(), | ||||||
ListenersEvent::Error { listener_id, error } => f | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ use crate::{ | |
}; | ||
use futures::prelude::*; | ||
use std::{error, fmt, hash::Hash}; | ||
use smallvec::SmallVec; | ||
|
||
/// Event that can happen on the `Network`. | ||
pub enum NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> | ||
|
@@ -55,6 +56,8 @@ where | |
ListenerClosed { | ||
/// The listener ID that closed. | ||
listener_id: ListenerId, | ||
/// The addresses that the listener was listening on. | ||
addresses: SmallVec<[Multiaddr; 4]>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark |
||
/// Reason for the closure. Contains `Ok(())` if the stream produced `None`, or `Err` | ||
/// if the stream produced an error. | ||
reason: Result<(), TTrans::Error>, | ||
|
@@ -183,9 +186,10 @@ where | |
.field("listen_addr", listen_addr) | ||
.finish() | ||
} | ||
NetworkEvent::ListenerClosed { listener_id, reason } => { | ||
NetworkEvent::ListenerClosed { listener_id, addresses, reason } => { | ||
f.debug_struct("ListenerClosed") | ||
.field("listener_id", listener_id) | ||
.field("addresses", addresses) | ||
.field("reason", reason) | ||
.finish() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,9 +445,12 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>, | |
this.behaviour.inject_expired_listen_addr(&listen_addr); | ||
return Poll::Ready(SwarmEvent::ExpiredListenAddr(listen_addr)); | ||
} | ||
Poll::Ready(NetworkEvent::ListenerClosed { listener_id, reason }) => { | ||
Poll::Ready(NetworkEvent::ListenerClosed { listener_id, addresses, reason }) => { | ||
log::debug!("Listener {:?}; Closed by {:?}.", listener_id, reason); | ||
this.behaviour.inject_listener_closed(listener_id); | ||
for addr in addresses.iter() { | ||
this.behaviour.inject_expired_listen_addr(addr); | ||
} | ||
Comment on lines
+450
to
+452
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One last change: could you move this above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, done! |
||
} | ||
Poll::Ready(NetworkEvent::ListenerError { listener_id, error }) => | ||
this.behaviour.inject_listener_error(listener_id, &error), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nit, but I'd rather go with
Vec
in order to not expose a third-party dependency in our API.Alternatively, a custom iterator type that wraps around
smallvec::IntoIter
would work as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, will fix and re-spin. Thanks.