pkarr

Relays

In UDP-less environments (like web browsers, virtual machines, containers and firewalled networks) clients need to rely on a remote server that can relay their PUT and GET messages.

API

Public relays need to setup cors headers.

PUT

Request

PUT /:z-base32-encoded-key HTTP/2
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, PUT, OPTIONS
If-Match: 1741107004412159

<body>

Response

HTTP/2 204 NO CONTENT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, PUT, OPTIONS	

Body is described at Payload encoding section.

On receiving a PUT request, the relay server should:

  1. Encode the seq and v to a bencode message as follows: 3:seqi<sequence>e1:v<v's length>:<v's bytes>
  2. Verify that the sig matches the encoded message from step 1, if it is invalid, return a 400 Bad Request response.
  3. Perform the DHT Put request as defined in BEP0044, optionally using the If-Match as the CAS field, where the header value is the utf8-encoded u64 timestamp.
  4. If the DHT request is successful, return a 204 No Content response, otherwise if any error occurred return a 500 Internal Server Error response.

Errors

GET

Request

GET /:z-base32-encoded-key HTTP/2
If-Modified-Since: Fri, 18 Oct 2024 13:24:21 GMT

Response

HTTP/2 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, PUT, OPTIONS
Content-Type: application/pkarr.org/relays#payload
Cache-Control: public, max-age=300

Last-Modified: Fri, 18 Oct 2024 13:24:21 GMT

<body>

Cache-Control header would help browsers reduce their reliance on the relay, the max-age should be set to be the minimum ttl in the resource records in the packet or some minimum ttl chosen by the relay. If-Modified-Since can be sent by the client to avoid downloading packets they already have, when the relay responds with 304 Not Modified.

Body is described at Payload encoding section.

On receiving a GET request, the relay server should:

  1. Perform a DHT mutable GET query as defined in BEP0044
  2. Concat the sig, big-endian encoded seq, and v.
  3. If no records were found, respond with 404 Not Found.

Errors

Payload

Relay payload is a subset of the Canonical encoding, omitting the leading public key:

RelayPayload = signature timestamp dns-packet

signature   = 64 OCTET ; ed25519 signature over encoded DNS packet
timestamp   =  8 OCTET ; big-endian UNIX timestamp in microseconds
dns-packet  =  * OCTET ; compressed encoded DNS answer packet, less than 1000 bytes