mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-29 07:09:33 +00:00
appc,ipn/ipnlocal: add a required event bus to the AppConnector type (#17390)
Require the presence of the bus, but do not use it yet. Check for required fields and update tests and production use to plumb the necessary arguments. Updates #15160 Updates #17192 Change-Id: I8cefd2fdb314ca9945317d3320bd5ea6a92e8dcb Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"tailscale.com/types/views"
|
||||
"tailscale.com/util/clientmetric"
|
||||
"tailscale.com/util/dnsname"
|
||||
"tailscale.com/util/eventbus"
|
||||
"tailscale.com/util/execqueue"
|
||||
"tailscale.com/util/slicesx"
|
||||
)
|
||||
@@ -136,7 +137,9 @@ type RouteInfo struct {
|
||||
// routes not yet served by the AppConnector the local node configuration is
|
||||
// updated to advertise the new route.
|
||||
type AppConnector struct {
|
||||
// These fields are immutable after initialization.
|
||||
logf logger.Logf
|
||||
eventBus *eventbus.Bus
|
||||
routeAdvertiser RouteAdvertiser
|
||||
|
||||
// storeRoutesFunc will be called to persist routes if it is not nil.
|
||||
@@ -168,6 +171,10 @@ type Config struct {
|
||||
// It must be non-nil.
|
||||
Logf logger.Logf
|
||||
|
||||
// EventBus receives events when the collection of routes maintained by the
|
||||
// connector is updated. It must be non-nil.
|
||||
EventBus *eventbus.Bus
|
||||
|
||||
// RouteAdvertiser allows the connector to update the set of advertised routes.
|
||||
// It must be non-nil.
|
||||
RouteAdvertiser RouteAdvertiser
|
||||
@@ -183,8 +190,18 @@ type Config struct {
|
||||
|
||||
// NewAppConnector creates a new AppConnector.
|
||||
func NewAppConnector(c Config) *AppConnector {
|
||||
switch {
|
||||
case c.Logf == nil:
|
||||
panic("missing logger")
|
||||
case c.EventBus == nil:
|
||||
panic("missing event bus")
|
||||
case c.RouteAdvertiser == nil:
|
||||
panic("missing route advertiser")
|
||||
}
|
||||
|
||||
ac := &AppConnector{
|
||||
logf: logger.WithPrefix(c.Logf, "appc: "),
|
||||
eventBus: c.EventBus,
|
||||
routeAdvertiser: c.RouteAdvertiser,
|
||||
storeRoutesFunc: c.StoreRoutesFunc,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user