mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-28 12:36:26 -08:00
lanscaping: remove ringbuffer package (magicsock endpoint debug)
-rwxr-xr-x@ 1 bradfitz staff 12473138 Jan 11 06:55 /Users/bradfitz/bin/tailscaled.min -rwxr-xr-x@ 1 bradfitz staff 12910744 Jan 11 06:56 /Users/bradfitz/bin/tailscaled.minlinux Change-Id: I2cc774294814e7711b40fd7ef1a9211b47606a2a Signed-off-by: Brad Fitzpatrick <[email protected]>
This commit is contained in:
1 parent
7d9bbf51cd
commit
d6f275fb65
5 files changed
-158
No files matched your search
@@ -144,7 +144,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
tailscale.com/util/nocasemaps from tailscale.com/types/ipproto
|
||||
tailscale.com/util/osuser from tailscale.com/ipn/ipnlocal+
|
||||
tailscale.com/util/rands from tailscale.com/ipn/ipnlocal+
|
||||
tailscale.com/util/ringbuffer from tailscale.com/wgengine/magicsock
|
||||
tailscale.com/util/set from tailscale.com/control/controlclient+
|
||||
tailscale.com/util/singleflight from tailscale.com/control/controlclient+
|
||||
tailscale.com/util/slicesx from tailscale.com/control/controlclient+
|
||||
|
||||
@@ -5845,23 +5845,6 @@ func (b *LocalBackend) ResetAuth() error {
|
||||
return b.resetForProfileChangeLockedOnEntry(unlock)
|
||||
}
|
||||
|
||||
func (b *LocalBackend) GetPeerEndpointChanges(ctx context.Context, ip netip.Addr) ([]magicsock.EndpointChange, error) {
|
||||
pip, ok := b.e.PeerForIP(ip)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no matching peer")
|
||||
}
|
||||
if pip.IsSelf {
|
||||
return nil, fmt.Errorf("%v is local Tailscale IP", ip)
|
||||
}
|
||||
peer := pip.Node
|
||||
|
||||
chs, err := b.MagicConn().GetEndpointChanges(peer)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting endpoint changes: %w", err)
|
||||
}
|
||||
return chs, nil
|
||||
}
|
||||
|
||||
var breakTCPConns func() error
|
||||
|
||||
func (b *LocalBackend) DebugBreakTCPConns() error {
|
||||
|
||||
@@ -70,7 +70,6 @@ var handler = map[string]localAPIHandler{
|
||||
"debug-log": (*Handler).serveDebugLog,
|
||||
"debug-packet-filter-matches": (*Handler).serveDebugPacketFilterMatches,
|
||||
"debug-packet-filter-rules": (*Handler).serveDebugPacketFilterRules,
|
||||
"debug-peer-endpoint-changes": (*Handler).serveDebugPeerEndpointChanges,
|
||||
"derpmap": (*Handler).serveDERPMap,
|
||||
"dev-set-state-store": (*Handler).serveDevSetStateStore,
|
||||
"dial": (*Handler).serveDial,
|
||||
@@ -862,34 +861,6 @@ func (h *Handler) serveStatus(w http.ResponseWriter, r *http.Request) {
|
||||
e.Encode(st)
|
||||
}
|
||||
|
||||
func (h *Handler) serveDebugPeerEndpointChanges(w http.ResponseWriter, r *http.Request) {
|
||||
if !h.PermitRead {
|
||||
http.Error(w, "status access denied", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
ipStr := r.FormValue("ip")
|
||||
if ipStr == "" {
|
||||
http.Error(w, "missing 'ip' parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
ip, err := netip.ParseAddr(ipStr)
|
||||
if err != nil {
|
||||
http.Error(w, "invalid IP", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
chs, err := h.b.GetPeerEndpointChanges(r.Context(), ip)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
e := json.NewEncoder(w)
|
||||
e.SetIndent("", "\t")
|
||||
e.Encode(chs)
|
||||
}
|
||||
|
||||
// InUseOtherUserIPNStream reports whether r is a request for the watch-ipn-bus
|
||||
// handler. If so, it writes an ipn.Notify InUseOtherUser message to the user
|
||||
// and returns true. Otherwise it returns false, in which case it doesn't write
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/ringbuffer"
|
||||
"tailscale.com/util/slicesx"
|
||||
)
|
||||
|
||||
@@ -59,7 +58,6 @@ type endpoint struct {
|
||||
lastRecvWG mono.Time // last time there were incoming packets from this peer destined for wireguard-go (e.g. not disco)
|
||||
lastRecvUDPAny mono.Time // last time there were incoming UDP packets from this peer of any kind
|
||||
numStopAndResetAtomic int64
|
||||
debugUpdates *ringbuffer.RingBuffer[EndpointChange]
|
||||
|
||||
// These fields are initialized once and never modified.
|
||||
c *Conn
|
||||
@@ -439,18 +437,8 @@ func (st *endpointState) addPongReplyLocked(r pongReply) {
|
||||
}
|
||||
|
||||
func (de *endpoint) deleteEndpointLocked(why string, ep netip.AddrPort) {
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "deleteEndpointLocked-" + why,
|
||||
From: ep,
|
||||
})
|
||||
delete(de.endpointState, ep)
|
||||
if de.bestAddr.AddrPort == ep {
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "deleteEndpointLocked-bestAddr-" + why,
|
||||
From: de.bestAddr,
|
||||
})
|
||||
de.setBestAddrLocked(addrQuality{})
|
||||
}
|
||||
}
|
||||
@@ -1345,30 +1333,15 @@ func (de *endpoint) updateFromNode(n tailcfg.NodeView, heartbeatDisabled bool, p
|
||||
key: n.DiscoKey(),
|
||||
short: n.DiscoKey().ShortString(),
|
||||
})
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "updateFromNode-resetLocked",
|
||||
})
|
||||
de.resetLocked()
|
||||
}
|
||||
if n.DERP() == "" {
|
||||
if de.derpAddr.IsValid() {
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "updateFromNode-remove-DERP",
|
||||
From: de.derpAddr,
|
||||
})
|
||||
}
|
||||
de.derpAddr = netip.AddrPort{}
|
||||
} else {
|
||||
newDerp, _ := netip.ParseAddrPort(n.DERP())
|
||||
if de.derpAddr != newDerp {
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "updateFromNode-DERP",
|
||||
From: de.derpAddr,
|
||||
To: newDerp,
|
||||
})
|
||||
}
|
||||
de.derpAddr = newDerp
|
||||
}
|
||||
@@ -1400,13 +1373,6 @@ func (de *endpoint) setEndpointsLocked(eps interface {
|
||||
newIpps = append(newIpps, ipp)
|
||||
}
|
||||
}
|
||||
if len(newIpps) > 0 {
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "updateFromNode-new-Endpoints",
|
||||
To: newIpps,
|
||||
})
|
||||
}
|
||||
|
||||
// Now delete anything unless it's still in the network map or
|
||||
// was a recently discovered endpoint.
|
||||
@@ -1603,21 +1569,9 @@ func (de *endpoint) handlePongConnLocked(m *disco.Pong, di *discoInfo, src netip
|
||||
thisPong := addrQuality{sp.to, latency, tstun.WireMTU(pingSizeToPktLen(sp.size, sp.to.Addr().Is6()))}
|
||||
if betterAddr(thisPong, de.bestAddr) {
|
||||
de.c.logf("magicsock: disco: node %v %v now using %v mtu=%v tx=%x", de.publicKey.ShortString(), de.discoShort(), sp.to, thisPong.wireMTU, m.TxID[:6])
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "handlePingLocked-bestAddr-update",
|
||||
From: de.bestAddr,
|
||||
To: thisPong,
|
||||
})
|
||||
de.setBestAddrLocked(thisPong)
|
||||
}
|
||||
if de.bestAddr.AddrPort == thisPong.AddrPort {
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "handlePingLocked-bestAddr-latency",
|
||||
From: de.bestAddr,
|
||||
To: thisPong,
|
||||
})
|
||||
de.bestAddr.latency = latency
|
||||
de.bestAddrAt = now
|
||||
de.trustBestAddrUntil = now.Add(trustUDPAddrDuration)
|
||||
@@ -1749,11 +1703,6 @@ func (de *endpoint) handleCallMeMaybe(m *disco.CallMeMaybe) {
|
||||
}
|
||||
}
|
||||
if len(newEPs) > 0 {
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "handleCallMeMaybe-new-endpoints",
|
||||
To: newEPs,
|
||||
})
|
||||
|
||||
de.c.dlogf("[v1] magicsock: disco: call-me-maybe from %v %v added new endpoints: %v",
|
||||
de.publicKey.ShortString(), de.discoShort(),
|
||||
@@ -1820,10 +1769,6 @@ func (de *endpoint) stopAndReset() {
|
||||
}
|
||||
}
|
||||
|
||||
de.debugUpdates.Add(EndpointChange{
|
||||
When: time.Now(),
|
||||
What: "stopAndReset-resetLocked",
|
||||
})
|
||||
de.resetLocked()
|
||||
if de.heartBeatTimer != nil {
|
||||
de.heartBeatTimer.Stop()
|
||||
|
||||
@@ -54,7 +54,6 @@ import (
|
||||
"tailscale.com/types/views"
|
||||
"tailscale.com/util/clientmetric"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/ringbuffer"
|
||||
"tailscale.com/util/set"
|
||||
"tailscale.com/util/testenv"
|
||||
"tailscale.com/util/uniq"
|
||||
@@ -951,25 +950,6 @@ func (c *Conn) populateCLIPingResponseLocked(res *ipnstate.PingResult, latency t
|
||||
res.DERPRegionCode = c.derpRegionCodeLocked(regionID)
|
||||
}
|
||||
|
||||
// GetEndpointChanges returns the most recent changes for a particular
|
||||
// endpoint. The returned EndpointChange structs are for debug use only and
|
||||
// there are no guarantees about order, size, or content.
|
||||
func (c *Conn) GetEndpointChanges(peer tailcfg.NodeView) ([]EndpointChange, error) {
|
||||
c.mu.Lock()
|
||||
if c.privateKey.IsZero() {
|
||||
c.mu.Unlock()
|
||||
return nil, fmt.Errorf("tailscaled stopped")
|
||||
}
|
||||
ep, ok := c.peerMap.endpointForNodeKey(peer.Key())
|
||||
c.mu.Unlock()
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown peer")
|
||||
}
|
||||
|
||||
return ep.debugUpdates.GetAll(), nil
|
||||
}
|
||||
|
||||
// DiscoPublicKey returns the discovery public key.
|
||||
func (c *Conn) DiscoPublicKey() key.DiscoPublic {
|
||||
return c.discoPublic
|
||||
@@ -2042,32 +2022,6 @@ func nodesEqual(x, y views.Slice[tailcfg.NodeView]) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// debugRingBufferSize returns a maximum size for our set of endpoint ring
|
||||
// buffers by assuming that a single large update is ~500 bytes, and that we
|
||||
// want to not use more than 1MiB of memory on phones / 4MiB on other devices.
|
||||
// Calculate the per-endpoint ring buffer size by dividing that out, but always
|
||||
// storing at least two entries.
|
||||
func debugRingBufferSize(numPeers int) int {
|
||||
const defaultVal = 2
|
||||
if numPeers == 0 {
|
||||
return defaultVal
|
||||
}
|
||||
var maxRingBufferSize int
|
||||
if runtime.GOOS == "ios" || runtime.GOOS == "android" {
|
||||
maxRingBufferSize = 1 << 20
|
||||
// But as of 2024-03-20, we now just disable the ring buffer entirely
|
||||
// on mobile as it hadn't proven useful enough to justify even 1 MB.
|
||||
} else {
|
||||
maxRingBufferSize = 4 << 20
|
||||
}
|
||||
if v := debugRingBufferMaxSizeBytes(); v > 0 {
|
||||
maxRingBufferSize = v
|
||||
}
|
||||
|
||||
const averageRingBufferElemSize = 512
|
||||
return max(defaultVal, maxRingBufferSize/(averageRingBufferElemSize*numPeers))
|
||||
}
|
||||
|
||||
// debugFlags are the debug flags in use by the magicsock package.
|
||||
// They might be set by envknob and/or controlknob.
|
||||
// The value is comparable.
|
||||
@@ -2155,8 +2109,6 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
|
||||
|
||||
c.logf("[v1] magicsock: got updated network map; %d peers", len(nm.Peers))
|
||||
|
||||
entriesPerBuffer := debugRingBufferSize(len(nm.Peers))
|
||||
|
||||
// Try a pass of just upserting nodes and creating missing
|
||||
// endpoints. If the set of nodes is the same, this is an
|
||||
// efficient alloc-free update. If the set of nodes is different,
|
||||
@@ -2233,14 +2185,6 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
|
||||
heartbeatDisabled: flags.heartbeatDisabled,
|
||||
isWireguardOnly: n.IsWireGuardOnly(),
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "ios", "android":
|
||||
// Omit, to save memory. Prior to 2024-03-20 we used to limit it to
|
||||
// ~1MB on mobile but we never used the data so the memory was just
|
||||
// wasted.
|
||||
default:
|
||||
ep.debugUpdates = ringbuffer.New[EndpointChange](entriesPerBuffer)
|
||||
}
|
||||
if n.Addresses().Len() > 0 {
|
||||
ep.nodeAddr = n.Addresses().At(0).Addr()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user