mirror of
https://github.com/amnezia-vpn/amnezia-tun2socks.git
synced 2026-05-17 00:05:47 +03:00
Refactor: return metadata.Addr only
This commit is contained in:
@@ -25,9 +25,6 @@ func (m *Metadata) SourceAddress() string {
|
||||
}
|
||||
|
||||
func (m *Metadata) Addr() net.Addr {
|
||||
if udpAddr := m.UDPAddr(); udpAddr != nil {
|
||||
return udpAddr
|
||||
}
|
||||
return &Addr{metadata: m}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ type directPacketConn struct {
|
||||
}
|
||||
|
||||
func (pc *directPacketConn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||
if ma, ok := addr.(*M.Addr); ok && ma.Metadata().DstIP != nil {
|
||||
return pc.PacketConn.WriteTo(b, ma.Metadata().UDPAddr())
|
||||
if udpAddr, ok := addr.(*net.UDPAddr); ok {
|
||||
return pc.PacketConn.WriteTo(b, udpAddr)
|
||||
}
|
||||
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", addr.String())
|
||||
|
||||
@@ -48,7 +48,13 @@ func handleUDPConn(uc adapter.UDPConn) {
|
||||
pc = newUDPTracker(pc, metadata)
|
||||
defer pc.Close()
|
||||
|
||||
remote := metadata.Addr()
|
||||
var remote net.Addr
|
||||
if udpAddr := metadata.UDPAddr(); udpAddr != nil {
|
||||
remote = udpAddr
|
||||
} else {
|
||||
remote = metadata.Addr()
|
||||
}
|
||||
|
||||
go handleUDPToRemote(uc, pc, remote)
|
||||
handleUDPToLocal(uc, pc, remote)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user