
Yesterday I left off asking the obvious question about mesh: if nodes can relay for each other, what stops a message from bouncing around forever? Today I read up on how Meshtastic actually handles this, since it's the mesh implementation with the most public documentation I could find, and apparently a reasonable reference point even though I still need to confirm exactly how much our own firmware overlaps with it.
The answer is refreshingly simple, and honestly simpler than I expected: flood routing. There's no routing table, no negotiation phase where nodes figure out the "best path" to a destination ahead of time. A node just broadcasts its message. Every neighboring node that hears it rebroadcasts the same message. Their neighbors hear that and rebroadcast too, and so on, until the message has propagated outward across the whole mesh — which is why it's called "flooding."
The obvious problem is exactly what I was worried about yesterday: without something stopping it, a flooded message could bounce around indefinitely, with nodes rebroadcasting things they'd already rebroadcast, forever. Meshtastic handles this with two mechanisms, as I understand it. First, a hop limit — each message carries a counter that decrements every time it's rebroadcast, and once it hits zero, nodes stop relaying it further. (I've seen the default hop limit described as a small number, something like 3, but I want to double-check the actual current firmware default rather than repeat a number I'm not fully sure of.) Second, deduplication — each message has an ID, and a node that's already seen and rebroadcast a given message ID won't rebroadcast it again if it hears a duplicate copy arrive from another neighbor.
What I find interesting is the tradeoff this represents versus a "smarter" scheme. A path-based routing protocol — where nodes maintain routing tables and figure out an efficient path to a destination — would use less airtime per message, since ideally only the nodes actually on the path relay it, instead of every node in radio range. But maintaining routing tables costs its own overhead: nodes need to discover neighbors, exchange topology info, and update tables when the network changes (a node moves, a battery dies, a new node joins). That's added complexity and its own airtime cost, and it doesn't handle nodes coming and going gracefully without extra protocol work.
Flood routing skips all of that. No tables to build or keep in sync, no topology discovery protocol, works fine even if nodes are constantly joining, leaving, or moving. The cost is that a single message triggers a lot of redundant rebroadcasts — every neighbor within range rebroadcasts the same thing, even nodes that weren't "needed" to get the message where it was going. On a shared, half-duplex radio medium where every transmission eats into a limited duty-cycle/airtime budget (and battery, for battery-powered nodes), that redundancy is a real cost, not just an inefficiency on paper.
It makes sense to me now why this fits a mesh of relatively low-power, resource-constrained embedded nodes — which is exactly what our SQC485Iv2 nodes are — better than something that needs each node to hold and maintain state about the whole network's topology. Still want to ask Wei how our firmware tunes the hop limit for a real industrial site, since I'd guess a smaller site would want a lower hop limit to cut down on redundant airtime.

昨天最後留了一個關於 mesh 的明顯問題:如果節點可以互相 relay,那要怎麼防止訊息無限彈來彈去?今天讀了 Meshtastic 實際上怎麼處理這件事,因為它是我找得到公開文件最多的 mesh 實作,應該算是個合理的參考點——雖然我們自己的韌體實際上跟它重疊多少,這點還要再確認。
答案意外地簡單,老實說比我預期的還簡單:flood routing。沒有 routing table,也沒有一個節點事先協商「到目的地最佳路徑」的階段。一個節點就是直接廣播它的訊息。每個聽到的鄰居節點就轉播同一則訊息。它們的鄰居聽到了也跟著轉播,一路下去,直到訊息傳遍整個 mesh——這也是「flooding(洪泛)」這個名字的由來。
明顯的問題就是我昨天擔心的那個:如果沒有東西擋著,被 flood 出去的訊息理論上可以無限彈下去,節點不斷重複轉播已經轉播過的東西。據我了解,Meshtastic 用兩個機制處理這件事。第一是 hop limit——每則訊息帶著一個計數器,每被轉播一次就遞減,歸零之後節點就不再繼續轉送。(我看到有資料說預設 hop limit 是個小數字,大概像是 3,但我想先跟目前韌體的實際預設值對一下,不想直接引用一個我沒完全把握的數字。)第二是去重(deduplication)——每則訊息有自己的 ID,如果一個節點已經看過並轉播過某個訊息 ID,之後又從別的鄰居那邊聽到同一個 ID 的重複副本,就不會再轉播一次。
我覺得有意思的是這跟「更聰明」的機制之間的取捨。Path-based 的 routing 協定——節點維護 routing table、算出到目的地的有效路徑——理論上每則訊息花的 airtime 更少,因為理想狀況下只有真正在路徑上的節點才轉送,而不是收訊範圍內的每個節點都轉。但維護 routing table 本身也有代價:節點要探索鄰居、交換拓樸資訊,網路一有變動(節點移動、電池沒電、新節點加入)就要更新表格。這是額外的複雜度,也有自己的 airtime 成本,而且沒有額外的協定機制就沒辦法優雅地處理節點來來去去。
Flood routing 全部跳過這些。不用建表也不用維護表格同步,不用拓樸探索協定,就算節點一直加入、離開、移動也照樣能運作。代價是一則訊息會觸發「大量」重複的轉播——範圍內的每個鄰居都轉播同一則東西,就算有些節點根本「不需要」也照轉。在共享的半雙工無線電媒介上,每一次傳輸都在吃掉有限的 duty-cycle/airtime 預算(對電池供電的節點來說還吃電池),這種重複是實打實的成本,不只是紙上談兵的效率問題。
現在我比較理解為什麼這種機制適合像我們 SQC485Iv2 這種相對低功耗、資源有限的嵌入式節點所組成的 mesh,比起要求每個節點都持有並維護整個網路拓樸狀態的方案要合適。還想問 Wei 我們的韌體在實際工業場地怎麼調 hop limit——我猜比較小的場地會想把 hop limit 調低一點,減少重複的 airtime 消耗。