platform: Add tailscale device name and logout
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -17,7 +17,9 @@ func (t *Endpoint) SubscribeTailscaleStatus(ctx context.Context, fn func(*adapte
|
||||
localBackend := t.server.ExportLocalBackend()
|
||||
sendStatus := func() {
|
||||
status := localBackend.Status()
|
||||
fn(convertTailscaleStatus(status))
|
||||
result := convertTailscaleStatus(status)
|
||||
result.KeyAuth = t.keyAuth
|
||||
fn(result)
|
||||
}
|
||||
sendStatus()
|
||||
localBackend.WatchNotifications(ctx, ipn.NotifyInitialState|ipn.NotifyInitialNetMap|ipn.NotifyRateLimit, nil, func(roNotify *ipn.Notify) (keepGoing bool) {
|
||||
|
||||
Reference in New Issue
Block a user