mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-15 22:48:02 +08:00
chore: modify UDPSniff's function signature to prepare for its ability to handle multiple packets.
This commit is contained in:
parent
0ed159e41d
commit
7ff046a455
@ -60,7 +60,10 @@ func (sd *Dispatcher) forceSniff(metadata *C.Metadata) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sd *Dispatcher) UDPSniff(packet C.PacketAdapter) bool {
|
// UDPSniff is called when a UDP NAT is created and passed the first initialization packet.
|
||||||
|
// It may return a wrapped packetSender if the sniffer process needs to wait for multiple packets.
|
||||||
|
// This function must be non-blocking, and any blocking operations should be done in the wrapped packetSender.
|
||||||
|
func (sd *Dispatcher) UDPSniff(packet C.PacketAdapter, packetSender C.PacketSender) C.PacketSender {
|
||||||
metadata := packet.Metadata()
|
metadata := packet.Metadata()
|
||||||
if sd.shouldOverride(metadata) {
|
if sd.shouldOverride(metadata) {
|
||||||
for sniffer, config := range sd.sniffers {
|
for sniffer, config := range sd.sniffers {
|
||||||
@ -75,13 +78,13 @@ func (sd *Dispatcher) UDPSniff(packet C.PacketAdapter) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sd.replaceDomain(metadata, host, overrideDest)
|
sd.replaceDomain(metadata, host, overrideDest)
|
||||||
return true
|
return packetSender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return packetSender
|
||||||
}
|
}
|
||||||
|
|
||||||
// TCPSniff returns true if the connection is sniffed to have a domain
|
// TCPSniff returns true if the connection is sniffed to have a domain
|
||||||
|
@ -378,12 +378,14 @@ func handleUDPConn(packet C.PacketAdapter) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if sniffingEnable && snifferDispatcher.Enable() {
|
|
||||||
snifferDispatcher.UDPSniff(packet)
|
|
||||||
}
|
|
||||||
|
|
||||||
key := packet.Key()
|
key := packet.Key()
|
||||||
sender, loaded := natTable.GetOrCreate(key, newPacketSender)
|
sender, loaded := natTable.GetOrCreate(key, func() C.PacketSender {
|
||||||
|
sender := newPacketSender()
|
||||||
|
if sniffingEnable && snifferDispatcher.Enable() {
|
||||||
|
return snifferDispatcher.UDPSniff(packet, sender)
|
||||||
|
}
|
||||||
|
return sender
|
||||||
|
})
|
||||||
if !loaded {
|
if !loaded {
|
||||||
dial := func() (C.PacketConn, C.WriteBackProxy, error) {
|
dial := func() (C.PacketConn, C.WriteBackProxy, error) {
|
||||||
if err := sender.ResolveUDP(metadata); err != nil {
|
if err := sender.ResolveUDP(metadata); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user