-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplycode.go
39 lines (34 loc) · 1.15 KB
/
replycode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package socks5
import (
"fmt"
)
// ReplyCode is the reply code in SOCKS5 packets sent from the server to a client.
type ReplyCode byte
const (
ReplySuccess ReplyCode = 0
ReplyGeneralFailure ReplyCode = 1
ReplyConnectionNotAllowed ReplyCode = 2
ReplyNetworkUnreachable ReplyCode = 3
ReplyHostUnreachable ReplyCode = 4
ReplyConnectionRefused ReplyCode = 5
ReplyTTLExpired ReplyCode = 6
ReplyCommandNotSupported ReplyCode = 7
ReplyAddrTypeNotSupported ReplyCode = 8
)
var replyCodeError = map[ReplyCode]error{
ReplySuccess: nil,
ReplyGeneralFailure: ErrReplyGeneralFailure,
ReplyConnectionNotAllowed: ErrReplyConnectionNotAllowed,
ReplyNetworkUnreachable: ErrReplyNetworkUnreachable,
ReplyHostUnreachable: ErrReplyHostUnreachable,
ReplyConnectionRefused: ErrReplyConnectionRefused,
ReplyTTLExpired: ErrReplyTTLExpired,
ReplyCommandNotSupported: ErrReplyCommandNotSupported,
ReplyAddrTypeNotSupported: ErrReplyAddrTypeNotSupported,
}
func (code ReplyCode) ToError() error {
if err, ok := replyCodeError[code]; ok {
return err
}
return fmt.Errorf("socks5code(%v)", code)
}