# Site relays

_For tartan 0.9.36._

A site relay carries traffic between your devices when they can't reach each other directly.

A site relay carries traffic between your devices when they can't reach each other directly. It runs on your own
host, at one of your sites.

Devices connect to each other directly, even behind NAT. When two devices both sit behind strict NAT and no direct
path forms, they need a relay. A site relay is a site node (a Linux virtual machine Tartan builds) like a gateway, built on your own Hyper-V host the same
way, but it belongs to no site.

## Before you start

- The Owner or Admin role.
- A Windows Hyper-V host, as for a [gateway](gateway-pairs.md): steps 1 to 3 there (check, fetch, dry-run) apply
  here with `-Kind relay` and no `-Site`.
- **A public address.** On the site's router, forward one WAN UDP port to the relay's LAN address, UDP port 4242,
  and give the relay a fixed DHCP reservation. A private, carrier-NAT or loopback address is refused: peers and
  control, Tartan's control plane, must reach the relay from outside.

## 1. Mint the Ignition

The Ignition is the settings the VM reads on its first boot. On your own computer, with the gateway image that
`tartan edge site-node show --org acme` lists, and the router's WAN address and forwarded port:

```sh
tartan edge ignition --org acme --kind relay --name office-relay1 --image ghcr.io/tartan-networks/tartan-gateway@<gateway_image> --control_url <control url> --public 203.0.113.7:4242 --host <hyper-v host> --json > answer.json
```

This steps up and has no dry run. Its answer holds a one-hour join code: treat the file like one. The helper takes
it for 15 minutes from minting.

## 2. Build it on the host

Move `answer.json` to the Hyper-V host and run the helper:

```powershell
powershell.exe -NoProfile -ExecutionPolicy AllSigned -File New-TartanSiteNode.ps1 -Kind relay -Name office-relay1 -Org <org id> -ControlUrl <control url> -ExpectCidr 192.168.1.0/24 -Switch <switch> -Vlan 0 -BaseVhdx <base vhdx> -KvpCtl <kvpctl exe> -Tartan .\tartan.exe -IgnitionFile answer.json -NoWait
```

It makes the VM, starts it, deletes the answer file and prints a `-WaitOnly` line. Run that line on your own
computer: it waits until the relay has enrolled, then checks it with `tartan edge converge` until it has converged.
That check is a change, not a read: your passkey approves each one.

In the console, **Control plane** has **Add a site relay**: it gives the `tartan edge ignition` command to fill in
and run.

## 3. How devices use it

Peers are told the relay's public address, never its LAN address. Tartan checks that address from outside, and
devices are told about the relay only while that check passes.

To change the address later (a new WAN address or port), an Owner or Admin runs this, and their passkey approves it:

```sh
tartan device set --org acme --device <relay device id> --public 203.0.113.7:4243
```

A new address takes the relay out of use until it passes the outside check there. `--public ""` clears it, and a
relay with no address is never used.

## 4. A second relay

One site relay alone leaves devices that need a relay with none while it is down. Build a second at another site,
on another host, the same way with another name.

## Check it worked

```sh
tartan edge list --org acme
tartan doctor run --org acme
```

`edge list` shows the relay and its health. `doctor run` warns about a site relay with no public address. One
site relay alone is listed as `info`, not a warning: when it is down, devices that need a relay have none.

## Next

- [Gateways in pairs](gateway-pairs.md)
- [Add a site](add-site.md)
- [Printers and legacy systems](legacy-systems.md)
