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
set p2p setup
  • Loading branch information
ethanndickson committed Jul 9, 2024
commit b2405072da6160d67b4966bf6df88955fc31855a
60 changes: 21 additions & 39 deletions tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,7 @@ func NewConn(options *Options) (conn *Conn, err error) {
server.telemetryStore.setNetInfo(ni)
nodeUp.setNetInfo(ni)
})
server.wireguardEngine.AddNetworkMapCallback(func(nm *netmap.NetworkMap) {
if server.telemetryStore.updateNetworkMap(nm) {
server.sendUpdatedTelemetry()
}
})
server.wireguardEngine.AddNetworkMapCallback(server.networkMapCallback)
} else {
server.wireguardEngine.SetNetInfoCallback(nodeUp.setNetInfo)
}
Expand Down Expand Up @@ -723,25 +719,7 @@ func (c *Conn) SendConnectedTelemetry(ip netip.Addr, application string) {
c.telemetryStore.markConnected(&ip, c.createdAt, application)
e := c.newTelemetryEvent()
e.Status = proto.TelemetryEvent_CONNECTED
c.telemetryWg.Add(1)
go func() {
defer c.telemetryWg.Done()
c.telemetrySink.SendTelemetryEvent(e)
}()
}

// Currently only called when the preferred DERP is updated.
func (c *Conn) sendUpdatedTelemetry() {
if c.telemetrySink == nil {
return
}
e := c.newTelemetryEvent()
e.Status = proto.TelemetryEvent_CONNECTED
c.telemetryWg.Add(1)
go func() {
defer c.telemetryWg.Done()
c.telemetrySink.SendTelemetryEvent(e)
}()
c.sendTelemetryBackground(e)
}

func (c *Conn) SendDisconnectedTelemetry() {
Expand All @@ -750,11 +728,7 @@ func (c *Conn) SendDisconnectedTelemetry() {
}
e := c.newTelemetryEvent()
e.Status = proto.TelemetryEvent_DISCONNECTED
c.telemetryWg.Add(1)
go func() {
defer c.telemetryWg.Done()
c.telemetrySink.SendTelemetryEvent(e)
}()
c.sendTelemetryBackground(e)
}

func (c *Conn) SendSpeedtestTelemetry(throughputMbits float64) {
Expand All @@ -764,11 +738,7 @@ func (c *Conn) SendSpeedtestTelemetry(throughputMbits float64) {
e := c.newTelemetryEvent()
e.ThroughputMbits = wrapperspb.Float(float32(throughputMbits))
e.Status = proto.TelemetryEvent_CONNECTED
c.telemetryWg.Add(1)
go func() {
defer c.telemetryWg.Done()
c.telemetrySink.SendTelemetryEvent(e)
}()
c.sendTelemetryBackground(e)
}

// nolint:revive
Expand All @@ -782,15 +752,12 @@ func (c *Conn) sendPingTelemetry(pr *ipnstate.PingResult) {
if pr.Endpoint != "" {
e.P2PLatency = latency
e.P2PEndpoint = c.telemetryStore.toEndpoint(pr.Endpoint)
e.P2PSetup = durationpb.New(time.Since(c.createdAt))
} else {
e.DerpLatency = latency
}
e.Status = proto.TelemetryEvent_CONNECTED
c.telemetryWg.Add(1)
go func() {
defer c.telemetryWg.Done()
c.telemetrySink.SendTelemetryEvent(e)
}()
c.sendTelemetryBackground(e)
}

// The returned telemetry event will not have it's status set.
Expand All @@ -804,6 +771,21 @@ func (c *Conn) newTelemetryEvent() *proto.TelemetryEvent {
return event
}

func (c *Conn) networkMapCallback(nm *netmap.NetworkMap) {
c.telemetryStore.updateNetworkMap(nm)
if c.telemetryStore.connectedIP != nil {
go func() { _, _, _, _ = c.Ping(context.Background(), *c.telemetryStore.connectedIP) }()
}
}

func (c *Conn) sendTelemetryBackground(e *proto.TelemetryEvent) {
c.telemetryWg.Add(1)
go func() {
defer c.telemetryWg.Done()
c.telemetrySink.SendTelemetryEvent(e)
}()
}

// PeerDiagnostics is a checklist of human-readable conditions necessary to establish an encrypted
// tunnel to a peer via a Conn
type PeerDiagnostics struct {
Expand Down
7 changes: 3 additions & 4 deletions tailnet/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,17 @@ func (b *TelemetryStore) updateRemoteNodeIDLocked(nm *netmap.NetworkMap) {
}
}

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

if nm == nil {
return false
return
}

b.updateDerpMapLocked(nm.DERPMap)
b.updateRemoteNodeIDLocked(nm)
return b.updateByNodeLocked(nm.SelfNode)
b.updateByNodeLocked(nm.SelfNode)
}

// Given a DERPMap, anonymise all IPs and hostnames.
Expand Down