diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index 74d00316c..42a19cf20 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -76,7 +76,7 @@ bool FloodingRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p) CoverageFilter incomingCoverage; loadCoverageFilterFromPacket(p, incomingCoverage); - float forwardProb = calculateForwardProbability(incomingCoverage); + float forwardProb = calculateForwardProbability(incomingCoverage, p->from); float rnd = static_cast(rand()) / static_cast(RAND_MAX); if (rnd <= forwardProb) { @@ -158,7 +158,7 @@ void FloodingRouter::mergeMyCoverage(CoverageFilter &coverage) } } -float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming) +float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming, NodeNum lastSender) { // If we are a router or repeater, always forward because it's assumed these are in the most advantageous locations if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER || @@ -177,14 +177,20 @@ float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming // Count how many neighbors are NOT yet in the coverage int uncovered = 0; + int neighbors = 0; for (auto nodeId : recentNeighbors) { + // Don't count the person we got this packet from + if (nodeId == lastSender) continue; + + neighbors++; + if (!incoming.check(nodeId)) { uncovered++; } } // Calculate coverage ratio - float coverageRatio = static_cast(uncovered) / static_cast(recentNeighbors.size()); + float coverageRatio = static_cast(uncovered) / static_cast(neighbors); // Calculate forwarding probability float forwardProb = BASE_FORWARD_PROB + (coverageRatio * COVERAGE_SCALE_FACTOR); diff --git a/src/mesh/FloodingRouter.h b/src/mesh/FloodingRouter.h index cf412239d..72c2e5230 100644 --- a/src/mesh/FloodingRouter.h +++ b/src/mesh/FloodingRouter.h @@ -42,7 +42,7 @@ class FloodingRouter : public Router, protected PacketHistory void mergeMyCoverage(CoverageFilter &coverage); - float calculateForwardProbability(const CoverageFilter &incoming); + float calculateForwardProbability(const CoverageFilter &incoming, NodeNum lastSender); public: /** diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index 475f8e8bb..c303db9e5 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -771,12 +771,12 @@ typedef struct _meshtastic_MeshPacket { /* Last byte of the node number of the node that will relay/relayed this packet. Set by the firmware internally, clients are not supposed to set this. */ uint8_t relay_node; - - meshtastic_MeshPacket_coverage_filter_t coverage_filter; /* *Never* sent over the radio links. Timestamp after which this packet may be sent. Set by the firmware internally, clients are not supposed to set this. */ uint32_t tx_after; + /* Flips two bits per node added to the filter */ + meshtastic_MeshPacket_coverage_filter_t coverage_filter; } meshtastic_MeshPacket; /* The bluetooth to device link: @@ -1309,6 +1309,7 @@ extern "C" { #define meshtastic_MeshPacket_next_hop_tag 18 #define meshtastic_MeshPacket_relay_node_tag 19 #define meshtastic_MeshPacket_tx_after_tag 20 +#define meshtastic_MeshPacket_coverage_filter_tag 21 #define meshtastic_NodeInfo_num_tag 1 #define meshtastic_NodeInfo_user_tag 2 #define meshtastic_NodeInfo_position_tag 3 @@ -1506,7 +1507,8 @@ X(a, STATIC, SINGULAR, BYTES, public_key, 16) \ X(a, STATIC, SINGULAR, BOOL, pki_encrypted, 17) \ X(a, STATIC, SINGULAR, UINT32, next_hop, 18) \ X(a, STATIC, SINGULAR, UINT32, relay_node, 19) \ -X(a, STATIC, SINGULAR, UINT32, tx_after, 20) +X(a, STATIC, SINGULAR, UINT32, tx_after, 20) \ +X(a, STATIC, SINGULAR, BYTES, coverage_filter, 21) #define meshtastic_MeshPacket_CALLBACK NULL #define meshtastic_MeshPacket_DEFAULT NULL #define meshtastic_MeshPacket_payload_variant_decoded_MSGTYPE meshtastic_Data