Fix continuous handshake sending with the agent without relay support.

This commit is contained in:
Zoltán Papp 2024-08-05 09:46:01 +02:00
parent cbe90b5dd9
commit 7da74e707a
2 changed files with 24 additions and 7 deletions

View File

@ -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
}

View File

@ -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
}