@ -12,7 +12,6 @@ import (
"sync/atomic"
"sync/atomic"
"time"
"time"
"tailscale.com/health"
"tailscale.com/net/sockstats"
"tailscale.com/net/sockstats"
"tailscale.com/tailcfg"
"tailscale.com/tailcfg"
"tailscale.com/tstime"
"tailscale.com/tstime"
@ -23,7 +22,6 @@ import (
"tailscale.com/types/structs"
"tailscale.com/types/structs"
"tailscale.com/util/backoff"
"tailscale.com/util/backoff"
"tailscale.com/util/clientmetric"
"tailscale.com/util/clientmetric"
"tailscale.com/util/eventbus"
"tailscale.com/util/execqueue"
"tailscale.com/util/execqueue"
)
)
@ -123,8 +121,6 @@ type Auto struct {
observerQueue execqueue . ExecQueue
observerQueue execqueue . ExecQueue
shutdownFn func ( ) // to be called prior to shutdown or nil
shutdownFn func ( ) // to be called prior to shutdown or nil
eventSubs eventbus . Monitor
mu sync . Mutex // mutex guards the following fields
mu sync . Mutex // mutex guards the following fields
wantLoggedIn bool // whether the user wants to be logged in per last method call
wantLoggedIn bool // whether the user wants to be logged in per last method call
@ -195,10 +191,6 @@ func NewNoStart(opts Options) (_ *Auto, err error) {
shutdownFn : opts . Shutdown ,
shutdownFn : opts . Shutdown ,
}
}
// Set up eventbus client and subscriber
ec := opts . Bus . Client ( "controlClient.Auto" )
c . eventSubs = ec . Monitor ( c . consumeEventbusTopics ( ec ) )
c . authCtx , c . authCancel = context . WithCancel ( context . Background ( ) )
c . authCtx , c . authCancel = context . WithCancel ( context . Background ( ) )
c . authCtx = sockstats . WithSockStats ( c . authCtx , sockstats . LabelControlClientAuto , opts . Logf )
c . authCtx = sockstats . WithSockStats ( c . authCtx , sockstats . LabelControlClientAuto , opts . Logf )
@ -208,27 +200,6 @@ func NewNoStart(opts Options) (_ *Auto, err error) {
return c , nil
return c , nil
}
}
// consumeEventbusTopics consumes events from all relevant
// [eventbus.Subscriber]'s and passes them to their related handler. Events are
// always handled in the order they are received, i.e. the next event is not
// read until the previous event's handler has returned. It returns when the
// [eventbus.Client] is closed.
func ( c * Auto ) consumeEventbusTopics ( ec * eventbus . Client ) func ( * eventbus . Client ) {
healthChangeSub := eventbus . Subscribe [ health . Change ] ( ec )
return func ( cli * eventbus . Client ) {
for {
select {
case <- cli . Done ( ) :
return
case change := <- healthChangeSub . Events ( ) :
if change . WarnableChanged {
c . direct . ReportWarnableChange ( change . Warnable , change . UnhealthyState )
}
}
}
}
}
// SetPaused controls whether HTTP activity should be paused.
// SetPaused controls whether HTTP activity should be paused.
//
//
// The client can be paused and unpaused repeatedly, unlike Start and Shutdown, which can only be used once.
// The client can be paused and unpaused repeatedly, unlike Start and Shutdown, which can only be used once.
@ -782,8 +753,6 @@ func (c *Auto) UpdateEndpoints(endpoints []tailcfg.Endpoint) {
}
}
func ( c * Auto ) Shutdown ( ) {
func ( c * Auto ) Shutdown ( ) {
c . eventSubs . Close ( )
c . mu . Lock ( )
c . mu . Lock ( )
if c . closed {
if c . closed {
c . mu . Unlock ( )
c . mu . Unlock ( )