Funlink v1
Status: draft. The name and port range are provisional.
Funlink lets an application tell other local applications that it is running and which services it offers. A hub such as RustyFunPlayer can then offer the user a one-click “Connect” prompt instead of manual endpoint setup.
Funlink only handles discovery. The actual connection still uses the application’s existing protocol, such as the OFS WebSocket API or Buttplug.
Quick start
To announce your application, send this JSON every 5 seconds:
POST http://127.0.0.1:<port>/funlink/v1/announce
Content-Type: application/json
to each port from 37420 to 37429. Ignore connection errors: no hub is listening on that port. That is all a peer must do.
{
"id": "8d0c6a8e-3f0e-4c38-9a57-2f1d6b0c9e11",
"session": "f3a91c0e5b7d",
"name": "FapLand",
"version": "1.4.0",
"services": [
{ "protocol": "ofs-ws", "endpoint": "ws://127.0.0.1:8080/ofs" }
]
}
Optionally send POST /funlink/v1/bye on a clean exit so the hub removes the
entry immediately.
Terms
- Peer: an application that announces itself, for example FapLand.
- Hub: an application that receives announcements and offers to connect, for example RustyFunPlayer.
- Service: one endpoint that a peer offers, identified by a protocol.
The key words MUST, MUST NOT, SHOULD and MAY are used as in RFC 2119.
Transport
- HTTP/1.1 over TCP on the loopback interface, without TLS.
- Hubs listen on
127.0.0.1and bind the first free port from 37420 to 37429. - Peers connect to
127.0.0.1. They SHOULD NOT uselocalhost, which may resolve to::1first. - Bodies are UTF-8 JSON with
Content-Type: application/json. - If the environment variable
FUNLINK_PORTis set, hubs bind and peers send to that single port only. This is meant for tests and unusual setups.
Announce
POST /funlink/v1/announce
A peer MUST send an announce when it starts and then every 5 seconds while it runs. Each announce carries the complete record; there are no partial updates. Peers SHOULD use a request timeout of about 1 second.
Record
| Field | Required | Type | Rules |
|---|---|---|---|
id | yes | string | Stable for the peer. 1 to 64 characters from A-Z a-z 0-9 . _ -. A fixed name for the application is recommended, such as fapland or org.example.player; it also seeds the OFS port. A random UUID created on first run also works. |
session | yes | string | Random for each launch of the peer. 8 to 32 characters from A-Z a-z 0-9. |
name | yes | string | Display name, 1 to 64 characters. |
version | no | string | Display version, up to 32 characters. |
icon | no | string | data:image/png;base64,..., square, 128 px recommended, at most 512 px on each side. The whole URI is at most 64 KiB. |
services | yes | array | 1 to 8 service objects. |
ext | no | object | Application-specific data. Keys MUST be reverse domain names such as org.fapland. |
Service
| Field | Required | Type | Rules |
|---|---|---|---|
protocol | yes | string | A registered protocol name, or x-<vendor>-<name> for unregistered ones. |
endpoint | yes | string | Absolute URL. The host MUST be a loopback address: 127.0.0.0/8 or [::1]. The scheme MUST match the protocol. |
features | no | array | Up to 16 strings that describe optional capabilities. |
Response
On success the hub answers 200 OK:
{
"hub": { "id": "4b1e...", "name": "RustyFunPlayer", "version": "0.1.0" },
"supported": ["ofs-ws", "buttplug-ws"],
"state": "available"
}
state | Meaning |
|---|---|
available | The hub knows the peer and may offer it to the user. |
connected | The hub is connected to one of the peer’s services. |
dismissed | The user declined for this session. The hub will not prompt again until the session changes. |
unsupported | The hub cannot use any of the announced services. |
Peers MAY ignore the response. Peers that read it can, for example, show “Connected to RustyFunPlayer”.
Bye
POST /funlink/v1/bye
{ "id": "8d0c6a8e-3f0e-4c38-9a57-2f1d6b0c9e11", "session": "f3a91c0e5b7d" }
The hub answers 204 No Content and removes the entry. Sending bye is
optional; without it the entry expires.
Errors
Errors use an HTTP status and this body:
{ "code": "invalid_announce", "message": "services[0].endpoint must use a loopback host" }
| Status | code | Cause |
|---|---|---|
| 400 | invalid_announce | The record does not follow this specification. |
| 403 | forbidden | The Host or Origin header was rejected. |
| 404 | not_found | Unknown path, including unsupported versions. |
| 413 | too_large | The body exceeds 96 KiB. |
| 429 | rate_limited | Requests for the same id less than 200 ms apart, or more than 64 peers. |
Hub rules
A hub:
- MUST forget an entry 15 seconds after its last announce, or immediately on
bye. - MUST treat an announce with the same
idand a newsessionas a restart of that peer. - MUST reject requests whose
Hostheader is not127.0.0.1:<port>,localhost:<port>or[::1]:<port>. This blocks DNS rebinding. - MUST NOT connect to a service because of an announce alone. It connects only
after the user confirms, or after the user earlier chose to always connect
to that
id. - SHOULD prompt at most once per
sessionand SHOULD NOT prompt while it is already connected to a source. - MUST reject bodies larger than 96 KiB.
- SHOULD refuse connections from other users of the machine where the operating system names the owner of a loopback socket, as Linux does.
Browsers
Browser-based peers can announce with fetch. Because the body is JSON, the
browser sends a CORS preflight. A hub that accepts browser peers answers
OPTIONS with Access-Control-Allow-Origin set to the request origin,
Access-Control-Allow-Methods: POST and
Access-Control-Allow-Headers: Content-Type. Browsers may additionally ask
the user for local network access.
When an Origin header is present, the hub MUST show that origin in the
prompt and MUST store “always connect” decisions per origin and id, never per
id alone. A hub MAY reject all browser origins.
Local network
Everything above happens on one machine. A peer on another machine of the local network, such as a TCode device with Wi-Fi or a player on a Steam Deck, announces the same record through two transports instead:
- DNS-SD over multicast DNS (RFC 6762 and RFC 6763), the standard that
Bonjour and Avahi implement, under the service type
_funlink._udp.local. - The Funlink beacon: the record as JSON in a UDP datagram on port 37420, sent to a multicast group and as a broadcast.
Hubs that support the local network listen on both and merge what they hear.
A peer MAY use either transport or both; small firmware may prefer the beacon,
which needs no DNS stack, and DNS-SD makes the peer visible in standard
browsers such as avahi-browse or Bonjour Browser.
Discovery on the local network is a separate choice on both sides. A hub MUST NOT listen on the local network unless its user turned that on, and a peer announces there only when the application asks for it.
Endpoints
A peer does not know which of its addresses a hub reaches it by, so it writes
the host of each endpoint as 0.0.0.0, such as ws://0.0.0.0:8080/ofs. A hub
MUST replace the host of every endpoint with the source address of the packet
that carried the record, whatever host the record names. A record therefore
cannot point a hub at another machine. An IPv6 source address is written in
brackets, with a zone as in RFC 6874, such as ws://[fe80::1%25eth0]:8080/.
Services whose scheme does not name a network socket, such as unix or
serial, MUST be dropped; a record without other services is ignored. The
services of a local network record listen on a network interface, so anyone
on the network can connect to them, and peers SHOULD protect them
accordingly.
Record limits
A local network record is the record of Announce with these differences:
- It has no
icon. - Over DNS-SD it has no
exteither. - The whole record, encoded as described below, fits in 1200 bytes.
DNS-SD
A peer registers one instance of _funlink._udp.local:
- Instance name: the display name, cut to at most 54 bytes at a character
boundary, a space and the first 8 characters of the session, such as
Stroker f3a91c0e. Hubs ignore instance names. - SRV: target
funlink-<session>.local, with an A record of each of the peer’s IPv4 addresses. The port is the port of the first service. Hubs ignore the target and the port. - TXT, with
vfirst. Hubs accept the other keys in any order.
| Key | Required | Value |
|---|---|---|
v | yes | 1 |
id | yes | The record’s id. |
s | yes | The record’s session. |
n | yes | The record’s name. |
ver | no | The record’s version. |
p0 to p7 | p0 | Service N as its protocol, a space and its endpoint, such as ofs-ws ws://0.0.0.0:8080/ofs. |
f0 to f7 | no | The features of service N, separated by commas. |
Services are numbered from 0 without gaps; a hub stops at the first missing
p<N>. Each key=value string is at most 255 bytes, as DNS requires, and
the TXT data is at most 1200 bytes. Features MUST NOT contain commas in a
record announced over DNS-SD.
Timing:
- PTR, SRV and TXT records SHOULD have a TTL of 15 seconds and A records one of 120 seconds. Hubs do not rely on other TTLs than 0, so the defaults of an existing mDNS stack also work.
- A peer announces its records unsolicited when it starts, again 1 second
later, and whenever the record changes. It answers every query for
_funlink._udp.localby multicast after a random delay of 20 to 120 milliseconds, with the PTR record as the answer and the SRV, TXT and A records as additional records. On a clean exit it sends the same records with a TTL of 0. - A hub sends a query for the PTR records of
_funlink._udp.localto224.0.0.251:5353when it starts, 1 second later and then every 5 seconds. It MUST NOT list known answers, so that every peer answers each query. - A hub reads every response that carries a PTR record of
_funlink._udp.localwith the instance’s SRV and TXT records in the same packet, and MAY query SRV and TXT on their own when a response lacks them. A record with a TTL of 0 counts as a bye.
IPv4 is required. Peers and hubs MAY also use [ff02::fb]:5353.
Beacon
Every beacon datagram is one UTF-8 JSON object of at most 1200 bytes with the
fields funlink, which is 1, and type. Receivers MUST ignore datagrams
that are larger, are not such an object, have another funlink value, or
have an unknown type, without answering them.
The beacon uses UDP port 37420, the multicast group 239.255.37.20 and the
limited broadcast address 255.255.255.255. If the environment variable
FUNLINK_LAN_PORT is set, hubs and peers use that port instead; this is
meant for tests.
type | Sender | Other fields |
|---|---|---|
announce | Peer | The record: id, session, name, version, services, ext. |
bye | Peer | id, session. |
query | Hub | None. |
status | Hub | id and session of the peer, then hub, supported and state as in the response to an announce. |
{"funlink":1,"type":"announce","id":"sr6-a41c","session":"f3a91c0e5b7d","name":"SR6","services":[{"protocol":"tcode-udp","endpoint":"udp://0.0.0.0:8000"}]}
A peer:
- binds port 37420 with address reuse (
SO_REUSEADDR, andSO_REUSEPORTwhere it exists), so that several peers and hubs share it, and joins the multicast group on each IPv4 interface; a peer that cannot set address reuse, such as one written in a game engine without that option, MUST NOT bind the port, so that it never keeps a hub on the same machine from listening; it then answers no queries, and hubs find it by its next announce; - sends its datagrams from a second socket on a random port, so that answers reach it and not another program on port 37420;
- sends
announcewhen it starts and then every 5 seconds, each time to the multicast group and to the broadcast address; - answers a
querywith anannouncesent only to the query’s source address and port, after a random delay of 20 to 120 milliseconds, and at most once per second for each source address; - MAY send
byeto the group and the broadcast address on a clean exit.
A hub:
- binds and joins like a peer, and sends from a second socket on a random port;
- sends
queryto the group and the broadcast address when it starts, 1 second later and whenever the user asks to search again; - MAY send
queryto addresses that the user entered, which reaches peers on other subnets. It repeats these queries every 5 seconds, because the announces of such peers do not cross the router; - treats an
announcethat answers its query like any other; - answers each
announcewith astatussent only to its source address and port, at most once per second for each peer. Peers MAY ignore it.
Hub rules for the local network
On top of the hub rules, a hub:
- MUST ignore packets whose source address is not a loopback address, a
private IPv4 address (
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16), a link-local address (169.254.0.0/16,fe80::/10) or a unique local IPv6 address (fc00::/7). - MUST validate the record as an announce, except that endpoint hosts are replaced as described in Endpoints and not checked.
- MUST key entries by source address and
id. The same key heard over DNS-SD and the beacon is one entry; its record is the latest one heard, butextfrom the beacon stays until the beacon record changes or expires. - MUST ignore a local network record with the
idandsessionof a peer that announces over loopback HTTP, and drops such an entry when the loopback announce arrives later. - MUST treat a record with the
idandsessionof an existing entry but from another source address, such as from a peer with Wi-Fi and Ethernet, as a sign of life of that entry only. It neither creates a second entry nor changes the record or address of the first. - MUST forget an entry 15 seconds after it last heard the record by either
transport, or at once on
byeor a DNS-SD TTL of 0. - MUST NOT keep more than 64 entries from the local network, nor more than 8 from one source address, and ignores records for one key and transport that arrive less than 200 milliseconds apart. A peer announces over both transports at once, so the gap does not apply across them.
- MUST NOT act on
extdata of a local network record that names files, programs or processes, because it describes another machine. - MUST show the source address in the prompt and MUST store “always connect”
and “never ask” decisions per address and
id, never peridalone.
Compatibility rules
- Receivers MUST ignore unknown fields, unknown
statevalues, unknown protocols and unknown features. - Fields keep their meaning and type in all v1 revisions.
- Only incompatible changes create a new path, such as
/funlink/v2/. A peer MAY announce to several versions.
Protocol registry
protocol | Endpoint schemes | Description |
|---|---|---|
ofs-ws | ws, wss | OpenFunscripter WebSocket API. |
ofs-ws-extended | ws, wss | OpenFunscripter WebSocket API with device state and range edits. See ofs-ws-extended. Announced beside an ofs-ws service with the same endpoint. |
ofs-ws-fapland | ws, wss | Alias of ofs-ws-extended that FapLand announces. Hubs that support one of the two MUST support both. |
buttplug-ws | ws, wss | Buttplug protocol server, such as Intiface. |
vlc-http | http | VLC HTTP interface. |
mpc-http | http | MPC-HC web interface. |
whirligig-tcp | tcp | Whirligig timecode server. |
tcode-ws | ws, wss | TCode device over WebSocket. |
tcode-tcp | tcp | TCode device over TCP. |
tcode-udp | udp | TCode device over UDP. |
edi | http | A game that expects an EDI server at the endpoint. The hub serves it instead of connecting to it. |
mpv-ipc | unix | An mpv player’s JSON IPC socket. The endpoint’s path is the socket on this machine, such as unix://127.0.0.1/run/user/1000/mpv.sock. |
tcode-serial | serial | A TCode device on a serial port of this machine. The endpoint’s path is the port, such as serial://127.0.0.1/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0. The hub connects an output to it, beside any source. |
New entries are added by request with a short description and a link to the
protocol’s documentation. Names starting with x- need no registration.
Examples
An EDI game
A game with an EDI mod announces the edi service on the port it calls, and
tells RustyFunPlayer where it is installed. The paths are absolute paths of the
host system, so a game under Wine translates its Z:\ paths first. The program
and the configuration lie inside root, and the configuration is the game’s
EdiConfig.json. Use your own id; RustyFunPlayer recognizes the game by its
config, so its card replaces the one for the same game found by
rustyfunplayer-detect.
{
"id": "castle-of-temptation",
"session": "b81c4e0a92d3",
"name": "Castle of Temptation",
"services": [{ "protocol": "edi", "endpoint": "http://127.0.0.1:5000/" }],
"ext": {
"org.rustyfunplayer.edi": {
"root": "/games/Castle",
"executable": "/games/Castle/Castle.exe",
"config": "/games/Castle/Edi/EdiConfig.json"
}
}
}
Shell
curl -sS -X POST http://127.0.0.1:37420/funlink/v1/announce \
-H 'Content-Type: application/json' \
-d '{"id":"test","session":"abcdefgh","name":"Test","services":[{"protocol":"ofs-ws","endpoint":"ws://127.0.0.1:8080/ofs"}]}'
JavaScript (Node.js 18+ and Electron)
The same code runs in a browser, but RustyFunPlayer refuses browser requests (see Browsers).
const record = {
id: installId, // stored on first run
session: crypto.randomUUID().replaceAll("-", ""),
name: "FapLand",
version: "1.4.0",
services: [{ protocol: "ofs-ws", endpoint: "ws://127.0.0.1:8080/ofs" }],
};
function announce() {
for (let port = 37420; port <= 37429; port++) {
fetch(`http://127.0.0.1:${port}/funlink/v1/announce`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(record),
signal: AbortSignal.timeout(1000),
}).catch(() => {});
}
}
announce();
setInterval(announce, 5000);
Python
import json, secrets, time, urllib.request
record = {
"id": install_id, # stored on first run
"session": secrets.token_hex(8),
"name": "Example",
"services": [{"protocol": "ofs-ws", "endpoint": "ws://127.0.0.1:8080/ofs"}],
}
body = json.dumps(record).encode()
def announce():
for port in range(37420, 37430):
request = urllib.request.Request(
f"http://127.0.0.1:{port}/funlink/v1/announce",
data=body,
headers={"Content-Type": "application/json"},
)
try:
urllib.request.urlopen(request, timeout=1).close()
except OSError:
pass
# Run this loop on a background thread in a real application.
while True:
announce()
time.sleep(5)
Implementations
- RustyFunPlayer is a hub.
- FapLand announces its OFS bridge as
ofs-ws. - The libraries in this repository implement both roles.
Planned extensions
These are intentionally left out of v1:
- Coordination between several hubs, so that a service used by one hub is not offered by another.
- A peer request such as “connect me now” for a button in the peer’s UI.
- Pairing with keys, so that a hub can trust a peer on the local network across addresses and connect to it without asking.
- A hub that announces itself on the local network.