From 518db13ec897f5c4f2585f6fbe108c223376b6c6 Mon Sep 17 00:00:00 2001 From: Chad Attermann Date: Mon, 1 Jul 2024 20:25:46 -0600 Subject: [PATCH] WIP: Switched to macros for build control of logs --- examples/lora/LoRaInterface.cpp | 12 +- examples/lora/main.cpp | 10 +- examples/main.cpp | 14 +- examples/test/TestBytes.cpp | 80 ++--- examples/test/TestCollections.cpp | 16 +- examples/test/TestCrypto.cpp | 4 +- examples/test/TestFilesystem.cpp | 14 +- examples/test/TestOS.cpp | 4 +- examples/test/TestPersistence.cpp | 166 +++++------ examples/test/TestReference.cpp | 16 +- examples/test/main.cpp | 4 +- examples/udp/UDPInterface.cpp | 22 +- examples/udp/main.cpp | 10 +- src/Bytes.cpp | 6 +- src/Bytes.h | 20 +- src/Cryptography/Fernet.cpp | 34 +-- src/Cryptography/Hashes.cpp | 6 +- src/Cryptography/PKCS7.h | 12 +- src/Cryptography/X25519.h | 20 +- src/Destination.cpp | 98 +++--- src/Destination.h | 10 +- src/Filesystem.h | 32 +- src/Identity.cpp | 118 ++++---- src/Identity.h | 14 +- src/Interface.cpp | 22 +- src/Interface.h | 38 +-- src/Link.cpp | 2 +- src/Link.h | 6 +- src/Log.h | 13 +- src/Packet.cpp | 32 +- src/Packet.h | 18 +- src/Reticulum.cpp | 18 +- src/Reticulum.h | 12 +- src/Transport.cpp | 474 +++++++++++++++--------------- src/Utilities/OS.cpp | 4 +- src/Utilities/Persistence.h | 56 ++-- 36 files changed, 719 insertions(+), 718 deletions(-) diff --git a/examples/lora/LoRaInterface.cpp b/examples/lora/LoRaInterface.cpp index 4e7908a..18fd09d 100644 --- a/examples/lora/LoRaInterface.cpp +++ b/examples/lora/LoRaInterface.cpp @@ -58,7 +58,7 @@ bool LoRaInterface::start() { LoRa.setTxPower(power); info("LoRa init succeeded."); - extreme("LoRa bandwidth is " + std::to_string(Utilities::OS::round(bitrate()/1000.0, 2)) + " Kbps"); + TRACE("LoRa bandwidth is " + std::to_string(Utilities::OS::round(bitrate()/1000.0, 2)) + " Kbps"); #endif online(true); @@ -80,7 +80,7 @@ void LoRaInterface::loop() { #ifdef ARDUINO int available = LoRa.parsePacket(); if (available > 0) { - extreme("LoRaInterface: receiving bytes..."); + TRACE("LoRaInterface: receiving bytes..."); // read header (for detecting split packets) uint8_t header = LoRa.read(); @@ -103,15 +103,15 @@ void LoRaInterface::loop() { } /*virtual*/ void LoRaInterface::on_incoming(const Bytes& data) { - debug(toString() + ".on_incoming: data: " + data.toHex()); + DEBUG(toString() + ".on_incoming: data: " + data.toHex()); Interface::on_incoming(data); } /*virtual*/ void LoRaInterface::on_outgoing(const Bytes& data) { - debug(toString() + ".on_outgoing: data: " + data.toHex()); + DEBUG(toString() + ".on_outgoing: data: " + data.toHex()); try { if (online()) { - extreme("LoRaInterface: sending " + std::to_string(data.size()) + " bytes..."); + TRACE("LoRaInterface: sending " + std::to_string(data.size()) + " bytes..."); // Send packet #ifdef ARDUINO @@ -132,7 +132,7 @@ void LoRaInterface::loop() { LoRa.endPacket(); // finish packet and send it #endif - extreme("LoRaInterface: sent bytes"); + TRACE("LoRaInterface: sent bytes"); } Interface::on_outgoing(data); } diff --git a/examples/lora/main.cpp b/examples/lora/main.cpp index 163ad8b..f1ff998 100644 --- a/examples/lora/main.cpp +++ b/examples/lora/main.cpp @@ -71,7 +71,7 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); RNS::info("onPacket: data: " + data.toHex()); RNS::info("onPacket: text: \"" + data.toString() + "\""); - //RNS::extreme("onPacket: " + packet.debugString()); + //TRACE("onPacket: " + packet.debugString()); RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -80,7 +80,7 @@ void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); RNS::info("onPingPacket: data: " + data.toHex()); RNS::info("onPingPacket: text: \"" + data.toString() + "\""); - //RNS::extreme("onPingPacket: " + packet.debugString()); + //TRACE("onPingPacket: " + packet.debugString()); RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -191,14 +191,14 @@ void reticulum_setup() { RNS::head("Sending send packet...", RNS::LOG_EXTREME); send_packet.pack(); #ifndef NDEBUG - RNS::extreme("Test send_packet: " + send_packet.debugString()); + TRACE("Test send_packet: " + send_packet.debugString()); #endif RNS::head("Creating recv packet...", RNS::LOG_EXTREME); RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw()); recv_packet.unpack(); #ifndef NDEBUG - RNS::extreme("Test recv_packet: " + recv_packet.debugString()); + TRACE("Test recv_packet: " + recv_packet.debugString()); #endif RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME); @@ -257,7 +257,7 @@ void setup() { RNS::error("SPIFFS filesystem mount failed"); } else { - RNS::debug("SPIFFS filesystem is ready"); + DEBUG("SPIFFS filesystem is ready"); } #endif diff --git a/examples/main.cpp b/examples/main.cpp index 5e18ce4..c99935e 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -83,7 +83,7 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); RNS::info("onPacket: data: " + data.toHex()); RNS::info("onPacket: text: \"" + data.toString() + "\""); - //RNS::extreme("onPacket: " + packet.debugString()); + //TRACE("onPacket: " + packet.debugString()); RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -92,7 +92,7 @@ void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); RNS::info("onPingPacket: data: " + data.toHex()); RNS::info("onPingPacket: text: \"" + data.toString() + "\""); - //RNS::extreme("onPingPacket: " + packet.debugString()); + //TRACE("onPingPacket: " + packet.debugString()); RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -122,7 +122,7 @@ void run_tests() { try { - RNS::extreme("Running tests..."); + TRACE("Running tests..."); RNS::LogLevel loglevel = RNS::loglevel(); //RNS::loglevel(RNS::LOG_WARNING); RNS::loglevel(RNS::LOG_EXTREME); @@ -131,7 +131,7 @@ void run_tests() { //testCrypto(); testPersistence(); RNS::loglevel(loglevel); - RNS::extreme("Finished running tests"); + TRACE("Finished running tests"); //return; } catch (std::exception& e) { @@ -258,14 +258,14 @@ void reticulum_setup() { RNS::head("Sending send packet...", RNS::LOG_EXTREME); send_packet.pack(); #ifndef NDEBUG - RNS::extreme("Test send_packet: " + send_packet.debugString()); + TRACE("Test send_packet: " + send_packet.debugString()); #endif RNS::head("Creating recv packet...", RNS::LOG_EXTREME); RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw()); recv_packet.unpack(); #ifndef NDEBUG - RNS::extreme("Test recv_packet: " + recv_packet.debugString()); + TRACE("Test recv_packet: " + recv_packet.debugString()); #endif RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME); @@ -333,7 +333,7 @@ void setup() { RNS::error("SPIFFS filesystem mount failed"); } else { - RNS::debug("SPIFFS filesystem is ready"); + DEBUG("SPIFFS filesystem is ready"); } #endif diff --git a/examples/test/TestBytes.cpp b/examples/test/TestBytes.cpp index 7d9d649..3b89fca 100644 --- a/examples/test/TestBytes.cpp +++ b/examples/test/TestBytes.cpp @@ -16,7 +16,7 @@ RNS::Bytes ref("Test"); const RNS::Bytes& testBytesReference() { // NOTE: Can NOT return local instance as reference!!! //RNS::Bytes ref("Test"); - RNS::extreme("returning..."); + TRACE("returning..."); return ref; } @@ -51,18 +51,18 @@ void testBytesMain() { assert(prebuf != postbuf); if (prebuf == postbuf) { - RNS::extreme("bytess are the same"); + TRACE("bytess are the same"); } else { - RNS::extreme("bytess are different"); + TRACE("bytess are different"); } bytes += prebuf + postbuf; assert(bytes.size() == 11); assert(memcmp(bytes.data(), "Hello World", bytes.size()) == 0); - RNS::extreme("assign bytes: " + bytes.toString()); - RNS::extreme("assign prebuf: " + prebuf.toString()); - RNS::extreme("assign postbuf: " + postbuf.toString()); + TRACE("assign bytes: " + bytes.toString()); + TRACE("assign prebuf: " + prebuf.toString()); + TRACE("assign postbuf: " + postbuf.toString()); // test string assignment bytes = "Foo"; @@ -84,56 +84,56 @@ void testBytesMain() { // test left in range { RNS::Bytes left(bytes.left(5)); - RNS::extreme("left: " + left.toString()); + TRACE("left: " + left.toString()); assert(left.size() == 5); assert(memcmp(left.data(), "Hello", left.size()) == 0); } // test left oob { RNS::Bytes left(bytes.left(20)); - RNS::extreme("oob left: " + left.toString()); + TRACE("oob left: " + left.toString()); assert(left.size() == 11); assert(memcmp(left.data(), "Hello World", left.size()) == 0); } // test right in range { RNS::Bytes right(bytes.right(5)); - RNS::extreme("right: " + right.toString()); + TRACE("right: " + right.toString()); assert(right.size() == 5); assert(memcmp(right.data(), "World", right.size()) == 0); } // test right oob { RNS::Bytes right(bytes.right(20)); - RNS::extreme("oob right: " + right.toString()); + TRACE("oob right: " + right.toString()); assert(right.size() == 11); assert(memcmp(right.data(), "Hello World", right.size()) == 0); } // test mid in range { RNS::Bytes mid(bytes.mid(3, 5)); - RNS::extreme("mid: " + mid.toString()); + TRACE("mid: " + mid.toString()); assert(mid.size() == 5); assert(memcmp(mid.data(), "lo Wo", mid.size()) == 0); } // test mid oob pos { RNS::Bytes mid(bytes.mid(20, 5)); - RNS::extreme("oob pos mid: " + mid.toString()); + TRACE("oob pos mid: " + mid.toString()); assert(!mid); assert(mid.size() == 0); } // test mid oob pos { RNS::Bytes mid(bytes.mid(3, 20)); - RNS::extreme("oob len mid: " + mid.toString()); + TRACE("oob len mid: " + mid.toString()); assert(mid.size() == 8); assert(memcmp(mid.data(), "lo World", mid.size()) == 0); } // test mid to end variant { RNS::Bytes mid(bytes.mid(3)); - RNS::extreme("end mid: " + mid.toString()); + TRACE("end mid: " + mid.toString()); assert(mid.size() == 8); assert(memcmp(mid.data(), "lo World", mid.size()) == 0); } @@ -142,7 +142,7 @@ void testBytesMain() { { RNS::Bytes shrink(bytes); shrink.resize(5); - RNS::extreme("shrink: " + shrink.toString()); + TRACE("shrink: " + shrink.toString()); assert(shrink.size() == 5); assert(memcmp(shrink.data(), "Hello", shrink.size()) == 0); } @@ -151,9 +151,9 @@ void testBytesMain() { { RNS::Bytes strmbuf; strmbuf << prebuf << postbuf; - RNS::extreme("stream prebuf: " + prebuf.toString()); - RNS::extreme("stream postbuf: " + postbuf.toString()); - RNS::extreme("stream strmbuf: " + strmbuf.toString()); + TRACE("stream prebuf: " + prebuf.toString()); + TRACE("stream postbuf: " + postbuf.toString()); + TRACE("stream strmbuf: " + strmbuf.toString()); assert(strmbuf.size() == 11); assert(memcmp(strmbuf.data(), "Hello World", strmbuf.size()) == 0); assert(prebuf.size() == 5); @@ -170,9 +170,9 @@ void testBytesMain() { assert(memcmp(strmbuf.data(), "Stream ", strmbuf.size()) == 0); strmbuf << prebuf << postbuf; - RNS::extreme("stream prebuf: " + prebuf.toString()); - RNS::extreme("stream postbuf: " + postbuf.toString()); - RNS::extreme("stream strmbuf: " + strmbuf.toString()); + TRACE("stream prebuf: " + prebuf.toString()); + TRACE("stream postbuf: " + postbuf.toString()); + TRACE("stream strmbuf: " + strmbuf.toString()); assert(strmbuf.size() == 18); assert(memcmp(strmbuf.data(), "Stream Hello World", strmbuf.size()) == 0); assert(prebuf.size() == 5); @@ -190,9 +190,9 @@ void testBytesMain() { const RNS::Bytes post(" World"); assert(post.size() == 6); RNS::Bytes strmbuf = pre << post; - RNS::extreme("stream pre: " + prebuf.toString()); - RNS::extreme("stream post: " + postbuf.toString()); - RNS::extreme("stream strmbuf: " + strmbuf.toString()); + TRACE("stream pre: " + prebuf.toString()); + TRACE("stream post: " + postbuf.toString()); + TRACE("stream strmbuf: " + strmbuf.toString()); assert(strmbuf.size() == 11); assert(memcmp(strmbuf.data(), "Hello World", strmbuf.size()) == 0); assert(pre.size() == 11); @@ -234,14 +234,14 @@ void testBytesMain() { } // function default argument - RNS::extreme("TestBytes: function default argument"); + TRACE("TestBytes: function default argument"); testBytesDefault(); // function reference return - RNS::extreme("TestBytes: function reference return"); + TRACE("TestBytes: function reference return"); { RNS::Bytes test = testBytesReference(); - RNS::extreme("returned"); + TRACE("returned"); assert(test); assert(test.size() == 4); assert(memcmp(test.data(), "Test", test.size()) == 0); @@ -267,9 +267,9 @@ void testCowBytes() { assert(memcmp(bytes3.data(), "1", bytes3.size()) == 0); assert(bytes3.data() == bytes2.data()); - RNS::extreme("pre bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString()); - RNS::extreme("pre bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString()); - RNS::extreme("pre bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString()); + TRACE("pre bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString()); + TRACE("pre bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString()); + TRACE("pre bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString()); //bytes1.append("mississippi"); //assert(bytes1.size() == 12); @@ -286,9 +286,9 @@ void testCowBytes() { assert(memcmp(bytes3.data(), "mississippi", bytes3.size()) == 0); assert(bytes3.data() != bytes2.data()); - RNS::extreme("post bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString()); - RNS::extreme("post bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString()); - RNS::extreme("post bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString()); + TRACE("post bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString()); + TRACE("post bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString()); + TRACE("post bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString()); } void testBytesConversion() { @@ -296,14 +296,14 @@ void testBytesConversion() { { RNS::Bytes bytes("Hello World"); std::string hex = bytes.toHex(true); - RNS::extreme("text: \"" + bytes.toString() + "\" upper hex: \"" + hex + "\""); + TRACE("text: \"" + bytes.toString() + "\" upper hex: \"" + hex + "\""); assert(hex.length() == 22); assert(hex.compare("48656C6C6F20576F726C64") == 0); } { RNS::Bytes bytes("Hello World"); std::string hex = bytes.toHex(false); - RNS::extreme("text: \"" + bytes.toString() + "\" lower hex: \"" + hex + "\""); + TRACE("text: \"" + bytes.toString() + "\" lower hex: \"" + hex + "\""); assert(hex.length() == 22); assert(hex.compare("48656c6c6f20576f726c64") == 0); } @@ -312,7 +312,7 @@ void testBytesConversion() { RNS::Bytes bytes; bytes.assignHex(hex.c_str()); std::string text = bytes.toString(); - RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); assert(text.length() == 11); assert(text.compare("Hello World") == 0); } @@ -321,19 +321,19 @@ void testBytesConversion() { RNS::Bytes bytes; bytes.assignHex(hex.c_str()); std::string text = bytes.toString(); - RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); assert(text.length() == 11); assert(text.compare("Hello World") == 0); bytes.assignHex(hex.c_str()); text = bytes.toString(); - RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); assert(text.length() == 11); assert(text.compare("Hello World") == 0); bytes.appendHex(hex.c_str()); text = bytes.toString(); - RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); assert(text.length() == 22); assert(text.compare("Hello WorldHello World") == 0); } @@ -341,7 +341,7 @@ void testBytesConversion() { } void testBytesResize() { - RNS::extreme("Testing downsize of Bytes with initial capacity"); + TRACE("Testing downsize of Bytes with initial capacity"); RNS::Bytes bytes(1024); assert(!bytes); diff --git a/examples/test/TestCollections.cpp b/examples/test/TestCollections.cpp index 4a241ef..06766a1 100644 --- a/examples/test/TestCollections.cpp +++ b/examples/test/TestCollections.cpp @@ -29,14 +29,14 @@ void testBytesMap() assert(preit != map.end()); assert((*preit).second.compare("hello") == 0); if (preit != map.end()) { - RNS::extreme(std::string("found prebuf: ") + (*preit).second); + TRACE(std::string("found prebuf: ") + (*preit).second); } auto postit = map.find(postbuf); assert(postit != map.end()); assert((*postit).second.compare("world") == 0); if (postit != map.end()) { - RNS::extreme(std::string("found postbuf: ") + (*postit).second); + TRACE(std::string("found postbuf: ") + (*postit).second); } const uint8_t newstr[] = "World"; @@ -47,7 +47,7 @@ void testBytesMap() assert(newit != map.end()); assert((*newit).second.compare("world") == 0); if (newit != map.end()) { - RNS::extreme(std::string("found newbuf: ") + (*newit).second); + TRACE(std::string("found newbuf: ") + (*newit).second); } std::string str = map["World"]; @@ -59,9 +59,9 @@ class Entry { public: // CBA for some reason default constructor is required for map index reference/asign to work // ("error: no matching constructor for initialization of 'Entry'" results otherwise) - Entry() { RNS::extreme("Entry: default constructor"); } - Entry(const Entry& entry) : _hash(entry._hash) { RNS::extreme("Entry: copy constructor"); } - Entry(const char* hash) : _hash(hash) { RNS::extreme("Entry: hash constructor"); } + Entry() { TRACE("Entry: default constructor"); } + Entry(const Entry& entry) : _hash(entry._hash) { TRACE("Entry: copy constructor"); } + Entry(const char* hash) : _hash(hash) { TRACE("Entry: hash constructor"); } RNS::Bytes _hash; }; @@ -86,7 +86,7 @@ void testOldMap() { } } for (auto& pair : entries) { - RNS::extreme("entries: " + pair.second._hash.toString()); + TRACE("entries: " + pair.second._hash.toString()); } assert(entries.size() == 2); assert(other_entries.size() == 2); @@ -114,7 +114,7 @@ void testNewMap() { } } for (auto& [hash, entry] : entries) { - RNS::extreme("entries: " + entry._hash.toString()); + TRACE("entries: " + entry._hash.toString()); } assert(entries.size() == 2); assert(other_entries.size() == 2); diff --git a/examples/test/TestCrypto.cpp b/examples/test/TestCrypto.cpp index aa02cc0..6d6eecb 100644 --- a/examples/test/TestCrypto.cpp +++ b/examples/test/TestCrypto.cpp @@ -43,10 +43,10 @@ void testHMAC() { RNS::Bytes key(keystr); RNS::Bytes data(datastr); RNS::Bytes hash(hasharr, sizeof(hasharr)); - RNS::extreme("expected hash: " + hash.toHex()); + TRACE("expected hash: " + hash.toHex()); RNS::Cryptography::HMAC hmac(key, data); RNS::Bytes result = hmac.digest(); - RNS::extreme("result hash: " + result.toHex()); + TRACE("result hash: " + result.toHex()); assert(memcmp(hash.data(), result.data(), result.size()) == 0); } } diff --git a/examples/test/TestFilesystem.cpp b/examples/test/TestFilesystem.cpp index e868fa8..ef76813 100644 --- a/examples/test/TestFilesystem.cpp +++ b/examples/test/TestFilesystem.cpp @@ -46,7 +46,7 @@ void listDir(char * dir){ #endif TestFilesystem::TestFilesystem() : Filesystem() { - extreme("TestFilesystem initializing..."); + TRACE("TestFilesystem initializing..."); #ifdef ARDUINO #ifdef ESP32 @@ -73,7 +73,7 @@ TestFilesystem::TestFilesystem() : Filesystem() { else { OS::remove_file("/test"); } - debug("SPIFFS filesystem is ready"); + DEBUG("SPIFFS filesystem is ready"); #elif NRF52 // Initialize Internal File System info("InternalFS mounting filesystem"); @@ -103,7 +103,7 @@ TestFilesystem::TestFilesystem() : Filesystem() { FILE* file = fopen(file_path, "r"); if (file != nullptr) { #endif - //extreme("file_exists: file exists, closing file"); + //TRACE("file_exists: file exists, closing file"); #ifdef ARDUINO #ifdef ESP32 file.close(); @@ -147,12 +147,12 @@ TestFilesystem::TestFilesystem() : Filesystem() { //size_t read = fread(data.writable(size), size, 1, file); size_t read = fread(data.writable(size), 1, size, file); #endif - extreme("read_file: read " + std::to_string(read) + " Bytes from file " + std::string(file_path)); + TRACE("read_file: read " + std::to_string(read) + " Bytes from file " + std::string(file_path)); if (read != size) { error("read_file: failed to read file " + std::string(file_path)); data.clear(); } - //extreme("read_file: closing input file"); + //TRACE("read_file: closing input file"); #ifdef ARDUINO #ifdef ESP32 file.close(); @@ -189,11 +189,11 @@ TestFilesystem::TestFilesystem() : Filesystem() { //size_t wrote = fwrite(data.data(), data.size(), 1, file); size_t wrote = fwrite(data.data(), 1, data.size(), file); #endif - extreme("write_file: wrote " + std::to_string(wrote) + " Bytes to file " + std::string(file_path)); + TRACE("write_file: wrote " + std::to_string(wrote) + " Bytes to file " + std::string(file_path)); if (wrote < data.size()) { warning("write_file: not all data was written to file " + std::string(file_path)); } - //extreme("write_file: closing output file"); + //TRACE("write_file: closing output file"); #ifdef ARDUINO #ifdef ESP32 file.close(); diff --git a/examples/test/TestOS.cpp b/examples/test/TestOS.cpp index 5dfb7d7..27fe808 100644 --- a/examples/test/TestOS.cpp +++ b/examples/test/TestOS.cpp @@ -22,12 +22,12 @@ void testTime() double diff_time; diff_time = (double)(end_ltime - start_ltime) / 1000.0; - RNS::extreme(std::string("ltime diff: ") + std::to_string(diff_time)); + TRACE(std::string("ltime diff: ") + std::to_string(diff_time)); assert(diff_time > sleep_time * 0.99); assert(diff_time < sleep_time * 1.01); diff_time = end_dtime - start_dtime; - RNS::extreme(std::string("dtime diff: ") + std::to_string(diff_time)); + TRACE(std::string("dtime diff: ") + std::to_string(diff_time)); assert(diff_time > sleep_time * 0.99); assert(diff_time < sleep_time * 1.01); diff --git a/examples/test/TestPersistence.cpp b/examples/test/TestPersistence.cpp index 7baaee0..ca50e1a 100644 --- a/examples/test/TestPersistence.cpp +++ b/examples/test/TestPersistence.cpp @@ -28,11 +28,11 @@ public: private: virtual void on_incoming(const RNS::Bytes& data) { - RNS::debug(toString() + ".on_incoming: data: " + data.toHex()); + DEBUG(toString() + ".on_incoming: data: " + data.toHex()); Interface::on_incoming(data); } virtual void on_outgoing(const RNS::Bytes& data) { - RNS::debug(toString() + ".on_outgoing: data: " + data.toHex()); + DEBUG(toString() + ".on_outgoing: data: " + data.toHex()); Interface::on_outgoing(data); } @@ -82,10 +82,10 @@ const char test_file_data[] = "test data"; void testWrite() { RNS::Bytes data(test_file_data); if (RNS::Utilities::OS::write_file(test_file_path, data) == data.size()) { - RNS::extreme("wrote: " + std::to_string(data.size()) + " bytes"); + TRACE("wrote: " + std::to_string(data.size()) + " bytes"); } else { - RNS::extreme("write failed"); + TRACE("write failed"); assert(false); } } @@ -93,14 +93,14 @@ void testWrite() { void testRead() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_file_path, data) > 0) { - RNS::extreme("read: " + std::to_string(data.size()) + " bytes"); - RNS::extreme("data: " + data.toString()); + TRACE("read: " + std::to_string(data.size()) + " bytes"); + TRACE("data: " + data.toString()); assert(data.size() == strlen(test_file_data)); assert(memcmp(data.data(), test_file_data, strlen(test_file_data)) == 0); //assert(RNS::Utilities::OS::remove_file(test_file_path)); } else { - RNS::extreme("read failed"); + TRACE("read failed"); assert(false); } } @@ -127,18 +127,18 @@ void testSerializeObject() { if (length < size) { data.resize(length); } - RNS::extreme("serialized " + std::to_string(length) + " bytes"); + TRACE("serialized " + std::to_string(length) + " bytes"); if (length > 0) { if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) { - RNS::extreme("wrote: " + std::to_string(data.size()) + " bytes"); + TRACE("wrote: " + std::to_string(data.size()) + " bytes"); } else { - RNS::extreme("write failed"); + TRACE("write failed"); assert(false); } } else { - RNS::extreme("failed to serialize"); + TRACE("failed to serialize"); assert(false); } @@ -152,24 +152,24 @@ void testDeserializeObject() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) { if (data) { - RNS::extreme("read: " + std::to_string(data.size()) + " bytes"); - //RNS::extreme("data: " + data.toString()); + TRACE("read: " + std::to_string(data.size()) + " bytes"); + //TRACE("data: " + data.toString()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { JsonObject root = doc.as(); for (JsonPair kv : root) { - RNS::extreme("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); + TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); } } else { - RNS::extreme("failed to deserialize"); + TRACE("failed to deserialize"); assert(false); } //assert(RNS::Utilities::OS::remove_file(test_object_path)); } else { - RNS::extreme("read failed"); + TRACE("read failed"); assert(false); } @@ -179,7 +179,7 @@ void testSerializeObject() { std::vector vec({"one", "two"}); TestObject test("test", vec); - RNS::extreme("serializeObject: test: " + test.toString()); + TRACE("serializeObject: test: " + test.toString()); StaticJsonDocument<1024> doc; doc = test; @@ -191,18 +191,18 @@ void testSerializeObject() { if (length < size) { data.resize(length); } - RNS::extreme("serialized " + std::to_string(length) + " bytes"); + TRACE("serialized " + std::to_string(length) + " bytes"); if (length > 0) { if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) { - RNS::extreme("wrote: " + std::to_string(data.size()) + " bytes"); + TRACE("wrote: " + std::to_string(data.size()) + " bytes"); } else { - RNS::extreme("write failed"); + TRACE("write failed"); assert(false); } } else { - RNS::extreme("failed to serialize"); + TRACE("failed to serialize"); assert(false); } @@ -215,26 +215,26 @@ void testDeserializeObject() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) { - RNS::extreme("read: " + std::to_string(data.size()) + " bytes"); - //RNS::extreme("data: " + data.toString()); + TRACE("read: " + std::to_string(data.size()) + " bytes"); + //TRACE("data: " + data.toString()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // RNS::extreme("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); + // TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); //} TestObject test = doc.as(); - RNS::extreme("testDeserializeObject: test: " + test.toString()); + TRACE("testDeserializeObject: test: " + test.toString()); } else { - RNS::extreme("failed to deserialize"); + TRACE("failed to deserialize"); assert(false); } //assert(RNS::Utilities::OS::remove_file(test_object_path)); } else { - RNS::extreme("read failed"); + TRACE("read failed"); assert(false); } @@ -289,18 +289,18 @@ void testSerializeVector() { if (length < size) { data.resize(length); } - RNS::extreme("testSerializeVector: serialized " + std::to_string(length) + " bytes"); + TRACE("testSerializeVector: serialized " + std::to_string(length) + " bytes"); if (length > 0) { if (RNS::Utilities::OS::write_file(test_vector_path, data) == data.size()) { - RNS::extreme("testSerializeVector: wrote: " + std::to_string(data.size()) + " bytes"); + TRACE("testSerializeVector: wrote: " + std::to_string(data.size()) + " bytes"); } else { - RNS::extreme("testSerializeVector: write failed"); + TRACE("testSerializeVector: write failed"); assert(false); } } else { - RNS::extreme("testSerializeVector: failed to serialize"); + TRACE("testSerializeVector: failed to serialize"); assert(false); } @@ -319,31 +319,31 @@ void testDeserializeVector() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_vector_path, data) > 0) { - RNS::extreme("testDeserializeVector: read: " + std::to_string(data.size()) + " bytes"); - //RNS::extreme("testDeserializeVector: data: " + data.toString()); + TRACE("testDeserializeVector: read: " + std::to_string(data.size()) + " bytes"); + //TRACE("testDeserializeVector: data: " + data.toString()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { - RNS::extreme("testDeserializeVector: successfully deserialized"); + TRACE("testDeserializeVector: successfully deserialized"); std::vector vector = doc.as>(); for (auto& test : vector) { - RNS::extreme("testDeserializeVector: entry: " + test.toString()); + TRACE("testDeserializeVector: entry: " + test.toString()); } //JsonArray arr = doc.as(); //for (JsonVariant elem : arr) { - // RNS::extreme("testDeserializeVector: entry: " + elem.as().toString()); + // TRACE("testDeserializeVector: entry: " + elem.as().toString()); //} } else { - RNS::extreme("testDeserializeVector: failed to deserialize"); + TRACE("testDeserializeVector: failed to deserialize"); assert(false); } //assert(RNS::Utilities::OS::remove_file(test_vector_path)); } else { - RNS::extreme("testDeserializeVector: read failed"); + TRACE("testDeserializeVector: read failed"); assert(false); } @@ -386,18 +386,18 @@ void testSerializeSet() { if (length < size) { data.resize(length); } - RNS::extreme("testSerializeSet: serialized " + std::to_string(length) + " bytes"); + TRACE("testSerializeSet: serialized " + std::to_string(length) + " bytes"); if (length > 0) { if (RNS::Utilities::OS::write_file(test_set_path, data) == data.size()) { - RNS::extreme("testSerializeSet: wrote: " + std::to_string(data.size()) + " bytes"); + TRACE("testSerializeSet: wrote: " + std::to_string(data.size()) + " bytes"); } else { - RNS::extreme("testSerializeSet: write failed"); + TRACE("testSerializeSet: write failed"); assert(false); } } else { - RNS::extreme("testSerializeSet: failed to serialize"); + TRACE("testSerializeSet: failed to serialize"); assert(false); } @@ -416,31 +416,31 @@ void testDeserializeSet() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_set_path, data) > 0) { - RNS::extreme("testDeserializeSet: read: " + std::to_string(data.size()) + " bytes"); - //RNS::extreme("testDeserializeSet: data: " + data.toString()); + TRACE("testDeserializeSet: read: " + std::to_string(data.size()) + " bytes"); + //TRACE("testDeserializeSet: data: " + data.toString()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { - RNS::extreme("testDeserializeSet: successfully deserialized"); + TRACE("testDeserializeSet: successfully deserialized"); std::set set = doc.as>(); for (auto& test : set) { - RNS::extreme("testDeserializeSet: entry: " + test.toString()); + TRACE("testDeserializeSet: entry: " + test.toString()); } //JsonArray arr = doc.as(); //for (JsonVariant elem : arr) { - // RNS::extreme("testDeserializeSet: entry: " + elem.as().toString()); + // TRACE("testDeserializeSet: entry: " + elem.as().toString()); //} } else { - RNS::extreme("testDeserializeSet: failed to deserialize"); + TRACE("testDeserializeSet: failed to deserialize"); assert(false); } //assert(RNS::Utilities::OS::remove_file(test_set_path)); } else { - RNS::extreme("testDeserializeSet: read failed"); + TRACE("testDeserializeSet: read failed"); assert(false); } @@ -475,18 +475,18 @@ void testSerializeMap() { if (length < size) { data.resize(length); } - RNS::extreme("testSerializeMap: serialized " + std::to_string(length) + " bytes"); + TRACE("testSerializeMap: serialized " + std::to_string(length) + " bytes"); if (length > 0) { if (RNS::Utilities::OS::write_file(test_map_path, data) == data.size()) { - RNS::extreme("testSerializeMap: wrote: " + std::to_string(data.size()) + " bytes"); + TRACE("testSerializeMap: wrote: " + std::to_string(data.size()) + " bytes"); } else { - RNS::extreme("testSerializeMap: write failed"); + TRACE("testSerializeMap: write failed"); assert(false); } } else { - RNS::extreme("testSerializeMap: failed to serialize"); + TRACE("testSerializeMap: failed to serialize"); assert(false); } @@ -505,31 +505,31 @@ void testDeserializeMap() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_map_path, data) > 0) { - RNS::extreme("testDeserializeMap: read: " + std::to_string(data.size()) + " bytes"); - //RNS::extreme("testDeserializeMap: data: " + data.toString()); + TRACE("testDeserializeMap: read: " + std::to_string(data.size()) + " bytes"); + //TRACE("testDeserializeMap: data: " + data.toString()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { - RNS::extreme("testDeserializeMap: successfully deserialized"); + TRACE("testDeserializeMap: successfully deserialized"); std::map map(doc.as>()); for (auto& [str, test] : map) { - RNS::extreme("testDeserializeMap: entry: " + str + " = " + test.toString()); + TRACE("testDeserializeMap: entry: " + str + " = " + test.toString()); } //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // RNS::extreme("testDeserializeMap: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as().toString()); + // TRACE("testDeserializeMap: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as().toString()); //} } else { - RNS::extreme("testDeserializeMap: failed to deserialize"); + TRACE("testDeserializeMap: failed to deserialize"); assert(false); } //assert(RNS::Utilities::OS::remove_file(test_map_path)); } else { - RNS::extreme("testDeserializeMap: read failed"); + TRACE("testDeserializeMap: read failed"); assert(false); } @@ -586,13 +586,13 @@ void testSerializeDestinationTable() { } for (auto& [hash, test] : map) { - RNS::extreme("testSerializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString()); + TRACE("testSerializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString()); } //StaticJsonDocument<1024> doc; //doc = map; - RNS::extreme("testSerializeDestinationTable: JSON_OBJECT_SIZE " + std::to_string(JSON_OBJECT_SIZE(1)) + " bytes"); - RNS::extreme("testSerializeDestinationTable: JSON_ARRAY_SIZE " + std::to_string(JSON_ARRAY_SIZE(1)) + " bytes"); + TRACE("testSerializeDestinationTable: JSON_OBJECT_SIZE " + std::to_string(JSON_OBJECT_SIZE(1)) + " bytes"); + TRACE("testSerializeDestinationTable: JSON_ARRAY_SIZE " + std::to_string(JSON_ARRAY_SIZE(1)) + " bytes"); int calcsize = 0; for (auto& [destination_hash, destination_entry] : map) { // entry @@ -604,39 +604,39 @@ void testSerializeDestinationTable() { // blobs calcsize += JSON_ARRAY_SIZE(destination_entry._random_blobs.size()); } - RNS::extreme("testSerializeDestinationTable: calcsize " + std::to_string(calcsize) + " bytes"); + TRACE("testSerializeDestinationTable: calcsize " + std::to_string(calcsize) + " bytes"); const int BUFFER_SIZE = (JSON_OBJECT_SIZE(9) + JSON_ARRAY_SIZE(2)) * map.size() + JSON_ARRAY_SIZE(map.size()); - RNS::extreme("testSerializeDestinationTable: BUFFER_SIZE " + std::to_string(BUFFER_SIZE) + " bytes"); + TRACE("testSerializeDestinationTable: BUFFER_SIZE " + std::to_string(BUFFER_SIZE) + " bytes"); //DynamicJsonDocument doc(32768); //DynamicJsonDocument doc(BUFFER_SIZE); DynamicJsonDocument doc(calcsize); doc.set(map); - RNS::extreme("testSerializeDestinationTable: doc size " + std::to_string(doc.size())); - RNS::extreme("testSerializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage())); + TRACE("testSerializeDestinationTable: doc size " + std::to_string(doc.size())); + TRACE("testSerializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage())); RNS::Bytes data; // /size_t size = 1024; //size_t size = calcsize; size_t size = doc.memoryUsage(); - RNS::extreme("testSerializeDestinationTable: buffer size " + std::to_string(size) + " bytes"); + TRACE("testSerializeDestinationTable: buffer size " + std::to_string(size) + " bytes"); size_t length = serializeJson(doc, data.writable(size), size); //size_t length = serializeMsgPack(doc, data.writable(size), size); if (length < size) { data.resize(length); } - RNS::extreme("testSerializeDestinationTable: serialized " + std::to_string(length) + " bytes"); + TRACE("testSerializeDestinationTable: serialized " + std::to_string(length) + " bytes"); if (length > 0) { - RNS::extreme("json: " + data.toString()); + TRACE("json: " + data.toString()); if (RNS::Utilities::OS::write_file(test_destination_table_path, data) == data.size()) { - RNS::extreme("testSerializeDestinationTable: wrote: " + std::to_string(data.size()) + " bytes"); + TRACE("testSerializeDestinationTable: wrote: " + std::to_string(data.size()) + " bytes"); } else { - RNS::extreme("testSerializeDestinationTable: write failed"); + TRACE("testSerializeDestinationTable: write failed"); assert(false); } } else { - RNS::extreme("testSerializeDestinationTable: failed to serialize"); + TRACE("testSerializeDestinationTable: failed to serialize"); assert(false); } @@ -651,34 +651,34 @@ void testDeserializeDestinationTable() { int calcsize = data.size() * 1.5; DynamicJsonDocument doc(calcsize); - RNS::extreme("testDeserializeDestinationTable: read: " + std::to_string(data.size()) + " bytes"); - //RNS::extreme("testDeserializeVector: data: " + data.toString()); + TRACE("testDeserializeDestinationTable: read: " + std::to_string(data.size()) + " bytes"); + //TRACE("testDeserializeVector: data: " + data.toString()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); - RNS::extreme("testDeserializeDestinationTable: doc size " + std::to_string(doc.size())); - RNS::extreme("testDeserializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage())); + TRACE("testDeserializeDestinationTable: doc size " + std::to_string(doc.size())); + TRACE("testDeserializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage())); if (!error) { - RNS::extreme("testDeserializeDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes"); - RNS::extreme("json: " + data.toString()); + TRACE("testDeserializeDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes"); + TRACE("json: " + data.toString()); static std::map map(doc.as>()); for (auto& [hash, test] : map) { - RNS::extreme("testDeserializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString()); + TRACE("testDeserializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString()); } //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // RNS::extreme("testDeserializeDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as().toString()); + // TRACE("testDeserializeDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as().toString()); //} } else { - RNS::extreme("testDeserializeDestinationTable: failed to deserialize"); + TRACE("testDeserializeDestinationTable: failed to deserialize"); assert(false); } //assert(RNS::Utilities::OS::remove_file(test_destination_table_path)); } else { - RNS::extreme("testDeserializeDestinationTable: read failed"); + TRACE("testDeserializeDestinationTable: read failed"); assert(false); } diff --git a/examples/test/TestReference.cpp b/examples/test/TestReference.cpp index a3f03c5..7369a5d 100644 --- a/examples/test/TestReference.cpp +++ b/examples/test/TestReference.cpp @@ -28,7 +28,7 @@ void testReference() { interfaces.insert(testinterface); for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - RNS::extreme("Found interface: " + interface.toString()); + TRACE("Found interface: " + interface.toString()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -41,7 +41,7 @@ void testReference() { std::set, std::less> interfaces; interfaces.insert(testinterface); for (auto& interface : interfaces) { - RNS::extreme("Found interface: " + interface.toString()); + TRACE("Found interface: " + interface.toString()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -55,7 +55,7 @@ void testReference() { interfaces.push_back(testinterface); for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - RNS::extreme("Found interface: " + interface.toString()); + TRACE("Found interface: " + interface.toString()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -69,7 +69,7 @@ void testReference() { interfaces.push_back(testinterface); //for (auto& interface : interfaces) { for (RNS::Interface& interface : interfaces) { - RNS::extreme("Found interface: " + interface.toString()); + TRACE("Found interface: " + interface.toString()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -83,14 +83,14 @@ void testReference() { interfaces.push_back(testinterface); for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - RNS::extreme("1 Found interface: " + interface.toString()); + TRACE("1 Found interface: " + interface.toString()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } } for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - RNS::extreme("2 Found interface: " + interface.toString()); + TRACE("2 Found interface: " + interface.toString()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -103,13 +103,13 @@ void testReference() { destinations.insert({destination.hash(), destination}); //for (RNS::Destination& destination : destinations) { for (auto& [hash, destination] : destinations) { - RNS::extreme("Iterated destination: " + destination.toString()); + TRACE("Iterated destination: " + destination.toString()); } RNS::Bytes hash = destination.hash(); auto iter = destinations.find(hash); if (iter != destinations.end()) { RNS::Destination& destination = (*iter).second; - RNS::extreme("Found destination: " + destination.toString()); + TRACE("Found destination: " + destination.toString()); } return; } diff --git a/examples/test/main.cpp b/examples/test/main.cpp index 82b5ed8..c87705c 100644 --- a/examples/test/main.cpp +++ b/examples/test/main.cpp @@ -41,7 +41,7 @@ void setup() { try { - RNS::extreme("Running tests..."); + TRACE("Running tests..."); RNS::LogLevel loglevel = RNS::loglevel(); //RNS::loglevel(RNS::LOG_WARNING); RNS::loglevel(RNS::LOG_EXTREME); @@ -56,7 +56,7 @@ void setup() { testBytes(); RNS::loglevel(loglevel); - RNS::extreme("Finished running tests"); + TRACE("Finished running tests"); //return; } catch (std::exception& e) { diff --git a/examples/udp/UDPInterface.cpp b/examples/udp/UDPInterface.cpp index a8a4f0a..62a0f11 100644 --- a/examples/udp/UDPInterface.cpp +++ b/examples/udp/UDPInterface.cpp @@ -57,12 +57,12 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p } _local_port = port; _remote_port = port; - extreme("UDPInterface: wifi ssid: " + _wifi_ssid); - extreme("UDPInterface: wifi password: " + _wifi_password); - extreme("UDPInterface: local host: " + _local_host); - extreme("UDPInterface: local port: " + std::to_string(_local_port)); - extreme("UDPInterface: remote host: " + _remote_host); - extreme("UDPInterface: remote port: " + std::to_string(_remote_port)); + TRACE("UDPInterface: wifi ssid: " + _wifi_ssid); + TRACE("UDPInterface: wifi password: " + _wifi_password); + TRACE("UDPInterface: local host: " + _local_host); + TRACE("UDPInterface: local port: " + std::to_string(_local_port)); + TRACE("UDPInterface: remote host: " + _remote_host); + TRACE("UDPInterface: remote port: " + std::to_string(_remote_port)); #ifdef ARDUINO // Connect to the WiFi network @@ -149,7 +149,7 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p } // open udp socket - extreme("Opening UDP socket"); + TRACE("Opening UDP socket"); _socket = socket( PF_INET, SOCK_DGRAM, 0 ); if (_socket < 0) { error("Unable to create socket with error " + std::to_string(errno)); @@ -219,12 +219,12 @@ void UDPInterface::loop() { } /*virtual*/ void UDPInterface::on_incoming(const Bytes& data) { - debug(toString() + ".on_incoming: data: " + data.toHex()); + DEBUG(toString() + ".on_incoming: data: " + data.toHex()); Interface::on_incoming(data); } /*virtual*/ void UDPInterface::on_outgoing(const Bytes& data) { - debug(toString() + ".on_outgoing: data: " + data.toHex()); + DEBUG(toString() + ".on_outgoing: data: " + data.toHex()); try { if (online()) { // Send packet @@ -233,13 +233,13 @@ void UDPInterface::loop() { udp.write(data.data(), data.size()); udp.endPacket(); #else - extreme("Sending UDP packet to " + std::string(_remote_host) + ":" + std::to_string(_remote_port)); + TRACE("Sending UDP packet to " + std::string(_remote_host) + ":" + std::to_string(_remote_port)); sockaddr_in sock_addr; sock_addr.sin_family = AF_INET; sock_addr.sin_addr.s_addr = _remote_address; sock_addr.sin_port = htons(_remote_port); int sent = sendto(_socket, data.data(), data.size(), 0, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); - extreme("Sent " + std::to_string(sent) + " bytes to " + std::string(_remote_host) + ":" + std::to_string(_remote_port)); + TRACE("Sent " + std::to_string(sent) + " bytes to " + std::string(_remote_host) + ":" + std::to_string(_remote_port)); #endif } diff --git a/examples/udp/main.cpp b/examples/udp/main.cpp index 612490a..820c0a5 100644 --- a/examples/udp/main.cpp +++ b/examples/udp/main.cpp @@ -72,7 +72,7 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); RNS::info("onPacket: data: " + data.toHex()); RNS::info("onPacket: text: \"" + data.toString() + "\""); - //RNS::extreme("onPacket: " + packet.debugString()); + //TRACE("onPacket: " + packet.debugString()); RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -81,7 +81,7 @@ void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); RNS::info("onPingPacket: data: " + data.toHex()); RNS::info("onPingPacket: text: \"" + data.toString() + "\""); - //RNS::extreme("onPingPacket: " + packet.debugString()); + //TRACE("onPingPacket: " + packet.debugString()); RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -192,14 +192,14 @@ void reticulum_setup() { RNS::head("Sending send packet...", RNS::LOG_EXTREME); send_packet.pack(); #ifndef NDEBUG - RNS::extreme("Test send_packet: " + send_packet.debugString()); + TRACE("Test send_packet: " + send_packet.debugString()); #endif RNS::head("Creating recv packet...", RNS::LOG_EXTREME); RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw()); recv_packet.unpack(); #ifndef NDEBUG - RNS::extreme("Test recv_packet: " + recv_packet.debugString()); + TRACE("Test recv_packet: " + recv_packet.debugString()); #endif RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME); @@ -258,7 +258,7 @@ void setup() { RNS::error("SPIFFS filesystem mount failed"); } else { - RNS::debug("SPIFFS filesystem is ready"); + DEBUG("SPIFFS filesystem is ready"); } #endif diff --git a/src/Bytes.cpp b/src/Bytes.cpp index 5889adb..d450062 100644 --- a/src/Bytes.cpp +++ b/src/Bytes.cpp @@ -6,7 +6,7 @@ using namespace RNS; // - If size is specified (>0) then create shared data with initial size // - If size is not specified (<=0) then create empty shared data void Bytes::newData(size_t size /*= 0*/) { - //mem("Bytes is creating its own data"); + MEM("Bytes is creating its own data"); if (size > 0) { // CBA Note that this method of construction creates vector with specified and initializes all eleemtnets with default values Data* data = new Data(size); @@ -39,7 +39,7 @@ void Bytes::exclusiveData(bool copy /*= true*/, size_t size /*= 0*/) { else if (!_exclusive) { Data *data; if (copy && !_data->empty()) { - //extreme("Bytes is creating a writable copy of its shared data"); + //TRACE("Bytes is creating a writable copy of its shared data"); data = new Data(*_data.get()); if (data == nullptr) { error("Bytes failed to duplicate data buffer"); @@ -52,7 +52,7 @@ void Bytes::exclusiveData(bool copy /*= true*/, size_t size /*= 0*/) { _exclusive = true; } else { - //extreme("Bytes is creating its own data because shared is empty"); + //TRACE("Bytes is creating its own data because shared is empty"); //data = new Data(); //if (data == nullptr) { // error("Bytes failed to allocate empty data buffer"); diff --git a/src/Bytes.h b/src/Bytes.h index 1a6e5bd..dc86fbd 100644 --- a/src/Bytes.h +++ b/src/Bytes.h @@ -31,35 +31,35 @@ namespace RNS { public: Bytes() { - //mem("Bytes object created from default, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM("Bytes object created from default, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } Bytes(const NoneConstructor none) { - //mem("Bytes object created from NONE, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM("Bytes object created from NONE, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } Bytes(const Bytes& bytes) { - //mem("Bytes is using shared data"); + MEM("Bytes is using shared data"); assign(bytes); - //mem("Bytes object copy created from bytes \"" + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM("Bytes object copy created from bytes \"" + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } Bytes(const uint8_t* chunk, size_t size) { assign(chunk, size); - //mem(std::string("Bytes object created from chunk \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM(std::string("Bytes object created from chunk \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } Bytes(const char* string) { assign(string); - //mem(std::string("Bytes object created from string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM(std::string("Bytes object created from string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } Bytes(const std::string& string) { assign(string); - //mem(std::string("Bytes object created from std::string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM(std::string("Bytes object created from std::string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } Bytes(size_t capacity) { newData(); reserve(capacity); - //mem(std::string("Bytes object created with capacity ") + std::to_string(capacity) + ", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM(std::string("Bytes object created with capacity ") + std::to_string(capacity) + ", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } virtual ~Bytes() { - //mem(std::string("Bytes object destroyed \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); + MEM(std::string("Bytes object destroyed \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get())); } inline const Bytes& operator = (const Bytes& bytes) { @@ -94,7 +94,7 @@ namespace RNS { private: inline SharedData shareData() const { - //mem("Bytes is sharing its own data"); + MEM("Bytes is sharing its own data"); _exclusive = false; return _data; } diff --git a/src/Cryptography/Fernet.cpp b/src/Cryptography/Fernet.cpp index 36e6ff5..0ee5c0f 100644 --- a/src/Cryptography/Fernet.cpp +++ b/src/Cryptography/Fernet.cpp @@ -26,11 +26,11 @@ Fernet::Fernet(const Bytes& key) { //self._encryption_key = key[16:] _encryption_key = key.mid(16); - mem("Fernet object created"); + MEM("Fernet object created"); } Fernet::~Fernet() { - mem("Fernet object destroyed"); + MEM("Fernet object destroyed"); } bool Fernet::verify_hmac(const Bytes& token) { @@ -41,44 +41,44 @@ bool Fernet::verify_hmac(const Bytes& token) { //received_hmac = token[-32:] Bytes received_hmac = token.right(32); - debug("Fernet::verify_hmac: received_hmac: " + received_hmac.toHex()); + DEBUG("Fernet::verify_hmac: received_hmac: " + received_hmac.toHex()); //expected_hmac = HMAC.new(self._signing_key, token[:-32]).digest() Bytes expected_hmac = HMAC::generate(_signing_key, token.left(token.size()-32))->digest(); - debug("Fernet::verify_hmac: expected_hmac: " + expected_hmac.toHex()); + DEBUG("Fernet::verify_hmac: expected_hmac: " + expected_hmac.toHex()); return (received_hmac == expected_hmac); } const Bytes Fernet::encrypt(const Bytes& data) { - debug("Fernet::encrypt: plaintext length: " + std::to_string(data.size())); + DEBUG("Fernet::encrypt: plaintext length: " + std::to_string(data.size())); Bytes iv = random(16); //double current_time = OS::time(); - extreme("Fernet::encrypt: iv: " + iv.toHex()); + TRACE("Fernet::encrypt: iv: " + iv.toHex()); - extreme("Fernet::encrypt: plaintext: " + data.toHex()); + TRACE("Fernet::encrypt: plaintext: " + data.toHex()); Bytes ciphertext = AES_128_CBC::encrypt( PKCS7::pad(data), _encryption_key, iv ); - debug("Fernet::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size())); - extreme("Fernet::encrypt: ciphertext: " + ciphertext.toHex()); + DEBUG("Fernet::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size())); + TRACE("Fernet::encrypt: ciphertext: " + ciphertext.toHex()); Bytes signed_parts = iv + ciphertext; //return signed_parts + HMAC::generate(_signing_key, signed_parts)->digest(); Bytes sig(HMAC::generate(_signing_key, signed_parts)->digest()); - extreme("Fernet::encrypt: sig: " + sig.toHex()); + TRACE("Fernet::encrypt: sig: " + sig.toHex()); Bytes token(signed_parts + sig); - debug("Fernet::encrypt: token length: " + std::to_string(token.size())); + DEBUG("Fernet::encrypt: token length: " + std::to_string(token.size())); return token; } const Bytes Fernet::decrypt(const Bytes& token) { - debug("Fernet::decrypt: token length: " + std::to_string(token.size())); + DEBUG("Fernet::decrypt: token length: " + std::to_string(token.size())); if (token.size() < 48) { throw std::invalid_argument("Cannot decrypt token of only " + std::to_string(token.size()) + " bytes"); } @@ -89,11 +89,11 @@ const Bytes Fernet::decrypt(const Bytes& token) { //iv = token[:16] Bytes iv = token.left(16); - extreme("Fernet::decrypt: iv: " + iv.toHex()); + TRACE("Fernet::decrypt: iv: " + iv.toHex()); //ciphertext = token[16:-32] Bytes ciphertext = token.mid(16, token.size()-48); - extreme("Fernet::decrypt: ciphertext: " + ciphertext.toHex()); + TRACE("Fernet::decrypt: ciphertext: " + ciphertext.toHex()); try { Bytes plaintext = PKCS7::unpad( @@ -103,10 +103,10 @@ const Bytes Fernet::decrypt(const Bytes& token) { iv ) ); - debug("Fernet::encrypt: unpadded plaintext length: " + std::to_string(plaintext.size())); - extreme("Fernet::decrypt: plaintext: " + plaintext.toHex()); + DEBUG("Fernet::encrypt: unpadded plaintext length: " + std::to_string(plaintext.size())); + TRACE("Fernet::decrypt: plaintext: " + plaintext.toHex()); - debug("Fernet::decrypt: plaintext length: " + std::to_string(plaintext.size())); + DEBUG("Fernet::decrypt: plaintext length: " + std::to_string(plaintext.size())); return plaintext; } catch (std::exception& e) { diff --git a/src/Cryptography/Hashes.cpp b/src/Cryptography/Hashes.cpp index a74be12..5687efa 100644 --- a/src/Cryptography/Hashes.cpp +++ b/src/Cryptography/Hashes.cpp @@ -15,13 +15,13 @@ calls in RNS end up here. */ const Bytes RNS::Cryptography::sha256(const Bytes& data) { - //extreme("Cryptography::sha256: data: " + data.toHex() ); + //TRACE("Cryptography::sha256: data: " + data.toHex() ); SHA256 digest; digest.reset(); digest.update(data.data(), data.size()); Bytes hash; digest.finalize(hash.writable(32), 32); - //extreme("Cryptography::sha256: hash: " + hash.toHex() ); + //TRACE("Cryptography::sha256: hash: " + hash.toHex() ); return hash; } @@ -31,6 +31,6 @@ const Bytes RNS::Cryptography::sha512(const Bytes& data) { digest.update(data.data(), data.size()); Bytes hash; digest.finalize(hash.writable(64), 64); - //extreme("Cryptography::sha512: hash: " + hash.toHex() ); + //TRACE("Cryptography::sha512: hash: " + hash.toHex() ); return hash; } diff --git a/src/Cryptography/PKCS7.h b/src/Cryptography/PKCS7.h index 93895fe..4167d31 100644 --- a/src/Cryptography/PKCS7.h +++ b/src/Cryptography/PKCS7.h @@ -28,9 +28,9 @@ namespace RNS { namespace Cryptography { // updates passed buffer static inline void inplace_pad(Bytes& data, size_t bs = BLOCKSIZE) { size_t len = data.size(); - //debug("PKCS7::pad: len: " + std::to_string(len)); + //DEBUG("PKCS7::pad: len: " + std::to_string(len)); size_t padlen = bs - (len % bs); - //debug("PKCS7::pad: pad len: " + std::to_string(padlen)); + //DEBUG("PKCS7::pad: pad len: " + std::to_string(padlen)); // create zero-filled byte padding array of size padlen //p v = bytes([padlen]) //uint8_t pad[padlen] = {0}; @@ -41,24 +41,24 @@ namespace RNS { namespace Cryptography { // concatenate data with padding //p return data+v*padlen data.append(pad, padlen); - //debug("PKCS7::pad: data size: " + std::to_string(data.size())); + //DEBUG("PKCS7::pad: data size: " + std::to_string(data.size())); } // updates passed buffer static inline void inplace_unpad(Bytes& data, size_t bs = BLOCKSIZE) { size_t len = data.size(); - //debug("PKCS7::unpad: len: " + std::to_string(len)); + //DEBUG("PKCS7::unpad: len: " + std::to_string(len)); // read last byte which is pad length //pad = data[-1] size_t padlen = (size_t)data.data()[data.size()-1]; - //debug("PKCS7::unpad: pad len: " + std::to_string(padlen)); + //DEBUG("PKCS7::unpad: pad len: " + std::to_string(padlen)); if (padlen > bs) { throw std::runtime_error("Cannot unpad, invalid padding length of " + std::to_string(padlen) + " bytes"); } // truncate data to strip padding //return data[:len-padlen] data.resize(len - padlen); - //debug("PKCS7::unpad: data size: " + std::to_string(data.size())); + //DEBUG("PKCS7::unpad: data size: " + std::to_string(data.size())); } }; diff --git a/src/Cryptography/X25519.h b/src/Cryptography/X25519.h index 6472dbf..f6ae92d 100644 --- a/src/Cryptography/X25519.h +++ b/src/Cryptography/X25519.h @@ -169,26 +169,26 @@ namespace RNS { namespace Cryptography { } */ inline const Bytes exchange(const Bytes& peer_public_key) { - debug("X25519PublicKey::exchange: public key: " + _publicKey.toHex()); - debug("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex()); - debug("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex()); + DEBUG("X25519PublicKey::exchange: public key: " + _publicKey.toHex()); + DEBUG("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex()); + DEBUG("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex()); Bytes sharedKey; if (!Curve25519::eval(sharedKey.writable(32), _privateKey.data(), peer_public_key.data())) { throw std::runtime_error("Peer key is invalid"); } - debug("X25519PublicKey::exchange: shared key: " + sharedKey.toHex()); - debug("X25519PublicKey::exchange: post private key: " + _privateKey.toHex()); + DEBUG("X25519PublicKey::exchange: shared key: " + sharedKey.toHex()); + DEBUG("X25519PublicKey::exchange: post private key: " + _privateKey.toHex()); return sharedKey; } inline bool verify(const Bytes& peer_public_key) { - debug("X25519PublicKey::exchange: public key: " + _publicKey.toHex()); - debug("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex()); - debug("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex()); + DEBUG("X25519PublicKey::exchange: public key: " + _publicKey.toHex()); + DEBUG("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex()); + DEBUG("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex()); Bytes sharedKey(peer_public_key); bool success = Curve25519::dh2(sharedKey.writable(32), _privateKey.writable(32)); - debug("X25519PublicKey::exchange: shared key: " + sharedKey.toHex()); - debug("X25519PublicKey::exchange: post private key: " + _privateKey.toHex()); + DEBUG("X25519PublicKey::exchange: shared key: " + sharedKey.toHex()); + DEBUG("X25519PublicKey::exchange: post private key: " + _privateKey.toHex()); return success; } diff --git a/src/Destination.cpp b/src/Destination.cpp index 3cffb7f..51d64b7 100644 --- a/src/Destination.cpp +++ b/src/Destination.cpp @@ -15,52 +15,52 @@ using namespace RNS::Utilities; Destination::Destination(const Identity& identity, const directions direction, const types type, const char* app_name, const char* aspects) : _object(new Object(identity)) { assert(_object); - mem("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); // Check input values and build name string if (strchr(app_name, '.') != nullptr) { throw std::invalid_argument("Dots can't be used in app names"); } - //extreme("Destination::Destination: app name: " + std::string(app_name)); + //TRACE("Destination::Destination: app name: " + std::string(app_name)); _object->_type = type; _object->_direction = direction; std::string fullaspects(aspects); if (!identity && direction == IN && _object->_type != PLAIN) { - extreme("Destination::Destination: identity not provided, creating new one"); + TRACE("Destination::Destination: identity not provided, creating new one"); _object->_identity = Identity(); // CBA TODO determine why identity.hexhash is added both here and by expand_name called below fullaspects += "." + _object->_identity.hexhash(); } - //extreme("Destination::Destination: full aspects: " + fullaspects); + //TRACE("Destination::Destination: full aspects: " + fullaspects); if (_object->_identity && _object->_type == PLAIN) { throw std::invalid_argument("Selected destination type PLAIN cannot hold an identity"); } _object->_name = expand_name(_object->_identity, app_name, fullaspects.c_str()); - //extreme("Destination::Destination: name: " + _object->_name); + //TRACE("Destination::Destination: name: " + _object->_name); // Generate the destination address hash - //extreme("Destination::Destination: creating hash..."); + //TRACE("Destination::Destination: creating hash..."); _object->_hash = hash(_object->_identity, app_name, fullaspects.c_str()); _object->_hexhash = _object->_hash.toHex(); - extreme("Destination::Destination: hash: " + _object->_hash.toHex()); - //extreme("Destination::Destination: creating name hash..."); + TRACE("Destination::Destination: hash: " + _object->_hash.toHex()); + //TRACE("Destination::Destination: creating name hash..."); //p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)] _object->_name_hash = name_hash(app_name, aspects); - //extreme("Destination::Destination: name hash: " + _object->_name_hash.toHex()); + //TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex()); - //extreme("Destination::Destination: calling register_destination"); + //TRACE("Destination::Destination: calling register_destination"); Transport::register_destination(*this); - mem("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Destination::Destination(const Identity& identity, const Type::Destination::directions direction, const Type::Destination::types type, const Bytes& hash) : _object(new Object(identity)) { assert(_object); - mem("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); _object->_type = type; _object->_direction = direction; @@ -71,26 +71,26 @@ Destination::Destination(const Identity& identity, const Type::Destination::dire _object->_hash = hash; _object->_hexhash = _object->_hash.toHex(); - extreme("Destination::Destination: hash: " + _object->_hash.toHex()); - //extreme("Destination::Destination: creating name hash..."); + TRACE("Destination::Destination: hash: " + _object->_hash.toHex()); + //TRACE("Destination::Destination: creating name hash..."); //p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)] _object->_name_hash = name_hash("unknown", "unknown"); - //extreme("Destination::Destination: name hash: " + _object->_name_hash.toHex()); + //TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex()); - //extreme("Destination::Destination: calling register_destination"); + //TRACE("Destination::Destination: calling register_destination"); Transport::register_destination(*this); - mem("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } /*virtual*/ Destination::~Destination() { - mem("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); if (_object && _object.use_count() == 1) { - mem("Destination object has last data reference"); + MEM("Destination object has last data reference"); // CBA Can't call deregister_destination here because it's possible (likely even) that Destination // is being destructed from that same collection which will result in a llop and memory errors. - //extreme("Destination::~Destination: calling deregister_destination"); + //TRACE("Destination::~Destination: calling deregister_destination"); //Transport::deregister_destination(*this); } } @@ -184,7 +184,7 @@ relevant interfaces. Application specific data can be added to the announce. //Packet Destination::announce(const Bytes& app_data /*= {}*/, bool path_response /*= false*/, const Interface& attached_interface /*= {Type::NONE}*/, const Bytes& tag /*= {}*/, bool send /*= true*/) { Packet Destination::announce(const Bytes& app_data, bool path_response, const Interface& attached_interface, const Bytes& tag /*= {}*/, bool send /*= true*/) { assert(_object); - extreme("Destination::announce: announcing destination..."); + TRACE("Destination::announce: announcing destination..."); if (_object->_type != SINGLE) { throw std::invalid_argument("Only SINGLE destination types can be announced"); @@ -213,29 +213,29 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In /* // CBA TEST - extreme("Destination::announce: performing path test..."); - extreme("Destination::announce: inserting path..."); + TRACE("Destination::announce: performing path test..."); + TRACE("Destination::announce: inserting path..."); _object->_path_responses.insert({Bytes("foo_tag"), {0, Bytes("this is foo tag")}}); - extreme("Destination::announce: inserting path..."); + TRACE("Destination::announce: inserting path..."); _object->_path_responses.insert({Bytes("test_tag"), {0, Bytes("this is test tag")}}); if (path_response) { - extreme("Destination::announce: path_response is true"); + TRACE("Destination::announce: path_response is true"); } if (!tag.empty()) { - extreme("Destination::announce: tag is specified"); + TRACE("Destination::announce: tag is specified"); std::string tagstr((const char*)tag.data(), tag.size()); - debug(std::string("Destination::announce: tag: ") + tagstr); - debug(std::string("Destination::announce: tag len: ") + std::to_string(tag.size())); - extreme("Destination::announce: searching for tag..."); + DEBUG(std::string("Destination::announce: tag: ") + tagstr); + DEBUG(std::string("Destination::announce: tag len: ") + std::to_string(tag.size())); + TRACE("Destination::announce: searching for tag..."); if (_object->_path_responses.find(tag) != _object->_path_responses.end()) { - extreme("Destination::announce: found tag in _path_responses"); - debug(std::string("Destination::announce: data: ") +_object->_path_responses[tag].second.toString()); + TRACE("Destination::announce: found tag in _path_responses"); + DEBUG(std::string("Destination::announce: data: ") +_object->_path_responses[tag].second.toString()); } else { - extreme("Destination::announce: tag not found in _path_responses"); + TRACE("Destination::announce: tag not found in _path_responses"); } } - extreme("Destination::announce: path test finished"); + TRACE("Destination::announce: path test finished"); */ if (path_response && !tag.empty() && _object->_path_responses.find(tag) != _object->_path_responses.end()) { @@ -247,7 +247,7 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In // received via multiple paths. The difference in reception time will // potentially also be useful in determining characteristics of the // multiple available paths, and to choose the best one. - //z extreme("Using cached announce data for answering path request with tag "+RNS.prettyhexrep(tag)); + //z TRACE("Using cached announce data for answering path request with tag "+RNS.prettyhexrep(tag)); announce_data << _object->_path_responses[tag].second; } else { @@ -262,20 +262,20 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In } Bytes signed_data; - //extreme("Destination::announce: hash: " + _object->_hash.toHex()); - //extreme("Destination::announce: public key: " + _object->_identity.get_public_key().toHex()); - //extreme("Destination::announce: name hash: " + _object->_name_hash.toHex()); - //extreme("Destination::announce: random hash: " + random_hash.toHex()); - //extreme("Destination::announce: app data: " + new_app_data.toHex()); - //extreme("Destination::announce: app data text:" + new_app_data.toString()); + //TRACE("Destination::announce: hash: " + _object->_hash.toHex()); + //TRACE("Destination::announce: public key: " + _object->_identity.get_public_key().toHex()); + //TRACE("Destination::announce: name hash: " + _object->_name_hash.toHex()); + //TRACE("Destination::announce: random hash: " + random_hash.toHex()); + //TRACE("Destination::announce: app data: " + new_app_data.toHex()); + //TRACE("Destination::announce: app data text:" + new_app_data.toString()); signed_data << _object->_hash << _object->_identity.get_public_key() << _object->_name_hash << random_hash; if (new_app_data) { signed_data << new_app_data; } - //extreme("Destination::announce: signed data: " + signed_data.toHex()); + //TRACE("Destination::announce: signed data: " + signed_data.toHex()); Bytes signature(_object->_identity.sign(signed_data)); - //extreme("Destination::announce: signature: " + signature.toHex()); + //TRACE("Destination::announce: signature: " + signature.toHex()); announce_data << _object->_identity.get_public_key() << _object->_name_hash << random_hash << signature; @@ -285,20 +285,20 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In _object->_path_responses.insert({tag, {OS::time(), announce_data}}); } - //extreme("Destination::announce: announce_data:" + announce_data.toHex()); + //TRACE("Destination::announce: announce_data:" + announce_data.toHex()); Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE; if (path_response) { announce_context = Type::Packet::PATH_RESPONSE; } - //extreme("Destination::announce: creating announce packet..."); + //TRACE("Destination::announce: creating announce packet..."); //p announce_packet = RNS.Packet(self, announce_data, RNS.Packet.ANNOUNCE, context = announce_context, attached_interface = attached_interface) //Packet announce_packet(*this, announce_data, Type::Packet::ANNOUNCE, announce_context, Type::Transport::BROADCAST, Type::Packet::HEADER_1, nullptr, attached_interface); Packet announce_packet(*this, attached_interface, announce_data, Type::Packet::ANNOUNCE, announce_context, Type::Transport::BROADCAST, Type::Packet::HEADER_1); if (send) { - extreme("Destination::announce: sending announce packet..."); + TRACE("Destination::announce: sending announce packet..."); announce_packet.send(); return {Type::NONE}; } @@ -362,7 +362,7 @@ void Destination::receive(const Packet& packet) { else { // CBA TODO Why isn't the Packet decrypting itself? Bytes plaintext(decrypt(packet.data())); - //extreme("Destination::receive: decrypted data: " + plaintext.toHex()); + //TRACE("Destination::receive: decrypted data: " + plaintext.toHex()); if (plaintext) { if (packet.packet_type() == Type::Packet::DATA) { if (_object->_callbacks._packet) { @@ -370,7 +370,7 @@ void Destination::receive(const Packet& packet) { _object->_callbacks._packet(plaintext, packet); } catch (std::exception& e) { - debug("Error while executing receive callback from " + toString() + ". The contained exception was: " + e.what()); + DEBUG("Error while executing receive callback from " + toString() + ". The contained exception was: " + e.what()); } } } @@ -396,7 +396,7 @@ Encrypts information for ``RNS.Destination.SINGLE`` or ``RNS.Destination.GROUP`` */ /*virtual*/ const Bytes Destination::encrypt(const Bytes& data) { assert(_object); - extreme("Destination::encrypt: encrypting data..."); + TRACE("Destination::encrypt: encrypting data..."); if (_object->_type == PLAIN) { return data; @@ -433,7 +433,7 @@ Decrypts information for ``RNS.Destination.SINGLE`` or ``RNS.Destination.GROUP`` */ /*virtual*/ const Bytes Destination::decrypt(const Bytes& data) { assert(_object); - extreme("Destination::decrypt: decrypting data..."); + TRACE("Destination::decrypt: decrypting data..."); if (_object->_type == PLAIN) { return data; diff --git a/src/Destination.h b/src/Destination.h index 9fcbb9b..ec4bf56 100644 --- a/src/Destination.h +++ b/src/Destination.h @@ -55,10 +55,10 @@ namespace RNS { public: Destination(Type::NoneConstructor none) { - mem("Destination NONE object created, this: " + std::to_string((uintptr_t)this)); + MEM("Destination NONE object created, this: " + std::to_string((uintptr_t)this)); } Destination(const Destination& destination) : _object(destination._object) { - mem("Destination object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Destination object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Destination( const Identity& identity, @@ -77,7 +77,7 @@ namespace RNS { inline Destination& operator = (const Destination& destination) { _object = destination._object; - mem("Destination object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Destination object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return *this; } inline operator bool() const { @@ -179,8 +179,8 @@ namespace RNS { private: class Object { public: - Object(const Identity& identity) : _identity(identity) { mem("Destination::Data object created, this: " + std::to_string((uintptr_t)this)); } - virtual ~Object() { mem("Destination::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } + Object(const Identity& identity) : _identity(identity) { MEM("Destination::Data object created, this: " + std::to_string((uintptr_t)this)); } + virtual ~Object() { MEM("Destination::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } private: bool _accept_link_requests = true; Callbacks _callbacks; diff --git a/src/Filesystem.h b/src/Filesystem.h index 5b62c35..90d5f64 100644 --- a/src/Filesystem.h +++ b/src/Filesystem.h @@ -18,51 +18,51 @@ namespace RNS { public: Filesystem(Type::NoneConstructor none) { - mem("Filesystem object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Filesystem(const Filesystem& filesystem) : _object(filesystem._object) { - mem("Filesystem object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Filesystem() : _object(new Object(this)), _creator(true) { - mem("Filesystem object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } virtual ~Filesystem() { if (_creator) { - mem("Filesystem object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); // clear reference to parent in object foir safety assert(_object); _object->_parent = nullptr; } - mem("Filesystem object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } inline Filesystem& operator = (const Filesystem& filesystem) { _object = filesystem._object; - mem("Filesystem object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); if (_creator) { - mem("Filesystem object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); _creator = false; } return *this; } inline operator bool() const { - mem("Filesystem object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() != nullptr; } inline bool operator < (const Filesystem& filesystem) const { - mem("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() < filesystem._object.get(); } inline bool operator > (const Filesystem& filesystem) const { - mem("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() > filesystem._object.get(); } inline bool operator == (const Filesystem& filesystem) const { - mem("Filesystem object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() == filesystem._object.get(); } inline bool operator != (const Filesystem& filesystem) const { - mem("Filesystem object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Filesystem object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() != filesystem._object.get(); } @@ -76,7 +76,7 @@ namespace RNS { virtual bool directory_exists(const char* directory_path) { return false; } virtual bool create_directory(const char* directory_path) { return false; } virtual bool remove_directory(const char* directory_path) { return false; } - virtual std::list list_directory(const char* directory_path) { extreme("list_directory: empty"); return _empty; } + virtual std::list list_directory(const char* directory_path) { TRACE("list_directory: empty"); return _empty; } public: inline bool do_file_exists(const char* file_path) { assert(_object); return _object->do_file_exists(file_path); } @@ -107,9 +107,9 @@ namespace RNS { private: class Object { public: - Object(Filesystem* parent) : _parent(parent) { mem("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); } - Object(Filesystem* parent, const char* name) : _parent(parent) { mem("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); } - virtual ~Object() { mem("Filesystem::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } + Object(Filesystem* parent) : _parent(parent) { MEM("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); } + Object(Filesystem* parent, const char* name) : _parent(parent) { MEM("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); } + virtual ~Object() { MEM("Filesystem::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } private: virtual inline bool do_file_exists(const char* file_path) { if (_parent == nullptr) return false; return _parent->file_exists(file_path); } virtual inline size_t do_read_file(const char* file_path, Bytes& data) { if (_parent == nullptr) return {Bytes::NONE}; return _parent->read_file(file_path, data); } diff --git a/src/Identity.cpp b/src/Identity.cpp index c499594..0342a98 100644 --- a/src/Identity.cpp +++ b/src/Identity.cpp @@ -25,7 +25,7 @@ Identity::Identity(bool create_keys /*= true*/) : _object(new Object()) { if (create_keys) { createKeys(); } - mem("Identity object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Identity object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } void Identity::createKeys() { @@ -34,22 +34,22 @@ void Identity::createKeys() { // CRYPTO: create encryption private keys _object->_prv = Cryptography::X25519PrivateKey::generate(); _object->_prv_bytes = _object->_prv->private_bytes(); - //extreme("Identity::createKeys: prv bytes: " + _object->_prv_bytes.toHex()); + //TRACE("Identity::createKeys: prv bytes: " + _object->_prv_bytes.toHex()); // CRYPTO: create signature private keys _object->_sig_prv = Cryptography::Ed25519PrivateKey::generate(); _object->_sig_prv_bytes = _object->_sig_prv->private_bytes(); - //extreme("Identity::createKeys: sig prv bytes: " + _object->_sig_prv_bytes.toHex()); + //TRACE("Identity::createKeys: sig prv bytes: " + _object->_sig_prv_bytes.toHex()); // CRYPTO: create encryption public keys _object->_pub = _object->_prv->public_key(); _object->_pub_bytes = _object->_pub->public_bytes(); - //extreme("Identity::createKeys: pub bytes: " + _object->_pub_bytes.toHex()); + //TRACE("Identity::createKeys: pub bytes: " + _object->_pub_bytes.toHex()); // CRYPTO: create signature public keys _object->_sig_pub = _object->_sig_prv->public_key(); _object->_sig_pub_bytes = _object->_sig_pub->public_bytes(); - //extreme("Identity::createKeys: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); + //TRACE("Identity::createKeys: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); update_hashes(); @@ -70,20 +70,20 @@ bool Identity::load_private_key(const Bytes& prv_bytes) { //p self.prv_bytes = prv_bytes[:Identity.KEYSIZE//8//2] _object->_prv_bytes = prv_bytes.left(Type::Identity::KEYSIZE/8/2); _object->_prv = X25519PrivateKey::from_private_bytes(_object->_prv_bytes); - //extreme("Identity::load_private_key: prv bytes: " + _object->_prv_bytes.toHex()); + //TRACE("Identity::load_private_key: prv bytes: " + _object->_prv_bytes.toHex()); //p self.sig_prv_bytes = prv_bytes[Identity.KEYSIZE//8//2:] _object->_sig_prv_bytes = prv_bytes.mid(Type::Identity::KEYSIZE/8/2); _object->_sig_prv = Ed25519PrivateKey::from_private_bytes(_object->_sig_prv_bytes); - //extreme("Identity::load_private_key: sig prv bytes: " + _object->_sig_prv_bytes.toHex()); + //TRACE("Identity::load_private_key: sig prv bytes: " + _object->_sig_prv_bytes.toHex()); _object->_pub = _object->_prv->public_key(); _object->_pub_bytes = _object->_pub->public_bytes(); - //extreme("Identity::load_private_key: pub bytes: " + _object->_pub_bytes.toHex()); + //TRACE("Identity::load_private_key: pub bytes: " + _object->_pub_bytes.toHex()); _object->_sig_pub = _object->_sig_prv->public_key(); _object->_sig_pub_bytes = _object->_sig_pub->public_bytes(); - //extreme("Identity::load_private_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); + //TRACE("Identity::load_private_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); update_hashes(); @@ -110,11 +110,11 @@ void Identity::load_public_key(const Bytes& pub_bytes) { //_pub_bytes = pub_bytes[:Identity.KEYSIZE//8//2] _object->_pub_bytes = pub_bytes.left(Type::Identity::KEYSIZE/8/2); - //extreme("Identity::load_public_key: pub bytes: " + _object->_pub_bytes.toHex()); + //TRACE("Identity::load_public_key: pub bytes: " + _object->_pub_bytes.toHex()); //_sig_pub_bytes = pub_bytes[Identity.KEYSIZE//8//2:] _object->_sig_pub_bytes = pub_bytes.mid(Type::Identity::KEYSIZE/8/2); - //extreme("Identity::load_public_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); + //TRACE("Identity::load_public_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); _object->_pub = X25519PublicKey::from_public_bytes(_object->_pub_bytes); _object->_sig_pub = Ed25519PublicKey::from_public_bytes(_object->_sig_pub_bytes); @@ -127,7 +127,7 @@ void Identity::load_public_key(const Bytes& pub_bytes) { } bool Identity::load(const char* path) { - extreme("Reading identity key from storage..."); + TRACE("Reading identity key from storage..."); try { Bytes prv_bytes; if (OS::read_file(path, prv_bytes) > 0) { @@ -153,7 +153,7 @@ communication for the identity. Be very careful with this method. :returns: True if the file was saved, otherwise False. */ bool Identity::to_file(const char* path) { - extreme("Writing identity key to storage..."); + TRACE("Writing identity key to storage..."); try { return (OS::write_file(path, get_private_key()) == get_private_key().size()); } @@ -197,10 +197,10 @@ Recall identity for a destination hash. :returns: An :ref:`RNS.Identity` instance that can be used to create an outgoing :ref:`RNS.Destination`, or *None* if the destination is unknown. */ /*static*/ Identity Identity::recall(const Bytes& destination_hash) { - extreme("Identity::recall..."); + TRACE("Identity::recall..."); auto iter = _known_destinations.find(destination_hash); if (iter != _known_destinations.end()) { - extreme("Identity::recall: Found identity entry for destination " + destination_hash.toHex()); + TRACE("Identity::recall: Found identity entry for destination " + destination_hash.toHex()); const IdentityEntry& identity_data = (*iter).second; Identity identity(false); identity.load_public_key(identity_data._public_key); @@ -208,16 +208,16 @@ Recall identity for a destination hash. return identity; } else { - extreme("Identity::recall: Unable to find identity entry for destination " + destination_hash.toHex() + ", performing destination lookup..."); + TRACE("Identity::recall: Unable to find identity entry for destination " + destination_hash.toHex() + ", performing destination lookup..."); Destination registered_destination(Transport::find_destination_from_hash(destination_hash)); if (registered_destination) { - extreme("Identity::recall: Found destination " + destination_hash.toHex()); + TRACE("Identity::recall: Found destination " + destination_hash.toHex()); Identity identity(false); identity.load_public_key(registered_destination.identity().get_public_key()); identity.app_data({Bytes::NONE}); return identity; } - extreme("Identity::recall: Unable to find destination " + destination_hash.toHex()); + TRACE("Identity::recall: Unable to find destination " + destination_hash.toHex()); return {Type::NONE}; } } @@ -229,15 +229,15 @@ Recall last heard app_data for a destination hash. :returns: *Bytes* containing app_data, or *None* if the destination is unknown. */ /*static*/ Bytes Identity::recall_app_data(const Bytes& destination_hash) { - extreme("Identity::recall_app_data..."); + TRACE("Identity::recall_app_data..."); auto iter = _known_destinations.find(destination_hash); if (iter != _known_destinations.end()) { - extreme("Identity::recall_app_data: Found identity entry for destination " + destination_hash.toHex()); + TRACE("Identity::recall_app_data: Found identity entry for destination " + destination_hash.toHex()); const IdentityEntry& identity_data = (*iter).second; return identity_data._app_data; } else { - extreme("Identity::recall_app_data: Unable to find identity entry for destination " + destination_hash.toHex()); + TRACE("Identity::recall_app_data: Unable to find identity entry for destination " + destination_hash.toHex()); return {Bytes::NONE}; } } @@ -289,7 +289,7 @@ Recall last heard app_data for a destination hash. // TODO /* - debug("Saving " + std::to_string(_known_destinations.size()) + " known destinations to storage..."); + DEBUG("Saving " + std::to_string(_known_destinations.size()) + " known destinations to storage..."); file = open(RNS.Reticulum.storagepath+"/known_destinations","wb") umsgpack.dump(Identity.known_destinations, file) file.close() @@ -304,7 +304,7 @@ Recall last heard app_data for a destination hash. time_str = std::to_string(OS::round(save_time, 1)) + " s"; } - debug("Saved known destinations to storage in " + time_str); + DEBUG("Saved known destinations to storage in " + time_str); success = true; } @@ -344,25 +344,25 @@ Recall last heard app_data for a destination hash. try { if (packet.packet_type() == Type::Packet::ANNOUNCE) { Bytes destination_hash = packet.destination_hash(); - //extreme("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex()); + //TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex()); Bytes public_key = packet.data().left(KEYSIZE/8); - //extreme("Identity::validate_announce: public_key: " + public_key.toHex()); + //TRACE("Identity::validate_announce: public_key: " + public_key.toHex()); Bytes name_hash = packet.data().mid(KEYSIZE/8, NAME_HASH_LENGTH/8); - //extreme("Identity::validate_announce: name_hash: " + name_hash.toHex()); + //TRACE("Identity::validate_announce: name_hash: " + name_hash.toHex()); Bytes random_hash = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8, RANDOM_HASH_LENGTH/8); - //extreme("Identity::validate_announce: random_hash: " + random_hash.toHex()); + //TRACE("Identity::validate_announce: random_hash: " + random_hash.toHex()); Bytes signature = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8, SIGLENGTH/8); - //extreme("Identity::validate_announce: signature: " + signature.toHex()); + //TRACE("Identity::validate_announce: signature: " + signature.toHex()); Bytes app_data; if (packet.data().size() > (KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8)) { app_data = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8); } - //extreme("Identity::validate_announce: app_data: " + app_data.toHex()); - //extreme("Identity::validate_announce: app_data text: " + app_data.toString()); + //TRACE("Identity::validate_announce: app_data: " + app_data.toHex()); + //TRACE("Identity::validate_announce: app_data text: " + app_data.toString()); Bytes signed_data; signed_data << packet.destination_hash() << public_key << name_hash << random_hash+app_data; - //extreme("Identity::validate_announce: signed_data: " + signed_data.toHex()); + //TRACE("Identity::validate_announce: signed_data: " + signed_data.toHex()); if (packet.data().size() <= KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8) { app_data.clear(); @@ -374,8 +374,8 @@ Recall last heard app_data for a destination hash. if (announced_identity.pub() && announced_identity.validate(signature, signed_data)) { Bytes hash_material = name_hash << announced_identity.hash(); Bytes expected_hash = full_hash(hash_material).left(Type::Reticulum::TRUNCATED_HASHLENGTH/8); - //extreme("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex()); - //extreme("Identity::validate_announce: expected_hash: " + expected_hash.toHex()); + //TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex()); + //TRACE("Identity::validate_announce: expected_hash: " + expected_hash.toHex()); if (packet.destination_hash() == expected_hash) { // Check if we already have a public key for this destination @@ -412,21 +412,21 @@ Recall last heard app_data for a destination hash. */ if (packet.transport_id()) { - extreme("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received via " + packet.transport_id().toHex() + " on " + packet.receiving_interface().toString() + signal_str); + TRACE("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received via " + packet.transport_id().toHex() + " on " + packet.receiving_interface().toString() + signal_str); } else { - extreme("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received on " + packet.receiving_interface().toString() + signal_str); + TRACE("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received on " + packet.receiving_interface().toString() + signal_str); } return true; } else { - debug("Received invalid announce for " + packet.destination_hash().toHex() + ": Destination mismatch."); + DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Destination mismatch."); return false; } } else { - debug("Received invalid announce for " + packet.destination_hash().toHex() + ": Invalid signature."); + DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Invalid signature."); //p del announced_identity return false; } @@ -458,18 +458,18 @@ Encrypts information for the identity. */ const Bytes Identity::encrypt(const Bytes& plaintext) const { assert(_object); - extreme("Identity::encrypt: encrypting data..."); + TRACE("Identity::encrypt: encrypting data..."); if (!_object->_pub) { throw std::runtime_error("Encryption failed because identity does not hold a public key"); } Cryptography::X25519PrivateKey::Ptr ephemeral_key = Cryptography::X25519PrivateKey::generate(); Bytes ephemeral_pub_bytes = ephemeral_key->public_key()->public_bytes(); - extreme("Identity::encrypt: ephemeral public key: " + ephemeral_pub_bytes.toHex()); + TRACE("Identity::encrypt: ephemeral public key: " + ephemeral_pub_bytes.toHex()); // CRYPTO: create shared key for key exchange using own public key //shared_key = ephemeral_key.exchange(self.pub) Bytes shared_key = ephemeral_key->exchange(_object->_pub_bytes); - extreme("Identity::encrypt: shared key: " + shared_key.toHex()); + TRACE("Identity::encrypt: shared key: " + shared_key.toHex()); Bytes derived_key = Cryptography::hkdf( 32, @@ -477,13 +477,13 @@ const Bytes Identity::encrypt(const Bytes& plaintext) const { get_salt(), get_context() ); - extreme("Identity::encrypt: derived key: " + derived_key.toHex()); + TRACE("Identity::encrypt: derived key: " + derived_key.toHex()); Cryptography::Fernet fernet(derived_key); - extreme("Identity::encrypt: Fernet encrypting data of length " + std::to_string(plaintext.size())); - extreme("Identity::encrypt: plaintext: " + plaintext.toHex()); + TRACE("Identity::encrypt: Fernet encrypting data of length " + std::to_string(plaintext.size())); + TRACE("Identity::encrypt: plaintext: " + plaintext.toHex()); Bytes ciphertext = fernet.encrypt(plaintext); - extreme("Identity::encrypt: ciphertext: " + ciphertext.toHex()); + TRACE("Identity::encrypt: ciphertext: " + ciphertext.toHex()); return ephemeral_pub_bytes + ciphertext; } @@ -498,12 +498,12 @@ Decrypts information for the identity. */ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const { assert(_object); - extreme("Identity::decrypt: decrypting data..."); + TRACE("Identity::decrypt: decrypting data..."); if (!_object->_prv) { throw std::runtime_error("Decryption failed because identity does not hold a private key"); } if (ciphertext_token.size() <= Type::Identity::KEYSIZE/8/2) { - debug("Decryption failed because the token size " + std::to_string(ciphertext_token.size()) + " was invalid."); + DEBUG("Decryption failed because the token size " + std::to_string(ciphertext_token.size()) + " was invalid."); return {Bytes::NONE}; } Bytes plaintext; @@ -512,12 +512,12 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const { Bytes peer_pub_bytes = ciphertext_token.left(Type::Identity::KEYSIZE/8/2); //peer_pub = X25519PublicKey.from_public_bytes(peer_pub_bytes) //Cryptography::X25519PublicKey::Ptr peer_pub = Cryptography::X25519PublicKey::from_public_bytes(peer_pub_bytes); - extreme("Identity::decrypt: peer public key: " + peer_pub_bytes.toHex()); + TRACE("Identity::decrypt: peer public key: " + peer_pub_bytes.toHex()); // CRYPTO: create shared key for key exchange using peer public key //shared_key = _object->_prv->exchange(peer_pub); Bytes shared_key = _object->_prv->exchange(peer_pub_bytes); - extreme("Identity::decrypt: shared key: " + shared_key.toHex()); + TRACE("Identity::decrypt: shared key: " + shared_key.toHex()); Bytes derived_key = Cryptography::hkdf( 32, @@ -525,19 +525,19 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const { get_salt(), get_context() ); - extreme("Identity::decrypt: derived key: " + derived_key.toHex()); + TRACE("Identity::decrypt: derived key: " + derived_key.toHex()); Cryptography::Fernet fernet(derived_key); //ciphertext = ciphertext_token[Identity.KEYSIZE//8//2:] Bytes ciphertext(ciphertext_token.mid(Type::Identity::KEYSIZE/8/2)); - extreme("Identity::decrypt: Fernet decrypting data of length " + std::to_string(ciphertext.size())); - extreme("Identity::decrypt: ciphertext: " + ciphertext.toHex()); + TRACE("Identity::decrypt: Fernet decrypting data of length " + std::to_string(ciphertext.size())); + TRACE("Identity::decrypt: ciphertext: " + ciphertext.toHex()); plaintext = fernet.decrypt(ciphertext); - extreme("Identity::decrypt: plaintext: " + plaintext.toHex()); - //extreme("Identity::decrypt: Fernet decrypted data of length " + std::to_string(plaintext.size())); + TRACE("Identity::decrypt: plaintext: " + plaintext.toHex()); + //TRACE("Identity::decrypt: Fernet decrypted data of length " + std::to_string(plaintext.size())); } catch (std::exception& e) { - debug("Decryption by " + toString() + " failed: " + e.what()); + DEBUG("Decryption by " + toString() + " failed: " + e.what()); } return plaintext; @@ -576,7 +576,7 @@ bool Identity::validate(const Bytes& signature, const Bytes& message) const { assert(_object); if (_object->_pub) { try { - extreme("Identity::validate: Attempting to verify signature: " + signature.toHex() + " and message: " + message.toHex()); + TRACE("Identity::validate: Attempting to verify signature: " + signature.toHex() + " and message: " + message.toHex()); _object->_sig_pub->verify(signature, message); return true; } @@ -595,21 +595,21 @@ void Identity::prove(const Packet& packet, const Destination& destination /*= {T Bytes proof_data; if (RNS::Reticulum::should_use_implicit_proof()) { proof_data = signature; - extreme("Identity::prove: implicit proof data: " + proof_data.toHex()); + TRACE("Identity::prove: implicit proof data: " + proof_data.toHex()); } else { proof_data = packet.packet_hash() + signature; - extreme("Identity::prove: explicit proof data: " + proof_data.toHex()); + TRACE("Identity::prove: explicit proof data: " + proof_data.toHex()); } if (!destination) { - extreme("Identity::prove: proving packet with proof destination..."); + TRACE("Identity::prove: proving packet with proof destination..."); ProofDestination proof_destination = packet.generate_proof_destination(); Packet proof(proof_destination, packet.receiving_interface(), proof_data, Type::Packet::PROOF); proof.send(); } else { - extreme("Identity::prove: proving packet with specified destination..."); + TRACE("Identity::prove: proving packet with specified destination..."); Packet proof(destination, packet.receiving_interface(), proof_data, Type::Packet::PROOF); proof.send(); } diff --git a/src/Identity.h b/src/Identity.h index e1d18a6..84a180f 100644 --- a/src/Identity.h +++ b/src/Identity.h @@ -43,19 +43,19 @@ namespace RNS { public: Identity(Type::NoneConstructor none) { - mem("Identity NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Identity NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Identity(const Identity& identity) : _object(identity._object) { - mem("Identity object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Identity object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Identity(bool create_keys = true); virtual ~Identity() { - mem("Identity object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Identity object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } inline Identity& operator = (const Identity& identity) { _object = identity._object; - mem("Identity object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Identity object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return *this; } inline operator bool() const { @@ -87,7 +87,7 @@ namespace RNS { inline void update_hashes() { assert(_object); _object->_hash = truncated_hash(get_public_key()); - extreme("Identity::update_hashes: hash: " + _object->_hash.toHex()); + TRACE("Identity::update_hashes: hash: " + _object->_hash.toHex()); _object->_hexhash = _object->_hash.toHex(); }; bool load(const char* path); @@ -161,8 +161,8 @@ namespace RNS { private: class Object { public: - Object() { mem("Identity::Data object created, this: " + std::to_string((uintptr_t)this)); } - virtual ~Object() { mem("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } + Object() { MEM("Identity::Data object created, this: " + std::to_string((uintptr_t)this)); } + virtual ~Object() { MEM("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } private: Cryptography::X25519PrivateKey::Ptr _prv; diff --git a/src/Interface.cpp b/src/Interface.cpp index de7a634..6d6393a 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -10,17 +10,17 @@ using namespace RNS::Type::Interface; Interface::Interface() : _object(new Object(this)), _creator(true) { _object->_hash = Identity::full_hash({toString()}); - mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Interface::Interface(const char* name) : _object(new Object(this, name)), _creator(true) { _object->_hash = Identity::full_hash({toString()}); - mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } /*virtual*/ inline void Interface::on_incoming(const Bytes& data) { - //extreme("Interface.on_incoming: data: " + data.toHex()); - extreme("Interface.on_incoming"); + //TRACE("Interface.on_incoming: data: " + data.toHex()); + TRACE("Interface.on_incoming"); assert(_object); _object->_rxb += data.size(); // CBA TODO implement concept of owner or a callback mechanism for incoming data @@ -29,8 +29,8 @@ Interface::Interface(const char* name) : _object(new Object(this, name)), _creat } /*virtual*/ inline void Interface::on_outgoing(const Bytes& data) { - //extreme("Interface.on_outgoing: data: " + data.toHex()); - extreme("Interface.on_outgoing"); + //TRACE("Interface.on_outgoing: data: " + data.toHex()); + TRACE("Interface.on_outgoing"); assert(_object); _object->_txb += data.size(); } @@ -90,19 +90,19 @@ void Interface::process_announce_queue() { /* void ArduinoJson::convertFromJson(JsonVariantConst src, RNS::Interface& dst) { - RNS::extreme(">>> Deserializing Interface"); -RNS::extreme(">>> Interface pre: " + dst.debugString()); + TRACE(">>> Deserializing Interface"); +TRACE(">>> Interface pre: " + dst.debugString()); if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - RNS::extreme(">>> Querying Transport for Interface hash " + hash.toHex()); + TRACE(">>> Querying Transport for Interface hash " + hash.toHex()); // Query transport for matching interface dst = Transport::find_interface_from_hash(hash); -RNS::extreme(">>> Interface post: " + dst.debugString()); +TRACE(">>> Interface post: " + dst.debugString()); } else { dst = {RNS::Type::NONE}; -RNS::extreme(">>> Interface post: " + dst.debugString()); +TRACE(">>> Interface post: " + dst.debugString()); } } */ diff --git a/src/Interface.h b/src/Interface.h index a79bea0..1f350a3 100644 --- a/src/Interface.h +++ b/src/Interface.h @@ -43,50 +43,50 @@ namespace RNS { public: Interface(Type::NoneConstructor none) { - mem("Interface object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Interface(const Interface& interface) : _object(interface._object) { - mem("Interface object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Interface(); Interface(const char* name); virtual ~Interface() { if (_creator) { - mem("Interface object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); // clear reference to parent in object foir safety assert(_object); _object->_parent = nullptr; } - mem("Interface object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } inline Interface& operator = (const Interface& interface) { _object = interface._object; - mem("Interface object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); if (_creator) { - mem("Interface object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); _creator = false; } return *this; } inline operator bool() const { - mem("Interface object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() != nullptr; } inline bool operator < (const Interface& interface) const { - mem("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() < interface._object.get(); } inline bool operator > (const Interface& interface) const { - mem("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() > interface._object.get(); } inline bool operator == (const Interface& interface) const { - mem("Interface object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() == interface._object.get(); } inline bool operator != (const Interface& interface) const { - mem("Interface object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Interface object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return _object.get() != interface._object.get(); } @@ -147,9 +147,9 @@ namespace RNS { private: class Object { public: - Object(Interface* parent) : _parent(parent) { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); } - Object(Interface* parent, const char* name) : _parent(parent), _name(name) { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); } - virtual ~Object() { mem("Interface::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } + Object(Interface* parent) : _parent(parent) { MEM("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); } + Object(Interface* parent, const char* name) : _parent(parent), _name(name) { MEM("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); } + virtual ~Object() { MEM("Interface::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } private: //virtual inline void process_incoming(const Bytes& data) { if (_parent != nullptr) { _parent->on_incoming(data); } } virtual inline void process_outgoing(const Bytes& data) { if (_parent != nullptr) { _parent->on_outgoing(data); } } @@ -187,11 +187,11 @@ namespace RNS { /* namespace ArduinoJson { inline bool convertToJson(const RNS::Interface& src, JsonVariant dst) { - RNS::extreme("<<< Serializing Interface"); + TRACE("<<< Serializing Interface"); if (!src) { return dst.set(nullptr); } - RNS::extreme("<<< Interface hash " + src.get_hash().toHex()); + TRACE("<<< Interface hash " + src.get_hash().toHex()); return dst.set(src.get_hash().toHex()); } void convertFromJson(JsonVariantConst src, RNS::Interface& dst); @@ -208,15 +208,15 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - RNS::extreme("<<< Serializing interface hash " + src.get_hash().toHex()); + TRACE("<<< Serializing interface hash " + src.get_hash().toHex()); return dst.set(src.get_hash().toHex()); } static RNS::Interface fromJson(JsonVariantConst src) { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - RNS::extreme(">>> Deserialized interface hash " + hash.toHex()); - RNS::extreme(">>> Querying transport for interface"); + TRACE(">>> Deserialized interface hash " + hash.toHex()); + TRACE(">>> Querying transport for interface"); // Query transport for matching interface return RNS::Interface::find_interface_from_hash(hash); } diff --git a/src/Link.cpp b/src/Link.cpp index 39513da..0188d31 100644 --- a/src/Link.cpp +++ b/src/Link.cpp @@ -9,7 +9,7 @@ using namespace RNS::Type::Link; Link::Link(const Destination& destination) : _object(new Object(destination)) { assert(_object); - mem("Link object created"); + MEM("Link object created"); } diff --git a/src/Link.h b/src/Link.h index 9edca37..06ab3bb 100644 --- a/src/Link.h +++ b/src/Link.h @@ -22,14 +22,14 @@ namespace RNS { public: Link(Type::NoneConstructor none) { - mem("Link NONE object created"); + MEM("Link NONE object created"); } Link(const Link& link) : _object(link._object) { - mem("Link object copy created"); + MEM("Link object copy created"); } Link(const Destination& destination); virtual ~Link(){ - mem("Link object destroyed"); + MEM("Link object destroyed"); } inline Link& operator = (const Link& link) { diff --git a/src/Log.h b/src/Log.h index 9106b35..0c1c0aa 100644 --- a/src/Log.h +++ b/src/Log.h @@ -7,13 +7,14 @@ #include #ifndef NDEBUG -#define DEBUG(msg) (RNS::debug(msg)) -#define TRACE(msg) (RNS::extreme(msg)) -#define MEM(msg) (RNS::mem(msg)) + #define DEBUG(msg) (RNS::debug(msg)) + #define TRACE(msg) (RNS::extreme(msg)) + //#define MEM(msg) (RNS::mem(msg)) + #define MEM(ignore) ((void)0) #else -#define DEBUG(ignore) ((void)0) -#define TRACE(ignore) ((void)0) -#define MEM(ignore) ((void)0) + #define DEBUG(ignore) ((void)0) + #define TRACE(ignore) ((void)0) + #define MEM(ignore) ((void)0) #endif namespace RNS { diff --git a/src/Packet.cpp b/src/Packet.cpp index 04c809b..4616196 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -20,7 +20,7 @@ ProofDestination::ProofDestination(const Packet& packet) : Destination({Type::NO Packet::Packet(const Destination& destination, const Interface& attached_interface, const Bytes& data, types packet_type /*= DATA*/, context_types context /*= CONTEXT_NONE*/, Type::Transport::types transport_type /*= Type::Transport::BROADCAST*/, header_types header_type /*= HEADER_1*/, const Bytes& transport_id /*= {Bytes::NONE}*/, bool create_receipt /*= true*/) : _object(new Object(destination, attached_interface)) { if (_object->_destination) { - extreme("Creating packet with destination..."); + TRACE("Creating packet with destination..."); // CBA Should never see empty transport_type //if (transport_type == NONE) { // transport_type = Type::Transport::BROADCAST; @@ -41,13 +41,13 @@ Packet::Packet(const Destination& destination, const Interface& attached_interfa _object->_create_receipt = create_receipt; } else { - extreme("Creating packet without destination..."); + TRACE("Creating packet without destination..."); _object->_raw = data; _object->_packed = true; _object->_fromPacked = true; _object->_create_receipt = false; } - mem("Packet object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Packet object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } @@ -241,7 +241,7 @@ but excluding any interface access codes. void Packet::pack() { assert(_object); - extreme("Packet::pack: packing packet..."); + TRACE("Packet::pack: packing packet..."); if (!_object->_destination) { throw std::logic_error("Packet destination is required"); @@ -255,14 +255,14 @@ void Packet::pack() { _object->_raw << _object->_hops; if (_object->_context == LRPROOF) { - extreme("Packet::pack: destination link id: " + _object->_destination.link_id().toHex() ); + TRACE("Packet::pack: destination link id: " + _object->_destination.link_id().toHex() ); _object->_raw << _object->_destination.link_id(); _object->_raw << (uint8_t)_object->_context; _object->_raw << _object->_data; } else { if (_object->_header_type == HEADER_1) { - extreme("Packet::pack: destination hash: " + _object->_destination.hash().toHex() ); + TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() ); _object->_raw << _object->_destination.hash(); _object->_raw << (uint8_t)_object->_context; @@ -307,8 +307,8 @@ void Packet::pack() { if (!_object->_transport_id) { throw std::invalid_argument("Packet with header type 2 must have a transport ID"); } - extreme("Packet::pack: transport id: " + _object->_transport_id.toHex() ); - extreme("Packet::pack: destination hash: " + _object->_destination.hash().toHex() ); + TRACE("Packet::pack: transport id: " + _object->_transport_id.toHex() ); + TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() ); _object->_raw << _object->_transport_id; _object->_raw << _object->_destination.hash(); _object->_raw << (uint8_t)_object->_context; @@ -333,7 +333,7 @@ void Packet::pack() { bool Packet::unpack() { assert(_object); - extreme("Packet::unpack: unpacking packet..."); + TRACE("Packet::unpack: unpacking packet..."); try { if (_object->_raw.size() < Type::Reticulum::HEADER_MINSIZE) { throw std::length_error("Packet size of " + std::to_string(_object->_raw.size()) + " does not meet minimum header size of " + std::to_string(Type::Reticulum::HEADER_MINSIZE) +" bytes"); @@ -391,7 +391,7 @@ Sends the packet. */ bool Packet::send() { assert(_object); - extreme("Packet::send: sending packet..."); + TRACE("Packet::send: sending packet..."); if (_object->_sent) { throw std::logic_error("Packet was already sent"); } @@ -414,7 +414,7 @@ bool Packet::send() { } if (Transport::outbound(*this)) { - extreme("Packet::send: successfully sent packet!!!"); + TRACE("Packet::send: successfully sent packet!!!"); //z return self.receipt // MOCK return true; @@ -434,7 +434,7 @@ Re-sends the packet. */ bool Packet::resend() { assert(_object); - extreme("Packet::resend: re-sending packet..."); + TRACE("Packet::resend: re-sending packet..."); if (!_object->_sent) { throw std::logic_error("Packet was not sent yet"); } @@ -443,7 +443,7 @@ bool Packet::resend() { pack(); if (Transport::outbound(*this)) { - extreme("Packet::resend: successfully sent packet!!!"); + TRACE("Packet::resend: successfully sent packet!!!"); //z return self.receipt // MOCK return true; @@ -458,7 +458,7 @@ bool Packet::resend() { void Packet::prove(const Destination& destination /*= {Type::NONE}*/) { assert(_object); - extreme("Packet::prove: proving packet..."); + TRACE("Packet::prove: proving packet..."); if (!_object->_destination) { throw std::logic_error("Packet destination is required"); } @@ -780,7 +780,7 @@ bool PacketReceipt::validate_link_proof(const Bytes& proof, const Link& link) { } bool PacketReceipt::validate_link_proof(const Bytes& proof, const Link& link, const Packet& proof_packet) { assert(_object); - extreme("PacketReceipt::validate_link_proof: validating link proof..."); + TRACE("PacketReceipt::validate_link_proof: validating link proof..."); // TODO: Hardcoded as explicit proofs for now if (true || proof.size() == EXPL_LENGTH) { // This is an explicit proof @@ -843,7 +843,7 @@ bool PacketReceipt::validate_proof(const Bytes& proof) { } bool PacketReceipt::validate_proof(const Bytes& proof, const Packet& proof_packet) { assert(_object); - extreme("PacketReceipt::validate_proof: validating proof..."); + TRACE("PacketReceipt::validate_proof: validating proof..."); if (proof.size() == EXPL_LENGTH) { // This is an explicit proof Bytes proof_hash = proof.left(Type::Identity::HASHLENGTH/8); diff --git a/src/Packet.h b/src/Packet.h index dd48f6b..17e68e1 100644 --- a/src/Packet.h +++ b/src/Packet.h @@ -136,10 +136,10 @@ namespace RNS { public: Packet(Type::NoneConstructor none) { - mem("Packet NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Packet NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Packet(const Packet& packet) : _object(packet._object) { - mem("Packet object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Packet object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Packet( const Destination& destination, @@ -163,12 +163,12 @@ namespace RNS { bool create_receipt = true ) : Packet(destination, {Type::NONE}, data, packet_type, context, transport_type, header_type, transport_id, create_receipt) {} virtual ~Packet() { - mem("Packet object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Packet object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } inline Packet& operator = (const Packet& packet) { _object = packet._object; - mem("Packet object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Packet object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return *this; } inline operator bool() const { @@ -244,8 +244,8 @@ namespace RNS { private: class Object { public: - Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) { mem("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); } - virtual ~Object() { mem("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } + Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) { MEM("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); } + virtual ~Object() { MEM("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } private: Destination _destination = {Type::NONE}; Link _link = {Type::NONE}; @@ -314,15 +314,15 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - RNS::extreme("<<< Serializing packet hash " + src.get_hash().toHex()); + TRACE("<<< Serializing packet hash " + src.get_hash().toHex()); return dst.set(src.get_hash().toHex()); } static RNS::Packet fromJson(JsonVariantConst src) { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - RNS::extreme(">>> Deserialized packet hash " + hash.toHex()); - RNS::extreme(">>> Querying transport for cached packet"); + TRACE(">>> Deserialized packet hash " + hash.toHex()); + TRACE(">>> Querying transport for cached packet"); // Query transport for matching interface return RNS::Packet::get_cached_packet(hash); } diff --git a/src/Reticulum.cpp b/src/Reticulum.cpp index f2f1d0a..404de2d 100644 --- a/src/Reticulum.cpp +++ b/src/Reticulum.cpp @@ -37,12 +37,12 @@ pass any traffic before being instantiated. */ //def __init__(self,configdir=None, loglevel=None, logdest=None, verbosity=None): Reticulum::Reticulum() : _object(new Object()) { - mem("Reticulum default object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Reticulum default object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); // Initialize random number generator - extreme("Initializing RNG..."); + TRACE("Initializing RNG..."); RNG.begin("Reticulum"); - extreme("RNG initial random value: " + std::to_string(Cryptography::randomnum())); + TRACE("RNG initial random value: " + std::to_string(Cryptography::randomnum())); #ifdef ARDUINO // Add a noise source to the list of sources known to RNG. @@ -89,7 +89,7 @@ Reticulum::Reticulum() : _object(new Object()) { Bytes buf; if (OS::read_file(time_offset_path.c_str(), buf) == 8) { uint64_t offset = *(uint64_t*)buf.data(); - debug("Read time offset of " + std::to_string(offset) + " from file"); + DEBUG("Read time offset of " + std::to_string(offset) + " from file"); OS::setTimeOffset(offset); } } @@ -154,7 +154,7 @@ Reticulum::Reticulum() : _object(new Object()) { signal.signal(signal.SIGTERM, Reticulum.sigterm_handler) */ - mem("Reticulum default object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Reticulum default object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } /*p TODO @@ -229,7 +229,7 @@ void Reticulum::should_persist_data() { } void Reticulum::persist_data() { - extreme("Persisting transport and identity data..."); + TRACE("Persisting transport and identity data..."); Transport::persist_data(); Identity::persist_data(); @@ -238,7 +238,7 @@ void Reticulum::persist_data() { try { std::string time_offset_path = Reticulum::_storagepath + "/time_offset"; uint64_t offset = OS::ltime(); - debug("Writing time offset of " + std::to_string(offset) + " to file"); + DEBUG("Writing time offset of " + std::to_string(offset) + " to file"); Bytes buf((uint8_t*)&offset, sizeof(offset)); OS::write_file(time_offset_path.c_str(), buf); } @@ -251,7 +251,7 @@ void Reticulum::persist_data() { } void Reticulum::clean_caches() { - extreme("Cleaning resource and packet caches..."); + TRACE("Cleaning resource and packet caches..."); double now = OS::time(); /* @@ -295,7 +295,7 @@ void Reticulum::clean_caches() { } void Reticulum::clear_caches() { - extreme("Clearing resource and packet caches..."); + TRACE("Clearing resource and packet caches..."); try { std::string destination_table_path = _storagepath + "/destination_table"; diff --git a/src/Reticulum.h b/src/Reticulum.h index 5a0e65c..8255c2b 100644 --- a/src/Reticulum.h +++ b/src/Reticulum.h @@ -36,19 +36,19 @@ namespace RNS { public: Reticulum(Type::NoneConstructor none) { - mem("Reticulum NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Reticulum NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Reticulum(const Reticulum& reticulum) : _object(reticulum._object) { - mem("Reticulum object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Reticulum object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } Reticulum(); virtual ~Reticulum() { - mem("Reticulum object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Reticulum object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); } inline Reticulum& operator = (const Reticulum& reticulum) { _object = reticulum._object; - mem("Reticulum object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEM("Reticulum object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); return *this; } inline operator bool() const { @@ -97,10 +97,10 @@ namespace RNS { class Object { public: Object() { - mem("Reticulum data object created, this: " + std::to_string((uintptr_t)this)); + MEM("Reticulum data object created, this: " + std::to_string((uintptr_t)this)); } virtual ~Object() { - mem("Reticulum data object destroyed, this: " + std::to_string((uintptr_t)this)); + MEM("Reticulum data object destroyed, this: " + std::to_string((uintptr_t)this)); } private: diff --git a/src/Transport.cpp b/src/Transport.cpp index 8305dc4..8af9246 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -126,7 +126,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (!_identity) { std::string transport_identity_path = Reticulum::_storagepath + "/transport_identity"; - debug("Checking for transport identity..."); + DEBUG("Checking for transport identity..."); try { // CBA TEST //OS::remove_file(transport_identity_path.c_str()); @@ -170,7 +170,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); path_request_destination.set_packet_callback(path_request_handler); _control_destinations.insert(path_request_destination); _control_hashes.insert(path_request_destination.hash()); - debug("Created transport-specific path request destination " + path_request_destination.hash().toHex()); + DEBUG("Created transport-specific path request destination " + path_request_destination.hash().toHex()); // Create transport-specific destination for tunnel synthesize Destination tunnel_synthesize_destination({Type::NONE}, Type::Destination::IN, Type::Destination::PLAIN, APP_NAME, "tunnel.synthesize"); @@ -179,7 +179,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); //p Transport.control_destinations.append(Transport.tunnel_synthesize_handler) _control_destinations.insert(tunnel_synthesize_destination); _control_hashes.insert(tunnel_synthesize_destination.hash()); - debug("Created transport-specific tunnel synthesize destination " + tunnel_synthesize_destination.hash().toHex()); + DEBUG("Created transport-specific tunnel synthesize destination " + tunnel_synthesize_destination.hash().toHex()); _jobs_running = false; @@ -202,7 +202,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); Destination probe_destination(_identity, Type::Destination::IN, Type::Destination::SINGLE, APP_NAME, "probe"); probe_destination.accepts_links(false); probe_destination.set_proof_strategy(Type::Destination::PROVE_ALL); - debug("Created probe responder destination " + probe_destination.hash().toHex()); + DEBUG("Created probe responder destination " + probe_destination.hash().toHex()); probe_destination.announce(); notice("Transport Instance will respond to probe requests on " + probe_destination.toString()); } @@ -264,7 +264,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } if ((OS::time() - last_path_request) > Type::Transport::PATH_REQUEST_MI) { - debug("Trying to rediscover path for " + link.destination().hash().toHex() + " since an attempted link was never established"); + DEBUG("Trying to rediscover path for " + link.destination().hash().toHex() + " since an attempted link was never established"); //if (path_requests.find(link.destination().hash()) == path_requests.end()) { if (path_requests.count(link.destination().hash()) == 0) { path_requests.insert(link.destination().hash()); @@ -319,17 +319,17 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); //for (auto& pair : _announce_table) { // const auto& destination_hash = pair.first; // auto& announce_entry = pair.second; -//extreme("[0] announce entry data size: " + std::to_string(announce_entry._packet.data().size())); +//TRACE("[0] announce entry data size: " + std::to_string(announce_entry._packet.data().size())); //p announce_entry = Transport.announce_table[destination_hash] if (announce_entry._retries > Type::Transport::PATHFINDER_R) { - extreme("Completed announce processing for " + destination_hash.toHex() + ", retry limit reached"); + TRACE("Completed announce processing for " + destination_hash.toHex() + ", retry limit reached"); // CBA OK to modify collection here since we're immediately exiting iteration _announce_table.erase(destination_hash); break; } else { if (OS::time() > announce_entry._retransmit_timeout) { - extreme("Performing announce processing for " + destination_hash.toHex() + "..."); + TRACE("Performing announce processing for " + destination_hash.toHex() + "..."); announce_entry._retransmit_timeout = OS::time() + Type::Transport::PATHFINDER_G + Type::Transport::PATHFINDER_RW; announce_entry._retries += 1; //p packet = announce_entry[5] @@ -347,9 +347,9 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); //P announce_destination.hexhash = announce_destination.hash.hex() //if (announce_entry._attached_interface) { -//extreme("[1] interface is valid"); -//extreme("[1] interface: " + announce_entry._attached_interface.debugString()); -//extreme("[1] interface: " + announce_entry._attached_interface.toString()); +//TRACE("[1] interface is valid"); +//TRACE("[1] interface: " + announce_entry._attached_interface.debugString()); +//TRACE("[1] interface: " + announce_entry._attached_interface.toString()); //} Packet new_packet( announce_destination, @@ -366,10 +366,10 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); new_packet.hops(announce_entry._hops); if (announce_entry._block_rebroadcasts) { - debug("Rebroadcasting announce as path response for " + announce_destination.hash().toHex() + " with hop count " + std::to_string(new_packet.hops())); + DEBUG("Rebroadcasting announce as path response for " + announce_destination.hash().toHex() + " with hop count " + std::to_string(new_packet.hops())); } else { - debug("Rebroadcasting announce for " + announce_destination.hash().toHex() + " with hop count " + std::to_string(new_packet.hops())); + DEBUG("Rebroadcasting announce for " + announce_destination.hash().toHex() + " with hop count " + std::to_string(new_packet.hops())); } outgoing.push_back(new_packet); @@ -391,7 +391,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); //_announce_table.insert_or_assign({destination_hash, held_entry}); _announce_table.erase(destination_hash); _announce_table.insert({destination_hash, held_entry}); - debug("Reinserting held announce into table"); + DEBUG("Reinserting held announce into table"); } } } @@ -453,7 +453,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // If the path has been invalidated between the time of // making the link request and now, try to rediscover it if (!has_path(link_entry._destination_hash)) { - debug("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted link was never established, and path is now missing"); + DEBUG("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted link was never established, and path is now missing"); path_request_conditions = true; } @@ -461,7 +461,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // attempt to rediscover a path to the destination, if this // has not already happened recently. else if (!path_request_throttle && lr_taken_hops == 0) { - debug("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted local client link was never established"); + DEBUG("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted local client link was never established"); path_request_conditions = true; } @@ -470,7 +470,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // of our interfaces, and that it roamed somewhere else. // In that case, try to discover a new path. else if (!path_request_throttle && hops_to(link_entry._destination_hash) == 1) { - debug("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted link was never established, and destination was previously local to an interface on this instance"); + DEBUG("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted link was never established, and destination was previously local to an interface on this instance"); path_request_conditions = true; } @@ -479,7 +479,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // of our interfaces, and that it roamed somewhere else. // In that case, try to discover a new path. else if ( !path_request_throttle and lr_taken_hops == 1) { - debug("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted link was never established, and link initiator is local to an interface on this instance"); + DEBUG("Trying to rediscover path for " + link_entry._destination_hash.toHex() + " since an attempted link was never established, and link initiator is local to an interface on this instance"); path_request_conditions = true; } @@ -516,11 +516,11 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (OS::time() > destination_expiry) { stale_paths.push_back(destination_hash); - debug("Path to " + destination_hash.toHex() + " timed out and was removed"); + DEBUG("Path to " + destination_hash.toHex() + " timed out and was removed"); } else if (_interfaces.count(attached_interface.get_hash()) == 0) { stale_paths.push_back(destination_hash); - debug("Path to " + destination_hash.toHex() + " was removed since the attached interface no longer exists"); + DEBUG("Path to " + destination_hash.toHex() + " was removed since the attached interface no longer exists"); } } @@ -529,7 +529,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); for (const auto& [destination_hash, path_entry] : _discovery_path_requests) { if (OS::time() > path_entry._timeout) { stale_discovery_path_requests.push_back(destination_hash); - debug("Waiting path request for " + destination_hash.toString() + " timed out and was removed"); + DEBUG("Waiting path request for " + destination_hash.toString() + " timed out and was removed"); } } @@ -539,14 +539,14 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); for (const auto& [tunnel_id, tunnel_entry] : _tunnels) { if (OS::time() > tunnel_entry._expires) { stale_tunnels.push_back(tunnel_id); - extreme("Tunnel " + tunnel_id.toHex() + " timed out and was removed"); + TRACE("Tunnel " + tunnel_id.toHex() + " timed out and was removed"); } else { std::vector stale_tunnel_paths; for (const auto& [destination_hash, destination_entry] : tunnel_entry._serialised_paths) { if (OS::time() > (destination_entry._timestamp + DESTINATION_TIMEOUT)) { stale_tunnel_paths.push_back(destination_hash); - extreme("Tunnel path to " + destination_hash.toHex() + " timed out and was removed"); + TRACE("Tunnel path to " + destination_hash.toHex() + " timed out and was removed"); } } @@ -558,7 +558,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } if (count > 0) { - extreme("Removed " + std::to_string(count) + " tunnel paths"); + TRACE("Removed " + std::to_string(count) + " tunnel paths"); } count = 0; @@ -567,7 +567,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); ++count; } if (count > 0) { - extreme("Released " + std::to_string(count) + " reverse table entries"); + TRACE("Released " + std::to_string(count) + " reverse table entries"); } count = 0; @@ -576,7 +576,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); ++count; } if (count > 0) { - extreme("Released " + std::to_string(count) + " links"); + TRACE("Released " + std::to_string(count) + " links"); } count = 0; @@ -586,7 +586,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); ++count; } if (count > 0) { - extreme("Removed " + std::to_string(count) + " paths"); + TRACE("Removed " + std::to_string(count) + " paths"); } count = 0; @@ -595,7 +595,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); ++count; } if (count > 0) { - extreme("Removed " + std::to_string(count) + " waiting path requests"); + TRACE("Removed " + std::to_string(count) + " waiting path requests"); } count = 0; @@ -604,7 +604,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); ++count; } if (count > 0) { - extreme("Removed " + std::to_string(count) + " tunnels"); + TRACE("Removed " + std::to_string(count) + " tunnels"); } #ifndef NDEBUG @@ -644,14 +644,14 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } /*static*/ void Transport::transmit(Interface& interface, const Bytes& raw) { - extreme("Transport::transmit()"); + TRACE("Transport::transmit()"); // CBA if (_callbacks._transmit_packet) { try { _callbacks._transmit_packet(raw, interface); } catch (std::exception& e) { - debug("Error while executing transmit packet callback. The contained exception was: " + std::string(e.what())); + DEBUG("Error while executing transmit packet callback. The contained exception was: " + std::string(e.what())); } } try { @@ -706,7 +706,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } /*static*/ bool Transport::outbound(Packet& packet) { - extreme("Transport::outbound()"); + TRACE("Transport::outbound()"); ++_packets_sent; if (!packet.destination()) { @@ -715,10 +715,10 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); return false; } - extreme("Transport::outbound: destination=" + packet.destination_hash().toHex() + " hops=" + std::to_string(packet.hops())); + TRACE("Transport::outbound: destination=" + packet.destination_hash().toHex() + " hops=" + std::to_string(packet.hops())); while (_jobs_running) { - extreme("Transport::outbound: sleeping..."); + TRACE("Transport::outbound: sleeping..."); OS::sleep(0.0005); } @@ -730,7 +730,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // Check if we have a known path for the destination in the path table //if packet.packet_type != RNS.Packet.ANNOUNCE and packet.destination.type != RNS.Destination.PLAIN and packet.destination.type != RNS.Destination.GROUP and packet.destination_hash in Transport.destination_table: if (packet.packet_type() != Type::Packet::ANNOUNCE && packet.destination().type() != Type::Destination::PLAIN && packet.destination().type() != Type::Destination::GROUP && _destination_table.find(packet.destination_hash()) != _destination_table.end()) { - extreme("Transport::outbound: Path to destination is known"); + TRACE("Transport::outbound: Path to destination is known"); //outbound_interface = Transport.destination_table[packet.destination_hash][5] DestinationEntry destination_entry = (*_destination_table.find(packet.destination_hash())).second; Interface outbound_interface = destination_entry.receiving_interface(); @@ -742,7 +742,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // to a local shared Reticulum instance. //if Transport.destination_table[packet.destination_hash][2] > 1: if (destination_entry._hops > 1) { - extreme("Forwarding packet to next closest interface..."); + TRACE("Forwarding packet to next closest interface..."); if (packet.header_type() == Type::Packet::HEADER_1) { // Insert packet into transport //new_flags = (RNS.Packet.HEADER_2) << 6 | (Transport.TRANSPORT) << 4 | (packet.flags & 0b00001111) @@ -772,7 +772,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // to transport it onto the network. //elif Transport.destination_table[packet.destination_hash][2] == 1 and Transport.owner.is_connected_to_shared_instance: else if (destination_entry._hops == 1 && _owner.is_connected_to_shared_instance()) { - extreme("Transport::outbound: Sending packet for directly connected interface to shared instance..."); + TRACE("Transport::outbound: Sending packet for directly connected interface to shared instance..."); if (packet.header_type() == Type::Packet::HEADER_1) { // Insert packet into transport //new_flags = (RNS.Packet.HEADER_2) << 6 | (Transport.TRANSPORT) << 4 | (packet.flags & 0b00001111) @@ -797,7 +797,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // directly reachable, and also on which interface, so we // simply transmit the packet directly on that one. else { - extreme("Transport::outbound: Sending packet over directly connected interface..."); + TRACE("Transport::outbound: Sending packet over directly connected interface..."); transmit(outbound_interface, packet.raw()); sent = true; } @@ -807,7 +807,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // just the relevant interface if the packet has an attached // interface, or belongs to a link. else { - extreme("Transport::outbound: Path to destination is unknown"); + TRACE("Transport::outbound: Path to destination is unknown"); bool stored_hash = false; #if defined(INTERFACES_SET) for (const Interface& interface : _interfaces) { @@ -816,13 +816,13 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); #elif defined(INTERFACES_MAP) for (auto& [hash, interface] : _interfaces) { #endif - extreme("Transport::outbound: Checking interface " + interface.toString()); + TRACE("Transport::outbound: Checking interface " + interface.toString()); if (interface.OUT()) { bool should_transmit = true; if (packet.destination().type() == Type::Destination::LINK) { if (packet.destination().status() == Type::Link::CLOSED) { - extreme("Transport::outbound: Pscket destination is link-closed, not transmitting"); + TRACE("Transport::outbound: Pscket destination is link-closed, not transmitting"); should_transmit = false; } // CBA Bug? Destination has no member attached_interface @@ -832,15 +832,15 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } if (packet.attached_interface() && interface != packet.attached_interface()) { - extreme("Transport::outbound: Packet has wrong attached interface, not transmitting"); + TRACE("Transport::outbound: Packet has wrong attached interface, not transmitting"); should_transmit = false; } if (packet.packet_type() == Type::Packet::ANNOUNCE) { if (!packet.attached_interface()) { - extreme("Transport::outbound: Packet has no attached interface"); + TRACE("Transport::outbound: Packet has no attached interface"); if (interface.mode() == Type::Interface::MODE_ACCESS_POINT) { - extreme("Blocking announce broadcast on " + interface.toString() + " due to AP mode"); + TRACE("Blocking announce broadcast on " + interface.toString() + " due to AP mode"); should_transmit = false; } else if (interface.mode() == Type::Interface::MODE_ROAMING) { @@ -865,7 +865,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); //} if (iter != _destinations.end()) { #endif - extreme("Allowing announce broadcast on roaming-mode interface from instance-local destination"); + TRACE("Allowing announce broadcast on roaming-mode interface from instance-local destination"); } else { const Interface& from_interface = next_hop_interface(packet.destination_hash()); @@ -873,19 +873,19 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (!from_interface || from_interface.mode() == Type::Interface::MODE_NONE) { should_transmit = false; if (!from_interface) { - extreme("Blocking announce broadcast on " + interface.toString() + " since next hop interface doesn't exist"); + TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface doesn't exist"); } else if (from_interface.mode() == Type::Interface::MODE_NONE) { - extreme("Blocking announce broadcast on " + interface.toString() + " since next hop interface has no mode configured"); + TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface has no mode configured"); } } else { if (from_interface.mode() == Type::Interface::MODE_ROAMING) { - extreme("Blocking announce broadcast on " + interface.toString() + " due to roaming-mode next-hop interface"); + TRACE("Blocking announce broadcast on " + interface.toString() + " due to roaming-mode next-hop interface"); should_transmit = false; } else if (from_interface.mode() == Type::Interface::MODE_BOUNDARY) { - extreme("Blocking announce broadcast on " + interface.toString() + " due to boundary-mode next-hop interface"); + TRACE("Blocking announce broadcast on " + interface.toString() + " due to boundary-mode next-hop interface"); should_transmit = false; } } @@ -914,22 +914,22 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); auto iter = _destinations.find(packet.destination_hash()); if (iter != _destinations.end()) { #endif - extreme("Allowing announce broadcast on boundary-mode interface from instance-local destination"); + TRACE("Allowing announce broadcast on boundary-mode interface from instance-local destination"); } else { const Interface& from_interface = next_hop_interface(packet.destination_hash()); if (!from_interface || from_interface.mode() == Type::Interface::MODE_NONE) { should_transmit = false; if (!from_interface) { - extreme("Blocking announce broadcast on " + interface.toString() + " since next hop interface doesn't exist"); + TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface doesn't exist"); } else if (from_interface.mode() == Type::Interface::MODE_NONE) { - extreme("Blocking announce broadcast on " + interface.toString() + " since next hop interface has no mode configured"); + TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface has no mode configured"); } } else { if (from_interface.mode() == Type::Interface::MODE_ROAMING) { - extreme("Blocking announce broadcast on " + interface.toString() + " due to roaming-mode next-hop interface"); + TRACE("Blocking announce broadcast on " + interface.toString() + " due to roaming-mode next-hop interface"); should_transmit = false; } } @@ -1007,19 +1007,19 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); //z timer.start() if (wait_time < 1000) { - extreme("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string((int)wait_time) + " ms"); + TRACE("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string((int)wait_time) + " ms"); } else { - extreme("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string(OS::round(wait_time/1000,1)) + " s"); + TRACE("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string(OS::round(wait_time/1000,1)) + " s"); } } else { double wait_time = std::max(interface.announce_allowed_at() - OS::time(), (double)0); if (wait_time < 1000) { - extreme("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string((int)wait_time) + " ms"); + TRACE("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string((int)wait_time) + " ms"); } else { - extreme("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string(OS::round(wait_time/1000,1)) + " s"); + TRACE("Added announce to queue (height " + std::to_string(interface.announce_queue().size()) + ") on " + interface.toString() + " for processing in " + std::to_string(OS::round(wait_time/1000,1)) + " s"); } } } @@ -1037,7 +1037,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } if (should_transmit) { - extreme("Transport::outbound: Packet transmission allowed"); + TRACE("Transport::outbound: Packet transmission allowed"); if (!stored_hash) { _packet_hashlist.insert(packet.packet_hash()); stored_hash = true; @@ -1058,7 +1058,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); sent = true; } else { - extreme("Transport::outbound: Packet transmission refused"); + TRACE("Transport::outbound: Packet transmission refused"); } } } @@ -1117,7 +1117,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (packet.destination_type() == Type::Destination::PLAIN) { if (packet.packet_type() != Type::Packet::ANNOUNCE) { if (packet.hops() > 1) { - debug("Dropped PLAIN packet " + packet.packet_hash().toHex() + " with " + std::to_string(packet.hops()) + " hops"); + DEBUG("Dropped PLAIN packet " + packet.packet_hash().toHex() + " with " + std::to_string(packet.hops()) + " hops"); return false; } else { @@ -1125,7 +1125,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } else { - debug("Dropped invalid PLAIN announce packet"); + DEBUG("Dropped invalid PLAIN announce packet"); return false; } } @@ -1133,7 +1133,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (packet.destination_type() == Type::Destination::GROUP) { if (packet.packet_type() != Type::Packet::ANNOUNCE) { if (packet.hops() > 1) { - debug("Dropped GROUP packet " + packet.packet_hash().toHex() + " with " + std::to_string(packet.hops()) + " hops"); + DEBUG("Dropped GROUP packet " + packet.packet_hash().toHex() + " with " + std::to_string(packet.hops()) + " hops"); return false; } else { @@ -1141,34 +1141,34 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } else { - debug("Dropped invalid GROUP announce packet"); + DEBUG("Dropped invalid GROUP announce packet"); return false; } } if (_packet_hashlist.find(packet.packet_hash()) == _packet_hashlist.end()) { - extreme("Transport::packet_filter: packet not previously seen"); + TRACE("Transport::packet_filter: packet not previously seen"); return true; } else { if (packet.packet_type() == Type::Packet::ANNOUNCE) { if (packet.destination_type() == Type::Destination::SINGLE) { - extreme("Transport::packet_filter: packet previously seen but is SINGLE ANNOUNCE"); + TRACE("Transport::packet_filter: packet previously seen but is SINGLE ANNOUNCE"); return true; } else { - debug("Dropped invalid announce packet"); + DEBUG("Dropped invalid announce packet"); return false; } } } - debug("Filtered packet with hash " + packet.packet_hash().toHex()); + DEBUG("Filtered packet with hash " + packet.packet_hash().toHex()); return false; } /*static*/ void Transport::inbound(const Bytes& raw, const Interface& interface /*= {Type::NONE}*/) { - extreme("Transport::inbound()"); + TRACE("Transport::inbound()"); ++_packets_received; // CBA if (_callbacks._receive_packet) { @@ -1176,7 +1176,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); _callbacks._receive_packet(raw, interface); } catch (std::exception& e) { - debug("Error while executing receive packet callback. The contained exception was: " + std::string(e.what())); + DEBUG("Error while executing receive packet callback. The contained exception was: " + std::string(e.what())); } } // TODO @@ -1248,7 +1248,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); */ while (_jobs_running) { - extreme("Transport::inbound: sleeping..."); + TRACE("Transport::inbound: sleeping..."); OS::sleep(0.0005); } @@ -1265,10 +1265,10 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); return; } #ifndef NDEBUG - extreme("Transport::inbound: packet: " + packet.debugString()); + TRACE("Transport::inbound: packet: " + packet.debugString()); #endif - extreme("Transport::inbound: destination=" + packet.destination_hash().toHex() + " hops=" + std::to_string(packet.hops())); + TRACE("Transport::inbound: destination=" + packet.destination_hash().toHex() + " hops=" + std::to_string(packet.hops())); packet.receiving_interface(interface); packet.hops(packet.hops() + 1); @@ -1313,14 +1313,14 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); accept = _callbacks._filter_packet(packet); } catch (std::exception& e) { - debug("Error while executing filter packet callback. The contained exception was: " + std::string(e.what())); + DEBUG("Error while executing filter packet callback. The contained exception was: " + std::string(e.what())); } } if (accept) { accept = packet_filter(packet); } if (accept) { - extreme("Transport::inbound: Packet accepted by filter"); + TRACE("Transport::inbound: Packet accepted by filter"); _packet_hashlist.insert(packet.packet_hash()); cache_packet(packet); @@ -1388,7 +1388,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); for (auto& [hash, interface] : _interfaces) { #endif if (interface != packet.receiving_interface()) { - extreme("Transport::inbound: Broadcasting packet on " + interface.toString()); + TRACE("Transport::inbound: Broadcasting packet on " + interface.toString()); #if defined(INTERFACES_SET) transmit(const_cast(interface), packet.raw()); #else @@ -1401,7 +1401,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // it directly to all local clients else { for (const Interface& interface : _local_client_interfaces) { - extreme("Transport::inbound: Broadcasting packet on " + interface.toString()); + TRACE("Transport::inbound: Broadcasting packet on " + interface.toString()); transmit(const_cast(interface), packet.raw()); } } @@ -1416,7 +1416,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // packets according to transport tables and recording // entries in reverse and link tables. if (Reticulum::transport_enabled() || from_local_client || for_local_client || for_local_client_link) { - extreme("Transport::inbound: Performing general transport handling"); + TRACE("Transport::inbound: Performing general transport handling"); // If there is no transport id, but the packet is // for a local client, we generate the transport @@ -1426,7 +1426,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // able), and reinsert, so the normal transport // implementation can handle the packet. if (!packet.transport_id() && for_local_client) { - extreme("Transport::inbound: Regenerating transport id"); + TRACE("Transport::inbound: Regenerating transport id"); packet.transport_id(_identity.hash()); } @@ -1435,7 +1435,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // normal processing. if (packet.context() == Type::Packet::CACHE_REQUEST) { if (cache_request_packet(packet)) { - extreme("Transport::inbound: Cached packet"); + TRACE("Transport::inbound: Cached packet"); return; } } @@ -1444,12 +1444,12 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // are the designated next hop, and process it // accordingly if we are. if (packet.transport_id() && packet.packet_type() != Type::Packet::ANNOUNCE) { - extreme("Transport::inbound: Packet is in transport..."); + TRACE("Transport::inbound: Packet is in transport..."); if (packet.transport_id() == _identity.hash()) { - extreme("Transport::inbound: We are designated next-hop"); + TRACE("Transport::inbound: We are designated next-hop"); auto destination_iter = _destination_table.find(packet.destination_hash()); if (destination_iter != _destination_table.end()) { - extreme("Transport::inbound: Found next-hop path to destination"); + TRACE("Transport::inbound: Found next-hop path to destination"); DestinationEntry destination_entry = (*destination_iter).second; Bytes next_hop = destination_entry._received_from; uint8_t remaining_hops = destination_entry._hops; @@ -1490,7 +1490,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); Interface outbound_interface = destination_entry.receiving_interface(); if (packet.packet_type() == Type::Packet::LINKREQUEST) { - extreme("Transport::inbound: Packet is next-hop LINKREQUEST"); + TRACE("Transport::inbound: Packet is next-hop LINKREQUEST"); double now = OS::time(); double proof_timeout = now + Type::Link::ESTABLISHMENT_TIMEOUT_PER_HOP * std::max((uint8_t)1, remaining_hops); LinkEntry link_entry( @@ -1507,7 +1507,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); _link_table.insert({packet.getTruncatedHash(), link_entry}); } else { - extreme("Transport::inbound: Packet is next-hop other type"); + TRACE("Transport::inbound: Packet is next-hop other type"); ReverseEntry reverse_entry( packet.receiving_interface(), outbound_interface, @@ -1515,7 +1515,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); ); _reverse_table.insert({packet.getTruncatedHash(), reverse_entry}); } - extreme("Transport::outbound: Sending packet to next hop..."); + TRACE("Transport::outbound: Sending packet to next hop..."); #if defined(INTERFACES_SET) transmit(const_cast(outbound_interface), new_raw); #else @@ -1527,24 +1527,24 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // TODO: There should probably be some kind of REJECT // mechanism here, to signal to the source that their // expected path failed. - extreme("Got packet in transport, but no known path to final destination " + packet.destination_hash().toHex() + ". Dropping packet."); + TRACE("Got packet in transport, but no known path to final destination " + packet.destination_hash().toHex() + ". Dropping packet."); } } else { - extreme("Transport::inbound: We are not designated next-hop so not transporting"); + TRACE("Transport::inbound: We are not designated next-hop so not transporting"); } } else { - extreme("Transport::inbound: Either packet is announce or packet has no next-hop (possibly for a local destination)"); + TRACE("Transport::inbound: Either packet is announce or packet has no next-hop (possibly for a local destination)"); } // Link transport handling. Directs packets according // to entries in the link tables if (packet.packet_type() != Type::Packet::ANNOUNCE && packet.packet_type() != Type::Packet::LINKREQUEST && packet.context() != Type::Packet::LRPROOF) { - extreme("Transport::inbound: Checking if packet is meant for link transport..."); + TRACE("Transport::inbound: Checking if packet is meant for link transport..."); auto link_iter = _link_table.find(packet.destination_hash()); if (link_iter != _link_table.end()) { - extreme("Transport::inbound: Found link entry, handling link transport"); + TRACE("Transport::inbound: Found link entry, handling link transport"); LinkEntry link_entry = (*link_iter).second; // If receiving and outbound interface is // the same for this link, direction doesn't @@ -1554,7 +1554,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // But check that taken hops matches one // of the expectede values. if (packet.hops() == link_entry._remaining_hops || packet.hops() == link_entry._hops) { - extreme("Transport::inbound: Link inbound/outbound interfaes are same, transporting on same interface"); + TRACE("Transport::inbound: Link inbound/outbound interfaes are same, transporting on same interface"); outbound_interface = link_entry._outbound_interface; } } @@ -1565,21 +1565,21 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (packet.receiving_interface() == link_entry._outbound_interface) { // Also check that expected hop count matches if (packet.hops() == link_entry._remaining_hops) { - extreme("Transport::inbound: Link transporting on inbound interface"); + TRACE("Transport::inbound: Link transporting on inbound interface"); outbound_interface = link_entry._receiving_interface; } } else if (packet.receiving_interface() == link_entry._receiving_interface) { // Also check that expected hop count matches if (packet.hops() == link_entry._hops) { - extreme("Transport::inbound: Link transporting on outbound interface"); + TRACE("Transport::inbound: Link transporting on outbound interface"); outbound_interface = link_entry._outbound_interface; } } } if (outbound_interface) { - extreme("Transport::inbound: Transmitting link transport packet"); + TRACE("Transport::inbound: Transmitting link transport packet"); Bytes new_raw; //new_raw = packet.raw[0:1] new_raw << packet.raw().left(1); @@ -1605,7 +1605,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // announces, queueing rebroadcasts of these, and removal // of queued announce rebroadcasts once handed to the next node. if (packet.packet_type() == Type::Packet::ANNOUNCE) { - extreme("Transport::inbound: Packet is ANNOUNCE"); + TRACE("Transport::inbound: Packet is ANNOUNCE"); Bytes received_from; //p local_destination = next((d for d in Transport.destinations if d.hash == packet.destination_hash), None) #if defined(DESTINATIONS_SET) @@ -1625,7 +1625,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); auto iter = _destinations.find(packet.destination_hash()); if (iter == _destinations.end() && Identity::validate_announce(packet)) { #endif - extreme("Transport::inbound: Packet is announce for non-local destination, processing..."); + TRACE("Transport::inbound: Packet is announce for non-local destination, processing..."); if (packet.transport_id()) { received_from = packet.transport_id(); @@ -1637,10 +1637,10 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); AnnounceEntry& announce_entry = (*_announce_table.find(packet.destination_hash())).second; if ((packet.hops() - 1) == announce_entry._hops) { - debug("Heard a local rebroadcast of announce for " + packet.destination_hash().toHex()); + DEBUG("Heard a local rebroadcast of announce for " + packet.destination_hash().toHex()); announce_entry._local_rebroadcasts += 1; if (announce_entry._local_rebroadcasts >= LOCAL_REBROADCASTS_MAX) { - debug("Max local rebroadcasts of announce for " + packet.destination_hash().toHex() + " reached, dropping announce from our table"); + DEBUG("Max local rebroadcasts of announce for " + packet.destination_hash().toHex() + " reached, dropping announce from our table"); _announce_table.erase(packet.destination_hash()); } } @@ -1648,7 +1648,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if ((packet.hops() - 1) == (announce_entry._hops + 1) && announce_entry._retries > 0) { double now = OS::time(); if (now < announce_entry._timestamp) { - debug("Rebroadcasted announce for " + packet.destination_hash().toHex() + " has been passed on to another node, no further tries needed"); + DEBUG("Rebroadcasted announce for " + packet.destination_hash().toHex() + " has been passed on to another node, no further tries needed"); _announce_table.erase(packet.destination_hash()); } } @@ -1734,7 +1734,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (random_blobs.find(random_blob) == random_blobs.end()) { // TODO: Check that this ^ approach actually // works under all circumstances - debug("Replacing destination table entry for " + packet.destination_hash().toHex() + " with new announce due to expired path"); + DEBUG("Replacing destination table entry for " + packet.destination_hash().toHex() + " with new announce due to expired path"); should_add = true; } else { @@ -1744,7 +1744,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); else { if (announce_emitted > path_announce_emitted) { if (random_blobs.find(random_blob) == random_blobs.end()) { - debug("Replacing destination table entry for " + packet.destination_hash().toHex() + " with new announce, since it was more recently emitted"); + DEBUG("Replacing destination table entry for " + packet.destination_hash().toHex() + " with new announce, since it was more recently emitted"); should_add = true; } else { @@ -1826,7 +1826,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // Insert announce into announce table for retransmission if (rate_blocked) { - debug("Blocking rebroadcast of announce from " + packet.destination_hash().toHex() + " due to excessive announce rate"); + DEBUG("Blocking rebroadcast of announce from " + packet.destination_hash().toHex() + " due to excessive announce rate"); } else { if (Transport::from_local_client(packet)) { @@ -1937,7 +1937,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); PathRequestEntry& pr_entry = (*iter).second; attached_interface = pr_entry._requesting_interface; - debug("Got matching announce, answering waiting discovery path request for " + packet.destination_hash().toHex() + " on " + attached_interface.toString()); + DEBUG("Got matching announce, answering waiting discovery path request for " + packet.destination_hash().toHex() + " on " + attached_interface.toString()); Identity announce_identity(Identity::recall(packet.destination_hash())); //Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, "unknown", "unknown"); //announce_destination.hash(packet.destination_hash()); @@ -1962,14 +1962,14 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } // CBA Culling before adding to esnure table does not exceed maxsize - extreme("Caching packet " + packet.get_hash().toHex()); + TRACE("Caching packet " + packet.get_hash().toHex()); if (RNS::Transport::cache_packet(packet, true)) { packet.cached(true); } - //extreme("Adding packet " + packet.get_hash().toHex() + " to packet table"); + //TRACE("Adding packet " + packet.get_hash().toHex() + " to packet table"); //PacketEntry packet_entry(packet); //_packet_table.insert({packet.get_hash(), packet_entry}); - extreme("Adding destination " + packet.destination_hash().toHex() + " to path table"); + TRACE("Adding destination " + packet.destination_hash().toHex() + " to path table"); DestinationEntry destination_table_entry( now, received_from, @@ -1987,9 +1987,9 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); cull_path_table(); } - debug("Destination " + packet.destination_hash().toHex() + " is now " + std::to_string(announce_hops) + " hops away via " + received_from.toHex() + " on " + packet.receiving_interface().toString()); - //extreme("Transport::inbound: Destination " + packet.destination_hash().toHex() + " has data: " + packet.data().toHex()); - //extreme("Transport::inbound: Destination " + packet.destination_hash().toHex() + " has text: " + packet.data().toString()); + DEBUG("Destination " + packet.destination_hash().toHex() + " is now " + std::to_string(announce_hops) + " hops away via " + received_from.toHex() + " on " + packet.receiving_interface().toString()); + //TRACE("Transport::inbound: Destination " + packet.destination_hash().toHex() + " has data: " + packet.data().toHex()); + //TRACE("Transport::inbound: Destination " + packet.destination_hash().toHex() + " has text: " + packet.data().toString()); // TODO /* @@ -2001,16 +2001,16 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); paths[packet.destination_hash] = destination_table_entry; expires = OS::time() + Transport::DESTINATION_TIMEOUT; tunnel_entry[3] = expires; - debug("Path to " + packet.destination_hash().toHex() + " associated with tunnel " + packet.receiving_interface().tunnel_id().toHex()); + DEBUG("Path to " + packet.destination_hash().toHex() + " associated with tunnel " + packet.receiving_interface().tunnel_id().toHex()); } */ // Call externally registered callbacks from apps // wanting to know when an announce arrives if (packet.context() != Type::Packet::PATH_RESPONSE) { - extreme("Transport::inbound: Not path response, sending to announce handler..."); + TRACE("Transport::inbound: Not path response, sending to announce handler..."); for (auto& handler : _announce_handlers) { - extreme("Transport::inbound: Checking filter of announce handler..."); + TRACE("Transport::inbound: Checking filter of announce handler..."); try { // Check that the announced destination matches // the handlers aspect filter @@ -2045,19 +2045,19 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } else { - extreme("Transport::inbound: Packet is announce for local destination, not processing"); + TRACE("Transport::inbound: Packet is announce for local destination, not processing"); } } else { - extreme("Transport::inbound: Packet is announce for local destination, not processing"); + TRACE("Transport::inbound: Packet is announce for local destination, not processing"); } } // Handling for link requests to local destinations else if (packet.packet_type() == Type::Packet::LINKREQUEST) { - extreme("Transport::inbound: Packet is LINKREQUEST"); + TRACE("Transport::inbound: Packet is LINKREQUEST"); if (!packet.transport_id() || packet.transport_id() == _identity.hash()) { - extreme("Transport::inbound: Checking if LINKREQUEST is for local destination"); + TRACE("Transport::inbound: Checking if LINKREQUEST is for local destination"); #if defined(DESTINATIONS_SET) for (auto& destination : _destinations) { if (destination.hash() == packet.destination_hash() && destination.type() == packet.destination_type()) { @@ -2082,13 +2082,13 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // Handling for data packets to local destinations else if (packet.packet_type() == Type::Packet::DATA) { - extreme("Transport::inbound: Packet is DATA"); + TRACE("Transport::inbound: Packet is DATA"); if (packet.destination_type() == Type::Destination::LINK) { // Data is destined for a link - extreme("Transport::inbound: Packet is DATA for a LINK"); + TRACE("Transport::inbound: Packet is DATA for a LINK"); for (auto& link : _active_links) { if (link.link_id() == packet.destination_hash()) { - extreme("Transport::inbound: Packet is DATA for an active LINK"); + TRACE("Transport::inbound: Packet is DATA for an active LINK"); packet.link(link); const_cast(link).receive(packet); } @@ -2103,10 +2103,10 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); auto iter = _destinations.find(packet.destination_hash()); if (iter != _destinations.end()) { // Data is for a local destination - debug("Packet destination " + packet.destination_hash().toHex() + " found, destination is local"); + DEBUG("Packet destination " + packet.destination_hash().toHex() + " found, destination is local"); auto& destination = (*iter).second; if (destination.type() == packet.destination_type()) { - extreme("Transport::inbound: Packet destination type " + std::to_string(packet.destination_type()) + " matched, processing"); + TRACE("Transport::inbound: Packet destination type " + std::to_string(packet.destination_type()) + " matched, processing"); #endif packet.destination(destination); #if defined(DESTINATIONS_SET) @@ -2132,20 +2132,20 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } else { - debug("Transport::inbound: Packet destination type " + std::to_string(packet.destination_type()) + " mismatch, ignoring"); + DEBUG("Transport::inbound: Packet destination type " + std::to_string(packet.destination_type()) + " mismatch, ignoring"); } } else { - debug("Transport::inbound: Local destination " + packet.destination_hash().toHex() + " not found, not handling packet locally"); + DEBUG("Transport::inbound: Local destination " + packet.destination_hash().toHex() + " not found, not handling packet locally"); } } } // Handling for proofs and link-request proofs else if (packet.packet_type() == Type::Packet::PROOF) { - extreme("Transport::inbound: Packet is PROOF"); + TRACE("Transport::inbound: Packet is PROOF"); if (packet.context() == Type::Packet::LRPROOF) { - extreme("Transport::inbound: Packet is LINK PROOF"); + TRACE("Transport::inbound: Packet is LINK PROOF"); // This is a link request proof, check if it // needs to be transported if ((Reticulum::transport_enabled() || for_local_client_link || from_local_client) && _link_table.find(packet.destination_hash()) != _link_table.end()) { @@ -2161,7 +2161,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); Bytes signature = packet.data().left(Type::Identity::SIGLENGTH/8); if (peer_identity.validate(signature, signed_data)) { - extreme("Link request proof validated for transport via " + link_entry._receiving_interface.toString()); + TRACE("Link request proof validated for transport via " + link_entry._receiving_interface.toString()); //p new_raw = packet.raw[0:1] Bytes new_raw = packet.raw().left(1); //p new_raw += struct.pack("!B", packet.hops) @@ -2172,7 +2172,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); transmit(link_entry._receiving_interface, new_raw); } else { - debug("Invalid link request proof in transport for link " + packet.destination_hash().toHex() + ", dropping proof."); + DEBUG("Invalid link request proof in transport for link " + packet.destination_hash().toHex() + ", dropping proof."); } } } @@ -2181,7 +2181,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } else { - debug("Link request proof received on wrong interface, not transporting it."); + DEBUG("Link request proof received on wrong interface, not transporting it."); } } else { @@ -2196,7 +2196,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } else if (packet.context() == Type::Packet::RESOURCE_PRF) { - extreme("Transport::inbound: Packet is RESOURCE PROOF"); + TRACE("Transport::inbound: Packet is RESOURCE PROOF"); for (auto& link : _active_links) { if (link.link_id() == packet.destination_hash()) { // TODO @@ -2205,7 +2205,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } else { - extreme("Transport::inbound: Packet is regular PROOF"); + TRACE("Transport::inbound: Packet is regular PROOF"); if (packet.destination_type() == Type::Destination::LINK) { for (auto& link : _active_links) { if (link.link_id() == packet.destination_hash()) { @@ -2223,7 +2223,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if ((Reticulum::transport_enabled() || from_local_client || proof_for_local_client) && _reverse_table.find(packet.destination_hash()) != _reverse_table.end()) { ReverseEntry reverse_entry = (*_reverse_table.find(packet.destination_hash())).second; if (packet.receiving_interface() == reverse_entry._outbound_interface) { - extreme("Proof received on correct interface, transporting it via " + reverse_entry._receiving_interface.toString()); + TRACE("Proof received on correct interface, transporting it via " + reverse_entry._receiving_interface.toString()); //p new_raw = packet.raw[0:1] Bytes new_raw = packet.raw().left(1); //p new_raw += struct.pack("!B", packet.hops) @@ -2233,11 +2233,11 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); transmit(reverse_entry._receiving_interface, new_raw); } else { - debug("Proof received on wrong interface, not transporting it."); + DEBUG("Proof received on wrong interface, not transporting it."); } } else { - extreme("Proof is not candidate for transporting"); + TRACE("Proof is not candidate for transporting"); } std::list cull_receipts; @@ -2383,7 +2383,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } /*static*/ void Transport::register_interface(Interface& interface) { - extreme("Transport: Registering interface " + interface.get_hash().toHex() + " " + interface.toString()); + TRACE("Transport: Registering interface " + interface.get_hash().toHex() + " " + interface.toString()); #if defined(INTERFACES_SET) _interfaces.insert(interface); #elif defined(INTERFACES_LIST) @@ -2395,12 +2395,12 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } /*static*/ void Transport::deregister_interface(const Interface& interface) { - extreme("Transport: Deregistering interface " + interface.toString()); + TRACE("Transport: Deregistering interface " + interface.toString()); #if defined(INTERFACES_SET) //for (auto iter = _interfaces.begin(); iter != _interfaces.end(); ++iter) { // if ((*iter).get() == interface) { // _interfaces.erase(iter); - // extreme("Transport::deregister_interface: Found and removed interface " + (*iter).get().toString()); + // TRACE("Transport::deregister_interface: Found and removed interface " + (*iter).get().toString()); // break; // } //} @@ -2408,28 +2408,28 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); auto iter = _interfaces.find(const_cast(interface)); if (iter != _interfaces.end()) { _interfaces.erase(iter); - extreme("Transport::deregister_interface: Found and removed interface " + (*iter).get().toString()); + TRACE("Transport::deregister_interface: Found and removed interface " + (*iter).get().toString()); } #elif defined(INTERFACES_LIST) for (auto iter = _interfaces.begin(); iter != _interfaces.end(); ++iter) { if ((*iter).get() == interface) { _interfaces.erase(iter); - extreme("Transport::deregister_interface: Found and removed interface " + (*iter).get().toString()); + TRACE("Transport::deregister_interface: Found and removed interface " + (*iter).get().toString()); break; } } #elif defined(INTERFACES_MAP) auto iter = _interfaces.find(interface.get_hash()); if (iter != _interfaces.end()) { - extreme("Transport::deregister_interface: Found and removed interface " + (*iter).second.toString()); + TRACE("Transport::deregister_interface: Found and removed interface " + (*iter).second.toString()); _interfaces.erase(iter); } #endif } /*static*/ void Transport::register_destination(Destination& destination) { - //extreme("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - extreme("Transport: Registering destination " + destination.toString()); + //TRACE("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + TRACE("Transport: Registering destination " + destination.toString()); destination.mtu(Type::Reticulum::MTU); if (destination.direction() == Type::Destination::IN) { #if defined(DESTINATIONS_SET) @@ -2453,13 +2453,13 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (_owner && _owner.is_connected_to_shared_instance()) { if (destination.type() == Type::Destination::SINGLE) { - extreme("Transport:register_destination: Announcing destination " + destination.toString()); + TRACE("Transport:register_destination: Announcing destination " + destination.toString()); destination.announce({}, true); } } } else { - extreme("Transport:register_destination: Skipping registration (not direction IN) of destination " + destination.toString()); + TRACE("Transport:register_destination: Skipping registration (not direction IN) of destination " + destination.toString()); } /* @@ -2468,24 +2468,24 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); #elif defined(DESTINATIONS_MAP) for (auto& [hash, destination] : _destinations) { #endif - extreme("Transport::register_destination: Listed destination " + destination.toString()); + TRACE("Transport::register_destination: Listed destination " + destination.toString()); } */ - //extreme("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + //TRACE("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } /*static*/ void Transport::deregister_destination(const Destination& destination) { - extreme("Transport: Deregistering destination " + destination.toString()); + TRACE("Transport: Deregistering destination " + destination.toString()); #if defined(DESTINATIONS_SET) if (_destinations.find(destination) != _destinations.end()) { _destinations.erase(destination); - extreme("Transport::deregister_destination: Found and removed destination " + destination.toString()); + TRACE("Transport::deregister_destination: Found and removed destination " + destination.toString()); } #elif defined(DESTINATIONS_MAP) auto iter = _destinations.find(destination.hash()); if (iter != _destinations.end()) { _destinations.erase(iter); - extreme("Transport::deregister_destination: Found and removed destination " + (*iter).second.toString()); + TRACE("Transport::deregister_destination: Found and removed destination " + (*iter).second.toString()); } #endif } @@ -2493,7 +2493,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); /*static*/ void Transport::register_link(const Link& link) { // TODO /* - extreme("Transport: Registering link " + link.toString()); + TRACE("Transport: Registering link " + link.toString()); if (link.initiator()) { _pending_links.insert(link); } @@ -2506,7 +2506,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); /*static*/ void Transport::activate_link(Link& link) { // TODO /* - extreme("Transport: Activating link " + link.toString()); + TRACE("Transport: Activating link " + link.toString()); if (_pending_links.find(link) != _pending_links.end()) { if (link.status() != Type::Link::ACTIVE) { throw std::runtime_error("Invalid link state for link activation: " + link.status_string()); @@ -2527,7 +2527,7 @@ Registers an announce handler. :param handler: Must be an object with an *aspect_filter* attribute and a *received_announce(destination_hash, announced_identity, app_data)* callable. See the :ref:`Announce Example` for more info. */ /*static*/ void Transport::register_announce_handler(HAnnounceHandler handler) { - extreme("Transport: Registering announce handler " + handler->aspect_filter()); + TRACE("Transport: Registering announce handler " + handler->aspect_filter()); _announce_handlers.insert(handler); } @@ -2537,10 +2537,10 @@ Deregisters an announce handler. :param handler: The announce handler to be deregistered. */ /*static*/ void Transport::deregister_announce_handler(HAnnounceHandler handler) { - extreme("Transport: Deregistering announce handler " + handler->aspect_filter()); + TRACE("Transport: Deregistering announce handler " + handler->aspect_filter()); if (_announce_handlers.find(handler) != _announce_handlers.end()) { _announce_handlers.erase(handler); - extreme("Transport::deregister_announce_handler: Found and removed handler" + handler->aspect_filter()); + TRACE("Transport::deregister_announce_handler: Found and removed handler" + handler->aspect_filter()); } } @@ -2548,21 +2548,21 @@ Deregisters an announce handler. #if defined(INTERFACES_SET) for (const Interface& interface : _interfaces) { if (interface.get_hash() == interface_hash) { - extreme("Transport::find_interface_from_hash: Found interface " + interface.toString()); + TRACE("Transport::find_interface_from_hash: Found interface " + interface.toString()); return interface; } } #elif defined(INTERFACES_LIST) for (Interface& interface : _interfaces) { if (interface.get_hash() == interface_hash) { - extreme("Transport::find_interface_from_hash: Found interface " + interface.toString()); + TRACE("Transport::find_interface_from_hash: Found interface " + interface.toString()); return interface; } } #elif defined(INTERFACES_MAP) auto iter = _interfaces.find(interface_hash); if (iter != _interfaces.end()) { - extreme("Transport::find_interface_from_hash: Found interface " + (*iter).second.toString()); + TRACE("Transport::find_interface_from_hash: Found interface " + (*iter).second.toString()); return (*iter).second; } #endif @@ -2586,9 +2586,9 @@ Deregisters an announce handler. // increased yet! Take note of this when reading from // the packet cache. /*static*/ bool Transport::cache_packet(const Packet& packet, bool force_cache /*= false*/) { - extreme("Checking to see if packet " + packet.get_hash().toHex() + " should be cached"); + TRACE("Checking to see if packet " + packet.get_hash().toHex() + " should be cached"); if (should_cache_packet(packet) || force_cache) { - extreme("Saving packet " + packet.get_hash().toHex() + " to storage"); + TRACE("Saving packet " + packet.get_hash().toHex() + " to storage"); try { std::string packet_cache_path = Reticulum::_cachepath + "/" + packet.get_hash().toHex(); return Persistence::serialize(packet, packet_cache_path.c_str()); @@ -2601,7 +2601,7 @@ Deregisters an announce handler. } /*static*/ Packet Transport::get_cached_packet(const Bytes& packet_hash) { - extreme("Loading packet " + packet_hash.toHex() + " from cache storage"); + TRACE("Loading packet " + packet_hash.toHex() + " from cache storage"); try { /*p packet_hash = RNS.hexrep(packet_hash, delimit=False) @@ -2638,17 +2638,17 @@ Deregisters an announce handler. } /*static*/ bool Transport::clear_cached_packet(const Bytes& packet_hash) { - extreme("Clearing packet " + packet_hash.toHex() + " from cache storage"); + TRACE("Clearing packet " + packet_hash.toHex() + " from cache storage"); try { std::string packet_cache_path = Reticulum::_cachepath + "/" + packet_hash.toHex(); double start_time = OS::time(); bool success = RNS::Utilities::OS::remove_file(packet_cache_path.c_str()); double diff_time = OS::time() - start_time; if (diff_time < 1.0) { - debug("Remove cached packet in " + std::to_string((int)(diff_time*1000)) + " ms"); + DEBUG("Remove cached packet in " + std::to_string((int)(diff_time*1000)) + " ms"); } else { - debug("Remove cached packet in " + std::to_string(diff_time) + " s"); + DEBUG("Remove cached packet in " + std::to_string(diff_time) + " s"); } } catch (std::exception& e) { @@ -2816,13 +2816,13 @@ will announce it. bool queued_announces = (on_interface.announce_queue().size() > 0); if (queued_announces) { - extreme("Blocking recursive path request on " + on_interface.toString() + " due to queued announces"); + TRACE("Blocking recursive path request on " + on_interface.toString() + " due to queued announces"); return; } else { double now = OS::time(); if (now < on_interface.announce_allowed_at()) { - extreme("Blocking recursive path request on " + on_interface.toString() + " due to active announce cap"); + TRACE("Blocking recursive path request on " + on_interface.toString() + " due to active announce cap"); return; } else { @@ -2846,14 +2846,14 @@ will announce it. } /*static*/ void Transport::path_request_handler(const Bytes& data, const Packet& packet) { - extreme("Transport::path_request_handler"); + TRACE("Transport::path_request_handler"); try { // If there is at least bytes enough for a destination // hash in the packet, we assume those bytes are the // destination being requested. if (data.size() >= Type::Identity::TRUNCATED_HASHLENGTH/8) { Bytes destination_hash = data.left(Type::Identity::TRUNCATED_HASHLENGTH/8); - //extreme("Transport::path_request_handler: destination_hash: " + destination_hash.toHex()); + //TRACE("Transport::path_request_handler: destination_hash: " + destination_hash.toHex()); // If there is also enough bytes for a transport // instance ID and at least one tag byte, we // assume the next bytes to be the trasport ID @@ -2861,7 +2861,7 @@ will announce it. Bytes requesting_transport_instance; if (data.size() > (Type::Identity::TRUNCATED_HASHLENGTH/8)*2) { requesting_transport_instance = data.mid(Type::Identity::TRUNCATED_HASHLENGTH/8, Type::Identity::TRUNCATED_HASHLENGTH/8); - //extreme("Transport::path_request_handler: requesting_transport_instance: " + requesting_transport_instance.toHex()); + //TRACE("Transport::path_request_handler: requesting_transport_instance: " + requesting_transport_instance.toHex()); } Bytes tag_bytes; @@ -2873,13 +2873,13 @@ will announce it. } if (tag_bytes) { - //extreme("Transport::path_request_handler: tag_bytes: " + tag_bytes.toHex()); + //TRACE("Transport::path_request_handler: tag_bytes: " + tag_bytes.toHex()); if (tag_bytes.size() > Type::Identity::TRUNCATED_HASHLENGTH/8) { tag_bytes = tag_bytes.left(Type::Identity::TRUNCATED_HASHLENGTH/8); } Bytes unique_tag = destination_hash + tag_bytes; - //extreme("Transport::path_request_handler: unique_tag: " + unique_tag.toHex()); + //TRACE("Transport::path_request_handler: unique_tag: " + unique_tag.toHex()); if (_discovery_pr_tags.find(unique_tag) == _discovery_pr_tags.end()) { _discovery_pr_tags.insert(unique_tag); @@ -2893,11 +2893,11 @@ will announce it. ); } else { - debug("Ignoring duplicate path request for " + destination_hash.toHex() + " with tag " + unique_tag.toHex()); + DEBUG("Ignoring duplicate path request for " + destination_hash.toHex() + " with tag " + unique_tag.toHex()); } } else { - debug("Ignoring tagless path request for " + destination_hash.toHex()); + DEBUG("Ignoring tagless path request for " + destination_hash.toHex()); } } } @@ -2907,26 +2907,26 @@ will announce it. } /*static*/ void Transport::path_request(const Bytes& destination_hash, bool is_from_local_client, const Interface& attached_interface, const Bytes& requestor_transport_id /*= {}*/, const Bytes& tag /*= {}*/) { - extreme("Transport::path_request"); + TRACE("Transport::path_request"); bool should_search_for_unknown = false; std::string interface_str; if (attached_interface) { if (Reticulum::transport_enabled() && (attached_interface.mode() & Interface::DISCOVER_PATHS_FOR) > 0) { - extreme("Transport::path_request_handler: interface allows searching for unknown paths"); + TRACE("Transport::path_request_handler: interface allows searching for unknown paths"); should_search_for_unknown = true; } interface_str = " on " + attached_interface.toString(); } - debug("Path request for destination " + destination_hash.toHex() + interface_str); + DEBUG("Path request for destination " + destination_hash.toHex() + interface_str); bool destination_exists_on_local_client = false; if (_local_client_interfaces.size() > 0) { auto iter = _destination_table.find(destination_hash); if (iter != _destination_table.end()) { - extreme("Transport::path_request_handler: entry found for destination " + destination_hash.toHex()); + TRACE("Transport::path_request_handler: entry found for destination " + destination_hash.toHex()); DestinationEntry& destination_entry = (*iter).second; if (is_local_client_interface(destination_entry.receiving_interface())) { destination_exists_on_local_client = true; @@ -2934,7 +2934,7 @@ will announce it. } } else { - extreme("Transport::path_request_handler: entry not found for destination " + destination_hash.toHex()); + TRACE("Transport::path_request_handler: entry not found for destination " + destination_hash.toHex()); } } @@ -2956,18 +2956,18 @@ will announce it. auto& local_destination = (*iter).second; #endif local_destination.announce({Bytes::NONE}, true, attached_interface, tag); - debug("Answering path request for destination " + destination_hash.toHex() + interface_str + ", destination is local to this system"); + DEBUG("Answering path request for destination " + destination_hash.toHex() + interface_str + ", destination is local to this system"); } //p elif (RNS.Reticulum.transport_enabled() or is_from_local_client) and (destination_hash in Transport.destination_table): else if ((Reticulum::transport_enabled() || is_from_local_client) && destination_iter != _destination_table.end()) { - extreme("Transport::path_request_handler: entry found for destination " + destination_hash.toHex()); + TRACE("Transport::path_request_handler: entry found for destination " + destination_hash.toHex()); DestinationEntry& destination_entry = (*destination_iter).second; const Packet& announce_packet = destination_entry.announce_packet(); const Bytes& next_hop = destination_entry._received_from; const Interface& receiving_interface = destination_entry.receiving_interface(); if (attached_interface.mode() == Type::Interface::MODE_ROAMING && attached_interface == receiving_interface) { - debug("Not answering path request on roaming-mode interface, since next hop is on same roaming-mode interface"); + DEBUG("Not answering path request on roaming-mode interface, since next hop is on same roaming-mode interface"); } else { if (requestor_transport_id && destination_entry._received_from == requestor_transport_id) { @@ -2977,10 +2977,10 @@ will announce it. // inefficient. There is probably a better way. Doing // path invalidation here would decrease the network // convergence time. Maybe just drop it? - debug("Not answering path request for destination " + destination_hash.toHex() + interface_str + ", since next hop is the requestor"); + DEBUG("Not answering path request for destination " + destination_hash.toHex() + interface_str + ", since next hop is the requestor"); } else { - debug("Answering path request for destination " + destination_hash.toHex() + interface_str + ", path is known"); + DEBUG("Answering path request for destination " + destination_hash.toHex() + interface_str + ", path is known"); double now = OS::time(); uint8_t retries = Type::Transport::PATHFINDER_R; @@ -3046,7 +3046,7 @@ will announce it. else if (is_from_local_client) { // Forward path request on all interfaces // except the local client - debug("Forwarding path request from local client for destination " + destination_hash.toHex() + interface_str + " to all other interfaces"); + DEBUG("Forwarding path request from local client for destination " + destination_hash.toHex() + interface_str + " to all other interfaces"); Bytes request_tag = Identity::get_random_hash(); #if defined(INTERFACES_SET) for (const Interface& interface : _interfaces) { @@ -3061,14 +3061,14 @@ will announce it. } } else if (should_search_for_unknown) { - extreme("Transport::path_request_handler: searching for unknown path to " + destination_hash.toHex()); + TRACE("Transport::path_request_handler: searching for unknown path to " + destination_hash.toHex()); if (_discovery_path_requests.find(destination_hash) != _discovery_path_requests.end()) { - debug("There is already a waiting path request for destination " + destination_hash.toHex() + " on behalf of path request" + interface_str); + DEBUG("There is already a waiting path request for destination " + destination_hash.toHex() + " on behalf of path request" + interface_str); } else { // Forward path request on all interfaces // except the requestor interface - debug("Attempting to discover unknown path to destination " + destination_hash.toHex() + " on behalf of path request" + interface_str); + DEBUG("Attempting to discover unknown path to destination " + destination_hash.toHex() + " on behalf of path request" + interface_str); //p pr_entry = { "destination_hash": destination_hash, "timeout": time.time()+Transport.PATH_REQUEST_TIMEOUT, "requesting_interface": attached_interface } //p _discovery_path_requests[destination_hash] = pr_entry; _discovery_path_requests.insert({destination_hash, { @@ -3088,13 +3088,13 @@ will announce it. // path-finding over LoRa mesh //if (interface != attached_interface) { if (true) { - extreme("Transport::path_request: requesting path on interface " + interface.toString()); + TRACE("Transport::path_request: requesting path on interface " + interface.toString()); // Use the previously extracted tag from this path request // on the new path requests as well, to avoid potential loops request_path(destination_hash, interface, tag, true); } else { - extreme("Transport::path_request: not requesting path on same interface " + interface.toString()); + TRACE("Transport::path_request: not requesting path on same interface " + interface.toString()); } } } @@ -3102,13 +3102,13 @@ will announce it. else if (!is_from_local_client && _local_client_interfaces.size() > 0) { // Forward the path request on all local // client interfaces - debug("Forwarding path request for destination " + destination_hash.toHex() + interface_str + " to local clients"); + DEBUG("Forwarding path request for destination " + destination_hash.toHex() + interface_str + " to local clients"); for (const Interface& interface : _local_client_interfaces) { request_path(destination_hash, interface); } } else { - debug("Ignoring path request for destination " + destination_hash.toHex() + interface_str + ", no path known"); + DEBUG("Ignoring path request for destination " + destination_hash.toHex() + interface_str + ", no path known"); } } @@ -3273,7 +3273,7 @@ will announce it. } /*static*/ bool Transport::read_path_table() { - debug("Transport::read_path_table"); + DEBUG("Transport::read_path_table"); std::string destination_table_path = Reticulum::_storagepath + "/destination_table"; if (!_owner.is_connected_to_shared_instance() && OS::file_exists(destination_table_path.c_str())) { /*p @@ -3313,31 +3313,31 @@ will announce it. */ try { -extreme("Transport::start: buffer capacity " + std::to_string(Persistence::_buffer.capacity()) + " bytes"); +TRACE("Transport::start: buffer capacity " + std::to_string(Persistence::_buffer.capacity()) + " bytes"); if (RNS::Utilities::OS::read_file(destination_table_path.c_str(), Persistence::_buffer) > 0) { - extreme("Transport::start: read: " + std::to_string(Persistence::_buffer.size()) + " bytes"); + TRACE("Transport::start: read: " + std::to_string(Persistence::_buffer.size()) + " bytes"); #ifndef NDEBUG // CBA DEBUG Dump path table -extreme("Transport::start: buffer addr: " + std::to_string((long)Persistence::_buffer.data())); -extreme("Transport::start: buffer size " + std::to_string(Persistence::_buffer.size()) + " bytes"); - //extreme("SERIALIZED: destination_table"); - //extreme(Persistence::_buffer.toString()); +TRACE("Transport::start: buffer addr: " + std::to_string((long)Persistence::_buffer.data())); +TRACE("Transport::start: buffer size " + std::to_string(Persistence::_buffer.size()) + " bytes"); + //TRACE("SERIALIZED: destination_table"); + //TRACE(Persistence::_buffer.toString()); #endif #ifdef USE_MSGPACK DeserializationError error = deserializeMsgPack(Persistence::_document, Persistence::_buffer.data()); #else DeserializationError error = deserializeJson(Persistence::_document, Persistence::_buffer.data()); #endif - extreme("Transport::start: doc size: " + std::to_string(Persistence::_buffer.size()) + " bytes"); + TRACE("Transport::start: doc size: " + std::to_string(Persistence::_buffer.size()) + " bytes"); if (!error) { _destination_table = Persistence::_document.as>(); - extreme("Transport::start: successfully deserialized path table with " + std::to_string(_destination_table.size()) + " entries"); + TRACE("Transport::start: successfully deserialized path table with " + std::to_string(_destination_table.size()) + " entries"); // Calculate crc for dirty-checking before write _destination_table_crc = crypto_crc8(0, Persistence::_buffer.data(), Persistence::_buffer.size()); std::vector invalid_paths; for (auto& [destination_hash, destination_entry] : _destination_table) { #ifndef NDEBUG - extreme("Transport::start: entry: " + destination_hash.toHex() + " = " + destination_entry.debugString()); + TRACE("Transport::start: entry: " + destination_hash.toHex() + " = " + destination_entry.debugString()); #endif // CBA TODO If announce packet load fails then remove destination entry (it's useless without announce packet) if (!destination_entry.announce_packet()) { @@ -3352,11 +3352,11 @@ extreme("Transport::start: buffer size " + std::to_string(Persistence::_buffer.s return true; } else { - extreme("Transport::start: failed to deserialize"); + TRACE("Transport::start: failed to deserialize"); } } else { - extreme("Transport::start: destination table read failed"); + TRACE("Transport::start: destination table read failed"); } verbose("Loaded " + std::to_string(_destination_table.size()) + " path table entries from storage"); @@ -3369,7 +3369,7 @@ extreme("Transport::start: buffer size " + std::to_string(Persistence::_buffer.s } /*static*/ bool Transport::write_path_table() { - debug("Transport::write_path_table"); + DEBUG("Transport::write_path_table"); //return false; if (Transport::_owner.is_connected_to_shared_instance()) { @@ -3393,7 +3393,7 @@ extreme("Transport::start: buffer size " + std::to_string(Persistence::_buffer.s try { _saving_path_table = true; double save_start = OS::time(); - debug("Saving " + std::to_string(_destination_table.size()) + " path table entries to storage..."); + DEBUG("Saving " + std::to_string(_destination_table.size()) + " path table entries to storage..."); /*p serialised_destinations = [] @@ -3440,19 +3440,19 @@ extreme("Transport::start: buffer size " + std::to_string(Persistence::_buffer.s { Persistence::_document.set(_destination_table); - extreme("Transport::write_path_table: doc size " + std::to_string(Persistence::_document.memoryUsage()) + " bytes"); + TRACE("Transport::write_path_table: doc size " + std::to_string(Persistence::_document.memoryUsage()) + " bytes"); //size_t size = 8192; size_t size = Persistence::_buffer.capacity(); -extreme("Transport::write_path_table: obtaining buffer size " + std::to_string(size) + " bytes"); +TRACE("Transport::write_path_table: obtaining buffer size " + std::to_string(size) + " bytes"); uint8_t* buffer = Persistence::_buffer.writable(size); -extreme("Transport::write_path_table: buffer addr: " + std::to_string((long)buffer)); +TRACE("Transport::write_path_table: buffer addr: " + std::to_string((long)buffer)); #ifdef USE_MSGPACK size_t length = serializeMsgPack(Persistence::_document, buffer, size); #else size_t length = serializeJson(Persistence::_document, buffer, size); #endif - extreme("Transport::write_path_table: serialized " + std::to_string(length) + " bytes"); + TRACE("Transport::write_path_table: serialized " + std::to_string(length) + " bytes"); if (length < size) { Persistence::_buffer.resize(length); } @@ -3460,46 +3460,46 @@ extreme("Transport::write_path_table: buffer addr: " + std::to_string((long)buff if (Persistence::_buffer.size() > 0) { #ifndef NDEBUG // CBA DEBUG Dump path table -extreme("Transport::write_path_table: buffer addr: " + std::to_string((long)Persistence::_buffer.data())); -extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence::_buffer.size()) + " bytes"); - //extreme("SERIALIZED: destination_table"); - //extreme(Persistence::_buffer.toString()); +TRACE("Transport::write_path_table: buffer addr: " + std::to_string((long)Persistence::_buffer.data())); +TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence::_buffer.size()) + " bytes"); + //TRACE("SERIALIZED: destination_table"); + //TRACE(Persistence::_buffer.toString()); #endif // Check crc to see if data has changed before writing uint8_t crc = crypto_crc8(0, Persistence::_buffer.data(), Persistence::_buffer.size()); if (_destination_table_crc > 0 && crc == _destination_table_crc) { - extreme("Transport::write_path_table: no change detected, skipping write"); + TRACE("Transport::write_path_table: no change detected, skipping write"); } else if (RNS::Utilities::OS::write_file(destination_table_path.c_str(), Persistence::_buffer) == Persistence::_buffer.size()) { - extreme("Transport::write_path_table: wrote " + std::to_string(_destination_table.size()) + " entries, " + std::to_string(Persistence::_buffer.size()) + " bytes"); + TRACE("Transport::write_path_table: wrote " + std::to_string(_destination_table.size()) + " entries, " + std::to_string(Persistence::_buffer.size()) + " bytes"); _destination_table_crc = crc; success = true; #ifndef NDEBUG // CBA DEBUG Dump path table - //extreme("FILE: destination_table"); + //TRACE("FILE: destination_table"); //if (OS::read_file("/destination_table", Persistence::_buffer) > 0) { - // extreme(Persistence::_buffer.toString()); + // TRACE(Persistence::_buffer.toString()); //} #endif } else { - extreme("Transport::write_path_table: write failed"); + TRACE("Transport::write_path_table: write failed"); } } else { - extreme("Transport::write_path_table: failed to serialize"); + TRACE("Transport::write_path_table: failed to serialize"); } if (success) { double save_time = OS::time() - save_start; if (save_time < 1.0) { - //debug("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string(OS::round(save_time * 1000, 1)) + " ms"); - debug("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string((int)(save_time*1000)) + " ms"); + //DEBUG("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string(OS::round(save_time * 1000, 1)) + " ms"); + DEBUG("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string((int)(save_time*1000)) + " ms"); } else { - //debug("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string(OS::round(save_time, 1)) + " s"); - debug("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string(save_time) + " s"); + //DEBUG("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string(OS::round(save_time, 1)) + " s"); + DEBUG("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string(save_time) + " s"); } } } @@ -3513,7 +3513,7 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence } /*static*/ void Transport::read_tunnel_table() { - debug("Transport::read_tunnel_table"); + DEBUG("Transport::read_tunnel_table"); // TODO /* tunnel_table_path = RNS.Reticulum.storagepath+"/tunnels" @@ -3647,18 +3647,18 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence } /*static*/ void Transport::persist_data() { - extreme("Transport::persist_data()"); + TRACE("Transport::persist_data()"); write_packet_hashlist(); write_path_table(); write_tunnel_table(); } /*static*/ void Transport::clean_caches() { - extreme("Transport::clean_caches()"); + TRACE("Transport::clean_caches()"); // CBA Remove cached packets no longer in path list std::list files = OS::list_directory(Reticulum::_cachepath.c_str()); for (auto& file : files) { - extreme("Transport::clean_caches: Checking for use of cached packet " + file); + TRACE("Transport::clean_caches: Checking for use of cached packet " + file); bool found = false; for (auto& [destination_hash, destination_entry] : _destination_table) { if (file.compare(destination_entry._announce_packet.toHex()) == 0) { @@ -3667,7 +3667,7 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence } } if (!found) { - extreme("Transport::clean_caches: Removing cached packet " + file); + TRACE("Transport::clean_caches: Removing cached packet " + file); std::string packet_cache_path = Reticulum::_cachepath + "/" + file; OS::remove_file(packet_cache_path.c_str()); } @@ -3691,39 +3691,39 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence // _discovery_pr_tags // _control_destinations // _control_hashes - extreme("preqs: " + std::to_string(_path_requests.size()) + " dpreqs: " + std::to_string(_discovery_path_requests.size()) + " ppreqs: " + std::to_string(_pending_local_path_requests.size()) + " dprt: " + std::to_string(_discovery_pr_tags.size()) + " cdsts: " + std::to_string(_control_destinations.size()) + " chshs: " + std::to_string(_control_hashes.size())); + TRACE("preqs: " + std::to_string(_path_requests.size()) + " dpreqs: " + std::to_string(_discovery_path_requests.size()) + " ppreqs: " + std::to_string(_pending_local_path_requests.size()) + " dprt: " + std::to_string(_discovery_pr_tags.size()) + " cdsts: " + std::to_string(_control_destinations.size()) + " chshs: " + std::to_string(_control_hashes.size())); // _packet_hashlist // _receipts // _link_table // _pending_links // _active_links // _tunnels - extreme("phl: " + std::to_string(_packet_hashlist.size()) + " rcp: " + std::to_string(_receipts.size()) + " lt: " + std::to_string(_link_table.size()) + " pl: " + std::to_string(_pending_links.size()) + " al: " + std::to_string(_active_links.size()) + " tun: " + std::to_string(_tunnels.size())); - extreme("pin: " + std::to_string(_packets_received) + " pout: " + std::to_string(_packets_sent) + " dadd: " + std::to_string(_destinations_added) + "\r\n"); + TRACE("phl: " + std::to_string(_packet_hashlist.size()) + " rcp: " + std::to_string(_receipts.size()) + " lt: " + std::to_string(_link_table.size()) + " pl: " + std::to_string(_pending_links.size()) + " al: " + std::to_string(_active_links.size()) + " tun: " + std::to_string(_tunnels.size())); + TRACE("pin: " + std::to_string(_packets_received) + " pout: " + std::to_string(_packets_sent) + " dadd: " + std::to_string(_destinations_added) + "\r\n"); #endif } /*static*/ void Transport::exit_handler() { - extreme("Transport::exit_handler()"); + TRACE("Transport::exit_handler()"); if (!_owner.is_connected_to_shared_instance()) { persist_data(); } } /*static*/ Destination Transport::find_destination_from_hash(const Bytes& destination_hash) { - extreme("Transport::find_destination_from_hash: Searching for destination " + destination_hash.toHex()); + TRACE("Transport::find_destination_from_hash: Searching for destination " + destination_hash.toHex()); #if defined(DESTINATIONS_SET) for (const Destination& destination : _destinations) { if (destination.get_hash() == destination_hash) { - extreme("Transport::find_destination_from_hash: Found destination " + destination.toString()); + TRACE("Transport::find_destination_from_hash: Found destination " + destination.toString()); return destination; } } #elif defined(DESTINATIONS_MAP) auto iter = _destinations.find(destination_hash); if (iter != _destinations.end()) { - extreme("Transport::find_destination_from_hash: Found destination " + (*iter).second.toString()); + TRACE("Transport::find_destination_from_hash: Found destination " + (*iter).second.toString()); return (*iter).second; } #endif @@ -3746,7 +3746,7 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence MapToValues(_destination_table, sorted_values); for (auto& destination_entry : sorted_values) { Packet announce_packet = destination_entry.announce_packet(); - extreme("Transport::cull_path_table: Removing destination " + announce_packet.destination_hash().toHex() + " from path table"); + TRACE("Transport::cull_path_table: Removing destination " + announce_packet.destination_hash().toHex() + " from path table"); // Remove destination from path table if (_destination_table.erase(announce_packet.destination_hash()) < 1) { warning("Failed to remove destination " + announce_packet.destination_hash().toHex() + " from path table"); @@ -3765,7 +3765,7 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence break; } } - debug("Removed " + std::to_string(count) + " path(s) from path table"); + DEBUG("Removed " + std::to_string(count) + " path(s) from path table"); */ uint16_t count = 0; std::vector> sorted_pairs; @@ -3779,7 +3779,7 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence }); // Iterate vector of sorted values for (auto& [destination_hash, destination_entry] : sorted_pairs) { - extreme("Transport::cull_path_table: Removing destination " + destination_hash.toHex() + " from path table"); + TRACE("Transport::cull_path_table: Removing destination " + destination_hash.toHex() + " from path table"); // Remove destination from path table if (_destination_table.erase(destination_hash) < 1) { warning("Failed to remove destination " + destination_hash.toHex() + " from path table"); @@ -3798,6 +3798,6 @@ extreme("Transport::write_path_table: buffer size " + std::to_string(Persistence break; } } - debug("Removed " + std::to_string(count) + " path(s) from path table"); + DEBUG("Removed " + std::to_string(count) + " path(s) from path table"); } } \ No newline at end of file diff --git a/src/Utilities/OS.cpp b/src/Utilities/OS.cpp index e3a18bd..614ea17 100644 --- a/src/Utilities/OS.cpp +++ b/src/Utilities/OS.cpp @@ -19,12 +19,12 @@ using namespace RNS::Utilities; /*static*/ uint64_t OS::timeOffset = 0; /*static*/ void OS::register_filesystem(Filesystem& filesystem) { - extreme("Registering filesystem..."); + TRACE("Registering filesystem..."); OS::filesystem = filesystem; } /*static*/ void OS::deregister_filesystem() { - extreme("Deregistering filesystem..."); + TRACE("Deregistering filesystem..."); OS::filesystem = {Type::NONE}; } diff --git a/src/Utilities/Persistence.h b/src/Utilities/Persistence.h index 391ad1c..c3a4609 100644 --- a/src/Utilities/Persistence.h +++ b/src/Utilities/Persistence.h @@ -122,15 +122,15 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - RNS::extreme("<<< Serializing interface hash " + src.get_hash().toHex()); + TRACE("<<< Serializing interface hash " + src.get_hash().toHex()); return dst.set(src.get_hash().toHex()); } static RNS::Interface fromJson(JsonVariantConst src) { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - RNS::extreme(">>> Deserialized interface hash " + hash.toHex()); - RNS::extreme(">>> Querying transport for interface"); + TRACE(">>> Deserialized interface hash " + hash.toHex()); + TRACE(">>> Querying transport for interface"); // Query transport for matching interface return RNS::Transport::find_interface_from_hash(hash); } @@ -152,7 +152,7 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - RNS::extreme("<<< Serializing packet hash " + src.get_hash().toHex()); + TRACE("<<< Serializing packet hash " + src.get_hash().toHex()); // Whenever a reference to a packet is serialized we must ensure that packet itself also gets serialized separately RNS::Transport::cache_packet(src, true); return dst.set(src.get_hash().toHex()); @@ -161,8 +161,8 @@ namespace ArduinoJson { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - RNS::extreme(">>> Deserialized packet hash " + hash.toHex()); - RNS::extreme(">>> Querying transport for cached packet"); + TRACE(">>> Deserialized packet hash " + hash.toHex()); + TRACE(">>> Querying transport for cached packet"); // Query transport for matching packet return RNS::Transport::get_cached_packet(hash); } @@ -179,16 +179,16 @@ namespace ArduinoJson { template <> struct Converter { static bool toJson(const RNS::Packet& src, JsonVariant dst) { - RNS::extreme("<<< Serializing Packet"); + TRACE("<<< Serializing Packet"); //dst["hash"] = src.get_hash(); dst["raw"] = src.raw(); dst["sent_at"] = src.sent_at(); dst["destination_hash"] = src.get_hash(); - RNS::extreme("<<< Finished serializing Packet"); + TRACE("<<< Finished serializing Packet"); return true; } static RNS::Packet fromJson(JsonVariantConst src) { - RNS::extreme(">>> Deserializing Packet"); + TRACE(">>> Deserializing Packet"); RNS::Bytes raw = src["raw"]; RNS::Packet packet( {RNS::Type::NONE}, @@ -199,7 +199,7 @@ namespace ArduinoJson { RNS::Bytes destination_hash = src["destination_hash"]; // set cached flag since pcket was read from cache packet.cached(true); - RNS::extreme(">>> Finished deserializing Packet"); + TRACE(">>> Finished deserializing Packet"); return packet; } static bool checkJson(JsonVariantConst src) { @@ -215,16 +215,16 @@ namespace ArduinoJson { template <> struct Converter { static bool toJson(const RNS::Transport::PacketEntry& src, JsonVariant dst) { - RNS::extreme("<<< Serializing Transport::PacketEntry"); + TRACE("<<< Serializing Transport::PacketEntry"); //dst["hash"] = src._hash; dst["raw"] = src._raw; dst["sent_at"] = src._sent_at; dst["destination_hash"] = src._destination_hash; - RNS::extreme("<<< Finished serializing Transport::PacketEntry"); + TRACE("<<< Finished serializing Transport::PacketEntry"); return true; } static RNS::Transport::PacketEntry fromJson(JsonVariantConst src) { - RNS::extreme(">>> Deserializing Transport::PacketEntry"); + TRACE(">>> Deserializing Transport::PacketEntry"); RNS::Transport::PacketEntry dst; //dst._hash = src["hash"]; dst._raw = src["raw"]; @@ -232,7 +232,7 @@ namespace ArduinoJson { dst._destination_hash = src["destination_hash"]; // set cached flag since pcket was read from cache dst._cached = true; - RNS::extreme(">>> Finished deserializing Transport::PacketEntry"); + TRACE(">>> Finished deserializing Transport::PacketEntry"); return dst; } static bool checkJson(JsonVariantConst src) { @@ -248,7 +248,7 @@ namespace ArduinoJson { template <> struct Converter { static bool toJson(const RNS::Transport::DestinationEntry& src, JsonVariant dst) { - RNS::extreme("<<< Serializing Transport::DestinationEntry"); + TRACE("<<< Serializing Transport::DestinationEntry"); dst["timestamp"] = src._timestamp; dst["received_from"] = src._received_from; dst["announce_hops"] = src._hops; @@ -275,7 +275,7 @@ namespace ArduinoJson { } } else { - RNS::extreme("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached"); + TRACE("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached"); } } else { @@ -284,11 +284,11 @@ namespace ArduinoJson { */ dst["interface_hash"] = src._receiving_interface; dst["packet_hash"] = src._announce_packet; - RNS::extreme("<<< Finished Serializing Transport::DestinationEntry"); + TRACE("<<< Finished Serializing Transport::DestinationEntry"); return true; } static RNS::Transport::DestinationEntry fromJson(JsonVariantConst src) { - RNS::extreme(">>> Deserializing Transport::DestinationEntry"); + TRACE(">>> Deserializing Transport::DestinationEntry"); RNS::Transport::DestinationEntry dst; dst._timestamp = src["timestamp"]; dst._received_from = src["received_from"]; @@ -323,7 +323,7 @@ namespace ArduinoJson { src["packet"].as() ); */ - RNS::extreme(">>> Finished Deserializing Transport::DestinationEntry"); + TRACE(">>> Finished Deserializing Transport::DestinationEntry"); return dst; } static bool checkJson(JsonVariantConst src) { @@ -356,42 +356,42 @@ namespace RNS { namespace Persistence { if (length < size) { _buffer.resize(length); } - RNS::extreme("Persistence::serialize: serialized " + std::to_string(length) + " bytes"); + TRACE("Persistence::serialize: serialized " + std::to_string(length) + " bytes"); if (length > 0) { if (RNS::Utilities::OS::write_file(file_path, _buffer) == _buffer.size()) { - RNS::extreme("Persistence::serialize: wrote " + std::to_string(_buffer.size()) + " bytes"); + TRACE("Persistence::serialize: wrote " + std::to_string(_buffer.size()) + " bytes"); } else { - RNS::extreme("Persistence::serialize: write failed"); + TRACE("Persistence::serialize: write failed"); return false; } } else { - RNS::extreme("Persistence::serialize: failed to serialize"); + TRACE("Persistence::serialize: failed to serialize"); return false; } return true; } template bool deserialize(T& obj, const char* file_path) { if (RNS::Utilities::OS::read_file(file_path, _buffer) > 0) { - RNS::extreme("Persistence::deserialize: read: " + std::to_string(_buffer.size()) + " bytes"); - //RNS::extreme("testDeserializeVector: data: " + _buffer.toString()); + TRACE("Persistence::deserialize: read: " + std::to_string(_buffer.size()) + " bytes"); + //TRACE("testDeserializeVector: data: " + _buffer.toString()); #ifdef USE_MSGPACK DeserializationError error = deserializeMsgPack(_document, _buffer.data()); #else DeserializationError error = deserializeJson(_document, _buffer.data()); #endif if (!error) { - RNS::extreme("Persistence::deserialize: successfully deserialized"); + TRACE("Persistence::deserialize: successfully deserialized"); obj = _document.as(); return true; } else { - RNS::extreme("Persistence::deserialize: failed to deserialize"); + TRACE("Persistence::deserialize: failed to deserialize"); } } else { - RNS::extreme("Persistence::deserialize: read failed"); + TRACE("Persistence::deserialize: read failed"); } return false;; }