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

feat(mdns): emit ToSwarm::NewExternalAddrOfPeer #5623

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

wlynxg
Copy link

@wlynxg wlynxg commented Oct 5, 2024

Description

implement #5104

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, and thanks for this! Overal looks good too me, just left one comment.

@@ -290,6 +296,11 @@ where
&mut self,
cx: &mut Context<'_>,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
// If there are pending addresses to be emitted we emit them.
if let Some(event) = self.pending_events.pop_front() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you prefer having this here instead of after returning discovered addresses?
I feel it's more correct to do this after returning the addresses and maintaining the previous flow of the pool loop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments.

However, my idea here is that Event::Discovered and ToSwarm::NewExternalAddrOfPeer events are related.

After Event::Discovered is returned in

return Poll::Ready(ToSwarm::GenerateEvent(event));
,
poll will return.
When poll is entered next time, the NewExternalAddrOfPeer event will be returned because there is a NewExternalAddrOfPeer event in the queue.

The result is similar to this:

receive mdns::Event::Discovered Event
mDNS discovered a new peer: 12D3KooWGkhG2wR1mtadqShqiVEBjLHo8xk48ULrbkdftMsBbttR
NewExternalAddrOfPeer: /ip4/192.168.175.1/udp/63808/quic-v1/p2p/12D3KooWGkhG2wR1mtadqShqiVEBjLHo8xk48ULrbkdftMsBbttR, 12D3KooWGkhG2wR1mtadqShqiVEBjLHo8xk48ULrbkdftMsBbttR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, my idea here is that Event::Discovered and ToSwarm::NewExternalAddrOfPeer events are related.

yeah exactly, that's why if we discover multiple addresses we shouldn't return all the NewExternalAddrOfPeer events before the second and subsequent Event::Discovered(discovered) right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your detailed explanation.
I have placed the return time of the NewExternalAddrOfPeer event after the Event::Discovered event.
Please check whether it meets your expectations.

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting, I just found what may be a bug, even if we discover multiple nodes and insert them in discovered we only return the first one added as discovered is a scope variable, right? So what I suggest is dropping discovered and just push everything to pending events, that way we'll have the ToSwarm::GenerateEvent(Event::Discovered(event)) ToSwarm::NewExternalAddrOfPeer events returned sequentially wdyt?

@wlynxg
Copy link
Author

wlynxg commented Oct 23, 2024

This is interesting, I just found what may be a bug, even if we discover multiple nodes and insert them in discovered we only return the first one added as discovered is a scope variable, right? So what I suggest is dropping discovered and just push everything to pending events, that way we'll have the ToSwarm::GenerateEvent(Event::Discovered(event)) ToSwarm::NewExternalAddrOfPeer events returned sequentially wdyt?

This is indeed a very good suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants