tailcfg: add MapRequest.ReadOnly and OmitPeers; remove DebugForceDisco

DebugForceDisco was a development & safety knob during the the transition
to discovery. It's no longer needed.

Add MapRequest.ReadOnly to prevent clients needing to do two
peer-spamming MapRequest at start-up.

This only adds the field, not the use of the field. (The control server
needs to support it first.)

Updates tailscale/corp#557

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2020-09-17 11:28:09 -07:00 committed by Brad Fitzpatrick
parent c41947903a
commit 904a91038a
2 changed files with 32 additions and 30 deletions

View File

@ -493,16 +493,15 @@ func (c *Direct) PollNetMap(ctx context.Context, maxPolls int, cb func(*NetworkM
} }
request := tailcfg.MapRequest{ request := tailcfg.MapRequest{
Version: 4, Version: 4,
IncludeIPv6: true, IncludeIPv6: true,
DeltaPeers: true, DeltaPeers: true,
KeepAlive: c.keepAlive, KeepAlive: c.keepAlive,
NodeKey: tailcfg.NodeKey(persist.PrivateNodeKey.Public()), NodeKey: tailcfg.NodeKey(persist.PrivateNodeKey.Public()),
DiscoKey: c.discoPubKey, DiscoKey: c.discoPubKey,
Endpoints: ep, Endpoints: ep,
Stream: allowStream, Stream: allowStream,
Hostinfo: hostinfo, Hostinfo: hostinfo,
DebugForceDisco: Debug.ForceDisco,
} }
if c.newDecompressor != nil { if c.newDecompressor != nil {
request.Compress = "zstd" request.Compress = "zstd"
@ -843,25 +842,20 @@ func wgIPToNetaddr(ips []wgcfg.IP) (ret []netaddr.IP) {
var Debug = initDebug() var Debug = initDebug()
type debug struct { type debug struct {
NetMap bool NetMap bool
ProxyDNS bool ProxyDNS bool
OnlyDisco bool OnlyDisco bool
Disco bool Disco bool
ForceDisco bool // ask control server to not filter out our disco key
} }
func initDebug() debug { func initDebug() debug {
d := debug{ use := os.Getenv("TS_DEBUG_USE_DISCO")
NetMap: envBool("TS_DEBUG_NETMAP"), return debug{
ProxyDNS: envBool("TS_DEBUG_PROXY_DNS"), NetMap: envBool("TS_DEBUG_NETMAP"),
OnlyDisco: os.Getenv("TS_DEBUG_USE_DISCO") == "only", ProxyDNS: envBool("TS_DEBUG_PROXY_DNS"),
ForceDisco: os.Getenv("TS_DEBUG_USE_DISCO") == "only" || envBool("TS_DEBUG_USE_DISCO"), OnlyDisco: use == "only",
Disco: use == "only" || use == "" || envBool("TS_DEBUG_USE_DISCO"),
} }
if d.ForceDisco || os.Getenv("TS_DEBUG_USE_DISCO") == "" {
// This is now defaults to on.
d.Disco = true
}
return d
} }
func envBool(k string) bool { func envBool(k string) bool {

View File

@ -452,11 +452,19 @@ type MapRequest struct {
Stream bool // if true, multiple MapResponse objects are returned Stream bool // if true, multiple MapResponse objects are returned
Hostinfo *Hostinfo Hostinfo *Hostinfo
// DebugForceDisco is a temporary flag during the deployment // ReadOnly is whether the client just wants to fetch the
// of magicsock active discovery. It says that that the client // MapResponse, without updating their Endpoints. The
// has environment variables explicitly turning discovery on, // Endpoints field will be ignored and LastSeen will not be
// so control should not disable it. // updated and peers will not be notified of changes.
DebugForceDisco bool `json:"debugForceDisco,omitempty"` //
// The intended use if for clients to discover the DERP map at
// start-up before their first real endpoint update.
ReadOnly bool `json:",omitempty"`
// OmitPeers is whether the client is okay with the Peers list
// being omitted in the response. (For example, a client on
// start up using ReadOnly to get the DERP map.)
OmitPeers bool `json:",omitempty"`
} }
// PortRange represents a range of UDP or TCP port numbers. // PortRange represents a range of UDP or TCP port numbers.