mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 14:42:05 +00:00
cleanup virtual inheritence for Router/Reliable/Flooding/DSR
This commit is contained in:
parent
8e2e154cdd
commit
c9cb293bf2
@ -48,7 +48,8 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
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
|
||||
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)
|
||||
@ -67,12 +68,17 @@ void DSRRouter::sniffReceived(const MeshPacket *p)
|
||||
}
|
||||
}
|
||||
|
||||
// Handle route reply packets
|
||||
if (p->decoded.which_payload == SubPacket_reply_tag) {
|
||||
updateRoutes(p->decoded.reply, true);
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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 a nak with no-route available
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,19 +17,18 @@ ErrorCode FloodingRouter::send(MeshPacket *p)
|
||||
return Router::send(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from loop()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
*
|
||||
* Note: this method will free the provided packet
|
||||
*/
|
||||
void FloodingRouter::handleReceived(MeshPacket *p)
|
||||
bool FloodingRouter::shouldFilterReceived(const MeshPacket *p)
|
||||
{
|
||||
if (wasSeenRecently(p)) {
|
||||
DEBUG_MSG("Ignoring incoming msg, because we've already seen it\n");
|
||||
packetPool.release(p);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Router::shouldFilterReceived(p);
|
||||
}
|
||||
|
||||
void FloodingRouter::sniffReceived(const MeshPacket *p)
|
||||
{
|
||||
// If a broadcast, possibly _also_ send copies out into the mesh.
|
||||
// (FIXME, do something smarter than naive flooding here)
|
||||
if (p->to == NODENUM_BROADCAST && p->hop_limit > 0) {
|
||||
@ -50,6 +49,5 @@ void FloodingRouter::handleReceived(MeshPacket *p)
|
||||
}
|
||||
|
||||
// handle the packet as normal
|
||||
Router::handleReceived(p);
|
||||
}
|
||||
Router::sniffReceived(p);
|
||||
}
|
||||
|
@ -46,11 +46,15 @@ class FloodingRouter : public Router, protected PacketHistory
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called from loop()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
* Should this incoming filter be dropped?
|
||||
*
|
||||
* Note: this method will free the provided packet
|
||||
* Called immedately on receiption, before any further processing.
|
||||
* @return true to abandon the packet
|
||||
*/
|
||||
virtual void handleReceived(MeshPacket *p);
|
||||
virtual bool shouldFilterReceived(const MeshPacket *p);
|
||||
|
||||
/**
|
||||
* Look for broadcasts we need to rebroadcast
|
||||
*/
|
||||
virtual void sniffReceived(const MeshPacket *p);
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ ErrorCode ReliableRouter::send(MeshPacket *p)
|
||||
*
|
||||
* Otherwise, let superclass handle it.
|
||||
*/
|
||||
void ReliableRouter::handleReceived(MeshPacket *p)
|
||||
void ReliableRouter::sniffReceived(const MeshPacket *p)
|
||||
{
|
||||
NodeNum ourNode = getNodeNum();
|
||||
|
||||
@ -55,7 +55,6 @@ void ReliableRouter::handleReceived(MeshPacket *p)
|
||||
sendAckNak(true, p->from, p->id);
|
||||
}
|
||||
|
||||
if (perhapsDecode(p)) {
|
||||
// If the payload is valid, look for ack/nak
|
||||
|
||||
PacketId ackId = p->decoded.which_ack == SubPacket_success_id_tag ? p->decoded.ack.success_id : 0;
|
||||
@ -73,10 +72,9 @@ void ReliableRouter::handleReceived(MeshPacket *p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle the packet as normal
|
||||
FloodingRouter::handleReceived(p);
|
||||
FloodingRouter::sniffReceived(p);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,13 +88,9 @@ class ReliableRouter : public FloodingRouter
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called from loop()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
*
|
||||
* Note: this method will free the provided packet
|
||||
* Look for acks/naks or someone retransmitting us
|
||||
*/
|
||||
virtual void handleReceived(MeshPacket *p);
|
||||
virtual void sniffReceived(const MeshPacket *p);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ void Router::loop()
|
||||
{
|
||||
MeshPacket *mp;
|
||||
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL) {
|
||||
handleReceived(mp);
|
||||
perhapsHandleReceived(mp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,6 +191,12 @@ void Router::handleReceived(MeshPacket *p)
|
||||
notifyPacketReceived.notifyObservers(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Router::perhapsHandleReceived(MeshPacket *p)
|
||||
{
|
||||
if (!shouldFilterReceived(p))
|
||||
handleReceived(p);
|
||||
|
||||
packetPool.release(p);
|
||||
}
|
@ -67,14 +67,12 @@ class Router
|
||||
virtual ErrorCode send(MeshPacket *p);
|
||||
|
||||
/**
|
||||
* Called from loop()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
* Should this incoming filter be dropped?
|
||||
*
|
||||
* Note: this packet will never be called for messages sent/generated by this node.
|
||||
* Note: this method will free the provided packet.
|
||||
* Called immedately on receiption, before any further processing.
|
||||
* @return true to abandon the packet
|
||||
*/
|
||||
virtual void handleReceived(MeshPacket *p);
|
||||
virtual bool shouldFilterReceived(const MeshPacket *p) { return false; }
|
||||
|
||||
/**
|
||||
* Every (non duplicate) packet this node receives will be passed through this method. This allows subclasses to
|
||||
@ -88,6 +86,27 @@ class Router
|
||||
* @return true for success, false for corrupt packet.
|
||||
*/
|
||||
bool perhapsDecode(MeshPacket *p);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Called from loop()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
*
|
||||
* Note: this packet will never be called for messages sent/generated by this node.
|
||||
* Note: this method will free the provided packet.
|
||||
*/
|
||||
void perhapsHandleReceived(MeshPacket *p);
|
||||
|
||||
/**
|
||||
* Called from perhapsHandleReceived() - allows subclass message delivery behavior.
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
*
|
||||
* Note: this packet will never be called for messages sent/generated by this node.
|
||||
* Note: this method will free the provided packet.
|
||||
*/
|
||||
void handleReceived(MeshPacket *p);
|
||||
};
|
||||
|
||||
extern Router &router;
|
||||
|
Loading…
Reference in New Issue
Block a user