# What Is the Maximum Hop Count for BLE Mesh Messages in BitChat?

> Discover the maximum hop count for BLE mesh messages in BitChat. Learn how the 7 hop limit prevents infinite forwarding loops and optimizes network performance.

- Repository: [permissionlesstech/bitchat](https://github.com/permissionlesstech/bitchat)
- Tags: faq
- Published: 2026-08-23

---

**The maximum hop count for BLE mesh messages in BitChat is 7 hops, after which packets are automatically discarded by the routing engine to prevent infinite forwarding loops.**

BitChat, an open-source Bluetooth Low Energy (BLE) mesh messaging application developed by permissionlesstech, implements a strict **maximum hop count for BLE mesh messages** to ensure reliable message delivery across decentralized networks. The routing protocol hard-codes a ceiling of seven intermediate relays, balancing network reach with performance constraints while preventing infinite forwarding loops.

## Where the 7-Hop Limit Is Documented

The definitive source for this constraint appears in the repository's primary documentation. In [`README.md`](https://github.com/permissionlesstech/bitchat/blob/main/README.md) (lines 40-44), the feature list explicitly states: "Multi-hop Relay: Messages route through nearby devices (max 7 hops)". This architectural decision caps the message traversal depth to prevent network congestion in large mesh deployments.

## Implementation in the Routing Engine

The enforcement mechanism resides in BitChat's Swift-based routing services, where the `computeRoute(from:to:maxHops:)` method validates paths against the hard-coded ceiling before packet transmission.

### Validation Tests in MeshTopologyTrackerTests

Unit tests within [`bitchatTests/Services/MeshTopologyTrackerTests.swift`](https://github.com/permissionlesstech/bitchat/blob/main/bitchatTests/Services/MeshTopologyTrackerTests.swift) (lines 131-139) verify that the routing logic rejects any path requiring more than seven intermediate nodes. These tests ensure that when the topology tracker calculates a route between source and destination nodes, it returns `nil` if the hop count exceeds the allowed threshold, effectively dropping undeliverable messages rather than allowing them to propagate.

### Computing Routes with Hop Constraints

When constructing a message route, developers interact with the `MeshTopologyTracker` to specify the maximum allowable relays:

```swift
// BitChat enforces a hard limit of 7 hops for BLE mesh forwarding
let maxAllowedHops = 7

let route = try tracker.computeRoute(
    from: sourceNode,
    to: destinationNode,
    maxHops: maxAllowedHops
)

// Routes exceeding the limit are rejected
guard let viableRoute = route else {
    print("Message cannot be delivered – exceeds 7-hop limit")
    return
}

// Forward via the validated path
meshEngine.sendPacket(packet, via: viableRoute)

```

This pattern ensures that `meshEngine.sendPacket` only receives validated routes that respect the **maximum hop count for BLE mesh messages** enforced by the protocol.

## Architectural Rationale for Mesh Hop Limits

Mesh networks require hop limits to prevent infinite routing loops and reduce latency. By couting intermediary relays at seven, BitChat balances the trade-off between network coverage and message propagation delay. Each hop introduces potential latency and battery consumption on relay devices; the seven-hop ceiling ensures messages remain viable for real-time chat applications while still enabling multi-hop relay across distributed device clusters.

## Summary

- **BitChat enforces a strict 7-hop maximum** for all BLE mesh message routing, as documented in [`README.md`](https://github.com/permissionlesstech/bitchat/blob/main/README.md) (lines 40-44).
- The `MeshTopologyTracker.computeRoute()` method rejects routes exceeding this limit, returning `nil` for undeliverable messages.
- Unit tests in [`bitchatTests/Services/MeshTopologyTrackerTests.swift`](https://github.com/permissionlesstech/bitchat/blob/main/bitchatTests/Services/MeshTopologyTrackerTests.swift) (lines 131-139) validate that the routing engine correctly discards packets requiring more than seven intermediate hops.
- This limit prevents infinite forwarding loops and manages battery consumption across the decentralized network.

## Frequently Asked Questions

### What happens when a BitChat message exceeds 7 hops?

When a message route would require more than seven intermediate relays, the `computeRoute(from:to:maxHops:)` method returns `nil`, and the packet is discarded rather than forwarded. This prevents "orphaned" messages from circulating indefinitely in the mesh network.

### Can the maximum hop count be configured by users?

According to the source code in `permissionlesstech/bitchat`, the 7-hop limit is hard-coded as a constant in the routing logic. Users cannot override this value through the application interface, as it represents a fundamental protocol constraint designed to ensure network stability.

### Where is the hop limit documented in the BitChat repository?

The limit is explicitly documented in the [`README.md`](https://github.com/permissionlesstech/bitchat/blob/main/README.md) file within the "Multi-hop Relay" feature description, which states that messages route through nearby devices with a maximum of 7 hops (lines 40-44).

### How does BitChat validate the hop count during routing?

Validation occurs in [`bitchatTests/Services/MeshTopologyTrackerTests.swift`](https://github.com/permissionlesstech/bitchat/blob/main/bitchatTests/Services/MeshTopologyTrackerTests.swift), where unit tests verify that the routing algorithm correctly identifies and rejects paths exceeding the seven-hop threshold (lines 131-139), ensuring the production code adheres to the architectural constraint.