Documentation ¶
Overview ¶
Package core provides Go HTTP client for interacting with Core API a.k.a. NordVPN API
Index ¶
- Constants
- Variables
- func ByGroup(s config.ServerGroup) func(Group) bool
- func ByTag(tag string) func(Group) bool
- func ExtractError(resp *http.Response) error
- type Authentication
- type CDN
- type CDNAPI
- type CDNAPIResponse
- type Cities
- type City
- type CombinedAPI
- type Countries
- type Country
- type CredentialsAPI
- type CredentialsResponse
- type CurrentUserResponse
- type DefaultAPI
- func (api *DefaultAPI) Accept(token string, self uuid.UUID, invitation uuid.UUID, doIAllowInbound bool, ...) error
- func (api *DefaultAPI) Base() string
- func (api *DefaultAPI) Configure(token string, id uuid.UUID, peerID uuid.UUID, ...) error
- func (api *DefaultAPI) CreateUser(email, password string) (*UserCreateResponse, error)
- func (api *DefaultAPI) CurrentUser(token string) (*CurrentUserResponse, error)
- func (api *DefaultAPI) DeleteToken(token string) error
- func (api *DefaultAPI) Insights() (*Insights, error)
- func (api *DefaultAPI) Invite(token string, self uuid.UUID, email string, doIAllowInbound bool, ...) error
- func (api *DefaultAPI) List(token string, self uuid.UUID) (mesh.MachinePeers, error)
- func (api *DefaultAPI) Local(token string) (mesh.Machines, error)
- func (api *DefaultAPI) Logout(token string) error
- func (api *DefaultAPI) Map(token string, self uuid.UUID) (*mesh.MachineMap, error)
- func (api *DefaultAPI) NotificationCredentials(token, appUserID string) (NotificationCredentialsResponse, error)
- func (api *DefaultAPI) NotifyNewTransfer(token string, self uuid.UUID, peer uuid.UUID, fileName string, fileCount int) error
- func (api *DefaultAPI) Plans() (*Plans, error)
- func (api *DefaultAPI) Received(token string, self uuid.UUID) (mesh.Invitations, error)
- func (api *DefaultAPI) RecommendedServers(filter ServersFilter, longitude, latitude float64) (Servers, http.Header, error)
- func (api *DefaultAPI) Register(token string, peer mesh.Machine) (*mesh.Machine, error)
- func (api *DefaultAPI) Reject(token string, self uuid.UUID, invitation uuid.UUID) error
- func (api *DefaultAPI) Revoke(token string, self uuid.UUID, invitation uuid.UUID) error
- func (api *DefaultAPI) Sent(token string, self uuid.UUID) (mesh.Invitations, error)
- func (api *DefaultAPI) Server(id int64) (*Server, error)
- func (api *DefaultAPI) Servers() (Servers, http.Header, error)
- func (api *DefaultAPI) ServersCountries() (Countries, http.Header, error)
- func (api *DefaultAPI) ServiceCredentials(token string) (*CredentialsResponse, error)
- func (api *DefaultAPI) Services(token string) (ServicesResponse, error)
- func (api *DefaultAPI) TokenRenew(token string) (*TokenRenewResponse, error)
- func (api *DefaultAPI) Unpair(token string, self uuid.UUID, peer uuid.UUID) error
- func (api *DefaultAPI) Unregister(token string, self uuid.UUID) error
- func (api *DefaultAPI) Update(token string, id uuid.UUID, info mesh.MachineUpdateRequest) error
- type Group
- type Groups
- type Insights
- type InsightsAPI
- type Location
- type Locations
- type LoginRequest
- type LoginResponse
- type NameServers
- type NotificationCredentialsRequest
- type NotificationCredentialsResponse
- type OAuth2
- type Pivot
- type Plan
- type Plans
- type Predicate
- type Server
- type ServerBy
- type ServerGroup
- type ServerIP
- type ServerIPRecord
- type ServerObfuscationStatus
- type ServerTag
- type ServerTechnology
- type Servers
- type ServersAPI
- type ServersFilter
- type Service
- type ServiceData
- type ServicesResponse
- type Specification
- type Status
- type Technologies
- type Technology
- type TokenRenewResponse
- type UserCreateRequest
- type UserCreateResponse
Constants ¶
const ( Online = "online" Offline = "offline" Maintenance = "maintenance" )
const ( HeaderDigest = "x-digest" // CDNURL is the url for NordCDN CDNURL = "https://downloads.nordcdn.com" // InsightsURL defines url to get information about ip // Used by JobInsights every 30mins to set the user country InsightsURL = "/v1/helpers/ips/insights" // PlanURL defines endpoint to fetch plans PlanURL = "/v1/plans?filters[plans.active]=1&filters[plans.type]=linux" // ServersURL defines url to get servers list // Used as a fallback if /v1/servers/recommendations returns // an empty list or a http error ServersURL = "/v1/servers" // ServersCountriesURL defines url to get servers countries list // Used by JobCountries every 6h to populate /var/lib/nordvpn/data/countries.dat ServersCountriesURL = ServersURL + "/countries" // RecommendedServersURL defines url for recommended servers list RecommendedServersURL = ServersURL + "/recommendations" // UsersURL defines url to create a new user UsersURL = "/v1/users" // TokensURL defines url to get user token TokensURL = UsersURL + "/tokens" // #nosec // ServicesURL defines url to check user's current/expired services ServicesURL = UsersURL + "/services" // CredentialsURL defines url to generate openvpn credentials CredentialsURL = ServicesURL + "/credentials" // CurrentUserURL defines url to check user's metadata CurrentUserURL = UsersURL + "/current" // TokenRenewURL defines url to renew user's token TokenRenewURL = UsersURL + "/tokens/renew" // #nosec // ServersURLConnectQuery is all servers query optimized // for minimal dm size required // to create servers maps and calculate their penalty scores // so instead of downloading 15mb we download 1.5mb // and when connecting, download all info about specific server // // no problems with this logic so far ServersURLConnectQuery = "?limit=1073741824" + "&filters[servers.status]=online" + "&fields[servers.id]" + "&fields[servers.name]" + "&fields[servers.hostname]" + "&fields[servers.station]" + "&fields[servers.status]" + "&fields[servers.load]" + "&fields[servers.created_at]" + "&fields[servers.groups.id]" + "&fields[servers.groups.title]" + "&fields[servers.technologies.id]" + "&fields[servers.technologies.metadata]" + "&fields[servers.technologies.pivot.status]" + "&fields[servers.specifications.identifier]" + "&fields[servers.specifications.values.value]" + "&fields[servers.locations.country.name]" + "&fields[servers.locations.country.code]" + "&fields[servers.locations.country.city.name]" + "&fields[servers.locations.country.city.latitude]" + "&fields[servers.locations.country.city.longitude]" + "&fields[servers.locations.country.city.hub_score]" + "&fields[servers.ips]" RecommendedServersURLConnectQuery = "?limit=%d" + "&filters[servers.status]=online" + "&filters[servers_technologies]=%d" + "&filters[servers_technologies][pivot][status]=online" + "&fields[servers.id]" + "&fields[servers.name]" + "&fields[servers.hostname]" + "&fields[servers.station]" + "&fields[servers.status]" + "&fields[servers.load]" + "&fields[servers.created_at]" + "&fields[servers.groups.id]" + "&fields[servers.groups.title]" + "&fields[servers.technologies.id]" + "&fields[servers.technologies.metadata]" + "&fields[servers.technologies.pivot.status]" + "&fields[servers.specifications.identifier]" + "&fields[servers.specifications.values.value]" + "&fields[servers.locations.country.name]" + "&fields[servers.locations.country.code]" + "&fields[servers.locations.country.city.name]" + "&fields[servers.locations.country.city.latitude]" + "&fields[servers.locations.country.city.longitude]" + "&coordinates[longitude]=%f&coordinates[latitude]=%f" + "&fields[servers.ips]" RecommendedServersCountryFilter = "&filters[country_id]=%d" RecommendedServersCityFilter = "&filters[country_city_id]=%d" RecommendedServersGroupsFilter = "&filters[servers_groups]=%d" // ServersURLSpecificQuery defines query params for a specific server ServersURLSpecificQuery = "?filters[servers.id]=%d" // DebFileinfoURLFormat is the path to debian repository's package information DebFileinfoURLFormat = "/deb/%s/debian/dists/stable/main/binary-%s/Packages.gz" // RpmRepoMdURLFormat is the path to rpm repository's information RpmRepoMdURLFormat = "/yum/%s/centos/%s/repodata/%s" // RpmRepoMdURL is the path to rpm repository's information file RpmRepoMdURL = "/repomd.xml" // RepoTypeProduction defines production repo type RepoTypeProduction = "nordvpn" // RepoTypeTest defines non-production (qa, development) repo type RepoTypeTest = "nordvpn-test" )
Variables ¶
var ( // ErrBadRequest is returned for 400 HTTP responses. ErrBadRequest = errors.New(http.StatusText(http.StatusBadRequest)) // ErrMaximumDeviceCount is returned for some of the 400 HTTP responses. ErrMaximumDeviceCount = errors.New("maximum device count reached") // error codes returned for meshnet nicknames, when 400 HTTP responses ErrRateLimitReach = errors.New("reach max allowed nickname changes for a week") ErrNicknameTooLong = errors.New("nickname is too long") ErrDuplicateNickname = errors.New("nickname already exist") ErrContainsForbiddenWord = errors.New("nickname contains forbidden word") ErrInvalidPrefixOrSuffix = errors.New("nickname contains invalid prefix or suffix") ErrNicknameWithDoubleHyphens = errors.New("nickname contains double hyphens") ErrContainsInvalidChars = errors.New("nickname contains invalid characters") ErrUnauthorized = errors.New(http.StatusText(http.StatusUnauthorized)) // ErrForbidden is returned for 403 HTTP responses. ErrForbidden = errors.New(http.StatusText(http.StatusForbidden)) // ErrNotFound is returned for 404 HTTP responses. ErrNotFound = errors.New(http.StatusText(http.StatusNotFound)) // ErrConflict is returned for 409 HTTP responses. ErrConflict = errors.New(http.StatusText(http.StatusConflict)) // ErrTooManyRequests is returned for 429 HTTP responses. ErrTooManyRequests = errors.New(http.StatusText(http.StatusTooManyRequests)) // ErrServerInternal is returned for 500 HTTP responses. ErrServerInternal = errors.New(http.StatusText(http.StatusInternalServerError)) )
var ( // ErrPublicKeyNotProvided is returned when peer does not have a public key set. ErrPublicKeyNotProvided = errors.New("public key not provided") // ErrPeerOSNotProvided is returned when peer does not have os name or os version set. ErrPeerOSNotProvided = errors.New("os not provided") // ErrPeerEndpointsNotProvided is returned when peer has on endpoints. ErrPeerEndpointsNotProvided = errors.New("endpoints not provided") )
Functions ¶
func ByGroup ¶
func ByGroup(s config.ServerGroup) func(Group) bool
ByGroup is a Comparison function meant for use with github.com/NordSecurity/nordvpn-linux/slices.ContainsFunc function.
func ByTag ¶
ByTag is a Comparison function meant for use with github.com/NordSecurity/nordvpn-linux/slices.ContainsFunc function.
func ExtractError ¶
ExtractError from the response if it exists
if an error was returned, do not try to read a response again.
Types ¶
type Authentication ¶
type Authentication interface { Login() (string, error) Token(string) (*LoginResponse, error) }
Authentication is responsible for verifying user's identity.
type CDN ¶
type CDN interface { ThreatProtectionLite() (*NameServers, error) ConfigTemplate(isObfuscated bool, method string) (http.Header, []byte, error) }
CDN provides methods to interact with Nord's Content Delivery Network
type CDNAPI ¶
func (*CDNAPI) ConfigTemplate ¶
func (*CDNAPI) ThreatProtectionLite ¶
func (api *CDNAPI) ThreatProtectionLite() (*NameServers, error)
type CDNAPIResponse ¶
type CDNAPIResponse struct { Headers http.Header Body io.ReadCloser }
type CombinedAPI ¶
type CombinedAPI interface { CredentialsAPI InsightsAPI ServersAPI Base() string Plans() (*Plans, error) Logout(token string) error CreateUser(email, password string) (*UserCreateResponse, error) }
type Country ¶
type Country struct { ID int64 `json:"id"` Name string `json:"name"` Code string `json:"code"` City `json:"city,omitempty"` Cities `json:"cities,omitempty"` }
Country is a weird struct in that it is defined in two different ways by the backend. Server recommendations endpoint response has city field, while server countries endpoint response has cities field. Basically, only one of the city/cities field exists at a given time.
type CredentialsAPI ¶
type CredentialsAPI interface { NotificationCredentials(token, appUserID string) (NotificationCredentialsResponse, error) ServiceCredentials(string) (*CredentialsResponse, error) TokenRenew(string) (*TokenRenewResponse, error) Services(string) (ServicesResponse, error) CurrentUser(string) (*CurrentUserResponse, error) DeleteToken(string) error }
type CredentialsResponse ¶
type CurrentUserResponse ¶
type DefaultAPI ¶
type DefaultAPI struct {
// contains filtered or unexported fields
}
func NewDefaultAPI ¶
func (*DefaultAPI) Accept ¶
func (api *DefaultAPI) Accept( token string, self uuid.UUID, invitation uuid.UUID, doIAllowInbound bool, doIAllowRouting bool, doIAllowLocalNetwork bool, doIAllowFileshare bool, ) error
Accept invitation.
func (*DefaultAPI) Base ¶
func (api *DefaultAPI) Base() string
func (*DefaultAPI) Configure ¶
func (api *DefaultAPI) Configure( token string, id uuid.UUID, peerID uuid.UUID, peerUpdateInfo mesh.PeerUpdateRequest, ) error
Configure interaction with a specific peer.
func (*DefaultAPI) CreateUser ¶
func (api *DefaultAPI) CreateUser(email, password string) (*UserCreateResponse, error)
CreateUser accepts email and password as arguments and creates the user
func (*DefaultAPI) CurrentUser ¶
func (api *DefaultAPI) CurrentUser(token string) (*CurrentUserResponse, error)
CurrentUser returns metadata of current user
func (*DefaultAPI) DeleteToken ¶
func (api *DefaultAPI) DeleteToken(token string) error
func (*DefaultAPI) Insights ¶
func (api *DefaultAPI) Insights() (*Insights, error)
Insights returns insights about user
func (*DefaultAPI) Invite ¶
func (api *DefaultAPI) Invite( token string, self uuid.UUID, email string, doIAllowInbound bool, doIAllowRouting bool, doIAllowLocalNetwork bool, doIAllowFileshare bool, ) error
Invite to mesh.
func (*DefaultAPI) List ¶
func (api *DefaultAPI) List(token string, self uuid.UUID) (mesh.MachinePeers, error)
List peers in the mesh network for a given peer.
func (*DefaultAPI) Local ¶
func (api *DefaultAPI) Local(token string) (mesh.Machines, error)
Local peer list.
func (*DefaultAPI) Logout ¶
func (api *DefaultAPI) Logout(token string) error
func (*DefaultAPI) Map ¶
func (api *DefaultAPI) Map(token string, self uuid.UUID) (*mesh.MachineMap, error)
func (*DefaultAPI) NotificationCredentials ¶
func (api *DefaultAPI) NotificationCredentials(token, appUserID string) (NotificationCredentialsResponse, error)
NotificationCredentials retrieves the credentials for notification center appUserID
func (*DefaultAPI) NotifyNewTransfer ¶
func (api *DefaultAPI) NotifyNewTransfer( token string, self uuid.UUID, peer uuid.UUID, fileName string, fileCount int, ) error
Notify peer about a new incoming transfer
func (*DefaultAPI) Plans ¶
func (api *DefaultAPI) Plans() (*Plans, error)
func (*DefaultAPI) Received ¶
func (api *DefaultAPI) Received(token string, self uuid.UUID) (mesh.Invitations, error)
Received invitations from other users.
func (*DefaultAPI) RecommendedServers ¶
func (api *DefaultAPI) RecommendedServers(filter ServersFilter, longitude, latitude float64) (Servers, http.Header, error)
RecommendedServers returns recommended servers list
func (*DefaultAPI) Sent ¶
func (api *DefaultAPI) Sent(token string, self uuid.UUID) (mesh.Invitations, error)
Sent invitations to other users.
func (*DefaultAPI) Server ¶
func (api *DefaultAPI) Server(id int64) (*Server, error)
Server returns specific server
func (*DefaultAPI) Servers ¶
func (api *DefaultAPI) Servers() (Servers, http.Header, error)
Servers returns servers list
func (*DefaultAPI) ServersCountries ¶
func (api *DefaultAPI) ServersCountries() (Countries, http.Header, error)
ServersCountries returns server countries list
func (*DefaultAPI) ServiceCredentials ¶
func (api *DefaultAPI) ServiceCredentials(token string) (*CredentialsResponse, error)
ServiceCredentials returns service credentials
func (*DefaultAPI) Services ¶
func (api *DefaultAPI) Services(token string) (ServicesResponse, error)
Services returns all previously and currently used services by the user
func (*DefaultAPI) TokenRenew ¶
func (api *DefaultAPI) TokenRenew(token string) (*TokenRenewResponse, error)
TokenRenew queries the renew token and returns new token data
func (*DefaultAPI) Unregister ¶
func (api *DefaultAPI) Unregister(token string, self uuid.UUID) error
Unregister peer from the mesh network.
func (*DefaultAPI) Update ¶
func (api *DefaultAPI) Update(token string, id uuid.UUID, info mesh.MachineUpdateRequest) error
Update publishes new endpoints.
type Group ¶
type Group struct { ID config.ServerGroup `json:"id"` Title string `json:"title"` }
type InsightsAPI ¶
type LoginRequest ¶
type LoginResponse ¶
type NameServers ¶
type NameServers struct {
Servers []string `json:"servers"`
}
type Predicate ¶
Predicate function used in algorithms like filter.
func IsConnectableVia ¶
func IsConnectableVia(tech ServerTechnology) Predicate
IsConnectableVia returns true if it's possible to connect to server using a given technology.
func IsConnectableWithProtocol ¶
func IsConnectableWithProtocol(tech config.Technology, proto config.Protocol) Predicate
IsConnectableWithProtocol behaves like IsConnectableVia, but also includes protocol.
func IsObfuscated ¶
func IsObfuscated() Predicate
IsObfuscated returns a filter for keeping only obfuscated servers.
type Server ¶
type Server struct { ID int64 `json:"id"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` Name string `json:"name"` Station string `json:"station"` Hostname string `json:"hostname"` Load int64 `json:"load"` Status Status `json:"status"` Locations `json:"locations"` Technologies Technologies `json:"technologies"` Groups `json:"groups"` Specifications []Specification `json:"specifications"` Distance float64 `json:"distance"` Timestamp int64 `json:"timestamp"` Penalty float64 `json:"penalty"` PartialPenalty float64 `json:"partial_penalty"` NordLynxPublicKey string `json:"-"` Keys []string `json:"-"` IPRecords []ServerIPRecord `json:"ips"` }
func (*Server) SupportsIPv6 ¶
func (*Server) UnmarshalJSON ¶
type ServerGroup ¶
type ServerGroup int64
ServerGroup represents a server group type
const ( // UndefinedGroup represents non existing server group UndefinedGroup ServerGroup = 0 // DoubleVPN represents the double vpn server group DoubleVPN ServerGroup = 1 // OnionOverVPN represents a OnionOverVPN server group OnionOverVPN ServerGroup = 3 // UltraFastTV represents a UltraFastTV server group UltraFastTV ServerGroup = 5 // AntiDDoS represents an AntiDDoS server group AntiDDoS ServerGroup = 7 // DedicatedIP servers represents the Dedicated IP servers DedicatedIP ServerGroup = 9 // StandardVPNServers represents a StandardVPNServers group StandardVPNServers ServerGroup = 11 // NetflixUSA represents a NetflixUSA server group NetflixUSA ServerGroup = 13 // P2P represents a P2P server group P2P ServerGroup = 15 // Obfuscated represents an Obfuscated server group Obfuscated ServerGroup = 17 // Europe servers represents the European servers Europe ServerGroup = 19 // TheAmericas represents TheAmericas servers TheAmericas ServerGroup = 21 // AsiaPacific represents a AsiaPacific server group AsiaPacific ServerGroup = 23 // AfricaMiddleEastIndia represents a Africa, the Middle East and India server group AfricaMiddleEastIndia ServerGroup = 25 )
type ServerIPRecord ¶
type ServerObfuscationStatus ¶
type ServerObfuscationStatus int
ServerObfuscationStatus is the return status of IsServerObfuscated
const ( // ServerObfuscated status returned when server is obfuscated ServerObfuscated ServerObfuscationStatus = iota // ServerNotObfuscated status returned when server is not obfuscated ServerNotObfuscated // NotAServerName returned when server with such name has not been found // (there is no hostname beginning with given server tag) NotAServerName )
func IsServerObfuscated ¶
func IsServerObfuscated(servers Servers, serverTag string) ServerObfuscationStatus
IsServerObfuscated returns ServerObfuscationStatus for a given server tag
type ServerTechnology ¶
type ServerTechnology int64
ServerTechnology represents the nordvpn server technology
const ( // Unknown is used for invalid cases Unknown ServerTechnology = 0 // OpenVPNUDP represents the OpenVPN udp technology OpenVPNUDP ServerTechnology = 3 // OpenVPNTCP represents the OpenVpn tcp technology OpenVPNTCP ServerTechnology = 5 // Socks5 represents the socks 5 technology Socks5 ServerTechnology = 7 // HTTPProxy represents the http proxy technology HTTPProxy ServerTechnology = 9 // PPTP represents the pptp technology PPTP ServerTechnology = 11 // L2TP represents the l2tp technology L2TP ServerTechnology = 13 // OpenVPNUDPObfuscated represents the openvpn udp obfuscated technology OpenVPNUDPObfuscated ServerTechnology = 15 // OpenVPNTCPObfuscated represents the openvpn tcp obfuscated technology OpenVPNTCPObfuscated ServerTechnology = 17 // WireguardTech represents wireguard technology WireguardTech ServerTechnology = 35 )
type ServersAPI ¶
type ServersFilter ¶
type ServersFilter struct { Limit int Tech ServerTechnology Group config.ServerGroup Tag ServerTag }
type ServiceData ¶
type ServicesResponse ¶
type ServicesResponse []ServiceData
type Specification ¶
type Status ¶
type Status string
Status is used by Server and Technology to communicate availability
type Technologies ¶
type Technologies []Technology
type Technology ¶
type Technology struct { ID ServerTechnology `json:"id"` Pivot Pivot `json:"pivot"` Metadata []struct { Name string `json:"name,omitempty"` Value interface{} `json:"value,omitempty"` } `json:"metadata"` }
func (Technology) IsOnline ¶
func (t Technology) IsOnline() bool