forked from sipt/shuttle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
73 lines (64 loc) · 1.32 KB
/
Copy pathmodel.go
File metadata and controls
73 lines (64 loc) · 1.32 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package shuttle
import (
"net"
"strconv"
)
const (
CmdTCP = 0x01
CmdUDP = 0x03
ProtocolSocks = "SOCKS"
ProtocolHttp = "HTTP"
ProtocolHttps = "HTTPS"
AddrTypeIPv4 = 0x01 // 0x01:IPv4
AddrTypeDomain = 0x03 // 0x03:域名
AddrTypeIPv6 = 0x04 // 0x04:IPv6
)
//|VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
type Request struct {
Ver uint8
Cmd uint8
Rsv uint8
Atyp uint8
Addr string
IP net.IP
Port uint16
DomainHost DomainHost
Data []byte //for udp
Protocol string
Target string
ConnID int64
}
func (r *Request) Host() string {
if len(r.IP) > 0 {
return net.JoinHostPort(r.IP.String(), strconv.Itoa(int(r.Port)))
} else {
return net.JoinHostPort(r.Addr, strconv.Itoa(int(r.Port)))
}
}
func (r *Request) Host2() string {
if len(r.Addr) > 0 {
return net.JoinHostPort(r.Addr, strconv.Itoa(int(r.Port)))
} else {
return net.JoinHostPort(r.IP.String(), strconv.Itoa(int(r.Port)))
}
}
func (r *Request) Network() string {
switch r.Cmd {
case CmdTCP:
return TCP
case CmdUDP:
return UDP
}
return ""
}
func (r *Request) GetIP() net.IP {
if len(r.IP) > 0 {
return r.IP
}
if r.IP = net.ParseIP(r.Addr); len(r.IP) > 0 {
return r.IP
}
err := ResolveDomain(r)
Logger.Errorf("[Request] GetIP error: %v", err)
return nil
}