# How messages travel

> The mesh, the relay, and what each can see.

## Direct links and the mesh

Each browser keeps direct links to a few others, about 6 (4 on phones), not to everyone. A message to a peer you are not linked to is forwarded hop by hop through other browsers in the room. That keeps a 30-peer room cheap for every browser, and it means a message to one peer may pass through other peers' browsers.

> **Diagram: A room of eleven peers: each is linked directly to a few others, and one link goes through the relay.** Peers p1 to p11 in one room, p7 marked as you. Each has a few direct links, none links to everyone. The introducer, outside the room, is idle. The relay, outside the room, carries the one link between p7 and p9. A message travels on the link from p11 to p7.

Messages sent with `send` and `sendReliable` are **sealed**: the browsers in between cannot read or alter them. `broadcast` is signed by its sender, so it cannot be forged, but it is not sealed; see [security and privacy](https://jsflow.com/docs/guides/security-and-privacy.md).

## The relay

When two browsers cannot connect directly (strict NATs, some corporate networks), their link goes through jsflow's relay (TURN). This needs nothing from you: credentials come with each join. On networks that block UDP the relay falls back to TCP and TLS on port 443.

> **Diagram: When two peers cannot link directly, their link goes through the relay, which sees only ciphertext.** p7 (you) and p9 are in the room with p3 and p8, which link to them directly. Between p7 and p9 the direct link is blocked (a cross). A dashed link runs from p7 down to the relay, outside the room, and back up to p9. The relay sees only ciphertext.

Relayed traffic is the part of jsflow that costs bandwidth, so it is metered separately from [peer-minutes](https://jsflow.com/docs/guides/limits.md). Whether links in your rooms are direct or relayed is visible in the dashboard.

You can send everything through the relay on purpose, so that peers never see each other's IP addresses: join with `iceTransportPolicy: 'relay'`. See [security and privacy](https://jsflow.com/docs/guides/security-and-privacy.md).

## Reading the diagrams

> **Diagram: The key to the diagrams: peers, direct and relayed links, the introducer, and a message in flight.** Peers: a laptop, a phone, a dot for small sizes, each in its peer colour with its id; an away peer drawn hollow and grey with no links; a gone peer is not drawn. Lines: direct (solid), relayed (dashed, through the relay), the introducer's touch (dotted, only during a join), the room boundary (dash-dot). Live: a message in flight in the lamp colour, a sealed message with a lock, and a route in ink with arrows and hop numbers.

Source: https://jsflow.com/docs/concepts/how-messages-travel/
