Improve: udp NAT type

This commit is contained in:
Dreamacro
2020-01-31 14:43:54 +08:00
parent aa207ec664
commit 26ce3e8814
18 changed files with 71 additions and 108 deletions

View File

@ -59,7 +59,7 @@ type ProxyAdapter interface {
Name() string
Type() AdapterType
DialContext(ctx context.Context, metadata *Metadata) (Conn, error)
DialUDP(metadata *Metadata) (PacketConn, net.Addr, error)
DialUDP(metadata *Metadata) (PacketConn, error)
SupportUDP() bool
MarshalJSON() ([]byte, error)
}

View File

@ -3,6 +3,7 @@ package constant
import (
"encoding/json"
"net"
"strconv"
)
// Socks addr type
@ -70,6 +71,17 @@ func (m *Metadata) RemoteAddress() string {
return net.JoinHostPort(m.String(), m.DstPort)
}
func (m *Metadata) UDPAddr() *net.UDPAddr {
if m.NetWork != UDP || m.DstIP == nil {
return nil
}
port, _ := strconv.Atoi(m.DstPort)
return &net.UDPAddr{
IP: m.DstIP,
Port: port,
}
}
func (m *Metadata) String() string {
if m.Host != "" {
return m.Host