mirror of
https://github.com/tailscale/tailscale.git
synced 2025-09-24 23:21:02 +02:00
control/controlclient: switch ID to be incrementing instead of random (#17230)
Also cleans up a a few comments. Updates #15160 Signed-off-by: Claus Lensbøl <claus@tailscale.com>
This commit is contained in:
parent
1b5201023f
commit
f67ad67c6f
@ -14,7 +14,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand/v2"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@ -221,6 +220,8 @@ type NetmapDeltaUpdater interface {
|
|||||||
UpdateNetmapDelta([]netmap.NodeMutation) (ok bool)
|
UpdateNetmapDelta([]netmap.NodeMutation) (ok bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nextControlClientID atomic.Int64
|
||||||
|
|
||||||
// NewDirect returns a new Direct client.
|
// NewDirect returns a new Direct client.
|
||||||
func NewDirect(opts Options) (*Direct, error) {
|
func NewDirect(opts Options) (*Direct, error) {
|
||||||
if opts.ServerURL == "" {
|
if opts.ServerURL == "" {
|
||||||
@ -314,7 +315,7 @@ func NewDirect(opts Options) (*Direct, error) {
|
|||||||
}
|
}
|
||||||
c.closedCtx, c.closeCtx = context.WithCancel(context.Background())
|
c.closedCtx, c.closeCtx = context.WithCancel(context.Background())
|
||||||
|
|
||||||
c.controlClientID = rand.Int64()
|
c.controlClientID = nextControlClientID.Add(1)
|
||||||
|
|
||||||
if opts.Hostinfo == nil {
|
if opts.Hostinfo == nil {
|
||||||
c.SetHostinfo(hostinfo.New())
|
c.SetHostinfo(hostinfo.New())
|
||||||
@ -835,21 +836,21 @@ func (c *Direct) SendUpdate(ctx context.Context) error {
|
|||||||
return c.sendMapRequest(ctx, false, nil)
|
return c.sendMapRequest(ctx, false, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientID returns the ControlClientID of the controlClient
|
// ClientID returns the controlClientID of the controlClient.
|
||||||
func (c *Direct) ClientID() int64 {
|
func (c *Direct) ClientID() int64 {
|
||||||
return c.controlClientID
|
return c.controlClientID
|
||||||
}
|
}
|
||||||
|
|
||||||
// AutoUpdate wraps a bool for naming on the eventbus
|
// AutoUpdate is an eventbus value, reporting the value of tailcfg.MapResponse.DefaultAutoUpdate.
|
||||||
type AutoUpdate struct {
|
type AutoUpdate struct {
|
||||||
ClientID int64 // The ID field is used for consumers to differentiate instances of Direct
|
ClientID int64 // The ID field is used for consumers to differentiate instances of Direct.
|
||||||
Value bool
|
Value bool // The Value represents DefaultAutoUpdate from [tailcfg.MapResponse].
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControlTime wraps a [time.Time] for naming on the eventbus
|
// ControlTime is an eventbus value, reporting the value of tailcfg.MapResponse.ControlTime.
|
||||||
type ControlTime struct {
|
type ControlTime struct {
|
||||||
ClientID int64 // The ID field is used for consumers to differentiate instances of Direct
|
ClientID int64 // The ID field is used for consumers to differentiate instances of Direct.
|
||||||
Value time.Time
|
Value time.Time // The Value represents ControlTime from [tailcfg.MapResponse].
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we go more than watchdogTimeout without hearing from the server,
|
// If we go more than watchdogTimeout without hearing from the server,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user