file

package
v0.35.7 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: GPL-3.0 Imports: 34 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 OrderTable added in v0.35.7

func OrderTable(g []*model.RouteCandidate)

OrderTable sorts an effective table in the order the web shows: exact paths, ^~ prefixes, regexps in the order tried, prefixes from the longest; entries that do not compile last. It is a linear view of the selection, not the selection itself: the hit tester is the authority.

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) ExcludeFromSubtree added in v0.35.7

func (s *DbUtils) ExcludeFromSubtree(id int, host string, exclude bool) error

ExcludeFromSubtree adds the host name or pattern host to the SubtreeExclude of the subtree entry id, or removes it if exclude is false.

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

IsHostExist reports whether another entry has the route key of h: the same host name (case and a trailing dot ignored), an overlapping scheme and the same Location (see model.RouteKey). It is the one duplicate check.

func (*DbUtils) IsHostModify

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

func (*DbUtils) IsPubClient

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

func (*DbUtils) MatchHost added in v0.35.7

func (s *DbUtils) MatchHost(host, scheme, p string, explain bool) model.HostSelection

MatchHost runs model.SelectHost for host, scheme ("" for any) and the decoded path p.

func (*DbUtils) MatchRequest added in v0.35.7

func (s *DbUtils) MatchRequest(host string, r *http.Request) (model.HostMatch, error)

MatchRequest finds the entry that serves r for the host name host. Routes match the decoded, normalized path of r (see model.NormalizeRequestPath).

func (*DbUtils) MoveRegex added in v0.35.7

func (s *DbUtils) MoveRegex(id int, up bool) error

MoveRegex moves the regexp entry id one place earlier (up) or later among the regexps of its own site, rewriting their priorities to 10, 20, ... from the last; only changed entries are written.

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) PreviewHost added in v0.35.7

func (s *DbUtils) PreviewHost(draft *model.Host, samples []string) HostPreview

PreviewHost previews the normalized entry draft (see model.NormalizeHostRoute) for the request paths samples, model.SamplePaths of the draft if none, on the https side unless the draft is http only. A draft without an id takes the next one.

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) RouteViews added in v0.35.7

func (s *DbUtils) RouteViews(hosts []*model.Host) map[int]RouteView

RouteViews returns the RouteView of each entry of hosts, by id.

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) SiteTable added in v0.35.7

func (s *DbUtils) SiteTable(name string) (model.HostSelection, map[int][]model.RouteWarning)

SiteTable returns the ordered effective table of the site or host name name for any scheme, with the warnings of its entries.

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 HostPreview added in v0.35.7

type HostPreview struct {
	// Draft is the draft in Site.Table, nil if an entry of the same key
	// leaves it out.
	Draft *model.RouteCandidate
	// Moves holds, by the id of a regexp of the same site that a warning
	// names, how many places up MoveRegex must move the draft to pass it.
	Moves    map[int]int
	Samples  []PreviewSample
	Warnings []model.RouteWarning
	Site     model.HostSelection
	Inheritance
	// Place is the 1-based place of the draft in Site.Table, as OrderTable
	// sorts it; 0 if it is not there.
	Place int
	// Duplicate reports that another entry has the draft's route key (see
	// IsHostExist): saving it fails.
	Duplicate bool
}

HostPreview is how a draft entry would fare among the stored ones, for the forms. It runs the selection the proxy runs, on the stored entries with the draft in place of the stored entry of its id.

type Inheritance added in v0.35.7

type Inheritance struct {
	Hosts      []string `json:"inherited_hosts,omitempty"`
	Overridden []string `json:"overriding_hosts,omitempty"`
	Excluded   []string `json:"excluded_hosts,omitempty"`
}

Inheritance is where a subtree entry goes among the stored sites below its own: the sites whose effective table holds it, those where an entry of the same key replaces it, and those its SubtreeExclude leaves out.

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

type PreviewSample added in v0.35.7

type PreviewSample struct {
	Path string
	Sel  model.HostSelection
	// Matches reports whether the draft's Location matches Path at all.
	Matches bool
}

PreviewSample is how the request path Path of a preview is served.

type RouteView added in v0.35.7

type RouteView struct {
	Kind     string               `json:"location_kind"`
	Warnings []model.RouteWarning `json:"route_warnings,omitempty"`
	Inheritance
	// Rank is the place in the order shown (see OrderTable).
	Rank int `json:"effective_rank"`
	// RegexRank is the place among the regexps, 0 for other kinds.
	RegexRank int `json:"regex_rank,omitempty"`
	// InheritedBy counts the more specific stored sites whose effective
	// table holds this subtree entry: len(Inheritance.Hosts).
	InheritedBy int `json:"inherited_by,omitempty"`
}

RouteView is the effective order of an entry in the effective table of its own site, for the web.

Jump to

Keyboard shortcuts

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