Documentation
¶
Index ¶
- Constants
- func AutoConfigureProxy(config *ProxyConfig)
- func IsProxyEnabled() bool
- func IsProxyProbed() bool
- func IsProxyReliable() bool
- func IsSOCKS5Proxy() bool
- func ProbeProxyBehavior(dialer Dialer, timeout time.Duration) bool
- func SetProxyEnabled(enabled bool)
- func SetProxyInitialized(initialized bool)
- func SetProxyProbed(probed bool)
- func SetProxyReliable(reliable bool)
- func SetSOCKS5Standard(standard bool)
- type Dialer
- type ProxyConfig
- type ProxyError
- type ProxyManager
- type ProxyStats
- type ProxyType
- type TLSDialer
Constants ¶
View Source
const ( // ProxyTypeStringNone 代理类型字符串 - 无代理 ProxyTypeStringNone = "none" // ProxyTypeStringHTTP HTTP代理 ProxyTypeStringHTTP = "http" // ProxyTypeStringHTTPS HTTPS代理 ProxyTypeStringHTTPS = "https" // ProxyTypeStringSOCKS5 SOCKS5代理 ProxyTypeStringSOCKS5 = "socks5" // ProxyTypeStringUnknown 未知代理类型 ProxyTypeStringUnknown = "unknown" )
View Source
const ( // DefaultProxyTimeout 默认代理配置值 - 默认超时时间 DefaultProxyTimeout = 30 * time.Second // DefaultProxyMaxRetries 默认最大重试次数 DefaultProxyMaxRetries = 3 // DefaultProxyKeepAlive 默认保持连接时间 DefaultProxyKeepAlive = 30 * time.Second // DefaultProxyIdleTimeout 默认空闲超时时间 DefaultProxyIdleTimeout = 90 * time.Second // DefaultProxyMaxIdleConns 默认最大空闲连接数 DefaultProxyMaxIdleConns = 10 )
View Source
const ( // ErrTypeConfig 预定义错误类型 - 配置错误 ErrTypeConfig = "config_error" // ErrTypeConnection 连接错误 ErrTypeConnection = "connection_error" // ErrTypeAuth 认证错误 ErrTypeAuth = "auth_error" // ErrTypeTimeout 超时错误 ErrTypeTimeout = "timeout_error" // ErrTypeProtocol 协议错误 ErrTypeProtocol = "protocol_error" )
View Source
const ( // ErrCodeUnsupportedProxyType Manager错误代码 - 不支持的代理类型 ErrCodeUnsupportedProxyType = 1001 // ErrCodeEmptyConfig 配置为空 ErrCodeEmptyConfig = 1002 // ErrCodeSOCKS5ParseFailed SOCKS5错误代码 - 地址解析失败 ErrCodeSOCKS5ParseFailed = 2001 // ErrCodeSOCKS5CreateFailed 拨号器创建失败 ErrCodeSOCKS5CreateFailed = 2002 // ErrCodeDirectConnFailed 直连错误代码 - 直连失败 ErrCodeDirectConnFailed = 3001 // ErrCodeSOCKS5ConnTimeout SOCKS5连接超时 ErrCodeSOCKS5ConnTimeout = 3002 // ErrCodeSOCKS5ConnFailed SOCKS5连接失败 ErrCodeSOCKS5ConnFailed = 3003 // ErrCodeHTTPConnFailed HTTP代理错误代码 - 连接失败 ErrCodeHTTPConnFailed = 4001 // ErrCodeHTTPSetWriteTimeout 设置写超时失败 ErrCodeHTTPSetWriteTimeout = 4002 // ErrCodeHTTPSendConnectFail 发送CONNECT请求失败 ErrCodeHTTPSendConnectFail = 4003 // ErrCodeHTTPSetReadTimeout 设置读超时失败 ErrCodeHTTPSetReadTimeout = 4004 // ErrCodeHTTPReadRespFailed 读取响应失败 ErrCodeHTTPReadRespFailed = 4005 // ErrCodeHTTPProxyAuthFailed 代理认证失败 ErrCodeHTTPProxyAuthFailed = 4006 // ErrCodeTLSTCPConnFailed TLS错误代码 - TCP连接失败 ErrCodeTLSTCPConnFailed = 5001 // ErrCodeTLSHandshakeFailed TLS握手失败 ErrCodeTLSHandshakeFailed = 5002 )
View Source
const ( // HTTPStatusOK HTTP响应状态码 - 成功状态码200 HTTPStatusOK = 200 // HTTPVersion HTTP协议常量 - HTTP版本 HTTPVersion = "HTTP/1.1" // HTTPMethodConnect CONNECT方法 HTTPMethodConnect = "CONNECT" // HTTPHeaderHost HTTP头部常量 - Host头 HTTPHeaderHost = "Host" // HTTPHeaderProxyAuth Proxy-Authorization头 HTTPHeaderProxyAuth = "Proxy-Authorization" // HTTPHeaderAuthBasic Basic认证方式 HTTPHeaderAuthBasic = "Basic" )
View Source
const ( // NetworkTCP 网络协议 - TCP协议 NetworkTCP = "tcp" // ProxyProtocolSOCKS5 代理协议前缀 - SOCKS5协议 ProxyProtocolSOCKS5 = "socks5" // AuthSeparator 认证分隔符 - 冒号分隔符 AuthSeparator = ":" )
View Source
const ( // ErrMsgUnsupportedProxyType Manager错误消息 - 不支持的代理类型 ErrMsgUnsupportedProxyType = "不支持的代理类型" // ErrMsgEmptyConfig 配置不能为空 ErrMsgEmptyConfig = "配置不能为空" // ErrMsgSOCKS5ParseFailed SOCKS5错误消息 - 地址解析失败 ErrMsgSOCKS5ParseFailed = "SOCKS5代理地址解析失败" // ErrMsgSOCKS5CreateFailed 拨号器创建失败 ErrMsgSOCKS5CreateFailed = "SOCKS5拨号器创建失败" // ErrMsgSOCKS5ConnTimeout 连接超时 ErrMsgSOCKS5ConnTimeout = "SOCKS5连接超时" // ErrMsgSOCKS5ConnFailed 连接失败 ErrMsgSOCKS5ConnFailed = "SOCKS5连接失败" // ErrMsgDirectConnFailed 直连错误消息 - 直连失败 ErrMsgDirectConnFailed = "直连失败" // ErrMsgHTTPConnFailed HTTP代理错误消息 - 连接失败 ErrMsgHTTPConnFailed = "连接HTTP代理服务器失败" // ErrMsgHTTPSetWriteTimeout 设置写超时失败 ErrMsgHTTPSetWriteTimeout = "设置写超时失败" // ErrMsgHTTPSendConnectFail 发送CONNECT请求失败 ErrMsgHTTPSendConnectFail = "发送CONNECT请求失败" // ErrMsgHTTPSetReadTimeout 设置读超时失败 ErrMsgHTTPSetReadTimeout = "设置读超时失败" // ErrMsgHTTPReadRespFailed 读取响应失败 ErrMsgHTTPReadRespFailed = "读取HTTP响应失败" // ErrMsgHTTPProxyAuthFailed 代理认证失败 ErrMsgHTTPProxyAuthFailed = "HTTP代理连接失败,状态码: %d" // ErrMsgTLSTCPConnFailed TLS错误消息 - TCP连接失败 ErrMsgTLSTCPConnFailed = "建立TCP连接失败" // ErrMsgTLSHandshakeFailed TLS握手失败 ErrMsgTLSHandshakeFailed = "TLS握手失败" )
View Source
const ( // CacheKeySOCKS5 缓存键前缀 - SOCKS5代理缓存键格式 CacheKeySOCKS5 = "socks5_%s" // CacheKeyHTTP HTTP代理缓存键格式 CacheKeyHTTP = "http_%s" )
View Source
const ( // SOCKS5URLFormat SOCKS5 URL格式 - 基本格式 SOCKS5URLFormat = "socks5://%s" // SOCKS5URLAuthFormat 带认证的SOCKS5 URL格式 SOCKS5URLAuthFormat = "socks5://%s:%s@%s" // HTTPConnectRequestFormat HTTP CONNECT请求格式 - CONNECT请求行 HTTPConnectRequestFormat = "CONNECT %s HTTP/1.1\r\nHost: %s\r\n" // HTTPAuthHeaderFormat 认证头格式 HTTPAuthHeaderFormat = "Proxy-Authorization: Basic %s\r\n" // HTTPRequestEndFormat 请求结束标记 HTTPRequestEndFormat = "\r\n" )
View Source
const ( // DefaultCacheExpiry 缓存配置 - 默认缓存过期时间 DefaultCacheExpiry = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func AutoConfigureProxy ¶
func AutoConfigureProxy(config *ProxyConfig)
AutoConfigureProxy 自动配置代理相关行为 根据代理类型和状态自动调整扫描策略
func ProbeProxyBehavior ¶
ProbeProxyBehavior 探测代理是否存在"全回显"问题 通过连接一个几乎肯定不可达的地址,并尝试发送数据来判断代理行为 返回 true 表示代理可靠,false 表示代理存在全回显问题
判断标准: - 连接失败 → 可靠(代理正确拒绝不可达目标) - 写入失败 → 可靠(代理在数据传输时报告错误) - 读取超时 → 可靠(代理转发了请求,目标没响应是正常的) - 读取错误 → 可靠(代理正确报告了目标不可达) - 收到数据 → 不可靠(代理伪造了响应)
Types ¶
type Dialer ¶
type Dialer interface {
Dial(network, address string) (net.Conn, error)
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer 拨号器接口
type ProxyConfig ¶
type ProxyConfig struct {
Type ProxyType `json:"type"`
Address string `json:"address"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
LocalAddr string `json:"local_addr,omitempty"` // 本地网卡IP地址(VPN场景)
Timeout time.Duration `json:"timeout"`
MaxRetries int `json:"max_retries"`
KeepAlive time.Duration `json:"keep_alive"`
IdleTimeout time.Duration `json:"idle_timeout"`
MaxIdleConns int `json:"max_idle_conns"`
}
ProxyConfig 代理配置
type ProxyError ¶
type ProxyError struct {
Type string `json:"type"`
Message string `json:"message"`
Code int `json:"code"`
Cause error `json:"cause,omitempty"`
}
ProxyError 代理错误类型
func NewProxyError ¶
func NewProxyError(errType, message string, code int, cause error) *ProxyError
NewProxyError 创建代理错误
func (*ProxyError) Error ¶
func (e *ProxyError) Error() string
type ProxyManager ¶
type ProxyManager interface {
GetDialer() (Dialer, error)
GetTLSDialer() (TLSDialer, error)
UpdateConfig(config *ProxyConfig) error
Close() error
Stats() *ProxyStats // 保留接口但实现为空操作
}
ProxyManager 代理管理器接口
func NewProxyManager ¶
func NewProxyManager(config *ProxyConfig) ProxyManager
NewProxyManager 创建新的代理管理器
type ProxyStats ¶
type ProxyStats struct {
TotalConnections int64 `json:"total_connections"`
ActiveConnections int64 `json:"active_connections"`
FailedConnections int64 `json:"failed_connections"`
AverageConnectTime time.Duration `json:"average_connect_time"`
LastConnectTime time.Time `json:"last_connect_time"`
LastError string `json:"last_error,omitempty"`
ProxyType string `json:"proxy_type"`
ProxyAddress string `json:"proxy_address"`
// contains filtered or unexported fields
}
ProxyStats 代理统计信息(暂时保留以维护编译)
Click to show internal directories.
Click to hide internal directories.