+++
title = "Routing"
weight = 4
+++

Meshy supports two routing strategies for delivering direct messages: **Classic** and **Smart**. You can set a global default in [Settings > Routing and Messaging](@/guide/settings.md#routing-and-messaging) and optionally override it for individual contacts in the [contact detail dialog](@/guide/contacts.md#routing).

## Classic Routing

Classic routing is very similar to the behavior of the official client. If there is no established path between you and the contact, the message is flood routed with up to 3 attempts. If an established path exists, it is used to route the message with up to 4 attempts. The 5th attempt is flood routed unless **Automatically Reset Path** is disabled. If no attempt is successful, it switches to flood routing and tries to find a new path.

If an established path exists, it is pre-filled in the **Out Path** field in the form of comma-separated hex hop identifiers (e.g., `9a,74` for 1-byte hashes, `9a3b,744c` for 2-byte). The hash size is auto-detected from the hop length.

Classic routing allows you to:

- **manually set a path** by typing it in the **Out Path** field.
- **reset the path** when you know the established path is outdated and you would like to directly switch to flood routing to discover a new one.
- disable **Automatically Reset Path** when you don't want to automatically switch to flood routing after failed delivery attempts. Useful in situations when the established path is not stable, but you still trust it to deliver the message and want to avoid flood routing.
- **force flood** when you only want to use flood routing without establishing a path. Please note that the flood routing is very expensive for the mesh network and should be avoided unless necessary.
- **show Path on Map**, which visualizes the route on a map with colored markers at each hop.

## Smart Routing

Smart routing tries to solve the main problem with classic routing, which is that it uses only one path for delivery attempts. Instead, it uses a list of recently successful paths and intelligently selects the best one for each attempt.

If there are no available paths on the list, it uses flood routing with up to 3 attempts, like the classic routing. If delivery is successful, the path used is added to the list with an initial weight of 2.5. Each additional successful delivery increases the path's weight by 0.5, while an unsuccessful delivery decreases it by 0.2. If a path is discovered by the firmware (e.g. via a message received from the contact), it is added to the list with an initial weight of 1.0. The weight is capped at 5.0. If a path's weight drops to 0, it is removed from the list. The weight serves as a health indicator -- it keeps useful paths in the pool and prunes dead ones, but it does not determine the order in which paths are tried.

If there are multiple paths on the list, smart routing selects the best path for each delivery attempt (up to 4 attempts total). The selection is based on a composite **score** that combines three factors:

  | Factor | Weight | Formula |
  |--------|--------|---------|
  | Reliability | 60% | *(successes + 1) / (total_attempts + 2)* -- Laplace-smoothed success rate |
  | Latency | 20% | *1 / (1 + last_trip_ms / 10 000)* -- lower latency -> higher score (0.5 if unknown) |
  | Recency | 20% | *1 / (1 + age_days)* -- days since last successful delivery (0 if never) |

  **score = reliability x 0.6 + latency x 0.2 + recency x 0.2**

Each attempt uses a different path from the available pool, selected by highest score. If there are fewer paths than attempts, the best paths can be reused. The 5th attempt is always flood routed unless **Automatically Reset Path** is disabled. If there are no paths left in the list, it automatically switches to flood routing and tries to find a new path.

Clicking **Available Paths** in the contact detail gives you a list of recently successful paths, showing their weights, the number of successful and unsuccessful attempts, the number of hops and the time taken for the last delivery. Each path is color-coded with a dot for easy identification. Clicking the **map icon** in the header bar opens a map dialog showing all available paths simultaneously, each drawn as a colored line matching its dot in the list. This allows you to visually compare routes and see which repeaters they pass through. If the list is outdated and no longer useful for routing, click the **Clear History** button. This will forget all paths and switch routing to flood to find new paths.

## Choosing Between Classic and Smart

| Classic | Smart |
|-------|-------|
| Direct manual control over paths | Automatic path selection based on history |
| Better for mobile nodes | Better for stationary nodes |
| Useful for troubleshooting | Learns optimal routes over time |
| Single path at a time | Multiple paths with quality tracking |

## Global Default and Per-Contact Override

The **Default Routing** toggle in [Settings > Routing and Messaging](@/guide/settings.md#routing-and-messaging) sets the routing strategy used for all contacts. When you change a contact's routing mode in the [contact detail dialog](@/guide/contacts.md#routing), it becomes a per-contact override that persists independently of the global setting. Changing the global default will not affect contacts that have been explicitly overridden.
