feat(swarm): allow NetworkBehaviours to create and remove listeners#3292
feat(swarm): allow NetworkBehaviours to create and remove listeners#3292mergify[bot] merged 50 commits intolibp2p:masterfrom
NetworkBehaviours to create and remove listeners#3292Conversation
thomaseizinger
left a comment
There was a problem hiding this comment.
Overall I am in support of this but we should probably wait until we have the connection management story figured out or at least found consensus on #3290.
|
@dariusc93 note that the connection management work, namely #3254, is merged, thus no longer blocking this pull request. |
Thank you for letting me know. I would have to double check, but was it ever decided on rather a |
I think we will need to issue the |
Providing the This can be done outside of this PR too in its own separate PR EDIT: I made a PR at #3567 just to get your thoughts on the change. |
…ibp2p into networkbehaviour-listen
swarm/src/lib.rs
Outdated
| } | ||
| } | ||
| ToSwarm::ListenOn { id, address } => { | ||
| self.transport.listen_on(id, address).ok()?; |
There was a problem hiding this comment.
If this fails, the NetworkBehaviour will never learn about it. I think we need to capture this error and report it back to the NetworkBehaviour as well as issue a ListenerError.
The documentation on ListenerError talks about "non-fatal" errors but I think adding another variant is even more confusing.
There was a problem hiding this comment.
I was thinking about this back during the initial PR, but I assumed it would be alright since ToSwarm::Dial ignores the error. We could do this instead
| self.transport.listen_on(id, address).ok()?; | |
| if let Err(e) = self.transport.listen_on(id, address) { | |
| self.behaviour.on_swarm_event(FromSwarm::ListenerError( | |
| behaviour::ListenerError { | |
| listener_id: id, | |
| err: &e, | |
| }, | |
| )); | |
| } |
So it would notify the behaviour of the error instead of ignoring it.
There was a problem hiding this comment.
I was thinking about this back during the initial PR, but I assumed it would be alright since
ToSwarm::Dialignores the error.
Are we? Probably also something that should be fixed then :)
We could do this instead
Suggested change
self.transport.listen_on(id, address).ok()?; if let Err(e) = self.transport.listen_on(id, address) { self.behaviour.on_swarm_event(FromSwarm::ListenerError( behaviour::ListenerError { listener_id: id, err: &e, }, )); } So it would notify the behaviour of the error instead of ignoring it.
Yep, that looks good to me!
There was a problem hiding this comment.
I was thinking about this back during the initial PR, but I assumed it would be alright since
ToSwarm::Dialignores the error.Are we? Probably also something that should be fixed then :)
Looking at Swarm::dial, it does send the error to the behaviour internally before returning the error itself so it doesnt look to be necessary
EDIT: Overlooked the beginning, but it looks like it doesnt send anything for dial_opts.get_or_parse_peer_id().map_err(DialError::InvalidPeerId), but not sure if this would need to be sent to the behaviour. If it does we could do this internally there in the function by doing
let peer_id = match dial_opts
.get_or_parse_peer_id()
.map_err(DialError::InvalidPeerId)
{
Ok(peer_id) => peer_id,
Err(e) => {
self.behaviour
.on_swarm_event(FromSwarm::DialFailure(DialFailure {
peer_id: None,
error: &e,
connection_id,
}));
return Err(e);
}
};There was a problem hiding this comment.
That error will go away once we have multiformats/rust-multiaddr#73.
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
ListenOn and RemoveListener to ToSwarm
ListenOn and RemoveListener to ToSwarmNetworkBehaviours to create and remove listeners
NetworkBehaviours to create and remove listenersNetworkBehaviours to create and remove listeners
…ibp2p into networkbehaviour-listen
|
@thomaseizinger do the latest commits address your concerns? |
thomaseizinger
left a comment
There was a problem hiding this comment.
A few minor things but overall, happy to merge this design. Thank you for iterating on this with me @dariusc93 !
mxinden
left a comment
There was a problem hiding this comment.
@dariusc93 thanks for being patient with all the feedback. Your work on this is valued.
Description
This extends
ToSwarmto addToSwarm::ListenOnandToSwarm::RemoveListener, which allows creating and removing listeners from aNetworkBehaviour.Resolves #3291.
Notes
Links to any relevant issues
Open Questions
Change checklist