proxygate

package
v0.0.0-...-9944d71 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPoolRefreshInterval = 2 * time.Minute

DefaultPoolRefreshInterval is the default interval for refreshing pool from database

Variables

This section is empty.

Functions

func FetchProxyDB

func FetchProxyDB(ctx context.Context, minUptime float64, maxResponse float64) ([]string, error)

FetchProxyDB fetches and parses proxies from proxydb.net Returns only high-quality proxies (uptime > minUptime%, response < maxResponse seconds)

func IsProxyDBURL

func IsProxyDBURL(url string) bool

IsProxyDBURL checks if a URL is proxydb.net

Types

type Config

type Config struct {
	Enabled              bool
	ListenAddr           string   // e.g., "localhost:8081"
	SourceURLs           []string // Default GitHub raw URLs
	RefreshInterval      time.Duration
	ValidatorConcurrency int
}

func DefaultConfig

func DefaultConfig() *Config

type Fetcher

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

func NewFetcher

func NewFetcher(sources []string, pool *Pool) *Fetcher

func (*Fetcher) AddSource

func (f *Fetcher) AddSource(url string)

func (*Fetcher) ForceRefresh

func (f *Fetcher) ForceRefresh(ctx context.Context) error

func (*Fetcher) GetSources

func (f *Fetcher) GetSources() []string

func (*Fetcher) LastUpdated

func (f *Fetcher) LastUpdated() time.Time

func (*Fetcher) RemoveSource

func (f *Fetcher) RemoveSource(url string)

func (*Fetcher) Run

func (f *Fetcher) Run(ctx context.Context) error

type Pool

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

Pool manages a pool of proxies with optional database persistence

func NewPool

func NewPool() *Pool

NewPool creates a new proxy pool (in-memory only)

func NewPoolWithRepo

func NewPoolWithRepo(repo domain.ProxyListRepository) *Pool

NewPoolWithRepo creates a new proxy pool with database persistence

func (*Pool) AddRawProxies

func (p *Pool) AddRawProxies(ctx context.Context, proxies []*domain.Proxy) error

AddRawProxies adds multiple raw proxies to the database

func (*Pool) AddRawProxy

func (p *Pool) AddRawProxy(ctx context.Context, proxy *domain.Proxy) error

AddRawProxy adds a raw (unvalidated) proxy to the database with pending status

func (*Pool) AddValidated

func (p *Pool) AddValidated(proxyAddr string)

AddValidated adds a validated proxy to the pool

func (*Pool) AddValidatedProxy

func (p *Pool) AddValidatedProxy(proxy *domain.Proxy)

AddValidatedProxy adds a validated proxy object to the pool

func (*Pool) CleanupDead

func (p *Pool) CleanupDead(ctx context.Context) (int, error)

CleanupDead removes dead proxies from database

func (*Pool) GetNext

func (p *Pool) GetNext() (string, error)

GetNext returns the next proxy in round-robin fashion

func (*Pool) GetNextWithID

func (p *Pool) GetNextWithID() (*domain.Proxy, error)

GetNextWithID returns the next proxy with its database ID

func (*Pool) GetStats

func (p *Pool) GetStats(ctx context.Context) (*domain.ProxyStats, error)

GetStats returns proxy statistics

func (*Pool) HasRepo

func (p *Pool) HasRepo() bool

HasRepo returns true if a database repository is configured

func (*Pool) LoadFromDatabase

func (p *Pool) LoadFromDatabase(ctx context.Context) error

LoadFromDatabase loads healthy proxies from database into memory

func (*Pool) MarkFailed

func (p *Pool) MarkFailed(proxyAddr string)

MarkFailed marks a proxy as failed

func (*Pool) MarkSuccess

func (p *Pool) MarkSuccess(proxyAddr string)

MarkSuccess marks a proxy as successful

func (*Pool) Remove

func (p *Pool) Remove(proxyAddr string)

Remove removes a proxy from the pool

func (*Pool) RemoveByID

func (p *Pool) RemoveByID(id int64)

RemoveByID removes a proxy by database ID

func (*Pool) SetRepo

func (p *Pool) SetRepo(repo domain.ProxyListRepository)

SetRepo sets the database repository for persistence (can be called after construction)

func (*Pool) Size

func (p *Pool) Size() int

Size returns the number of proxies in the memory pool

type ProxyDBEntry

type ProxyDBEntry struct {
	IP       string
	Port     int
	Country  string
	Uptime   float64 // percentage
	Response float64 // seconds
}

ProxyDBEntry represents a parsed proxy from proxydb.net

type ProxyGate

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

func New

func New(cfg *Config) *ProxyGate

func (*ProxyGate) AddProxyToPool

func (pg *ProxyGate) AddProxyToPool(proxy *domain.Proxy)

AddProxyToPool adds a proxy directly to the in-memory pool Use this when adding proxies via API to immediately make them available

func (*ProxyGate) AddSource

func (pg *ProxyGate) AddSource(url string)

func (*ProxyGate) GetSources

func (pg *ProxyGate) GetSources() []string

func (*ProxyGate) GetStats

func (pg *ProxyGate) GetStats() (int, int, time.Time)

func (*ProxyGate) LoadFromDatabase

func (pg *ProxyGate) LoadFromDatabase(ctx context.Context) error

LoadFromDatabase loads healthy proxies from database into the in-memory pool This should be called after SetPoolRepo to initialize the pool with existing proxies

func (*ProxyGate) PoolSize

func (pg *ProxyGate) PoolSize() int

PoolSize returns the current number of proxies in memory

func (*ProxyGate) Refresh

func (pg *ProxyGate) Refresh(ctx context.Context) error

func (*ProxyGate) ReloadFromDatabase

func (pg *ProxyGate) ReloadFromDatabase(ctx context.Context) error

ReloadFromDatabase reloads all healthy proxies from database This can be called periodically or after bulk updates

func (*ProxyGate) RemoveSource

func (pg *ProxyGate) RemoveSource(url string)

func (*ProxyGate) Run

func (pg *ProxyGate) Run(ctx context.Context) error

func (*ProxyGate) SetPoolRepo

func (pg *ProxyGate) SetPoolRepo(repo domain.ProxyListRepository)

SetPoolRepo sets the database repository for proxy persistence This can be called after construction when database becomes available

type Server

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

func NewServer

func NewServer(addr string, pool *Pool) *Server

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

type Validator

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

func NewValidator

func NewValidator(concurrency int, pool *Pool) *Validator

func (*Validator) Run

func (v *Validator) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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