# SIP003 Plugin Support

Slipstream client/server can run in SIP003 environments by reading `SS_*` variables. Command-line
flags always win when set; environment values fill gaps.

## Environment mapping

Client (`slipstream-client`):

- `SS_LOCAL_HOST` + `SS_LOCAL_PORT` -> `--tcp-listen-host` + `--tcp-listen-port`
- `SS_REMOTE_HOST` + `SS_REMOTE_PORT` -> recursive resolver fallback (used only when no
  `--resolver`/`--authoritative` values are provided via CLI or plugin options; see
  `authoritative` note below)

Server (`slipstream-server`):

- `SS_REMOTE_HOST` + `SS_REMOTE_PORT` -> `--dns-listen-host` + `--dns-listen-port`
- `SS_LOCAL_HOST` + `SS_LOCAL_PORT` -> `--target-address`

`SS_LOCAL_*` and `SS_REMOTE_*` must be provided as pairs when used.

## SS_PLUGIN_OPTIONS

Supported keys:

- `domain`
- `resolver`
- `authoritative`
- `cert`
- `key`
- `reset-seed`
- `fallback`
- `max-connections`
- `congestion-control`
- `keep-alive-interval`

Client consumes `domain`, `resolver`, `authoritative`, `cert`, `congestion-control`, and
`keep-alive-interval`. Server consumes `domain`, `cert`, `key`, `reset-seed`, `fallback`, and
`max-connections`.

Syntax: `key=value;key=value`. Semicolons, equal signs, and backslashes must be escaped with
backslashes (`\;`, `\=`, `\\`).

List keys (`resolver`, `authoritative`) accept comma-separated values or repeated keys.
Order is preserved across keys, matching CLI ordering behavior.
`domain` is a comma-separated list in a single option; repeating `domain` is invalid. The client
requires exactly one domain value, while the server accepts multiple domains.
IPv6 resolver addresses must be bracketed, for example `[2001:db8::1]:53`.
Using `authoritative` with an empty value (for example `authoritative=` or a bare
`authoritative` entry) switches the `SS_REMOTE_*` fallback into authoritative mode.

Examples:

- `resolver=1.1.1.1:53,[2001:db8::1]:53;authoritative=9.9.9.9:5353`
- `domain=example.com,tunnel.example.com`

## Precedence notes

- CLI arguments override plugin options and `SS_*` env values.
- Plugin options override `SS_REMOTE_*` for resolver selection.
- If at least one resolver/authoritative is provided via CLI or plugin options, `SS_REMOTE_*` is
  ignored by the client.
- `SS_LOCAL_*` and `SS_REMOTE_*` are only applied when both corresponding listen flags are omitted.

## Example usage

Client:

```
SS_LOCAL_HOST=127.0.0.1 \
SS_LOCAL_PORT=7000 \
SS_REMOTE_HOST=203.0.113.10 \
SS_REMOTE_PORT=8853 \
SS_PLUGIN_OPTIONS="domain=example.com;resolver=1.1.1.1:53" \
./target/release/slipstream-client
```

Server:

```
SS_REMOTE_HOST=0.0.0.0 \
SS_REMOTE_PORT=8853 \
SS_LOCAL_HOST=127.0.0.1 \
SS_LOCAL_PORT=5201 \
SS_PLUGIN_OPTIONS="domain=example.com;cert=./cert.pem;key=./key.pem" \
./target/release/slipstream-server
```
