From 12148c5d62514bcfc88b2c47a6a7a56a7774e3a3 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Tue, 27 Sep 2022 14:12:52 +0800 Subject: [PATCH] Fix build failed on windows Udp mux need retrieve destination address to dispatch received packet when listen at Any address. Windows use winsock APIs to get that, but conn.FD() is not implement for windows, so dispatch packet to first candidate, not ideally, but it will work for ice connectin, wasm will have same result too. --- udp_mux.go | 11 +++++++++-- udpmsghelper.go | 2 +- udpmsghelper_js.go => udpmsghelper_js_win.go | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) rename udpmsghelper_js.go => udpmsghelper_js_win.go (92%) diff --git a/udp_mux.go b/udp_mux.go index f93a546..a477ead 100644 --- a/udp_mux.go +++ b/udp_mux.go @@ -365,12 +365,19 @@ func (m *UDPMuxDefault) connWorker() { //nolint:gocognit var destinationConn *udpMuxedConn m.addressMapMu.Lock() if conns, ok := m.addressMap[addr.String()]; ok { - destinationConn = conns[ipAddr(localHost.String())] + if localHost.IsUnspecified() { + for _, c := range conns { + destinationConn = c + break + } + } else { + destinationConn = conns[ipAddr(localHost.String())] + } } m.addressMapMu.Unlock() // If we haven't seen this address before but is a STUN packet lookup by ufrag - if destinationConn == nil && stun.IsMessage(buf[:n]) { + if destinationConn == nil && stun.IsMessage(buf[:n]) && !localHost.IsUnspecified() { msg := &stun.Message{ Raw: append([]byte{}, buf[:n]...), } diff --git a/udpmsghelper.go b/udpmsghelper.go index b5b95d5..51efa36 100644 --- a/udpmsghelper.go +++ b/udpmsghelper.go @@ -1,4 +1,4 @@ -//go:build !js +//go:build !js && !windows package ice diff --git a/udpmsghelper_js.go b/udpmsghelper_js_win.go similarity index 92% rename from udpmsghelper_js.go rename to udpmsghelper_js_win.go index e55911a..51c990a 100644 --- a/udpmsghelper_js.go +++ b/udpmsghelper_js_win.go @@ -1,4 +1,4 @@ -//go:build js +//go:build js || windows package ice