Skip to content
Dashboard

Connector, relay and API

View as Markdown

Every endpoint, a Paper server or a Velocity proxy, at home behind NAT or in a cluster, should be reachable for players without an open port and without Minekube running anything per server. Three parts do that.

The connector, inside the server’s process

Section titled “The connector, inside the server’s process”

The connector is a Rust library with iroh, loaded into the JVM through Java’s Foreign Function and Memory API (FFM). It runs inside Paper and Velocity, with the Minekube plugin.

  • One connection, a stream per player. The connector holds one iroh connection to its relay. Each player is a stream on it: no handshake per join, and one player does not hold up another.
  • Into the platform as a local connection. Each stream reaches the server as a local Netty connection, through the server’s own channel setup, so ViaVersion and Velocity’s handlers apply, and with the player’s real address.
  • A key is its identity. On its first start the connector creates a key in the plugin folder. The registry knows which network the key belongs to. Code addresses servers by their labels, not their keys, so setting a server up again, moving it or changing its key changes no code.
  • No Connect plugin needed. A server or proxy with the Minekube plugin brings its own connector, so it does not need the Connect plugin and should not load it as well. The Connect plugin stays the way online for servers without the Minekube plugin.
  • A narrow boundary. Bytes cross between Java and Rust through a handful of calls, with backpressure in both directions and no thread per player. No panic crosses the boundary.

Why in the process and not next to it: hosting panels that run one container per server, such as Pterodactyl and Pelican, end every process in the container when Java exits. A companion process would not outlive anything there; it would only cost memory. In the process, the fixed price is one iroh connection per endpoint.

FFM is final from Java 22 on, so the connector loads on servers running Java 22 or newer. The plugin jar carries native libraries for Linux (x64 and arm64), macOS (arm64 and x64) and Windows (x64), built in CI; loading them is not yet tested on every platform.

Relays: they pass bytes and understand nothing

Section titled “Relays: they pass bytes and understand nothing”

A relay takes the player’s TCP connection, reads the hostname from the handshake, much like SNI in HTTPS, picks a healthy instance of that network, opens a stream to its connector and copies bytes both ways.

  • Every network shares a few relay addresses. A network needs neither a public IP nor an open port.
  • Players’ traffic stays theirs. In online mode the connection between client and server is encrypted end to end, so the relay cannot read or inject anything. It sees metadata: addresses, hostnames, times and amounts.
  • It runs no customer code. Network rules run in the network’s own runtimes.
  • It keeps working without the Minekube API. It caches the API’s answers and serves joins from the cache when the API is unreachable.
  • Endpoints without outbound UDP reach it through iroh’s relay service over HTTPS, which runs inside the relay too.
  • Low latency comes from where the relay is, not from anycast. The route from player to server is fixed; a relay close to the server lies almost on it. The connector measures the latency to every relay at start and takes the nearest as its home.

A relay is small, so relays are small virtual servers in a few regions, two per region behind a health check. Anycast is planned as a paid tier for failover, not for latency.

The Minekube API is a Worker with Durable Objects. Its registry is two kinds of them: one directory that maps every key to its network and holds pending claim codes and the relays, and one object per network with its instances, their labels, load and home relay. A request goes from the Worker to exactly one object; no object calls another in a player’s path.

  • Joining a network. Always with the server’s consent: an invite it shows once (mk network invite), a token its environment gives it that a trust rule covers (as below), or the code a new connector logs while it belongs to no network (mk claim <code> --network <name>; 8 characters without look-alikes, valid for 15 minutes). An owner cannot add a key without the server, since a key alone is public. Let servers in shows each way.
  • System labels such as platform and version are set by the registry, not by the connector.
  • A signed control channel. Each instance keeps a WebSocket to its network’s object, signed with its key, and reports its load every 10 seconds. Hibernation keeps an idle channel almost free.
  • One source for types. The messages between Cloudflare and Rust are one Effect Schema, turned into JSON Schema and from there into Rust types; CI fails if they drift.

An instance’s identity should be checkable outside Minekube too, with standard tools and without asking us. So every network is an OpenID Connect issuer, hosted by the Minekube API:

  • Its keys are public. https://<api>/n/<network>/.well-known/openid-configuration and /jwks list the Ed25519 keys of the network’s members, each with its instance ID as kid. A token an instance signs with its own key can be checked anywhere with any JWT library, for as long as the instance belongs to the network. A bundle asks for one with Instance.token, to call a backend of its own: Authenticate servers to your backend.
  • Servers join with the token their environment gives them. Instead of a claim code, a server can show the token it already has: a Kubernetes service account token, or a CI job’s OIDC token. The network keeps trust rules: the issuer, the audience, the subject (exact or by prefix) and, for an issuer the registry cannot reach, such as a private cluster’s, that issuer’s key set. mk trust add, mk trust list and mk trust remove manage them. In connector.json, "join": {"network": "<network>", "token": "<file>"} names the token file. The connector reads the file fresh on each attempt, since projected tokens rotate, and posts the token signed with its own key; the registry checks it against the issuer’s published keys, and when a rule matches, the key becomes a member. No Minekube secret is stored on the server.
  • Keep such tokens narrow. The environment’s token is not bound to the instance’s key, so a rule should require an audience of its own (minekube) and short-lived tokens, as Kubernetes projects them.
  • Labels from the rule. mk trust add --labels game=parkour (and mk network invite --labels) gives every server it lets in these labels from the registry, so one rule decides which servers a version reaches.
  • Another network as the issuer. mk trust add --network-issuer --issuer https://<api>/n/<network> lets servers of another network move over with a token of their own. Write the issuer exactly as that API does; its keys always come from there, so a server it lets go stops counting, and a token lets in only the server whose key signed it. Without --network-issuer, a rule for an issuer whose path ends in /n/<name>, on any host, is refused: it would take any member’s token for any server.
  • A removed rule takes its servers along. mk trust remove removes the rule and, in the same step, the servers it let in: out of the key set, their channels closed, and refused however fast they reconnect. mk instances remove <id> takes out one server; one a rule still covers joins again with its next token, and mk says so.
  • Planned: tokens for players, so a network’s website, shop or forum can offer “sign in with our server”; and a signing key of the network’s own for statements the network makes itself.

Rights stay primitives here too: a verified token says who is calling; what a network does with that is up to its own routing.

Latency through the relay, the connector’s memory, the relay under load, start and restart times and a change of network mid-session were measured on one machine. The numbers, with what, where and when, are on Performance.

Was this helpful?