2018-06-10 22:50:03 +08:00
|
|
|
package constant
|
|
|
|
|
2018-06-11 18:36:39 +08:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2018-06-10 22:50:03 +08:00
|
|
|
// Socks addr type
|
|
|
|
const (
|
|
|
|
AtypIPv4 = 1
|
|
|
|
AtypDomainName = 3
|
|
|
|
AtypIPv6 = 4
|
2018-06-14 01:00:58 +08:00
|
|
|
|
2018-07-26 00:04:59 +08:00
|
|
|
TCP NetWork = iota
|
2018-06-14 01:00:58 +08:00
|
|
|
UDP
|
2018-07-26 00:04:59 +08:00
|
|
|
|
|
|
|
HTTP SourceType = iota
|
|
|
|
SOCKS
|
2018-12-05 21:13:29 +08:00
|
|
|
REDIR
|
2018-06-10 22:50:03 +08:00
|
|
|
)
|
|
|
|
|
2018-06-14 01:00:58 +08:00
|
|
|
type NetWork int
|
|
|
|
|
|
|
|
func (n *NetWork) String() string {
|
|
|
|
if *n == TCP {
|
|
|
|
return "tcp"
|
|
|
|
}
|
|
|
|
return "udp"
|
|
|
|
}
|
|
|
|
|
2018-07-26 00:04:59 +08:00
|
|
|
type SourceType int
|
|
|
|
|
2018-09-30 12:25:52 +08:00
|
|
|
// Metadata is used to store connection address
|
|
|
|
type Metadata struct {
|
2018-06-14 01:00:58 +08:00
|
|
|
NetWork NetWork
|
2018-07-26 00:04:59 +08:00
|
|
|
Source SourceType
|
2019-02-02 21:03:13 +08:00
|
|
|
SourceIP *net.IP
|
2018-06-10 22:50:03 +08:00
|
|
|
AddrType int
|
|
|
|
Host string
|
2018-06-11 18:36:39 +08:00
|
|
|
IP *net.IP
|
2018-06-10 22:50:03 +08:00
|
|
|
Port string
|
|
|
|
}
|
2018-06-11 18:36:39 +08:00
|
|
|
|
2019-02-02 20:47:38 +08:00
|
|
|
func (m *Metadata) String() string {
|
|
|
|
if m.Host == "" {
|
|
|
|
return m.IP.String()
|
2018-06-11 18:36:39 +08:00
|
|
|
}
|
2019-02-02 20:47:38 +08:00
|
|
|
return m.Host
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Metadata) Valid() bool {
|
|
|
|
return m.Host != "" || m.IP != nil
|
|
|
|
}
|