Skip to content

Commit

Permalink
At autoconnect if NordWhisper is disabled switch to NordLynx or OpenV…
Browse files Browse the repository at this point in the history
…PN (#739)
  • Loading branch information
bartoszWojciechO authored Jan 16, 2025
1 parent fc717a9 commit a6a17e6
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions daemon/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@ func connectErrorCheck(err error) bool {
return err == nil
}

func (r *RPC) fallbackTechnology(targetTechnology config.Technology) error {
log.Println(internal.DebugPrefix,
"technology was configured to NordWhisper, but NordWhisper was disabled, switching to",
targetTechnology.String())
v, err := r.factory(targetTechnology)
if err != nil {
return fmt.Errorf("failed to build VPN instance: %s", err)
}

err = r.cm.SaveWith(func(c config.Config) config.Config {
c.Technology = targetTechnology
c.AutoConnectData.Protocol = config.Protocol_UDP
return c
})
if err != nil {
return fmt.Errorf("failed to fallback to %s tech: %s", targetTechnology.String(), err)
}

r.netw.SetVPN(v)
return nil
}

// StartAutoConnect connect to VPN server if autoconnect is enabled
func (r *RPC) StartAutoConnect(timeoutFn GetTimeoutFunc) error {
tries := 1
Expand All @@ -234,13 +256,13 @@ func (r *RPC) StartAutoConnect(timeoutFn GetTimeoutFunc) error {
}

if cfg.Technology == config.Technology_NORDWHISPER && !r.isNordWhisperEnabled() {
err := r.cm.SaveWith(func(c config.Config) config.Config {
c.Technology = config.Technology_NORDLYNX
c.AutoConnectData.Protocol = config.Protocol_UDP
return c
})
if err != nil {
log.Println(internal.ErrorPrefix, "failed to fallback to Nordlynx tech:", err)
log.Println(internal.DebugPrefix,
"technology was configured to NordWhisper, but NordWhisper was disabled, switching to NordLynx")
if err := r.fallbackTechnology(config.Technology_NORDLYNX); err != nil {
log.Println(internal.ErrorPrefix, "failed to fall back to NordLynx technology, will try OpenVPN")
if err := r.fallbackTechnology(config.Technology_OPENVPN); err != nil {
return fmt.Errorf("falling back to OpenVPN technology: %s", err)
}
}
}

Expand Down

0 comments on commit a6a17e6

Please sign in to comment.