Documentation ¶
Index ¶
- Constants
- Variables
- func CheckCipherMethod(method string) error
- func Pipe(reader io.Reader, writer io.Writer, trafficFunc TrafficFunc) (written int64, err error)
- type AuthMethod
- type Cipher
- type Command
- type ConnHandler
- type CryptoStreamer
- type HttpProxy
- type HttpProxyConn
- type InterruptedError
- type PasswordHandle
- type Pipeline
- type ProxyConfig
- type ProxyListener
- type ProxyRoute
- type ProxyRule
- type ProxyServer
- func (p *ProxyServer) AddBlack(rule *Rule) error
- func (p *ProxyServer) AddConnectionWrappers(handler ConnHandler) *ProxyServer
- func (p *ProxyServer) AddRule(route *ProxyRoute) error
- func (p *ProxyServer) Close() error
- func (p *ProxyServer) Listen(ctx context.Context, network, address string) error
- func (p *ProxyServer) SetDeadline(duration time.Duration) *ProxyServer
- func (p *ProxyServer) SetDefaultProxy(tunnel *ProxyTunnel)
- type ProxyTunnel
- type Reply
- type Request
- type Rule
- type RuleMatcher
- type RuleOpts
- type RulePart
- type Socks5Conn
- type SocksConn
- type SocksProxyTCPConn
- type SocksProxyUDPConn
- type SocksVersion
- type TrafficFunc
- type UsernamePassword
Constants ¶
const ( AuthUsernamePasswordVersion = 0x01 AuthStatusSucceeded = 0x00 )
const ( AddrTypeIPv4 = 0x01 AddrTypeFQDN = 0x03 AddrTypeIPv6 = 0x04 CmdConnect Command = 0x01 // establishes an active-open forward proxy connection CmdBind Command = 0x02 // establishes a passive-open forward proxy connection CmdUdp = 0x03 AuthMethodNotRequired AuthMethod = 0x00 // no authentication required AuthMethodUsernamePassword AuthMethod = 0x02 // use username/password AuthMethodNoAcceptableMethods AuthMethod = 0xff // no acceptable authentication methods StatusSucceeded Reply = 0x00 )
Wire protocol constants.
const ( Exact = iota // string to match Wildcard = iota // * Separator = iota // ^ StartAnchor = iota // | DomainAnchor = iota // || Root = iota Substring = iota // Wildcard + Exact )
const BurstLimit = 1000 * 1000 * 1000
const ByteSize = 4108
Variables ¶
var ( ErrAddrType = errors.New("socks addr type not supported") ErrVer = errors.New("socks version not supported") ErrMethod = errors.New("socks only support 1 method now") ErrAuthExtraData = errors.New("socks authentication get extra data") ErrReqExtraData = errors.New("socks request get extra data") ErrCmd = errors.New("socks command not supported") ErrNoSupportedAuth = errors.New("socks no supported authentication mechanism") ErrNoSupportedAccountAuth = errors.New("socks no supported account authentication") ErrClientNoResponse = errors.New("socks client no response") ErrDomainForbidConnect = errors.New("forbid domain connect") ErrUserAuthFailed = errors.New("socks user authentication failed") ErrUnrecognizedAddrType = errors.New("socks unrecognized address type") ErrEmptyPassword = errors.New("socks authentication password is empty") ErrProxyClosed = errors.New("proxy server closed") ErrNoSupportedProxyType = errors.New("no supported proxy type") )
var ErrorLogger *logs.Logger
ErrorLogger exported
var GeneralLogger *logs.Logger
Logger exported
var (
NullOpts = RuleOpts{}
)
Functions ¶
func CheckCipherMethod ¶
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
type ConnHandler ¶
type CryptoStreamer ¶
type HttpProxy ¶
type HttpProxy struct {
// contains filtered or unexported fields
}
func NewHttpProxy ¶
func NewHttpProxy() *HttpProxy
func (*HttpProxy) Forward ¶
func (h *HttpProxy) Forward(response http.ResponseWriter, request *http.Request)
func (*HttpProxy) ServeHTTP ¶
func (h *HttpProxy) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServeHTTP implements HTTP Handler
func (*HttpProxy) SetRateLimit ¶
type HttpProxyConn ¶
func NewHttpProxyConn ¶
func NewHttpProxyConn(conn net.Conn) *HttpProxyConn
func (*HttpProxyConn) SetRateLimit ¶
func (conn *HttpProxyConn) SetRateLimit(bytesPerSec float64)
SetRateLimit 设置网速
type InterruptedError ¶
func (*InterruptedError) Error ¶
func (e *InterruptedError) Error() string
type PasswordHandle ¶
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
func NewPipeline ¶
type ProxyConfig ¶
type ProxyConfig struct { Listen string `toml:"listen" json:"listen"` GFWList string `toml:"gfw_list" json:"gfw_list"` GFWProxy []string `toml:"gfw_proxy" json:"gfw_proxy"` Proxy map[string]ProxyTunnel `toml:"proxy" json:"proxy"` Rules map[string]ProxyRule `toml:"rule" json:"rule"` Blacklist []string `toml:"blacklist" json:"blacklist"` }
func (*ProxyConfig) Resolve ¶
func (p *ProxyConfig) Resolve() (map[string]*ProxyRoute, error)
Resolve 解析白名单
func (*ProxyConfig) ResolveBlacklist ¶
func (p *ProxyConfig) ResolveBlacklist() ([]*Rule, error)
ResolveBlacklist 解析黑名单
func (*ProxyConfig) String ¶
func (p *ProxyConfig) String() string
type ProxyRoute ¶
type ProxyRoute struct { Rule *Rule Channel map[string]*ProxyTunnel }
func (*ProxyRoute) String ¶
func (proxy *ProxyRoute) String() string
type ProxyServer ¶
type ProxyServer struct { Authenticate PasswordHandle ReadTimeout time.Duration WriteTimeout time.Duration // contains filtered or unexported fields }
func NewProxyServer ¶
func NewProxyServer() *ProxyServer
func (*ProxyServer) AddConnectionWrappers ¶
func (p *ProxyServer) AddConnectionWrappers(handler ConnHandler) *ProxyServer
AddConnectionWrappers 增加连接的包装器
func (*ProxyServer) AddRule ¶
func (p *ProxyServer) AddRule(route *ProxyRoute) error
func (*ProxyServer) Listen ¶
func (p *ProxyServer) Listen(ctx context.Context, network, address string) error
func (*ProxyServer) SetDeadline ¶
func (p *ProxyServer) SetDeadline(duration time.Duration) *ProxyServer
func (*ProxyServer) SetDefaultProxy ¶
func (p *ProxyServer) SetDefaultProxy(tunnel *ProxyTunnel)
type ProxyTunnel ¶
type ProxyTunnel struct { Name string `toml:"name" json:"name"` Type string `toml:"type" json:"type"` Addr string `toml:"addr" json:"addr"` UserName string `toml:"username" json:"username"` Password string `toml:"password" json:"password"` }
func (*ProxyTunnel) DialTimeout ¶
func (tunnel *ProxyTunnel) DialTimeout(network string, address string, timeout time.Duration) (conn net.Conn, err error)
DialTimeout 连接到远程代理,并设置超时时间
func (*ProxyTunnel) String ¶
func (tunnel *ProxyTunnel) String() string
type Request ¶
type Request struct { // URL is matched against rule parts. Mandatory. URL string // Domain is matched against optional domain or third-party rules Domain string // ContentType is matched against optional content rules. This // information is often available only in client responses. Filters // may be applied twice, once at request time, once at response time. ContentType string // OriginDomain is matched against optional third-party rules. OriginDomain string // Timeout is the maximum amount of time a single matching can take. Timeout time.Duration CheckFreq int // GenericBlock is true if rules not matching a specific domain are to be // ignored. If nil, the matcher will determine it internally based on // $genericblock options. GenericBlock *bool }
Request defines client request properties to be matched against a set of rules.
func (*Request) HasGenericBlock ¶
type Rule ¶
type Rule struct { // The original string representation Raw string // Exception is true for exclusion rules (prefixed with "@@") Exception bool // Parts is the sequence of RulePart matching URLs Parts []RulePart // Opts are optional rules applied to content Opts RuleOpts }
Rule represents a complete adblockplus rule.
func ParseRules ¶
ParseRules returns the sequence of rules extracted from supplied reader content.
func (*Rule) HasContentOpts ¶
func (*Rule) HasUnsupportedOpts ¶
type RuleMatcher ¶
type RuleMatcher struct {
// contains filtered or unexported fields
}
RuleMatcher implements a complete set of include and exclude AdblockPlus rules.
func NewMatcherFromFiles ¶
func NewMatcherFromFiles(paths ...string) (*RuleMatcher, int, error)
func (*RuleMatcher) AddRule ¶
func (m *RuleMatcher) AddRule(rule *Rule, ruleId int) error
AddRule adds a rule to the matcher. Supplied rule identifier will be returned by Match().
func (*RuleMatcher) Match ¶
func (m *RuleMatcher) Match(rq *Request) (bool, int, error)
Match applies include and exclude rules on supplied request. If the request is accepted, it returns true and the matching rule identifier.
func (*RuleMatcher) String ¶
func (m *RuleMatcher) String() string
String returns a textual representation of the include and exclude rules, matching request with or without content.
type RuleOpts ¶
type RuleOpts struct { Raw string Collapse *bool Document bool Domains []string ElemHide bool Font *bool GenericBlock bool GenericHide bool Image *bool Media *bool Object *bool ObjectSubRequest *bool Other *bool Ping *bool Popup *bool Script *bool Stylesheet *bool SubDocument *bool ThirdParty *bool Websocket *bool WebRTC *bool XmlHttpRequest *bool }
RuleOpts defines custom rules applied to content once the URL part has been matched by the RuleParts.
func NewRuleOpts ¶
NewRuleOpts parses the rule part following the '$' separator and return content matching options.
type RulePart ¶
type RulePart struct { // Rule type, like Exact, Wildcard, etc. Type int // Rule part string representation Value string }
RulePart is the base component of rules. It represents a single matching element, like an exact match, a wildcard, a domain anchor...
type Socks5Conn ¶
func NewSocks5Conn ¶
func NewSocks5Conn(conn net.Conn, method AuthMethod) *Socks5Conn
NewSocks5Conn 初始化一个socks5协议的连接,并指定支持的认证方式
func (*Socks5Conn) Authenticate ¶
func (conn *Socks5Conn) Authenticate(handle PasswordHandle) error
Authenticate 如果是用户名认证,则需要调用该方法进行认证
func (*Socks5Conn) Forward ¶
func (conn *Socks5Conn) Forward() error
func (*Socks5Conn) SetRateLimit ¶
func (conn *Socks5Conn) SetRateLimit(bytesPerSec float64)
SetRateLimit 设置网速
type SocksProxyTCPConn ¶
type SocksProxyTCPConn struct {
SocksConn
}
type SocksProxyUDPConn ¶
type SocksProxyUDPConn struct {
SocksConn
}
type SocksVersion ¶
type SocksVersion uint8
const ( Socks5Version SocksVersion = 0x05 Socks4Version SocksVersion = 0x04 )
type TrafficFunc ¶
type TrafficFunc func(n int)
type UsernamePassword ¶
func (*UsernamePassword) Authenticate ¶
func (up *UsernamePassword) Authenticate(rw io.ReadWriter, auth AuthMethod) error