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 support for blockEndpoints to configMaps#11512

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-blockEndpoints
Jan 11, 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
22 changes: 18 additions & 4 deletionstailnet/configmaps.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -207,7 +207,11 @@ func (c *configMaps) netMapLocked() *netmap.NetworkMap {
func (c*configMaps)peerConfigLocked() []*tailcfg.Node {
out:=make([]*tailcfg.Node,0,len(c.peers))
for_,p:=rangec.peers {
out=append(out,p.node.Clone())
n:=p.node.Clone()
ifc.blockEndpoints {
n.Endpoints=nil
}
out=append(out,n)
}
returnout
}
Expand All@@ -228,6 +232,19 @@ func (c *configMaps) setAddresses(ips []netip.Prefix) {
c.Broadcast()
}

// setBlockEndpoints sets whether we should block configuring endpoints we learn
// from peers. It triggers a configuration of the engine if the value changes.
// nolint: revive
func (c*configMaps)setBlockEndpoints(blockEndpointsbool) {
c.L.Lock()
deferc.L.Unlock()
ifc.blockEndpoints!=blockEndpoints {
c.netmapDirty=true
}
c.blockEndpoints=blockEndpoints
c.Broadcast()
}

// derMapLocked returns the current DERPMap. c.L must be held
func (c*configMaps)derpMapLocked()*tailcfg.DERPMap {
m:=DERPMapFromProto(c.derpMap)
Expand DownExpand Up@@ -342,9 +359,6 @@ func (c *configMaps) updatePeerLocked(update *proto.CoordinateResponse_PeerUpdat
// to avoid random hangs while we set up the connection again after
// inactivity.
node.KeepAlive=ok&&peerStatus.Active
ifc.blockEndpoints {
node.Endpoints=nil
}
}
switch {
case!ok&&update.Kind==proto.CoordinateResponse_PeerUpdate_NODE:
Expand Down
87 changes: 87 additions & 0 deletionstailnet/configmaps_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -484,6 +484,93 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) {
_=testutil.RequireRecvCtx(ctx,t,done)
}

funcTestConfigMaps_setBlockEndpoints_different(t*testing.T) {
t.Parallel()
ctx:=testutil.Context(t,testutil.WaitShort)
logger:=slogtest.Make(t,nil).Leveled(slog.LevelDebug)
fEng:=newFakeEngineConfigurable()
nodePrivateKey:=key.NewNode()
nodeID:=tailcfg.NodeID(5)
discoKey:=key.NewDisco()
uut:=newConfigMaps(logger,fEng,nodeID,nodePrivateKey,discoKey.Public(),nil)
deferuut.close()

p1ID:=uuid.MustParse("10000000-0000-0000-0000-000000000000")
p1Node:=newTestNode(1)
p1n,err:=NodeToProto(p1Node)
require.NoError(t,err)
p1tcn,err:=uut.protoNodeToTailcfg(p1n)
p1tcn.KeepAlive=true
require.NoError(t,err)

// Given: peer already exists
uut.L.Lock()
uut.peers[p1ID]=&peerLifecycle{
peerID:p1ID,
node:p1tcn,
lastHandshake:time.Date(2024,1,7,12,0,10,0,time.UTC),
}
uut.L.Unlock()

uut.setBlockEndpoints(true)

nm:=testutil.RequireRecvCtx(ctx,t,fEng.setNetworkMap)
r:=testutil.RequireRecvCtx(ctx,t,fEng.reconfig)
require.Len(t,nm.Peers,1)
require.Len(t,nm.Peers[0].Endpoints,0)
require.Len(t,r.wg.Peers,1)

done:=make(chanstruct{})
gofunc() {
deferclose(done)
uut.close()
}()
_=testutil.RequireRecvCtx(ctx,t,done)
}

funcTestConfigMaps_setBlockEndpoints_same(t*testing.T) {
t.Parallel()
ctx:=testutil.Context(t,testutil.WaitShort)
logger:=slogtest.Make(t,nil).Leveled(slog.LevelDebug)
fEng:=newFakeEngineConfigurable()
nodePrivateKey:=key.NewNode()
nodeID:=tailcfg.NodeID(5)
discoKey:=key.NewDisco()
uut:=newConfigMaps(logger,fEng,nodeID,nodePrivateKey,discoKey.Public(),nil)
deferuut.close()

p1ID:=uuid.MustParse("10000000-0000-0000-0000-000000000000")
p1Node:=newTestNode(1)
p1n,err:=NodeToProto(p1Node)
require.NoError(t,err)
p1tcn,err:=uut.protoNodeToTailcfg(p1n)
p1tcn.KeepAlive=true
require.NoError(t,err)

// Given: peer already exists && blockEndpoints set to true
uut.L.Lock()
uut.peers[p1ID]=&peerLifecycle{
peerID:p1ID,
node:p1tcn,
lastHandshake:time.Date(2024,1,7,12,0,10,0,time.UTC),
}
uut.blockEndpoints=true
uut.L.Unlock()

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

// When we set blockEndpoints to true
uut.setBlockEndpoints(true)

done:=make(chanstruct{})
gofunc() {
deferclose(done)
uut.close()
}()
_=testutil.RequireRecvCtx(ctx,t,done)
}

funcexpectStatusWithHandshake(
ctx context.Context,t testing.TB,fEng*fakeEngineConfigurable,k key.NodePublic,lastHandshake time.Time,
)<-chanstruct{} {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp