# Entry and routing

> How a player's connection finds a server in a Minekube network - the relay reads the typed address and picks an entry instance that takes players - and why the network decides where players go while Minekube only guarantees identity, the boundary and verified facts.

> **Preview: Connect in the Minekube plugin:**
> This page describes networks in the Minekube plugin, the next generation of Connect. Today's Connect plugin and its `<endpoint>.play.minekube.net` addresses are described in the [Connect docs](https://minekube.com/guide/) and keep working. [Networks in the Minekube plugin](https://minekube.com/guide/networks/) compares the two.

Entry is how a player's connection gets into a [network](https://minekube.com/guide/networks/concepts/network): from the address they typed to one instance. Routing is everything after that: which server they play on, where they go after a kick, who may join at all.

Minekube handles entry the same way for every network. Routing belongs to the network.

## From the address to the network

A Minecraft client sends the address the player typed in its first packet, the handshake, much like a browser sends the host name in HTTPS. The [relay](https://minekube.com/guide/networks/concepts/relay) reads that packet and nothing after it.

- **The first label of the address names the network.** `my-network.g.minekube.net` leads to the network `my-network`.
- **Any other address leads nowhere.** The relay turns the player away with "This address does not lead to a Minekube network."

Hostnames under a network, such as `arena.my-network.g.minekube.net`, and custom domains that point at a network are planned.

## Picking an entry instance

The relay asks the registry for the network's online entry instances: the members labelled `minekube.com/entry=true`. It caches the answer, so most joins never wait for the registry, and joins keep working from the cache while the registry is unreachable.

1. **It keeps the instances that take players:** online, ready, and not full.
2. **It tries the one with the most free slots first.** An instance without a player limit counts as having the most.
3. **It opens a stream to that instance's connector.** If that fails or takes too long, it tries the next one.
4. **It passes the bytes,** after a short preamble with the player's address, the typed host name and the network. The server reads the handshake itself and sees the player's real address.

When no entry instance takes the player, the server list shows the network as offline, and a join ends with "No server of `my-network` is reachable right now. Try again in a moment." The next player's join asks the registry again.

## Behind the entry

What happens after the entry instance depends on the network's shape.

- **With Velocity,** the proxy is the entry instance. It knows its backends by name, and each name stands for a [label selector](https://minekube.com/guide/networks/labels). When the proxy connects a player to `lobby`, its connector asks the registry for the instances that match, picks a ready one with the most free slots and opens a stream to it, connector to connector. A [proxy bundle](https://minekube.com/games/write/proxy-bundles) decides `/lobby` and where kicked players go, with Velocity's own events.
- **Without a proxy,** each Paper server labelled as an entry is a way in, and players stay on the server they entered. Moving players between Paper servers by a transfer through Minekube host names is planned.

## What the network decides and what Minekube guarantees

Who may go where is not Minekube's decision. A whitelist, bans, a lobby that only accepts players from the hub, a partner network, or a server open to everyone: each network writes these rules as code. Minekube guarantees only what no network can build for itself.

| Minekube guarantees | Status |
| --- | --- |
| **Identity.** Every instance has a key, and the registry says with authority which network it belongs to. | Built |
| **The network boundary.** A connector accepts streams only from Minekube's relays and from instances of its own network. | Built, and tested against the registry |
| **Verified facts.** A routing decision gets only what is true: the player's UUID and name after Mojang's check, their address from the relay, the host name they typed, and where they came from. | Planned |
| **An origin that cannot be forged.** An instance that sends a player on signs a token with its key; the target checks it through the registry. Without a valid signature, the origin is empty, never guessed. | Planned |
| **Rejection.** A network can turn a player away wherever the routing question is asked. | Planned |

| The network decides | Where, today |
| --- | --- |
| Who may join, and who is banned | In the entry instance: a proxy bundle on Velocity, or a game on Paper |
| Which server a player lands on | Velocity's server names and their selectors, and the proxy bundle |
| Where a player goes after a kick or when a server stops | The proxy bundle on Velocity |
| Queues, parties, and anything shared between servers | Network code |

Why primitives and not policy: any rule Minekube built in would be wrong for some network, and a network could not change it. A few guarantees that cannot be faked are enough for every rule above to be a few lines of a network's own code. Minekube's own network features are planned the same way, as Effect bundles on the same public SDKs, with no private path.

## The planned routing question

Wherever a network does not know where a player should go, such as a join, a server that went away, a kick or the waiting room, it is planned to ask one question. The reason is a tagged union, and the answer is data:

| Answer | Means |
| --- | --- |
| `Route.To(selector)` | To a matching instance. Whether that happens inside the session or by a transfer is the system's concern. |
| `Route.Hold` | Hold the player until something happens, with a time limit and a next answer. |
| `Route.Kick(message)` | Disconnect the player, with a message. |

The network's answers are planned to come from a routing bundle, Effect code that runs on Cloudflare. Because the answers are data, the relay can cache them, a proxy can keep the last ones for when it cannot reach the network's code, and no separate rule language is needed. A waiting room in the relay, which holds a player while no entry instance is ready, is planned with it. Today, entry needs an online entry instance.

## Related

- [Networks by design](https://minekube.com/guide/networks/network-model): the design behind routing, and the network shapes.
- [Labels and selectors](https://minekube.com/guide/networks/labels): how Velocity finds its backends.
- [Relay](https://minekube.com/guide/networks/concepts/relay): the part that does the entry.
