Documentation
¶
Overview ¶
Package proxypool adapts the proxypool library to router policy and storage.
Index ¶
- Variables
- func NormalizeCountryCode(raw string) string
- func TransportFor(proxyURL string, timeout time.Duration) (*http.Transport, error)
- type MigrationReport
- type Pick
- type Proxy
- type Service
- func (s *Service) Get(id string) (*Proxy, error)
- func (s *Service) IsLimited(id, key string, now time.Time) (bool, error)
- func (s *Service) KnownIDs() ([]string, error)
- func (s *Service) LimitedAny(id string, keys []string) (bool, error)
- func (s *Service) List() ([]*Proxy, error)
- func (s *Service) MarkLimit(id, key string, resetsAt time.Time, reason string) error
- func (s *Service) Rank(whitelist []string, mode string, ids []string, _ string) ([]Pick, error)
- func (s *Service) RankWait(ctx context.Context, whitelist []string, ids []string, provider string) ([]Pick, error)
- func (s *Service) RequestRefresh() bool
- func (s *Service) SetLogger(logger *slog.Logger)
- func (s *Service) SetSourceHandlers(keys func() ([]string, error), ...)
- func (s *Service) SourceInfos() []SourceInfo
- func (s *Service) Start(ctx context.Context)
- func (s *Service) Status() (Status, error)
- func (s *Service) Touch()
- type SourceInfo
- type Status
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoProxies = errors.New("proxy pool has no usable proxy")
)
Functions ¶
func NormalizeCountryCode ¶
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.
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 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 (*Service) IsLimited ¶ added in v0.3.7
IsLimited checks and lazily removes an expired proxy-scoped limit.
func (*Service) KnownIDs ¶ added in v0.3.7
KnownIDs returns IDs for all cached proxies, including dead entries.
func (*Service) LimitedAny ¶ added in v0.3.7
func (*Service) MarkLimit ¶ added in v0.3.7
MarkLimit stores one proxy-scoped limit in the library-managed metadata.
func (*Service) Rank ¶ added in v0.0.7
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
RequestRefresh coalesces a background refresh request.
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
Start begins the initial refresh and adaptive refresh schedule.
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.