From a05b9510184c26354193a54e5a39e8416ae420eb Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Tue, 14 Jan 2025 20:13:20 +1100 Subject: [PATCH] * removed unused Destination class --- examples/simple_secure_chat/main.cpp | 4 ---- src/Destination.cpp | 29 ---------------------------- src/Destination.h | 25 ------------------------ src/Mesh.cpp | 4 ++++ 4 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 src/Destination.cpp delete mode 100644 src/Destination.h diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index 50246ec..411196b 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -107,10 +107,6 @@ protected: void onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_idx, uint8_t* data, size_t len) override { if (type == PAYLOAD_TYPE_TXT_MSG && len > 5) { - // NOTE: this is a 'first packet wins' impl. When receiving from multiple paths, the first to arrive wins. - // For flood mode, the path may not be the 'best' in terms of hops. - // FUTURE: could send back multiple paths, using createPathReturn(), and let sender choose which to use(?) - int i = matching_peer_indexes[sender_idx]; if (i < 0 && i >= num_contacts) { MESH_DEBUG_PRINTLN("onPeerDataRecv: Invalid sender idx: %d", i); diff --git a/src/Destination.cpp b/src/Destination.cpp deleted file mode 100644 index a6408d7..0000000 --- a/src/Destination.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "Destination.h" -#include "Utils.h" -#include - -namespace mesh { - -Destination::Destination(const Identity& identity, const char* name) { - uint8_t name_hash[MAX_HASH_SIZE]; - Utils::sha256(name_hash, MAX_HASH_SIZE, (const uint8_t *)name, strlen(name)); - - Utils::sha256(hash, MAX_HASH_SIZE, name_hash, MAX_HASH_SIZE, identity.pub_key, PUB_KEY_SIZE); -} - -Destination::Destination(const char* name) { - uint8_t name_hash[MAX_HASH_SIZE]; - Utils::sha256(name_hash, MAX_HASH_SIZE, (const uint8_t *)name, strlen(name)); - - Utils::sha256(hash, MAX_HASH_SIZE, name_hash, MAX_HASH_SIZE); -} - -Destination::Destination() { - memset(hash, 0, MAX_HASH_SIZE); -} - -bool Destination::matches(const uint8_t* other_hash) { - return memcmp(hash, other_hash, MAX_HASH_SIZE) == 0; -} - -} \ No newline at end of file diff --git a/src/Destination.h b/src/Destination.h deleted file mode 100644 index 071741e..0000000 --- a/src/Destination.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -namespace mesh { - -/** - * \brief Represents an end-point in the mesh, identified by a truncated SHA256 hash. (of DEST_HASH_SIZE) - * The hash is either from just a 'name' (C-string), and these can be thought of as 'broadcast' addresses, - * or can be the hash of name + Identity.public_key -*/ -class Destination { -public: - uint8_t hash[MAX_HASH_SIZE]; - - Destination(const Identity& identity, const char* name); - Destination(const char* name); - Destination(const uint8_t desthash[]) { memcpy(hash, desthash, MAX_HASH_SIZE); } - Destination(); - - bool matches(const uint8_t* other_hash); -}; - -} diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 329eaf5..0e7414e 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -73,6 +73,10 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) { if (i + 2 >= pkt->payload_len) { MESH_DEBUG_PRINTLN("Mesh::onRecvPacket(): incomplete data packet"); } else if (!_tables->hasSeen(pkt)) { + // NOTE: this is a 'first packet wins' impl. When receiving from multiple paths, the first to arrive wins. + // For flood mode, the path may not be the 'best' in terms of hops. + // FUTURE: could send back multiple paths, using createPathReturn(), and let sender choose which to use(?) + if (self_id.isHashMatch(&dest_hash)) { // scan contacts DB, for all matching hashes of 'src_hash' (max 4 matches supported ATM) int num = searchPeersByHash(&src_hash);