@@ -34,7 +34,7 @@ type TelemetryStore struct {
34
34
nodeID uint64
35
35
homeDerp int32
36
36
37
- connSetupTime time .Duration
37
+ connSetupTime * durationpb .Duration
38
38
}
39
39
40
40
func newTelemetryStore () (* TelemetryStore , error ) {
@@ -59,7 +59,7 @@ func (b *TelemetryStore) newEvent() *proto.TelemetryEvent {
59
59
LatestNetcheck : b .cleanNetCheck ,
60
60
NodeIdSelf : b .nodeID ,
61
61
HomeDerp : b .homeDerp ,
62
- ConnectionSetup : durationpb . New ( b .connSetupTime ) ,
62
+ ConnectionSetup : b .connSetupTime ,
63
63
64
64
// TODO(ethanndickson):
65
65
P2PSetup : & durationpb.Duration {},
@@ -70,7 +70,7 @@ func (b *TelemetryStore) markConnected(connSetupTime time.Duration) {
70
70
b .mu .Lock ()
71
71
defer b .mu .Unlock ()
72
72
73
- b .connSetupTime = connSetupTime
73
+ b .connSetupTime = durationpb . New ( connSetupTime )
74
74
}
75
75
76
76
// Given a DERPMap, anonymise all IPs and hostnames.
@@ -97,24 +97,26 @@ func (b *TelemetryStore) updateDerpMap(cur *tailcfg.DERPMap) {
97
97
b .cleanDerpMap = cleanMap
98
98
}
99
99
100
- func (b * TelemetryStore ) updateByNode (n * Node ) {
100
+ // Update the telemetry store with the current node state.
101
+ // Returns true if the home DERP has changed.
102
+ func (b * TelemetryStore ) updateByNode (n * Node ) bool {
101
103
b .mu .Lock ()
102
104
defer b .mu .Unlock ()
103
105
104
106
b .nodeID = uint64 (n .ID )
105
- b .homeDerp = int32 (n .PreferredDERP )
107
+ newHome := int32 (n .PreferredDERP )
108
+ if b .homeDerp != newHome {
109
+ b .homeDerp = newHome
110
+ return true
111
+ }
112
+ return false
106
113
}
107
114
108
115
// Store an anonymized proto.Netcheck given a tailscale NetInfo.
109
- func (b * TelemetryStore ) setNetInfo (ni * tailcfg.NetInfo ) bool {
116
+ func (b * TelemetryStore ) setNetInfo (ni * tailcfg.NetInfo ) {
110
117
b .mu .Lock ()
111
118
defer b .mu .Unlock ()
112
119
113
- derpHomeChanged := false
114
- if b .cleanNetCheck != nil {
115
- derpHomeChanged = b .cleanNetCheck .PreferredDERP != int64 (ni .PreferredDERP )
116
- }
117
-
118
120
b .cleanNetCheck = & proto.Netcheck {
119
121
UDP : ni .UDP ,
120
122
IPv6 : ni .IPv6 ,
@@ -152,7 +154,6 @@ func (b *TelemetryStore) setNetInfo(ni *tailcfg.NetInfo) bool {
152
154
for rid , seconds := range ni .DERPLatencyV6 {
153
155
b .cleanNetCheck .RegionV6Latency [int64 (rid )] = durationpb .New (time .Duration (seconds * float64 (time .Second )))
154
156
}
155
- return derpHomeChanged
156
157
}
157
158
158
159
func (b * TelemetryStore ) toEndpoint (ipport string ) * proto.TelemetryEvent_P2PEndpoint {
0 commit comments