Documentation
¶
Overview ¶
Package socks5 is imported from https://github.com/armon/go-socks5 and https://github.com/h12w/socks
Index ¶
- Variables
- func BidiCopyUDP(udpConn *net.UDPConn, tunnelConn *UDPAssociateTunnelConn) error
- func Dial(proxyURI string, cmdType byte) func(string, string) (net.Conn, error)
- func DialSocks5Proxy(c *Client) func(string, string) (net.Conn, *net.UDPConn, *net.UDPAddr, error)
- func HTTPTransportProxyFunc(proxy string) func(*http.Request) (*url.URL, error)
- func NewHTTPProxyServer(listenAddr string, proxy *HTTPProxy) *http.Server
- func TransceiveUDPPacket(conn *net.UDPConn, proxyAddr, dstAddr *net.UDPAddr, payload []byte) ([]byte, error)
- type Auth
- type Client
- type Config
- type Credential
- type HTTPProxy
- type Request
- type Server
- type UDPAssociateTunnelConn
Constants ¶
This section is empty.
Variables ¶
var ( HTTPMetricGroupName = "HTTP proxy" HTTPRequests = metrics.RegisterMetric(HTTPMetricGroupName, "Requests", metrics.COUNTER) HTTPConnErrors = metrics.RegisterMetric(HTTPMetricGroupName, "ConnErrors", metrics.COUNTER) HTTPSchemeErrors = metrics.RegisterMetric(HTTPMetricGroupName, "SchemeErrors", metrics.COUNTER) )
var ( HandshakeErrors = metrics.RegisterMetric("socks5", "HandshakeErrors", metrics.COUNTER) DNSResolveErrors = metrics.RegisterMetric("socks5", "DNSResolveErrors", metrics.COUNTER) UnsupportedCommandErrors = metrics.RegisterMetric("socks5", "UnsupportedCommandErrors", metrics.COUNTER) NetworkUnreachableErrors = metrics.RegisterMetric("socks5", "NetworkUnreachableErrors", metrics.COUNTER) HostUnreachableErrors = metrics.RegisterMetric("socks5", "HostUnreachableErrors", metrics.COUNTER) ConnectionRefusedErrors = metrics.RegisterMetric("socks5", "ConnectionRefusedErrors", metrics.COUNTER) UDPAssociateErrors = metrics.RegisterMetric("socks5", "UDPAssociateErrors", metrics.COUNTER) UDPAssociateUploadBytes = metrics.RegisterMetric("socks5 UDP associate", "UploadBytes", metrics.COUNTER) UDPAssociateDownloadBytes = metrics.RegisterMetric("socks5 UDP associate", "DownloadBytes", metrics.COUNTER) UDPAssociateUploadPackets = metrics.RegisterMetric("socks5 UDP associate", "UploadPackets", metrics.COUNTER) UDPAssociateDownloadPackets = metrics.RegisterMetric("socks5 UDP associate", "DownloadPackets", metrics.COUNTER) )
Functions ¶
func BidiCopyUDP ¶
func BidiCopyUDP(udpConn *net.UDPConn, tunnelConn *UDPAssociateTunnelConn) error
BidiCopyUDP does bi-directional data copy between a proxy client UDP endpoint and the proxy tunnel.
func Dial ¶
Dial returns the dial function to be used in http.Transport object. Argument proxyURI should be in the format: "socks5://user:password@127.0.0.1:1080?timeout=5s". Only socks5 protocol is supported.
func DialSocks5Proxy ¶
DialSocks5Proxy returns two connections that can be used to send TCP and UDP traffic.
func HTTPTransportProxyFunc ¶
HTTPTransportProxyFunc returns the Proxy function used by http.Transport.
func NewHTTPProxyServer ¶
NewHTTPProxyServer returns a new HTTP proxy server.
Types ¶
type Auth ¶
type Auth struct { // Do socks5 authentication at proxy client side. ClientSideAuthentication bool // Credentials to authenticate incoming requests. // If empty, username password authentication is not supported. IngressCredentials []Credential // Credential to dial an outgoing socks5 connection. // If nil, username password authentication is not used. EgressCredential *Credential }
Auth provide authentication settings to socks5 server.
type Client ¶
type Client struct { Host string Credential *Credential Timeout time.Duration CmdType byte }
Client contains socks5 client configuration.
type Config ¶
type Config struct { // Mieru proxy multiplexer. ProxyMux *protocol.Mux // Egress controller. EgressController egress.Controller // Resolver can be provided to do custom name resolution. Resolver apicommon.DNSResolver // BindIP is used for bind or udp associate BindIP net.IP // Authentication options. AuthOpts Auth // Handshake timeout to establish socks5 connection. // Use 0 or negative value to disable the timeout. HandshakeTimeout time.Duration // Use mieru proxy to carry socks5 traffic. UseProxy bool // Allow using socks5 to access resources served in localhost. AllowLocalDestination bool }
Config is used to setup and configure a socks5 server.
type Credential ¶
type Credential struct { // User to dial an outgoing socks5 connection. User string // Password to dial an outgoing socks5 connection. Password string }
Credential stores socks5 credential for user password authentication.
type HTTPProxy ¶
type HTTPProxy struct { ProxyURI string // contains filtered or unexported fields }
type Request ¶
type Request struct { // Protocol version. Version uint8 // Requested command. Command uint8 // AddrSpec of the desired destination. DstAddr *model.AddrSpec // Raw request bytes. Raw []byte }
A Request represents request received by a server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is responsible for accepting connections and handling the details of the SOCKS5 protocol
func (*Server) ListenAndServe ¶
ListenAndServe is used to create a listener and serve on it.
type UDPAssociateTunnelConn ¶
type UDPAssociateTunnelConn struct {
io.ReadWriteCloser
}
UDPAssociateTunnelConn keeps the boundary of UDP packets when transmitted inside the proxy tunnel, which is typically a streaming pipe.
Each original UDP packet will be wrapped like this
0x00 + 2 bytes of original length + original content + 0xff
the length is encoded with big endian.
func WrapUDPAssociateTunnel ¶
func WrapUDPAssociateTunnel(conn io.ReadWriteCloser) *UDPAssociateTunnelConn
WrapUDPAssociateTunnel wraps an existing connection with UDPAssociateTunnelConn.
func (*UDPAssociateTunnelConn) Close ¶
func (c *UDPAssociateTunnelConn) Close() error