mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-21 20:51:50 +01:00
[management] Send relay credentials with turn updates (#3164)
send relay credentials when sending turn credentials update to avoid removing servers from clients
This commit is contained in:
parent
409003b4f9
commit
649bfb236b
@ -13,13 +13,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/util"
|
|
||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
|
|
||||||
|
"github.com/netbirdio/netbird/management/server/util"
|
||||||
|
|
||||||
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
|
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
|
||||||
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
|
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
|
||||||
networkTypes "github.com/netbirdio/netbird/management/server/networks/types"
|
networkTypes "github.com/netbirdio/netbird/management/server/networks/types"
|
||||||
@ -937,7 +938,7 @@ func BenchmarkUpdateAccountPeers(b *testing.B) {
|
|||||||
{"Small single", 50, 10, 90, 120, 90, 120},
|
{"Small single", 50, 10, 90, 120, 90, 120},
|
||||||
{"Medium single", 500, 10, 110, 170, 120, 200},
|
{"Medium single", 500, 10, 110, 170, 120, 200},
|
||||||
{"Large 5", 5000, 15, 1300, 2100, 4900, 7000},
|
{"Large 5", 5000, 15, 1300, 2100, 4900, 7000},
|
||||||
{"Extra Large", 2000, 2000, 1300, 2400, 4000, 6400},
|
{"Extra Large", 2000, 2000, 1300, 2400, 3900, 6400},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.SetOutput(io.Discard)
|
log.SetOutput(io.Discard)
|
||||||
|
@ -158,7 +158,7 @@ func (m *TimeBasedAuthSecretsManager) refreshTURNTokens(ctx context.Context, pee
|
|||||||
log.WithContext(ctx).Debugf("stopping TURN refresh for %s", peerID)
|
log.WithContext(ctx).Debugf("stopping TURN refresh for %s", peerID)
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
m.pushNewTURNTokens(ctx, peerID)
|
m.pushNewTURNAndRelayTokens(ctx, peerID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ func (m *TimeBasedAuthSecretsManager) refreshRelayTokens(ctx context.Context, pe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TimeBasedAuthSecretsManager) pushNewTURNTokens(ctx context.Context, peerID string) {
|
func (m *TimeBasedAuthSecretsManager) pushNewTURNAndRelayTokens(ctx context.Context, peerID string) {
|
||||||
turnToken, err := m.turnHmacToken.GenerateToken(sha1.New)
|
turnToken, err := m.turnHmacToken.GenerateToken(sha1.New)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to generate token for peer '%s': %s", peerID, err)
|
log.Errorf("failed to generate token for peer '%s': %s", peerID, err)
|
||||||
@ -201,10 +201,21 @@ func (m *TimeBasedAuthSecretsManager) pushNewTURNTokens(ctx context.Context, pee
|
|||||||
update := &proto.SyncResponse{
|
update := &proto.SyncResponse{
|
||||||
WiretrusteeConfig: &proto.WiretrusteeConfig{
|
WiretrusteeConfig: &proto.WiretrusteeConfig{
|
||||||
Turns: turns,
|
Turns: turns,
|
||||||
// omit Relay to avoid updates there
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// workaround for the case when client is unable to handle turn and relay updates at different time
|
||||||
|
if m.relayCfg != nil {
|
||||||
|
token, err := m.GenerateRelayToken()
|
||||||
|
if err == nil {
|
||||||
|
update.WiretrusteeConfig.Relay = &proto.RelayConfig{
|
||||||
|
Urls: m.relayCfg.Addresses,
|
||||||
|
TokenPayload: token.Payload,
|
||||||
|
TokenSignature: token.Signature,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.WithContext(ctx).Debugf("sending new TURN credentials to peer %s", peerID)
|
log.WithContext(ctx).Debugf("sending new TURN credentials to peer %s", peerID)
|
||||||
m.updateManager.SendUpdate(ctx, peerID, &UpdateMessage{Update: update})
|
m.updateManager.SendUpdate(ctx, peerID, &UpdateMessage{Update: update})
|
||||||
}
|
}
|
||||||
|
@ -133,11 +133,14 @@ loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if relay := update.Update.GetWiretrusteeConfig().GetRelay(); relay != nil {
|
if relay := update.Update.GetWiretrusteeConfig().GetRelay(); relay != nil {
|
||||||
relayUpdates++
|
// avoid updating on turn updates since they also send relay credentials
|
||||||
if relayUpdates == 1 {
|
if update.Update.GetWiretrusteeConfig().GetTurns() == nil {
|
||||||
firstRelayUpdate = relay
|
relayUpdates++
|
||||||
} else {
|
if relayUpdates == 1 {
|
||||||
secondRelayUpdate = relay
|
firstRelayUpdate = relay
|
||||||
|
} else {
|
||||||
|
secondRelayUpdate = relay
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user