(ctx context.Context, loop bool)
| 99 | } |
| 100 | |
| 101 | func runMonitor(ctx context.Context, loop bool) error { |
| 102 | b := eventbus.New() |
| 103 | defer b.Close() |
| 104 | |
| 105 | dump := func(st *netmon.State) { |
| 106 | j, _ := json.MarshalIndent(st, "", " ") |
| 107 | os.Stderr.Write(j) |
| 108 | } |
| 109 | mon, err := netmon.New(b, log.Printf) |
| 110 | if err != nil { |
| 111 | return err |
| 112 | } |
| 113 | defer mon.Close() |
| 114 | |
| 115 | eventClient := b.Client("debug.runMonitor") |
| 116 | m := eventClient.Monitor(changeDeltaWatcher(eventClient, ctx, dump)) |
| 117 | defer m.Close() |
| 118 | |
| 119 | if loop { |
| 120 | log.Printf("Starting link change monitor; initial state:") |
| 121 | } |
| 122 | dump(mon.InterfaceState()) |
| 123 | if !loop { |
| 124 | return nil |
| 125 | } |
| 126 | mon.Start() |
| 127 | log.Printf("Started link change monitor; waiting...") |
| 128 | select {} |
| 129 | } |
| 130 | |
| 131 | func changeDeltaWatcher(ec *eventbus.Client, ctx context.Context, dump func(st *netmon.State)) func(*eventbus.Client) { |
| 132 | changeSub := eventbus.Subscribe[netmon.ChangeDelta](ec) |
no test coverage detected
searching dependent graphs…