From d47c8c71f1fb58210f43c9f920f2e63f1ed49b4b Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Wed, 7 Oct 2026 10:52:42 -0500 Subject: [PATCH] lighthouse: Send an update when the relays we advertise change on reload (#1916) --- lighthouse.go | 10 ++++++++++ lighthouse_test.go | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lighthouse.go b/lighthouse.go index 837a8df4..f3a6f737 100644 --- a/lighthouse.go +++ b/lighthouse.go @@ -360,6 +360,11 @@ func (lh *LightHouse) reload(c *config.C, initial bool) error { } if initial || c.HasChanged("relay.relays") { + var before []netip.Addr + if !initial { + before = lh.GetRelaysForMe() + } + switch c.GetBool("relay.am_relay", false) { case true: // Relays aren't allowed to specify other relays @@ -384,6 +389,11 @@ func (lh *LightHouse) reload(c *config.C, initial bool) error { } lh.relaysForMe.Store(&relaysForMe) } + + // Tell the lighthouses now rather than at the next interval, but only when what we advertise changed + if !initial && !slices.Equal(before, lh.GetRelaysForMe()) { + lh.TriggerUpdate() + } } return nil diff --git a/lighthouse_test.go b/lighthouse_test.go index bb588429..fab44cb9 100644 --- a/lighthouse_test.go +++ b/lighthouse_test.go @@ -955,3 +955,24 @@ func TestLighthouse_PunchNotificationDoesNotCloseLockCycle(t *testing.T) { t.Fatal("deadlock: the lighthouse paths never finished after stop was signalled") } } + +func TestLighthouse_reloadRelaysTriggersUpdate(t *testing.T) { + l := test.NewLogger() + c := config.NewC(l) + base := "lighthouse:\n am_lighthouse: true\nlisten:\n port: 4242\n" + require.NoError(t, c.LoadString(base+"relay:\n relays: [10.128.0.5]\n")) + + lh, err := NewLightHouseFromConfig(t.Context(), l, c, testCertState(netip.MustParsePrefix("10.128.0.1/24")), nil, nil) + require.NoError(t, err) + assert.Empty(t, lh.updateTrigger) + + require.NoError(t, c.ReloadConfigString(base+"relay:\n relays: [10.128.0.6]\n")) + assert.Equal(t, []netip.Addr{netip.MustParseAddr("10.128.0.6")}, lh.GetRelaysForMe()) + require.Len(t, lh.updateTrigger, 1) + <-lh.updateTrigger + + // The config changed but what we advertise did not, a bad entry is skipped + require.NoError(t, c.ReloadConfigString(base+"relay:\n relays: [10.128.0.6, nope]\n")) + assert.Equal(t, []netip.Addr{netip.MustParseAddr("10.128.0.6")}, lh.GetRelaysForMe()) + assert.Empty(t, lh.updateTrigger) +}