Watch for changes in the connection type (P2P<->DERP) and send telemetry events.
()
| 911 | |
| 912 | // Watch for changes in the connection type (P2P<->DERP) and send telemetry events. |
| 913 | func (c *Conn) watchConnChange() { |
| 914 | ticker := time.NewTicker(time.Millisecond * 50) |
| 915 | defer ticker.Stop() |
| 916 | for { |
| 917 | select { |
| 918 | case <-c.watchCtx.Done(): |
| 919 | return |
| 920 | case <-ticker.C: |
| 921 | } |
| 922 | status := c.Status() |
| 923 | peers := status.Peers() |
| 924 | if len(peers) > 1 { |
| 925 | // Not a CLI<->agent connection, stop watching |
| 926 | return |
| 927 | } else if len(peers) == 0 { |
| 928 | continue |
| 929 | } |
| 930 | peer := status.Peer[peers[0]] |
| 931 | // If the connection type has changed, send a telemetry event with the latest ping stats |
| 932 | if c.telemetryStore.changedConntype(peer.CurAddr) { |
| 933 | c.telemetryStore.pingPeer(c) |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | // PeerDiagnostics is a checklist of human-readable conditions necessary to establish an encrypted |
| 939 | // tunnel to a peer via a Conn |