refactor: udp

This commit is contained in:
世界
2022-06-09 21:16:42 +08:00
parent cd466f05d3
commit 637a8b6ed5
23 changed files with 231 additions and 127 deletions

View File

@@ -6,6 +6,8 @@ import (
"net"
"net/netip"
"strconv"
M "github.com/sagernet/sing/common/metadata"
)
// Socks addr type
@@ -170,6 +172,18 @@ func (m *Metadata) UDPAddr() *net.UDPAddr {
}
}
func (m *Metadata) Socksaddr() M.Socksaddr {
port, _ := strconv.ParseUint(m.DstPort, 10, 16)
if m.Host != "" {
return M.Socksaddr{
Fqdn: m.Host,
Port: uint16(port),
}
} else {
return M.SocksaddrFromAddrPort(m.DstIP, uint16(port))
}
}
func (m *Metadata) String() string {
if m.Host != "" {
return m.Host