Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
ethanndickson committed Jul 8, 2024
commit af36c3734aa9d4c11c7528871c3e84c6aa3033d9
4 changes: 2 additions & 2 deletions tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ func (c *Conn) MagicsockServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
c.magicConn.ServeHTTPDebug(w, r)
}

// Currently called when connected to the Agent with the given IP using the given application.
func (c *Conn) SendConnectedTelemetry(ip netip.Addr, application string) {
if c.telemetrySink == nil {
return
Expand All @@ -732,8 +733,7 @@ func (c *Conn) SendConnectedTelemetry(ip netip.Addr, application string) {
}()
}

// Called whenever the Node is updated.
// Expects that the telemetry store has the latest node information.
// Currently only called when the preferred DERP is updated.
func (c *Conn) sendUpdatedTelemetry() {
if c.telemetrySink == nil {
return
Expand Down
16 changes: 12 additions & 4 deletions tailnet/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
const (
TelemetryApplicationSSH string = "ssh"
TelemetryApplicationSpeedtest string = "speedtest"
TelemetryApplicationVSCode string = "vscode"
)

// Responsible for storing and anonymizing networking telemetry state.
Expand Down Expand Up @@ -84,9 +85,6 @@ func (b *TelemetryStore) markConnected(ip *netip.Addr, connCreatedAt time.Time,
}

func (b *TelemetryStore) updateRemoteNodeIDLocked(nm *netmap.NetworkMap) {
b.mu.Lock()
defer b.mu.Unlock()

if b.connectedIP == nil {
return
}
Expand All @@ -102,11 +100,15 @@ func (b *TelemetryStore) updateRemoteNodeIDLocked(nm *netmap.NetworkMap) {
}
}

// Returning whether a new telemetry event should be sent
// Returns whether a new telemetry event should be sent
func (b *TelemetryStore) updateNetworkMap(nm *netmap.NetworkMap) bool {
b.mu.Lock()
defer b.mu.Unlock()

if nm == nil {
return false
}

b.updateDerpMapLocked(nm.DERPMap)
b.updateRemoteNodeIDLocked(nm)
return b.updateByNodeLocked(nm.SelfNode)
Expand All @@ -116,6 +118,9 @@ func (b *TelemetryStore) updateNetworkMap(nm *netmap.NetworkMap) bool {
// Keep track of seen hostnames/cert names to anonymize them from future logs.
// b.mu must NOT be held.
func (b *TelemetryStore) updateDerpMapLocked(cur *tailcfg.DERPMap) {
if cur == nil {
return
}
cleanMap := cur.Clone()
for _, r := range cleanMap.Regions {
for _, n := range r.Nodes {
Expand All @@ -137,6 +142,9 @@ func (b *TelemetryStore) updateDerpMapLocked(cur *tailcfg.DERPMap) {
// Update the telemetry store with the current self node state.
// Returns true if the home DERP has changed.
func (b *TelemetryStore) updateByNodeLocked(n *tailcfg.Node) bool {
if n == nil {
return false
}
b.nodeID = uint64(n.ID)
derpIP, err := netip.ParseAddrPort(n.DERP)
if err != nil {
Expand Down