fixed types. ignore sender

This commit is contained in:
medentem 2024-12-31 08:57:10 -06:00
parent f7595403c5
commit 563126e4b0
3 changed files with 15 additions and 7 deletions

View File

@ -76,7 +76,7 @@ bool FloodingRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p)
CoverageFilter incomingCoverage; CoverageFilter incomingCoverage;
loadCoverageFilterFromPacket(p, incomingCoverage); loadCoverageFilterFromPacket(p, incomingCoverage);
float forwardProb = calculateForwardProbability(incomingCoverage); float forwardProb = calculateForwardProbability(incomingCoverage, p->from);
float rnd = static_cast<float>(rand()) / static_cast<float>(RAND_MAX); float rnd = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
if (rnd <= forwardProb) { 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 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 || 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 // Count how many neighbors are NOT yet in the coverage
int uncovered = 0; int uncovered = 0;
int neighbors = 0;
for (auto nodeId : recentNeighbors) { for (auto nodeId : recentNeighbors) {
// Don't count the person we got this packet from
if (nodeId == lastSender) continue;
neighbors++;
if (!incoming.check(nodeId)) { if (!incoming.check(nodeId)) {
uncovered++; uncovered++;
} }
} }
// Calculate coverage ratio // Calculate coverage ratio
float coverageRatio = static_cast<float>(uncovered) / static_cast<float>(recentNeighbors.size()); float coverageRatio = static_cast<float>(uncovered) / static_cast<float>(neighbors);
// Calculate forwarding probability // Calculate forwarding probability
float forwardProb = BASE_FORWARD_PROB + (coverageRatio * COVERAGE_SCALE_FACTOR); float forwardProb = BASE_FORWARD_PROB + (coverageRatio * COVERAGE_SCALE_FACTOR);

View File

@ -42,7 +42,7 @@ class FloodingRouter : public Router, protected PacketHistory
void mergeMyCoverage(CoverageFilter &coverage); void mergeMyCoverage(CoverageFilter &coverage);
float calculateForwardProbability(const CoverageFilter &incoming); float calculateForwardProbability(const CoverageFilter &incoming, NodeNum lastSender);
public: public:
/** /**

View File

@ -771,12 +771,12 @@ typedef struct _meshtastic_MeshPacket {
/* Last byte of the node number of the node that will relay/relayed this packet. /* 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. */ Set by the firmware internally, clients are not supposed to set this. */
uint8_t relay_node; uint8_t relay_node;
meshtastic_MeshPacket_coverage_filter_t coverage_filter;
/* *Never* sent over the radio links. /* *Never* sent over the radio links.
Timestamp after which this packet may be sent. Timestamp after which this packet may be sent.
Set by the firmware internally, clients are not supposed to set this. */ Set by the firmware internally, clients are not supposed to set this. */
uint32_t tx_after; uint32_t tx_after;
/* Flips two bits per node added to the filter */
meshtastic_MeshPacket_coverage_filter_t coverage_filter;
} meshtastic_MeshPacket; } meshtastic_MeshPacket;
/* The bluetooth to device link: /* The bluetooth to device link:
@ -1309,6 +1309,7 @@ extern "C" {
#define meshtastic_MeshPacket_next_hop_tag 18 #define meshtastic_MeshPacket_next_hop_tag 18
#define meshtastic_MeshPacket_relay_node_tag 19 #define meshtastic_MeshPacket_relay_node_tag 19
#define meshtastic_MeshPacket_tx_after_tag 20 #define meshtastic_MeshPacket_tx_after_tag 20
#define meshtastic_MeshPacket_coverage_filter_tag 21
#define meshtastic_NodeInfo_num_tag 1 #define meshtastic_NodeInfo_num_tag 1
#define meshtastic_NodeInfo_user_tag 2 #define meshtastic_NodeInfo_user_tag 2
#define meshtastic_NodeInfo_position_tag 3 #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, BOOL, pki_encrypted, 17) \
X(a, STATIC, SINGULAR, UINT32, next_hop, 18) \ X(a, STATIC, SINGULAR, UINT32, next_hop, 18) \
X(a, STATIC, SINGULAR, UINT32, relay_node, 19) \ 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_CALLBACK NULL
#define meshtastic_MeshPacket_DEFAULT NULL #define meshtastic_MeshPacket_DEFAULT NULL
#define meshtastic_MeshPacket_payload_variant_decoded_MSGTYPE meshtastic_Data #define meshtastic_MeshPacket_payload_variant_decoded_MSGTYPE meshtastic_Data