Skip to content

Commit c455d51

Browse files
committed
Enhance relay decision logic in Graph and GraphLite to include fallback conditions for uncovered neighbors. This ensures packet propagation when expected relays are unavailable, improving network reliability.
1 parent 379b74b commit c455d51

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/mesh/graph/Graph.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,18 @@ bool Graph::shouldRelayEnhancedConservative(NodeNum myNode, NodeNum sourceNode,
10121012
auto relayCandidates = findAllRelayCandidates(alreadyCovered, candidates, currentTime, packetId);
10131013

10141014
if (relayCandidates.empty()) {
1015-
LOG_DEBUG("Graph: No relay candidates found - not relaying");
1016-
return false; // No one can provide additional coverage
1015+
// No relay candidates found - but we might still need to relay if we have neighbors
1016+
// that aren't covered by the transmitting node. This handles cases where stock gateways
1017+
// or nodes that went down were expected to relay but won't.
1018+
auto myNeighbors = getDirectNeighbors(myNode);
1019+
for (NodeNum neighbor : myNeighbors) {
1020+
if (alreadyCovered.find(neighbor) == alreadyCovered.end()) {
1021+
LOG_DEBUG("Graph: Conservative fallback - neighbor %08x not covered, relaying", neighbor);
1022+
return true; // We have neighbors not covered - relay to ensure propagation
1023+
}
1024+
}
1025+
LOG_DEBUG("Graph: No relay candidates and all neighbors covered - not relaying");
1026+
return false;
10171027
}
10181028

10191029
// Find candidates in tier 0 (primary relays)

src/mesh/graph/GraphLite.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,15 @@ bool GraphLite::shouldRelaySimpleConservative(NodeNum myNode, NodeNum sourceNode
771771
}
772772

773773
if (!transmittingEdges) {
774-
return false; // No transmitting node edges found
774+
// No topology data for transmitting node - this might be a stock node or a node that went down
775+
// In this case, fall back to relaying if we have neighbors (to ensure propagation)
776+
LOG_DEBUG("GraphLite: No topology for transmitting node %08x - fallback relay", heardFrom);
777+
return true;
775778
}
776779

777780
// Count SR neighbors we have that the transmitting node doesn't have direct connection to
778781
uint8_t uniqueSrNeighbors = 0;
782+
uint8_t totalNeighborsNotCovered = 0;
779783
for (uint8_t i = 0; i < myEdges->edgeCount; i++) {
780784
NodeNum neighbor = myEdges->edges[i].to;
781785
if (neighbor == sourceNode || neighbor == heardFrom) {
@@ -793,12 +797,26 @@ bool GraphLite::shouldRelaySimpleConservative(NodeNum myNode, NodeNum sourceNode
793797

794798
if (!transmittingHasIt) {
795799
uniqueSrNeighbors++;
800+
totalNeighborsNotCovered++;
796801
}
797802
}
798803

799804
// Conservative logic: Require at least 2 unique SR neighbors before relaying
800805
// This reduces redundant relaying while still ensuring branch connectivity
801-
return uniqueSrNeighbors >= 2;
806+
if (uniqueSrNeighbors >= 2) {
807+
return true;
808+
}
809+
810+
// Fallback: if we have ANY neighbors not covered by the transmitting node, relay
811+
// This ensures packet propagation when stock gateways might not relay
812+
// (e.g., they went down, are in CLIENT_MUTE mode, or have rebroadcast disabled)
813+
if (totalNeighborsNotCovered > 0) {
814+
LOG_DEBUG("GraphLite: Conservative fallback - have %u uncovered neighbors, relaying", totalNeighborsNotCovered);
815+
return true;
816+
}
817+
818+
// All our neighbors are covered by the transmitting node - no need to relay
819+
return false;
802820
}
803821

804822
uint32_t GraphLite::getContentionWindowMs()

0 commit comments

Comments
 (0)