SOCKS Protocol Version 5 Library.
Full TCP/UDP and IPv4/IPv6 support. Goals: KISS, less is more, small API, code is like the original protocol.
$ go get github.com/txthinking/socks5
- Negotiation:
type NegotiationRequest structfunc NewNegotiationRequest(methods []byte), in clientfunc (r *NegotiationRequest) WriteTo(w io.Writer), client writes to serverfunc NewNegotiationRequestFrom(r io.Reader), server reads from client
type NegotiationReply structfunc NewNegotiationReply(method byte), in serverfunc (r *NegotiationReply) WriteTo(w io.Writer), server writes to clientfunc NewNegotiationReplyFrom(r io.Reader), client reads from server
- User and password negotiation:
type UserPassNegotiationRequest structfunc NewUserPassNegotiationRequest(username []byte, password []byte), in clientfunc (r *UserPassNegotiationRequest) WriteTo(w io.Writer), client writes to serverfunc NewUserPassNegotiationRequestFrom(r io.Reader), server reads from client
type UserPassNegotiationReply structfunc NewUserPassNegotiationReply(status byte), in serverfunc (r *UserPassNegotiationReply) WriteTo(w io.Writer), server writes to clientfunc NewUserPassNegotiationReplyFrom(r io.Reader), client reads from server
- Request:
type Request structfunc NewRequest(cmd byte, atyp byte, dstaddr []byte, dstport []byte), in clientfunc (r *Request) WriteTo(w io.Writer), client writes to serverfunc NewRequestFrom(r io.Reader), server reads from client- After server gets the client's *Request, processes...
- Reply:
type Reply structfunc NewReply(rep byte, atyp byte, bndaddr []byte, bndport []byte), in serverfunc (r *Reply) WriteTo(w io.Writer), server writes to clientfunc NewReplyFrom(r io.Reader), client reads from server
- Datagram:
type Datagram structfunc NewDatagram(atyp byte, dstaddr []byte, dstport []byte, data []byte)func NewDatagramFromBytes(bb []byte)func (d *Datagram) Bytes()
Server. You can process client's request by yourself after reading *Request from client. Also, here is a advanced interfaces.
type Server structtype Handler interfaceTCPHandle(*Server, *net.TCPConn, *Request) errorUDPHandle(*Server, *net.UDPAddr, *Datagram) error
Example:
s, _ := NewClassicServer(addr, ip, username, password, tcpTimeout, udpTimeout)
s.ListenAndServe(Handler)
- If you want a standard socks5 server, pass in nil
- If you want to handle data by yourself, pass in a custom Handler
Client. Here is a client support both TCP and UDP and return net.Conn.
type Client struct
Example:
c, _ := socks5.NewClient(server, username, password, tcpTimeout, udpTimeout)
conn, _ := c.Dial(network, addr)