Documentation ¶
Index ¶
- Constants
- type ErrorNotLoggedIn
- type INetChangeDetector
- type IServersUpdater
- type IServiceEventsReceiver
- type IWgKeysManager
- type RequiredState
- type Service
- func (s *Service) APIRequest(apiAlias string) (responseData []byte, err error)
- func (s *Service) ConnectOpenVPN(connectionParams openvpn.ConnectionParams, manualDNS net.IP, firewallOn bool, ...) error
- func (s *Service) ConnectWireGuard(connectionParams wireguard.ConnectionParams, manualDNS net.IP, firewallOn bool, ...) error
- func (s *Service) Connected() bool
- func (s *Service) ConnectedType() (isConnected bool, connectedVpnType vpn.Type)
- func (s *Service) Disconnect() error
- func (s *Service) FirewallEnabled() (bool, error)
- func (s *Service) GetDisabledFunctions() (wgErr, ovpnErr, obfspErr error)
- func (s *Service) GetWiFiAvailableNetworks() []string
- func (s *Service) GetWiFiCurrentState() (ssid string, isInsecureNetwork bool)
- func (s *Service) IsPaused() bool
- func (s *Service) KillSwitchState() (isEnabled, isPersistant, isAllowLAN, isAllowLanMulticast bool, err error)
- func (s *Service) OnControlConnectionClosed() (isServiceMustBeClosed bool, err error)
- func (s *Service) Pause() error
- func (s *Service) PingServers(retryCount int, timeoutMs int) (map[string]int, error)
- func (s *Service) Preferences() preferences.Preferences
- func (s *Service) RequestSessionStatus() (apiCode int, apiErrorMsg string, sessionToken string, ...)
- func (s *Service) ResetManualDNS() error
- func (s *Service) Resume() error
- func (s *Service) ServersList() (*types.ServersInfoResponse, error)
- func (s *Service) ServersUpdateNotifierChannel() chan struct{}
- func (s *Service) SessionDelete() error
- func (s *Service) SessionNew(accountID string, forceLogin bool, captchaID string, captcha string, ...) (apiCode int, apiErrorMsg string, accountInfo preferences.AccountStatus, ...)
- func (s *Service) SetKillSwitchAllowLAN(isAllowLan bool) error
- func (s *Service) SetKillSwitchAllowLANMulticast(isAllowLanMulticast bool) error
- func (s *Service) SetKillSwitchIsPersistent(isPersistant bool) error
- func (s *Service) SetKillSwitchState(isEnabled bool) error
- func (s *Service) SetManualDNS(dns net.IP) error
- func (s *Service) SetPreference(key string, val string) error
- func (s *Service) WireGuardGenerateKeys(updateIfNecessary bool) error
- func (s *Service) WireGuardGetKeys() (session, wgPublicKey, wgPrivateKey, wgLocalIP string, generatedTime time.Time, ...)
- func (s *Service) WireGuardSaveNewKeys(wgPublicKey string, wgPrivateKey string, wgLocalIP string)
- func (s *Service) WireGuardSetKeysRotationInterval(interval int64)
Constants ¶
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 ¶
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) ConnectedType ¶
ConnectedType returns connected VPN type (only if VPN connected!)
func (*Service) FirewallEnabled ¶
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 ¶
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 ¶
GetWiFiAvailableNetworks returns list of available WIFI networks
func (*Service) GetWiFiCurrentState ¶
GetWiFiCurrentState returns info about currently connected wifi
func (*Service) KillSwitchState ¶
func (s *Service) KillSwitchState() (isEnabled, isPersistant, isAllowLAN, isAllowLanMulticast bool, err error)
KillSwitchState returns killswitch state
func (*Service) OnControlConnectionClosed ¶
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) PingServers ¶
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 ¶
ResetManualDNS set dns to default
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 ¶
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 ¶
SetKillSwitchAllowLAN change kill-switch value
func (*Service) SetKillSwitchAllowLANMulticast ¶
SetKillSwitchAllowLANMulticast change kill-switch value
func (*Service) SetKillSwitchIsPersistent ¶
SetKillSwitchIsPersistent change kill-switch value
func (*Service) SetKillSwitchState ¶
SetKillSwitchState enable\disable killswitch
func (*Service) SetManualDNS ¶
SetManualDNS set dns
func (*Service) SetPreference ¶
SetPreference set preference value
func (*Service) WireGuardGenerateKeys ¶
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 ¶
WireGuardSaveNewKeys saves WG keys
func (*Service) WireGuardSetKeysRotationInterval ¶
WireGuardSetKeysRotationInterval change WG key rotation interval