daemon

package
v0.0.0-...-851e5e8 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 44 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 (
	// 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 Connect

func Connect(
	events chan ConnectEvent,
	creds vpn.Credentials,
	serverData vpn.ServerData,
	allowlist config.Allowlist,
	nameservers []string,
	netw networker.Networker,
)

func GetLatestVersion

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

func JobCountries

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

func JobHeartBeat

func JobHeartBeat(
	timePeriod int,
	events *Events,
) func()

JobHeartBeat sends heart beats.

func JobInsights

func JobInsights(
	dm InsightsDataManager,
	api core.InsightsAPI,
	networker interface{ IsVPNActive() bool },
	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.CombinedAPI,
	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 excees 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,
) (core.Server, bool, error)

PickServer by the specified criteria.

func SetAppData

func SetAppData(dm *DataManager, tech config.Technology, servers core.Servers)

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 {
	CountryNames map[bool]map[config.Protocol]mapset.Set[string]
	CityNames    map[bool]map[config.Protocol]map[string]mapset.Set[string]
	GroupNames   map[bool]map[config.Protocol]mapset.Set[string]
}

type ConnectEvent

type ConnectEvent struct {
	Code    int64
	Message string
}

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) *DataManager

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) 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) SetAppData

func (dm *DataManager) SetAppData(
	countryNames map[bool]map[config.Protocol]mapset.Set[string],
	cityNames map[bool]map[config.Protocol]map[string]mapset.Set[string],
	groupNames map[bool]map[config.Protocol]mapset.Set[string],
)

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) 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 Publisher

type Publisher interface {
	SettingsPublisher
	ServicePublisher
}

type RPC

type RPC struct {
	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,
	fw firewall.Service,
	events *Events,
	factory FactoryFunc,
	endpointResolver network.EndpointResolver,
	netw networker.Networker,
	publisher events.Publisher[string],
	nameservers dns.Getter,
	ncClient nc.NotificationClient,
	analytics events.Analytics,
	norduser service.NorduserService,
	meshRegistry mesh.Registry,
) *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.Payload, error)

Cities provides cities command and autocompletion.

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) Countries

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

Countries provides country command and country autocompletion.

func (*RPC) Disconnect

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

func (*RPC) Groups

func (r *RPC) Groups(ctx context.Context, in *pb.Empty) (*pb.Payload, 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.Empty, 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.String) (*pb.Empty, 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) (*pb.Payload, error)

Logout erases user credentials and disconnects completely

func (*RPC) Ping

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

func (*RPC) Plans

func (r *RPC) Plans(ctx context.Context, in *pb.Empty) (*pb.PlansResponse, error)

func (*RPC) RateConnection

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

func (*RPC) Register

func (r *RPC) Register(ctx context.Context, in *pb.RegisterRequest) (*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) 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) Settings

func (r *RPC) Settings(ctx context.Context, in *pb.SettingsRequest) (*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()

func (*RPC) StartKillSwitch

func (r *RPC) StartKillSwitch()

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) TokenInfo

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

TokenInfo returns token information.

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 ServersData

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

type ServicePublisher

type ServicePublisher interface {
	NotifyConnect(events.DataConnect) error
	NotifyDisconnect(events.DataDisconnect) error
	NotifyLogin(any) error
	NotifyAccountCheck(core.ServicesResponse) error
	NotifyRate(events.ServerRating) error
	NotifyHeartBeat(int) error
}

type SettingsEvents

func (*SettingsEvents) Publish

func (s *SettingsEvents) Publish(cfg config.Config)

func (*SettingsEvents) Subscribe

func (s *SettingsEvents) Subscribe(to SettingsPublisher)

type SettingsPublisher

type SettingsPublisher interface {
	NotifyKillswitch(bool) error
	NotifyAutoconnect(bool) error
	NotifyDNS(events.DataDNS) error
	NotifyThreatProtectionLite(bool) error
	NotifyProtocol(config.Protocol) error
	NotifyAllowlist(events.DataAllowlist) error
	NotifyTechnology(config.Technology) error
	NotifyObfuscate(bool) error
	NotifyFirewall(bool) error
	NotifyRouting(bool) error
	NotifyNotify(bool) error
	NotifyMeshnet(bool) error
	NotifyIpv6(bool) error
	NotifyDefaults(any) error
}

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.
iprouter
Package iprouter provides Go API for interacting with ip route.
Package iprouter provides Go API for interacting with ip route.
iprule
Package iprule provides Go API for interacting with ip rule.
Package iprule provides Go API for interacting with ip rule.
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