platform: Add tailscale device name and logout

This commit is contained in:
世界
2026-06-02 11:29:06 +08:00
parent dbf960deff
commit f0ca4dca1b
15 changed files with 299 additions and 121 deletions
+18 -1
View File
@@ -121,6 +121,7 @@ type Endpoint struct {
systemInterface bool
systemInterfaceName string
systemInterfaceMTU uint32
keyAuth bool
serverStarted bool
started atomic.Bool
systemTun tun.Tun
@@ -133,7 +134,11 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
if stateDirectory == "" {
stateDirectory = "tailscale"
}
platformInterface := service.FromContext[adapter.PlatformInterface](ctx)
hostname := options.Hostname
if hostname == "" && platformInterface != nil {
hostname = platformInterface.TailscaleHostname()
}
if hostname == "" {
osHostname, _ := os.Hostname()
osHostname = strings.TrimSpace(osHostname)
@@ -189,7 +194,7 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
dnsRouter: dnsRouter,
queryOptions: dialerQueryOptions,
network: service.FromContext[adapter.NetworkManager](ctx),
platformInterface: service.FromContext[adapter.PlatformInterface](ctx),
platformInterface: platformInterface,
server: &tsnet.Server{
Dir: stateDirectory,
Hostname: hostname,
@@ -235,6 +240,7 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
systemInterface: options.SystemInterface,
systemInterfaceName: options.SystemInterfaceName,
systemInterfaceMTU: options.SystemInterfaceMTU,
keyAuth: options.AuthKey != "",
}, nil
}
@@ -563,6 +569,17 @@ func (t *Endpoint) SetTailscaleExitNode(ctx context.Context, stableID string) er
return nil
}
func (t *Endpoint) Logout(ctx context.Context) error {
if !t.started.Load() {
return E.New("Tailscale is not ready yet")
}
err := common.Must1(t.server.LocalClient()).Logout(ctx)
if err != nil {
return E.Cause(err, "tailscale logout")
}
return nil
}
func (t *Endpoint) Close() error {
var err error
t.started.Store(false)