-
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
refactor the holepunching code #1355
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.
this is a very welcome refactor; some questions about our favourite topic, the timer.
|
||
// wait for sync to reach the other peer and then punch a hole for it in our NAT | ||
// by attempting a connect to it. | ||
timer := time.NewTimer(synTime) |
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.
why are we creating a timer for every iteration? This is no better than using time.After.
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.
Because a time.Timer
can be stopped, whereas a time.After
cannot.
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.
yes but same inefficiency.
We should move the timer out of the loop, defer stop it, and reset for use.
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.
Yeah, I don't care about the inefficiency in this case:
- If the hole punch succeeds, the code only gets executed once.
- Even if it doesn't, it's 3 timers on the entire connection
Probably not worth getting into trouble with the Reset API.
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.
ok fair enough, lets avoid the foot bazooka.
This came out of a discussion with @mxinden and @dennis-tra.
This PR splits the hole punching code into two components:
Service
, which is run on all hosts, independent of their NAT status. This service accepts DCUtR streams and responds to hole punching requests.HolePuncher
, which is only run on hosts behind a NAT. This service initiates DCUtR streams when it detects new relayed connections.Note: This will be merged for the v0.19.0 release.