derp, wgengine: let clients advertise an opaque app name to DERP servers
Add an AppName field to the DERP ClientInfo so DERP servers can attribute connections to the application making them, primarily for best effort stats purposes. The value is plumbed per engine instance rather than via a process global, so a process hosting multiple stacks can attribute each one's DERP connections separately: wgengine.Config.DERPAppName flows through magicsock.Options and derphttp.Client into the naclbox-sealed ClientInfo JSON. Old servers ignore the unknown field. There are no callers in the tree yet setting the name. Updates tailscale/corp#24454 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: Ia7d3e9c2b6f8140e5a9d7c3b2e6f1a8d4c0b5e9f
This commit is contained in:
committed by
Brad Fitzpatrick
parent
37e175a032
commit
246c82a658
@@ -414,6 +414,7 @@ func (c *Conn) derpWriteChanForRegion(regionID int, peer key.NodePublic) chan de
|
||||
return derpMap.Regions[regionID]
|
||||
})
|
||||
dc.HealthTracker = c.health
|
||||
dc.AppName = c.derpAppName
|
||||
if c.extraRootCAs != nil {
|
||||
dc.TLSConfig = &tls.Config{RootCAs: c.extraRootCAs}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ type Conn struct {
|
||||
health *health.Tracker // or nil
|
||||
extraRootCAs *x509.CertPool // additional trusted root CAs; or nil
|
||||
controlKnobs *controlknobs.Knobs // or nil
|
||||
derpAppName string // or empty, see Options.DERPAppName
|
||||
|
||||
// ================================================================
|
||||
// No locking required to access these fields, either because
|
||||
@@ -489,6 +490,10 @@ type Options struct {
|
||||
// for TLS connections to DERP servers.
|
||||
ExtraRootCAs *x509.CertPool
|
||||
|
||||
// DERPAppName, if non-empty, is an opaque app name string to
|
||||
// advertise to DERP servers for stats purposes.
|
||||
DERPAppName string
|
||||
|
||||
// Metrics specifies the metrics registry to record metrics to.
|
||||
Metrics *usermetric.Registry
|
||||
|
||||
@@ -705,6 +710,7 @@ func NewConn(opts Options) (*Conn, error) {
|
||||
c.netMon = opts.NetMon
|
||||
c.health = opts.HealthTracker
|
||||
c.extraRootCAs = opts.ExtraRootCAs
|
||||
c.derpAppName = opts.DERPAppName
|
||||
c.getPeerByKey = opts.PeerByKeyFunc
|
||||
|
||||
if err := c.rebind(keepCurrentPort); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user