mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-09 15:38:26 +01:00
Fix continuous handshake sending with the agent without relay support.
This commit is contained in:
parent
cbe90b5dd9
commit
7da74e707a
@ -318,9 +318,15 @@ func (conn *Conn) reconnectLoopWithRetry() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conn.workerRelay.IsRelayConnectionSupportedWithPeer() {
|
||||||
if conn.statusRelay == StatusDisconnected || conn.statusICE == StatusDisconnected {
|
if conn.statusRelay == StatusDisconnected || conn.statusICE == StatusDisconnected {
|
||||||
conn.log.Tracef("ticker timedout, relay state: %s, ice state: %s", conn.statusRelay, conn.statusICE)
|
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
|
// checks if there is peer connection is established via relay or ice
|
||||||
if conn.isConnected() {
|
if conn.isConnected() {
|
||||||
@ -708,13 +714,16 @@ func (conn *Conn) isConnected() bool {
|
|||||||
conn.mu.Lock()
|
conn.mu.Lock()
|
||||||
defer conn.mu.Unlock()
|
defer conn.mu.Unlock()
|
||||||
|
|
||||||
if conn.statusRelay != StatusConnected {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if conn.statusICE != StatusConnected && conn.statusICE != StatusConnecting {
|
if conn.statusICE != StatusConnected && conn.statusICE != StatusConnecting {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conn.workerRelay.IsRelayConnectionSupportedWithPeer() {
|
||||||
|
if conn.statusRelay != StatusConnected {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -35,6 +36,7 @@ type WorkerRelay struct {
|
|||||||
conn WorkerRelayCallbacks
|
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 {
|
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) {
|
func (w *WorkerRelay) OnNewOffer(remoteOfferAnswer *OfferAnswer) {
|
||||||
if !w.isRelaySupported(remoteOfferAnswer) {
|
if !w.isRelaySupported(remoteOfferAnswer) {
|
||||||
w.log.Infof("Relay is not supported by remote peer")
|
w.log.Infof("Relay is not supported by remote peer")
|
||||||
|
w.relaySupportedOnRemotePeer.Store(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
w.relaySupportedOnRemotePeer.Store(true)
|
||||||
|
|
||||||
// the relayManager will return with error in case if the connection has lost with relay server
|
// the relayManager will return with error in case if the connection has lost with relay server
|
||||||
currentRelayAddress, err := w.relayManager.RelayInstanceAddress()
|
currentRelayAddress, err := w.relayManager.RelayInstanceAddress()
|
||||||
@ -99,6 +103,10 @@ func (w *WorkerRelay) RelayInstanceAddress() (string, error) {
|
|||||||
return w.relayManager.RelayInstanceAddress()
|
return w.relayManager.RelayInstanceAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WorkerRelay) IsRelayConnectionSupportedWithPeer() bool {
|
||||||
|
return w.relaySupportedOnRemotePeer.Load() && w.RelayIsSupportedLocally()
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WorkerRelay) IsController() bool {
|
func (w *WorkerRelay) IsController() bool {
|
||||||
return w.config.LocalKey > w.config.Key
|
return w.config.LocalKey > w.config.Key
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user