Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: stop spamming DERP map updates for equivalent maps#11792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intomainfromspike/fix-derp-spam
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletioncoderd/workspaceagents.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -904,7 +904,7 @@ func (api *API) _dialWorkspaceAgentTailnet(agentID uuid.UUID) (*codersdk.Workspa
}

derpMap := api.DERPMap()
if lastDERPMap == nil || tailnet.CompareDERPMaps(lastDERPMap, derpMap) {
if lastDERPMap == nil ||!tailnet.CompareDERPMaps(lastDERPMap, derpMap) {
conn.SetDERPMap(derpMap)
lastDERPMap = derpMap
}
Expand Down
16 changes: 5 additions & 11 deletionstailnet/configmaps.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,7 +65,7 @@ type configMaps struct {
static netmap.NetworkMap
peers map[uuid.UUID]*peerLifecycle
addresses []netip.Prefix
derpMap *proto.DERPMap
derpMap *tailcfg.DERPMap
logger slog.Logger
blockEndpoints bool

Expand DownExpand Up@@ -204,7 +204,7 @@ func (c *configMaps) netMapLocked() *netmap.NetworkMap {
nm.Addresses = make([]netip.Prefix, len(c.addresses))
copy(nm.Addresses, c.addresses)

nm.DERPMap =DERPMapFromProto(c.derpMap)
nm.DERPMap = c.derpMap.Clone()
nm.Peers = c.peerConfigLocked()
nm.SelfNode.Addresses = nm.Addresses
nm.SelfNode.AllowedIPs = nm.Addresses
Expand DownExpand Up@@ -255,15 +255,10 @@ func (c *configMaps) setBlockEndpoints(blockEndpoints bool) {

// setDERPMap sets the DERP map, triggering a configuration of the engine if it has changed.
// c.L MUST NOT be held.
func (c *configMaps) setDERPMap(derpMap *proto.DERPMap) {
func (c *configMaps) setDERPMap(derpMap *tailcfg.DERPMap) {
c.L.Lock()
defer c.L.Unlock()
eq, err := c.derpMap.Equal(derpMap)
if err != nil {
c.logger.Critical(context.Background(), "failed to compare DERP maps", slog.Error(err))
return
}
if eq {
if CompareDERPMaps(c.derpMap, derpMap) {
return
}
c.derpMap = derpMap
Expand All@@ -273,8 +268,7 @@ func (c *configMaps) setDERPMap(derpMap *proto.DERPMap) {

// derMapLocked returns the current DERPMap. c.L must be held
func (c *configMaps) derpMapLocked() *tailcfg.DERPMap {
m := DERPMapFromProto(c.derpMap)
return m
return c.derpMap.Clone()
}

// reconfig computes the correct wireguard config and calls the engine.Reconfig
Expand Down
48 changes: 38 additions & 10 deletionstailnet/configmaps_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,12 +674,12 @@ func TestConfigMaps_setDERPMap_different(t *testing.T) {
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

derpMap := &proto.DERPMap{
HomeParams: &proto.DERPMap_HomeParams{RegionScore: map[int64]float64{1: 0.025}},
Regions: map[int64]*proto.DERPMap_Region{
derpMap := &tailcfg.DERPMap{
HomeParams: &tailcfg.DERPHomeParams{RegionScore: map[int]float64{1: 0.025}},
Regions: map[int]*tailcfg.DERPRegion{
1: {
RegionCode: "AUH",
Nodes: []*proto.DERPMap_Region_Node{
Nodes: []*tailcfg.DERPNode{
{Name: "AUH0"},
},
},
Expand DownExpand Up@@ -716,15 +716,24 @@ func TestConfigMaps_setDERPMap_same(t *testing.T) {
defer uut.close()

// Given: DERP Map already set
derpMap := &proto.DERPMap{
HomeParams: &proto.DERPMap_HomeParams{RegionScore: map[int64]float64{1: 0.025}},
Regions: map[int64]*proto.DERPMap_Region{
derpMap := &tailcfg.DERPMap{
HomeParams: &tailcfg.DERPHomeParams{RegionScore: map[int]float64{
1: 0.025,
1001: 0.111,
}},
Regions: map[int]*tailcfg.DERPRegion{
1: {
RegionCode: "AUH",
Nodes: []*proto.DERPMap_Region_Node{
Nodes: []*tailcfg.DERPNode{
{Name: "AUH0"},
},
},
1001: {
RegionCode: "DXB",
Nodes: []*tailcfg.DERPNode{
{Name: "DXB0"},
},
},
},
}
uut.L.Lock()
Expand All@@ -734,8 +743,27 @@ func TestConfigMaps_setDERPMap_same(t *testing.T) {
// Then: we don't configure
requireNeverConfigures(ctx, t, &uut.phased)

// When we set the same DERP map
uut.setDERPMap(derpMap)
// When we set the equivalent DERP map, with different ordering
uut.setDERPMap(&tailcfg.DERPMap{
HomeParams: &tailcfg.DERPHomeParams{RegionScore: map[int]float64{
1001: 0.111,
1: 0.025,
}},
Regions: map[int]*tailcfg.DERPRegion{
1001: {
RegionCode: "DXB",
Nodes: []*tailcfg.DERPNode{
{Name: "DXB0"},
},
},
1: {
RegionCode: "AUH",
Nodes: []*tailcfg.DERPNode{
{Name: "AUH0"},
},
},
},
})

done := make(chan struct{})
go func() {
Expand Down
4 changes: 2 additions & 2 deletionstailnet/conn.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -218,7 +218,7 @@ func NewConn(options *Options) (conn *Conn, err error) {
magicConn.DiscoPublicKey(),
)
cfgMaps.setAddresses(options.Addresses)
cfgMaps.setDERPMap(DERPMapToProto(options.DERPMap))
cfgMaps.setDERPMap(options.DERPMap)
cfgMaps.setBlockEndpoints(options.BlockEndpoints)

nodeUp := newNodeUpdater(
Expand DownExpand Up@@ -326,7 +326,7 @@ func (c *Conn) SetNodeCallback(callback func(node *Node)) {

// SetDERPMap updates the DERPMap of a connection.
func (c *Conn) SetDERPMap(derpMap *tailcfg.DERPMap) {
c.configMaps.setDERPMap(DERPMapToProto(derpMap))
c.configMaps.setDERPMap(derpMap)
}

func (c *Conn) SetDERPForceWebSockets(v bool) {
Expand Down
12 changes: 0 additions & 12 deletionstailnet/proto/compare.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,15 +18,3 @@ func (s *Node) Equal(o *Node) (bool, error) {
}
return bytes.Equal(sBytes, oBytes), nil
}

func (s *DERPMap) Equal(o *DERPMap) (bool, error) {
sBytes, err := gProto.Marshal(s)
if err != nil {
return false, err
}
oBytes, err := gProto.Marshal(o)
if err != nil {
return false, err
}
return bytes.Equal(sBytes, oBytes), nil
}

[8]ページ先頭

©2009-2025 Movatter.jp