Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions tailnet/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type configMaps struct {
clock clock.Clock
}

func newConfigMaps(logger slog.Logger, engine engineConfigurable, nodeID tailcfg.NodeID, nodeKey key.NodePrivate, discoKey key.DiscoPublic, addresses []netip.Prefix) *configMaps {
func newConfigMaps(logger slog.Logger, engine engineConfigurable, nodeID tailcfg.NodeID, nodeKey key.NodePrivate, discoKey key.DiscoPublic) *configMaps {
pubKey := nodeKey.Public()
c := &configMaps{
phased: phased{Cond: *(sync.NewCond(&sync.Mutex{}))},
Expand Down Expand Up @@ -114,9 +114,8 @@ func newConfigMaps(logger slog.Logger, engine engineConfigurable, nodeID tailcfg
Caps: []filter.CapMatch{},
}},
},
peers: make(map[uuid.UUID]*peerLifecycle),
addresses: addresses,
clock: clock.New(),
peers: make(map[uuid.UUID]*peerLifecycle),
clock: clock.New(),
}
go c.configLoop()
return c
Expand Down
31 changes: 19 additions & 12 deletions tailnet/configmaps_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestConfigMaps_setAddresses_different(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

addrs := []netip.Prefix{netip.MustParsePrefix("192.168.0.200/32")}
Expand Down Expand Up @@ -93,11 +93,18 @@ func TestConfigMaps_setAddresses_same(t *testing.T) {
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
addrs := []netip.Prefix{netip.MustParsePrefix("192.168.0.200/32")}
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), addrs)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

// Given: addresses already set
uut.L.Lock()
uut.addresses = addrs
uut.L.Unlock()

// Then: it doesn't configure
requireNeverConfigures(ctx, t, &uut.phased)

// When: we set addresses
uut.setAddresses(addrs)

done := make(chan struct{})
Expand All @@ -116,7 +123,7 @@ func TestConfigMaps_updatePeers_new(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

p1ID := uuid.UUID{1}
Expand Down Expand Up @@ -186,7 +193,7 @@ func TestConfigMaps_updatePeers_same(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

// Then: we don't configure
Expand Down Expand Up @@ -245,7 +252,7 @@ func TestConfigMaps_updatePeers_disconnect(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

p1ID := uuid.UUID{1}
Expand Down Expand Up @@ -313,7 +320,7 @@ func TestConfigMaps_updatePeers_lost(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()
start := time.Date(2024, time.January, 1, 8, 0, 0, 0, time.UTC)
mClock := clock.NewMock()
Expand Down Expand Up @@ -406,7 +413,7 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()
start := time.Date(2024, time.January, 1, 8, 0, 0, 0, time.UTC)
mClock := clock.NewMock()
Expand Down Expand Up @@ -492,7 +499,7 @@ func TestConfigMaps_setBlockEndpoints_different(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

p1ID := uuid.MustParse("10000000-0000-0000-0000-000000000000")
Expand Down Expand Up @@ -536,7 +543,7 @@ func TestConfigMaps_setBlockEndpoints_same(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

p1ID := uuid.MustParse("10000000-0000-0000-0000-000000000000")
Expand Down Expand Up @@ -579,7 +586,7 @@ func TestConfigMaps_setDERPMap_different(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

derpMap := &proto.DERPMap{
Expand Down Expand Up @@ -620,7 +627,7 @@ func TestConfigMaps_setDERPMap_same(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

// Given: DERP Map already set
Expand Down Expand Up @@ -697,7 +704,7 @@ func TestConfigMaps_updatePeers_nonexist(t *testing.T) {
nodePrivateKey := key.NewNode()
nodeID := tailcfg.NodeID(5)
discoKey := key.NewDisco()
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), nil)
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public())
defer uut.close()

// Then: we don't configure
Expand Down