-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from geeksville/reliable
Reliable
- Loading branch information
Showing
11 changed files
with
231 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule proto
updated
from e095ea to bfae47
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "DSRRouter.h" | ||
#include "configuration.h" | ||
|
||
/* when we receive any packet | ||
- sniff and update tables (especially useful to find adjacent nodes). Update user, network and position info. | ||
- if we need to route() that packet, resend it to the next_hop based on our nodedb. | ||
- if it is broadcast or destined for our node, deliver locally | ||
- handle routereply/routeerror/routediscovery messages as described below | ||
- then free it | ||
routeDiscovery | ||
- if we've already passed through us (or is from us), then it ignore it | ||
- use the nodes already mentioned in the request to update our routing table | ||
- if they were looking for us, send back a routereply | ||
- if max_hops is zero and they weren't looking for us, drop (FIXME, send back error - I think not though?) | ||
- if we receive a discovery packet, we use it to populate next_hop (if needed) towards the requester (after decrementing max_hops) | ||
- if we receive a discovery packet, and we have a next_hop in our nodedb for that destination we send a (reliable) we send a route | ||
reply towards the requester | ||
when sending any reliable packet | ||
- if timeout doing retries, send a routeError (nak) message back towards the original requester. all nodes eavesdrop on that | ||
packet and update their route caches. | ||
when we receive a routereply packet | ||
- update next_hop on the node, if the new reply needs fewer hops than the existing one (we prefer shorter paths). fixme, someday | ||
use a better heuristic | ||
when we receive a routeError packet | ||
- delete the route for that failed recipient, restartRouteDiscovery() | ||
- if we receive routeerror in response to a discovery, | ||
- fixme, eventually keep caches of possible other routes. | ||
*/ | ||
|
||
void DSRRouter::sniffReceived(const MeshPacket *p) | ||
{ | ||
|
||
// FIXME, update nodedb | ||
|
||
// Handle route discovery packets (will be a broadcast message) | ||
if (p->decoded.which_payload == SubPacket_request_tag) { | ||
// FIXME - always start request with the senders nodenum | ||
|
||
if (weAreInRoute(p->decoded.request)) { | ||
DEBUG_MSG("Ignoring a route request that contains us\n"); | ||
} else { | ||
updateRoutes(p->decoded.request, false); // 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.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.request, nextHop); | ||
} else { | ||
// Not in our route cache, rebroadcast on their behalf (after adding ourselves to the request route) | ||
resendRouteRequest(p); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Handle regular packets | ||
if (p->to == getNodeNum()) { // Destined for us (at least for this hop) | ||
|
||
// We need to route this packet | ||
if (p->decoded.dest != p->to) { | ||
// FIXME | ||
} | ||
} | ||
|
||
return ReliableRouter::sniffReceived(p); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "ReliableRouter.h" | ||
|
||
class DSRRouter : public ReliableRouter | ||
{ | ||
|
||
protected: | ||
/** | ||
* Every (non duplicate) packet this node receives will be passed through this method. This allows subclasses to | ||
* update routing tables etc... based on what we overhear (even for messages not destined to our node) | ||
*/ | ||
virtual void sniffReceived(const MeshPacket *p); | ||
|
||
private: | ||
/** | ||
* Does our node appear in the specified route | ||
*/ | ||
bool weAreInRoute(const RouteDiscovery &route); | ||
|
||
/** | ||
* Given a DSR route, use that route to update our DB of possible routes | ||
**/ | ||
void updateRoutes(const RouteDiscovery &route, bool reverse); | ||
|
||
/** | ||
* send back a route reply (the sender address will be first in the list) | ||
*/ | ||
void sendRouteReply(const RouteDiscovery &route, NodeNum toAppend = 0); | ||
|
||
/** | ||
* Given a nodenum return the next node we should forward to if we want to reach that node. | ||
* | ||
* @return 0 if no route found | ||
*/ | ||
NodeNum getNextHop(NodeNum dest); | ||
|
||
/** Not in our route cache, rebroadcast on their behalf (after adding ourselves to the request route) | ||
*/ | ||
void resendRouteRequest(const MeshPacket *p); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.