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
31 lines
950 B
Go
31 lines
950 B
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package derpserver
|
|
|
|
import (
|
|
"tailscale.com/derp"
|
|
"tailscale.com/types/key"
|
|
"tailscale.com/util/testenv"
|
|
)
|
|
|
|
// forTest is an unexported type to hide the test-only methods on
|
|
// [Server] from godoc.
|
|
type forTest struct{ s *Server }
|
|
|
|
// ForTest returns a handle to test-only methods on s. The resulting
|
|
// type is unexported to make it very obvious in godoc that this is
|
|
// not stable API. This method panics if called outside of tests,
|
|
// which also centralizes all must-be-in-tests validation.
|
|
func (s *Server) ForTest() forTest {
|
|
testenv.AssertInTest()
|
|
return forTest{s}
|
|
}
|
|
|
|
// SetOnClientInfo sets a func to be called with each connecting
|
|
// client's key and the ClientInfo it sent. It must be called before
|
|
// the server accepts any connections.
|
|
func (f forTest) SetOnClientInfo(fn func(key.NodePublic, derp.ClientInfo)) {
|
|
f.s.onClientInfoForTest = fn
|
|
}
|