wgengine/monitor: change API to permit multiple independent callbakcks

Currently it assumes exactly 1 registered callback. This changes it to
support 0, 1, or more than 1.

This is a step towards plumbing wgengine/monitor into more places (and
moving some of wgengine's interface state fetching into monitor in a
later step)

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-02-27 19:33:21 -08:00
parent 0eea490724
commit dda03a911e
3 changed files with 41 additions and 14 deletions

View File

@ -256,14 +256,16 @@ func newUserspaceEngineAdvanced(conf EngineConfig) (_ Engine, reterr error) {
e.linkState, _ = getLinkState()
logf("link state: %+v", e.linkState)
mon, err := monitor.New(logf, func() {
e.LinkChange(false)
tshttpproxy.InvalidateCache()
})
mon, err := monitor.New(logf)
if err != nil {
return nil, err
}
closePool.add(mon)
unregisterMonWatch := mon.RegisterChangeCallback(func() {
e.LinkChange(false)
tshttpproxy.InvalidateCache()
})
closePool.addFunc(unregisterMonWatch)
e.linkMon = mon
endpointsFn := func(endpoints []string) {