* added getTransmitDelay(), applied to Flood mode retransmissions.
This commit is contained in:
@@ -144,7 +144,7 @@ protected:
|
|||||||
return airtime_factor;
|
return airtime_factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool allowPacketForward(mesh::Packet* packet) override {
|
bool allowPacketForward(const mesh::Packet* packet) override {
|
||||||
uint8_t hash[MAX_HASH_SIZE];
|
uint8_t hash[MAX_HASH_SIZE];
|
||||||
packet->calculatePacketHash(hash);
|
packet->calculatePacketHash(hash);
|
||||||
|
|
||||||
|
|||||||
12
src/Mesh.cpp
12
src/Mesh.cpp
@@ -11,9 +11,14 @@ void Mesh::loop() {
|
|||||||
Dispatcher::loop();
|
Dispatcher::loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mesh::allowPacketForward(mesh::Packet* packet) {
|
bool Mesh::allowPacketForward(const mesh::Packet* packet) {
|
||||||
return false; // by default, Transport NOT enabled
|
return false; // by default, Transport NOT enabled
|
||||||
}
|
}
|
||||||
|
uint32_t Mesh::getRetransmitDelay(const mesh::Packet* packet) {
|
||||||
|
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * 52 / 50) / 2;
|
||||||
|
|
||||||
|
return _rng->nextInt(0, 5)*t;
|
||||||
|
}
|
||||||
|
|
||||||
int Mesh::searchPeersByHash(const uint8_t* hash) {
|
int Mesh::searchPeersByHash(const uint8_t* hash) {
|
||||||
return 0; // not found
|
return 0; // not found
|
||||||
@@ -34,7 +39,7 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
// remove our hash from 'path', then re-broadcast
|
// remove our hash from 'path', then re-broadcast
|
||||||
pkt->path_len -= PATH_HASH_SIZE;
|
pkt->path_len -= PATH_HASH_SIZE;
|
||||||
memcpy(pkt->path, &pkt->path[PATH_HASH_SIZE], pkt->path_len);
|
memcpy(pkt->path, &pkt->path[PATH_HASH_SIZE], pkt->path_len);
|
||||||
return ACTION_RETRANSMIT(0); // Routed traffic is HIGHEST priority
|
return ACTION_RETRANSMIT(0); // Routed traffic is HIGHEST priority (and NO per-hop delay)
|
||||||
}
|
}
|
||||||
return ACTION_RELEASE; // this node is NOT the next hop (OR this packet has already been forwarded), so discard.
|
return ACTION_RELEASE; // this node is NOT the next hop (OR this packet has already been forwarded), so discard.
|
||||||
}
|
}
|
||||||
@@ -204,8 +209,9 @@ DispatcherAction Mesh::routeRecvPacket(Packet* packet) {
|
|||||||
// append this node's hash to 'path'
|
// append this node's hash to 'path'
|
||||||
packet->path_len += self_id.copyHashTo(&packet->path[packet->path_len]);
|
packet->path_len += self_id.copyHashTo(&packet->path[packet->path_len]);
|
||||||
|
|
||||||
|
uint32_t d = getRetransmitDelay(packet);
|
||||||
// as this propagates outwards, give it lower and lower priority
|
// as this propagates outwards, give it lower and lower priority
|
||||||
return ACTION_RETRANSMIT(packet->path_len); // give priority to closer sources, than ones further away
|
return ACTION_RETRANSMIT_DELAYED(packet->path_len, d); // give priority to closer sources, than ones further away
|
||||||
}
|
}
|
||||||
return ACTION_RELEASE;
|
return ACTION_RELEASE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,12 @@ protected:
|
|||||||
* \brief Check whether this packet should be forwarded (re-transmitted) or not.
|
* \brief Check whether this packet should be forwarded (re-transmitted) or not.
|
||||||
* Is sub-classes responsibility to make sure given packet is only transmitted ONCE (by this node)
|
* Is sub-classes responsibility to make sure given packet is only transmitted ONCE (by this node)
|
||||||
*/
|
*/
|
||||||
virtual bool allowPacketForward(Packet* packet);
|
virtual bool allowPacketForward(const Packet* packet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \returns number of milliseconds delay to apply to retransmitting the given packet.
|
||||||
|
*/
|
||||||
|
virtual uint32_t getRetransmitDelay(const Packet* packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Perform search of local DB of peers/contacts.
|
* \brief Perform search of local DB of peers/contacts.
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ namespace mesh {
|
|||||||
class RNG {
|
class RNG {
|
||||||
public:
|
public:
|
||||||
virtual void random(uint8_t* dest, size_t sz) = 0;
|
virtual void random(uint8_t* dest, size_t sz) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \returns random number between _min (inclusive) and _max (exclusive)
|
||||||
|
*/
|
||||||
uint32_t nextInt(uint32_t _min, uint32_t _max);
|
uint32_t nextInt(uint32_t _min, uint32_t _max);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user