Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 1 addition & 43 deletions mobile/mysterium/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ import (
"path/filepath"

"github.com/mitchellh/go-homedir"
"github.com/mysteriumnetwork/go-openvpn/openvpn3"
"github.com/mysteriumnetwork/node/cmd"
"github.com/mysteriumnetwork/node/core/connection"
"github.com/mysteriumnetwork/node/core/node"
"github.com/mysteriumnetwork/node/metadata"
"github.com/mysteriumnetwork/node/services/openvpn"
"github.com/mysteriumnetwork/node/services/openvpn/session"
)

// MobileNode represents node object tuned for mobile devices
Expand All @@ -38,11 +34,8 @@ type MobileNode struct {
// MobileNetworkOptions alias for node.OptionsNetwork to be visible from mobile framework
type MobileNetworkOptions node.OptionsNetwork

// Openvpn3TunnelSetup is alias for openvpn3 tunnel setup interface exposed to Android/iOS interop
type Openvpn3TunnelSetup openvpn3.TunnelSetup

// NewNode function creates new Node
func NewNode(appPath string, optionsNetwork *MobileNetworkOptions, tunnelSetup Openvpn3TunnelSetup) (*MobileNode, error) {
func NewNode(appPath string, optionsNetwork *MobileNetworkOptions) (*MobileNode, error) {
var di cmd.Dependencies

var dataDir, currentDir string
Expand Down Expand Up @@ -81,41 +74,6 @@ func NewNode(appPath string, optionsNetwork *MobileNetworkOptions, tunnelSetup O
return nil, err
}

di.ConnectionRegistry.Register("openvpn", func(options connection.ConnectOptions, channel connection.StateChannel) (connection.Connection, error) {

vpnClientConfig, err := openvpn.NewClientConfigFromSession(options.SessionConfig, "", "")
if err != nil {
return nil, err
}

profileContent, err := vpnClientConfig.ToConfigFileContent()
if err != nil {
return nil, err
}

config := openvpn3.NewConfig(profileContent)
config.GuiVersion = "govpn 0.1"
config.CompressionMode = "asym"

signer := di.SignerFactory(options.ConsumerID)

username, password, err := session.SignatureCredentialsProvider(options.SessionID, signer)()
if err != nil {
return nil, err
}

credentials := openvpn3.UserCredentials{
Username: username,
Password: password,
}

session := openvpn3.NewMobileSession(config, credentials, channelToCallbacks(channel, di.StatsKeeper), tunnelSetup)

return &sessionWrapper{
session: session,
}, nil
})

return &MobileNode{di: di}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ import (
"github.com/mysteriumnetwork/go-openvpn/openvpn3"
"github.com/mysteriumnetwork/node/client/stats"
"github.com/mysteriumnetwork/node/core/connection"
"github.com/mysteriumnetwork/node/services/openvpn"
"github.com/mysteriumnetwork/node/services/openvpn/session"
)

type sessionWrapper struct {
session *openvpn3.Session
}

func (wrapper *sessionWrapper) Start() error {

wrapper.session.Start()
return nil
}

func (wrapper *sessionWrapper) Stop() {
wrapper.session.Stop()
}

func (wrapper *sessionWrapper) Wait() error {
return wrapper.session.Wait()
}

type statsUpdater interface {
Save(stats stats.SessionStats)
}
Expand Down Expand Up @@ -65,3 +85,45 @@ func (adapter channelToCallbacksAdapter) OnStats(openvpnStats openvpn3.Statistic
BytesReceived: uint64(openvpnStats.BytesIn),
})
}

// Openvpn3TunnelSetup is alias for openvpn3 tunnel setup interface exposed to Android/iOS interop
type Openvpn3TunnelSetup openvpn3.TunnelSetup

// OverrideOpenvpnConnection replaces default openvpn connection factory with mobile related one
func (mobNode *MobileNode) OverrideOpenvpnConnection(tunnelSetup Openvpn3TunnelSetup) {

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.

Maybe we can call it MobileOpenvpnConnection. From user standpoint he is not overriding anything..

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.

See my comment above

mobNode.di.ConnectionRegistry.Register("openvpn", func(options connection.ConnectOptions, channel connection.StateChannel) (connection.Connection, error) {

vpnClientConfig, err := openvpn.NewClientConfigFromSession(options.SessionConfig, "", "")
if err != nil {
return nil, err
}

profileContent, err := vpnClientConfig.ToConfigFileContent()
if err != nil {
return nil, err
}

config := openvpn3.NewConfig(profileContent)
config.GuiVersion = "govpn 0.1"
config.CompressionMode = "asym"
config.ConnTimeout = 0 //essentially means - reconnect forever (but can always stopped with disconnect)

signer := mobNode.di.SignerFactory(options.ConsumerID)

username, password, err := session.SignatureCredentialsProvider(options.SessionID, signer)()
if err != nil {
return nil, err
}

credentials := openvpn3.UserCredentials{
Username: username,
Password: password,
}

session := openvpn3.NewMobileSession(config, credentials, channelToCallbacks(channel, mobNode.di.StatsKeeper), tunnelSetup)

return &sessionWrapper{
session: session,
}, nil
})
}
40 changes: 40 additions & 0 deletions mobile/mysterium/wireguard_connection_setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2018 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package mysterium

import (
"errors"

"github.com/mysteriumnetwork/node/core/connection"
)

// TODO this probably can be aligned with openvpn3 setup interface as its very close to android api, but for sake of
// package independencies we are not reusing the same interface although implementation is rougly the same
type tunnSetupPlaceholder interface {
Establish() int
}

// WireguardTunnelSetup represents interface for setuping tunnel on caller side (i.e. android api)
type WireguardTunnelSetup tunnSetupPlaceholder

// OverrideWireguardConnection overrides default wireguard connection implementation to more mobile adapted one
func (mobNode *MobileNode) OverrideWireguardConnection(wgTunnelSetup WireguardTunnelSetup) {

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.

Why to call it Override? Its simple connection through our bridge.

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.

Because it exactly what it does - overrides default "openvpn" connection configured in node

mobNode.di.ConnectionRegistry.Register("wireguard", func(options connection.ConnectOptions, channel connection.StateChannel) (connection.Connection, error) {
return nil, errors.New("not implemented yet")
})
}
38 changes: 0 additions & 38 deletions mobile/mysterium/wrapper.go

This file was deleted.