Type Method
localhost(_:)
Returns a loopback endpoint (127.0.0.1:port) for the given port.
static func localhost(_ port: Int) -> HostPort
Parameters
-
port
-
TCP port on 127.0.0.1.
Return Value
A fresh HostPort with host == "127.0.0.1".
Discussion
Convenience factory for the most common shape of HostPort inside swift-tor: Tor’s SOCKS and control endpoints both live on the loopback interface, and the overwhelming majority of callers never need a non-loopback host. Using this factory makes it impossible to typo "127.0.0.1" at call sites and keeps intent explicit.
Note
This factory always returns an IPv4 loopback. If you need IPv6 loopback (::1), construct the value explicitly via init(host:port:). The two loopback families are distinct at the kernel socket layer and will not unify on connect(2).
Important
The string literal "localhost" is deliberately not used here to avoid an unnecessary DNS lookup on Apple platforms.