Documentation
¶
Index ¶
- func GetMapKeys(m *sync.Map, isSort bool, sortKey, order string) (keys []int)
- func OrderTable(g []*model.RouteCandidate)
- func RefreshAccessLists()
- func ReportGeoData()
- func WatchAccessLists(ctx context.Context, interval time.Duration)
- type DbUtils
- func (s *DbUtils) ClientChanged(c *model.Client)
- func (s *DbUtils) ClientEntryCount(c *model.Client) (num int)
- func (s *DbUtils) ClientHost(c *model.Client, h *model.Host) (hh *model.Host, exist bool)
- func (s *DbUtils) ClientPresence(id int, c *model.Client, online bool)
- func (s *DbUtils) ClientTunnel(c *model.Client, t *model.Tunnel) (tt *model.Tunnel, exist bool)
- func (s *DbUtils) DelClient(id int) error
- func (s *DbUtils) DelHost(id int) error
- func (s *DbUtils) DelTask(id int) error
- func (s *DbUtils) ExcludeFromSubtree(id int, host string, exclude bool) error
- func (s *DbUtils) FindCertByHost(host string) (*model.Host, error)
- func (s *DbUtils) FindReusableCert(host string, excludeID, clientID int) (*model.Host, error)
- func (s *DbUtils) GetClient(id int) (c *model.Client, err error)
- func (s *DbUtils) GetClientIdByBlake2bVkey(vkey string) (id int, err error)
- func (s *DbUtils) GetClientIdByMd5Vkey(vkey string) (id int, err error)
- func (s *DbUtils) GetClientList(start, length int, search, sort, order string, clientId int) ([]*model.Client, int)
- func (s *DbUtils) GetGlobal() (c *model.Glob)
- func (s *DbUtils) GetHost(start, length int, id int, search string) ([]*model.Host, int)
- func (s *DbUtils) GetHostById(id int) (h *model.Host, err error)
- func (s *DbUtils) GetIdByVerifyKey(vKey, addr, localAddr string, hashFunc func(string) string) (id int, err error)
- func (s *DbUtils) GetTask(id int) (t *model.Tunnel, err error)
- func (s *DbUtils) GetTaskByAccessID(id []byte) *model.Tunnel
- func (s *DbUtils) GetTaskByLegacySecret(sum []byte) (t *model.Tunnel)
- func (s *DbUtils) GetTaskBySecretIndex(p string) (t *model.Tunnel)
- func (s *DbUtils) GlobalDenied(addr net.Addr, what string) bool
- func (s *DbUtils) GlobalDeniedString(addr, what string) bool
- func (s *DbUtils) HostChanged(h *model.Host)
- func (s *DbUtils) IsHostExist(h *model.Host) bool
- func (s *DbUtils) IsHostModify(h *model.Host) bool
- func (s *DbUtils) IsPubClient(id int) bool
- func (s *DbUtils) MatchHost(host, scheme, p string, explain bool) model.HostSelection
- func (s *DbUtils) MatchRequest(host string, r *http.Request) (model.HostMatch, error)
- func (s *DbUtils) MoveRegex(id int, up bool) error
- func (s *DbUtils) NewClient(c *model.Client) error
- func (s *DbUtils) NewHost(t *model.Host) error
- func (s *DbUtils) NewTask(t *model.Tunnel) error
- func (s *DbUtils) NextHostID() int
- func (s *DbUtils) NextTunnelID() int
- func (s *DbUtils) OnClientChanged(f func(c *model.Client, deleted bool))
- func (s *DbUtils) OnEntriesChanged(f func())
- func (s *DbUtils) PreviewHost(draft *model.Host, samples []string) HostPreview
- func (s *DbUtils) RangeClientCertHosts(clientID int, fn func(*model.Host) bool)
- func (s *DbUtils) RangeClientHosts(id int, fn func(*model.Host) bool)
- func (s *DbUtils) RangeClientTunnels(id int, fn func(*model.Tunnel) bool)
- func (s *DbUtils) RangeHosts(fn func(*model.Host) bool)
- func (s *DbUtils) RangeTunnels(fn func(*model.Tunnel) bool)
- func (s *DbUtils) ReplaceClientVKey(oldKey, newKey string, id int)
- func (s *DbUtils) ReserveTaskPassword(t *model.Tunnel) error
- func (s *DbUtils) RouteViews(hosts []*model.Host) map[int]RouteView
- func (s *DbUtils) SaveGlobal(t *model.Glob) error
- func (s *DbUtils) SaveHost(h *model.Host, oldHost string) error
- func (s *DbUtils) SetEventBus(bus *event.Bus)
- func (s *DbUtils) SiteTable(name string) (model.HostSelection, map[int][]model.RouteWarning)
- func (s *DbUtils) TunnelChanged(t *model.Tunnel)
- func (s *DbUtils) UpdateClient(t *model.Client) error
- func (s *DbUtils) UpdateTask(t *model.Tunnel) error
- func (s *DbUtils) VerifyUserName(username string, id int) (res bool)
- func (s *DbUtils) VerifyVkey(vkey string, id int) (res bool)
- type HostPreview
- type Inheritance
- type JsonDb
- func (s *JsonDb) GetClient(id int) (c *model.Client, err error)
- func (s *JsonDb) GetClientId() int32
- func (s *JsonDb) GetHostId() int32
- func (s *JsonDb) GetTaskId() int32
- func (s *JsonDb) LoadClientFromJsonFile() error
- func (s *JsonDb) LoadGlobalFromJsonFile() error
- func (s *JsonDb) LoadHostFromJsonFile() error
- func (s *JsonDb) LoadTaskFromJsonFile() error
- func (s *JsonDb) StoreClientsToJsonFile() error
- func (s *JsonDb) StoreGlobalToJsonFile() error
- func (s *JsonDb) StoreHostToJsonFile() error
- func (s *JsonDb) StoreTasksToJsonFile() error
- type PreviewSample
- type RouteView
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
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 Open ¶ added in v0.35.0
Open returns the store kept in the conf directory of runPath, loaded from its files.
func (*DbUtils) ClientChanged ¶ added in v0.35.0
ClientChanged reports that the client c was changed in place.
func (*DbUtils) ClientEntryCount ¶ added in v0.35.0
ClientEntryCount returns how many tunnels and hosts c has.
func (*DbUtils) ClientHost ¶ added in v0.35.0
ClientHost returns the stored host of c with the host and location of h.
func (*DbUtils) ClientPresence ¶ added in v0.35.0
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
ClientTunnel returns the stored tunnel of c on the port or with the password of t.
func (*DbUtils) ExcludeFromSubtree ¶ added in v0.35.7
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 ¶
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
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) GetClientIdByBlake2bVkey ¶ added in v0.29.9
func (*DbUtils) GetClientIdByMd5Vkey ¶ added in v0.27.0
func (*DbUtils) GetClientList ¶
func (*DbUtils) GetIdByVerifyKey ¶
func (*DbUtils) GetTaskByAccessID ¶ added in v0.35.0
GetTaskByAccessID returns the task whose password has the access id (coreapi.AccessID), nil if none has.
func (*DbUtils) GetTaskByLegacySecret ¶ added in v0.35.3
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
GetTaskBySecretIndex returns the task whose password has index p (crypt.SecretIndex), nil if none has.
func (*DbUtils) GlobalDenied ¶ added in v0.34.9
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
GlobalDeniedString is GlobalDenied for an address given as text.
func (*DbUtils) HostChanged ¶ added in v0.35.0
HostChanged reports that the entry h was changed in place.
func (*DbUtils) IsHostExist ¶
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) IsPubClient ¶
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
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
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) NewTask ¶
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
NextHostID reserves the id of a new host.
func (*DbUtils) NextTunnelID ¶ added in v0.35.0
NextTunnelID reserves the id of a new tunnel.
func (*DbUtils) OnClientChanged ¶ added in v0.35.0
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
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
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
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
RangeHosts calls fn for every stored host until fn returns false.
func (*DbUtils) RangeTunnels ¶ added in v0.35.0
RangeTunnels calls fn for every stored tunnel until fn returns false.
func (*DbUtils) ReplaceClientVKey ¶ added in v0.35.0
ReplaceClientVKey moves the authentication index entry of client id from the verify key oldKey to newKey.
func (*DbUtils) ReserveTaskPassword ¶ added in v0.34.8
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
RouteViews returns the RouteView of each entry of hosts, by id.
func (*DbUtils) SaveHost ¶ added in v0.35.0
SaveHost stores the entry h, edited in place, which was named oldHost before.
func (*DbUtils) SetEventBus ¶ added in v0.35.0
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
TunnelChanged reports that the entry t was changed in place.
func (*DbUtils) UpdateTask ¶
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 ¶
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 (*JsonDb) GetClientId ¶
func (*JsonDb) LoadClientFromJsonFile ¶
func (*JsonDb) LoadGlobalFromJsonFile ¶
func (*JsonDb) LoadHostFromJsonFile ¶
func (*JsonDb) LoadTaskFromJsonFile ¶
func (*JsonDb) StoreClientsToJsonFile ¶
func (*JsonDb) StoreGlobalToJsonFile ¶
func (*JsonDb) StoreHostToJsonFile ¶
func (*JsonDb) StoreTasksToJsonFile ¶
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.