Skip to content

Commit b11f439

Browse files
author
Scott Powell
committed
* companion: fix for importContact(). Now removes the packet-hash from table, before 'replaying'
1 parent 1680eb2 commit b11f439

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Mesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class GroupChannel {
1616
class MeshTables {
1717
public:
1818
virtual bool hasSeen(const Packet* packet) = 0;
19+
virtual void clear(const Packet* packet) = 0; // remove this packet hash from table
1920
};
2021

2122
/**

src/helpers/BaseChatMesh.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ bool BaseChatMesh::importContact(const uint8_t src_buf[], uint8_t len) {
373373
if (pkt) {
374374
if (pkt->readFrom(src_buf, len) && pkt->getPayloadType() == PAYLOAD_TYPE_ADVERT) {
375375
pkt->header |= ROUTE_TYPE_FLOOD; // simulate it being received flood-mode
376+
getTables()->clear(pkt); // remove packet hash from table, so we can receive/process it again
376377
_pendingLoopback = pkt; // loop-back, as if received over radio
377378
return true; // success
378379
} else {

src/helpers/SimpleMeshTables.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ class SimpleMeshTables : public mesh::MeshTables {
8080
return false;
8181
}
8282

83+
void clear(const mesh::Packet* packet) override {
84+
if (packet->getPayloadType() == PAYLOAD_TYPE_ACK) {
85+
uint32_t ack;
86+
memcpy(&ack, packet->payload, 4);
87+
for (int i = 0; i < MAX_PACKET_ACKS; i++) {
88+
if (ack == _acks[i]) {
89+
_acks[i] = 0;
90+
break;
91+
}
92+
}
93+
} else {
94+
uint8_t hash[MAX_HASH_SIZE];
95+
packet->calculatePacketHash(hash);
96+
97+
uint8_t* sp = _hashes;
98+
for (int i = 0; i < MAX_PACKET_HASHES; i++, sp += MAX_HASH_SIZE) {
99+
if (memcmp(hash, sp, MAX_HASH_SIZE) == 0) {
100+
memset(sp, 0, MAX_HASH_SIZE);
101+
break;
102+
}
103+
}
104+
}
105+
}
106+
83107
uint32_t getNumDirectDups() const { return _direct_dups; }
84108
uint32_t getNumFloodDups() const { return _flood_dups; }
85109

0 commit comments

Comments
 (0)