mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
DSR WIP
This commit is contained in:
@@ -36,20 +36,32 @@ when we receive a routeError packet
|
||||
- fixme, eventually keep caches of possible other routes.
|
||||
*/
|
||||
|
||||
ErrorCode DSRRouter::send(MeshPacket *p)
|
||||
{
|
||||
// If we have an entry in our routing tables, just send it, otherwise start a route discovery
|
||||
|
||||
return ReliableRouter::send(p);
|
||||
}
|
||||
|
||||
void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
{
|
||||
// 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.
|
||||
// this will also add records for any ACKs we receive for our messages
|
||||
if (p->to != NODENUM_BROADCAST || p->hop_limit != HOP_RELIABLE) {
|
||||
addRoute(p->from, p->from, 0); // We are adjacent with zero hops
|
||||
}
|
||||
|
||||
// FIXME, update nodedb
|
||||
|
||||
// Handle route discovery packets (will be a broadcast message)
|
||||
if (p->decoded.which_payload == SubPacket_route_request_tag) {
|
||||
switch (p->decoded.which_payload) {
|
||||
case SubPacket_route_request_tag:
|
||||
// Handle route discovery packets (will be a broadcast message)
|
||||
// FIXME - always start request with the senders nodenum
|
||||
|
||||
if (weAreInRoute(p->decoded.route_request)) {
|
||||
DEBUG_MSG("Ignoring a route request that contains us\n");
|
||||
} else {
|
||||
updateRoutes(p->decoded.route_request,
|
||||
false); // Update our routing tables based on the route that came in so far on this request
|
||||
true); // Update our routing tables based on the route that came in so far on this request
|
||||
|
||||
if (p->decoded.dest == getNodeNum()) {
|
||||
// They were looking for us, send back a route reply (the sender address will be first in the list)
|
||||
@@ -66,23 +78,21 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SubPacket_route_reply_tag:
|
||||
updateRoutes(p->decoded.route_reply, false);
|
||||
|
||||
// Handle route reply packets
|
||||
if (p->decoded.which_payload == SubPacket_route_reply_tag) {
|
||||
updateRoutes(p->decoded.route_reply, true);
|
||||
}
|
||||
// FIXME, if any of our current pending packets were waiting for this route, send them (and leave them as regular pending
|
||||
// packets until ack arrives)
|
||||
// FIXME, if we don't get a route reply at all (or a route error), timeout and generate a routeerror TIMEOUT on our own...
|
||||
break;
|
||||
case SubPacket_route_error_tag:
|
||||
removeRoute(p->decoded.dest);
|
||||
|
||||
// Handle route error packets
|
||||
if (p->decoded.which_payload == SubPacket_route_error_tag) {
|
||||
// FIXME
|
||||
}
|
||||
|
||||
// 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) {
|
||||
addRoute(p->from, p->from, 0); // We are adjacent with zero hops
|
||||
// FIXME: if any pending packets were waiting on this route, delete them
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// We simply ignore ACKs - because ReliableRouter will delete the pending packet for us
|
||||
@@ -92,7 +102,7 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
|
||||
// We need to route this packet to some other node
|
||||
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 RouteError no-route available
|
||||
// if we have a route out, resend the packet to the next hop, otherwise return RouteError no-route available
|
||||
|
||||
NodeNum nextHop = getNextHop(p->decoded.dest);
|
||||
if (nextHop) {
|
||||
@@ -101,6 +111,7 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
// We don't have a route out
|
||||
assert(p->decoded.source); // I think this is guaranteed by now
|
||||
|
||||
// FIXME - what if the current packet _is_ a route error packet?
|
||||
sendRouteError(p, RouteError_NO_ROUTE);
|
||||
}
|
||||
|
||||
@@ -113,7 +124,7 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
if (nakId) {
|
||||
auto pending = findPendingPacket(p->to, nakId);
|
||||
if (pending && pending->packet->decoded.source) { // if source not set, this was not a multihop packet, just ignore
|
||||
removeRoute(pending->packet->decoded.dest, p->to); // We no longer have a route to the specified node
|
||||
removeRoute(pending->packet->decoded.dest); // We no longer have a route to the specified node
|
||||
|
||||
sendRouteError(p, RouteError_GOT_NAK);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user