Remove tsnet debug logging

This commit is contained in:
Ian Gulliver
2026-10-20 21:47:06 -07:00
parent 4fdcc91061
commit da824b9728
4 changed files with 2 additions and 61 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ final class Remote {
case .success:
self.receive(task)
case .failure(let error):
log.notice("client connection closed:\(errorText(error), privacy: .public); \(tailnetNode.peerState(self.api.origin.host()!), privacy: .public)")
log.notice("client connection closed:\(errorText(error), privacy: .public)")
self.ws = nil
try? await Task.sleep(for: retryAfter)
self.start()
-1
View File
@@ -253,7 +253,6 @@ final class Connection {
Notifier.shared.deliver()
return true
} catch {
log.notice("connect \(self.origin.absoluteString, privacy: .public) failed: \(errorText(error), privacy: .public); \(tailnetNode.peerState(self.origin.host()!), privacy: .public)")
await store.stop()
if !stopped {
phase = .failed(explain(error, origin))
-58
View File
@@ -40,7 +40,6 @@ final class TailnetNode: Sendable {
Self.check(sd, "set hostname", unsafe tailscale_set_hostname(sd, hostname))
Self.check(sd, "set dir", unsafe tailscale_set_dir(sd, dir.path))
Self.check(sd, "set ephemeral", tailscale_set_ephemeral(sd, 0))
Self.check(sd, "set logfd", tailscale_set_logfd(sd, Self.logPipe()))
Self.check(sd, "start", tailscale_start(sd))
var addr = [CChar](repeating: 0, count: 64)
var proxyCred = [CChar](repeating: 0, count: 33)
@@ -61,49 +60,6 @@ final class TailnetNode: Sendable {
}
}
private static let logs = Pipe()
private static func logPipe() -> Int32 {
let lines = LineBuffer()
logs.fileHandleForReading.readabilityHandler = { handle in
for line in lines.add(handle.availableData) {
log.notice("tsnet: \(line, privacy: .public)")
}
}
return dup(logs.fileHandleForWriting.fileDescriptor)
}
func peerState(_ host: String) -> String {
var out: UnsafeMutablePointer<CChar>?
guard unsafe tailscale_status_json(sd, &out) == 0, let out = unsafe out else {
return "no status: \(Self.errorMessage(sd))"
}
defer {
unsafe free(out)
}
struct Peer: Decodable {
let DNSName: String
let Online: Bool
let InNetworkMap: Bool
let InMagicSock: Bool
let InEngine: Bool
let LastHandshake: String
let CurAddr: String
let Relay: String
}
struct Status: Decodable {
let BackendState: String
let Peer: [String: Peer]?
}
guard let status = try? JSONDecoder().decode(Status.self, from: unsafe Data(bytes: out, count: strlen(out))) else {
return "undecodable status"
}
guard let p = (status.Peer ?? [:]).values.first(where: { $0.DNSName == host + "." || $0.DNSName == host }) else {
return "state=\(status.BackendState) peer \(host) not in status"
}
return "state=\(status.BackendState) online=\(p.Online) netmap=\(p.InNetworkMap) magicsock=\(p.InMagicSock) engine=\(p.InEngine) handshake=\(p.LastHandshake) addr=\(p.CurAddr) relay=\(p.Relay)"
}
static func errorMessage(_ sd: tailscale) -> String {
var buf = [CChar](repeating: 0, count: 1024)
_ = unsafe tailscale_errmsg(sd, &buf, buf.count)
@@ -167,20 +123,6 @@ final class TailnetNode: Sendable {
}
}
private final class LineBuffer: @unchecked Sendable {
private var pending = Data()
func add(_ data: Data) -> [String] {
pending.append(data)
var lines: [String] = []
while let nl = pending.firstIndex(of: 0x0A) {
lines.append(String(decoding: pending[pending.startIndex..<nl], as: UTF8.self))
pending.removeSubrange(pending.startIndex...nl)
}
return lines
}
}
let tailnetNode = TailnetNode()
@MainActor