Skip to content

Commit d311dda

Browse files
authored
feat: add enrichment of StartRequest with OS, device ID, version (#123)
Enriches `StartRequest` protocol message with device ID, OS, and version, for Coder Desktop telemetry.
1 parent f53a99f commit d311dda

File tree

7 files changed

+608
-4
lines changed

7 files changed

+608
-4
lines changed

Coder-Desktop/VPN/Manager.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import VPNLib
66
actor Manager {
77
let ptp: PacketTunnelProvider
88
let cfg: ManagerConfig
9+
let telemetryEnricher: TelemetryEnricher
910

1011
let tunnelHandle: TunnelHandle
1112
let speaker: Speaker<Vpn_ManagerMessage, Vpn_TunnelMessage>
@@ -19,6 +20,7 @@ actor Manager {
1920
init(with: PacketTunnelProvider, cfg: ManagerConfig) async throws(ManagerError) {
2021
ptp = with
2122
self.cfg = cfg
23+
telemetryEnricher = TelemetryEnricher()
2224
#if arch(arm64)
2325
let dylibPath = cfg.serverUrl.appending(path: "bin/coder-vpn-darwin-arm64.dylib")
2426
#elseif arch(x86_64)
@@ -176,6 +178,7 @@ actor Manager {
176178
req.value = header.value
177179
}
178180
}
181+
req = telemetryEnricher.enrich(req)
179182
}
180183
})
181184
} catch {

Coder-Desktop/VPNLib/Speaker.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ public actor Speaker<SendMsg: RPCMessage & Message, RecvMsg: RPCMessage & Messag
8888

8989
/// Does the VPN Protocol handshake and validates the result
9090
public func handshake() async throws(HandshakeError) {
91-
let hndsh = Handshaker(writeFD: writeFD, dispatch: dispatch, queue: queue, role: role)
92-
// ignore the version for now because we know it can only be 1.0
91+
let hndsh = Handshaker(writeFD: writeFD, dispatch: dispatch, queue: queue, role: role,
92+
versions: [ProtoVersion(1, 1)])
93+
// ignore the version for now because we know it can only be 1.0 or 1.1.
94+
// 1.1 adds support for telemetry to StartRequest, but since setting these
95+
// fields won't adversely affect a 1.0 speaker, we set them regardless.
9396
try _ = await hndsh.handshake()
9497
}
9598

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Foundation
2+
3+
public struct TelemetryEnricher {
4+
private let deviceID: String
5+
private let version: String?
6+
7+
public init() {
8+
version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
9+
10+
let userDefaults = UserDefaults.standard
11+
let key = "deviceID"
12+
13+
if let existingID = userDefaults.string(forKey: key) {
14+
deviceID = existingID
15+
} else {
16+
let newID = UUID().uuidString
17+
userDefaults.set(newID, forKey: key)
18+
deviceID = newID
19+
}
20+
}
21+
22+
public func enrich(_ original: Vpn_StartRequest) -> Vpn_StartRequest {
23+
var req = original
24+
req.deviceOs = "macOS"
25+
req.deviceID = deviceID
26+
if let version {
27+
req.coderDesktopVersion = version
28+
}
29+
return req
30+
}
31+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy