Set original hop limit in header flags

This commit is contained in:
GUVWAF
2023-10-13 21:00:12 +02:00
parent 3776064b80
commit 44dc270c8a
14 changed files with 77 additions and 78 deletions

View File

@@ -10,7 +10,7 @@ ErrorCode NextHopRouter::send(meshtastic_MeshPacket *p)
// Add any messages _we_ send to the seen message list (so we will ignore all retransmissions we see)
wasSeenRecently(p); // FIXME, move this to a sniffSent method
p->next_hop = getNextHop(p->to, p->current_relayer); // set the next hop
p->next_hop = getNextHop(p->to, p->relay_node); // set the next hop
LOG_DEBUG("Setting next hop for packet with dest %x to %x\n", p->to, p->next_hop);
return Router::send(p);
@@ -19,7 +19,7 @@ ErrorCode NextHopRouter::send(meshtastic_MeshPacket *p)
bool NextHopRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
{
if (wasSeenRecently(p)) { // Note: this will also add a recent packet record
if (p->next_hop == getNodeNum()) {
if (p->next_hop == (uint8_t)(getNodeNum() & 0xFF)) {
LOG_DEBUG("Ignoring incoming msg, because we've already seen it.\n");
} else {
LOG_DEBUG("Ignoring incoming msg, because we've already seen it and cancel any outgoing packets.\n");
@@ -36,14 +36,14 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
bool isAck =
((c && c->error_reason == meshtastic_Routing_Error_NONE)); // consider only ROUTING_APP message without error as ACK
if (isAck) {
// Update next-hop of this successful transmission to current relayer, but ONLY if "from" is not 0 or ourselves (means
// Update next-hop of this successful transmission to the relay node, but ONLY if "from" is not 0 or ourselves (means
// implicit ACK or someone is relaying our ACK)
if (p->from != 0 && p->from != getNodeNum()) {
if (p->current_relayer) {
if (p->relay_node) {
meshtastic_NodeInfoLite *sentTo = nodeDB.getMeshNode(p->from);
if (sentTo) {
LOG_DEBUG("Update next hop of %x to %x based on received ACK.\n", p->from, p->current_relayer);
sentTo->next_hop = p->current_relayer;
LOG_DEBUG("Update next hop of 0x%x to 0x%x based on received ACK.\n", p->from, p->relay_node);
sentTo->next_hop = p->relay_node;
}
}
}
@@ -51,9 +51,9 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
if (config.device.role != meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE) {
if ((p->to != getNodeNum()) && (getFrom(p) != getNodeNum())) {
if (p->next_hop == getNodeNum()) {
if (p->next_hop == (uint8_t)(getNodeNum() & 0xFF)) {
meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
LOG_INFO("Relaying received next-hop message coming from %x\n", p->current_relayer);
LOG_INFO("Relaying received next-hop message coming from %x\n", p->relay_node);
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
// If it is a traceRoute request, update the route that it went via me
@@ -71,8 +71,7 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
LOG_DEBUG("No preference for next hop, using FloodingRouter\n");
FloodingRouter::sniffReceived(p, c);
} else if (p->to == NODENUM_BROADCAST) {
// TODO how to handle broadcast messages?
LOG_DEBUG("TODO: Broadcast next-hop message\n");
// TODO: Smarter way of handling broadcasts
FloodingRouter::sniffReceived(p, c);
}
}
@@ -84,23 +83,22 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
}
/**
* Get the next hop for a destination, given the current relayer
* Get the next hop for a destination, given the relay node
* @return the node number of the next hop, 0 if no preference (fallback to FloodingRouter)
*/
uint32_t NextHopRouter::getNextHop(NodeNum to, NodeNum current_relayer)
uint8_t NextHopRouter::getNextHop(NodeNum to, uint8_t relay_node)
{
meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(to);
if (node) {
// We are careful not to return the current relayer as the next hop
if (node->next_hop != current_relayer) {
LOG_DEBUG("Next hop for %x is %x\n", to, node->next_hop);
// We are careful not to return the relay node as the next hop
if (node->next_hop != relay_node) {
LOG_DEBUG("Next hop for 0x%x is 0x%x\n", to, node->next_hop);
return node->next_hop;
} else {
LOG_WARN("Next hop for %x is %x, which is the same as current relayer; setting as no preference\n", to,
node->next_hop);
return 0;
LOG_WARN("Next hop for 0x%x is 0x%x, same as relayer; setting as no preference\n", to, node->next_hop);
return NO_NEXT_HOP_PREFERENCE;
}
} else {
return 0;
return NO_NEXT_HOP_PREFERENCE;
}
}