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

core/transport/memory: Return dialer address in Upgrade event #1724

Merged
merged 7 commits into from
Sep 8, 2020

Conversation

mxinden
Copy link
Member

@mxinden mxinden commented Aug 31, 2020

Previously a Listener would return its own address as the
remote_addr in the ListenerEvent::Upgrade event.

With this commit a Listener returns the dialer address as the
remote_addr in the ListenerEvent::Upgrade event. To do so a
DialFuture registers a port with the global HUB at construction
which is later on unregistered in the Drop implementation of the
dialer's Chan. The sending side of the mpsc::channel registered in
the HUB is dropped at DialFuture construction, thus one can not dial
the dialer port. This mimics the TCP transport behaviour preventing both
dialing and listening on the same TCP port.

Closes #1721.

Add a unit test checking whether the dialer address reported to the
listener on upgrade is unequal to the listeners own address.
Previously a `Listener` would return its own address as the
`remote_addr` in the `ListenerEvent::Upgrade` event.

With this commit a `Listener` returns the dialer address as the
`remote_addr` in the `ListenerEvent::Upgrade` event. To do so a
`DialFuture` registers a port with the global `HUB` at construction
which is later on unregistered in the `Drop` implementation of the
dialer's `Chan`. The sending side of the `mpsc::channel` registered in
the `HUB` is dropped at `DialFuture` construction, thus one can not dial
the dialer port. This mimics the TCP transport behaviour preventing both
dialing and listening on the same TCP port.
Copy link
Contributor

@romanb romanb left a comment

Choose a reason for hiding this comment

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

Looks good to me, I only left minor comments. It seems the current approach was intentional, supposedly mimicking the behaviour of unix domain sockets or udp sockets, though I do not understand the latter reference as UDP can certainly have different source and destination ports. I think generating ephemeral source ports is preferable.

#1721 does not mention what problems the current behaviour causes. Is it simply that the ListenerEvent::Upgrade::remote_addr is the same for all connections with the memory transport?

core/src/transport/memory.rs Outdated Show resolved Hide resolved
core/src/transport/memory.rs Outdated Show resolved Hide resolved
core/src/transport/memory.rs Outdated Show resolved Hide resolved
core/src/transport/memory.rs Show resolved Hide resolved
@mxinden
Copy link
Member Author

mxinden commented Sep 4, 2020

#1721 does not mention what problems the current behaviour causes. Is it simply that the ListenerEvent::Upgrade::remote_addr is the same for all connections with the memory transport?

That was my impression but maybe @tomaka has more information in that regard?

@tomaka
Copy link
Member

tomaka commented Sep 4, 2020

I opened #1721 after looking at Substrate logs and realizing that the local address and send back address were the same.
I admit that I didn't think this through too much. I immediately assumed that it was wrong and opened an issue to not forget about this problem. But it is in the end not obvious than it is a problem.

@mxinden
Copy link
Member Author

mxinden commented Sep 4, 2020

I think the behavior introduced in this pull request is at least more intuitive than the current behavior. Thus I am voting to merge this pull request. Objections?

@romanb
Copy link
Contributor

romanb commented Sep 8, 2020

Please don't forget to update the changelog, either before merging or after.

@mxinden
Copy link
Member Author

mxinden commented Sep 8, 2020

Please don't forget to update the changelog, either before merging or after.

Thanks for the reminder @romanb! It slipped my mind.

@mxinden mxinden merged commit 244c5aa into libp2p:master Sep 8, 2020
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.

Send-back address in MemoryTransport is wrong
3 participants