mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 10:42:49 +00:00
WIP 1.2 move routing into plugin
This commit is contained in:
@@ -62,7 +62,7 @@ ErrorCode DSRRouter::send(MeshPacket *p)
|
||||
return ReliableRouter::send(p);
|
||||
}
|
||||
|
||||
void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
void DSRRouter::sniffReceived(const MeshPacket *p, const Routing &c)
|
||||
{
|
||||
// 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
|
||||
@@ -72,25 +72,25 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
addRoute(p->from, p->from, 0); // We are adjacent with zero hops
|
||||
}
|
||||
|
||||
switch (p->decoded.which_payloadVariant) {
|
||||
case SubPacket_route_request_tag:
|
||||
switch (c.which_variant) {
|
||||
case Routing_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)) {
|
||||
if (weAreInRoute(c.route_request)) {
|
||||
DEBUG_MSG("Ignoring a route request that contains us\n");
|
||||
} else {
|
||||
updateRoutes(p->decoded.route_request,
|
||||
updateRoutes(c.route_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)
|
||||
sendRouteReply(p->decoded.route_request);
|
||||
sendRouteReply(c.route_request);
|
||||
} else {
|
||||
// They were looking for someone else, forward it along (as a zero hop broadcast)
|
||||
NodeNum nextHop = getNextHop(p->decoded.dest);
|
||||
if (nextHop) {
|
||||
// in our route cache, reply to the requester (the sender address will be first in the list)
|
||||
sendRouteReply(p->decoded.route_request, nextHop);
|
||||
sendRouteReply(c.route_request, nextHop);
|
||||
} else {
|
||||
// Not in our route cache, rebroadcast on their behalf (after adding ourselves to the request route)
|
||||
resendRouteRequest(p);
|
||||
@@ -98,14 +98,14 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SubPacket_route_reply_tag:
|
||||
updateRoutes(p->decoded.route_reply, false);
|
||||
case Routing_route_reply_tag:
|
||||
updateRoutes(c.route_reply, false);
|
||||
|
||||
// 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_error_reason_tag:
|
||||
case Routing_error_reason_tag:
|
||||
removeRoute(p->decoded.dest);
|
||||
|
||||
// FIXME: if any pending packets were waiting on this route, delete them
|
||||
@@ -131,7 +131,7 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
assert(p->decoded.source); // I think this is guaranteed by now
|
||||
|
||||
// FIXME - what if the current packet _is_ a route error packet?
|
||||
sendRouteError(p, ErrorReason_NO_ROUTE);
|
||||
sendRouteError(p, Routing_Error_NO_ROUTE);
|
||||
}
|
||||
|
||||
// FIXME, stop local processing of this packet
|
||||
@@ -139,18 +139,18 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
|
||||
// handle naks - convert them to route error packets
|
||||
// All naks are generated locally, because we failed resending the packet too many times
|
||||
PacketId nakId = p->decoded.which_ackVariant == SubPacket_fail_id_tag ? p->decoded.ackVariant.fail_id : 0;
|
||||
PacketId nakId = c.fail_id;
|
||||
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); // We no longer have a route to the specified node
|
||||
|
||||
sendRouteError(p, ErrorReason_GOT_NAK);
|
||||
sendRouteError(p, Routing_Error_GOT_NAK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ReliableRouter::sniffReceived(p);
|
||||
ReliableRouter::sniffReceived(p, c);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +230,7 @@ void DSRRouter::sendNextHop(NodeNum n, const MeshPacket *p)
|
||||
/**
|
||||
* Send a route error packet towards whoever originally sent this message
|
||||
*/
|
||||
void DSRRouter::sendRouteError(const MeshPacket *p, ErrorReason err)
|
||||
void DSRRouter::sendRouteError(const MeshPacket *p, Routing_Error err)
|
||||
{
|
||||
DEBUG_MSG("FIXME not implemented sendRouteError\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user