Documentation
¶
Index ¶
- Constants
- Variables
- func ActiveExitNetwork(except string) string
- func ClearSessionNotice()
- func EnsureSessionLoaded()
- func ForceLogout()
- func ForceRestorePhaseStartedAtForTest(t time.Time)
- func GetConfigPath() string
- func GetRestorePhase() string
- func HasOtherConnectedNetwork(except string) bool
- func HostHasDefaultRoute() bool
- func HostHasInstalledIGW() bool
- func IsDesktopServerCompatible(ver string) bool
- func IsSessionActive() bool
- func Refresh()
- func RestorePhaseStartedAt() time.Time
- func RestrictToSingleNetwork() bool
- func SessionAuthToken() string
- func SessionCredentials() (server, authToken string)
- func SessionIdentity() (username, tenantID string)
- func SetConfigPathForTest(dir string)
- func SetHandlers(d HandlerDeps)
- func SetRestorePhase(phase string)
- func SetSessionNotice(notice SessionNotice)
- func ShouldAbortSessionRestore() bool
- func ShouldDeferAutoExitClaim(network string) bool
- func Start(ctx context.Context)
- func Stop() error
- type ConfigureSessionRequest
- type Connection
- type DaemonHealthStatus
- type DaemonStatus
- type ErrorResponse
- type GetServerResponse
- type HandlerDeps
- type InterfaceStatus
- type Peer
- type SessionNotice
- type SetServerRequest
- type Status
Constants ¶
const ( RestorePhaseRegister = "register" RestorePhaseNetworks = "networks" RestorePhaseExit = "exit" RestorePhaseRoutes = "routes" )
Restore phase values exposed on GET /server while status=restoring.
const ErrCodeServerIncompatible = "server_incompatible"
ErrCodeServerIncompatible is returned on POST /server and PUT /session when the target Netmaker server is too old for this Desktop build.
const ErrCodeSessionRequired = "session_required"
ErrCodeSessionRequired is returned on session-gated routes when there is no usable Desktop JWT. The GUI should logout, clear local session, and stop polling.
const MinDesktopServerVersion = "v1.7.0"
MinDesktopServerVersion is the oldest Netmaker server this Desktop daemon refuses. Servers must be newer than this (v1.7.1+); v1.7.0 and below are incompatible with the NM-356 Desktop daemon.
Variables ¶
var OnRestoreIdle func()
OnRestoreIdle is set by the desktop package. Invoked when the restore phase transitions from a non-empty value to idle so deferred exit reconcile/teardown can run after the hold window.
Functions ¶
func ActiveExitNetwork ¶
ActiveExitNetwork is another connected network that already owns the default route / exit intent. The network being acted on (except) is never returned.
Desire is checked first so a clear→reselect on the owner network is not blocked, and so a second network cannot steal exit while routes flap. When desire is absent but the host still has a default route, ownership is inferred only in the single-connected-network case. With two+ networks up, blaming a sibling (e.g. after clear→assign) caused false 409s and exit theft.
func ClearSessionNotice ¶
func ClearSessionNotice()
ClearSessionNotice drops the current GUI notice.
func EnsureSessionLoaded ¶
func EnsureSessionLoaded()
EnsureSessionLoaded reads the persisted desktop session into memory. The CLI is a separate process from the daemon and otherwise sees no login.
func ForceLogout ¶
func ForceLogout()
ForceLogout clears the Desktop UI session (JWT) so the app returns to login. Keeps CurrServer / servers.json — callers demote the host entry for re-register. Used when the server deletes this host or force-logs out a disabled account.
func ForceRestorePhaseStartedAtForTest ¶
ForceRestorePhaseStartedAtForTest overrides the restore hold clock in tests.
func GetConfigPath ¶
func GetConfigPath() string
GetConfigPath returns the netclient config directory (single source of truth for uiapi files). Tests may override via SetConfigPathForTest.
func GetRestorePhase ¶
func GetRestorePhase() string
GetRestorePhase returns the current restore phase, or empty when idle.
func HasOtherConnectedNetwork ¶
HasOtherConnectedNetwork is true when any network other than except is up.
func HostHasDefaultRoute ¶
func HostHasDefaultRoute() bool
HostHasDefaultRoute reports whether the host currently has Netmaker IGW (CurrGw) or a peer advertising 0.0.0.0/0 / ::/0.
func HostHasInstalledIGW ¶
func HostHasInstalledIGW() bool
HostHasInstalledIGW is true only when CurrGw is set (routes installed). Peer AllowedIPs can still advertise 0.0.0.0/0 after a clear until MQTT converges — that must not block a new select or look like a foreign exit.
func IsDesktopServerCompatible ¶
IsDesktopServerCompatible reports whether a Netmaker server version can be used with this Desktop daemon (strictly newer than MinDesktopServerVersion). "dev" is always allowed. Unparseable versions are rejected.
func IsSessionActive ¶
func IsSessionActive() bool
IsSessionActive reports whether a non-expired desktop UI session is loaded.
func Refresh ¶
func Refresh()
Refresh reloads persisted session state without restarting the listener.
func RestorePhaseStartedAt ¶
RestorePhaseStartedAt returns when the current Networks/Exit/Routes hold began. Zero means idle or Register-only.
func RestrictToSingleNetwork ¶
func RestrictToSingleNetwork() bool
RestrictToSingleNetwork reports the RAC setting from the persisted session.
func SessionAuthToken ¶
func SessionAuthToken() string
SessionAuthToken returns the active desktop session JWT, or empty if none.
func SessionCredentials ¶
func SessionCredentials() (server, authToken string)
SessionCredentials returns the active server and user token for device API calls.
func SessionIdentity ¶
func SessionIdentity() (username, tenantID string)
SessionIdentity returns the logged-in username and tenant for auto-reconnect.
func SetConfigPathForTest ¶
func SetConfigPathForTest(dir string)
SetConfigPathForTest redirects GetConfigPath. Pass "" to restore the default.
func SetHandlers ¶
func SetHandlers(d HandlerDeps)
SetHandlers wires netclient operations into the desktop API layer.
func SetRestorePhase ¶
func SetRestorePhase(phase string)
SetRestorePhase records what session restore is doing for the GUI.
func SetSessionNotice ¶
func SetSessionNotice(notice SessionNotice)
SetSessionNotice stores a GUI notice and persists it with the session so a daemon restart still returns it on GET /session.
func ShouldAbortSessionRestore ¶
func ShouldAbortSessionRestore() bool
ShouldAbortSessionRestore is true when logout/handoff cancelled restore or the session is no longer usable.
func ShouldDeferAutoExitClaim ¶
ShouldDeferAutoExitClaim is true when auto-selecting an exit on network would steal from another network's exit (known owner) or from an installed IGW while multiple networks are up and desire does not name this network. Callers must not clear this network's server exit when this is true — it may be the owner (clearing kills routing right after a successful select).
Types ¶
type ConfigureSessionRequest ¶
type Connection ¶
type Connection struct {
Status InterfaceStatus `json:"status"`
Address *string `json:"address,omitempty"`
MTU *int `json:"mtu,omitempty"`
Peer *Peer `json:"peer,omitempty"`
Gateways []any `json:"gateways,omitempty"`
}
type DaemonHealthStatus ¶
type DaemonHealthStatus struct {
Status DaemonStatus `json:"status"`
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
OS string `json:"os"`
Arch string `json:"arch"`
}
type ErrorResponse ¶
type GetServerResponse ¶
type GetServerResponse struct {
Status Status `json:"status"`
Server string `json:"server"`
API string `json:"api"`
APIHost string `json:"APIHost"`
Username string `json:"username"`
AuthToken string `json:"auth_token"`
TenantID string `json:"tenant_id"`
Registered bool `json:"registered"`
ServerConfig nmConfig.ServerConfig `json:"server_config"`
RestorePhase string `json:"restore_phase,omitempty"`
WantIGW bool `json:"want_igw,omitempty"`
AutoExit bool `json:"auto_exit,omitempty"`
DesiredEgressID string `json:"desired_egress_id,omitempty"`
DesiredExitNetwork string `json:"desired_exit_network,omitempty"`
// DesiredNetworks is the desktop user's auto-reconnect set (session restore).
// Desktop multi-net UI uses this to mark per-network "Reconnecting…" instead
// of blocking the whole screen behind a restore panel.
DesiredNetworks []string `json:"desired_networks,omitempty"`
// Notice is a one-shot message for the GUI, such as a manual exit that
// failed its post-connect VPN health check.
Notice *SessionNotice `json:"notice,omitempty"`
}
type HandlerDeps ¶
type HandlerDeps struct {
RegisterSession func(server, username, authToken, password, tenantID string) error
// ReleaseSession tears down tunnels. When unregisterHost is true (user/tenant
// handoff on PUT /session), also DELETE the host under the current session
// JWT so the next Desktop login can enroll a different user/tenant.
// Normal logout passes unregisterHost=false so enrollment survives re-login.
ReleaseSession func(clearServer bool, unregisterHost bool) error
ApplyRegistrationReset func() <-chan struct{}
RegistrationResetPending func() bool
RegistrationEnrollmentPending func() bool
Connect func(network string) error
Disconnect func(network string) error
IsRegistered func(server string) bool
FetchNetworks func(server, token string) ([]models.DeviceNetwork, error)
JoinNetwork func(network, server, token string) (joinStatus string, err error)
LeaveNetwork func(network, server, token string) error
CancelJoin func(network, server, token string) error
RequestJIT func(network, server, token, reason string) error
Sync func(token string) error
ListExitNodes func(network, server, token string) ([]models.DeviceExitNode, error)
GetSelectedExitNode func(network, server, token string) (*models.DeviceExitNode, error)
SelectExitNode func(network, server, token, egressID string) (*models.DeviceExitNode, error)
SelectNearestExitNode func(network, server, token string) (*models.DeviceExitNode, error)
NetworkRequiresAutoExit func(network, server, token string) (bool, error)
RestoreDesiredConnections func(username, tenantID string) error
}
type InterfaceStatus ¶
type InterfaceStatus string
const ( InterfaceStatusUp InterfaceStatus = "up" InterfaceStatusDown InterfaceStatus = "down" )
type Peer ¶
type Peer struct {
PublicKey string `json:"public_key"`
AllowedIPs []string `json:"allowed_ips"`
Endpoint string `json:"endpoint"`
PersistentKeepalive string `json:"persistent_keepalive"`
LastHandshakeTime string `json:"last_handshake_time"`
ReceiveBytes int64 `json:"receive_bytes"`
SendBytes int64 `json:"send_bytes"`
}
type SessionNotice ¶
type SessionNotice struct {
Code string `json:"code"`
Network string `json:"network,omitempty"`
Message string `json:"message"`
}
SessionNotice is a message the desktop GUI can show from GET /session.
func GetSessionNotice ¶
func GetSessionNotice() SessionNotice
GetSessionNotice returns the current GUI notice. Code is empty when there is none.
type SetServerRequest ¶
type SetServerRequest struct {
// Server is the daemon map key: base domain for on-prem, tenant UUID for SaaS.
Server string `json:"server"`
// API is the dialable HTTPS host (api.<domain> or api-<tenant>.app…).
// Required for tenant UUID keys — never dial the UUID itself.
API string `json:"api,omitempty"`
}