server

package
v0.35.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: GPL-3.0 Imports: 51 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ServiceName = "Nps"

ServiceName is the name nps is installed as a system service under.

Variables

View Source
var (
	// ErrUpdateDisabled is returned by UpdateSelf when remote update is off.
	ErrUpdateDisabled = errors.New("remote update is disabled")
	// ErrUpdateRunning is returned by UpdateSelf while an update runs.
	ErrUpdateRunning = errors.New("an update is already running")
)
View Source
var ErrClosed = errors.New("server closed")

ErrClosed is returned by the operations of a server that is closed.

View Source
var EventTunnelsReport = logevent.TunnelsReport.Name

EventTunnelsReport is the type of the periodic full report.

Functions

func ApplyLimits added in v0.35.0

func ApplyLimits(cfg *servercfg.Snapshot)

ApplyLimits hands the flow and history settings to lib/model.

func ApplyNTP added in v0.35.0

func ApplyNTP(cfg *servercfg.Snapshot)

ApplyNTP starts the time sync as cfg says.

func GetCurrentYear

func GetCurrentYear() int

func GetVersion

func GetVersion() string

Types

type Config added in v0.35.0

type Config struct {
	// DisconnectTimeout is how long, in seconds, a silent client tunnel lives.
	DisconnectTimeout int
	// Transports are the bridge transports that listen on a port of their own.
	Transports bridge.Transports
	// SecureMode refuses the handshakes of npc versions that predate secure
	// mode.
	SecureMode bool
	// SelectMode is how a client with several nodes picks the node of a new
	// link.
	SelectMode bridge.SelectMode
	// DisableRemoteUpdate keeps the web interface from updating the server.
	DisableRemoteUpdate bool
	// LatestVersion returns the latest release as last known, or "" when
	// unknown, without waiting for the network; npc older than it can be
	// updated from the web. Nil compares with the server's own version.
	LatestVersion func() string
	// AllowedPorts are the ports tunnels may listen on; the zero value
	// allows every port.
	AllowedPorts ports.Allowed
	// Identity is the certificate of the bridge and the encrypted links, and
	// the key of the web login.
	Identity *crypt.Identity
	// AccessLog, if set, is called with every request to the domain proxy
	// when it ends, whatever the log level (httpproxy.HttpProxy.AccessLog).
	AccessLog func(httpproxy.AccessRecord)
	// CoreEntry is the new protocol on the bridge ports.
	CoreEntry coreapi.Entry
}

Config holds what a Server needs beyond the store and the current configuration.

type HostState added in v0.35.0

type HostState struct {
	model.HostInfo
	ClientOnline bool  `json:"client_online"`
	NowConn      int32 `json:"now_conn"`
	InletFlow    int64 `json:"inlet_flow"`
	ExportFlow   int64 `json:"export_flow"`
}

HostState is a domain entry in the full report.

type Server added in v0.35.0

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

Server is a running nps: the bridge the clients connect to, the tasks it serves, the web manager and the background work around them. Start starts it, Close stops it and waits for everything it started.

func New added in v0.35.0

func New(db *file.DbUtils, cfg Config) *Server

New returns a server of the entries in db; nothing runs before Start.

func (*Server) AddConfigApplier added in v0.35.0

func (s *Server) AddConfigApplier(a servercfg.Applier)

AddConfigApplier adds a, applied after those of the server in a reload.

func (*Server) AddTunnel added in v0.35.0

func (s *Server) AddTunnel(t *model.Tunnel) error

AddTunnel starts task t. Services that own a listening socket bind it before AddTunnel returns, so address errors are reported to the caller and a later StopTunnel always finds the running instance.

func (*Server) ApplyWebhook added in v0.35.0

func (s *Server) ApplyWebhook(cfg servercfg.WebhookConfig)

ApplyWebhook makes the webhook run as cfg says; it restarts it, discarding what is queued, only if cfg changed. The hub exists only while a webhook is configured, so entry changes cost nothing otherwise.

func (*Server) Bridge added in v0.35.0

func (s *Server) Bridge() *bridge.Bridge

Bridge returns the bridge of the server.

func (*Server) BuildTunnelsReport added in v0.35.0

func (s *Server) BuildTunnelsReport() TunnelsReport

BuildTunnelsReport snapshots all tunnels and domain entries, by id.

func (*Server) CanUpdateSelf added in v0.35.0

func (s *Server) CanUpdateSelf() bool

CanUpdateSelf reports whether the web interface may update the server.

func (*Server) ClientCanUpdate added in v0.35.0

func (s *Server) ClientCanUpdate(clientId int) bool

ClientCanUpdate reports whether a connected npc of client clientId can be updated from the web.

func (*Server) ClientConnected added in v0.35.0

func (s *Server) ClientConnected(id int) bool

ClientConnected reads live bridge membership without refreshing or sorting lists.

func (*Server) ClientPipes added in v0.35.2

func (s *Server) ClientPipes(id int) string

ClientPipes summarizes the carriers of the pipes client id uses now.

func (*Server) Close added in v0.35.0

func (s *Server) Close() error

Close stops the server and returns once every goroutine it started has returned. It first stops accepting management and registration requests, then closes the tasks, then the bridge with its clients, then the webhook. It returns the failure that stopped the server, if one did.

func (*Server) ConfigAppliers added in v0.35.0

func (s *Server) ConfigAppliers() []servercfg.Applier

ConfigAppliers returns the appliers of a reload in their order: those of the process and the server, then those added with AddConfigApplier.

func (*Server) DashboardData added in v0.35.0

func (s *Server) DashboardData(force bool) map[string]any

DashboardData returns the dashboard data, refreshed when force or when the cache is old.

func (*Server) DeleteClientResources added in v0.35.0

func (s *Server) DeleteClientResources(id int)

DeleteClientResources removes all tasks and domain entries of client id.

func (*Server) DeleteTunnel added in v0.35.0

func (s *Server) DeleteTunnel(id int) error

DeleteTunnel stops task id and removes it from the store.

func (*Server) DisconnectClient added in v0.35.0

func (s *Server) DisconnectClient(clientId int)

DisconnectClient closes the connections of client clientId.

func (*Server) Done added in v0.35.0

func (s *Server) Done() <-chan struct{}

Done is closed when the server starts stopping: by Close, by the end of the context given to Start, or by a failure after Start.

func (*Server) GenerateTunnelPort added in v0.35.0

func (s *Server) GenerateTunnelPort(t *model.Tunnel) int

GenerateTunnelPort picks a free port for t.

func (*Server) Identity added in v0.35.0

func (s *Server) Identity() *crypt.Identity

Identity returns the certificate and login key of the server.

func (*Server) ListClients added in v0.35.0

func (s *Server) ListClients(start, length int, search, sortField, order string, clientId int) (list []*model.Client, cnt int)

ListClients returns a page of the clients that match, and how many match.

func (*Server) ListHosts added in v0.35.0

func (s *Server) ListHosts(start, length, clientId int, search, sortField, order string) (list []*model.Host, cnt int)

ListHosts returns a page of the domain entries that match, and how many match.

func (*Server) ListTunnels added in v0.35.0

func (s *Server) ListTunnels(start, length int, typeVal string, clientId int, search string, sortField string, order string) ([]*model.Tunnel, int)

ListTunnels returns a page of the tasks that match, and how many match.

func (*Server) PingClient added in v0.35.0

func (s *Server) PingClient(id int, addr string) int

PingClient measures the round trip to client id, -1 when it fails.

func (*Server) ReloadConfig added in v0.35.0

func (s *Server) ReloadConfig() servercfg.Report

ReloadConfig reloads the config file and logs and returns the outcome.

func (*Server) RemoveHostCache added in v0.35.0

func (s *Server) RemoveHostCache(id int)

RemoveHostCache drops what the HTTP proxy cached of domain entry id.

func (*Server) RequestClientUpdate added in v0.35.0

func (s *Server) RequestClientUpdate(clientId int) (int, error)

RequestClientUpdate asks the connected npc of client clientId to update themselves; it returns how many were asked.

func (*Server) SetIPRegisterHandler added in v0.35.0

func (s *Server) SetIPRegisterHandler(handler http.Handler)

SetIPRegisterHandler sets the registration page that Start serves; call it before Start. Without it the page does not run.

func (*Server) SetWebHandler added in v0.35.0

func (s *Server) SetWebHandler(handler http.Handler)

SetWebHandler sets the handler of the web manager; it applies to a running server, so a config reload replaces it.

func (*Server) Start added in v0.35.0

func (s *Server) Start(ctx context.Context) error

Start opens the bridge listeners, starts the tasks of the store, the web manager and the background work. It returns the first error that keeps nps from starting; Close then releases what was started. A failure after that, of the web manager or of a bridge listener, stops the server: Done is closed and Close returns the failure. The server also stops when ctx is done.

func (*Server) StartTunnel added in v0.35.0

func (s *Server) StartTunnel(id int) error

StartTunnel starts task id of the store and marks it started.

func (*Server) StopTunnel added in v0.35.0

func (s *Server) StopTunnel(id int) error

StopTunnel stops task id and marks it stopped in the store.

func (*Server) Store added in v0.35.0

func (s *Server) Store() *file.DbUtils

Store returns the store of the entries the server serves.

func (*Server) TunnelPortAvailable added in v0.35.0

func (s *Server) TunnelPortAvailable(t *model.Tunnel) bool

TunnelPortAvailable reports whether t may listen on its port.

func (*Server) TunnelRunning added in v0.35.0

func (s *Server) TunnelRunning(id int) bool

TunnelRunning reports whether task id runs.

func (*Server) UpdateSelf added in v0.35.0

func (s *Server) UpdateSelf() (string, error)

UpdateSelf updates the server to the latest release and restarts it shortly as the new version. It returns the version updated to, or "" when the running version is the latest.

func (*Server) VirtualServices added in v0.35.0

func (s *Server) VirtualServices() []bridge.VirtualService

VirtualServices lists the services connected clients report.

type TunnelState added in v0.35.0

type TunnelState struct {
	model.TunnelInfo
	Running      bool  `json:"running"`
	ClientOnline bool  `json:"client_online"`
	NowConn      int32 `json:"now_conn"`
	InletFlow    int64 `json:"inlet_flow"`
	ExportFlow   int64 `json:"export_flow"`
}

TunnelState is a tunnel in the full report.

type TunnelsReport added in v0.35.0

type TunnelsReport struct {
	Tunnels []TunnelState `json:"tunnels"`
	Hosts   []HostState   `json:"hosts"`
}

TunnelsReport lets a receiver correct what it missed of the events.

type WebServer added in v0.32.2

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

WebServer serves the web manager of a Server on the web port and on the in-memory listener that bridge://web targets reach.

func NewWebServer added in v0.32.2

func NewWebServer(srv *Server) *WebServer

NewWebServer returns the web manager of srv.

func (*WebServer) Close added in v0.32.2

func (s *WebServer) Close() error

Close closes the listeners of the web manager; Start then returns.

func (*WebServer) Start added in v0.32.2

func (s *WebServer) Start() error

Directories

Path Synopsis
Package ports checks and picks the ports that tunnels listen on, within the ports the server config allows.
Package ports checks and picks the ports that tunnels listen on, within the ports the server config allows.
Package stats samples the load, memory and traffic of the server for the dashboard.
Package stats samples the load, memory and traffic of the server for the dashboard.

Jump to

Keyboard shortcuts

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