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

chore: add DERPForcedWebsocket to nodeUpdater#11567

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/10533-node-updater-derp-forced
Jan 17, 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
26 changes: 20 additions & 6 deletionstailnet/node.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,12 +86,13 @@ func newNodeUpdater(
id tailcfg.NodeID, np key.NodePublic, dp key.DiscoPublic,
) *nodeUpdater {
u := &nodeUpdater{
phased: phased{Cond: *(sync.NewCond(&sync.Mutex{}))},
logger: logger,
id: id,
key: np,
discoKey: dp,
callback: callback,
phased: phased{Cond: *(sync.NewCond(&sync.Mutex{}))},
logger: logger,
id: id,
key: np,
discoKey: dp,
derpForcedWebsockets: make(map[int]string),
callback: callback,
}
go u.updateLoop()
return u
Expand DownExpand Up@@ -132,3 +133,16 @@ func (u *nodeUpdater) setNetInfo(ni *tailcfg.NetInfo) {
u.Broadcast()
}
}

// setDERPForcedWebsocket handles callbacks from the magicConn about DERP regions that are forced to
// use websockets (instead of Upgrade: derp). This information is for debugging only.
func (u *nodeUpdater) setDERPForcedWebsocket(region int, reason string) {
u.L.Lock()
defer u.L.Unlock()
dirty := u.derpForcedWebsockets[region] != reason
u.derpForcedWebsockets[region] = reason
if dirty {
u.dirty = true
u.Broadcast()
}
}
79 changes: 77 additions & 2 deletionstailnet/node_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,12 +74,10 @@ func TestNodeUpdater_setNetInfo_same(t *testing.T) {
nodeKey := key.NewNode().Public()
discoKey := key.NewDisco().Public()
nodeCh := make(chan *Node)
goCh := make(chan struct{})
uut := newNodeUpdater(
logger,
func(n *Node) {
nodeCh <- n
<-goCh
},
id, nodeKey, discoKey,
)
Expand DownExpand Up@@ -108,3 +106,80 @@ func TestNodeUpdater_setNetInfo_same(t *testing.T) {
}()
_ = testutil.RequireRecvCtx(ctx, t, done)
}

func TestNodeUpdater_setDERPForcedWebsocket_different(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
id := tailcfg.NodeID(1)
nodeKey := key.NewNode().Public()
discoKey := key.NewDisco().Public()
nodeCh := make(chan *Node)
uut := newNodeUpdater(
logger,
func(n *Node) {
nodeCh <- n
},
id, nodeKey, discoKey,
)
defer uut.close()

// Given: preferred DERP is 1, so we'll send an update
uut.L.Lock()
uut.preferredDERP = 1
uut.L.Unlock()

// When: we set a new forced websocket reason
uut.setDERPForcedWebsocket(1, "test")

// Then: we receive an update with the reason set
node := testutil.RequireRecvCtx(ctx, t, nodeCh)
require.Equal(t, nodeKey, node.Key)
require.Equal(t, discoKey, node.DiscoKey)
require.True(t, maps.Equal(map[int]string{1: "test"}, node.DERPForcedWebsocket))

done := make(chan struct{})
go func() {
defer close(done)
uut.close()
}()
_ = testutil.RequireRecvCtx(ctx, t, done)
}

func TestNodeUpdater_setDERPForcedWebsocket_same(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
id := tailcfg.NodeID(1)
nodeKey := key.NewNode().Public()
discoKey := key.NewDisco().Public()
nodeCh := make(chan *Node)
uut := newNodeUpdater(
logger,
func(n *Node) {
nodeCh <- n
},
id, nodeKey, discoKey,
)
defer uut.close()

// Then: we don't configure
requireNeverConfigures(ctx, t, &uut.phased)

// Given: preferred DERP is 1, so we would send an update on change &&
// reason for region 1 is set to "test"
uut.L.Lock()
uut.preferredDERP = 1
uut.derpForcedWebsockets[1] = "test"
uut.L.Unlock()

// When: we set region 1 to "test
uut.setDERPForcedWebsocket(1, "test")

done := make(chan struct{})
go func() {
defer close(done)
uut.close()
}()
_ = testutil.RequireRecvCtx(ctx, t, done)
}

[8]ページ先頭

©2009-2025 Movatter.jp