Documentation ¶
Overview ¶
Package socks5 provies socks5 proxy for proxy.Client and proxy.Server.
Supports USER/PASSWORD authentication.
Reference ¶
English: https://www.ietf.org/rfc/rfc1928.txt
中文: https://aber.sh/articles/Socks5/
参考 https://studygolang.com/articles/31404
USER/PASSWORD authentication rfc:
https://datatracker.ietf.org/doc/html/rfc1929
Off Topic ¶
总体而言,vless/vmess/trojan协议借鉴了socks5,有不少类似的地方。 所以制作代理, 有必要学习socks5标准。
Index ¶
- Constants
- func Client_EstablishUDPAssociate(conn net.Conn) (port int, err error)
- func Client_ReadUDPResponse(udpConn *net.UDPConn, supposedServerAddr *net.UDPAddr) (target netLayer.Addr, data []byte, e error)
- func Client_RequestUDP(udpConn *net.UDPConn, target *netLayer.Addr, data []byte) error
- type Client
- type ClientCreator
- type ClientUDPConn
- func (cpc *ClientUDPConn) Associate() (err error)
- func (cpc *ClientUDPConn) CloseConnWithRaddr(raddr netLayer.Addr) error
- func (cpc *ClientUDPConn) Fullcone() bool
- func (cpc *ClientUDPConn) Read(p []byte) (n int, err error)
- func (cpc *ClientUDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (cpc *ClientUDPConn) ReadMsgFrom() (data []byte, target netLayer.Addr, err error)
- func (cpc *ClientUDPConn) Write(p []byte) (n int, err error)
- func (cpc *ClientUDPConn) WriteMsgTo(p []byte, addr netLayer.Addr) (err error)
- func (cpc *ClientUDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type Server
- type ServerCreator
- type ServerUDPConn
Constants ¶
const ( AuthNone = 0x00 AuthPassword = 0x02 AuthNoACCEPTABLE = 0xff )
SOCKS auth type
const ( CmdConnect = 0x01 CmdBind = 0x02 CmdUDPAssociate = 0x03 )
SOCKS request commands as defined in RFC 1928 section 4
const ( ATypIP4 = 0x1 ATypDomain = 0x3 ATypIP6 = 0x4 )
SOCKS address types as defined in RFC 1928 section 4
Note: vmess/vless用的是123,而这里用的是134,所以是不一样的。
const Name = "socks5"
const Version5 = 0x05
socks5 version number.
Variables ¶
This section is empty.
Functions ¶
func Client_EstablishUDPAssociate ¶
传入 conn必须非nil,否则panic
Types ¶
type Client ¶
type Client struct { proxy.Base utils.EasyUserPassHolder }
func (*Client) EstablishUDPChannel ¶
type ClientCreator ¶ added in v1.2.1
type ClientCreator struct{}
func (ClientCreator) NewClientFromURL ¶ added in v1.2.1
type ClientUDPConn ¶
type ClientUDPConn struct { *net.UDPConn ServerAddr *net.TCPAddr //用于建立 udp associate的 服务器地址 ServerUDPPort_forMe int //socks5服务会为每一个socks5客户端留一个专用的udp端口 WriteUDP_Target *net.UDPAddr // contains filtered or unexported fields }
实现 net.PacketConn , net.Conn 和 netLayer.MsgConn
func (*ClientUDPConn) Associate ¶
func (cpc *ClientUDPConn) Associate() (err error)
func (*ClientUDPConn) CloseConnWithRaddr ¶
func (cpc *ClientUDPConn) CloseConnWithRaddr(raddr netLayer.Addr) error
func (*ClientUDPConn) Fullcone ¶
func (cpc *ClientUDPConn) Fullcone() bool
func (*ClientUDPConn) ReadMsgFrom ¶
func (cpc *ClientUDPConn) ReadMsgFrom() (data []byte, target netLayer.Addr, err error)
func (*ClientUDPConn) WriteMsgTo ¶
func (cpc *ClientUDPConn) WriteMsgTo(p []byte, addr netLayer.Addr) (err error)
type Server ¶
type Server struct { proxy.Base utils.EasyUserPassHolder }
type ServerCreator ¶
type ServerCreator struct{}
func (ServerCreator) NewServer ¶
func (ServerCreator) NewServer(lc *proxy.ListenConf) (rs proxy.Server, err error)
func (ServerCreator) NewServerFromURL ¶
type ServerUDPConn ¶
用于socks5服务端的 udp连接, 实现 netLayer.MsgConn
func (*ServerUDPConn) CloseConnWithRaddr ¶
func (u *ServerUDPConn) CloseConnWithRaddr(raddr netLayer.Addr) error
func (*ServerUDPConn) Fullcone ¶
func (u *ServerUDPConn) Fullcone() bool
func (*ServerUDPConn) ReadMsgFrom ¶
func (u *ServerUDPConn) ReadMsgFrom() ([]byte, netLayer.Addr, error)
从 客户端读取 udp请求
func (*ServerUDPConn) WriteMsgTo ¶
func (u *ServerUDPConn) WriteMsgTo(bs []byte, raddr netLayer.Addr) error
将远程地址发来的响应 传给客户端