Skip to content

Commit 8c8e6e1

Browse files
committed
chore: add support for blockEndpoints to configMaps
1 parent 2baf90f commit 8c8e6e1

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed

tailnet/configmaps.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ func (c *configMaps) netMapLocked() *netmap.NetworkMap {
217217
func (c *configMaps) peerConfigLocked() []*tailcfg.Node {
218218
out := make([]*tailcfg.Node, 0, len(c.peers))
219219
for _, p := range c.peers {
220-
out = append(out, p.node.Clone())
220+
n := p.node.Clone()
221+
if c.blockEndpoints {
222+
n.Endpoints = nil
223+
}
224+
out = append(out, n)
221225
}
222226
return out
223227
}
@@ -235,6 +239,17 @@ func (c *configMaps) setAddresses(ips []netip.Prefix) {
235239
c.Broadcast()
236240
}
237241

242+
// nolint: revive
243+
func (c *configMaps) setBlockEndpoints(blockEndpoints bool) {
244+
c.L.Lock()
245+
defer c.L.Unlock()
246+
if c.blockEndpoints != blockEndpoints {
247+
c.netmapDirty = true
248+
}
249+
c.blockEndpoints = blockEndpoints
250+
c.Broadcast()
251+
}
252+
238253
func (c *configMaps) derpMapLocked() *tailcfg.DERPMap {
239254
m := DERPMapFromProto(c.derpMap)
240255
return m
@@ -338,9 +353,6 @@ func (c *configMaps) updatePeerLocked(update *proto.CoordinateResponse_PeerUpdat
338353
// to avoid random hangs while we set up the connection again after
339354
// inactivity.
340355
node.KeepAlive = ok && peerStatus.Active
341-
if c.blockEndpoints {
342-
node.Endpoints = nil
343-
}
344356
}
345357
switch {
346358
case !ok && update.Kind == proto.CoordinateResponse_PeerUpdate_NODE:

tailnet/configmaps_internal_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,93 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) {
473473
_ = testutil.RequireRecvCtx(ctx, t, done)
474474
}
475475

476+
func TestConfigMaps_setBlockEndpoints_different(t *testing.T) {
477+
t.Parallel()
478+
ctx := testutil.Context(t, testutil.WaitShort)
479+
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
480+
fEng := newFakeEngineConfigurable()
481+
nodePrivateKey := key.NewNode()
482+
nodeID := tailcfg.NodeID(5)
483+
discoKey := key.NewDisco()
484+
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
485+
defer uut.close()
486+
487+
p1ID := uuid.MustParse("10000000-0000-0000-0000-000000000000")
488+
p1Node := newTestNode(1)
489+
p1n, err := NodeToProto(p1Node)
490+
require.NoError(t, err)
491+
p1tcn, err := uut.protoNodeToTailcfg(p1n)
492+
p1tcn.KeepAlive = true
493+
require.NoError(t, err)
494+
495+
// Given: peer already exists
496+
uut.L.Lock()
497+
uut.peers[p1ID] = &peerLifecycle{
498+
peerID: p1ID,
499+
node: p1tcn,
500+
lastHandshake: time.Date(2024, 1, 7, 12, 0, 10, 0, time.UTC),
501+
}
502+
uut.L.Unlock()
503+
504+
uut.setBlockEndpoints(true)
505+
506+
nm := testutil.RequireRecvCtx(ctx, t, fEng.setNetworkMap)
507+
r := testutil.RequireRecvCtx(ctx, t, fEng.reconfig)
508+
require.Len(t, nm.Peers, 1)
509+
require.Len(t, nm.Peers[0].Endpoints, 0)
510+
require.Len(t, r.wg.Peers, 1)
511+
512+
done := make(chan struct{})
513+
go func() {
514+
defer close(done)
515+
uut.close()
516+
}()
517+
_ = testutil.RequireRecvCtx(ctx, t, done)
518+
}
519+
520+
func TestConfigMaps_setBlockEndpoints_same(t *testing.T) {
521+
t.Parallel()
522+
ctx := testutil.Context(t, testutil.WaitShort)
523+
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
524+
fEng := newFakeEngineConfigurable()
525+
nodePrivateKey := key.NewNode()
526+
nodeID := tailcfg.NodeID(5)
527+
discoKey := key.NewDisco()
528+
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
529+
defer uut.close()
530+
531+
p1ID := uuid.MustParse("10000000-0000-0000-0000-000000000000")
532+
p1Node := newTestNode(1)
533+
p1n, err := NodeToProto(p1Node)
534+
require.NoError(t, err)
535+
p1tcn, err := uut.protoNodeToTailcfg(p1n)
536+
p1tcn.KeepAlive = true
537+
require.NoError(t, err)
538+
539+
// Given: peer already exists && blockEndpoints set to true
540+
uut.L.Lock()
541+
uut.peers[p1ID] = &peerLifecycle{
542+
peerID: p1ID,
543+
node: p1tcn,
544+
lastHandshake: time.Date(2024, 1, 7, 12, 0, 10, 0, time.UTC),
545+
}
546+
uut.blockEndpoints = true
547+
uut.L.Unlock()
548+
549+
// Then: we don't configure
550+
requireNeverConfigures(ctx, t, uut)
551+
552+
// When we set blockEndpoints to true
553+
uut.setBlockEndpoints(true)
554+
555+
done := make(chan struct{})
556+
go func() {
557+
defer close(done)
558+
uut.close()
559+
}()
560+
_ = testutil.RequireRecvCtx(ctx, t, done)
561+
}
562+
476563
func expectStatusWithHandshake(
477564
ctx context.Context, t testing.TB, fEng *fakeEngineConfigurable, k key.NodePublic, lastHandshake time.Time,
478565
) <-chan struct{} {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy