file

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 31 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

This section is empty.

Variables

This section is empty.

Functions

func GetMapKeys

func GetMapKeys(m *sync.Map, isSort bool, sortKey, order string) (keys []int)

func RefreshAccessLists added in v0.35.0

func RefreshAccessLists()

RefreshAccessLists recompiles the access lists whose geodata changed, and logs the lists that keep their rules because the new geodata breaks some.

func ReportGeoData added in v0.35.0

func ReportGeoData()

ReportGeoData logs the geodata files the access lists use, as source_loaded for each file present.

func WatchAccessLists added in v0.34.9

func WatchAccessLists(ctx context.Context, interval time.Duration)

WatchAccessLists checks the geodata files every interval until ctx ends and refreshes the access lists when one of them changed, so that updated geodata takes effect. Checking reads file metadata only.

Types

type DbUtils

type DbUtils struct {
	JsonDb *JsonDb
	// contains filtered or unexported fields
}

func New added in v0.35.0

func New(runPath string) *DbUtils

New returns an empty store kept in the conf directory of runPath.

func Open added in v0.35.0

func Open(runPath string) (*DbUtils, error)

Open returns the store kept in the conf directory of runPath, loaded from its files.

func (*DbUtils) ClientChanged added in v0.35.0

func (s *DbUtils) ClientChanged(c *model.Client)

ClientChanged reports that the client c was changed in place.

func (*DbUtils) ClientEntryCount added in v0.35.0

func (s *DbUtils) ClientEntryCount(c *model.Client) (num int)

ClientEntryCount returns how many tunnels and hosts c has.

func (*DbUtils) ClientHost added in v0.35.0

func (s *DbUtils) ClientHost(c *model.Client, h *model.Host) (hh *model.Host, exist bool)

ClientHost returns the stored host of c with the host and location of h.

func (*DbUtils) ClientPresence added in v0.35.0

func (s *DbUtils) ClientPresence(id int, c *model.Client, online bool)

ClientPresence reports that client id got or lost its session; c is nil if the client was deleted already. Sessions of the public and visitor keys, not being clients an administrator manages, are left out. A session joined by more connections reports online once.

func (*DbUtils) ClientTunnel added in v0.35.0

func (s *DbUtils) ClientTunnel(c *model.Client, t *model.Tunnel) (tt *model.Tunnel, exist bool)

ClientTunnel returns the stored tunnel of c on the port or with the password of t.

func (*DbUtils) DelClient

func (s *DbUtils) DelClient(id int) error

func (*DbUtils) DelHost

func (s *DbUtils) DelHost(id int) error

func (*DbUtils) DelTask

func (s *DbUtils) DelTask(id int) error

func (*DbUtils) FindCertByHost

func (s *DbUtils) FindCertByHost(host string) (*model.Host, error)

FindCertByHost returns the host entry that terminates TLS for the server name host. An entry for the exact name beats a wildcard one, and a longer wildcard suffix a shorter one; among entries for the same name, one with TLS configured (a certificate or AutoSSL) wins, then the one with the shortest location, then the lowest id, so the choice never depends on map order. Names compare case-insensitively, ignoring a trailing dot.

func (*DbUtils) FindReusableCert added in v0.35.0

func (s *DbUtils) FindReusableCert(host string, excludeID, clientID int) (*model.Host, error)

FindReusableCert returns the entry whose certificate FindCertByHost would choose for the server name host among those with certificate files, leaving out the entry excludeID and, unless clientID is 0, entries of other clients.

func (*DbUtils) GetClient

func (s *DbUtils) GetClient(id int) (c *model.Client, err error)

func (*DbUtils) GetClientIdByBlake2bVkey added in v0.29.9

func (s *DbUtils) GetClientIdByBlake2bVkey(vkey string) (id int, err error)

func (*DbUtils) GetClientIdByMd5Vkey added in v0.27.0

func (s *DbUtils) GetClientIdByMd5Vkey(vkey string) (id int, err error)

func (*DbUtils) GetClientList

func (s *DbUtils) GetClientList(start, length int, search, sort, order string, clientId int) ([]*model.Client, int)

func (*DbUtils) GetGlobal

func (s *DbUtils) GetGlobal() (c *model.Glob)

func (*DbUtils) GetHost

func (s *DbUtils) GetHost(start, length int, id int, search string) ([]*model.Host, int)

func (*DbUtils) GetHostById

func (s *DbUtils) GetHostById(id int) (h *model.Host, err error)

func (*DbUtils) GetIdByVerifyKey

func (s *DbUtils) GetIdByVerifyKey(vKey, addr, localAddr string, hashFunc func(string) string) (id int, err error)

func (*DbUtils) GetInfoByHost

func (s *DbUtils) GetInfoByHost(host string, r *http.Request) (h *model.Host, err error)

GetInfoByHost get key by host from x

func (*DbUtils) GetTask

func (s *DbUtils) GetTask(id int) (t *model.Tunnel, err error)

func (*DbUtils) GetTaskByAccessID added in v0.35.0

func (s *DbUtils) GetTaskByAccessID(id []byte) *model.Tunnel

GetTaskByAccessID returns the task whose password has the access id (coreapi.AccessID), nil if none has.

func (*DbUtils) GetTaskByLegacySecret added in v0.35.3

func (s *DbUtils) GetTaskByLegacySecret(sum []byte) (t *model.Tunnel)

GetTaskByLegacySecret returns the point-to-point task whose password has the MD5 hex digest sum, nil if none has. npc before 0.35 names the task of a relayed access this way; the few such tasks are searched, as no index keeps a digest that only old visitors use.

func (*DbUtils) GetTaskBySecretIndex added in v0.35.0

func (s *DbUtils) GetTaskBySecretIndex(p string) (t *model.Tunnel)

GetTaskBySecretIndex returns the task whose password has index p (crypt.SecretIndex), nil if none has.

func (*DbUtils) GlobalDenied added in v0.34.9

func (s *DbUtils) GlobalDenied(addr net.Addr, what string) bool

GlobalDenied reports whether the global access lists, the firewall in front of every listener of nps, deny addr, and logs a denial. what names the listener in the log.

func (*DbUtils) GlobalDeniedString added in v0.34.9

func (s *DbUtils) GlobalDeniedString(addr, what string) bool

GlobalDeniedString is GlobalDenied for an address given as text.

func (*DbUtils) HostChanged added in v0.35.0

func (s *DbUtils) HostChanged(h *model.Host)

HostChanged reports that the entry h was changed in place.

func (*DbUtils) IsHostExist

func (s *DbUtils) IsHostExist(h *model.Host) bool

func (*DbUtils) IsHostModify

func (s *DbUtils) IsHostModify(h *model.Host) bool

func (*DbUtils) IsPubClient

func (s *DbUtils) IsPubClient(id int) bool

func (*DbUtils) NewClient

func (s *DbUtils) NewClient(c *model.Client) error

func (*DbUtils) NewHost

func (s *DbUtils) NewHost(t *model.Host) error

func (*DbUtils) NewTask

func (s *DbUtils) NewTask(t *model.Tunnel) error

NewTask adds t. A password explicitly set on a task created through the web or API that is already used by another task is rejected; for tasks delivered by a client configuration (NoStore) it is replaced by a random one, see taskPasswords.reserve.

func (*DbUtils) NextHostID added in v0.35.0

func (s *DbUtils) NextHostID() int

NextHostID reserves the id of a new host.

func (*DbUtils) NextTunnelID added in v0.35.0

func (s *DbUtils) NextTunnelID() int

NextTunnelID reserves the id of a new tunnel.

func (*DbUtils) OnClientChanged added in v0.35.0

func (s *DbUtils) OnClientChanged(f func(c *model.Client, deleted bool))

OnClientChanged makes f called after a client was created, changed or deleted (deleted true). It runs on the changing goroutine and returns promptly.

func (*DbUtils) OnEntriesChanged added in v0.35.0

func (s *DbUtils) OnEntriesChanged(f func())

OnEntriesChanged makes f called after tunnels or hosts of s were stored or changed in place, without any lock held; f must return promptly. The server that owns s sets it before it starts.

func (*DbUtils) RangeClientCertHosts added in v0.34.8

func (s *DbUtils) RangeClientCertHosts(clientID int, fn func(*model.Host) bool)

RangeClientCertHosts calls fn, until it returns false, for each host entry of the client clientID with a certificate configured.

func (*DbUtils) RangeClientHosts added in v0.35.6

func (s *DbUtils) RangeClientHosts(id int, fn func(*model.Host) bool)

RangeClientHosts calls fn, until it returns false, for each stored host that client id owns, in id order.

func (*DbUtils) RangeClientTunnels added in v0.35.6

func (s *DbUtils) RangeClientTunnels(id int, fn func(*model.Tunnel) bool)

RangeClientTunnels calls fn, until it returns false, for each stored tunnel that client id owns, in id order.

func (*DbUtils) RangeHosts added in v0.35.0

func (s *DbUtils) RangeHosts(fn func(*model.Host) bool)

RangeHosts calls fn for every stored host until fn returns false.

func (*DbUtils) RangeTunnels added in v0.35.0

func (s *DbUtils) RangeTunnels(fn func(*model.Tunnel) bool)

RangeTunnels calls fn for every stored tunnel until fn returns false.

func (*DbUtils) ReplaceClientVKey added in v0.35.0

func (s *DbUtils) ReplaceClientVKey(oldKey, newKey string, id int)

ReplaceClientVKey moves the authentication index entry of client id from the verify key oldKey to newKey.

func (*DbUtils) ReserveTaskPassword added in v0.34.8

func (s *DbUtils) ReserveTaskPassword(t *model.Tunnel) error

ReserveTaskPassword claims t.Password for t.Id under the same rules as NewTask and UpdateTask. It is used before an existing task is updated in place from t.

func (*DbUtils) SaveGlobal

func (s *DbUtils) SaveGlobal(t *model.Glob) error

func (*DbUtils) SaveHost added in v0.35.0

func (s *DbUtils) SaveHost(h *model.Host, oldHost string) error

SaveHost stores the entry h, edited in place, which was named oldHost before.

func (*DbUtils) SetEventBus added in v0.35.0

func (s *DbUtils) SetEventBus(bus *event.Bus)

SetEventBus makes s publish to bus; nil stops it, and then changes cost nothing.

func (*DbUtils) TunnelChanged added in v0.35.0

func (s *DbUtils) TunnelChanged(t *model.Tunnel)

TunnelChanged reports that the entry t was changed in place.

func (*DbUtils) UpdateClient

func (s *DbUtils) UpdateClient(t *model.Client) error

func (*DbUtils) UpdateTask

func (s *DbUtils) UpdateTask(t *model.Tunnel) error

UpdateTask stores t in place of the task with the same id. t may be the stored object itself or an edited copy; the password the task held before is tracked separately and released when it changes. A rejected password leaves the stored task and the password index unchanged.

func (*DbUtils) VerifyUserName

func (s *DbUtils) VerifyUserName(username string, id int) (res bool)

func (*DbUtils) VerifyVkey

func (s *DbUtils) VerifyVkey(vkey string, id int) (res bool)

type JsonDb

type JsonDb struct {
	Global *model.Glob

	Tasks    sync.Map
	Hosts    sync.Map
	HostsTmp sync.Map
	Clients  sync.Map

	HostFilePath   string //host file path
	TaskFilePath   string //task file path
	RunPath        string
	GlobalFilePath string //global file path
	ClientFilePath string //client file path

	HostIncreaseId   int32 //host increased id
	TaskIncreaseId   int32 //task increased id
	ClientIncreaseId int32 //client increased id
	// contains filtered or unexported fields
}

func NewJsonDb

func NewJsonDb(runPath string) *JsonDb

func (*JsonDb) GetClient

func (s *JsonDb) GetClient(id int) (c *model.Client, err error)

func (*JsonDb) GetClientId

func (s *JsonDb) GetClientId() int32

func (*JsonDb) GetHostId

func (s *JsonDb) GetHostId() int32

func (*JsonDb) GetTaskId

func (s *JsonDb) GetTaskId() int32

func (*JsonDb) LoadClientFromJsonFile

func (s *JsonDb) LoadClientFromJsonFile() error

func (*JsonDb) LoadGlobalFromJsonFile

func (s *JsonDb) LoadGlobalFromJsonFile() error

func (*JsonDb) LoadHostFromJsonFile

func (s *JsonDb) LoadHostFromJsonFile() error

func (*JsonDb) LoadTaskFromJsonFile

func (s *JsonDb) LoadTaskFromJsonFile() error

func (*JsonDb) StoreClientsToJsonFile

func (s *JsonDb) StoreClientsToJsonFile() error

func (*JsonDb) StoreGlobalToJsonFile

func (s *JsonDb) StoreGlobalToJsonFile() error

func (*JsonDb) StoreHostToJsonFile

func (s *JsonDb) StoreHostToJsonFile() error

func (*JsonDb) StoreTasksToJsonFile

func (s *JsonDb) StoreTasksToJsonFile() error

Jump to

Keyboard shortcuts

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