diff --git a/src/main.cpp b/src/main.cpp index dc6fe7ad..d7fb21bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,13 +27,12 @@ #include "NodeDB.h" #include "Periodic.h" #include "PowerFSM.h" -#include "Router.h" #include "UBloxGPS.h" #include "configuration.h" #include "error.h" #include "power.h" // #include "rom/rtc.h" -#include "ReliableRouter.h" +#include "DSRRouter.h" #include "main.h" #include "screen.h" #include "sleep.h" @@ -53,7 +52,7 @@ meshtastic::PowerStatus powerStatus; bool ssd1306_found; bool axp192_found; -ReliableRouter realRouter; +DSRRouter realRouter; Router &router = realRouter; // Users of router don't care what sort of subclass implements that API // ----------------------------------------------------------------------------- diff --git a/src/mesh/DSRRouter.cpp b/src/mesh/DSRRouter.cpp index cb22c546..7d788441 100644 --- a/src/mesh/DSRRouter.cpp +++ b/src/mesh/DSRRouter.cpp @@ -38,9 +38,26 @@ when we receive a routeError packet ErrorCode DSRRouter::send(MeshPacket *p) { - // If we have an entry in our routing tables, just send it, otherwise start a route discovery + // We only consider multihop routing packets (i.e. those with dest set) + if (p->decoded.dest) { + // add an entry for this pending message + auto pending = startRetransmission(p); + // FIXME - when acks come in for this packet, we should _not_ delete the record unless the ack was from + // the final dest. We need to keep that record around until FIXME + // Also we should not retransmit multihop entries in that table at all - return ReliableRouter::send(p); + // If we have an entry in our routing tables, just send it, otherwise start a route discovery + NodeNum nextHop = getNextHop(p->decoded.dest); + if (nextHop) { + sendNextHop(nextHop, p); // start a reliable single hop send + } else { + pending->wantRoute = true; + + // start discovery, but only if we don't already a discovery in progress for that node number + startDiscovery(p->decoded.dest); + } + } else + return ReliableRouter::send(p); } void DSRRouter::sniffReceived(const MeshPacket *p) diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 603768a0..3499c51b 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -146,13 +146,15 @@ bool ReliableRouter::stopRetransmission(GlobalPacketId key) /** * Add p to the list of packets to retransmit occasionally. We will free it once we stop retransmitting. */ -void ReliableRouter::startRetransmission(MeshPacket *p) +PendingPacket *ReliableRouter::startRetransmission(MeshPacket *p) { auto id = GlobalPacketId(p); auto rec = PendingPacket(p); stopRetransmission(p->from, p->id); pending[id] = rec; + + return &pending[id]; } /** diff --git a/src/mesh/ReliableRouter.h b/src/mesh/ReliableRouter.h index d984ea11..51cb587a 100644 --- a/src/mesh/ReliableRouter.h +++ b/src/mesh/ReliableRouter.h @@ -103,6 +103,11 @@ class ReliableRouter : public FloodingRouter */ virtual bool shouldFilterReceived(const MeshPacket *p); + /** + * Add p to the list of packets to retransmit occasionally. We will free it once we stop retransmitting. + */ + PendingPacket *startRetransmission(MeshPacket *p); + private: /** * Send an ack or a nak packet back towards whoever sent idFrom @@ -117,11 +122,6 @@ class ReliableRouter : public FloodingRouter bool stopRetransmission(NodeNum from, PacketId id); bool stopRetransmission(GlobalPacketId p); - /** - * Add p to the list of packets to retransmit occasionally. We will free it once we stop retransmitting. - */ - void startRetransmission(MeshPacket *p); - /** * Do any retransmissions that are scheduled (FIXME - for the time being called from loop) */ diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index c7e5a38c..ce3fe7e3 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -78,5 +78,12 @@ void nrf52Setup() // Not yet on board // pmu.init(); - DEBUG_MSG("FIXME, need to call randomSeed on nrf52!\n"); + + // Init random seed + // FIXME - use this to get random numbers + // #include "nrf_rng.h" + // uint32_t r; + // ble_controller_rand_vector_get_blocking(&r, sizeof(r)); + // randomSeed(r); + DEBUG_MSG("FIXME, call randomSeed\n"); } \ No newline at end of file