# Add devices to the mesh

> Create a mesh on one isotope, invite the next machine with a single-use code, and let them share work.

## What a mesh is

A mesh is a private, encrypted overlay between isotopes. One isotope per mesh is the **authority**: it holds the mesh’s certificate authority, mints invitations, gives each member a fixed mesh address and keeps the blocklist. A **lighthouse** is a member others can dial at a public address; it also relays traffic between members that cannot reach each other directly. Every other member is a **client**: it needs no public address and reaches peers through the lighthouses, though it may also publish direct addresses that peers dial.

Membership is what lets isotopes run each other’s work: members accept calls from the isotopes their authority enrolled and has not revoked, and nobody else. An isotope belongs to one mesh at a time; joining another leaves the first. Joining moves no application data.

## Before you start

- You are an administrator on the inviting isotope. **Settings → Mesh** is hidden from other roles.
- Both isotopes are installed and started (`drkm start`).
- The mesh authority’s HTTPS address, its `--public-url`, is reachable from the new machine. The invitation carries that address even when it was minted on another member; the join is redeemed there and refreshes are pulled from it.
- A machine that others should reach directly, a lighthouse, is dialable on UDP port 4242 or the port it declares. Clients need no reachable address.

## Create your mesh

A fresh isotope belongs to no mesh. In **Settings → Mesh**, the **Mesh networking** switch opens the **Create a mesh** dialog: name it, and this isotope becomes the authority of a one-member mesh. No restart is needed. For a machine other isotopes should dial, give it a reachable address when you start it.

```bash Terminal
# Declare the HTTPS origin and the UDP endpoint other isotopes can reach
drkm start --public-url https://isotope.example --nebula-advertise 203.0.113.10:4242
```

## Add a second machine

One command on the new machine, one click by you. Choose **Add isotope** in **Settings → Mesh → Isotopes** or on the Isotopes page to copy the command for your mesh, then run it on the new machine:

```bash Terminal
# A new machine: install drkm, start it, and ask to join
curl -fsSL https://drkm.com/install | sh -s -- --join https://main.example.com

# A machine already running drkm
drkm join https://main.example.com
```

The machine asks the mesh's authority for a code of its own. It prints a link and an eight-character match code, such as `4F7K-9QX2`, and keeps waiting. Open the link, or send it to someone who may add machines to the mesh, sign in, check that the page shows the same match code, and choose **Connect**, or **Not mine** if it isn't yours. The machine joins as yours, generates its keys locally, gets its mesh address and certificates from the authority, and brings its tunnel up.

`drkm join` needs no sign-in on the machine itself: it acts as the machine's owner. If the mesh runs a newer release than the machine, `drkm join` updates the machine first, so every member runs the same release (`--no-update` skips that). It waits up to 30 minutes for someone to let the machine in; run it again to ask anew.

### Join with an invitation code

A phone, or a mesh that doesn't take requests to join, uses a single-use invitation code instead. **Add isotope** offers **Create invitation code** for those, and `drkm enrollment invite` mints one from the terminal. Paste it under **Settings → Mesh → Settings → Join an existing mesh**, or run `drkm join` with no address and paste it at the hidden prompt. A code from the authority still waits for someone to let the machine in; a code minted on a member isotope is forwarded with that member's signature and joins without it. Codes last 24 hours, and **Not mine** stops one working.

```bash Terminal
# On any enrolled isotope, as an administrator
drkm enrollment invite --url https://isotope.example

# On the new machine
drkm join
# Invitation code: <paste the drkm1.… code>

# Unattended
DRKM_ENROLLMENT_TOKEN='drkm1.…' drkm join
```

<Note>
  A code is entered at the prompt or through the environment, never as an argument, and it carries the issuer's certificate authority. For a private-CA authority, add `--tls-ca /path/to/ca.pem` to `drkm join <address>` and to `drkm enrollment invite` and `remove`.
</Note>

### A machine still in a mesh that's gone

Joining a new mesh leaves the current one first. If the current mesh's authority can't be reached, `drkm join` asks whether to leave it on this machine only (`--leave-here-only` says yes up front), and the console offers **Leave … here only and join**. The old authority keeps listing the machine until someone removes it there.

## Join a Mac from the desktop app

Install Darkmatter for Mac first. Then, in your workspace, open the desktop-app menu at the foot of the sidebar and choose **Add this Mac to the workspace**. It mints a code and opens it straight in Darkmatter, which offers **Set up this Mac for your workspace**. One click there sets the Mac up as your machine in that workspace: it needs no account or organization of its own, joins the workspace's mesh with no **Connect** step, and the app then opens your workspace, where you sign in with your Darkmatter account and find the Mac under **Isotopes**.

<Warning>
  Asking for this code is the approval, so whoever holds it can put one machine on the mesh unchecked. That is why it lasts 10 minutes rather than 24 hours, works once, is minted only for an administrator on the authority, and is never shown or copied: it is handed to the app on the same computer. The Mac still asks before it is set up, so a link from another site cannot add it to a workspace on its own. Codes from **Add isotope** still wait for **Connect**.
</Warning>

## See it arrive

The Add isotope dialog reads _Joined: name_ as soon as the new isotope’s first heartbeat lands, within about a minute. After that heartbeat it appears under **Settings → Mesh → Isotopes**, on the **Isotopes** page, in `drkm console isotopes` and in `drkm.isotopes()`. Opening it there shows its roles, mesh address, dial address, enrollment time and last heartbeat, and offers **Rename**, **Configure network** and **Remove from mesh**.

## Lighthouses and addresses

Make an isotope a lighthouse from its entry under **Settings → Mesh → Isotopes**: **Configure network**, then add up to 16 host and port rows it can be dialed at. The **Lighthouses** tab shows the phone book every member pulls and a health line: with none, only known direct addresses can connect; with one, losing it leaves only direct addresses; with two or more, losing one is fine. Two lighthouses is the minimum for a mesh that must survive losing a machine.

If the authority is down, existing tunnels keep working; joins, renewals and blocklist pulls wait until it returns. Host certificates are signed for 10 years, so certificate expiry is not an availability concern.

## Remove, leave, restore

**Remove from mesh** on an isotope’s entry, or `drkm enrollment remove`, blocks every certificate the authority issued to it; peers stop trusting it at their next refresh, and the removed isotope learns at its own next refresh, turns its mesh off and keeps its identity, keys and data. A new invitation brings it back with the same mesh address, and the authority’s **Blocked isotopes** list offers **Restore**.

An isotope leaves on its own from **Settings → Mesh → Settings → Leave mesh** or with `drkm leave`. Leaving asks the authority to remove it; if the authority can't be reached, choose **Leave here only** or run `drkm leave --here-only`, and remove it at the authority later. An authority never leaves its own mesh: it removes members one at a time, or **Delete mesh** removes everyone at once and turns its mesh off.

```bash Terminal
drkm enrollment remove <isotope-id> --url https://isotope.example
drkm leave
```

## Keep the fleet up to date

Each isotope follows published releases itself; nothing is pushed from the authority. Administrators see an update icon at the bottom of the console sidebar, with a red dot when a newer release is out, and **Settings → Updates** offers **Check for updates**, **Update now**, **Automatic updates** and **Alpha releases**. On the host, `drkm update` does the same and redeploys a running isotope. Automatic updates run once a day unless turned off, restart the isotope, and roll back if the new release never becomes healthy.
