opennap

Napster server in Zig. Stateless replicas; shared state and configuration live in Postgres.

Requires Zig 0.16, libpq, OpenSSL, and zlib. zust is fetched from GitHub via build.zig.zon.

zig build
zig build analyze   # Error-class memory-safety gate (UAF, leaks, null deref, uninit)
export DATABASE_URL=postgres://opennap:opennap@127.0.0.1:5432/opennap
./zig-out/bin/opennap -l 0.0.0.0 -p 8888 -W 8890

Heap ownership is zust-proven (safe.Box / safe.String). Server maps (users, channels, hotlist, per-connection files) own safe.Box values. Handlers borrow through findUser / findChannel (raw pointers). Byte buffers (sendbuf, recvbuf, WS framing, persist dumps) are safe.String, not a box-per-byte list. POD lists (fds, ports, pollfd) stay std.ArrayList. C/OpenSSL/libpq pointers stay raw.

Open http://127.0.0.1:8890/ in a browser and switch among OpenNAP chat, Napster v2.0 (/?ui=win), and the Mac look (/?ui=mac) without dropping the session. Classic Napster clients still use 8888.

Helm (Kubernetes)

Image and chart both publish to GHCR. The chart defaults to ghcr.io/e-jerk/opennap:latest and runs a SQL migration Job on helm upgrade (and first install).

helm upgrade --install opennap oci://ghcr.io/e-jerk/charts/opennap \
  --namespace opennap \
  --create-namespace \
  --version 0.37.1

Point a Napster client at the cluster’s LoadBalancer (or node IP) on port 8888. Stats is 8889. WebSocket is 8890 (/ chat, /?ui=win / /?ui=mac for the v2.0 client). TLS 6697 (RFC 7194 ircs-u) only listens if you set certs. Immediate TLS, then either Napster frames (ALPN naps/1) or IRC lines (no ALPN). WebSocket over TLS (wss) is -S PORT (443 in the chart). The metaserver is plaintext 8875 and immediate TLS 8876 (metaserver -T 8876).

Override the default password (and anything else) with --set or a values file:

helm upgrade --install opennap oci://ghcr.io/e-jerk/charts/opennap \
  --namespace opennap \
  --create-namespace \
  --version 0.37.1 \
  --set postgres.password=change-me

From this repo instead of OCI:

helm upgrade --install opennap ./chart --namespace opennap --create-namespace

Container image

ghcr.io/e-jerk/opennap (Alpine, linux/amd64 and linux/arm64). Pushes to GHCR on main and v*.*.* tags.

docker compose up --build
# or
docker pull ghcr.io/e-jerk/opennap:latest
docker run --rm -e DATABASE_URL=postgres://opennap:opennap@host:5432/opennap \
  -p 8888:8888 -p 8890:8890 ghcr.io/e-jerk/opennap:latest

WebSocket (naps/1)

-W PORT (config ws_ports) is a third transport for the same protocol. After an RFC 6455 upgrade with optional subprotocol naps-1 (browsers reject / in that token; naps/1 is still accepted from non-browser clients):

  • Each binary message is one little-endian Napster frame: [u16 length][u16 type][data].
  • Each text message is JSON {"tag":403,"data":"..."} (t / d aliases work). After the first text frame, the server replies in JSON.

GET without Upgrade serves one SPA. / and /?ui=chat are the OpenNAP chat look; /?ui=win and /?ui=mac (also /napster) are the e-jerk/napster-client recreation. Switching looks keeps the same login, channel, and chat. They speak naps-1 binary frames to this hub. This port is plaintext; put TLS in front (ingress / reverse proxy) if you want wss://.

Channel chat, emotes, and PMs are stored (Postgres when DATABASE_URL is set, otherwise in memory). Join replays the last history_replay lines (default 50). Clients can request more with IRCv3-style CHATHISTORY:

LATEST #lobby * 50
BEFORE #lobby t=1710000000 50
AFTER #lobby msgid=ab12cd34ef56aa00 50
AROUND #lobby t=1710000000 50
BETWEEN #lobby t=1710000000 t=1710003600
LATEST alice * 50

Tag 11000 is the request; 11001 is one line (kind target msgid ts nick text); 11002 ends the batch. CHATHISTORY TARGETS lists recent conversations. JSON clients also get msgid, time, kind, target, from, and text. Offline PMs to a registered nick are kept as memos (11005) and delivered at next login. AWAY is tag 11003 / 11004 and shows up in WHOIS. On WebSocket login the server sends 11007 (CHATHISTORY AWAY MEMO SERVER-TIME MSGID CAP SASL=PLAIN,GPG GPG).

Metaserver

metaserver hands clients one host / port pair (classic Napster directory). Plaintext is 8875. Immediate TLS is 8876 (-T), same reply after the handshake. Advertise a TLS Napster listener with tls:host:6697 (third line naps/1):

metaserver -l 0.0.0.0 -p 8875 -T 8876 -C tls.crt -K tls.key \
  tls:napster.example.com:6697 napster.example.com:8888

TLS_CERT / TLS_KEY PEM in the environment override the files. Helm: metaserver.enabled=true and metaserver.tlsSecret (a kubernetes.io/tls secret).

RFC 7194 (ircs-u)

TCP 6697 is the IANA ircs-u port. After the TCP connect, TLS starts immediately (not STARTTLS). Clients that send ALPN naps/1 keep speaking Napster frames. Typical IRC clients send no ALPN and get RFC 1459 / IRCv3 lines (NICK/USER/PRIVMSG/CAP). Users on TLS get umode +Z. Channel mode +TLS (+Z / +S) is TLS-only join. Optional client certificates are requested but not required; SHA-256 CertFP is shown in WHOIS (276). WHOIS also sends 671 for a secure connection.

There is no plaintext port-6667 listener.

IRCv3 (on Napster frames and ircs-u)

IRCv3 is the same capability set on every transport: new tags in the 11010+ range, JSON cmd aliases (cap, authenticate, resume, tagmsg, redact, edit), or IRC CAP lines on 6697. CAP and SASL are allowed before login.

TagRole
11010 / 11011CAP LS 302, REQ, ACK/NAK, END
11012 / 11013SASL PLAIN or GPG (key login)
11029 / 11030KEY SET|GET|DEL|PROVE / KEY PUB fingerprints
11014 / 11015BATCH around history (+id chathistory #lobby / -id)
11016–11018FAIL / WARN / NOTE when standard-replies is enabled
11019 / 11020TAGMSG (+typing=active, +draft/react=+emoji msgid)
11021 / 11022redaction by msgid
11023 / 11024edit by msgid
11025 / 11026session resume token (120s)
11027account-notify / WHOIS account
11028STS (port=6697 duration=2592000)

Advertised caps: sasl=PLAIN,GPG, draft/gpg, server-time, message-tags, echo-message, batch, labeled-response, account-tag, account-notify, extended-join, away-notify, standard-replies, sts, message-redaction, +draft/reply, +draft/react, +draft/typing, draft/resume.

GPG / E2E (draft/gpg): each nick may publish an Ed25519 signing key and X25519 encryption key (KEY SET then KEY PROVE after login, or SASL GPG for a new nick). Public chat is signed (+draft/sig= or JSON sig); the server relays the signature only to GPG-capable clients and adds +draft/sig-valid=1 when it verified the sender’s key. Private chat may be sealed as e2e:v1: (X25519 + AES-256-GCM) and signed over the plaintext. The server never decrypts sealed PMs; capable clients verify the signature after decrypt. Clients without the cap see the plaintext public line and [encrypted message] for sealed PMs. Classic clients keep working unchanged.

SASL GPG: AUTHENTICATE GPG → + → nick (or base64 nick) → server sends a base64 challenge document → client signs those bytes and sends the 64-byte Ed25519 signature (raw or OpenPGP packet, hex or base64). A new nick is bound to the pending KEY SET material. An already-registered password nick cannot be claimed this way — log in first, then KEY PROVE. Then login with * as the password. After SASL SUCCESS of either mechanism, login with * works. Key-only accounts reject password and SASL PLAIN. A resume token is sent as 11026 when draft/resume is enabled; RESUME <token> logs back in without the password.

The bundled chat page (src/ws_client.html) generates a per-nick keypair in localStorage. Leave the password empty for key login; type a password for the classic path (then the server will challenge to bind the browser key). /, /?ui=win, and /?ui=mac serve e-jerk/napster-client (bun package napster-web). Docker builds it in a bun stage and Zig embeds dist/index.html. Local zig build runs bun install via scripts/build-napster-client.sh. Log in with a nickname (empty password creates the nick). GET /meta (and metaserver -W/-S) is meta-1 JSON. Browser peers then transfer files over WebRTC into a folder chosen with the File System Access API.

Clients can prefix a command with @label=…;+draft/reply=msgid;+draft/sig=… (or JSON fields label / reply / sig / e2e).

const ws = new WebSocket("ws://host:8890/", ["naps-1"]);
ws.onopen = () => {
  ws.send(JSON.stringify({ cmd: "cap", data: "LS 302" }));
  ws.send(JSON.stringify({ cmd: "cap", data: "REQ server-time message-tags echo-message batch" }));
  ws.send(JSON.stringify({ cmd: "cap", data: "END" }));
  ws.send(JSON.stringify({ tag: 2, data: 'nick password 6699 "web" 3' }));
};

This software is released into the public domain. See UNLICENSE.