proxies

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package proxies holds the rules for proxied copies that need no Docker and no database: what a proxy definition may contain, what the UI may see of it (never a secret), which services may run through a proxy, the traffic cap, and the exit-IP checks. It mirrors the web app's app/proxies.py (GeiserX/CashPilot docs/proxies.md); internal/runtime/proxied.go does the Docker side.

Index

Constants

View Source
const BaselineKeep = 31 * 24 * time.Hour

BaselineKeep is how long a tunnel's counter baseline is kept after its last reading, so the traffic of a tunnel that kept running while the app was closed is counted once, not again from zero.

View Source
const DefaultThresholdPct = 90

DefaultThresholdPct is where a cap stops the copies by default. Usage is read once a minute, so the copies can run up to a minute past it.

View Source
const GB = 1_000_000_000

GB is the decimal gigabyte providers sell.

View Source
const MinCapGB = 0.001

MinCapGB is the smallest cap accepted: 1 MB.

Variables

View Source
var ForbiddenCaps = map[string]bool{"NET_ADMIN": true, "NET_RAW": true, "SYS_ADMIN": true, "ALL": true}

ForbiddenCaps are the capabilities a proxied earner may never hold. It shares its tunnel's network namespace, so NET_ADMIN could flush the tunnel's firewall or put back a default route, NET_RAW could send frames out of the real interface past the output hook, and SYS_ADMIN covers both.

View Source
var Kinds = []string{"socks5", "http", "tailscale"}

Kinds are the proxy types a tunnel can carry.

View Source
var SecretFields = []string{"username", "password", "auth_key"}

SecretFields are the fields that are never shown back.

Functions

func CapBytes

func CapBytes(d Definition) (uint64, bool)

CapBytes is the cap in bytes; false when the proxy has none.

func CapReason

func CapReason(d Definition, when time.Time) string

CapReason says why the copies were stopped.

func IsInputError

func IsInputError(err error) bool

IsInputError reports whether err is a definition the owner has to fix.

func PublicIP

func PublicIP(ip string) string

PublicIP returns ip normalised when it is a public unicast address, else "". A private, loopback, link-local, CGNAT or unparseable address is never an exit a provider sees, so it is never grouped with anything.

func Refusal

func Refusal(svc catalog.Service) string

Refusal says why svc cannot run through a proxy, or "".

A proxied copy lives inside its tunnel's network namespace. Host networking, published ports and devices need the host's own network or hardware, and a volume would be shared with the copy on this machine.

func ResetDue

func ResetDue(d Definition, s State, today time.Time) bool

ResetDue is true when the period that began on the last reset day has not been started yet.

func RiskyCaps

func RiskyCaps(caps []string) []string

RiskyCaps are the forbidden capabilities among caps, upper-cased, sorted.

func SameExit

func SameExit(slug string, exitIP string, ownIP string, ownRuns bool, others []Exit, self int64) []string

SameExit lists where slug already leaves from exitIP: this machine's own connection, or another proxied copy of it. Empty when the exit is unknown (unknown is not shared) or rotating.

func ThresholdBytes

func ThresholdBytes(d Definition) (uint64, bool)

ThresholdBytes is where the copies are stopped; false when the proxy has no cap.

Types

type CapView

type CapView struct {
	Enabled      bool   `json:"enabled"`
	CapBytes     uint64 `json:"capBytes"`
	ThresholdPct int    `json:"thresholdPct"`
	ResetDay     int    `json:"resetDay"`
	UsedBytes    uint64 `json:"usedBytes"`
	PeriodStart  string `json:"periodStart"`
	CappedAt     string `json:"cappedAt"`
	CapReason    string `json:"capReason"`
}

CapView is the traffic cap as the UI shows it.

type CopyView

type CopyView struct {
	Slug         string `json:"slug"`
	Name         string `json:"name"`
	Status       string `json:"status"`
	TunnelStatus string `json:"tunnelStatus"`
	ExitIP       string `json:"exitIp"`
	ExitCountry  string `json:"exitCountry"`
	StoppedByCap bool   `json:"stoppedByCap"`
}

CopyView is one proxied copy of a service as the UI shows it.

type Counter

type Counter struct {
	Rx        uint64 `json:"rx"`
	Tx        uint64 `json:"tx"`
	SeenAt    int64  `json:"seen_at"`
	StartedAt string `json:"started_at"`
}

Counter is the last reading of one tunnel's interface counters.

type Definition

type Definition struct {
	Name            string   `json:"name"`
	Kind            string   `json:"kind"`
	Host            string   `json:"host"`
	Port            int      `json:"port"`
	Username        string   `json:"username"`
	Password        string   `json:"password"`
	AuthKey         string   `json:"auth_key"`
	ExitNode        string   `json:"exit_node"`
	LoginServer     string   `json:"login_server"`
	Rotating        bool     `json:"rotating"`
	CapGB           *float64 `json:"cap_gb"`
	CapThresholdPct int      `json:"cap_threshold_pct"`
	ResetDay        *int     `json:"reset_day"`
}

Definition is a proxy as stored (encrypted) in the store.

func Clean

func Clean(values map[string]string, existing *Definition) (Definition, error)

Clean validates what the form sent and returns the definition to store.

On an edit (existing non-nil) a secret left blank keeps the stored value, because the form never shows secrets back; "clear_<field>" set to "true" removes it. Any other field left out keeps its stored value too.

func (Definition) SecretValues

func (d Definition) SecretValues() []string

SecretValues are the secret values of a definition, for redacting messages.

type Exit

type Exit struct {
	Slug     string
	ProxyID  int64
	ExitIP   string
	Rotating bool
}

Exit is one running proxied copy and where it leaves from.

type InputError

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

InputError is a definition the owner has to fix; the message names the field.

func (*InputError) Error

func (e *InputError) Error() string

type State

type State struct {
	UsedBytes     uint64             `json:"used_bytes"`
	PeriodStart   string             `json:"period_start,omitempty"`
	CappedAt      string             `json:"capped_at,omitempty"`
	CapReason     string             `json:"cap_reason,omitempty"`
	LastExitIP    string             `json:"last_exit_ip,omitempty"`
	LastCountry   string             `json:"last_country,omitempty"`
	LastCheckedAt string             `json:"last_checked_at,omitempty"`
	LastTest      *TestResult        `json:"last_test,omitempty"`
	Counters      map[string]Counter `json:"counters,omitempty"`
}

State is what changes while a proxy is used. It holds no secret.

func Account

func Account(s State, d Definition, readings []Traffic, now time.Time) (State, bool)

Account folds one reading of a proxy's tunnels into its state. It returns the new state and whether this reading crossed the cap threshold. A missing counter is unknown, not zero.

func CapChange

func CapChange(old, updated Definition, s State, today time.Time) (State, bool)

CapChange brings the cap state in line with an edited definition. It returns the new state and whether the copies the cap stopped should start again. A cap turned on starts a fresh period, so traffic from before it existed never counts. A cap turned off, or moved above what this period has used, lifts the stop.

func ResetState

func ResetState(s State, today time.Time) State

ResetState starts a new period: nothing used, no cap hit. Counter baselines stay, so traffic from before the reset is not counted again.

type TestResult

type TestResult struct {
	OK    bool   `json:"ok"`
	At    string `json:"at"`
	Error string `json:"error"`
}

TestResult is the outcome of the last Test, kept so a failure outlives its toast.

type Traffic

type Traffic struct {
	TunnelID    string
	StartedAt   string
	Rx, Tx      *uint64
	ExitIP      string
	ExitCountry string
}

Traffic is one tunnel's counters, as the runtime read them.

type View

type View struct {
	ID            int64           `json:"id"`
	Name          string          `json:"name"`
	Kind          string          `json:"kind"`
	Host          string          `json:"host"`
	Port          int             `json:"port"`
	ExitNode      string          `json:"exitNode"`
	LoginServer   string          `json:"loginServer"`
	Rotating      bool            `json:"rotating"`
	Secrets       map[string]bool `json:"secrets"`
	Cap           CapView         `json:"cap"`
	LastExitIP    string          `json:"lastExitIp"`
	LastCountry   string          `json:"lastCountry"`
	LastCheckedAt string          `json:"lastCheckedAt"`
	LastTest      *TestResult     `json:"lastTest"`
	Copies        []CopyView      `json:"copies"`
}

View is what the UI receives for a proxy. Secrets appear only as "set".

func PublicView

func PublicView(id int64, d Definition, s State, copies []CopyView) View

PublicView is a proxy without its secrets.

Jump to

Keyboard shortcuts

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