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

refactor the holepunching code #1355

Merged
merged 4 commits into from
Mar 30, 2022
Merged

refactor the holepunching code #1355

merged 4 commits into from
Mar 30, 2022

Conversation

marten-seemann
Copy link
Contributor

This came out of a discussion with @mxinden and @dennis-tra.

This PR splits the hole punching code into two components:

  1. A Service, which is run on all hosts, independent of their NAT status. This service accepts DCUtR streams and responds to hole punching requests.
  2. A 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.

Copy link
Contributor

@vyzo vyzo 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 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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:

  1. If the hole punch succeeds, the code only gets executed once.
  2. Even if it doesn't, it's 3 timers on the entire connection
    Probably not worth getting into trouble with the Reset API.

Copy link
Contributor

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.

@marten-seemann marten-seemann merged commit 11e6345 into master Mar 30, 2022
@marten-seemann marten-seemann deleted the refactor-holepunching branch April 10, 2022 18:15
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