daemon

package
v0.0.0-...-555b79e Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: GPL-3.0 Imports: 48 Imported by: 0

Documentation

Overview

Package daemon provides gRPC interface for management of vpn on the device and various related functionalities, such as communication with the backend api and configuration management.

Index

Constants

View Source
const (

	// BaseURL defines the base uri for the api
	BaseURL = "https://api.nordvpn.com"

	// RepoURL is the url for NordVPN repository
	RepoURL = "https://repo.nordvpn.com"

	// RandomComponentMin defines minimal value of random component
	RandomComponentMin = 0

	// RandomComponentMax defines maximum value of random component
	RandomComponentMax = 0.001
)
View Source
const (
	Alpha  = 0.7
	Beta   = -0.15
	Lambda = 1
	K      = 0.5
	W      = 0.5
	Fi     = 7
)
View Source
const (
	// R defines earth radius in meters
	R = 6371e3
)

Variables

View Source
var (
	// ServersDataFilePath defines path to servers data file
	ServersDataFilePath = filepath.Join(internal.DatFilesPathCommon, "servers.dat")

	// CountryDataFilePath defines path to countries data file
	CountryDataFilePath = filepath.Join(internal.DatFilesPathCommon, "countries.dat")

	// InsightsFilePath defines filename of insights file
	InsightsFilePath = filepath.Join(internal.DatFilesPath, "insights.dat")

	// VersionFilePath defines filename of latest available version file
	VersionFilePath = filepath.Join(internal.DatFilesPathCommon, "version.dat")

	// IconPath defines icon file path
	IconPath = internal.PrefixCommonPath("/usr/share/icons/hicolor/scalable/apps/nordvpn.svg")
)
View Source
var ErrDedicatedIPServer = fmt.Errorf("selected dedicated IP servers group")
View Source
var (
	// ErrMissingExchangeToken is returned when login was successful but
	// there is not enough data to request the token
	ErrMissingExchangeToken = errors.New("exchange token not provided")
)

Functions

func GetLatestVersion

func GetLatestVersion(versions []semver.Version) semver.Version

func JobCountries

func JobCountries(dm *DataManager, api core.ServersAPI) func() error

func JobHeartBeat

func JobHeartBeat(
	publisher events.Publisher[time.Duration],
	period time.Duration,
) func()

JobHeartBeat sends heart beats.

func JobInsights

func JobInsights(
	dm InsightsDataManager,
	api core.InsightsAPI,
	networker interface{ IsVPNActive() bool },
	events *events.Events,
	downloader bool,
) func()

JobInsights is responsible for collecting information about the user's physical location. It helps Data Analytics team to deduce country of origin of our users regardless to which country they are connecting.

func JobServerCheck

func JobServerCheck(
	dm *DataManager,
	api core.ServersAPI,
	netw networker.Networker,
	server core.Server,
) func()

JobServerCheck marks servers as offline if connection to them drops

func JobServers

func JobServers(dm *DataManager, cm config.Manager, api core.ServersAPI, validate bool) func() error

JobServers is responsible for population of local server cache which is needed to avoid excess requests to the backend API.

func JobTemplates

func JobTemplates(cdn core.CDN) func()

func JobVersionCheck

func JobVersionCheck(dm *DataManager, api *RepoAPI) func()

func ParseDebianVersions

func ParseDebianVersions(data []byte) []string

func ParseRpmVersions

func ParseRpmVersions(data []byte) []string

func PickServer

func PickServer(
	api core.ServersAPI,
	countries core.Countries,
	servers core.Servers,
	longitude float64,
	latitude float64,
	tech config.Technology,
	protocol config.Protocol,
	obfuscated bool,
	tag string,
	groupFlag string,
	allowVirtualServer bool,
) (core.Server, bool, error)

PickServer by the specified criteria.

func StartNC

func StartNC(prefix string, ncClient nc.NotificationClient)

StartNC tries to start notification client and logs any errors if they occur. This is just a convenience wrapper, we always start notification client in another goroutine, so we cannot handle the errors directly in the caller. Prefix will be prepended to the error log.

func StringsToVersions

func StringsToVersions(v []string) []semver.Version

Types

type AppData

type AppData struct {
}

type ConnectionParameters

type ConnectionParameters struct {
	ConnectionSource pb.ConnectionSource
	Parameters       ServerParameters
}

type CountryData

type CountryData struct {
	UpdatedAt time.Time
	Countries core.Countries
	Hash      string
	// contains filtered or unexported fields
}

type DataManager

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

func NewDataManager

func NewDataManager(insightsFilePath,
	serversFilePath,
	countryFilePath,
	versionFilePath string,
	dataUpdateEvents *events.DataUpdateEvents) *DataManager

func (*DataManager) Cities

func (dm *DataManager) Cities(
	countryName string,
	technology config.Technology,
	protocol config.Protocol,
	obfuscated bool,
	virtualLocation bool,
) ([]*pb.ServerGroup, error)

func (*DataManager) Countries

func (dm *DataManager) Countries(
	technology config.Technology,
	protocol config.Protocol,
	obfuscated bool,
	virtualLocation bool,
) ([]*pb.ServerGroup, error)

func (*DataManager) CountryCodeToCountryName

func (dm *DataManager) CountryCodeToCountryName(code string) string

CountryCodeToCountryName returns country name for the given country code or an empty string if no match is found.

func (*DataManager) CountryDataExists

func (dm *DataManager) CountryDataExists() bool

func (*DataManager) GetAppData

func (dm *DataManager) GetAppData() AppData

func (*DataManager) GetCountryData

func (dm *DataManager) GetCountryData() CountryData

func (*DataManager) GetInsightsData

func (dm *DataManager) GetInsightsData() InsightsData

func (*DataManager) GetServersData

func (dm *DataManager) GetServersData() ServersData

func (*DataManager) GetVersionData

func (dm *DataManager) GetVersionData() VersionData

func (*DataManager) Groups

func (dm *DataManager) Groups(
	technology config.Technology,
	protocol config.Protocol,
	obfuscated bool,
	virtualLocation bool,
) ([]*pb.ServerGroup, error)

func (*DataManager) IsCountryDataValid

func (dm *DataManager) IsCountryDataValid() bool

func (*DataManager) IsServersDataValid

func (dm *DataManager) IsServersDataValid() bool

func (*DataManager) LoadData

func (dm *DataManager) LoadData() error

func (*DataManager) ServerDataExists

func (dm *DataManager) ServerDataExists() bool

func (*DataManager) SetCountryData

func (dm *DataManager) SetCountryData(updatedAt time.Time, countries core.Countries, hash string) error

func (*DataManager) SetInsightsData

func (dm *DataManager) SetInsightsData(insights core.Insights) error

func (*DataManager) SetServerStatus

func (dm *DataManager) SetServerStatus(s core.Server, status core.Status) error

func (*DataManager) SetServersData

func (dm *DataManager) SetServersData(updatedAt time.Time, servers core.Servers, hash string) (err error)

func (*DataManager) SetVersionData

func (dm *DataManager) SetVersionData(version semver.Version, newerAvailable bool)

func (*DataManager) UpdateServerPenalty

func (dm *DataManager) UpdateServerPenalty(s core.Server) error

type FactoryFunc

type FactoryFunc func(config.Technology) (vpn.VPN, error)

type GetTimeoutFunc

type GetTimeoutFunc func(tries int) time.Duration

type InsightsData

type InsightsData struct {
	Insights core.Insights
	// contains filtered or unexported fields
}

type InsightsDataManager

type InsightsDataManager interface {
	GetInsightsData() InsightsData
	SetInsightsData(core.Insights) error
}

type ParametersStorage

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

func (*ParametersStorage) GetConnectionParameters

func (c *ParametersStorage) GetConnectionParameters() (ConnectionParameters, error)

func (*ParametersStorage) SetConnectionParameters

func (c *ParametersStorage) SetConnectionParameters(connectionSource pb.ConnectionSource, parameters ServerParameters)

type RPC

type RPC struct {
	ConnectionParameters ParametersStorage

	pb.UnimplementedDaemonServer
	// contains filtered or unexported fields
}

RPC is a gRPC server.

func NewRPC

func NewRPC(
	environment internal.Environment,
	ac auth.Checker,
	cm config.Manager,
	dm *DataManager,
	api core.CombinedAPI,
	serversAPI core.ServersAPI,
	credentialsAPI core.CredentialsAPI,
	cdn core.CDN,
	repo *RepoAPI,
	authentication core.Authentication,
	version string,
	events *daemonevents.Events,
	factory FactoryFunc,
	endpointResolver network.EndpointResolver,
	netw networker.Networker,
	publisher events.Publisher[string],
	nameservers dns.Getter,
	ncClient nc.NotificationClient,
	analytics events.Analytics,
	norduser service.Service,
	meshRegistry mesh.Registry,
	statePublisher *state.StatePublisher,
	connectContext *sharedctx.Context,
) *RPC

func (*RPC) AccountInfo

func (r *RPC) AccountInfo(ctx context.Context, _ *pb.Empty) (*pb.AccountResponse, error)

AccountInfo returns user account information.

func (*RPC) Cities

func (r *RPC) Cities(ctx context.Context, in *pb.CitiesRequest) (*pb.ServerGroupsList, error)

Cities provides cities command and autocompletion.

func (*RPC) ClaimOnlinePurchase

func (r *RPC) ClaimOnlinePurchase(ctx context.Context, in *pb.Empty) (*pb.ClaimOnlinePurchaseResponse, error)

func (*RPC) Connect

func (r *RPC) Connect(in *pb.ConnectRequest, srv pb.Daemon_ConnectServer) (retErr error)

Connect initiates and handles the VPN connection process

func (*RPC) ConnectCancel

func (r *RPC) ConnectCancel(_ context.Context, _ *pb.Empty) (*pb.Payload, error)

ConnectCancel cancels an active call for connect to VPN server or meshnet exit node and returns response code immediately without waiting for an actual cancel.

func (*RPC) Countries

func (r *RPC) Countries(ctx context.Context, in *pb.Empty) (*pb.ServerGroupsList, error)

Countries provides country command and country autocompletion.

func (*RPC) Disconnect

func (r *RPC) Disconnect(_ *pb.Empty, srv pb.Daemon_DisconnectServer) error

func (*RPC) GetServers

func (r *RPC) GetServers(ctx context.Context, in *pb.Empty) (*pb.ServersResponse, error)

func (*RPC) Groups

func (r *RPC) Groups(ctx context.Context, in *pb.Empty) (*pb.ServerGroupsList, error)

Groups provides endpoint and autocompletion.

func (*RPC) IsLoggedIn

func (r *RPC) IsLoggedIn(ctx context.Context, _ *pb.Empty) (*pb.Bool, error)

func (*RPC) LoginOAuth2

func (r *RPC) LoginOAuth2(in *pb.LoginOAuth2Request, srv pb.Daemon_LoginOAuth2Server) error

LoginOAuth2 is called when logging in with OAuth2.

func (*RPC) LoginOAuth2Callback

func (r *RPC) LoginOAuth2Callback(ctx context.Context, in *pb.LoginOAuth2CallbackRequest) (payload *pb.Empty, retErr error)

LoginOAuth2Callback is called by the browser via cli during OAuth2 login.

func (*RPC) LoginWithToken

func (r *RPC) LoginWithToken(ctx context.Context, in *pb.LoginWithTokenRequest) (*pb.LoginResponse, error)

Login the user with given token

func (*RPC) Logout

func (r *RPC) Logout(ctx context.Context, in *pb.LogoutRequest) (payload *pb.Payload, retErr error)

Logout erases user credentials and disconnects completely

func (*RPC) Ping

func (r *RPC) Ping(ctx context.Context, in *pb.Empty) (*pb.PingResponse, error)

func (*RPC) RateConnection

func (r *RPC) RateConnection(ctx context.Context, in *pb.RateRequest) (*pb.Payload, error)

func (*RPC) SetAllowlist

func (r *RPC) SetAllowlist(ctx context.Context, in *pb.SetAllowlistRequest) (*pb.Payload, error)

func (*RPC) SetAnalytics

func (r *RPC) SetAnalytics(ctx context.Context, in *pb.SetGenericRequest) (*pb.Payload, error)

SetAnalytics

func (*RPC) SetAutoConnect

func (r *RPC) SetAutoConnect(ctx context.Context, in *pb.SetAutoconnectRequest) (*pb.Payload, error)

func (*RPC) SetDNS

func (r *RPC) SetDNS(ctx context.Context, in *pb.SetDNSRequest) (*pb.SetDNSResponse, error)

func (*RPC) SetDefaults

func (r *RPC) SetDefaults(ctx context.Context, in *pb.Empty) (*pb.Payload, error)

func (*RPC) SetFirewall

func (r *RPC) SetFirewall(ctx context.Context, in *pb.SetGenericRequest) (*pb.Payload, error)

SetFirewall controls whether firewall should be used by the app or not.

This setting impacts the usage of these features: - Killswitch (impacts only next enabling) - Allowlist - Connect (impacts only connections, disconnect still works with the old setting)

func (*RPC) SetFirewallMark

func (r *RPC) SetFirewallMark(ctx context.Context, in *pb.SetUint32Request) (*pb.Payload, error)

func (*RPC) SetIpv6

func (r *RPC) SetIpv6(ctx context.Context, in *pb.SetGenericRequest) (*pb.Payload, error)

SetIpv6 controls whether ipv6 usage should be allowed

func (*RPC) SetKillSwitch

func (r *RPC) SetKillSwitch(ctx context.Context, in *pb.SetKillSwitchRequest) (*pb.Payload, error)

func (*RPC) SetLANDiscovery

func (r *RPC) SetLANDiscovery(ctx context.Context, in *pb.SetLANDiscoveryRequest) (*pb.SetLANDiscoveryResponse, error)

func (*RPC) SetNotify

func (r *RPC) SetNotify(ctx context.Context, in *pb.SetNotifyRequest) (*pb.Payload, error)

func (*RPC) SetObfuscate

func (r *RPC) SetObfuscate(ctx context.Context, in *pb.SetGenericRequest) (*pb.Payload, error)

func (*RPC) SetPostQuantum

func (r *RPC) SetPostQuantum(ctx context.Context, in *pb.SetGenericRequest) (*pb.Payload, error)

func (*RPC) SetProtocol

func (r *RPC) SetProtocol(ctx context.Context, in *pb.SetProtocolRequest) (*pb.SetProtocolResponse, error)

func (*RPC) SetRouting

func (r *RPC) SetRouting(ctx context.Context, in *pb.SetGenericRequest) (*pb.Payload, error)

SetRouting controls whether routing should be used by the app or not.

This setting impacts the usage of these features: - Allowlist - Connect - Meshnet

func (*RPC) SetTechnology

func (r *RPC) SetTechnology(ctx context.Context, in *pb.SetTechnologyRequest) (*pb.Payload, error)

func (*RPC) SetTray

func (r *RPC) SetTray(ctx context.Context, in *pb.SetTrayRequest) (*pb.Payload, error)

func (*RPC) SetVirtualLocation

func (r *RPC) SetVirtualLocation(ctx context.Context, in *pb.SetGenericRequest) (*pb.Payload, error)

func (*RPC) Settings

func (r *RPC) Settings(ctx context.Context, in *pb.Empty) (*pb.SettingsResponse, error)

Settings returns system daemon settings

func (*RPC) SettingsProtocols

func (r *RPC) SettingsProtocols(ctx context.Context, _ *pb.Empty) (*pb.Payload, error)

func (*RPC) SettingsTechnologies

func (r *RPC) SettingsTechnologies(ctx context.Context, _ *pb.Empty) (*pb.Payload, error)

func (*RPC) StartAutoConnect

func (r *RPC) StartAutoConnect(timeoutFn GetTimeoutFunc) error

StartAutoConnect connect to VPN server if autoconnect is enabled

func (*RPC) StartAutoMeshnet

func (r *RPC) StartAutoMeshnet(meshService *meshnet.Server, timeoutFn GetTimeoutFunc) error

StartAutoMeshnet enable meshnet if it was enabled before

func (*RPC) StartJobs

func (r *RPC) StartJobs(
	statePublisher *state.StatePublisher,
	heartBeatPublisher events.Publisher[time.Duration],
)

func (*RPC) StartKillSwitch

func (r *RPC) StartKillSwitch()

func (*RPC) StartSystemShutdownMonitor

func (r *RPC) StartSystemShutdownMonitor()

StartSystemShutdownMonitor to be run on separate goroutine

func (*RPC) Status

func (r *RPC) Status(context.Context, *pb.Empty) (*pb.StatusResponse, error)

Status of daemon and connection

func (*RPC) StopKillSwitch

func (r *RPC) StopKillSwitch() error

func (*RPC) SubscribeToStateChanges

func (r *RPC) SubscribeToStateChanges(_ *pb.Empty, srv pb.Daemon_SubscribeToStateChangesServer) error

func (*RPC) TokenInfo

func (r *RPC) TokenInfo(ctx context.Context, _ *pb.Empty) (*pb.TokenInfoResponse, error)

TokenInfo returns token information.

func (*RPC) UnsetAllAllowlist

func (r *RPC) UnsetAllAllowlist(ctx context.Context, in *pb.Empty) (*pb.Payload, error)

func (*RPC) UnsetAllowlist

func (r *RPC) UnsetAllowlist(ctx context.Context, in *pb.SetAllowlistRequest) (*pb.Payload, error)

type RepoAPI

type RepoAPI struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRepoAPI

func NewRepoAPI(
	baseURL string,
	version string,
	env internal.Environment,
	packageType,
	arch string,
	client *http.Client,
) *RepoAPI

func (*RepoAPI) DebianFileList

func (api *RepoAPI) DebianFileList() ([]byte, error)

func (*RepoAPI) RpmFileList

func (api *RepoAPI) RpmFileList() ([]byte, error)

type RepoAPIResponse

type RepoAPIResponse struct {
	Headers http.Header
	Body    io.ReadCloser
}

type ServerParameters

type ServerParameters struct {
	Country string
	City    string
	Group   config.ServerGroup
}

func GetServerParameters

func GetServerParameters(serverTag string, groupTag string, countries core.Countries) ServerParameters

type ServersData

type ServersData struct {
	UpdatedAt time.Time
	Servers   core.Servers
	Hash      string
	// contains filtered or unexported fields
}

type VersionData

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

Directories

Path Synopsis
Package device provides utilities for querying device information.
Package device provides utilities for querying device information.
Package dns is responsible for configuring dns on various Linux distros.
Package dns is responsible for configuring dns on various Linux distros.
Package firewall provides firewall service to the caller
Package firewall provides firewall service to the caller
allowlist
Package allowlist implements allowlist routing.
Package allowlist implements allowlist routing.
iptables
Package iptables implements iptables firewall agent.
Package iptables implements iptables firewall agent.
notables
Package notables implements noop firewall agent.
Package notables implements noop firewall agent.
Package response provides utilities for processing and validation of NordVPN backend api responses.
Package response provides utilities for processing and validation of NordVPN backend api responses.
Package routes provides route setting functionality.
Package routes provides route setting functionality.
iprule
Package iprule provides Go API for interacting with ip rule.
Package iprule provides Go API for interacting with ip rule.
netlink
Package netlink provides router implementation that uses netlink.
Package netlink provides router implementation that uses netlink.
norouter
Package norouter implements noop router.
Package norouter implements noop router.
norule
Package norule implements noop policy router.
Package norule implements noop policy router.
vpn
Package vpn provides interface for vpn management.
Package vpn provides interface for vpn management.
nordlynx
Package nordlynx provides nordlynx vpn technology.
Package nordlynx provides nordlynx vpn technology.
nordlynx/libtelio
Package libtelio wraps generated Go bindings so that the rest of the project would not need C dependencies to run unit tests.
Package libtelio wraps generated Go bindings so that the rest of the project would not need C dependencies to run unit tests.
openvpn
Package openvpn provides OpenVPN technology.
Package openvpn provides OpenVPN technology.

Jump to

Keyboard shortcuts

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