mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-06 05:34:45 +00:00
now that the rfinterfaces are smarter, no need to do backoff in
the flood router. the interfaces will handle it.
This commit is contained in:
parent
ad2f639195
commit
1d9290afc0
@ -5,6 +5,8 @@
|
|||||||
/// We clear our old flood record five minute after we see the last of it
|
/// We clear our old flood record five minute after we see the last of it
|
||||||
#define FLOOD_EXPIRE_TIME (5 * 60 * 1000L)
|
#define FLOOD_EXPIRE_TIME (5 * 60 * 1000L)
|
||||||
|
|
||||||
|
static bool supportFlooding = true; // Sometimes to simplify debugging we want jusT simple broadcast only
|
||||||
|
|
||||||
FloodingRouter::FloodingRouter() : toResend(MAX_NUM_NODES)
|
FloodingRouter::FloodingRouter() : toResend(MAX_NUM_NODES)
|
||||||
{
|
{
|
||||||
recentBroadcasts.reserve(MAX_NUM_NODES); // Prealloc the worst case # of records - to prevent heap fragmentation
|
recentBroadcasts.reserve(MAX_NUM_NODES); // Prealloc the worst case # of records - to prevent heap fragmentation
|
||||||
@ -19,7 +21,8 @@ FloodingRouter::FloodingRouter() : toResend(MAX_NUM_NODES)
|
|||||||
ErrorCode FloodingRouter::send(MeshPacket *p)
|
ErrorCode FloodingRouter::send(MeshPacket *p)
|
||||||
{
|
{
|
||||||
// We update our table of recent broadcasts, even for messages we send
|
// We update our table of recent broadcasts, even for messages we send
|
||||||
wasSeenRecently(p);
|
if (supportFlooding)
|
||||||
|
wasSeenRecently(p);
|
||||||
|
|
||||||
return Router::send(p);
|
return Router::send(p);
|
||||||
}
|
}
|
||||||
@ -30,6 +33,12 @@ uint32_t getRandomDelay()
|
|||||||
return random(200, 10 * 1000L); // between 200ms and 10s
|
return random(200, 10 * 1000L); // between 200ms and 10s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now that our generalized packet send code has a random delay - I don't think we need to wait here
|
||||||
|
* But I'm leaving this bool until I rip the code out for good.
|
||||||
|
*/
|
||||||
|
bool needDelay = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from loop()
|
* Called from loop()
|
||||||
* Handle any packet that is received by an interface on this node.
|
* Handle any packet that is received by an interface on this node.
|
||||||
@ -39,28 +48,40 @@ uint32_t getRandomDelay()
|
|||||||
*/
|
*/
|
||||||
void FloodingRouter::handleReceived(MeshPacket *p)
|
void FloodingRouter::handleReceived(MeshPacket *p)
|
||||||
{
|
{
|
||||||
if (wasSeenRecently(p)) {
|
if (supportFlooding) {
|
||||||
DEBUG_MSG("Ignoring incoming floodmsg, because we've already seen it\n");
|
if (wasSeenRecently(p)) {
|
||||||
packetPool.release(p);
|
DEBUG_MSG("Ignoring incoming floodmsg, because we've already seen it\n");
|
||||||
} else {
|
packetPool.release(p);
|
||||||
if (p->to == NODENUM_BROADCAST) {
|
} else {
|
||||||
if (p->id != 0) {
|
if (p->to == NODENUM_BROADCAST) {
|
||||||
uint32_t delay = getRandomDelay();
|
if (p->id != 0) {
|
||||||
|
MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
|
||||||
|
|
||||||
DEBUG_MSG("Rebroadcasting received floodmsg to neighbors in %u msec, fr=0x%x,to=0x%x,id=%d\n", delay, p->from,
|
if (needDelay) {
|
||||||
p->to, p->id);
|
uint32_t delay = getRandomDelay();
|
||||||
|
|
||||||
MeshPacket *tosend = packetPool.allocCopy(*p);
|
DEBUG_MSG("Rebroadcasting received floodmsg to neighbors in %u msec, fr=0x%x,to=0x%x,id=%d\n", delay,
|
||||||
toResend.enqueue(tosend);
|
p->from, p->to, p->id);
|
||||||
setPeriod(delay); // This will work even if we were already waiting a random delay
|
|
||||||
} else {
|
toResend.enqueue(tosend);
|
||||||
DEBUG_MSG("Ignoring a simple (0 hop) broadcast\n");
|
setPeriod(delay); // This will work even if we were already waiting a random delay
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("Rebroadcasting received floodmsg to neighbors, fr=0x%x,to=0x%x,id=%d\n", p->from, p->to,
|
||||||
|
p->id);
|
||||||
|
// Note: we are careful to resend using the original senders node id
|
||||||
|
// We are careful not to call our hooked version of send() - because we don't want to check this again
|
||||||
|
Router::send(tosend);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("Ignoring a simple (0 hop) broadcast\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// handle the packet as normal
|
// handle the packet as normal
|
||||||
|
Router::handleReceived(p);
|
||||||
|
}
|
||||||
|
} else
|
||||||
Router::handleReceived(p);
|
Router::handleReceived(p);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloodingRouter::doTask()
|
void FloodingRouter::doTask()
|
||||||
|
Loading…
Reference in New Issue
Block a user