Documentation
¶
Overview ¶
Package socks5 is imported from https://github.com/armon/go-socks5
Index ¶
Constants ¶
const ( ConnectCommand = uint8(1) BindCommand = uint8(2) AssociateCommand = uint8(3) )
const ( // socks5 version number. Socks5Version byte = 5 // No authentication required. NoAuth byte = 0 )
Variables ¶
var ( HandshakeErrors = metrics.RegisterMetric("socks5", "HandshakeErrors") DNSResolveErrors = metrics.RegisterMetric("socks5", "DNSResolveErrors") UnsupportedCommandErrors = metrics.RegisterMetric("socks5", "UnsupportedCommandErrors") NetworkUnreachableErrors = metrics.RegisterMetric("socks5", "NetworkUnreachableErrors") HostUnreachableErrors = metrics.RegisterMetric("socks5", "HostUnreachableErrors") ConnectionRefusedErrors = metrics.RegisterMetric("socks5", "ConnectionRefusedErrors") UDPAssociateErrors = metrics.RegisterMetric("socks5", "UDPAssociateErrors") // Incoming UDP association bytes. UDPAssociateInBytes = metrics.RegisterMetric("socks5 UDP associate", "InBytes") // Outgoing UDP association bytes. UDPAssociateOutBytes = metrics.RegisterMetric("socks5 UDP associate", "OutBytes") // Incoming UDP association packets. UDPAssociateInPkts = metrics.RegisterMetric("socks5 UDP associate", "InPkts") // Outgoing UDP association packets. UDPAssociateOutPkts = metrics.RegisterMetric("socks5 UDP associate", "OutPkts") )
Functions ¶
func BidiCopyUDP ¶ added in v1.7.0
func BidiCopyUDP(udpConn *net.UDPConn, tunnelConn *UDPAssociateTunnelConn) error
BidiCopyUDP does bi-directional data copy between a proxy client UDP endpoint and the proxy tunnel.
Types ¶
type AddrSpec ¶
AddrSpec is used to return the target AddrSpec which may be specified as IPv4, IPv6, or a FQDN.
type Config ¶
type Config struct { // Resolver can be provided to do custom name resolution. Resolver *util.DNSResolver // BindIP is used for bind or udp associate BindIP net.IP // Allow using socks5 to access resources served in localhost. AllowLocalDestination bool // Use mieru proxy to carry socks5 traffic. UseProxy bool // Mieru proxy configuration. ProxyConf []ProxyConfig // Mieru proxy multiplexer. ProxyMux *protocolv2.Mux }
Config is used to setup and configure a socks5 server.
type ProxyConfig ¶ added in v1.3.0
type ProxyConfig struct { // NetworkType ("tcp", "udp", etc.) used when dial to the proxy. NetworkType string // Address is proxy server listening address, in host:port format. Address string // Password is used to derive the cipher block used for encryption. Password []byte // Dial is the function to dial to the proxy server. Dial func(ctx context.Context, proxyNetwork, localAddr, proxyAddr string, block cipher.BlockCipher) (net.Conn, error) }
ProxyConfig is used to configure mieru proxy options.
type Request ¶
type Request struct { // Protocol version. Version uint8 // Requested command. Command uint8 // AddrSpec of the the network that sent the request. RemoteAddr *AddrSpec // AddrSpec of the desired destination. DestAddr *AddrSpec }
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 ServerGroup ¶ added in v1.3.0
type ServerGroup struct {
// contains filtered or unexported fields
}
ServerGroup is a collection of socks5 servers that share the same lifecycle.
func (*ServerGroup) Add ¶ added in v1.3.0
func (g *ServerGroup) Add(underlayProtocol string, port int, s *Server) error
Add adds a socks5 server into the ServerGroup.
func (*ServerGroup) CloseAndRemoveAll ¶ added in v1.3.0
func (g *ServerGroup) CloseAndRemoveAll() error
CloseAndRemoveAll closes all the socks5 servers and clear the group.
func (*ServerGroup) IsEmpty ¶ added in v1.3.0
func (g *ServerGroup) IsEmpty() bool
IsEmpty returns true if the group has no socks5 server.
type UDPAssociateTunnelConn ¶ added in v1.7.0
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 little endian.
func WrapUDPAssociateTunnel ¶ added in v1.7.0
func WrapUDPAssociateTunnel(conn io.ReadWriteCloser) *UDPAssociateTunnelConn
WrapUDPAssociateTunnel wraps an existing connection with UDPAssociateTunnelConn.
func (*UDPAssociateTunnelConn) Close ¶ added in v1.7.0
func (c *UDPAssociateTunnelConn) Close() error