mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
fix: udp nat handle
This commit is contained in:
parent
f16ebf9bfe
commit
9d8c3b0a3b
|
@ -342,29 +342,9 @@ func handleUDPConn(packet C.PacketAdapter) {
|
|||
return false
|
||||
}
|
||||
|
||||
if handle() {
|
||||
packet.Drop()
|
||||
return
|
||||
}
|
||||
|
||||
cond, loaded := natTable.GetOrCreateLock(key)
|
||||
|
||||
go func() {
|
||||
defer packet.Drop()
|
||||
|
||||
if loaded {
|
||||
cond.L.Lock()
|
||||
cond.Wait()
|
||||
handle()
|
||||
cond.L.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
natTable.DeleteLock(key)
|
||||
cond.Broadcast()
|
||||
}()
|
||||
|
||||
proxy, rule, err := resolveMetadata(metadata)
|
||||
if err != nil {
|
||||
log.Warnln("[UDP] Parse metadata failed: %s", err.Error())
|
||||
|
@ -381,6 +361,25 @@ func handleUDPConn(packet C.PacketAdapter) {
|
|||
metadata.DstIP = ip
|
||||
}
|
||||
|
||||
if handle() {
|
||||
return
|
||||
}
|
||||
|
||||
cond, loaded := natTable.GetOrCreateLock(key)
|
||||
|
||||
if loaded {
|
||||
cond.L.Lock()
|
||||
cond.Wait()
|
||||
handle()
|
||||
cond.L.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
natTable.DeleteLock(key)
|
||||
cond.Broadcast()
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultUDPTimeout)
|
||||
defer cancel()
|
||||
rawPc, err := retry(ctx, func(ctx context.Context) (C.PacketConn, error) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user