clash/constant/metadata.go

54 lines
692 B
Go
Raw Normal View History

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