# Supgang architecture

> How your computers share changing addresses, verify each other, and find one another again.

- **Project:** [Supgang](https://agenxy.org/projects/supgang/)
- **Status:** Alpha, unreleased
- **Revised:** 2026-10-22

---

A home internet provider can change your public IP address without warning.
A laptop gets a different address on each new network. The saved address then
no longer leads to the computer.

Most solutions keep the new address on a company's server. Supgang keeps it
among computers you control. There is no central copy, account, public
directory, or vendor-operated relay.

## The idea

Each computer has a permanent cryptographic identity, independent of its name
or IP address. Periodically it makes a small signed note: who it is, and the
addresses where it can be reached. Supgang calls this an **address record**.

The signature lets another member verify which computer wrote the record and
that nobody changed it in transit. Connected members compare what they know
and pass along newer records. A computer that moves writes a new record; any
member that receives it passes it on.

<figure class="architecture-figure address-flow" aria-labelledby="address-flow-caption">
  <div class="flow-row">
    <div class="flow-step"><span>1</span><strong>The laptop moves</strong><small>Its old public address goes stale.</small></div>
    <span class="flow-arrow" aria-hidden="true">→</span>
    <div class="flow-step"><span>2</span><strong>One saved path still works</strong><small>The laptop reaches the home computer.</small></div>
    <span class="flow-arrow" aria-hidden="true">→</span>
    <div class="flow-step"><span>3</span><strong>Home verifies the update</strong><small>The signature proves which computer wrote it.</small></div>
    <span class="flow-arrow" aria-hidden="true">→</span>
    <div class="flow-step"><span>4</span><strong>Home carries it onward</strong><small>Other peers learn the laptop's new address.</small></div>
  </div>
  <figcaption id="address-flow-caption">The laptop needs no direct path to every member. One surviving connection carries its new address through the group.</figcaption>
</figure>

Governing limit: a new record travels only over a path that still exists. If
every path disappears, Supgang keeps retrying; it cannot invent a route
through the internet.

Supgang does not carry application traffic. It finds and verifies a computer;
SSH, file sharing, or another application makes the connection.

## What a computer shares

An address record contains only what another member needs to identify the
computer and try to reach it.

<figure class="architecture-figure record-card" aria-labelledby="record-caption">
  <p class="figure-label">Address record</p>
  <dl>
    <dt>Computer</dt><dd>A permanent identifier derived from its public key</dd>
    <dt>Name</dt><dd>A human-readable label, never used as proof of identity</dd>
    <dt>Version</dt><dd>A number that increases, so every member can tell which record is newer</dd>
    <dt>Valid until</dt><dd>When other members must stop trusting this copy</dd>
    <dt>Addresses</dt><dd>Up to eight current places to try, each labelled by where it came from</dd>
    <dt>Proof to expect</dt><dd>A short code for the credential the computer must show when reached; a substitute is rejected</dd>
  </dl>
  <p class="record-signature"><strong>Signed by this computer</strong><small>Other members can verify the record. They cannot alter or forge it.</small></p>
  <figcaption id="record-caption">Each computer publishes one current record and replaces it when its addresses change.</figcaption>
</figure>

Addresses come from four sources:

- **Local addresses**: read directly from the operating system. Useful when
  two computers share a network.
- **Direct public addresses**: belong to the computer and are routable across
  the internet. Common with IPv6, uncommon with IPv4.
- **Router-mapped addresses**: the local router is asked to send one public
  port to Supgang. Supgang uses UDP; some networks and firewalls block it entirely. The router may
  support PCP, NAT-PMP, or UPnP, three standard ways for software to request a
  temporary port mapping. The request stays on the local network.
- **Peer-observed addresses**: the public source addresses an authenticated
  member sees when traffic arrives. Supgang calls no outside “what is my IP?”
  service.

Every address is a place to try, not proof that it works. A mapping reported
by the router stays unverified until another authorised computer connects
through it. Old records are kept as bounded recovery hints, never shown as the
computer's current address.

## How computers find one another again

Recovery follows a fixed order. Inexpensive, likely paths come first; paths
that need another computer come later.

<figure class="architecture-figure recovery-ladder" aria-labelledby="recovery-caption">
  <ol>
    <li><span class="rung-number">1</span><span><strong>Use the open connection</strong><small>A live session carries the new record immediately.</small></span></li>
    <li><span class="rung-number">2</span><span><strong>Race the published addresses</strong><small>Try its newest addresses almost together, including any router-created mapping.</small></span></li>
    <li><span class="rung-number">3</span><span><strong>Retry addresses that worked before</strong><small>An older route may still lead to a fresh record.</small></span></li>
    <li><span class="rung-number">4</span><span><strong>Have both sides try together</strong><small>Coordinated attempts can open a temporary path through both routers.</small></span></li>
    <li><span class="rung-number">5</span><span><strong>Ask a mutual peer</strong><small>A member connected to both sides introduces them using the addresses it sees.</small></span></li>
    <li><span class="rung-number">6</span><span><strong>Use your own anchor</strong><small>An optional, reachable computer you control keeps more peer connections alive.</small></span></li>
  </ol>
  <figcaption id="recovery-caption">Supgang works down the list until a path succeeds. Every step requires at least one usable route.</figcaption>
</figure>

Addresses are raced, not tried one at a time while a dead address times out.
Supgang keeps a bounded history of addresses that worked before: sixteen per
peer by default, so recovery has more than one old lead.

Simultaneous attempts work because many routers reject unsolicited incoming
traffic but briefly admit replies after a computer sends something out.
Supgang gives both computers the same retry window, so each sends while the
other's router may admit the reply. This is **NAT traversal**: establishing a
direct path through routers that share one public address among several local
devices.

A mutual peer can help when it has authenticated connections to both
computers. It tells each side the source address it directly observed for the
other; both then try at once. The introduction is short-lived and single-use,
and is never saved as a trusted current address. This path requires at least
three members: the two being connected and their mutual peer.

## The optional anchor

An anchor is an ordinary Supgang member on an always-on computer you own, such
as a machine at another site or a small server in your own cloud account. It
must already have an address the other members can reach.

<figure class="architecture-figure anchor-map" aria-labelledby="anchor-caption">
  <div class="anchor-node"><strong>Your anchor</strong><small>Address updates and introductions only</small></div>
  <div class="anchor-links" aria-hidden="true"><span></span><span></span></div>
  <div class="peer-row">
    <div class="peer-node"><strong>Your laptop</strong></div>
    <div class="direct-link"><span>your SSH or file transfer (not Supgang)</span></div>
    <div class="peer-node"><strong>Your home computer</strong></div>
  </div>
  <figcaption id="anchor-caption">The anchor helps the laptop and home computer find each other. It never carries their application traffic; that travels directly or not at all.</figcaption>
</figure>

The anchor runs the same protocol in a mode built to receive connections
rather than chase them, and keeps more authenticated connections open. A new
address then has more places to travel, and two peers are more likely to share
an introducer. It does not accept public membership, publish a directory, or
relay SSH, files, or other general traffic.

An anchor is optional. It strengthens a fleet whose mobile members often lose
every direct connection. An unreachable anchor helps nobody.

## How a connection becomes trusted

Reaching an address proves only that something answered there. Supgang does
not call a peer connected until both sides prove their identities on that
specific connection.

The connection uses **QUIC** over UDP with **TLS 1.3**. The
answering computer presents a certificate. Its expected fingerprint is in the
signed address record, so a substituted certificate is rejected.

Both computers then sign a fresh, one-time challenge tied to this exact
encrypted connection; a captured proof from an earlier connection cannot be
replayed. Names and nicknames are conveniences for humans. Keys and signatures
decide who is trusted.

Signatures use **Ed25519**. Records
use canonical **CBOR**, a compact binary format similar in purpose to JSON.
Canonical means the same record has only one accepted encoding, so the bytes a
signature covers are unambiguous. Malformed, oversized, contradictory, or
unfamiliar records are rejected.

## What runs on each computer

One unprivileged program owns the network connection and local state.
`supgang run` operates in the foreground or as a per-user background service
through launchd on macOS or systemd on Linux. The other commands reach it
through a local socket that only the same user can open.

The first member creates the group, called a **hive**, and holds the root key
that approves new members and revocations. Each joining computer creates its
own device key; the private half never leaves that computer. Joining is an
offline exchange the user carries by a trusted method, such as a removable
drive or local file transfer.

The root key is held in an owner-only file on the founding computer.
Hardware-backed storage, offline-root operation, and root recovery are not yet
implemented.

With automatic router mapping disabled, Supgang communicates only with your
authorised computers. With it enabled, the only additional traffic is a
mapping request to the attached local router. The founding computer can revoke
a member; a revoked computer stops and refuses to start again with that
identity.

## Where it stops

Supgang improves the odds of reconnection. It guarantees no path through every
network.

- A carrier-grade NAT can put many customers behind infrastructure their home
  router cannot control. Common on mobile networks.
- Some routers do not support automatic mapping, and some networks assign a
  different public port for every destination. Peer introduction may fail on
  those networks.
- A firewall or network that blocks UDP blocks the connection.
- Two isolated computers that both move to unknown addresses, with no third
  authorised member reachable, cannot learn each other's new address.

## Current status

Published 0.1.0 is not a working wide-area release. Unreleased 0.2.0 alpha
adds address racing, bounded history, simultaneous attempts, router mapping,
peer introduction and the anchor role. Two Macs passed cross-network testing
over IPv4 through an owner-configured port forward. Later tests showed roaming
reconnection in about 7 seconds, transatlantic reconnection and an IPv6 path.

Unproven: Linux runtime; routes without an owner-configured forward; recovery
after the home's public address changes; NAT traversal without a forward;
and field use beyond two devices. There is no relay or rendezvous.

Source: https://agenxy.org/projects/supgang/architecture/
