service

package
v0.0.0-...-846a3b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2021 License: GPL-3.0 Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// SessionCheckInterval - the interval for periodical check session status
	SessionCheckInterval time.Duration = time.Hour * 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorNotLoggedIn

type ErrorNotLoggedIn struct {
}

ErrorNotLoggedIn - error, user not logged in into account

func (ErrorNotLoggedIn) Error

func (e ErrorNotLoggedIn) Error() string

type INetChangeDetector

type INetChangeDetector interface {
	// Start - start route change detector (asynchronous)
	//    'routingChangeChan' is the channel for notifying when the default routing is NOT over the 'interfaceToProtect' anymore
	//    'routingUpdateChan' is the channel for notifying when there were some routing changes but 'interfaceToProtect' is still is the default route
	Start(routingChangeChan chan<- struct{}, routingUpdateChan chan<- struct{}, currentDefaultInterface *net.Interface)
	Stop()
	DelayBeforeNotify() time.Duration
}

INetChangeDetector - object is detecting routing changes on a PC

type IServersUpdater

type IServersUpdater interface {
	GetServers() (*types.ServersInfoResponse, error)
	// UpdateNotifierChannel returns channel which is notifying when servers was updated
	UpdateNotifierChannel() chan struct{}
}

IServersUpdater - interface for updating server info mechanism

func CreateServersUpdater

func CreateServersUpdater(apiObj *api.API) (IServersUpdater, error)

CreateServersUpdater - constructor for serversUpdater object

type IServiceEventsReceiver

type IServiceEventsReceiver interface {
	OnServiceSessionChanged()
	OnAccountStatus(sessionToken string, account preferences.AccountStatus)
	OnDNSChanged(dns net.IP)
	OnKillSwitchStateChanged()
	OnWiFiChanged(ssid string, isInsecureNetwork bool)
	OnPingStatus(retMap map[string]int)
}

IServiceEventsReceiver is the receiver for service events (normally, it is protocol object)

type IWgKeysManager

type IWgKeysManager interface {
	Init(receiver wgkeys.IWgKeysChangeReceiver) error
	StartKeysRotation() error
	StopKeysRotation()
	GenerateKeys() error
	UpdateKeysIfNecessary() error
}

IWgKeysManager - WireGuard keys manager

type RequiredState

type RequiredState int

RequiredState VPN state which service is going to reach

const (
	Disconnect     RequiredState = 0
	Connect        RequiredState = 1
	KeepConnection RequiredState = 2
)

Requested VPN states

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service - IVPN service

func CreateService

func CreateService(evtReceiver IServiceEventsReceiver, api *api.API, updater IServersUpdater, netChDetector INetChangeDetector, wgKeysMgr IWgKeysManager) (*Service, error)

CreateService - service constructor

func (*Service) APIRequest

func (s *Service) APIRequest(apiAlias string) (responseData []byte, err error)

APIRequest do custom request to API

func (*Service) ConnectOpenVPN

func (s *Service) ConnectOpenVPN(connectionParams openvpn.ConnectionParams, manualDNS net.IP, firewallOn bool, firewallDuringConnection bool, stateChan chan<- vpn.StateInfo) error

ConnectOpenVPN start OpenVPN connection

func (*Service) ConnectWireGuard

func (s *Service) ConnectWireGuard(connectionParams wireguard.ConnectionParams, manualDNS net.IP, firewallOn bool, firewallDuringConnection bool, stateChan chan<- vpn.StateInfo) error

ConnectWireGuard start WireGuard connection

func (*Service) Connected

func (s *Service) Connected() bool

Connected returns 'true' if VPN connected

func (*Service) ConnectedType

func (s *Service) ConnectedType() (isConnected bool, connectedVpnType vpn.Type)

ConnectedType returns connected VPN type (only if VPN connected!)

func (*Service) Disconnect

func (s *Service) Disconnect() error

Disconnect disconnect vpn

func (*Service) FirewallEnabled

func (s *Service) FirewallEnabled() (bool, error)

FirewallEnabled returns firewall state (enabled\disabled) (in use, for example, by WireGuard keys manager, to know is it have sense to make API requests.)

func (*Service) GetDisabledFunctions

func (s *Service) GetDisabledFunctions() (wgErr, ovpnErr, obfspErr error)

GetDisabledFunctions returns info about functions which are disabled Some functionality can be not accessible It can happen, for example, if some external binaries not installed (e.g. obfsproxy or WireGuard on Linux)

func (*Service) GetWiFiAvailableNetworks

func (s *Service) GetWiFiAvailableNetworks() []string

GetWiFiAvailableNetworks returns list of available WIFI networks

func (*Service) GetWiFiCurrentState

func (s *Service) GetWiFiCurrentState() (ssid string, isInsecureNetwork bool)

GetWiFiCurrentState returns info about currently connected wifi

func (*Service) IsPaused

func (s *Service) IsPaused() bool

IsPaused returns 'true' if current vpn connection is in paused state

func (*Service) KillSwitchState

func (s *Service) KillSwitchState() (isEnabled, isPersistant, isAllowLAN, isAllowLanMulticast bool, err error)

KillSwitchState returns killswitch state

func (*Service) OnControlConnectionClosed

func (s *Service) OnControlConnectionClosed() (isServiceMustBeClosed bool, err error)

OnControlConnectionClosed - Perform reqired operations when protocol (controll channel with UI application) was closed (for example, we must disable firewall (if it not persistant)) Must be called by protocol object Return parameters: - isServiceMustBeClosed: true informing that service have to be closed ("Stop IVPN Agent when application is not running" feature) - err: error

func (*Service) Pause

func (s *Service) Pause() error

Pause pause vpn connection

func (*Service) PingServers

func (s *Service) PingServers(retryCount int, timeoutMs int) (map[string]int, error)

PingServers ping vpn servers. In some cases the multiple (and simultaneous pings) are leading to OS crash on macOS and Windows. It happens when installed some third-party 'security' software. Therefore, we using ping algorithm which avoids simultaneous pings and doing it one-by-one

func (*Service) Preferences

func (s *Service) Preferences() preferences.Preferences

Preferences returns preferences

func (*Service) RequestSessionStatus

func (s *Service) RequestSessionStatus() (
	apiCode int,
	apiErrorMsg string,
	sessionToken string,
	accountInfo preferences.AccountStatus,
	err error)

RequestSessionStatus receives session status

func (*Service) ResetManualDNS

func (s *Service) ResetManualDNS() error

ResetManualDNS set dns to default

func (*Service) Resume

func (s *Service) Resume() error

Resume resume vpn connection

func (*Service) ServersList

func (s *Service) ServersList() (*types.ServersInfoResponse, error)

ServersList - get VPN servers info

func (*Service) ServersUpdateNotifierChannel

func (s *Service) ServersUpdateNotifierChannel() chan struct{}

ServersUpdateNotifierChannel returns channel which is notifying when servers was updated

func (*Service) SessionDelete

func (s *Service) SessionDelete() error

SessionDelete removes session info

func (*Service) SessionNew

func (s *Service) SessionNew(accountID string, forceLogin bool, captchaID string, captcha string, confirmation2FA string) (
	apiCode int,
	apiErrorMsg string,
	accountInfo preferences.AccountStatus,
	rawResponse string,
	err error)

SessionNew creates new session

func (*Service) SetKillSwitchAllowLAN

func (s *Service) SetKillSwitchAllowLAN(isAllowLan bool) error

SetKillSwitchAllowLAN change kill-switch value

func (*Service) SetKillSwitchAllowLANMulticast

func (s *Service) SetKillSwitchAllowLANMulticast(isAllowLanMulticast bool) error

SetKillSwitchAllowLANMulticast change kill-switch value

func (*Service) SetKillSwitchIsPersistent

func (s *Service) SetKillSwitchIsPersistent(isPersistant bool) error

SetKillSwitchIsPersistent change kill-switch value

func (*Service) SetKillSwitchState

func (s *Service) SetKillSwitchState(isEnabled bool) error

SetKillSwitchState enable\disable killswitch

func (*Service) SetManualDNS

func (s *Service) SetManualDNS(dns net.IP) error

SetManualDNS set dns

func (*Service) SetPreference

func (s *Service) SetPreference(key string, val string) error

SetPreference set preference value

func (*Service) WireGuardGenerateKeys

func (s *Service) WireGuardGenerateKeys(updateIfNecessary bool) error

WireGuardGenerateKeys - generate new wireguard keys

func (*Service) WireGuardGetKeys

func (s *Service) WireGuardGetKeys() (session, wgPublicKey, wgPrivateKey, wgLocalIP string, generatedTime time.Time, updateInterval time.Duration)

WireGuardGetKeys get WG keys

func (*Service) WireGuardSaveNewKeys

func (s *Service) WireGuardSaveNewKeys(wgPublicKey string, wgPrivateKey string, wgLocalIP string)

WireGuardSaveNewKeys saves WG keys

func (*Service) WireGuardSetKeysRotationInterval

func (s *Service) WireGuardSetKeysRotationInterval(interval int64)

WireGuardSetKeysRotationInterval change WG key rotation interval

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL