Class
TorControlClient
Sendable high-level client for Tor’s control protocol (control-spec.txt).
final class TorControlClient
Mentioned In
Overview
Wraps a ControlSocket and exposes a typed, async method per control-protocol command family: authentication, GETINFO, SETCONF, SETEVENTS, SIGNAL, ADD_ONION / DEL_ONION. Every method sends exactly one command and awaits a single reply (or an async event stream in the case of subscribe(to:)), translating reply codes into TorError cases and typed payloads via ControlProtocolParser.
Most callers never construct one directly — start() creates a pre-authenticated instance and hands it out via control(). Construct directly when driving a Tor instance swift-tor did not launch (e.g. connecting to a systemd-managed tor over its ControlPort).
Onion-service lifecycle
addOnion(key:ports:detach:) registers an onion service whose lifetime is determined by the detach flag:
detach: false — service is tied to this control connection and is removed by Tor when the socket closes (control-spec.txt §3.27).
detach: true — service survives the control-socket closure and only disappears on explicit delOnion(_:) or on Tor process exit.
Note
Conformance is Sendable (compiler-verified, no @unchecked). Concurrent calls are safe and serialised at the socket layer — commands execute in arrival order.
Important
TorControlClient is authenticated at most once per instance; subsequent calls to authenticate(password:) after success are no-ops. For the embedded control socket (init(fileDescriptor:preAuthenticated:dataDirectory:) with preAuthenticated: true) authentication is skipped entirely.
Topics
Creating
Authentication
GETINFO
Configuration & events
Onion services
Signals
Escape hatch