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

Retry NAT punching without duration on mapping failure #95

Merged
merged 4 commits into from
Sep 14, 2016

Conversation

Kubuxu
Copy link
Member

@Kubuxu Kubuxu commented Aug 26, 2016

Some hardware doesn't support UPnP with durations.

@Kubuxu Kubuxu added the status/in-progress In progress label Aug 26, 2016
@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 26, 2016

//c @whyrusleeping for review

@whyrusleeping
Copy link
Contributor

what happens if we try to set a timeout on a router that doesnt support timeouts?

@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 26, 2016

The request fails, no mapping is created, this means that we didn't punch the NAT.

@whyrusleeping
Copy link
Contributor

If a request fails, can we tell that its because timeouts are not supported and not for some other reason?

@ghost
Copy link

ghost commented Aug 26, 2016

Oh lol I can see that happening :) Apart from this it's good to regularly retry the mapping even if it succeeded in the first place -- routers reset, forget stuff, etc.

Rule of thumb: assume that your router is crap in one way or another until proven otherwise :)

@ghost
Copy link

ghost commented Aug 26, 2016

Apart from this it's good to regularly retry the mapping even if it succeeded in the first place

But that's for a different PR -- LGTM!

@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 26, 2016

@whyrusleeping we can't, go nat gives us only generic error that SOAP call failed.

@lgierth didn't think about that, I will add it, shouldn't be hard.

@whyrusleeping
Copy link
Contributor

Yeah, this LGTM. only thing i would prefer is matching the errors more closely, but i doubt that we would get a consistent set of errors back in all cases

@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 26, 2016

Hmm, it looks like calling for new permanent mapping on the same port with the same agent returns same mapping.

So I can just not short circuit calls in case of permanent mappings.

@whyrusleeping retrying it with no timeout doesn't cause any damage and has just a benefit, worst case it will fail again, best case it will work.

@whyrusleeping
Copy link
Contributor

Yeah, that seems like a good idea to me

@Kubuxu Kubuxu added need/review Needs a review and removed status/in-progress In progress labels Aug 26, 2016
@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 26, 2016

Updated.

@jbenet
Copy link
Contributor

jbenet commented Aug 29, 2016

it looks like calling for new permanent mapping on the same port with the same agent returns same mapping.

For some NATs. Some NATs likely don't do that. Few things are always true in networking but "there is a middlebox that will do that" is a close one.

Basically, try and try again in a variety of ways, and you'll succeed.

@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 29, 2016

@lgierth @whyrusleeping does it look good now?

newport, err := nat.nat.AddPortMapping(m.Protocol(), m.InternalPort(), "http", MappingDuration)
comment := "libp2p"
if m.comment != "" {
comment = "libp2p-" + comment
Copy link
Member

Choose a reason for hiding this comment

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

@Kubuxu erm is there any change you meant comment = "libp2p-" + m.comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, thanks.

log.Debugf("Attempting port map: %s/%d", m.Protocol(), m.InternalPort())
newport, err := nat.nat.AddPortMapping(m.Protocol(), m.InternalPort(), "http", MappingDuration)
comment := "libp2p"
if m.comment != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

what if we get back our own comment here? would this end up with "libp2p-libp2p-libp2p-libp2p...." ?

Copy link
Member Author

Choose a reason for hiding this comment

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

there is m.commentand comment.
comment is temporary variable. I wanted to use context.WithValue to pass it but unfortunately goprocess doesn't have something like it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, i see. I had assumed the comment field came from a prexisting NAT mapping on a router

@whyrusleeping
Copy link
Contributor

@Kubuxu Not sure if we should try to fix it here or not, but we have a race condition in the old code: ipfs/kubo#3205

Can you check and see if a similar issue is present in the new code?

@whyrusleeping
Copy link
Contributor

I think the fix is to just lock around any time we use the 'nat' object

@Kubuxu
Copy link
Member Author

Kubuxu commented Sep 12, 2016

The code didn't change so the issue still will be there.
Will lock around. Or maybe we should chane it into worker loop?

@whyrusleeping
Copy link
Contributor

@Kubuxu hrm... i think for now the easiest thing will be to just lock around it.

@whyrusleeping
Copy link
Contributor

Those changes LGTM, but things don't appear to build

@Kubuxu
Copy link
Member Author

Kubuxu commented Sep 12, 2016

Hmm, I will check if once more.

Some hardware doesn't support UPnP with durations.
If we use same NAT agent and call for the same permanent mapping
again we get the same mapping, no harm done.

If router dies, we will remap again.
Just pros, no cons.
@whyrusleeping
Copy link
Contributor

LGTM

@whyrusleeping whyrusleeping merged commit 86d85de into master Sep 14, 2016
@whyrusleeping whyrusleeping deleted the feat/nat-permanent-retry branch September 14, 2016 22:38
marten-seemann pushed a commit that referenced this pull request Apr 21, 2022
avoid spawning goroutines for canceled dials
marten-seemann added a commit that referenced this pull request Apr 22, 2022
use the assigned role when upgrading a sim open connection
marten-seemann pushed a commit that referenced this pull request Apr 26, 2022
Update github.com/flynn/noise to address nonce handling security issues
marten-seemann pushed a commit that referenced this pull request Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/review Needs a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants