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

Fix VPN apps #390

Merged
merged 12 commits into from
Jun 10, 2020
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.idea/

/skywire.json
/apps/
#/apps/
Darkren marked this conversation as resolved.
Show resolved Hide resolved
/skywire/
/local*

Expand All @@ -24,7 +24,7 @@ pkg/visor/foo/
/users.db
/hypervisor
/*-node
/*-visor
#/*-visor
Darkren marked this conversation as resolved.
Show resolved Hide resolved
/*-cli
/*-server
/*.json
Expand Down
Binary file added apps/helloworld
Binary file not shown.
Binary file added apps/helloworld.v1.0
Binary file not shown.
Binary file added apps/skychat
Binary file not shown.
Binary file added apps/skychat.v1.0
Binary file not shown.
Binary file added apps/skysocks
Binary file not shown.
Binary file added apps/skysocks-client
Binary file not shown.
Binary file added apps/skysocks-client.v1.0
Binary file not shown.
Binary file added apps/skysocks.v1.0
Binary file not shown.
Binary file added apps/vpn-client
Binary file not shown.
Binary file added apps/vpn-server
Binary file not shown.
30 changes: 22 additions & 8 deletions internal/vpn/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,35 @@ 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)
directIPs := make([]net.IP, 0, 3+len(dmsgSrvAddrs)+len(stcpEntities))
Darkren marked this conversation as resolved.
Show resolved Hide resolved
directIPs = append(directIPs, dmsgDiscIP, tpDiscIP, rfIP)
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.
Darkren marked this conversation as resolved.
Show resolved Hide resolved
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
Binary file added skywire-visor
Binary file not shown.