-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: add connection selection logic #2726
base: master
Are you sure you want to change the base?
Conversation
Won't both LAN and WAN have the same performance? |
If the connection between two nodes with a LAN connection is via a WAN address, two situations can occur:
About hairpin mode: https://datatracker.ietf.org/doc/html/rfc5128#autoid-12 |
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 don't really understand the point of this, when is this code called ?
As far I can tell this code is only used when switching from a transient / relayed connection to a direct one after doing hole punching. Which was broken in this PR.
As the dialer already implements similar logic but with inclusion of RTT in the mix.
Each time NewStream is executed, swarm will find the best connection and then create the stream: go-libp2p/p2p/net/swarm/swarm.go Line 471 in 91e1025
|
@wlynxg we are trying to not get into a situation where we have more than one connection in the first place. For example the dialler cancel dialling once we got a success. I've meant to link the code that does this but that harder than it needs to be because the dialler use the worker goroutine pattern. |
The strategy I adopted when implementing p2p myself was to first sort the target addresses according to priority, and then perform traversal connections until one succeeds. To some extent, maintaining multiple connections is not a bad thing. It can quickly switch to a connection with another address when one connection is unavailable. In the implementation of tailscale, it also adopts a multi-link strategy, but it also sets up a dedicated goroutine to regularly perform RTT speed testing on each connection, and then selects the best connection. |
@wlynxg I assumed too much mb. The problem I have with this code is that it's not how go-libp2p operates, your current code looks correct now (as non Transient connections have priority). On a personal note, I do want multiple connections but not at the libp2p layer because they leak to applications, generate stream resets and require applications. There is libp2p/specs#328 on the subject but I believe work there is halted. |
I think the best performance of multi connections is like this: |
libp2p/specs#328 libp2p/specs#406 exists for theses purposes |
Add connection comparison logic and set more preferences to choose better connections: