wgengine: remove SetNetInfoCallback method from Engine

LocalBackend can talk to magicsock on its own to do this without
the "Engine" being involved.

(Continuing a little side quest of cleaning up the Engine
interface...)

Updates #cleanup

Change-Id: I8654acdca2b883b1bd557fdc0cfb90cd3a418a62
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/9375/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent ad4c11aca1
commit 727b1432a8

@ -1552,7 +1552,11 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
} }
cc.SetTKAHead(tkaHead) cc.SetTKAHead(tkaHead)
b.e.SetNetInfoCallback(b.setNetInfo) if mc, err := b.magicConn(); err != nil {
return fmt.Errorf("looking up magicsock: %w", err)
} else {
mc.SetNetInfoCallback(b.setNetInfo)
}
blid := b.backendLogID.String() blid := b.backendLogID.String()
b.logf("Backend: logs: be:%v fe:%v", blid, opts.FrontendLogID) b.logf("Backend: logs: be:%v fe:%v", blid, opts.FrontendLogID)

@ -657,7 +657,7 @@ func (c *Conn) updateNetInfo(ctx context.Context) (*netcheck.Report, error) {
return report, nil return report, nil
} }
// callNetInfoCallback calls the NetInfo callback (if previously // callNetInfoCallback calls the callback (if previously
// registered with SetNetInfoCallback) if ni has substantially changed // registered with SetNetInfoCallback) if ni has substantially changed
// since the last state. // since the last state.
// //
@ -691,6 +691,13 @@ func (c *Conn) addValidDiscoPathForTest(nodeKey key.NodePublic, addr netip.AddrP
c.peerMap.setNodeKeyForIPPort(addr, nodeKey) c.peerMap.setNodeKeyForIPPort(addr, nodeKey)
} }
// SetNetInfoCallback sets the func to be called whenever the network conditions
// change.
//
// At most one func can be registered; the most recent one replaces any previous
// registration.
//
// This is called by LocalBackend.
func (c *Conn) SetNetInfoCallback(fn func(*tailcfg.NetInfo)) { func (c *Conn) SetNetInfoCallback(fn func(*tailcfg.NetInfo)) {
if fn == nil { if fn == nil {
panic("nil NetInfoCallback") panic("nil NetInfoCallback")

@ -1157,10 +1157,6 @@ func (e *userspaceEngine) linkChange(delta *netmon.ChangeDelta) {
e.magicConn.ReSTUN(why) e.magicConn.ReSTUN(why)
} }
func (e *userspaceEngine) SetNetInfoCallback(cb NetInfoCallback) {
e.magicConn.SetNetInfoCallback(cb)
}
func (e *userspaceEngine) SetDERPMap(dm *tailcfg.DERPMap) { func (e *userspaceEngine) SetDERPMap(dm *tailcfg.DERPMap) {
e.magicConn.SetDERPMap(dm) e.magicConn.SetDERPMap(dm)
} }

@ -134,9 +134,6 @@ func (e *watchdogEngine) SetStatusCallback(cb StatusCallback) {
func (e *watchdogEngine) UpdateStatus(sb *ipnstate.StatusBuilder) { func (e *watchdogEngine) UpdateStatus(sb *ipnstate.StatusBuilder) {
e.watchdog("UpdateStatus", func() { e.wrap.UpdateStatus(sb) }) e.watchdog("UpdateStatus", func() { e.wrap.UpdateStatus(sb) })
} }
func (e *watchdogEngine) SetNetInfoCallback(cb NetInfoCallback) {
e.watchdog("SetNetInfoCallback", func() { e.wrap.SetNetInfoCallback(cb) })
}
func (e *watchdogEngine) RequestStatus() { func (e *watchdogEngine) RequestStatus() {
e.watchdog("RequestStatus", func() { e.wrap.RequestStatus() }) e.watchdog("RequestStatus", func() { e.wrap.RequestStatus() })
} }

@ -35,9 +35,6 @@ type Status struct {
// Exactly one of Status or error is non-nil. // Exactly one of Status or error is non-nil.
type StatusCallback func(*Status, error) type StatusCallback func(*Status, error)
// NetInfoCallback is the type used by Engine.SetNetInfoCallback.
type NetInfoCallback func(*tailcfg.NetInfo)
// NetworkMapCallback is the type used by callbacks that hook // NetworkMapCallback is the type used by callbacks that hook
// into network map updates. // into network map updates.
type NetworkMapCallback func(*netmap.NetworkMap) type NetworkMapCallback func(*netmap.NetworkMap)
@ -125,10 +122,6 @@ type Engine interface {
// The network map should only be read from. // The network map should only be read from.
SetNetworkMap(*netmap.NetworkMap) SetNetworkMap(*netmap.NetworkMap)
// SetNetInfoCallback sets the function to call when a
// new NetInfo summary is available.
SetNetInfoCallback(NetInfoCallback)
// DiscoPublicKey gets the public key used for path discovery // DiscoPublicKey gets the public key used for path discovery
// messages. // messages.
DiscoPublicKey() key.DiscoPublic DiscoPublicKey() key.DiscoPublic

Loading…
Cancel
Save