From e89fe2f7d9cbd1845a9b7ecc8c2cd72d3733509f Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 23 May 2020 12:50:33 -0700 Subject: [PATCH] DSR WIP --- src/mesh/DSRRouter.cpp | 11 +++++++++++ src/mesh/DSRRouter.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/mesh/DSRRouter.cpp b/src/mesh/DSRRouter.cpp index 60630b20d..99ef1a656 100644 --- a/src/mesh/DSRRouter.cpp +++ b/src/mesh/DSRRouter.cpp @@ -73,6 +73,15 @@ void DSRRouter::sniffReceived(const MeshPacket *p) updateRoutes(p->decoded.reply, true); } + // Learn 0 hop routes by just hearing any adjacent nodes + // But treat broadcasts carefully, because when flood broadcasts go out they keep the same original "from". So we want to + // ignore rebroadcasts. + if (p->to != NODENUM_BROADCAST || p->hop_limit != HOP_RELIABLE) { + setRoute(p->from, p->from, 0); // We are adjacent with zero hops + } + + // FIXME - handle any naks we receive (either because they are passing by us or someone naked a message we sent) + // Handle regular packets if (p->to == getNodeNum()) { // Destined for us (at least for this hop) @@ -80,6 +89,8 @@ void DSRRouter::sniffReceived(const MeshPacket *p) if (p->decoded.dest && p->decoded.dest != p->to) { // FIXME if we have a route out, resend the packet to the next hop, otherwise return a nak with no-route available } + + // FIXME - handle naks from our adjacent nodes - convert them to route error packets } return ReliableRouter::sniffReceived(p); diff --git a/src/mesh/DSRRouter.h b/src/mesh/DSRRouter.h index 5ecbdc8e5..62ec9c672 100644 --- a/src/mesh/DSRRouter.h +++ b/src/mesh/DSRRouter.h @@ -36,4 +36,11 @@ class DSRRouter : public ReliableRouter /** Not in our route cache, rebroadcast on their behalf (after adding ourselves to the request route) */ void resendRouteRequest(const MeshPacket *p); + + /** + * Record that forwarder can reach dest for us, but they will need numHops to get there. + * If our routing tables already have something that can reach that node in fewer hops we will keep the existing route + * instead. + */ + void setRoute(NodeNum dest, NodeNum forwarder, uint8_t numHops); }; \ No newline at end of file