@@ -1332,13 +1332,19 @@ void SignalRoutingModule::logNetworkTopology()
13321332 for (size_t i = 0 ; i < rawNodeCount; i++) {
13331333 NodeNum nodeId = nodeBuf[i];
13341334 bool isDownstream = false ;
1335- for (uint8_t j = 0 ; j < gatewayRelationCount; j++) {
1336- if (gatewayRelations[j].downstream == nodeId &&
1337- (now - gatewayRelations[j].lastSeen ) <= ACTIVE_NODE_TTL_SECS) {
1338- isDownstream = true ;
1339- break ;
1335+ // Check if this node is downstream of any gateway
1336+ for (uint8_t j = 0 ; j < gatewayDownstreamCount; j++) {
1337+ const GatewayDownstreamSet &set = gatewayDownstream[j];
1338+ if ((now - set.lastSeen ) <= ACTIVE_NODE_TTL_SECS) {
1339+ for (uint8_t k = 0 ; k < set.count ; k++) {
1340+ if (set.downstream [k] == nodeId) {
1341+ isDownstream = true ;
1342+ goto foundDownstream;
1343+ }
1344+ }
13401345 }
13411346 }
1347+ foundDownstream:
13421348 if (!isDownstream) {
13431349 nodeBuf[nodeCount++] = nodeId;
13441350 }
@@ -1460,11 +1466,18 @@ void SignalRoutingModule::logNetworkTopology()
14601466 }
14611467
14621468 // Filter out downstream nodes - they should only appear under their gateways
1469+ uint32_t now = millis () / 1000 ; // Use monotonic time
14631470 std::vector<NodeNum> topologyNodes;
14641471 for (NodeNum nodeId : allNodes) {
1465- if (downstreamGateway.find (nodeId) == downstreamGateway.end ()) {
1472+ auto dgIt = downstreamGateway.find (nodeId);
1473+ if (dgIt == downstreamGateway.end ()) {
1474+ // Node is not downstream of any gateway
1475+ topologyNodes.push_back (nodeId);
1476+ } else if ((now - dgIt->second .lastSeen ) > ACTIVE_NODE_TTL_SECS) {
1477+ // Downstream relationship has expired
14661478 topologyNodes.push_back (nodeId);
14671479 }
1480+ // If relationship is active, exclude from topology (node appears under its gateway)
14681481 }
14691482
14701483 LOG_INFO (" [SR] Network Topology: %d nodes total" , topologyNodes.size ());
0 commit comments