Skip to content

Commit

Permalink
Fixed android build with wireguard
Browse files Browse the repository at this point in the history
  • Loading branch information
soffokl committed Nov 29, 2018
1 parent 5a73287 commit c44520a
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 33 deletions.
22 changes: 3 additions & 19 deletions cmd/commands/service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
service_noop "github.com/mysteriumnetwork/node/services/noop"
service_openvpn "github.com/mysteriumnetwork/node/services/openvpn"
openvpn_service "github.com/mysteriumnetwork/node/services/openvpn/service"
service_wireguard "github.com/mysteriumnetwork/node/services/wireguard"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -151,16 +150,10 @@ func registerFlags(flags *[]cli.Flag) {
}

func parseFlagsByServiceType(ctx *cli.Context, serviceType string) (service.Options, error) {
switch serviceType {
case service_noop.ServiceType:
return parseNoopFlags(ctx), nil
case service_openvpn.ServiceType:
return parseOpenvpnFlags(ctx), nil
case service_wireguard.ServiceType:
return parseWireguardFlags(ctx), nil
default:
return service.Options{}, fmt.Errorf("Unknown service type: %q", serviceType)
if f, ok := serviceTypesFlagsParser[serviceType]; ok {
return f(ctx), nil
}
return service.Options{}, fmt.Errorf("Unknown service type: %q", serviceType)
}

// parseOpenvpnFlags function fills in openvpn options from CLI context
Expand All @@ -182,15 +175,6 @@ func parseNoopFlags(ctx *cli.Context) service.Options {
}
}

// parseWireguardFlags function fills in wireguard service options from CLI context
func parseWireguardFlags(ctx *cli.Context) service.Options {
return service.Options{
Identity: ctx.String(identityFlag.Name),
Passphrase: ctx.String(identityPassphraseFlag.Name),
Type: service_wireguard.ServiceType,
}
}

func printTermWarning(licenseCommandName string) {
fmt.Println(metadata.VersionAsSummary(metadata.LicenseCopyright(
"run program with 'myst "+licenseCommandName+" --"+license.LicenseWarrantyFlag.Name+"' option",
Expand Down
14 changes: 13 additions & 1 deletion cmd/commands/service/serviceTypes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !linux
// +build !linux linux,android

/*
* Copyright (C) 2017 The "MysteriumNetwork/node" Authors.
Expand All @@ -19,7 +19,19 @@

package service

import (
"github.com/mysteriumnetwork/node/core/service"
service_noop "github.com/mysteriumnetwork/node/services/noop"
service_openvpn "github.com/mysteriumnetwork/node/services/openvpn"
"github.com/urfave/cli"
)

var (
serviceTypesAvailable = []string{"openvpn", "noop"}
serviceTypesEnabled = []string{"openvpn", "noop"}

serviceTypesFlagsParser = map[string]func(ctx *cli.Context) service.Options{
service_noop.ServiceType: parseNoopFlags,
service_openvpn.ServiceType: parseOpenvpnFlags,
}
)
25 changes: 25 additions & 0 deletions cmd/commands/service/serviceTypes_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux,!android

/*
* Copyright (C) 2017 The "MysteriumNetwork/node" Authors.
*
Expand All @@ -17,7 +19,30 @@

package service

import (
"github.com/mysteriumnetwork/node/core/service"
service_noop "github.com/mysteriumnetwork/node/services/noop"
service_openvpn "github.com/mysteriumnetwork/node/services/openvpn"
service_wireguard "github.com/mysteriumnetwork/node/services/wireguard"
"github.com/urfave/cli"
)

var (
serviceTypesAvailable = []string{"openvpn", "wireguard", "noop"}
serviceTypesEnabled = []string{"openvpn", "noop"}

serviceTypesFlagsParser = map[string]func(ctx *cli.Context) service.Options{
service_noop.ServiceType: parseNoopFlags,
service_openvpn.ServiceType: parseOpenvpnFlags,
service_wireguard.ServiceType: parseWireguardFlags,
}
)

// parseWireguardFlags function fills in wireguard service options from CLI context
func parseWireguardFlags(ctx *cli.Context) service.Options {
return service.Options{
Identity: ctx.String(identityFlag.Name),
Passphrase: ctx.String(identityPassphraseFlag.Name),
Type: service_wireguard.ServiceType,
}
}
36 changes: 36 additions & 0 deletions cmd/connections_register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// +build !android

/*
* 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 cmd

import (
"github.com/mysteriumnetwork/node/core/node"
service_wireguard "github.com/mysteriumnetwork/node/services/wireguard"
)

func (di *Dependencies) registerConnections(nodeOptions node.Options) {
di.registerOpenvpnConnection(nodeOptions)
di.registerNoopConnection()
di.registerWireguardConnection()
}

func (di *Dependencies) registerWireguardConnection() {
service_wireguard.Bootstrap()
di.ConnectionRegistry.Register(service_wireguard.ServiceType, service_wireguard.NewConnectionCreator())
}
29 changes: 29 additions & 0 deletions cmd/connections_register_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// +build android

/*
* 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 cmd

import (
"github.com/mysteriumnetwork/node/core/node"
)

func (di *Dependencies) registerConnections(nodeOptions node.Options) {
di.registerOpenvpnConnection(nodeOptions)
di.registerNoopConnection()
}
12 changes: 0 additions & 12 deletions cmd/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
dto_discovery "github.com/mysteriumnetwork/node/service_discovery/dto"
service_noop "github.com/mysteriumnetwork/node/services/noop"
service_openvpn "github.com/mysteriumnetwork/node/services/openvpn"
service_wireguard "github.com/mysteriumnetwork/node/services/wireguard"
"github.com/mysteriumnetwork/node/session"
"github.com/mysteriumnetwork/node/tequilapi"
tequilapi_endpoints "github.com/mysteriumnetwork/node/tequilapi/endpoints"
Expand Down Expand Up @@ -133,12 +132,6 @@ func (di *Dependencies) Bootstrap(nodeOptions node.Options) error {
return nil
}

func (di *Dependencies) registerConnections(nodeOptions node.Options) {
di.registerOpenvpnConnection(nodeOptions)
di.registerNoopConnection()
di.registerWireguardConnection()
}

func (di *Dependencies) registerOpenvpnConnection(nodeOptions node.Options) {
service_openvpn.Bootstrap()
connectionFactory := service_openvpn.NewProcessBasedConnectionFactory(
Expand All @@ -157,11 +150,6 @@ func (di *Dependencies) registerNoopConnection() {
di.ConnectionRegistry.Register(service_noop.ServiceType, service_noop.NewConnectionCreator())
}

func (di *Dependencies) registerWireguardConnection() {
service_wireguard.Bootstrap()
di.ConnectionRegistry.Register(service_wireguard.ServiceType, service_wireguard.NewConnectionCreator())
}

// Shutdown stops container
func (di *Dependencies) Shutdown() (err error) {
var errs []error
Expand Down
2 changes: 1 addition & 1 deletion cmd/service_bootstrap_desktop.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin windows linux
// +build darwin windows linux,!android

/*
* Copyright (C) 2018 The "MysteriumNetwork/node" Authors.
Expand Down

0 comments on commit c44520a

Please sign in to comment.