-
Notifications
You must be signed in to change notification settings - Fork 964
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
feat(swarm): allow NetworkBehaviour
s to create and remove listeners
#3292
Conversation
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.
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
@@ -1121,6 +1121,12 @@ where | |||
} | |||
} | |||
} | |||
ToSwarm::ListenOn { id, address } => { | |||
self.transport.listen_on(id, address).ok()?; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this back during the initial PR, but I assumed it would be alright since
ToSwarm::Dial
ignores 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this back during the initial PR, but I assumed it would be alright since
ToSwarm::Dial
ignores 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ToSwarm
NetworkBehaviour
s to create and remove listeners
NetworkBehaviour
s to create and remove listenersNetworkBehaviour
s to create and remove listeners
…ibp2p into networkbehaviour-listen
@thomaseizinger do the latest commits address your concerns? |
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.
A few minor things but overall, happy to merge this design. Thank you for iterating on this with me @dariusc93 !
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.
Thanks!
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.
@dariusc93 thanks for being patient with all the feedback. Your work on this is valued.
Description
This extends
ToSwarm
to addToSwarm::ListenOn
andToSwarm::RemoveListener
, which allows creating and removing listeners from aNetworkBehaviour
.Resolves #3291.
Notes
Links to any relevant issues
Open Questions
Change checklist