proxypool

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package proxypool adapts the proxypool library to router policy and storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoProxies        = errors.New("proxy pool has no usable proxy")
	ErrInvalidBanReason = errors.New("invalid proxy ban reason")
)

Functions

func EnsureBuiltinFreePool added in v0.4.0

func EnsureBuiltinFreePool(ctx context.Context, database *db.Database) error

EnsureBuiltinFreePool inserts the built-in free-pool row when missing. Existing rows stay untouched: reruns never rewrite timestamps. Call it wherever provider rows with proxy references write without the proxypool service in the stack; server wiring seeds it through New.

func TransportFor

func TransportFor(proxyURL string, timeout time.Duration) (*http.Transport, error)

TransportFor builds an HTTP transport for a library-supported proxy URL (http/https/socks4/socks5, with optional userinfo credentials). Dialing lives in the proxypool library; this wrapper keeps the router-internal call boundary stable.

Types

type Candidate added in v0.3.8

type Candidate struct {
	URL     string
	Country string
}

Candidate is one proxy endpoint produced by a Lua proxy-source feed.

type DemandStat added in v0.3.8

type DemandStat struct {
	Countries       []string  `json:"countries"`
	State           string    `json:"state"`
	Waiters         int       `json:"waiters"`
	Alive           int       `json:"alive"`
	Target          int       `json:"target"`
	Served          int64     `json:"served"`
	CreatedAt       time.Time `json:"created_at,omitempty"`
	ExpiresAt       time.Time `json:"expires_at,omitempty"`
	ReplenishUntil  time.Time `json:"replenish_until,omitempty"`
	LastSatisfiedAt time.Time `json:"last_satisfied_at,omitempty"`
}

DemandStat reports one registered country demand.

type LaneStat added in v0.3.8

type LaneStat struct {
	Lane     string `json:"lane"`
	Inflight int    `json:"inflight"`
	Queued   int    `json:"queued"`
}

type NetStatus added in v0.3.8

type NetStatus struct {
	State     string    `json:"state"`
	RTTMs     int64     `json:"rtt_ms"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

type Proxy added in v0.3.7

type Proxy struct {
	ID          string        `json:"id"`
	URL         string        `json:"url"`
	Location    string        `json:"location"`
	Latency     time.Duration `json:"latency"`
	Score       float64       `json:"score"`
	LastChecked time.Time     `json:"last_checked"`
}

Proxy is the stable router-facing view of a validated library entry.

type Service

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

Service owns the adapter boundary, persistence and pool lifecycle. Proxy health and lifecycle remain in the proxypool library. Provider request routing never consults this service: plugins select proxies through Query and assign proxy_url per request.

func New

func New(database *db.Database) (*Service, error)

New constructs the library-backed pool and restores its persistent cache from SQLite. The built-in free-pool row seeds idempotently into the durable database so provider proxy references to "auto" satisfy the foreign key; proxy states load from the cache file.

func (*Service) DeleteCustomPool added in v0.3.8

func (s *Service) DeleteCustomPool(ctx context.Context, identifier string) error

DeleteCustomPool removes a custom pool by ID. Entries cascade from the pool foreign key. Built-in rows refuse: the free pool is not custom. A zero-row delete reports the not-found sentinel.

func (*Service) Get

func (s *Service) Get(id string) (*Proxy, error)

Get returns a cached proxy by its stable router ID, including dead entries.

func (*Service) KnownIDs added in v0.3.7

func (s *Service) KnownIDs() ([]string, error)

KnownIDs returns IDs for all cached proxies, including dead entries.

func (*Service) List

func (s *Service) List() ([]*Proxy, error)

List returns verified live proxies in library rank order.

func (*Service) ListCustomPools added in v0.3.8

func (s *Service) ListCustomPools(ctx context.Context) ([]*models.CustomProxyPool, error)

ListCustomPools returns every manually managed proxy pool by name order. Built-in rows (the free pool) stay out: they are not custom pools.

func (*Service) MarkDead added in v0.3.8

func (s *Service) MarkDead(proxyURL, reason string) bool

MarkDead applies the router failure mapping before updating proxy health.

func (*Service) Query added in v0.3.8

func (s *Service) Query(pool, country string, limit int) ([]models.ProxyView, error)

Query returns proxy endpoints for plugin selection. Pool "auto" reads the library free pool in rank order; empty pool means direct and returns no endpoints; any other name reads a custom pool by ID or name. Country filters case-insensitively; limit caps the result (<=0 means all).

func (*Service) RecheckBanned added in v0.3.8

func (s *Service) RecheckBanned(reason, source string) (int, error)

RecheckBanned queues manual rechecks for banned proxies matching the filters.

func (*Service) RequestIngest added in v0.3.8

func (s *Service) RequestIngest() bool

RequestIngest requests an immediate source ingest when the service is running.

func (*Service) Require added in v0.3.8

Require serves proxies.require. The free pool waits for a matching live proxy up to request.Timeout; an empty pool means direct; a custom pool answers from its own entries without waiting.

func (*Service) SaveCustomPool added in v0.3.8

func (s *Service) SaveCustomPool(ctx context.Context, pool *models.CustomProxyPool) (*models.CustomProxyPool, error)

SaveCustomPool creates or replaces a custom pool. IDs are slugified from the name when empty; entries with empty URLs are dropped. One transaction holds the pool upsert, the entry wipe, and the entry inserts on the transaction handle only.

func (*Service) SetLogger added in v0.3.7

func (s *Service) SetLogger(logger *slog.Logger)

SetLogger installs structured service logging.

func (*Service) SetSourceHandlers added in v0.3.7

func (s *Service) SetSourceHandlers(keys func() ([]string, error), fetch func(context.Context, string) ([]Candidate, error))

SetSourceHandlers connects registered Lua proxy-source feeds.

func (*Service) SourceInfos added in v0.0.5

func (s *Service) SourceInfos() []SourceInfo

SourceInfos returns last-fetch diagnostics for currently registered feeds.

func (*Service) Start added in v0.3.7

func (s *Service) Start(ctx context.Context)

Start begins the pool scheduler and the persistence flush loop. The method is non-blocking and idempotent.

func (*Service) Status added in v0.3.7

func (s *Service) Status() (Status, error)

Status returns the structured dashboard snapshot from the library pool. Persistence errors remain visible in LastError so the dashboard can still render the live scheduler/network state.

type SourceInfo added in v0.0.5

type SourceInfo struct {
	Key         string    `json:"key"`
	Name        string    `json:"name"`
	LastFetchAt time.Time `json:"last_fetch_at,omitempty"`
	Total       int       `json:"total"`
	Unsupported int       `json:"unsupported"`
	LastError   string    `json:"last_error,omitempty"`
}

SourceInfo reports feed diagnostics for registered Lua proxy sources.

type SourceStat added in v0.3.8

type SourceStat struct {
	Source     string         `json:"source"`
	Alive      int            `json:"alive"`
	Suspect    int            `json:"suspect"`
	Banned     int            `json:"banned"`
	Queued     int            `json:"queued"`
	BanReasons map[string]int `json:"ban_reasons"`
}

type Status added in v0.3.7

type Status struct {
	Mode         string         `json:"mode"`
	Net          NetStatus      `json:"net"`
	Limit        int            `json:"limit"`
	Inflight     int            `json:"inflight"`
	Total        int            `json:"total"`
	Alive        int            `json:"alive"`
	Suspect      int            `json:"suspect"`
	Banned       int            `json:"banned"`
	Queued       int            `json:"queued"`
	Lanes        []LaneStat     `json:"lanes"`
	Sources      []SourceStat   `json:"sources"`
	BanReasons   map[string]int `json:"ban_reasons"`
	Demands      []DemandStat   `json:"demands"`
	LastIngestAt time.Time      `json:"last_ingest_at,omitempty"`
	LastError    string         `json:"last_error,omitempty"`
}

Jump to

Keyboard shortcuts

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