|
1 | 1 | package socks5 |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "errors" |
5 | 4 | "fmt" |
6 | 5 | ) |
7 | 6 |
|
8 | | -// ReplyCode are the bytes sent in SOCKS5 packets |
9 | | -// that represent replies from the server to a client |
10 | | -// request. |
| 7 | +// ReplyCode is the reply code in SOCKS5 packets sent from the server to a client. |
11 | 8 | type ReplyCode byte |
12 | 9 |
|
13 | | -// The set of valid SOCKS5 reply types as per the RFC 1928. |
14 | 10 | const ( |
15 | | - Success ReplyCode = 0 |
16 | | - GeneralFailure ReplyCode = 1 |
17 | | - ConnectionNotAllowed ReplyCode = 2 |
18 | | - NetworkUnreachable ReplyCode = 3 |
19 | | - HostUnreachable ReplyCode = 4 |
20 | | - ConnectionRefused ReplyCode = 5 |
21 | | - TtlExpired ReplyCode = 6 |
22 | | - CommandNotSupported ReplyCode = 7 |
23 | | - AddrTypeNotSupported ReplyCode = 8 |
24 | | -) |
25 | | - |
26 | | -var ( |
27 | | - ErrGeneralFailure = errors.New("general failure") |
28 | | - ErrConnectionNotAllowed = errors.New("connection not allowed") |
29 | | - ErrNetworkUnreachable = errors.New("network unreachable") |
30 | | - ErrHostUnreachable = errors.New("host unreachable") |
31 | | - ErrConnectionRefused = errors.New("connection refused") |
32 | | - ErrTtlExpired = errors.New("ttl expired") |
33 | | - ErrCommandNotSupported = errors.New("command not supported") |
34 | | - ErrAddrTypeNotSupported = errors.New("address type not supported") |
| 11 | + ReplySuccess ReplyCode = 0 |
| 12 | + ReplyGeneralFailure ReplyCode = 1 |
| 13 | + ReplyConnectionNotAllowed ReplyCode = 2 |
| 14 | + ReplyNetworkUnreachable ReplyCode = 3 |
| 15 | + ReplyHostUnreachable ReplyCode = 4 |
| 16 | + ReplyConnectionRefused ReplyCode = 5 |
| 17 | + ReplyTTLExpired ReplyCode = 6 |
| 18 | + ReplyCommandNotSupported ReplyCode = 7 |
| 19 | + ReplyAddrTypeNotSupported ReplyCode = 8 |
35 | 20 | ) |
36 | 21 |
|
37 | 22 | var replyCodeError = map[ReplyCode]error{ |
38 | | - Success: nil, |
39 | | - GeneralFailure: ErrGeneralFailure, |
40 | | - ConnectionNotAllowed: ErrConnectionNotAllowed, |
41 | | - NetworkUnreachable: ErrNetworkUnreachable, |
42 | | - HostUnreachable: ErrHostUnreachable, |
43 | | - ConnectionRefused: ErrConnectionRefused, |
44 | | - TtlExpired: ErrTtlExpired, |
45 | | - CommandNotSupported: ErrCommandNotSupported, |
46 | | - AddrTypeNotSupported: ErrAddrTypeNotSupported, |
| 23 | + ReplySuccess: nil, |
| 24 | + ReplyGeneralFailure: ErrReplyGeneralFailure, |
| 25 | + ReplyConnectionNotAllowed: ErrReplyConnectionNotAllowed, |
| 26 | + ReplyNetworkUnreachable: ErrReplyNetworkUnreachable, |
| 27 | + ReplyHostUnreachable: ErrReplyHostUnreachable, |
| 28 | + ReplyConnectionRefused: ErrReplyConnectionRefused, |
| 29 | + ReplyTTLExpired: ErrReplyTTLExpired, |
| 30 | + ReplyCommandNotSupported: ErrReplyCommandNotSupported, |
| 31 | + ReplyAddrTypeNotSupported: ErrReplyAddrTypeNotSupported, |
47 | 32 | } |
48 | 33 |
|
49 | 34 | func (code ReplyCode) ToError() error { |
50 | 35 | if err, ok := replyCodeError[code]; ok { |
51 | 36 | return err |
52 | 37 | } |
53 | | - return fmt.Errorf("code(%d)", int(code)) |
| 38 | + return fmt.Errorf("socks5code(%v)", code) |
54 | 39 | } |
0 commit comments