feat: introduce a new robust approach to handle tproxy udp. (#389)

This commit is contained in:
Ovear
2023-02-17 16:31:15 +08:00
committed by GitHub
parent b2d1cea759
commit 8e4dfbd10d
10 changed files with 246 additions and 12 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/netip"
"sync"
"time"
"github.com/Dreamacro/clash/component/dialer"
@ -216,6 +217,10 @@ type UDPPacket interface {
// LocalAddr returns the source IP/Port of packet
LocalAddr() net.Addr
SetNatTable(natTable NatTable)
SetUdpInChan(in chan<- PacketAdapter)
}
type UDPPacketInAddr interface {
@ -227,3 +232,23 @@ type PacketAdapter interface {
UDPPacket
Metadata() *Metadata
}
type NatTable interface {
Set(key string, e PacketConn)
Get(key string) PacketConn
GetOrCreateLock(key string) (*sync.Cond, bool)
Delete(key string)
GetLocalConn(lAddr, rAddr string) *net.UDPConn
AddLocalConn(lAddr, rAddr string, conn *net.UDPConn) bool
RangeLocalConn(lAddr string, f func(key, value any) bool)
GetOrCreateLockForLocalConn(lAddr, key string) (*sync.Cond, bool)
DeleteLocalConnMap(lAddr, key string)
}