Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,27 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
}

uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
if(_prefs.tx_delay_factor == 0) {
MESH_DEBUG_PRINTLN("getRetransmitDelay: Total tx delay: %d", _prefs.tx_delay_factor);
return 5;
}

uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
return getRNG()->nextInt(0, 6) * t;
uint32_t total_delay = getRNG()->nextInt(5, t);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would make the maximum delay 't'. Whereas it used to be 5*t was the max.
This would change the interpretation of the _prefs values. Admins can set to some small fraction, like 0.1 (or smaller) if very small delays want to be experimented with. Currently max for the pref is 2.0 (I think), which is probably very wild/unrealistic.
Also, currently the minimum 'extra' delay is 0, and this introduces min of 5 which could be a fairly 'radical' change. For a first-try, I'd rather introducing JUST the granularity change... ie. no 6 buckets, and just continuous range instead

MESH_DEBUG_PRINTLN("getRetransmitDelay: Total tx delay: %d", total_delay);
return total_delay;
}

uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
if(_prefs.direct_tx_delay_factor == 0) {
MESH_DEBUG_PRINTLN("getDirectRetransmitDelay: Total tx delay: %d", _prefs.direct_tx_delay_factor);
return 5;
}

uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
return getRNG()->nextInt(0, 6) * t;
uint32_t total_delay = getRNG()->nextInt(5, t);
MESH_DEBUG_PRINTLN("getDirectRetransmitDelay: Total tx delay: %d", total_delay);
return total_delay;
}

void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender,
Expand Down
4 changes: 3 additions & 1 deletion src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ bool Mesh::allowPacketForward(const mesh::Packet* packet) {
uint32_t Mesh::getRetransmitDelay(const mesh::Packet* packet) {
uint32_t t = (_radio->getEstAirtimeFor(packet->getRawLength()) * 52 / 50) / 2;

return _rng->nextInt(0, 5)*t;
uint32_t total_delay = getRNG()->nextInt(5, t);
MESH_DEBUG_PRINTLN("getRetransmitDelay: Total tx delay: %d", total_delay);
return total_delay;
}
uint32_t Mesh::getDirectRetransmitDelay(const Packet* packet) {
return 0; // by default, no delay
Expand Down