proxypool

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 20 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")
)

Functions

func NormalizeCountryCode

func NormalizeCountryCode(raw string) string

NormalizeCountryCode canonicalizes a country code to uppercase ISO 3166-1 alpha-2. Alpha-3 input maps through the ISO table; anything else passes through uppercased so selection never mismatches on case alone.

func TransportFor

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

TransportFor builds an HTTP transport for a library-supported proxy URL.

Types

type MigrationReport added in v0.3.7

type MigrationReport struct {
	Imported           int
	Skipped            int
	Limits             int
	GeoBans            int
	ConfigFields       int
	SelectedIDsRemoved int
}

func MigrateLegacy added in v0.3.7

func MigrateLegacy(database *db.DB) (MigrationReport, error)

MigrateLegacy imports supported router proxy records into the library cache and rewrites durable references before dropping router-owned pool buckets.

type Pick added in v0.0.7

type Pick struct {
	ID       string
	URL      string
	Location string
}

Pick is one ordered proxy candidate for a provider request.

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, request policy and refresh schedule. Proxy health and lifecycle remain in the proxypool library.

func New

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

New constructs the library-backed pool and restores its persistent cache.

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) IsLimited added in v0.3.7

func (s *Service) IsLimited(id, key string, now time.Time) (bool, error)

IsLimited checks and lazily removes an expired proxy-scoped limit.

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) LimitedAny added in v0.3.7

func (s *Service) LimitedAny(id string, keys []string) (bool, error)

func (*Service) List

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

List returns verified live proxies in library rank order.

func (*Service) MarkLimit added in v0.3.7

func (s *Service) MarkLimit(id, key string, resetsAt time.Time, reason string) error

MarkLimit stores one proxy-scoped limit in the library-managed metadata.

func (*Service) Rank added in v0.0.7

func (s *Service) Rank(whitelist []string, mode string, ids []string, _ string) ([]Pick, error)

Rank returns library-ranked proxies allowed by the provider policy.

func (*Service) RankWait added in v0.1.0

func (s *Service) RankWait(ctx context.Context, whitelist []string, ids []string, provider string) ([]Pick, error)

RankWait waits for an in-progress library refresh when no proxy is ready.

func (*Service) RequestRefresh added in v0.3.7

func (s *Service) RequestRefresh() bool

RequestRefresh coalesces a background refresh request.

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) ([]models.ProxyCandidate, error))

SetSourceHandlers connects registered Lua proxy-source plugins.

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 initial refresh and adaptive refresh schedule.

func (*Service) Status added in v0.3.7

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

Status returns pool counts and scheduler state.

func (*Service) Touch added in v0.3.7

func (s *Service) Touch()

Touch records active pool use and wakes the scheduler after an idle period.

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 router-plugin feed diagnostics without claiming source ownership of proxies retained by the library cache.

type Status added in v0.3.7

type Status struct {
	Total           int           `json:"total"`
	Active          int           `json:"active"`
	Refreshing      bool          `json:"refreshing"`
	LastRefreshAt   time.Time     `json:"last_refresh_at,omitempty"`
	LastRefreshTime time.Duration `json:"last_refresh_duration"`
	NextRefreshAt   time.Time     `json:"next_refresh_at,omitempty"`
	RefreshInterval time.Duration `json:"refresh_interval"`
	LastError       string        `json:"last_error,omitempty"`
}

Status describes pool activity and the next scheduled refresh.

Jump to

Keyboard shortcuts

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