mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-28 16:01:34 +01:00
Fix relay mode evaulation
This commit is contained in:
parent
deb8203f06
commit
5b86a7f3f2
@ -212,7 +212,7 @@ func NewEngineWithProbes(
|
||||
clientCtx: clientCtx,
|
||||
clientCancel: clientCancel,
|
||||
signal: signalClient,
|
||||
signaler: NewSignaler(signalClient, config.WgPrivateKey),
|
||||
signaler: peer.NewSignaler(signalClient, config.WgPrivateKey),
|
||||
mgmClient: mgmClient,
|
||||
relayManager: relayManager,
|
||||
peerConns: make(map[string]*peer.Conn),
|
||||
|
@ -152,7 +152,7 @@ func (conn *Conn) Open() {
|
||||
log.Warnf("error while updating the state of peer %s,err: %v", conn.config.Key, err)
|
||||
}
|
||||
*/
|
||||
relayIsSupportedLocally := conn.connectorRelay.RelayIsSupported()
|
||||
relayIsSupportedLocally := conn.connectorRelay.RelayIsSupportedLocally()
|
||||
if relayIsSupportedLocally {
|
||||
go conn.connectorRelay.SetupRelayConnection()
|
||||
}
|
||||
|
@ -97,16 +97,7 @@ func NewConnectorICE(ctx context.Context, log *log.Entry, config ConnConfig, con
|
||||
// If the relay mode is supported then try to connect in p2p way only.
|
||||
// It is trying to reconnection in a loop until the context is canceled.
|
||||
// In case of success connection it will call the onICEConnReady callback.
|
||||
func (conn *ConnectorICE) SetupICEConnection(relayMode bool) {
|
||||
var preferredCandidateTypes []ice.CandidateType
|
||||
if relayMode {
|
||||
conn.connPriority = connPriorityICEP2P
|
||||
preferredCandidateTypes = candidateTypesP2P()
|
||||
} else {
|
||||
conn.connPriority = connPriorityICETurn
|
||||
preferredCandidateTypes = candidateTypes()
|
||||
}
|
||||
|
||||
func (conn *ConnectorICE) SetupICEConnection(hasRelayOnLocally bool) {
|
||||
for {
|
||||
if !conn.waitForReconnectTry() {
|
||||
return
|
||||
@ -120,6 +111,15 @@ func (conn *ConnectorICE) SetupICEConnection(relayMode bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
var preferredCandidateTypes []ice.CandidateType
|
||||
if hasRelayOnLocally && remoteOfferAnswer.RelaySrvAddress != "" {
|
||||
conn.connPriority = connPriorityICEP2P
|
||||
preferredCandidateTypes = candidateTypesP2P()
|
||||
} else {
|
||||
conn.connPriority = connPriorityICETurn
|
||||
preferredCandidateTypes = candidateTypes()
|
||||
}
|
||||
|
||||
ctx, ctxCancel := context.WithCancel(conn.ctx)
|
||||
agent, err := conn.reCreateAgent(ctxCancel, preferredCandidateTypes)
|
||||
if err != nil {
|
||||
|
@ -78,6 +78,8 @@ func (conn *ConnectorRelay) SetupRelayConnection() {
|
||||
rosenpassPubKey: remoteOfferAnswer.RosenpassPubKey,
|
||||
rosenpassAddr: remoteOfferAnswer.RosenpassAddr,
|
||||
})
|
||||
|
||||
// todo: waitForDisconnection()
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,8 +99,8 @@ func (conn *ConnectorRelay) preferredRelayServer(myRelayAddress, remoteRelayAddr
|
||||
return remoteRelayAddress
|
||||
}
|
||||
|
||||
func (conn *ConnectorRelay) RelayIsSupported() bool {
|
||||
return conn.relayManager.IsSupported()
|
||||
func (conn *ConnectorRelay) RelayIsSupportedLocally() bool {
|
||||
return conn.relayManager.HasRelayAddress()
|
||||
}
|
||||
|
||||
// waitForReconnectTry waits for a random duration before trying to reconnect
|
||||
|
@ -108,7 +108,7 @@ func (m *Manager) RelayAddress() (net.Addr, error) {
|
||||
return m.relayClient.RelayRemoteAddress()
|
||||
}
|
||||
|
||||
func (m *Manager) IsSupported() bool {
|
||||
func (m *Manager) HasRelayAddress() bool {
|
||||
return m.srvAddress != ""
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user