mirror of
https://github.com/tailscale/tailscale.git
synced 2025-11-06 11:11:26 +01:00
ipn/ipnlocal: use eventbus.SubscribeFunc in expiryManager
Updates #15160 Updates #17487 Change-Id: I8721e3ac1af505630edca7c5cb50695b0aad832a Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
parent
241ea1c98b
commit
109cb50d5f
@ -43,7 +43,7 @@ type expiryManager struct {
|
|||||||
logf logger.Logf
|
logf logger.Logf
|
||||||
clock tstime.Clock
|
clock tstime.Clock
|
||||||
|
|
||||||
eventSubs eventbus.Monitor
|
eventClient *eventbus.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func newExpiryManager(logf logger.Logf, bus *eventbus.Bus) *expiryManager {
|
func newExpiryManager(logf logger.Logf, bus *eventbus.Bus) *expiryManager {
|
||||||
@ -53,30 +53,13 @@ func newExpiryManager(logf logger.Logf, bus *eventbus.Bus) *expiryManager {
|
|||||||
clock: tstime.StdClock{},
|
clock: tstime.StdClock{},
|
||||||
}
|
}
|
||||||
|
|
||||||
cli := bus.Client("ipnlocal.expiryManager")
|
em.eventClient = bus.Client("ipnlocal.expiryManager")
|
||||||
em.eventSubs = cli.Monitor(em.consumeEventbusTopics(cli))
|
eventbus.SubscribeFunc(em.eventClient, func(ct controlclient.ControlTime) {
|
||||||
|
em.onControlTime(ct.Value)
|
||||||
|
})
|
||||||
return em
|
return em
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (em *expiryManager) consumeEventbusTopics(cli *eventbus.Client) func(*eventbus.Client) {
|
|
||||||
controlTimeSub := eventbus.Subscribe[controlclient.ControlTime](cli)
|
|
||||||
return func(cli *eventbus.Client) {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-cli.Done():
|
|
||||||
return
|
|
||||||
case time := <-controlTimeSub.Events():
|
|
||||||
em.onControlTime(time.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// onControlTime is called whenever we receive a new timestamp from the control
|
// onControlTime is called whenever we receive a new timestamp from the control
|
||||||
// server to store the delta.
|
// server to store the delta.
|
||||||
func (em *expiryManager) onControlTime(t time.Time) {
|
func (em *expiryManager) onControlTime(t time.Time) {
|
||||||
@ -245,7 +228,7 @@ func (em *expiryManager) nextPeerExpiry(nm *netmap.NetworkMap, localNow time.Tim
|
|||||||
return nextExpiry
|
return nextExpiry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em *expiryManager) close() { em.eventSubs.Close() }
|
func (em *expiryManager) close() { em.eventClient.Close() }
|
||||||
|
|
||||||
// ControlNow estimates the current time on the control server, calculated as
|
// ControlNow estimates the current time on the control server, calculated as
|
||||||
// localNow + the delta between local and control server clocks as recorded
|
// localNow + the delta between local and control server clocks as recorded
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user