mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-14 06:57:31 +00:00
ipn/{ipnext,ipnlocal}: add a SafeBackend interface
Updates #12614 Change-Id: I197e673666e86ea74c19e3935ed71aec269b6c94 Co-authored-by: Nick Khyl <nickk@tailscale.com> Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
25c4dc5fd7
commit
3d8533b5d0
@@ -20,7 +20,6 @@ import (
|
||||
"tailscale.com/ipn/ipnlocal"
|
||||
"tailscale.com/net/udprelay"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/tsd"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/ptr"
|
||||
@@ -40,7 +39,7 @@ func init() {
|
||||
// newExtension is an [ipnext.NewExtensionFn] that creates a new relay server
|
||||
// extension. It is registered with [ipnext.RegisterExtension] if the package is
|
||||
// imported.
|
||||
func newExtension(logf logger.Logf, _ *tsd.System) (ipnext.Extension, error) {
|
||||
func newExtension(logf logger.Logf, _ ipnext.SafeBackend) (ipnext.Extension, error) {
|
||||
return &extension{logf: logger.WithPrefix(logf, featureName+": ")}, nil
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"tailscale.com/ipn/ipnext"
|
||||
"tailscale.com/ipn/ipnlocal"
|
||||
"tailscale.com/taildrop"
|
||||
"tailscale.com/tsd"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
@@ -15,7 +14,7 @@ func init() {
|
||||
ipnext.RegisterExtension("taildrop", newExtension)
|
||||
}
|
||||
|
||||
func newExtension(logf logger.Logf, _ *tsd.System) (ipnext.Extension, error) {
|
||||
func newExtension(logf logger.Logf, b ipnext.SafeBackend) (ipnext.Extension, error) {
|
||||
return &extension{
|
||||
logf: logger.WithPrefix(logf, "taildrop: "),
|
||||
}, nil
|
||||
@@ -23,7 +22,7 @@ func newExtension(logf logger.Logf, _ *tsd.System) (ipnext.Extension, error) {
|
||||
|
||||
type extension struct {
|
||||
logf logger.Logf
|
||||
lb *ipnlocal.LocalBackend
|
||||
sb ipnext.SafeBackend
|
||||
mgr *taildrop.Manager
|
||||
}
|
||||
|
||||
@@ -32,11 +31,6 @@ func (e *extension) Name() string {
|
||||
}
|
||||
|
||||
func (e *extension) Init(h ipnext.Host) error {
|
||||
type I interface {
|
||||
Backend() ipnlocal.Backend
|
||||
}
|
||||
e.lb = h.(I).Backend().(*ipnlocal.LocalBackend)
|
||||
|
||||
// TODO(bradfitz): move init of taildrop.Manager from ipnlocal/peerapi.go to
|
||||
// here
|
||||
e.mgr = nil
|
||||
@@ -45,7 +39,11 @@ func (e *extension) Init(h ipnext.Host) error {
|
||||
}
|
||||
|
||||
func (e *extension) Shutdown() error {
|
||||
if mgr, err := e.lb.TaildropManager(); err == nil {
|
||||
lb, ok := e.sb.(*ipnlocal.LocalBackend)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if mgr, err := lb.TaildropManager(); err == nil {
|
||||
mgr.Shutdown()
|
||||
} else {
|
||||
e.logf("taildrop: failed to shutdown taildrop manager: %v", err)
|
||||
|
Reference in New Issue
Block a user