<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/PortPolicy",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Tor"
    ],
    "preciseIdentifier" : "s:3Tor10PortPolicyO"
  },
  "title" : "PortPolicy"
}
-->

# PortPolicy

Three-way policy describing how Tor should bind a configurable port.

```
enum PortPolicy
```

## Overview

`PortPolicy` is the typed counterpart to the port-number argument that
appears on Tor’s `SocksPort`, `ControlPort`, and related torrc options
(tor.1.txt). Rather than force callers to pass magic integers
(`0` to disable, `auto` to let Tor pick), the enum models the three
real choices and renders to the correct torrc token on demand via its
[`description`](/documentation/Tor/PortPolicy/description).

> Note: Conformance is `Sendable` + `Hashable` + `CustomStringConvertible`.
> The rendered string `description` is **deliberately identical** to the
> torrc token so you can interpolate directly into configuration
> strings; programmatic tests should pattern-match on the enum cases.

> Important: Only swift-tor’s SOCKS port currently uses this type. The
> control port is always bound by `tor_main_configuration_setup_control_socket()`
> and is not configurable via `PortPolicy`.

## Topics

### Policies

[`PortPolicy.ephemeral`](/documentation/Tor/PortPolicy/ephemeral)

Let Tor pick any unused TCP port on the loopback interface.

[`PortPolicy.fixed(_:)`](/documentation/Tor/PortPolicy/fixed(_:))

Bind the SOCKS port to an exact TCP port number.

[`PortPolicy.disabled`](/documentation/Tor/PortPolicy/disabled)

Disable the port entirely.

### Rendering

[`description`](/documentation/Tor/PortPolicy/description)

Torrc-compatible rendering of this policy.

