Skip to content

Protocol

David Reed edited this page Nov 20, 2026 · 2 revisions

This page is Wisp as holyWisp speaks it on the wire: how a connection opens, what the server advertises, how streams open and close, how flow control and backpressure work, the terminal streams, and the plain HTTP the same port answers. It is written for people who write or debug a client. The Wisp spec is the base; holyWisp follows wispurr's behaviour wherever the spec leaves room, so clients built for wispurr (@mercuryworkshop/wisp-js, epoxy, scramjet) work unchanged.

The options named here are listed with their ranges on Configuration. The limits that refuse a client are on Security-and-limits. WebTransport carries the same packets over HTTP/3; its own rules are on WebTransport.

Packets

Every Wisp packet is one binary WebSocket message:

type (u8) | stream_id (u32 LE) | payload

All integers are little-endian. Stream 0 is the connection itself.

Type Name Direction Payload
0x01 CONNECT client to server stream_type(u8) port(u16) hostname
0x02 DATA both the bytes
0x03 CONTINUE server to client buffer_remaining(u32)
0x04 CLOSE both reason(u8)
0x05 INFO both, v2 only, stream 0 major(u8) minor(u8), then extensions as id(u8) len(u32) meta
0xE1 LANE client to server, WebTransport only see WebTransport
0xE2 CREDIT client to server limit(u64)
0xE4 UPLOAD_CREDIT server to client limit(u64)
0xF0 Twisp resize client to server rows(u16) cols(u16)

Stream types in CONNECT: 0x01 TCP, 0x02 UDP, 0x03 Twisp terminal. A packet shorter than its 5-byte header is ignored. The codec is src/common/wisp.c; the private extensions are specified in docs/extensions.md.

Opening a connection

The client sends a WebSocket upgrade (GET, Upgrade: websocket, Connection: Upgrade, Sec-WebSocket-Version: 13, a Sec-WebSocket-Key) to any path. Before the 101, the server runs its admission checks (origin, client address, rate, reputation, connection caps); a refusal is an HTTP status, listed under Plain HTTP on the same port. The opening must be complete within handshake-timeout-ms (10000 ms), and on v2 that includes the INFO exchange.

Wisp v1

With no Sec-WebSocket-Protocol header, or with enable-v2 = off, the connection is v1. Right after the 101 the server sends one packet, the stream-0 CONTINUE, and nothing comes before it. Real output from a server on loopback with default settings:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
frame: 03 00 00 00 00 80 00 00 00

03 is CONTINUE, 00 00 00 00 is stream 0, 80 00 00 00 is 128: every new stream may receive 128 DATA packets before it waits for a CONTINUE.

Wisp v2

A client opts into v2 by sending a Sec-WebSocket-Protocol header with any token at all. The spec names no subprotocol, wispurr treats any non-empty header as v2, and epoxy sends a random UUID, so holyWisp goes by presence, not by the string wisp-v2. The first token of the header is echoed back as it was sent; a browser fails the handshake if the token it asked for does not come back.

The server then sends its INFO first. Without any password-user configured it sends the stream-0 CONTINUE right behind it, so v2 opens in as many round trips as v1. Real output, with motd = test relay and a UUID as the token:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: 3f2504e0-4f89-11d3-9a0c-0305e82c3301
frame: 05 00 00 00 00 02 01 01 00 00 00 00 05 00 00 00 00 04 0a 00 00 00 74 65 73 74 20 72 65 6c 61 79 e2 00 00 00 00 e3 04 00 00 00 00 08 00 00 e4 04 00 00 00 00 00 80 00
frame: 03 00 00 00 00 80 00 00 00

Read as: INFO on stream 0, version 2.1, then the extensions 0x01 (UDP, empty), 0x05 (stream confirmation, empty), 0x04 (MOTD, 10 bytes, test relay), 0xE2 (stream credit, empty), 0xE3 (stream limit, 2048), 0xE4 (upload credit, initial window 8388608 bytes). Then the CONTINUE of 128.

The client answers with its own INFO, which names the extensions it wants. Until that INFO is handled, the only packets the server acts on are INFO and CLOSE on stream 0; anything else is dropped. A client whose major version is not 2, or whose INFO does not parse, gets CLOSE 0x04 on stream 0 and the connection ends.

With a password-user configured, the CONTINUE waits for the client's INFO, because a hashed password is checked on a thread of its own and what the client sent meanwhile would be dropped. The INFO then looks like this (real output, one user configured, password-required = on):

frame: 05 00 00 00 00 02 01 01 00 00 00 00 05 00 00 00 00 02 01 00 00 00 01 e2 00 00 00 00 e3 04 00 00 00 00 08 00 00 e4 04 00 00 00 00 00 80 00

02 01 00 00 00 01 is the password extension with one byte of meta, 01: a password is required. A client in the wild reads INFO, sends its own and then reads the CONTINUE, which is there by then. The password outcomes are:

What the client did What it gets
v1, with password-required = on HTTP 426, wisp-v2 with authentication required
v2, no password, with password-required = on CLOSE 0xc2 (authentication required) on stream 0
v2, wrong user or password CLOSE 0xc0 (bad password) on stream 0
v2, the password checks out the stream-0 CONTINUE
v2, more than 64 hashed checks already waiting CLOSE 0x49 on stream 0

The client's password meta is user_len(u8) user password. How passwords are stored and checked is on Security-and-limits.

INFO extensions

Id Name When the server offers it Server's meta Client's meta
0x01 UDP allow-udp = on (default) empty empty
0x02 password any password-user is set required(u8) user_len(u8) user pass
0x04 MOTD motd is not empty the text
0x05 stream-open confirmation always empty empty
0xE1 lanes WebTransport sessions with webtransport-lanes of 2 or more lanes(u8)
0xE2 stream credit stream-credit = on (default) empty initial_window(u32)
0xE3 stream limit always on v2 max_streams(u32) empty
0xE4 upload credit upload-credit = on (default) and room in stream-queue-max initial_window(u32) empty

Unknown extension ids are skipped, never rejected, in both directions. The 0xE_ ids are holyWisp's own. Each one changes nothing until the client's INFO names it back, so a client that does not know them sees the spec's protocol plus entries it skips. v1 has none of them.

0x05 stream-open confirmation: when the client names it, a TCP stream gets CONTINUE(id, window) once its socket is connected (through an upstream proxy, once the proxy has answered), before any DATA. A stream that fails to open gets its CLOSE instead. UDP streams are never confirmed, since they have no connection and no CONTINUE window. The window value is the stream's remaining window: 128 by default, less any DATA packets the client sent while the stream was connecting.

0xE2 stream credit is flow control toward the client, in bytes, per TCP and Twisp stream. See Stream credit.

0xE3 stream limit tells the client how many streams it may have open at once: max-streams-per-conn (2048), or at most 16 for a client whose reputation is THROTTLE, and 0 for no limit. It does not change during the connection.

0xE4 upload credit is flow control toward the server, in bytes. See Upload credit.

0xE1 lanes and the server-opened stream exist only on WebTransport; see WebTransport.

Streams

CONNECT

A client picks a stream id (anything but 0) and sends CONNECT. The server answers only with a CLOSE if the stream cannot open, or with DATA once the remote sends something; there is no "opened" packet unless the client asked for 0x05. The client may send DATA right after CONNECT: the server queues it until the remote is connected.

The rules for a CONNECT, in the order the server applies them:

CONNECT Answer
on stream 0 nothing at all: a CLOSE on stream 0 would end the connection
hostname empty, over 255 bytes (over 4096 for a Twisp command line), or holding a NUL CLOSE 0x41
for an id that is already open the open stream is closed 0x41, and nothing new opens
the connection already has max-streams-per-conn streams CLOSE 0x49, nothing else held against the client
Twisp (0x03) the Twisp gate, see Twisp terminal streams
TCP with allow-tcp = off, or UDP with allow-udp = off CLOSE 0x48
any other stream type CLOSE 0x41
a hostname byte outside A-Z a-z 0-9 . - _ : [ ] CLOSE 0x41
over max-connects-per-source-per-second CLOSE 0x49
port 0 CLOSE 0x41
UDP with an upstream proxy and proxy-udp = refuse CLOSE 0x48
refused by the host or port filters CLOSE 0x48
a numeric name that is not a canonical IPv4 literal (0x7f.1, 2130706433, 1.2.3) CLOSE 0x41
an IP literal without allow-direct-ip, or one the egress policy refuses CLOSE 0x48

After that the name is resolved and each address is checked and dialled in turn; Security-and-limits has the policy. An example against a server with default policy, from holywisp-client -v:

$ printf 'hi\n' | holywisp-client -v -s ws://127.0.0.1:5789/ localhost 5782
connected: wisp-v1, window 128, 1 lane, stream credit 0, upload credit 0, stream limit 0
[stream 1] CLOSE host blocked (0x48)
$ printf 'hi\n' | holywisp-client -v -2 -s ws://127.0.0.1:5789/ '0x7f.1' 5782
connected: wisp-v2, window 128, 1 lane, stream credit 0, upload credit 0, stream limit 2048
[stream 1] CLOSE invalid stream info (0x41)

DATA

DATA for a TCP stream is bytes on the socket. DATA for a UDP stream is one datagram each way. DATA for an id the server does not have open (for example one it just closed) is dropped.

Toward the client, one read from the remote is split into as many DATA packets as it takes, each no larger than max-message-size less the 5-byte header and never more than 128 KiB of payload. A client holds a whole WebSocket message before it can use any of it, so smaller frames reach the page sooner.

From the client, a WebSocket message may be up to max-message-size (1 MiB + 5 bytes by default, so one 1 MiB DATA payload). A larger one closes the WebSocket with 1009.

CLOSE

A client's CLOSE for a stream gets no CLOSE back. A CLOSE on stream 0 from the client ends the connection. The server's CLOSE for a stream is final; DATA the client sends for it afterwards is dropped.

When a stream ends from the client's side, the server closes its socket toward the remote with a FIN, or with a reset in one narrow case: the stream is TCP and not through an upstream proxy, the remote has sent something since the client last did, nothing is queued toward the remote, and the kernel reports every written byte acknowledged. A reset leaves no TIME_WAIT on the server. A stream the remote ended, or one the server closed for its own reasons, always gets a plain close. macOS and Windows always close plainly.

Close reasons

These are the spec's codes. The table says when holyWisp sends each.

Code Name When holyWisp sends it
0x01 unknown an internal failure: out of memory, or a lookup that could not be queued for a reason other than the client's share
0x02 voluntary the remote closed its end (EOF)
0x03 network error a socket error on an open stream, a reset by the remote
0x04 incompatible the client's INFO has another major version, or does not parse (stream 0)
0x41 invalid stream info a malformed CONNECT, a bad hostname, port 0, a duplicate stream id, a Twisp command that does not split
0x42 unreachable the name did not resolve (or not within connect-timeout-ms), no route, a UDP port that answered "port unreachable", no WARP tunnel for the stream
0x43 no response the connect timed out (connect-timeout-ms, 15000 ms), or an upstream proxy took the connection and never answered
0x44 connection refused the remote refused the connect (RST), or the proxy reported it refused
0x47 transfer timeout an open TCP stream whose remote stopped answering: keepalive probes start after 60 s of silence, one every 15 s, and after 4 unanswered the stream is closed
0x48 blocked the egress policy, the host or port filters, direct IP without allow-direct-ip, a stream type that is off, UDP with a proxy and proxy-udp = refuse, a destination whose reputation is STRICT, Twisp refused
0x49 throttled a rate or cap ran out (per-source CONNECT rate, stream cap, SYN caps, per-destination rate, lookups per IP), a queue toward the remote passed stream-queue-max, or the password checks are full
0xc0 bad password the v2 password did not match (stream 0)
0xc2 authentication required password-required = on and the client sent no password (stream 0)

A UDP stream gets 0x42 as soon as the socket reports the port unreachable, whether a send or a read collects the error. Troubleshooting goes from a close code to its likely cause.

Flow control

Flow control has one job: a client sending as fast as it can into a remote that reads slowly is slowed down, never closed. There are two schemes for uploads (CONTINUE, which every client has, and upload credit, which a v2 client can ask for) and one for downloads (stream credit, v2 only).

The CONTINUE window

The window is counted in DATA packets per TCP or Twisp stream, not in bytes. A new stream may send as many packets as the stream-0 CONTINUE said. When it has sent them all, it waits for a CONTINUE(id, n) and may then send n more. UDP streams are never counted.

The advertised window is buffer-remaining (128), capped so that a full window of maximum-size packets fits in stream-queue-max: by default 128 MiB / 1 MiB = 128, so the cap does not bite. Lower stream-queue-max and the server logs buffer-remaining 128 capped to N at start. The server sends the refill CONTINUE only once the stream's bytes have left for the remote. While bytes toward the remote are still queued, it holds the CONTINUE back. That is why the queue never holds more than one window, and why a client inside its window is never closed 0x49.

The value in a refill CONTINUE is computed per stream, so that ten streams do not make the server buffer ten windows. It is upload-window (by default ws-write-high-water, 8 MiB) divided by the number of streams that are uploading, divided by the packet size this client actually sends, and then clamped between 4 and the advertised window. With the defaults, one stream sending 64 KiB packets gets 8 MiB / 64 KiB = 128; ten such streams get 12 each. The stream-0 CONTINUE always carries the full advertised window. Raise upload-window for fast uploads over a long path when ws-write-high-water is kept short for latency.

Upload credit

With 0xE4, a v2 client counts bytes instead of packets. The limit is absolute (bytes sent since the stream started) and only rises, so the server can grant early and a stream whose remote keeps up never runs dry. Without it, every window costs a round trip with nothing in flight.

The server's initial window is upload-window, at least 64 KiB and at most stream-queue-max less one maximum packet and 4 bytes. If stream-queue-max has no such room, 0xE4 is not offered and the log says so. The client may begin a DATA packet whenever it has sent less than the limit, and that packet may overshoot the limit by its own length. The server sends UPLOAD_CREDIT(id, limit) once the bytes that reached the remote's socket, plus the stream's share of upload-window, would raise the limit by half a share or more. The share is upload-window divided by the connection's open streams, at least 256 KiB and at most the initial window. A stream under upload credit gets no refill CONTINUE; the stream-0 CONTINUE and stream confirmation are still sent. holywisp-client --upload-credit asks for it.

Stream credit

With 0xE2, the client grants each TCP and Twisp stream a byte budget toward itself, like the receive window of a native socket. The client names it with initial_window(u32); a window under 16384 is 16384, and a meta shorter than 4 bytes counts as no request. The client then sends CREDIT(id, limit), the total payload the stream may have sent from its start. A CREDIT that is lower or repeated, on stream 0, for a stream that is not open or is UDP, on a session without credit, or under 8 bytes is ignored. Over WebTransport, a CREDIT in a datagram is dropped.

The server reads a stream's remote only while the stream has credit left, and asks for no more than that, so it never sends past a limit. A stream that is out of credit costs its neighbours nothing: the bytes wait in the remote's kernel buffers. Its CLOSE 0x02 waits too, until the grant that lets it read the end. A held stream whose remote resets is closed 0x03. holywisp-client --credit BYTES asks for it.

Backpressure

Toward a slow client

What the server has queued for a client is counted as wbuf plus any payloads waiting in relay pipes (on WebTransport, what QUIC has not yet sent). The thresholds hang off ws-write-high-water (8 MiB):

Queued for the client What happens
more than ws-write-high-water every stream on the connection stops reading its remote
under a quarter of it the streams read again
more than twice it the server also stops reading from the client, since pongs, CLOSEs and CONTINUEs are answers to what it sends
back at the mark the server reads from the client again
nothing moved for client-write-timeout-s (120 s) the connection is closed

idle-timeout-s (0, off) closes a connection that has no open streams and has sent nothing for that long, with WebSocket code 1001.

Toward a slow remote

Bytes the client sent that the remote has not taken wait in the stream's queue. Past stream-queue-max (128 MiB) the stream closes 0x49; a client that keeps to its window never reaches that. Across one connection, conn-queue-max (256 MiB, at least stream-queue-max) bounds the sum: past it the server stops reading from the client and resumes at half.

Across all connections, server-queue-max (4 GiB) and server-queue-max-per-ip (1 GiB) bound what is queued in both directions, counted in whole MiB per connection. A connection that would pass either stops reading its client and its remotes until it drains or the budget frees. Nothing is closed or dropped for it; /stats counts queueBudget.pauses.

bandwidth-limit-kbps (0, off) paces a client address the same way: it pauses, never drops. See Security-and-limits.

WebSocket rules

Client frame Server's answer
unmasked, reserved bits set, an unknown opcode, a continuation with no message open, a new message inside a fragmented one close 1002
a text frame close 1003
a message over max-message-size close 1009
ping pong with the same payload
close the close is echoed with the client's code

Server frames are never masked. Fragmented binary messages are reassembled up to max-message-size.

Twisp terminal streams

Twisp runs a command on a pseudo-terminal and relays it as a stream, as wispurr's terminal streams do. It is a remote shell: the command line is the client's, it runs as the server's user, and nothing in the config narrows what it may be. It is off unless enable-twisp = on, and the server refuses to start with it unless enable-v2 is on and at least one password-user exists. Windows has no pseudo-terminal, so it refuses enable-twisp outright.

A client opens one with a CONNECT of stream type 0x03. The hostname field holds the command line, up to 4096 bytes with no NUL (a TCP or UDP hostname stays at 255), and the host character rules do not apply to it; the port is ignored. The line is split as a shell would split it (single quotes literal, double quotes with backslash escapes, a bare backslash escaping the next character), up to 64 arguments, with no variable or glob expansion. argv[0] is looked up on PATH, and the child gets TERM=xterm-256color and none of the server's descriptors.

Twisp CONNECT Answer
enable-twisp = off CLOSE 0x48, not scored
a v1 client, or a v2 client that did not authenticate CLOSE 0x48, a twispNoAuth reputation event (40 points)
over max-connects-per-source-per-second, counted with the client's TCP and UDP CONNECTs CLOSE 0x49, a violation and a burstRate event
an empty command, or an unmatched quote CLOSE 0x41
the terminal could not be made CLOSE 0x03

Once open, DATA is the terminal's input and output, with the CONTINUE window and stream credit as for TCP. A resize packet (type 0xF0, the stream's id, rows(u16) cols(u16)) sets the window size. The stream ends when the process exits; a CLOSE from the client hangs up the terminal and kills the process if that does not end it. The systemd unit's sandbox applies to whatever the shell starts; Security-and-limits has the gate in full.

Plain HTTP on the same port

Any request that is not a WebSocket upgrade is answered as plain HTTP, always with Connection: close and Cache-Control: no-store. After a reply is queued the server reads nothing more from that connection.

Request Answer
GET /health 200, {"status":"ok"}
GET /stats 200, the counters as JSON (Stats-and-monitoring)
GET /webtransport.json with webtransport = on 200, the URL and certificate hashes, Access-Control-Allow-Origin: * (WebTransport)
GET / with serve-webclient = on (default) 200, the built-in browser client
anything else 200 with non-ws-response (a one-line notice), or 426 when it is empty
a malformed head 400 bad request

A path matches alone or followed by a query string: GET /health?probe=1 is /health and GET /?q=1 is the web client, while /healthz, /health/x and /x?/health are anything else.

Malformed means anything that would make the parsed headers differ from what was sent: more than 48 headers, a name that is not a token, a continuation line, a NUL or bare CR in a value, or a head over 8 KiB.

An upgrade can also be refused before the 101: 429 at accept for max-handshakes-per-ip, 403 for the origin list or a STRICT reputation, 400 for a cut forwarding header, 429 with Retry-After for the per-address rate and connection caps, 503 at max-concurrent-connections, and 426 for v1 with password-required. Admission at the upgrade has the order and the keys; Troubleshooting has the bodies and the fixes.

Real output, for a server with --non-ws-response "" and --serve-webclient off:

$ curl -i http://127.0.0.1:5255/
HTTP/1.1 426 Upgrade Required
Content-Type: text/plain; charset=utf-8
Content-Length: 27
Cache-Control: no-store
Connection: close

websocket upgrade required

Checking it yourself

holywisp-client -v prints what the server negotiated and every packet it receives, which covers most client debugging:

$ printf 'hello\n' | holywisp-client -v -2 --confirm -s ws://127.0.0.1:5398/ 127.0.0.1 5782
connected: wisp-v2, window 128, 1 lane, stream credit 0, upload credit 0, stream limit 2048, motd: test relay
[stream 1] CONTINUE 127
[stream 1] DATA 6 bytes
hello

(That server had --allow-loopback --allow-direct-ip and an echo service on port 5782. The confirmation says 127 because the client had already sent one DATA packet while the stream connected.)

To see the raw opening bytes, this Python script sends an upgrade and prints each frame the server sends in its first second. Pass a token as the second argument for v2:

import socket, sys
port, proto = int(sys.argv[1]), (sys.argv[2] if len(sys.argv) > 2 else None)
s = socket.create_connection(("127.0.0.1", port))
h = ("GET / HTTP/1.1\r\nHost: x\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n"
     "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nSec-WebSocket-Version: 13\r\n")
if proto:
    h += "Sec-WebSocket-Protocol: %s\r\n" % proto
s.sendall((h + "\r\n").encode())
s.settimeout(1)
buf = b""
try:
    while chunk := s.recv(65536):
        buf += chunk
except socket.timeout:
    pass
i = buf.index(b"\r\n\r\n") + 4
print(buf[:i].decode().rstrip())
b = buf[i:]
while len(b) >= 2:
    n, o = b[1] & 0x7F, 2
    if n == 126:
        n, o = int.from_bytes(b[2:4], "big"), 4
    print("frame:", b[o:o + n].hex(" "))
    b = b[o + n:]

The tests that hold this behaviour are tests/test_wisp.c (the codec), tests/test_e2e.c (the real server and client) and tests/ext_cases.h (the extensions over both transports).

Clone this wiki locally