mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 19:51:41 +00:00
ipn, ipn/ipnlocal: add session identifier for WatchIPNBus
This PR adds a SessionID field to the ipn.Notify struct so that ipn buses can identify a session and register deferred clean up code in the future. The first use case this is for is to be able to tie foreground serve configs to a specific watch session and ensure its clean up when a connection is closed. Updates #8489 Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
This commit is contained in:
parent
7175f06e62
commit
a4aa6507fa
@ -343,7 +343,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
|||||||
tailscale.com/util/osshare from tailscale.com/ipn/ipnlocal+
|
tailscale.com/util/osshare from tailscale.com/ipn/ipnlocal+
|
||||||
W tailscale.com/util/pidowner from tailscale.com/ipn/ipnauth
|
W tailscale.com/util/pidowner from tailscale.com/ipn/ipnauth
|
||||||
tailscale.com/util/racebuild from tailscale.com/logpolicy
|
tailscale.com/util/racebuild from tailscale.com/logpolicy
|
||||||
tailscale.com/util/rands from tailscale.com/ipn/localapi
|
tailscale.com/util/rands from tailscale.com/ipn/localapi+
|
||||||
tailscale.com/util/ringbuffer from tailscale.com/wgengine/magicsock
|
tailscale.com/util/ringbuffer from tailscale.com/wgengine/magicsock
|
||||||
tailscale.com/util/set from tailscale.com/health+
|
tailscale.com/util/set from tailscale.com/health+
|
||||||
tailscale.com/util/singleflight from tailscale.com/control/controlclient+
|
tailscale.com/util/singleflight from tailscale.com/control/controlclient+
|
||||||
|
@ -61,7 +61,7 @@ const (
|
|||||||
// each one via RequestEngineStatus.
|
// each one via RequestEngineStatus.
|
||||||
NotifyWatchEngineUpdates NotifyWatchOpt = 1 << iota
|
NotifyWatchEngineUpdates NotifyWatchOpt = 1 << iota
|
||||||
|
|
||||||
NotifyInitialState // if set, the first Notify message (sent immediately) will contain the current State + BrowseToURL
|
NotifyInitialState // if set, the first Notify message (sent immediately) will contain the current State + BrowseToURL + SessionID
|
||||||
NotifyInitialPrefs // if set, the first Notify message (sent immediately) will contain the current Prefs
|
NotifyInitialPrefs // if set, the first Notify message (sent immediately) will contain the current Prefs
|
||||||
NotifyInitialNetMap // if set, the first Notify message (sent immediately) will contain the current NetMap
|
NotifyInitialNetMap // if set, the first Notify message (sent immediately) will contain the current NetMap
|
||||||
|
|
||||||
@ -77,6 +77,12 @@ type Notify struct {
|
|||||||
_ structs.Incomparable
|
_ structs.Incomparable
|
||||||
Version string // version number of IPN backend
|
Version string // version number of IPN backend
|
||||||
|
|
||||||
|
// SessionID identifies the unique WatchIPNBus session.
|
||||||
|
// This field is only set in the first message when requesting
|
||||||
|
// NotifyInitialState. Clients must store it on their side as
|
||||||
|
// following notifications will not include this field.
|
||||||
|
SessionID string `json:",omitempty"`
|
||||||
|
|
||||||
// ErrMessage, if non-nil, contains a critical error message.
|
// ErrMessage, if non-nil, contains a critical error message.
|
||||||
// For State InUseOtherUser, ErrMessage is not critical and just contains the details.
|
// For State InUseOtherUser, ErrMessage is not critical and just contains the details.
|
||||||
ErrMessage *string
|
ErrMessage *string
|
||||||
|
@ -78,6 +78,7 @@ import (
|
|||||||
"tailscale.com/util/mak"
|
"tailscale.com/util/mak"
|
||||||
"tailscale.com/util/multierr"
|
"tailscale.com/util/multierr"
|
||||||
"tailscale.com/util/osshare"
|
"tailscale.com/util/osshare"
|
||||||
|
"tailscale.com/util/rands"
|
||||||
"tailscale.com/util/set"
|
"tailscale.com/util/set"
|
||||||
"tailscale.com/util/systemd"
|
"tailscale.com/util/systemd"
|
||||||
"tailscale.com/util/testenv"
|
"tailscale.com/util/testenv"
|
||||||
@ -1935,6 +1936,8 @@ func (b *LocalBackend) ResendHostinfoIfNeeded() {
|
|||||||
func (b *LocalBackend) WatchNotifications(ctx context.Context, mask ipn.NotifyWatchOpt, onWatchAdded func(), fn func(roNotify *ipn.Notify) (keepGoing bool)) {
|
func (b *LocalBackend) WatchNotifications(ctx context.Context, mask ipn.NotifyWatchOpt, onWatchAdded func(), fn func(roNotify *ipn.Notify) (keepGoing bool)) {
|
||||||
ch := make(chan *ipn.Notify, 128)
|
ch := make(chan *ipn.Notify, 128)
|
||||||
|
|
||||||
|
sessionID := rands.HexString(16)
|
||||||
|
|
||||||
origFn := fn
|
origFn := fn
|
||||||
if mask&ipn.NotifyNoPrivateKeys != 0 {
|
if mask&ipn.NotifyNoPrivateKeys != 0 {
|
||||||
fn = func(n *ipn.Notify) bool {
|
fn = func(n *ipn.Notify) bool {
|
||||||
@ -1956,10 +1959,12 @@ func (b *LocalBackend) WatchNotifications(ctx context.Context, mask ipn.NotifyWa
|
|||||||
var ini *ipn.Notify
|
var ini *ipn.Notify
|
||||||
|
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
|
|
||||||
const initialBits = ipn.NotifyInitialState | ipn.NotifyInitialPrefs | ipn.NotifyInitialNetMap
|
const initialBits = ipn.NotifyInitialState | ipn.NotifyInitialPrefs | ipn.NotifyInitialNetMap
|
||||||
if mask&initialBits != 0 {
|
if mask&initialBits != 0 {
|
||||||
ini = &ipn.Notify{Version: version.Long()}
|
ini = &ipn.Notify{Version: version.Long()}
|
||||||
if mask&ipn.NotifyInitialState != 0 {
|
if mask&ipn.NotifyInitialState != 0 {
|
||||||
|
ini.SessionID = sessionID
|
||||||
ini.State = ptr.To(b.state)
|
ini.State = ptr.To(b.state)
|
||||||
if b.state == ipn.NeedsLogin {
|
if b.state == ipn.NeedsLogin {
|
||||||
ini.BrowseToURL = ptr.To(b.authURLSticky)
|
ini.BrowseToURL = ptr.To(b.authURLSticky)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user