From 7da74e707abef94025a6cf01edca3368d9468df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Mon, 5 Aug 2024 09:46:01 +0200 Subject: [PATCH] Fix continuous handshake sending with the agent without relay support. --- client/internal/peer/conn.go | 21 +++++++++++++++------ client/internal/peer/worker_relay.go | 10 +++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index d68766995..6b615f667 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -318,8 +318,14 @@ func (conn *Conn) reconnectLoopWithRetry() { return } - if conn.statusRelay == StatusDisconnected || conn.statusICE == StatusDisconnected { - conn.log.Tracef("ticker timedout, relay state: %s, ice state: %s", conn.statusRelay, conn.statusICE) + if conn.workerRelay.IsRelayConnectionSupportedWithPeer() { + if conn.statusRelay == StatusDisconnected || conn.statusICE == StatusDisconnected { + conn.log.Tracef("ticker timedout, relay state: %s, ice state: %s", conn.statusRelay, conn.statusICE) + } + } else { + if conn.statusICE == StatusDisconnected { + conn.log.Tracef("ticker timedout, ice state: %s", conn.statusICE) + } } // checks if there is peer connection is established via relay or ice @@ -708,13 +714,16 @@ func (conn *Conn) isConnected() bool { conn.mu.Lock() defer conn.mu.Unlock() - if conn.statusRelay != StatusConnected { - return false - } - if conn.statusICE != StatusConnected && conn.statusICE != StatusConnecting { return false } + + if conn.workerRelay.IsRelayConnectionSupportedWithPeer() { + if conn.statusRelay != StatusConnected { + return false + } + } + return true } diff --git a/client/internal/peer/worker_relay.go b/client/internal/peer/worker_relay.go index cf72e30e6..f03626e14 100644 --- a/client/internal/peer/worker_relay.go +++ b/client/internal/peer/worker_relay.go @@ -4,6 +4,7 @@ import ( "context" "errors" "net" + "sync/atomic" "time" log "github.com/sirupsen/logrus" @@ -34,7 +35,8 @@ type WorkerRelay struct { relayManager relayClient.ManagerService conn WorkerRelayCallbacks - ctxCancel context.CancelFunc + ctxCancel context.CancelFunc + relaySupportedOnRemotePeer atomic.Bool } func NewWorkerRelay(ctx context.Context, log *log.Entry, config ConnConfig, relayManager relayClient.ManagerService, callbacks WorkerRelayCallbacks) *WorkerRelay { @@ -51,8 +53,10 @@ func NewWorkerRelay(ctx context.Context, log *log.Entry, config ConnConfig, rela func (w *WorkerRelay) OnNewOffer(remoteOfferAnswer *OfferAnswer) { if !w.isRelaySupported(remoteOfferAnswer) { w.log.Infof("Relay is not supported by remote peer") + w.relaySupportedOnRemotePeer.Store(false) return } + w.relaySupportedOnRemotePeer.Store(true) // the relayManager will return with error in case if the connection has lost with relay server currentRelayAddress, err := w.relayManager.RelayInstanceAddress() @@ -99,6 +103,10 @@ func (w *WorkerRelay) RelayInstanceAddress() (string, error) { return w.relayManager.RelayInstanceAddress() } +func (w *WorkerRelay) IsRelayConnectionSupportedWithPeer() bool { + return w.relaySupportedOnRemotePeer.Load() && w.RelayIsSupportedLocally() +} + func (w *WorkerRelay) IsController() bool { return w.config.LocalKey > w.config.Key }