mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-05 15:55:49 +00:00
all: construct new System values with an event bus pre-populated
Although, at the moment, we do not yet require an event bus to be present, as we start to add more pieces we will want to ensure it is always available. Add a new constructor and replace existing uses of new(tsd.System) throughout. Update generated files for import changes. Updates #15160 Change-Id: Ie5460985571ade87b8eac8b416948c7f49f0f64b Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
parent
9c181d3c88
commit
3219e27dff
@ -937,7 +937,7 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
|
|||||||
💣 tailscale.com/util/deephash from tailscale.com/ipn/ipnlocal+
|
💣 tailscale.com/util/deephash from tailscale.com/ipn/ipnlocal+
|
||||||
L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+
|
L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+
|
||||||
tailscale.com/util/dnsname from tailscale.com/appc+
|
tailscale.com/util/dnsname from tailscale.com/appc+
|
||||||
tailscale.com/util/eventbus from tailscale.com/tsd
|
tailscale.com/util/eventbus from tailscale.com/tsd+
|
||||||
tailscale.com/util/execqueue from tailscale.com/appc+
|
tailscale.com/util/execqueue from tailscale.com/appc+
|
||||||
tailscale.com/util/goroutines from tailscale.com/ipn/ipnlocal
|
tailscale.com/util/goroutines from tailscale.com/ipn/ipnlocal
|
||||||
tailscale.com/util/groupmember from tailscale.com/client/web+
|
tailscale.com/util/groupmember from tailscale.com/client/web+
|
||||||
|
@ -387,7 +387,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
|||||||
💣 tailscale.com/util/deephash from tailscale.com/ipn/ipnlocal+
|
💣 tailscale.com/util/deephash from tailscale.com/ipn/ipnlocal+
|
||||||
L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+
|
L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+
|
||||||
tailscale.com/util/dnsname from tailscale.com/appc+
|
tailscale.com/util/dnsname from tailscale.com/appc+
|
||||||
tailscale.com/util/eventbus from tailscale.com/cmd/tailscaled+
|
tailscale.com/util/eventbus from tailscale.com/tsd+
|
||||||
tailscale.com/util/execqueue from tailscale.com/control/controlclient+
|
tailscale.com/util/execqueue from tailscale.com/control/controlclient+
|
||||||
tailscale.com/util/goroutines from tailscale.com/ipn/ipnlocal
|
tailscale.com/util/goroutines from tailscale.com/ipn/ipnlocal
|
||||||
tailscale.com/util/groupmember from tailscale.com/client/web+
|
tailscale.com/util/groupmember from tailscale.com/client/web+
|
||||||
|
@ -62,7 +62,6 @@ import (
|
|||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/types/logid"
|
"tailscale.com/types/logid"
|
||||||
"tailscale.com/util/clientmetric"
|
"tailscale.com/util/clientmetric"
|
||||||
"tailscale.com/util/eventbus"
|
|
||||||
"tailscale.com/util/multierr"
|
"tailscale.com/util/multierr"
|
||||||
"tailscale.com/util/osshare"
|
"tailscale.com/util/osshare"
|
||||||
"tailscale.com/version"
|
"tailscale.com/version"
|
||||||
@ -340,11 +339,9 @@ var debugMux *http.ServeMux
|
|||||||
func run() (err error) {
|
func run() (err error) {
|
||||||
var logf logger.Logf = log.Printf
|
var logf logger.Logf = log.Printf
|
||||||
|
|
||||||
sys := new(tsd.System)
|
|
||||||
|
|
||||||
// Install an event bus as early as possible, so that it's
|
// Install an event bus as early as possible, so that it's
|
||||||
// available universally when setting up everything else.
|
// available universally when setting up everything else.
|
||||||
sys.Set(eventbus.New())
|
sys := tsd.NewSystemWithEventBus()
|
||||||
|
|
||||||
// Parse config, if specified, to fail early if it's invalid.
|
// Parse config, if specified, to fail early if it's invalid.
|
||||||
var conf *conffile.Config
|
var conf *conffile.Config
|
||||||
@ -683,6 +680,7 @@ var tstunNew = tstun.New
|
|||||||
|
|
||||||
func tryEngine(logf logger.Logf, sys *tsd.System, name string) (onlyNetstack bool, err error) {
|
func tryEngine(logf logger.Logf, sys *tsd.System, name string) (onlyNetstack bool, err error) {
|
||||||
conf := wgengine.Config{
|
conf := wgengine.Config{
|
||||||
|
EventBus: sys.Bus.Get(),
|
||||||
ListenPort: args.port,
|
ListenPort: args.port,
|
||||||
NetMon: sys.NetMon.Get(),
|
NetMon: sys.NetMon.Get(),
|
||||||
HealthTracker: sys.HealthTracker(),
|
HealthTracker: sys.HealthTracker(),
|
||||||
|
@ -327,7 +327,7 @@ func beWindowsSubprocess() bool {
|
|||||||
log.Printf("Error pre-loading \"%s\": %v", fqWintunPath, err)
|
log.Printf("Error pre-loading \"%s\": %v", fqWintunPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
netMon, err := netmon.New(log.Printf)
|
netMon, err := netmon.New(log.Printf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not create netMon: %v", err)
|
log.Fatalf("Could not create netMon: %v", err)
|
||||||
|
@ -100,7 +100,7 @@ func newIPN(jsConfig js.Value) map[string]any {
|
|||||||
logtail := logtail.NewLogger(c, log.Printf)
|
logtail := logtail.NewLogger(c, log.Printf)
|
||||||
logf := logtail.Logf
|
logf := logtail.Logf
|
||||||
|
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
sys.Set(store)
|
sys.Set(store)
|
||||||
dialer := &tsdial.Dialer{Logf: logf}
|
dialer := &tsdial.Dialer{Logf: logf}
|
||||||
eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
|
eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
|
||||||
|
@ -436,7 +436,7 @@ func (panicOnUseTransport) RoundTrip(*http.Request) (*http.Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newTestLocalBackend(t testing.TB) *LocalBackend {
|
func newTestLocalBackend(t testing.TB) *LocalBackend {
|
||||||
return newTestLocalBackendWithSys(t, new(tsd.System))
|
return newTestLocalBackendWithSys(t, tsd.NewSystemWithEventBus())
|
||||||
}
|
}
|
||||||
|
|
||||||
// newTestLocalBackendWithSys creates a new LocalBackend with the given tsd.System.
|
// newTestLocalBackendWithSys creates a new LocalBackend with the given tsd.System.
|
||||||
@ -4411,7 +4411,7 @@ func newLocalBackendWithTestControl(t *testing.T, enableLogging bool, newControl
|
|||||||
if enableLogging {
|
if enableLogging {
|
||||||
logf = tstest.WhileTestRunningLogger(t)
|
logf = tstest.WhileTestRunningLogger(t)
|
||||||
}
|
}
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
store := new(mem.Store)
|
store := new(mem.Store)
|
||||||
sys.Set(store)
|
sys.Set(store)
|
||||||
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
||||||
@ -4859,9 +4859,8 @@ func TestConfigFileReload(t *testing.T) {
|
|||||||
// Create backend with initial config
|
// Create backend with initial config
|
||||||
tc.initial.Path = path
|
tc.initial.Path = path
|
||||||
tc.initial.Raw = initialJSON
|
tc.initial.Raw = initialJSON
|
||||||
sys := &tsd.System{
|
sys := tsd.NewSystemWithEventBus()
|
||||||
InitialConfig: tc.initial,
|
sys.InitialConfig = tc.initial
|
||||||
}
|
|
||||||
b := newTestLocalBackendWithSys(t, sys)
|
b := newTestLocalBackendWithSys(t, sys)
|
||||||
|
|
||||||
// Update config file
|
// Update config file
|
||||||
|
@ -47,7 +47,7 @@ func TestLocalLogLines(t *testing.T) {
|
|||||||
idA := logid(0xaa)
|
idA := logid(0xaa)
|
||||||
|
|
||||||
// set up a LocalBackend, super bare bones. No functional data.
|
// set up a LocalBackend, super bare bones. No functional data.
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
store := new(mem.Store)
|
store := new(mem.Store)
|
||||||
sys.Set(store)
|
sys.Set(store)
|
||||||
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
||||||
|
@ -877,7 +877,7 @@ func newTestBackend(t *testing.T) *LocalBackend {
|
|||||||
logf = logger.WithPrefix(tstest.WhileTestRunningLogger(t), "... ")
|
logf = logger.WithPrefix(tstest.WhileTestRunningLogger(t), "... ")
|
||||||
}
|
}
|
||||||
|
|
||||||
sys := &tsd.System{}
|
sys := tsd.NewSystemWithEventBus()
|
||||||
e, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
|
e, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
|
||||||
SetSubsystem: sys.Set,
|
SetSubsystem: sys.Set,
|
||||||
HealthTracker: sys.HealthTracker(),
|
HealthTracker: sys.HealthTracker(),
|
||||||
|
@ -295,7 +295,7 @@ func TestStateMachine(t *testing.T) {
|
|||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
|
|
||||||
logf := tstest.WhileTestRunningLogger(t)
|
logf := tstest.WhileTestRunningLogger(t)
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
store := new(testStateStorage)
|
store := new(testStateStorage)
|
||||||
sys.Set(store)
|
sys.Set(store)
|
||||||
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
||||||
@ -934,7 +934,7 @@ func TestStateMachine(t *testing.T) {
|
|||||||
|
|
||||||
func TestEditPrefsHasNoKeys(t *testing.T) {
|
func TestEditPrefsHasNoKeys(t *testing.T) {
|
||||||
logf := tstest.WhileTestRunningLogger(t)
|
logf := tstest.WhileTestRunningLogger(t)
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
sys.Set(new(mem.Store))
|
sys.Set(new(mem.Store))
|
||||||
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1014,7 +1014,7 @@ func TestWGEngineStatusRace(t *testing.T) {
|
|||||||
t.Skip("test fails")
|
t.Skip("test fails")
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
logf := tstest.WhileTestRunningLogger(t)
|
logf := tstest.WhileTestRunningLogger(t)
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
sys.Set(new(mem.Store))
|
sys.Set(new(mem.Store))
|
||||||
|
|
||||||
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set)
|
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set)
|
||||||
|
@ -517,7 +517,7 @@ type newControlClientFn func(tb testing.TB, opts controlclient.Options) controlc
|
|||||||
func newLocalBackendWithTestControl(tb testing.TB, newControl newControlClientFn, enableLogging bool) *ipnlocal.LocalBackend {
|
func newLocalBackendWithTestControl(tb testing.TB, newControl newControlClientFn, enableLogging bool) *ipnlocal.LocalBackend {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
sys := &tsd.System{}
|
sys := tsd.NewSystemWithEventBus()
|
||||||
store := &mem.Store{}
|
store := &mem.Store{}
|
||||||
sys.Set(store)
|
sys.Set(store)
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ func TestServeWatchIPNBus(t *testing.T) {
|
|||||||
|
|
||||||
func newTestLocalBackend(t testing.TB) *ipnlocal.LocalBackend {
|
func newTestLocalBackend(t testing.TB) *ipnlocal.LocalBackend {
|
||||||
var logf logger.Logf = logger.Discard
|
var logf logger.Logf = logger.Discard
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
store := new(mem.Store)
|
store := new(mem.Store)
|
||||||
sys.Set(store)
|
sys.Set(store)
|
||||||
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
||||||
|
@ -1037,7 +1037,7 @@ func TestSSHAuthFlow(t *testing.T) {
|
|||||||
|
|
||||||
func TestSSH(t *testing.T) {
|
func TestSSH(t *testing.T) {
|
||||||
var logf logger.Logf = t.Logf
|
var logf logger.Logf = t.Logf
|
||||||
sys := &tsd.System{}
|
sys := tsd.NewSystemWithEventBus()
|
||||||
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set, sys.HealthTracker(), sys.UserMetricsRegistry())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -76,6 +76,14 @@ type System struct {
|
|||||||
userMetricsRegistry usermetric.Registry
|
userMetricsRegistry usermetric.Registry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSystemWithEventBus constructs a new otherwise-empty system with a
|
||||||
|
// freshly-constructed event bus populated.
|
||||||
|
func NewSystemWithEventBus() *System {
|
||||||
|
sys := new(System)
|
||||||
|
sys.Set(eventbus.New())
|
||||||
|
return sys
|
||||||
|
}
|
||||||
|
|
||||||
// NetstackImpl is the interface that *netstack.Impl implements.
|
// NetstackImpl is the interface that *netstack.Impl implements.
|
||||||
// It's an interface for circular dependency reasons: netstack.Impl
|
// It's an interface for circular dependency reasons: netstack.Impl
|
||||||
// references LocalBackend, and LocalBackend has a tsd.System.
|
// references LocalBackend, and LocalBackend has a tsd.System.
|
||||||
|
@ -553,7 +553,7 @@ func (s *Server) start() (reterr error) {
|
|||||||
s.Logf(format, a...)
|
s.Logf(format, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
sys := new(tsd.System)
|
sys := tsd.NewSystemWithEventBus()
|
||||||
s.sys = sys
|
s.sys = sys
|
||||||
if err := s.startLogger(&closePool, sys.HealthTracker(), tsLogf); err != nil {
|
if err := s.startLogger(&closePool, sys.HealthTracker(), tsLogf); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -567,6 +567,7 @@ func (s *Server) start() (reterr error) {
|
|||||||
|
|
||||||
s.dialer = &tsdial.Dialer{Logf: tsLogf} // mutated below (before used)
|
s.dialer = &tsdial.Dialer{Logf: tsLogf} // mutated below (before used)
|
||||||
eng, err := wgengine.NewUserspaceEngine(tsLogf, wgengine.Config{
|
eng, err := wgengine.NewUserspaceEngine(tsLogf, wgengine.Config{
|
||||||
|
EventBus: sys.Bus.Get(),
|
||||||
ListenPort: s.Port,
|
ListenPort: s.Port,
|
||||||
NetMon: s.netMon,
|
NetMon: s.netMon,
|
||||||
Dialer: s.dialer,
|
Dialer: s.dialer,
|
||||||
|
@ -48,7 +48,6 @@ import (
|
|||||||
_ "tailscale.com/types/logger"
|
_ "tailscale.com/types/logger"
|
||||||
_ "tailscale.com/types/logid"
|
_ "tailscale.com/types/logid"
|
||||||
_ "tailscale.com/util/clientmetric"
|
_ "tailscale.com/util/clientmetric"
|
||||||
_ "tailscale.com/util/eventbus"
|
|
||||||
_ "tailscale.com/util/multierr"
|
_ "tailscale.com/util/multierr"
|
||||||
_ "tailscale.com/util/osshare"
|
_ "tailscale.com/util/osshare"
|
||||||
_ "tailscale.com/version"
|
_ "tailscale.com/version"
|
||||||
|
@ -48,7 +48,6 @@ import (
|
|||||||
_ "tailscale.com/types/logger"
|
_ "tailscale.com/types/logger"
|
||||||
_ "tailscale.com/types/logid"
|
_ "tailscale.com/types/logid"
|
||||||
_ "tailscale.com/util/clientmetric"
|
_ "tailscale.com/util/clientmetric"
|
||||||
_ "tailscale.com/util/eventbus"
|
|
||||||
_ "tailscale.com/util/multierr"
|
_ "tailscale.com/util/multierr"
|
||||||
_ "tailscale.com/util/osshare"
|
_ "tailscale.com/util/osshare"
|
||||||
_ "tailscale.com/version"
|
_ "tailscale.com/version"
|
||||||
|
@ -48,7 +48,6 @@ import (
|
|||||||
_ "tailscale.com/types/logger"
|
_ "tailscale.com/types/logger"
|
||||||
_ "tailscale.com/types/logid"
|
_ "tailscale.com/types/logid"
|
||||||
_ "tailscale.com/util/clientmetric"
|
_ "tailscale.com/util/clientmetric"
|
||||||
_ "tailscale.com/util/eventbus"
|
|
||||||
_ "tailscale.com/util/multierr"
|
_ "tailscale.com/util/multierr"
|
||||||
_ "tailscale.com/util/osshare"
|
_ "tailscale.com/util/osshare"
|
||||||
_ "tailscale.com/version"
|
_ "tailscale.com/version"
|
||||||
|
@ -48,7 +48,6 @@ import (
|
|||||||
_ "tailscale.com/types/logger"
|
_ "tailscale.com/types/logger"
|
||||||
_ "tailscale.com/types/logid"
|
_ "tailscale.com/types/logid"
|
||||||
_ "tailscale.com/util/clientmetric"
|
_ "tailscale.com/util/clientmetric"
|
||||||
_ "tailscale.com/util/eventbus"
|
|
||||||
_ "tailscale.com/util/multierr"
|
_ "tailscale.com/util/multierr"
|
||||||
_ "tailscale.com/util/osshare"
|
_ "tailscale.com/util/osshare"
|
||||||
_ "tailscale.com/version"
|
_ "tailscale.com/version"
|
||||||
|
@ -56,7 +56,6 @@ import (
|
|||||||
_ "tailscale.com/types/logger"
|
_ "tailscale.com/types/logger"
|
||||||
_ "tailscale.com/types/logid"
|
_ "tailscale.com/types/logid"
|
||||||
_ "tailscale.com/util/clientmetric"
|
_ "tailscale.com/util/clientmetric"
|
||||||
_ "tailscale.com/util/eventbus"
|
|
||||||
_ "tailscale.com/util/multierr"
|
_ "tailscale.com/util/multierr"
|
||||||
_ "tailscale.com/util/osdiag"
|
_ "tailscale.com/util/osdiag"
|
||||||
_ "tailscale.com/util/osshare"
|
_ "tailscale.com/util/osshare"
|
||||||
|
@ -100,7 +100,7 @@ func getMemStats() (ms runtime.MemStats) {
|
|||||||
|
|
||||||
func makeNetstack(tb testing.TB, config func(*Impl)) *Impl {
|
func makeNetstack(tb testing.TB, config func(*Impl)) *Impl {
|
||||||
tunDev := tstun.NewFake()
|
tunDev := tstun.NewFake()
|
||||||
sys := &tsd.System{}
|
sys := tsd.NewSystemWithEventBus()
|
||||||
sys.Set(new(mem.Store))
|
sys.Set(new(mem.Store))
|
||||||
dialer := new(tsdial.Dialer)
|
dialer := new(tsdial.Dialer)
|
||||||
logf := tstest.WhileTestRunningLogger(tb)
|
logf := tstest.WhileTestRunningLogger(tb)
|
||||||
|
@ -66,7 +66,7 @@ func TestIsNetstackRouter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
sys := &tsd.System{}
|
sys := tsd.NewSystemWithEventBus()
|
||||||
if tt.setNetstackRouter {
|
if tt.setNetstackRouter {
|
||||||
sys.NetstackRouter.Set(true)
|
sys.NetstackRouter.Set(true)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user