From 48b7c6ec3cf54e57100d05fbd102c69e5e3a0547 Mon Sep 17 00:00:00 2001 From: braginini Date: Wed, 7 Sep 2022 11:17:54 +0200 Subject: [PATCH] Fix TURN issue --- client/internal/engine.go | 1 + client/internal/peer/conn.go | 11 +++++++++-- iface/bind.go | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/internal/engine.go b/client/internal/engine.go index 5a8720744..38a2abcff 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -219,6 +219,7 @@ func (e *Engine) Start() error { log.Infof("NetBird Engine started listening on WireGuard port %d", *port) e.routeManager = routemanager.NewManager(e.ctx, e.config.WgPrivateKey.PublicKey().String(), e.wgInterface, e.statusRecorder) + e.config.WgPort = *port e.receiveSignalEvents() e.receiveManagementEvents() diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index f399f1717..57a43aa8c 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -345,8 +345,15 @@ func (conn *Conn) startProxy(remoteConn net.Conn, remoteWgPort int) error { peerState := nbStatus.PeerState{PubKey: conn.config.Key} - p := proxy.NewNoProxy(conn.config.ProxyConfig, remoteWgPort) - peerState.Direct = true + var p proxy.Proxy + if pair.Local.Type() == ice.CandidateTypeRelay || pair.Remote.Type() == ice.CandidateTypeRelay { + p = proxy.NewWireguardProxy(conn.config.ProxyConfig) + peerState.Direct = false + } else { + p = proxy.NewNoProxy(conn.config.ProxyConfig, remoteWgPort) + peerState.Direct = true + } + conn.proxy = p err = p.Start(remoteConn) if err != nil { diff --git a/iface/bind.go b/iface/bind.go index 15f6efe88..a63b8d678 100644 --- a/iface/bind.go +++ b/iface/bind.go @@ -200,12 +200,16 @@ func (b *ICEBind) Send(buff []byte, endpoint conn.Endpoint) error { b.mu.Lock() co := b.endpointMap[(*net.UDPAddr)(nend).String()] - b.mu.Unlock() + if co == nil { // todo proper handling + // todo without it relayed connections didn't work. investigate log.Warnf("conn not found for endpoint %s", (*net.UDPAddr)(nend).String()) - return conn.ErrWrongEndpointType + co = b.sharedConn + b.endpointMap[(*net.UDPAddr)(nend).String()] = b.sharedConn + //return conn.ErrWrongEndpointType } + b.mu.Unlock() _, err := co.WriteTo(buff, (*net.UDPAddr)(nend)) return err