Documentation
¶
Overview ¶
Package proxybudget meters proxy socket bytes against a durable, bounded account. It is independent of provider selection, authentication, destination allowlists and the fleet token ledger; callers must enforce those separately. The accounting and reservations are extracted from go-search-duck-go's lane.
Adapted from go-search-duck-go/internal/lane/ledger.go; existing lane state remains owned by its service.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConfig = errors.New("proxybudget: invalid bounded configuration") ErrClosed = errors.New("proxybudget: closed") ErrDisabled = errors.New("proxybudget: disabled") ErrBusy = errors.New("proxybudget: in-flight limit reached") ErrBudget = errors.New("proxybudget: total budget exhausted") ErrDaily = errors.New("proxybudget: daily budget exhausted") ErrRequest = errors.New("proxybudget: request byte cap reached") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
StateDir string `json:"state_dir"`
TotalBudgetBytes int64 `json:"total_budget_bytes"`
DailyCapBytes int64 `json:"daily_cap_bytes"`
MaxRequestBytes int64 `json:"max_request_bytes"`
MaxInflight int `json:"max_inflight"`
InitialUsedBytes int64 `json:"initial_used_bytes,omitempty"`
FlushInterval time.Duration `json:"flush_interval,omitempty"`
}
Config requires positive total, daily, per-request and concurrency limits. StateDir must be a private, persistent absolute path unique to this account allocation. Never open another process's existing lane ledger here.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns a locked durable byte ledger and the live request tickets.
func Open ¶
Open validates limits and fails closed on a missing permission, corrupt ledger or an already-owned state directory. Existing usage is never reset.
func (*Manager) Admit ¶
Admit reserves the full per-request cap before any upstream socket exists. Cancellation closes the ticket's sockets and releases unused reservations.
type PoolConfig ¶
type PoolConfig struct {
ProviderID string `json:"provider_id"`
PoolID string `json:"pool_id"`
AllowedHosts []string `json:"allowed_hosts"`
Config
}
PoolConfig binds one provider/pool allocation to its byte budget and allowed destination hosts. It contains no proxy URL or credentials. Callers enforce AllowsHost on every target, including redirects and browser subresources, in addition to their normal SSRF checks.
func LoadPoolConfigs ¶
func LoadPoolConfigs(path string) ([]PoolConfig, error)
LoadPoolConfigs reads the strict {"pools":[...]} config without opening any ledgers. Duplicate pool identities or state directories, unknown fields, missing/invalid limits, empty host policies and oversized files fail closed.
func (PoolConfig) AllowsHost ¶
func (c PoolConfig) AllowsHost(host string) bool
AllowsHost performs an exact normalized host match, never wildcard expansion.
type Status ¶
type Status struct {
TotalUsedBytes int64 `json:"total_used_bytes"`
DailyUsedBytes int64 `json:"daily_used_bytes"`
ReservedBytes int64 `json:"reserved_bytes"`
TotalBudgetBytes int64 `json:"total_budget_bytes"`
DailyCapBytes int64 `json:"daily_cap_bytes"`
MaxRequestBytes int64 `json:"max_request_bytes"`
Inflight int `json:"inflight"`
Disabled bool `json:"disabled"`
Closed bool `json:"closed"`
}
Status contains only byte counts and limits, never upstream credentials.
type Ticket ¶
type Ticket struct {
// contains filtered or unexported fields
}
Ticket is a single admitted request across all its proxy connections. It is safe to wrap multiple browser subresource sockets in the same ticket.
func (*Ticket) Close ¶
Close is idempotent. No new I/O can start after the close barrier; outstanding reads/writes are unblocked by closing their sockets, then fully accounted.