Update network handler usages

This commit is contained in:
世界 2024-10-20 13:42:53 +08:00
parent a8ae222eeb
commit 99eea00432
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
12 changed files with 51 additions and 78 deletions

View file

@ -36,15 +36,14 @@ func NewUDPForwarder(ctx context.Context, stack *stack.Stack, handler Handler, u
return &UDPForwarder{
ctx: ctx,
stack: stack,
udpNat: udpnat.New[netip.AddrPort](udpTimeout, handler),
udpNat: udpnat.NewEx[netip.AddrPort](udpTimeout, handler),
}
}
func (f *UDPForwarder) HandlePacket(id stack.TransportEndpointID, pkt *stack.PacketBuffer) bool {
var upstreamMetadata M.Metadata
upstreamMetadata.Source = M.SocksaddrFrom(AddrFromAddress(id.RemoteAddress), id.RemotePort)
upstreamMetadata.Destination = M.SocksaddrFrom(AddrFromAddress(id.LocalAddress), id.LocalPort)
if upstreamMetadata.Source.IsIPv4() {
source := M.SocksaddrFrom(AddrFromAddress(id.RemoteAddress), id.RemotePort)
destination := M.SocksaddrFrom(AddrFromAddress(id.LocalAddress), id.LocalPort)
if source.IsIPv4() {
f.cacheProto = header.IPv4ProtocolNumber
} else {
f.cacheProto = header.IPv6ProtocolNumber
@ -55,11 +54,12 @@ func (f *UDPForwarder) HandlePacket(id stack.TransportEndpointID, pkt *stack.Pac
sBuffer.Write(view.AsSlice())
})
f.cacheID = id
f.udpNat.NewPacket(
f.udpNat.NewPacketEx(
f.ctx,
upstreamMetadata.Source.AddrPort(),
source.AddrPort(),
sBuffer,
upstreamMetadata,
source,
destination,
f.newUDPConn,
)
return true