Debian Codegraph @

README.md

raw symbols SCIP
1 ## socks5
2
3 [中文](README_ZH.md)
4
5 [![Go Report Card](https://goreportcard.com/badge/github.com/txthinking/socks5)](https://goreportcard.com/report/github.com/txthinking/socks5)
6 [![GoDoc](https://godoc.org/github.com/txthinking/socks5?status.svg)](https://godoc.org/github.com/txthinking/socks5)
7
8 [🗣 News](https://t.me/s/txthinking_news)
9 [🩸 Youtube](https://www.youtube.com/txthinking)
10
11 SOCKS Protocol Version 5 Library.
12
13 Full TCP/UDP and IPv4/IPv6 support.
14 Goals: KISS, less is more, small API, code is like the original protocol.
15
16 ❤️ A project by [txthinking.com](https://www.txthinking.com)
17
18 ### Install
19
20 ```
21 $ go get github.com/txthinking/socks5
22 ```
23
24 ### Struct is like concept in protocol
25
26 - Negotiation:
27 - `type NegotiationRequest struct`
28 - `func NewNegotiationRequest(methods []byte)`, in client
29 - `func (r *NegotiationRequest) WriteTo(w io.Writer)`, client writes to server
30 - `func NewNegotiationRequestFrom(r io.Reader)`, server reads from client
31 - `type NegotiationReply struct`
32 - `func NewNegotiationReply(method byte)`, in server
33 - `func (r *NegotiationReply) WriteTo(w io.Writer)`, server writes to client
34 - `func NewNegotiationReplyFrom(r io.Reader)`, client reads from server
35 - User and password negotiation:
36 - `type UserPassNegotiationRequest struct`
37 - `func NewUserPassNegotiationRequest(username []byte, password []byte)`, in client
38 - `func (r *UserPassNegotiationRequest) WriteTo(w io.Writer)`, client writes to server
39 - `func NewUserPassNegotiationRequestFrom(r io.Reader)`, server reads from client
40 - `type UserPassNegotiationReply struct`
41 - `func NewUserPassNegotiationReply(status byte)`, in server
42 - `func (r *UserPassNegotiationReply) WriteTo(w io.Writer)`, server writes to client
43 - `func NewUserPassNegotiationReplyFrom(r io.Reader)`, client reads from server
44 - Request:
45 - `type Request struct`
46 - `func NewRequest(cmd byte, atyp byte, dstaddr []byte, dstport []byte)`, in client
47 - `func (r *Request) WriteTo(w io.Writer)`, client writes to server
48 - `func NewRequestFrom(r io.Reader)`, server reads from client
49 - After server gets the client's \*Request, processes...
50 - Reply:
51 - `type Reply struct`
52 - `func NewReply(rep byte, atyp byte, bndaddr []byte, bndport []byte)`, in server
53 - `func (r *Reply) WriteTo(w io.Writer)`, server writes to client
54 - `func NewReplyFrom(r io.Reader)`, client reads from server
55 - Datagram:
56 - `type Datagram struct`
57 - `func NewDatagram(atyp byte, dstaddr []byte, dstport []byte, data []byte)`
58 - `func NewDatagramFromBytes(bb []byte)`
59 - `func (d *Datagram) Bytes()`
60
61 ### Advanced API
62
63 > This can satisfy the classic scenario, and it is still recommended that you choose the above small API to customize for special scenarios.
64
65 **Server**: support both TCP and UDP
66
67 - `type Server struct`
68 - `type Handler interface`
69 - `TCPHandle(*Server, *net.TCPConn, *Request) error`
70 - `UDPHandle(*Server, *net.UDPAddr, *Datagram) error`
71
72 Example:
73
74 ```
75 server, _ := NewClassicServer(addr, ip, username, password, tcpTimeout, udpTimeout)
76 server.ListenAndServe(Handler)
77 ```
78
79 **Client**: support both TCP and UDP and return net.Conn
80
81 - `type Client struct`
82
83 Example:
84
85 ```
86 client, _ := socks5.NewClient(server, username, password, tcpTimeout, udpTimeout)
87 conn, _ := client.Dial(network, addr)
88 ```
89
90 ### Projects using this library
91
92 - Brook: https://github.com/txthinking/brook
93 - Shiliew: https://www.txthinking.com/shiliew.html
94 - dismap: https://github.com/zhzyker/dismap
95 - emp3r0r: https://github.com/jm33-m0/emp3r0r
96 - hysteria: https://github.com/apernet/hysteria
97 - mtg: https://github.com/9seconds/mtg
98 - trojan-go: https://github.com/p4gefau1t/trojan-go
99
100
101 ## License
102
103 Licensed under The MIT License