Skip to content

Commit

Permalink
Merge branch 'feature/s133-Split-Tunnel-inverse' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
stenya committed Nov 2, 2023
2 parents df32d7a + 130ea05 commit cfd176b
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions daemon/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,44 @@ func (s *Service) init() error {
// - disable Split Tunnel mode
// - etc. ...
func (s *Service) UnInitialise() error {
return s.unInitialise()
}

// unInitialise - stop service on logout or daemon is going to stop
// - disconnect VPN (if connected)
// - disable Split Tunnel mode
// - etc. ...
func (s *Service) unInitialise() error {
log.Info("Uninitialising service...")
var retErr error
updateRetErr := func(e error) {
if retErr != nil {
retErr = fmt.Errorf("%w | error=%w", retErr, e)
} else {
retErr = e
}
}
// Disconnect VPN
if err := s.Disconnect(); err != nil {
log.Error(err)
updateRetErr(err)
}

// Disable ST
if err := firewall.SingleDnsRuleOff(); err != nil {
log.Error(err)
updateRetErr(err)
}
if err := splittun.Reset(); err != nil {
log.Error(err)
updateRetErr(err)
}
if err := splittun.ApplyConfig(false, false, false, false, splittun.ConfigAddresses{}, []string{}); err != nil {
log.Error(err)
updateRetErr(err)
}

return nil
return retErr
}

// IsConnectivityBlocked - returns nil if connectivity NOT blocked
Expand Down Expand Up @@ -1313,6 +1333,12 @@ func (s *Service) SplitTunnelling_GetStatus() (protocolTypes.SplitTunnelStatus,
isAllowWhenNoVpn = false
}

if !prefs.Session.IsLoggedIn() {
// SplitTunnel not applicable when logged out.
// Sending "disabled" status
isEnabled = false
}

ret := protocolTypes.SplitTunnelStatus{
IsFunctionalityNotAvailable: stErr != nil,
IsEnabled: isEnabled,
Expand Down Expand Up @@ -1411,6 +1437,10 @@ func (s *Service) splitTunnelling_ApplyConfig() (retError error) {

prefs := s.Preferences()

if !prefs.Session.IsLoggedIn() {
return srverrors.ErrorNotLoggedIn{}
}

// Network changes detection must be disabled for Inverse SplitTunneling
if prefs.IsInverseSplitTunneling() {
// If inverse SplitTunneling is enabled - stop detection of network changes (if it already started)
Expand Down Expand Up @@ -1570,7 +1600,6 @@ func (s *Service) SessionNew(accountID string, forceLogin bool, captchaID string
log.Info("Logging in - FAILED: ", err)
} else {
log.Info("Logging in - SUCCESS")

}
}()

Expand Down Expand Up @@ -1659,6 +1688,11 @@ func (s *Service) SessionNew(accountID string, forceLogin bool, captchaID string

log.Info(fmt.Sprintf("(logging in) WG keys updated (%s:%s; psk:%v)", successResp.WireGuard.IPAddress, publicKey, len(wgPresharedKey) > 0))

// Apply SplitTunnel configuration. It is applicable for Inverse mode of SplitTunnel
if err := s.splitTunnelling_ApplyConfig(); err != nil {
log.Error(err)
}

return apiCode, "", accountInfo, rawResponse, nil
}

Expand All @@ -1678,8 +1712,17 @@ func (s *Service) SessionDelete(isCanDeleteSessionLocally bool) error {
// in case if API request failed we just erasing session info locally (no errors returned)

func (s *Service) logOut(sessionNeedToDeleteOnBackend bool, isCanDeleteSessionLocally bool) error {
// Disconnect (if connected)
s.Disconnect()
// Stop service:
// - disconnect VPN (if connected)
// - disable Split Tunnel mode
// - etc. ...
if err := s.unInitialise(); err != nil {
log.Error(err)
}

defer func() {
s._evtReceiver.OnSplitTunnelStatusChanged()
}()

// stop session checker (use goroutine to avoid deadlocks)
go s.stopSessionChecker()
Expand Down

0 comments on commit cfd176b

Please sign in to comment.