Skip to content

Commit

Permalink
Merge pull request #390 from Darkren/fix/vpn-client
Browse files Browse the repository at this point in the history
Fix VPN apps
  • Loading branch information
jdknives authored Jun 10, 2020
2 parents 0b19237 + 90c218e commit 1dffd0b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
31 changes: 23 additions & 8 deletions internal/vpn/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,36 @@ func NewClient(cfg ClientConfig, l logrus.FieldLogger, conn net.Conn) (*Client,
return nil, fmt.Errorf("error getting STCP entities: %w", err)
}

stcprARip, err := stcprAddressResolverIPFromEnv()
if err != nil {
return nil, fmt.Errorf("error getting stcpr AR IP: %w", err)
var stcprARip net.IP
if _, ok := os.LookupEnv(STCPRAddressResolverAddrEnvKey); ok {
stcprARip, err = stcprAddressResolverIPFromEnv()
if err != nil {
return nil, fmt.Errorf("error getting stcpr AR IP: %w", err)
}
}

stcphARip, err := stcphAddressResolverIPFromEnv()
if err != nil {
return nil, fmt.Errorf("error getting stcph AR IP: %w", err)
var stcphARip net.IP
if _, ok := os.LookupEnv(STCPHAddressResolverAddrEnvKey); ok {
stcphARip, err = stcphAddressResolverIPFromEnv()
if err != nil {
return nil, fmt.Errorf("error getting stcph AR IP: %w", err)
}
}

directIPs := make([]net.IP, 0, 5+len(dmsgSrvAddrs)+len(stcpEntities))
directIPs = append(directIPs, dmsgDiscIP, tpDiscIP, rfIP, stcprARip, stcphARip)
requiredDirectIPs := []net.IP{dmsgDiscIP, tpDiscIP, rfIP}
directIPs := make([]net.IP, 0, len(requiredDirectIPs)+len(dmsgSrvAddrs)+len(stcpEntities))
directIPs = append(directIPs, requiredDirectIPs...)
directIPs = append(directIPs, dmsgSrvAddrs...)
directIPs = append(directIPs, stcpEntities...)

if stcprARip != nil {
directIPs = append(directIPs, stcprARip)
}

if stcphARip != nil {
directIPs = append(directIPs, stcphARip)
}

defaultGateway, err := DefaultNetworkGateway()
if err != nil {
return nil, fmt.Errorf("error getting default network gateway: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/appdisc/discovery_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (emptyUpdater) Start() {}
func (emptyUpdater) Stop() {}
func (emptyUpdater) ChangeValue(name string, v []byte) error { return nil }

// proxyUpdater updates proxy-discovery entry of locally running skysocks App.
type proxyUpdater struct {
// serviceUpdater updates service-discovery entry of locally running App.
type serviceUpdater struct {
client *servicedisc.HTTPClient
interval time.Duration

Expand All @@ -39,7 +39,7 @@ type proxyUpdater struct {
mu sync.Mutex
}

func (u *proxyUpdater) Start() {
func (u *serviceUpdater) Start() {
u.mu.Lock()
defer u.mu.Unlock()

Expand All @@ -57,7 +57,7 @@ func (u *proxyUpdater) Start() {
}()
}

func (u *proxyUpdater) Stop() {
func (u *serviceUpdater) Stop() {
u.mu.Lock()
defer u.mu.Unlock()

Expand All @@ -70,7 +70,7 @@ func (u *proxyUpdater) Stop() {
u.wg.Wait()
}

func (u *proxyUpdater) ChangeValue(name string, v []byte) error {
func (u *serviceUpdater) ChangeValue(name string, v []byte) error {
switch name {
case ConnCountValue:
n, err := strconv.Atoi(string(v))
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/appdisc/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ func (f *Factory) Updater(conf appcommon.ProcConfig) (Updater, bool) {

switch conf.AppName {
case skyenv.SkysocksName:
return &proxyUpdater{
return &serviceUpdater{
client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeProxy)),
interval: f.UpdateInterval,
}, true
case skyenv.VPNServerName:
return &proxyUpdater{
client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeVPN)),
return &serviceUpdater{
client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeVPN)),
interval: f.UpdateInterval,
}, true
default:
return &emptyUpdater{}, false
Expand Down
2 changes: 1 addition & 1 deletion pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func makeVPNEnvs(conf *visorconfig.V1, n *snet.Network) ([]string, error) {
envMap := vpn.AppEnvArgs(envCfg)

envs := make([]string, 0, len(envMap))
for k, v := range vpn.AppEnvArgs(envCfg) {
for k, v := range envMap {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"time"

"github.com/SkycoinProject/skywire-mainnet/pkg/skyenv"

"github.com/SkycoinProject/dmsg/buildinfo"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/google/uuid"
Expand Down Expand Up @@ -213,7 +215,15 @@ func (r *RPC) Apps(_ *struct{}, reply *[]*launcher.AppState) (err error) {
func (r *RPC) StartApp(name *string, _ *struct{}) (err error) {
defer rpcutil.LogCall(r.log, "StartApp", name)(nil, &err)

return r.visor.appL.StartApp(*name, nil, nil)
var envs []string
if *name == skyenv.VPNClientName {
envs, err = makeVPNEnvs(r.visor.conf, r.visor.net)
if err != nil {
return err
}
}

return r.visor.appL.StartApp(*name, nil, envs)
}

// StopApp stops App with provided name.
Expand Down

0 comments on commit 1dffd0b

Please sign in to comment.