prox5/proxy.go

70 lines
1.8 KiB
Go
Raw Normal View History

2022-06-26 02:51:42 +00:00
package prox5
import (
"time"
rl "github.com/yunginnanet/Rate5"
)
// https://pkg.go.dev/github.com/yunginnanet/Rate5#Policy
var defaultUseProxyRatelimiter = rl.Policy{
Window: 55,
Burst: 55,
2022-06-26 02:51:42 +00:00
}
var defaultBadProxyRateLimiter = rl.Policy{
Window: 55,
Burst: 10,
2022-06-26 02:51:42 +00:00
}
const (
stateUnlocked uint32 = iota
stateLocked
)
// Proxy represents an individual proxy
type Proxy struct {
// Endpoint is the address:port of the proxy that we connect to
Endpoint string
// ProxiedIP is the address that we end up having when making proxied requests through this proxy
2023-01-01 00:40:32 +00:00
// TODO: parse this and store as flat int type
2022-06-26 02:51:42 +00:00
ProxiedIP string
2022-09-22 23:24:35 +00:00
// protocol is the version/Protocol (currently SOCKS* only) of the proxy
protocol proto
2022-06-26 02:51:42 +00:00
// lastValidated is the time this proxy was last verified working
lastValidated time.Time
// timesValidated is the amount of times the proxy has been validated.
timesValidated int64
// timesBad is the amount of times the proxy has been marked as bad.
timesBad int64
2022-10-16 10:53:04 +00:00
parent *ProxyEngine
2022-06-28 02:27:52 +00:00
lock uint32
2022-06-26 02:51:42 +00:00
}
// UniqueKey is an implementation of the Identity interface from Rate5.
// See: https://pkg.go.dev/github.com/yunginnanet/Rate5#Identity
func (sock *Proxy) UniqueKey() string {
return sock.Endpoint
}
2022-09-22 23:24:35 +00:00
// GetProto retrieves the known protocol value of the Proxy.
func (sock *Proxy) GetProto() ProxyProtocol {
return sock.protocol.Get()
}
// GetProto safely retrieves the protocol value of the Proxy.
func (sock *Proxy) String() string {
buf := strs.Get()
defer strs.MustPut(buf)
buf.MustWriteString(sock.GetProto().String())
buf.MustWriteString("://")
buf.MustWriteString(sock.Endpoint)
2022-09-22 23:24:35 +00:00
if sock.parent.GetServerTimeoutStr() != "-1" {
buf.MustWriteString("?timeout=")
buf.MustWriteString(sock.parent.GetServerTimeoutStr())
buf.MustWriteString("s")
2022-09-22 23:24:35 +00:00
}
return buf.String()
2022-09-22 23:24:35 +00:00
}