mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-24 05:50:16 +00:00
Set last byte to 0xFF if it ended at 0x00
As per an idea of @S5NC
This commit is contained in:
parent
81f57b65e1
commit
ef2c6eed05
@ -19,7 +19,7 @@ ErrorCode NextHopRouter::send(meshtastic_MeshPacket *p)
|
|||||||
bool NextHopRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
|
bool NextHopRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
|
||||||
{
|
{
|
||||||
if (wasSeenRecently(p)) { // Note: this will also add a recent packet record
|
if (wasSeenRecently(p)) { // Note: this will also add a recent packet record
|
||||||
if (p->next_hop == (uint8_t)(getNodeNum() & 0xFF)) {
|
if (p->next_hop == nodeDB.getLastByteOfNodeNum(getNodeNum())) {
|
||||||
LOG_DEBUG("Ignoring incoming msg, because we've already seen it.\n");
|
LOG_DEBUG("Ignoring incoming msg, because we've already seen it.\n");
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("Ignoring incoming msg, because we've already seen it and cancel any outgoing packets.\n");
|
LOG_DEBUG("Ignoring incoming msg, because we've already seen it and cancel any outgoing packets.\n");
|
||||||
@ -51,7 +51,7 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
|
|||||||
|
|
||||||
if (config.device.role != meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE) {
|
if (config.device.role != meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE) {
|
||||||
if ((p->to != getNodeNum()) && (getFrom(p) != getNodeNum())) {
|
if ((p->to != getNodeNum()) && (getFrom(p) != getNodeNum())) {
|
||||||
if (p->next_hop == (uint8_t)(getNodeNum() & 0xFF)) {
|
if (p->next_hop == nodeDB.getLastByteOfNodeNum(getNodeNum())) {
|
||||||
meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
|
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->relay_node);
|
LOG_INFO("Relaying received next-hop message coming from %x\n", p->relay_node);
|
||||||
|
|
||||||
|
@ -824,10 +824,10 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp)
|
|||||||
|
|
||||||
// If this packet didn't travel any hops, then it was sent directly to us, so we know what to use as next hop to this node
|
// If this packet didn't travel any hops, then it was sent directly to us, so we know what to use as next hop to this node
|
||||||
if (mp.original_hop_limit == mp.hop_limit) {
|
if (mp.original_hop_limit == mp.hop_limit) {
|
||||||
info->next_hop = (uint8_t)(mp.from & 0xFF);
|
info->next_hop = getLastByteOfNodeNum(mp.from);
|
||||||
} else if (mp.relay_node && (mp.original_hop_limit - mp.hop_limit == 1)) {
|
} else if (mp.relay_node && (mp.original_hop_limit - mp.hop_limit == 1)) {
|
||||||
// This packet traveled one hop, so we can use the relay_node as next_hop
|
// This packet traveled one hop, so we can use the relay_node as next_hop
|
||||||
info->next_hop = (uint8_t)(mp.relay_node & 0xFF);
|
info->next_hop = getLastByteOfNodeNum(mp.relay_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,9 @@ class NodeDB
|
|||||||
/// @return our node number
|
/// @return our node number
|
||||||
NodeNum getNodeNum() { return myNodeInfo.my_node_num; }
|
NodeNum getNodeNum() { return myNodeInfo.my_node_num; }
|
||||||
|
|
||||||
|
// @return last byte of a NodeNum, 0xFF if it ended at 0x00
|
||||||
|
uint8_t getLastByteOfNodeNum(NodeNum num) { return (uint8_t)((num & 0xFF) ? (num & 0xFF) : 0xFF); }
|
||||||
|
|
||||||
/// if returns false, that means our node should send a DenyNodeNum response. If true, we think the number is okay for use
|
/// if returns false, that means our node should send a DenyNodeNum response. If true, we think the number is okay for use
|
||||||
// bool handleWantNodeNum(NodeNum n);
|
// bool handleWantNodeNum(NodeNum n);
|
||||||
|
|
||||||
|
@ -241,10 +241,10 @@ ErrorCode Router::send(meshtastic_MeshPacket *p)
|
|||||||
p->from = getFrom(p);
|
p->from = getFrom(p);
|
||||||
|
|
||||||
// If we are the original transmitter, set the original hop limit
|
// If we are the original transmitter, set the original hop limit
|
||||||
if (p->from == nodeDB.getNodeNum())
|
if (p->from == getNodeNum())
|
||||||
p->original_hop_limit = config.lora.hop_limit ? config.lora.hop_limit : HOP_RELIABLE;
|
p->original_hop_limit = config.lora.hop_limit ? config.lora.hop_limit : HOP_RELIABLE;
|
||||||
|
|
||||||
p->relay_node = (uint8_t)(getNodeNum() & 0xFF); // set the current relayer to us
|
p->relay_node = nodeDB.getLastByteOfNodeNum(getNodeNum()); // set the relayer to us
|
||||||
|
|
||||||
// If the packet hasn't yet been encrypted, do so now (it might already be encrypted if we are just forwarding it)
|
// If the packet hasn't yet been encrypted, do so now (it might already be encrypted if we are just forwarding it)
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ size_t NeighborInfoModule::cleanUpNeighbors()
|
|||||||
// Clear all next hops of nodes that had this neighbor as next hop
|
// Clear all next hops of nodes that had this neighbor as next hop
|
||||||
for (unsigned int j = 0; j < nodeDB.getNumMeshNodes(); j++) {
|
for (unsigned int j = 0; j < nodeDB.getNumMeshNodes(); j++) {
|
||||||
meshtastic_NodeInfoLite *node = nodeDB.getMeshNodeByIndex(j);
|
meshtastic_NodeInfoLite *node = nodeDB.getMeshNodeByIndex(j);
|
||||||
if (node->next_hop == (uint8_t)(neighbors[index].node_id & 0xFF)) {
|
if (node->next_hop == nodeDB.getLastByteOfNodeNum(neighbors[index].node_id)) {
|
||||||
node->next_hop = 0;
|
node->next_hop = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ void NeighborInfoModule::updateNextHops(meshtastic_NeighborInfo *np)
|
|||||||
meshtastic_NodeInfoLite *currentNode = nodeDB.getMeshNode(np->node_id);
|
meshtastic_NodeInfoLite *currentNode = nodeDB.getMeshNode(np->node_id);
|
||||||
// Check if the sender of this neighborInfo packet is a neighbor of ourselves
|
// Check if the sender of this neighborInfo packet is a neighbor of ourselves
|
||||||
if (currentNode && isANeighbor(np->node_id)) {
|
if (currentNode && isANeighbor(np->node_id)) {
|
||||||
currentNode->next_hop = (uint8_t)(np->node_id & 0xFF); // Set the next hop to the sender of this packet
|
currentNode->next_hop = nodeDB.getLastByteOfNodeNum(np->node_id); // Set the next hop to the sender of this packet
|
||||||
for (uint8_t i = 0; i < np->neighbors_count; i++) {
|
for (uint8_t i = 0; i < np->neighbors_count; i++) {
|
||||||
if (isANeighbor(np->neighbors[i].node_id))
|
if (isANeighbor(np->neighbors[i].node_id))
|
||||||
continue; // This node is a neighbor of ourselves
|
continue; // This node is a neighbor of ourselves
|
||||||
@ -259,7 +259,7 @@ void NeighborInfoModule::updateNextHops(meshtastic_NeighborInfo *np)
|
|||||||
meshtastic_NodeInfoLite *neighborOfCurrentNode = nodeDB.getMeshNode(np->neighbors[i].node_id);
|
meshtastic_NodeInfoLite *neighborOfCurrentNode = nodeDB.getMeshNode(np->neighbors[i].node_id);
|
||||||
// Update next hop of this node to the sender of this packet, because it is the most recent neighbor
|
// Update next hop of this node to the sender of this packet, because it is the most recent neighbor
|
||||||
if (neighborOfCurrentNode)
|
if (neighborOfCurrentNode)
|
||||||
neighborOfCurrentNode->next_hop = (uint8_t)(currentNode->num & 0xFF);
|
neighborOfCurrentNode->next_hop = nodeDB.getLastByteOfNodeNum(currentNode->num);
|
||||||
}
|
}
|
||||||
} else if (currentNode) { // Sender is not a neighbor
|
} else if (currentNode) { // Sender is not a neighbor
|
||||||
// Find common neighbors and use the most recent as next hop to this node
|
// Find common neighbors and use the most recent as next hop to this node
|
||||||
@ -270,7 +270,7 @@ void NeighborInfoModule::updateNextHops(meshtastic_NeighborInfo *np)
|
|||||||
if (neighborOfCurrentNode && isANeighbor(neighborOfCurrentNode->num)) {
|
if (neighborOfCurrentNode && isANeighbor(neighborOfCurrentNode->num)) {
|
||||||
// This neighbor was heard more recently than the current next hop
|
// This neighbor was heard more recently than the current next hop
|
||||||
if (neighborOfCurrentNode->last_heard > maxLastHeard) {
|
if (neighborOfCurrentNode->last_heard > maxLastHeard) {
|
||||||
currentNode->next_hop = (uint8_t)(neighborOfCurrentNode->num & 0xFF);
|
currentNode->next_hop = nodeDB.getLastByteOfNodeNum(neighborOfCurrentNode->num);
|
||||||
maxLastHeard = neighborOfCurrentNode->last_heard;
|
maxLastHeard = neighborOfCurrentNode->last_heard;
|
||||||
LOG_DEBUG("More recent node found, so update next_hop of %x to %x\n", currentNode->num,
|
LOG_DEBUG("More recent node found, so update next_hop of %x to %x\n", currentNode->num,
|
||||||
neighborOfCurrentNode->num);
|
neighborOfCurrentNode->num);
|
||||||
|
Loading…
Reference in New Issue
Block a user