Skip to content

NAT proxy for OpenVPN#850

Merged
zolia merged 4 commits intomasterfrom
feature/MYST-845-nat-proxy-openvpn
Apr 18, 2019
Merged

NAT proxy for OpenVPN#850
zolia merged 4 commits intomasterfrom
feature/MYST-845-nat-proxy-openvpn

Conversation

@zolia
Copy link
Copy Markdown
Contributor

@zolia zolia commented Apr 3, 2019

Implements NATProxy for OpenVPN.

  • if '--experiment-natpunching' is enabled and port auto-configuration fails node starts sending NAT pings
  • backwards compatible with clients without NATPinger functionality (or disabled)
  • NATProxy implementation
  • NATProxy for TCP protocol is bypassed
  • Removed restartable openvpn service code since not required now

What lacks:

  • Think how to test this
  • More testing with actual clients
  • Speed tests

Comment thread nat/traversal/pinger.go Outdated
Comment thread services/openvpn/service/factory.go Outdated
@zolia zolia force-pushed the feature/MYST-845-nat-proxy-openvpn branch 2 times, most recently from 5edea98 to 2ed7fa8 Compare April 15, 2019 15:49
@zolia zolia changed the title POC: initial natproxy frame NAT proxy for OpenVPN Apr 16, 2019
@zolia zolia force-pushed the feature/MYST-845-nat-proxy-openvpn branch 2 times, most recently from 1acfc01 to 6228ea7 Compare April 17, 2019 08:04
Comment thread cmd/di.go Outdated
Comment thread nat/traversal/nat_proxy.go
Comment thread nat/traversal/nat_proxy.go Outdated
Comment thread nat/traversal/nat_proxy.go Outdated
Comment thread nat/traversal/nat_proxy.go Outdated
case *traversal.NoopPinger:
log.Infof("noop pinger detected, returning nil client config.")
return nil, nil
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like configuration depends on implementation of traversal.Pinger - maybe it should provide the config to avoid type-conditionals?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if it is a bad solution, since introducing another config dependency will additionally span throughout the code. Does if worth it?

Comment thread nat/traversal/nat_proxy.go
Comment thread nat/traversal/nat_proxy.go Outdated
Comment thread nat/traversal/nat_proxy.go Outdated
Comment thread nat/traversal/nat_proxy.go Outdated
Comment thread nat/traversal/nat_proxy.go Outdated
Comment thread session/create_consumer.go Outdated
Comment thread session/create_consumer.go
Comment thread session/create_consumer_test.go Outdated
Comment thread session/manager.go Outdated
Comment thread session/manager.go Outdated
@zolia zolia force-pushed the feature/MYST-845-nat-proxy-openvpn branch from 6228ea7 to 7ac6338 Compare April 18, 2019 07:54
@zolia zolia requested a review from soffokl as a code owner April 18, 2019 07:54
@zolia zolia force-pushed the feature/MYST-845-nat-proxy-openvpn branch from 7ac6338 to 79b0498 Compare April 18, 2019 08:10
@zolia zolia requested review from Waldz, donce and vkuznecovas April 18, 2019 08:24
@zolia zolia force-pushed the feature/MYST-845-nat-proxy-openvpn branch from e8160ac to af29200 Compare April 18, 2019 08:26
Comment thread nat/traversal/nat_proxy.go Outdated
Comment thread nat/traversal/pinger.go Outdated
Parse(config json.RawMessage) (ip string, port int, serviceType services.ServiceType, err error)
}

type portSupplier interface {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We gave this interface in multiple places. Can't we define it once somewhere?
There are many examples of such definitions in a standard library: https://golang.org/pkg/io/#Reader

Comment thread nat/traversal/pinger.go

// Params contains session parameters needed to NAT ping remote peer
type Params struct {
RequestConfig json.RawMessage
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it called RequesConfig?
Is it a config of the request?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This config comes with session setup request.

@zolia zolia requested a review from soffokl April 18, 2019 10:03
Comment thread nat/traversal/pinger.go
}

log.Infof("%s ping target received: IP: %v, port: %v", prefix, IP, port)
log.Infof("%sping target received: IP: %v, port: %v", prefix, IP, port)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

prefix missing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

its not, its format string, prefix at the end.

Copy link
Copy Markdown
Contributor

@vkuznecovas vkuznecovas left a comment

Choose a reason for hiding this comment

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

I'm not sure about the moving of the ServicePortSupplier interface to a single spot and then having it referenced in other packages. You're adding hard coupling between the packages where there need not be any. I know it ain't DRY, but I'd rather have less coupling between the packages as you'll end up in a cyclic reference type of situation soon if you do that a lot.

But if everyone else is happy with this - I'm not going to block.

"testing"

"github.com/mysteriumnetwork/node/core/port"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this whitespace is still redundant

@zolia zolia merged commit fb392b7 into master Apr 18, 2019
@zolia zolia deleted the feature/MYST-845-nat-proxy-openvpn branch April 18, 2019 11:55
proposal := openvpn_discovery.NewServiceProposalWithLocation(currentLocation, transportOptions.Protocol)

var portSupplier port.ServicePortSupplier = di.PortPool
if transportOptions.Port != 0 && locationInfo.PubIP == locationInfo.OutIP {
Copy link
Copy Markdown
Contributor

@tadaskay tadaskay Apr 18, 2019

Choose a reason for hiding this comment

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

I'm a bit surprised nobody noticed. This actually changes behavior in most cases (because most clients will have a router), and openvpn.port flag/option is ignored and thus it's always randomized (which causes problems for desktop clients, so for now we decided to use static port 1194 - passing it through options when starting service via tequilapi).

Why was this check needed: locationInfo.PubIP == locationInfo.OutIP? I can't find any useful info in commit messages. Any ideas, @zolia , @vkuznecovas ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

locationInfo.PubIP == locationInfo.OutIP supposed to check if we are behind the NAT.
If IP on the host and public IP is the same, we, probably, don't need to do any NAT traversal since IP is reachable without it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

True, but I think we should respect user flags despite this.

@zolia
Copy link
Copy Markdown
Contributor Author

zolia commented Apr 19, 2019

You're adding hard coupling between the packages where there need not be any

For future reference. I see upsides and downsides of such solution. In this case, if we have package which is very very feature isolated and self sustained. I think such packageS could expose more generic interfaces. In this case port package IMHO is exactly such a package.

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.

6 participants