net/netmon: remove usage of direct callbacks from netmon (#17292)

The callback itself is not removed as it is used in other repos, making
it simpler for those to slowly transition to the eventbus.

Updates #15160

Signed-off-by: Claus Lensbøl <claus@tailscale.com>
This commit is contained in:
Claus Lensbøl
2025-10-01 14:59:38 -04:00
committed by GitHub
parent 6f7ce5eb5d
commit ce752b8a88
28 changed files with 217 additions and 48 deletions

View File

@@ -104,14 +104,10 @@ func runMonitor(ctx context.Context, loop bool) error {
}
defer mon.Close()
mon.RegisterChangeCallback(func(delta *netmon.ChangeDelta) {
if !delta.Major {
log.Printf("Network monitor fired; not a major change")
return
}
log.Printf("Network monitor fired. New state:")
dump(delta.New)
})
eventClient := b.Client("debug.runMonitor")
m := eventClient.Monitor(changeDeltaWatcher(eventClient, ctx, dump))
defer m.Close()
if loop {
log.Printf("Starting link change monitor; initial state:")
}
@@ -124,6 +120,27 @@ func runMonitor(ctx context.Context, loop bool) error {
select {}
}
func changeDeltaWatcher(ec *eventbus.Client, ctx context.Context, dump func(st *netmon.State)) func(*eventbus.Client) {
changeSub := eventbus.Subscribe[netmon.ChangeDelta](ec)
return func(ec *eventbus.Client) {
for {
select {
case <-ctx.Done():
return
case <-ec.Done():
return
case delta := <-changeSub.Events():
if !delta.Major {
log.Printf("Network monitor fired; not a major change")
return
}
log.Printf("Network monitor fired. New state:")
dump(delta.New)
}
}
}
}
func getURL(ctx context.Context, urlStr string) error {
if urlStr == "login" {
urlStr = "https://login.tailscale.com"