From 36ff1c5f002b54139b7dca5088bdaf6224ff8f81 Mon Sep 17 00:00:00 2001 From: Chad Attermann Date: Wed, 3 Jul 2024 11:30:01 -0600 Subject: [PATCH] WIP: Refactored logging to use macros --- examples/lora/LoRaInterface.cpp | 8 +-- examples/lora/main.cpp | 76 ++++++++++++++-------------- examples/main.cpp | 84 +++++++++++++++---------------- examples/test/Filesystem.cpp | 38 +++++++------- examples/test/TestBytes.cpp | 2 +- examples/test/TestCollections.cpp | 2 +- examples/test/TestCrypto.cpp | 2 +- examples/test/TestFilesystem.cpp | 10 ++-- examples/test/TestOS.cpp | 2 +- examples/test/TestPersistence.cpp | 2 +- examples/test/TestReference.cpp | 14 +++--- examples/test/TestReticulum.cpp | 2 +- examples/test/main.cpp | 8 +-- examples/udp/UDPInterface.cpp | 12 ++--- examples/udp/main.cpp | 76 ++++++++++++++-------------- src/Bytes.cpp | 8 +-- src/Cryptography/Fernet.cpp | 2 +- src/Identity.cpp | 30 +++++------ src/Log.cpp | 6 +-- src/Log.h | 22 +++++--- src/Packet.cpp | 14 +++--- src/Reticulum.cpp | 18 +++---- src/Transport.cpp | 82 +++++++++++++++--------------- src/Utilities/OS.cpp | 2 +- 24 files changed, 265 insertions(+), 257 deletions(-) diff --git a/examples/lora/LoRaInterface.cpp b/examples/lora/LoRaInterface.cpp index 18fd09d..7522193 100644 --- a/examples/lora/LoRaInterface.cpp +++ b/examples/lora/LoRaInterface.cpp @@ -37,7 +37,7 @@ LoRaInterface::LoRaInterface(const char* name /*= "LoRaInterface"*/) : Interface bool LoRaInterface::start() { online(false); - info("LoRa initializing..."); + INFO("LoRa initializing..."); #ifdef ARDUINO SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN); @@ -47,7 +47,7 @@ bool LoRaInterface::start() { // initialize radio if (!LoRa.begin(frequency)) { - error("LoRa init failed. Check your connections."); + ERROR("LoRa init failed. Check your connections."); return false; } @@ -57,7 +57,7 @@ bool LoRaInterface::start() { LoRa.setPreambleLength(20); LoRa.setTxPower(power); - info("LoRa init succeeded."); + INFO("LoRa init succeeded."); TRACE("LoRa bandwidth is " + std::to_string(Utilities::OS::round(bitrate()/1000.0, 2)) + " Kbps"); #endif @@ -137,6 +137,6 @@ void LoRaInterface::loop() { Interface::on_outgoing(data); } catch (std::exception& e) { - error("Could not transmit on " + toString() + ". The contained exception was: " + e.what()); + ERROR("Could not transmit on " + toString() + ". The contained exception was: " + e.what()); } } diff --git a/examples/lora/main.cpp b/examples/lora/main.cpp index f1ff998..deeb32d 100644 --- a/examples/lora/main.cpp +++ b/examples/lora/main.cpp @@ -53,35 +53,35 @@ public: ExampleAnnounceHandler(const char* aspect_filter = nullptr) : AnnounceHandler(aspect_filter) {} virtual ~ExampleAnnounceHandler() {} virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); if (announced_identity) { - RNS::info("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); - RNS::info("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); + INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); + INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); } if (app_data) { - RNS::info("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); + INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); } - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } }; // Test packet receive callback void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("onPacket: data: " + data.toHex()); - RNS::info("onPacket: text: \"" + data.toString() + "\""); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("onPacket: data: " + data.toHex()); + INFO("onPacket: text: \"" + data.toString() + "\""); //TRACE("onPacket: " + packet.debugString()); - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } // Ping packet receive callback void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("onPingPacket: data: " + data.toHex()); - RNS::info("onPingPacket: text: \"" + data.toString() + "\""); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("onPingPacket: data: " + data.toHex()); + INFO("onPingPacket: text: \"" + data.toString() + "\""); //TRACE("onPingPacket: " + packet.debugString()); - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -97,7 +97,7 @@ RNS::HAnnounceHandler announce_handler(new ExampleAnnounceHandler()); void reticulum_announce() { if (destination) { - RNS::head("Announcing destination...", RNS::LOG_EXTREME); + HEAD("Announcing destination...", RNS::LOG_TRACE); //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7])); // test path //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]), true, nullptr, RNS::bytesFromString("test_tag")); @@ -107,7 +107,7 @@ void reticulum_announce() { } void reticulum_setup() { - RNS::info("Setting up Reticulum..."); + INFO("Setting up Reticulum..."); try { @@ -119,14 +119,14 @@ void reticulum_setup() { // 21.8% baseline here with serial - RNS::head("Registering Interface instances with Transport...", RNS::LOG_EXTREME); + HEAD("Registering Interface instances with Transport...", RNS::LOG_TRACE); lora_interface.mode(RNS::Type::Interface::MODE_GATEWAY); RNS::Transport::register_interface(lora_interface); - RNS::head("Starting LoRaInterface...", RNS::LOG_EXTREME); + HEAD("Starting LoRaInterface...", RNS::LOG_TRACE); lora_interface.start(); - RNS::head("Creating Reticulum instance...", RNS::LOG_EXTREME); + HEAD("Creating Reticulum instance...", RNS::LOG_TRACE); //RNS::Reticulum reticulum; reticulum = RNS::Reticulum(); reticulum.transport_enabled(true); @@ -134,7 +134,7 @@ void reticulum_setup() { //return; // 21.9% (+0.1%) - RNS::head("Creating Identity instance...", RNS::LOG_EXTREME); + HEAD("Creating Identity instance...", RNS::LOG_TRACE); // new identity //RNS::Identity identity; //identity = RNS::Identity(); @@ -150,31 +150,31 @@ void reticulum_setup() { identity.load_private_key(prv_bytes); // 22.6% (+0.7%) - RNS::head("Creating Destination instance...", RNS::LOG_EXTREME); + HEAD("Creating Destination instance...", RNS::LOG_TRACE); //RNS::Destination destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "app", "aspects"); destination = RNS::Destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "app", "aspects"); // 23.0% (+0.4%) // Register DATA packet callback - RNS::head("Registering packet callback with Destination...", RNS::LOG_EXTREME); + HEAD("Registering packet callback with Destination...", RNS::LOG_TRACE); destination.set_packet_callback(onPacket); destination.set_proof_strategy(RNS::Type::Destination::PROVE_ALL); { // Register PING packet callback - RNS::head("Creating PING Destination instance...", RNS::LOG_EXTREME); + HEAD("Creating PING Destination instance...", RNS::LOG_TRACE); RNS::Destination ping_destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "example_utilities", "echo.request"); - RNS::head("Registering packet callback with PING Destination...", RNS::LOG_EXTREME); + HEAD("Registering packet callback with PING Destination...", RNS::LOG_TRACE); ping_destination.set_packet_callback(onPingPacket); ping_destination.set_proof_strategy(RNS::Type::Destination::PROVE_ALL); } - RNS::head("Registering announce handler with Transport...", RNS::LOG_EXTREME); + HEAD("Registering announce handler with Transport...", RNS::LOG_TRACE); RNS::Transport::register_announce_handler(announce_handler); /* - RNS::head("Announcing destination...", RNS::LOG_EXTREME); + HEAD("Announcing destination...", RNS::LOG_TRACE); //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7])); // test path //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]), true, nullptr, RNS::bytesFromString("test_tag")); @@ -185,49 +185,49 @@ void reticulum_setup() { #if defined (RETICULUM_PACKET_TEST) // test data send packet - RNS::head("Creating send packet...", RNS::LOG_EXTREME); + HEAD("Creating send packet...", RNS::LOG_TRACE); RNS::Packet send_packet(destination, "The quick brown fox jumps over the lazy dog"); - RNS::head("Sending send packet...", RNS::LOG_EXTREME); + HEAD("Sending send packet...", RNS::LOG_TRACE); send_packet.pack(); #ifndef NDEBUG TRACE("Test send_packet: " + send_packet.debugString()); #endif - RNS::head("Creating recv packet...", RNS::LOG_EXTREME); + HEAD("Creating recv packet...", RNS::LOG_TRACE); RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw()); recv_packet.unpack(); #ifndef NDEBUG TRACE("Test recv_packet: " + recv_packet.debugString()); #endif - RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME); + HEAD("Spoofing recv packet to destination...", RNS::LOG_TRACE); destination.receive(recv_packet); #endif - RNS::head("Ready!", RNS::LOG_EXTREME); + HEAD("Ready!", RNS::LOG_TRACE); } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in reticulum_setup: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in reticulum_setup: ") + e.what() + " !!!"); } } void reticulum_teardown() { - RNS::info("Tearing down Reticulum..."); + INFO("Tearing down Reticulum..."); RNS::Transport::save_path_table(); try { - RNS::head("Deregistering announce handler with Transport...", RNS::LOG_EXTREME); + HEAD("Deregistering announce handler with Transport...", RNS::LOG_TRACE); RNS::Transport::deregister_announce_handler(announce_handler); - RNS::head("Deregistering Interface instances with Transport...", RNS::LOG_EXTREME); + HEAD("Deregistering Interface instances with Transport...", RNS::LOG_TRACE); RNS::Transport::deregister_interface(lora_interface); } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in reticulum_teardown: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in reticulum_teardown: ") + e.what() + " !!!"); } } @@ -254,14 +254,14 @@ void setup() { // Setup filesystem if (!SPIFFS.begin(true, "")){ - RNS::error("SPIFFS filesystem mount failed"); + ERROR("SPIFFS filesystem mount failed"); } else { DEBUG("SPIFFS filesystem is ready"); } #endif - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); //RNS::loglevel(RNS::LOG_MEM); /* diff --git a/examples/main.cpp b/examples/main.cpp index c99935e..5cede19 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -65,35 +65,35 @@ public: ExampleAnnounceHandler(const char* aspect_filter = nullptr) : AnnounceHandler(aspect_filter) {} virtual ~ExampleAnnounceHandler() {} virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); if (announced_identity) { - RNS::info("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); - RNS::info("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); + INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); + INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); } if (app_data) { - RNS::info("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); + INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); } - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } }; // Test packet receive callback void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("onPacket: data: " + data.toHex()); - RNS::info("onPacket: text: \"" + data.toString() + "\""); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("onPacket: data: " + data.toHex()); + INFO("onPacket: text: \"" + data.toString() + "\""); //TRACE("onPacket: " + packet.debugString()); - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } // Ping packet receive callback void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("onPingPacket: data: " + data.toHex()); - RNS::info("onPingPacket: text: \"" + data.toString() + "\""); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("onPingPacket: data: " + data.toHex()); + INFO("onPingPacket: text: \"" + data.toString() + "\""); //TRACE("onPingPacket: " + packet.debugString()); - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -125,7 +125,7 @@ void run_tests() { TRACE("Running tests..."); RNS::LogLevel loglevel = RNS::loglevel(); //RNS::loglevel(RNS::LOG_WARNING); - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); //test(); //testReference(); //testCrypto(); @@ -135,7 +135,7 @@ void run_tests() { //return; } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in test: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in test: ") + e.what() + " !!!"); } } @@ -144,7 +144,7 @@ void run_tests() { #if defined(RUN_RETICULUM) void reticulum_announce() { if (destination) { - RNS::head("Announcing destination...", RNS::LOG_EXTREME); + HEAD("Announcing destination...", RNS::LOG_TRACE); //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7])); // test path //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]), true, nullptr, RNS::bytesFromString("test_tag")); @@ -154,7 +154,7 @@ void reticulum_announce() { } void reticulum_setup() { - RNS::info("Setting up Reticulum..."); + INFO("Setting up Reticulum..."); try { @@ -166,7 +166,7 @@ void reticulum_setup() { // 21.8% baseline here with serial - RNS::head("Registering Interface instances with Transport...", RNS::LOG_EXTREME); + HEAD("Registering Interface instances with Transport...", RNS::LOG_TRACE); #ifdef UDP_INTERFACE udp_interface.mode(RNS::Type::Interface::MODE_GATEWAY); RNS::Transport::register_interface(udp_interface); @@ -181,19 +181,19 @@ void reticulum_setup() { #endif #ifdef UDP_INTERFACE - RNS::head("Starting UDPInterface...", RNS::LOG_EXTREME); + HEAD("Starting UDPInterface...", RNS::LOG_TRACE); udp_interface.start("wifi_ssid", "wifi_password", 4242); #endif #ifdef UDP2_INTERFACE - RNS::head("Starting UDPInterface...", RNS::LOG_EXTREME); + HEAD("Starting UDPInterface...", RNS::LOG_TRACE); udp_interface.start("wifi_ssid", "wifi_password", 2424); #endif #ifdef LORA_INTERFACE - RNS::head("Starting LoRaInterface...", RNS::LOG_EXTREME); + HEAD("Starting LoRaInterface...", RNS::LOG_TRACE); lora_interface.start(); #endif - RNS::head("Creating Reticulum instance...", RNS::LOG_EXTREME); + HEAD("Creating Reticulum instance...", RNS::LOG_TRACE); //RNS::Reticulum reticulum; reticulum = RNS::Reticulum(); reticulum.transport_enabled(true); @@ -201,7 +201,7 @@ void reticulum_setup() { //return; // 21.9% (+0.1%) - RNS::head("Creating Identity instance...", RNS::LOG_EXTREME); + HEAD("Creating Identity instance...", RNS::LOG_TRACE); // new identity //RNS::Identity identity; //identity = RNS::Identity(); @@ -217,31 +217,31 @@ void reticulum_setup() { identity.load_private_key(prv_bytes); // 22.6% (+0.7%) - RNS::head("Creating Destination instance...", RNS::LOG_EXTREME); + HEAD("Creating Destination instance...", RNS::LOG_TRACE); //RNS::Destination destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "app", "aspects"); destination = RNS::Destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "app", "aspects"); // 23.0% (+0.4%) // Register DATA packet callback - RNS::head("Registering packet callback with Destination...", RNS::LOG_EXTREME); + HEAD("Registering packet callback with Destination...", RNS::LOG_TRACE); destination.set_packet_callback(onPacket); destination.set_proof_strategy(RNS::Type::Destination::PROVE_ALL); { // Register PING packet callback - RNS::head("Creating PING Destination instance...", RNS::LOG_EXTREME); + HEAD("Creating PING Destination instance...", RNS::LOG_TRACE); RNS::Destination ping_destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "example_utilities", "echo.request"); - RNS::head("Registering packet callback with PING Destination...", RNS::LOG_EXTREME); + HEAD("Registering packet callback with PING Destination...", RNS::LOG_TRACE); ping_destination.set_packet_callback(onPingPacket); ping_destination.set_proof_strategy(RNS::Type::Destination::PROVE_ALL); } - RNS::head("Registering announce handler with Transport...", RNS::LOG_EXTREME); + HEAD("Registering announce handler with Transport...", RNS::LOG_TRACE); RNS::Transport::register_announce_handler(announce_handler); /* - RNS::head("Announcing destination...", RNS::LOG_EXTREME); + HEAD("Announcing destination...", RNS::LOG_TRACE); //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7])); // test path //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]), true, nullptr, RNS::bytesFromString("test_tag")); @@ -252,44 +252,44 @@ void reticulum_setup() { #if defined (RETICULUM_PACKET_TEST) // test data send packet - RNS::head("Creating send packet...", RNS::LOG_EXTREME); + HEAD("Creating send packet...", RNS::LOG_TRACE); RNS::Packet send_packet(destination, "The quick brown fox jumps over the lazy dog"); - RNS::head("Sending send packet...", RNS::LOG_EXTREME); + HEAD("Sending send packet...", RNS::LOG_TRACE); send_packet.pack(); #ifndef NDEBUG TRACE("Test send_packet: " + send_packet.debugString()); #endif - RNS::head("Creating recv packet...", RNS::LOG_EXTREME); + HEAD("Creating recv packet...", RNS::LOG_TRACE); RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw()); recv_packet.unpack(); #ifndef NDEBUG TRACE("Test recv_packet: " + recv_packet.debugString()); #endif - RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME); + HEAD("Spoofing recv packet to destination...", RNS::LOG_TRACE); destination.receive(recv_packet); #endif - RNS::head("Ready!", RNS::LOG_EXTREME); + HEAD("Ready!", RNS::LOG_TRACE); } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in reticulum_setup: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in reticulum_setup: ") + e.what() + " !!!"); } } void reticulum_teardown() { - RNS::info("Tearing down Reticulum..."); + INFO("Tearing down Reticulum..."); RNS::Transport::save_path_table(); try { - RNS::head("Deregistering announce handler with Transport...", RNS::LOG_EXTREME); + HEAD("Deregistering announce handler with Transport...", RNS::LOG_TRACE); RNS::Transport::deregister_announce_handler(announce_handler); - RNS::head("Deregistering Interface instances with Transport...", RNS::LOG_EXTREME); + HEAD("Deregistering Interface instances with Transport...", RNS::LOG_TRACE); #ifdef UDP_INTERFACE RNS::Transport::deregister_interface(udp_interface); #endif @@ -302,7 +302,7 @@ void reticulum_teardown() { } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in reticulum_teardown: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in reticulum_teardown: ") + e.what() + " !!!"); } } #endif @@ -330,14 +330,14 @@ void setup() { // Setup filesystem if (!SPIFFS.begin(true, "")){ - RNS::error("SPIFFS filesystem mount failed"); + ERROR("SPIFFS filesystem mount failed"); } else { DEBUG("SPIFFS filesystem is ready"); } #endif - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); //RNS::loglevel(RNS::LOG_MEM); /* diff --git a/examples/test/Filesystem.cpp b/examples/test/Filesystem.cpp index d0970c2..04a0438 100644 --- a/examples/test/Filesystem.cpp +++ b/examples/test/Filesystem.cpp @@ -61,9 +61,9 @@ bool Filesystem::init() { #ifdef ARDUINO #ifdef BOARD_ESP32 // Setup filesystem - RNS::info("SPIFFS mounting filesystem"); + INFO("SPIFFS mounting filesystem"); if (!SPIFFS.begin(true, "")){ - RNS::error("SPIFFS filesystem mount failed"); + ERROR("SPIFFS filesystem mount failed"); return false; } uint32_t size = SPIFFS.totalBytes() / (1024 * 1024); @@ -77,7 +77,7 @@ bool Filesystem::init() { // ensure filesystem is writable and format if not RNS::Bytes test; if (!write_file("/test", test)) { - RNS::info("SPIFFS filesystem is being formatted, please wait..."); + INFO("SPIFFS filesystem is being formatted, please wait..."); SPIFFS.format(); } else { @@ -86,9 +86,9 @@ bool Filesystem::init() { DEBUG("SPIFFS filesystem is ready"); #elif BOARD_NRF52 // Initialize Internal File System - RNS::info("InternalFS mounting filesystem"); + INFO("InternalFS mounting filesystem"); InternalFS.begin(); - RNS::info("InternalFS filesystem is ready"); + INFO("InternalFS filesystem is ready"); #endif listDir("/"); #endif @@ -125,7 +125,7 @@ bool Filesystem::init() { return true; } else { - RNS::error("file_exists: failed to open file " + std::string(file_path)); + ERROR("file_exists: failed to open file " + std::string(file_path)); return false; } } @@ -159,7 +159,7 @@ bool Filesystem::init() { #endif TRACE("read_file: read " + std::to_string(read) + " RNS::Bytes from file " + std::string(file_path)); if (read != size) { - RNS::error("read_file: failed to read file " + std::string(file_path)); + ERROR("read_file: failed to read file " + std::string(file_path)); data.clear(); } //TRACE("read_file: closing input file"); @@ -175,7 +175,7 @@ bool Filesystem::init() { #endif } else { - RNS::error("read_file: failed to open input file " + std::string(file_path)); + ERROR("read_file: failed to open input file " + std::string(file_path)); } return read; } @@ -203,7 +203,7 @@ bool Filesystem::init() { #endif TRACE("write_file: wrote " + std::to_string(wrote) + " RNS::Bytes to file " + std::string(file_path)); if (wrote < data.size()) { - RNS::warning("write_file: not all data was written to file " + std::string(file_path)); + WARNING("write_file: not all data was written to file " + std::string(file_path)); } //TRACE("write_file: closing output file"); #ifdef ARDUINO @@ -218,7 +218,7 @@ bool Filesystem::init() { #endif } else { - RNS::error("write_file: failed to open output file " + std::string(file_path)); + ERROR("write_file: failed to open output file " + std::string(file_path)); } return wrote; } @@ -254,7 +254,7 @@ bool Filesystem::init() { } /*virtua*/ bool Filesystem::directory_exists(const char* directory_path) { - RNS::extreme("directory_exists: checking for existence of directory " + std::string(directory_path)); + TRACE("directory_exists: checking for existence of directory " + std::string(directory_path)); #ifdef ARDUINO #ifdef BOARD_ESP32 File file = SPIFFS.open(directory_path, FILE_READ); @@ -288,13 +288,13 @@ bool Filesystem::init() { #ifdef ARDUINO #ifdef BOARD_ESP32 if (!SPIFFS.mkdir(directory_path)) { - RNS::error("create_directory: failed to create directorty " + std::string(directory_path)); + ERROR("create_directory: failed to create directorty " + std::string(directory_path)); return false; } return true; #elif BOARD_NRF52 if (!InternalFS.mkdir(directory_path)) { - RNS::error("create_directory: failed to create directorty " + std::string(directory_path)); + ERROR("create_directory: failed to create directorty " + std::string(directory_path)); return false; } return true; @@ -312,18 +312,18 @@ bool Filesystem::init() { } /*virtua*/ bool Filesystem::remove_directory(const char* directory_path) { - RNS::extreme("remove_directory: removing directory " + std::string(directory_path)); + TRACE("remove_directory: removing directory " + std::string(directory_path)); #ifdef ARDUINO #ifdef BOARD_ESP32 //if (!LittleFS.rmdir_r(directory_path)) { if (!SPIFFS.rmdir(directory_path)) { - RNS::error("remove_directory: failed to remove directorty " + std::string(directory_path)); + ERROR("remove_directory: failed to remove directorty " + std::string(directory_path)); return false; } return true; #elif BOARD_NRF52 if (!InternalFS.rmdir_r(directory_path)) { - RNS::error("remove_directory: failed to remove directory " + std::string(directory_path)); + ERROR("remove_directory: failed to remove directory " + std::string(directory_path)); return false; } return true; @@ -337,7 +337,7 @@ bool Filesystem::init() { } /*virtua*/ std::list Filesystem::list_directory(const char* directory_path) { - RNS::extreme("list_directory: listing directory " + std::string(directory_path)); + TRACE("list_directory: listing directory " + std::string(directory_path)); std::list files; #ifdef ARDUINO #ifdef BOARD_ESP32 @@ -346,7 +346,7 @@ bool Filesystem::init() { File root = InternalFS.open(directory_path); #endif if (!root) { - RNS::error("list_directory: failed to open directory " + std::string(directory_path)); + ERROR("list_directory: failed to open directory " + std::string(directory_path)); return files; } File file = root.openNextFile(); @@ -359,7 +359,7 @@ bool Filesystem::init() { file.close(); file = root.openNextFile(); } - RNS::extreme("list_directory: returning directory listing"); + TRACE("list_directory: returning directory listing"); root.close(); return files; #else diff --git a/examples/test/TestBytes.cpp b/examples/test/TestBytes.cpp index 8bdf108..b77fe00 100644 --- a/examples/test/TestBytes.cpp +++ b/examples/test/TestBytes.cpp @@ -363,7 +363,7 @@ void testBytesResize() { } void testBytes() { - RNS::head("Running testBytes...", RNS::LOG_EXTREME); + HEAD("Running testBytes...", RNS::LOG_TRACE); size_t pre_memory = RNS::Utilities::OS::heap_available(); TRACE("testBytes: pre-mem: " + std::to_string(pre_memory)); diff --git a/examples/test/TestCollections.cpp b/examples/test/TestCollections.cpp index 06766a1..517fafa 100644 --- a/examples/test/TestCollections.cpp +++ b/examples/test/TestCollections.cpp @@ -122,7 +122,7 @@ void testNewMap() { } void testCollections() { - RNS::head("Running testCollections...", RNS::LOG_EXTREME); + HEAD("Running testCollections...", RNS::LOG_TRACE); testBytesMap(); testOldMap(); testNewMap(); diff --git a/examples/test/TestCrypto.cpp b/examples/test/TestCrypto.cpp index 6d6eecb..24a641f 100644 --- a/examples/test/TestCrypto.cpp +++ b/examples/test/TestCrypto.cpp @@ -129,7 +129,7 @@ void testPKCS7() { } void testCrypto() { - RNS::head("Running testCrypto...", RNS::LOG_EXTREME); + HEAD("Running testCrypto...", RNS::LOG_TRACE); testCryptoMain(); testHMAC(); testPKCS7(); diff --git a/examples/test/TestFilesystem.cpp b/examples/test/TestFilesystem.cpp index 7425587..4e01219 100644 --- a/examples/test/TestFilesystem.cpp +++ b/examples/test/TestFilesystem.cpp @@ -11,25 +11,25 @@ using namespace RNS::Utilities; void testListDirectory() { size_t pre_memory = OS::heap_available(); - info("testListDirectory: pre-mem: " + std::to_string(pre_memory)); + INFO("testListDirectory: pre-mem: " + std::to_string(pre_memory)); for (int i = 0; i < 1; i++) { std::list files; files = OS::list_directory("/"); for (auto& file : files) { - info("FILE: " + file); + INFO("FILE: " + file); } } size_t post_memory = OS::heap_available(); size_t diff_memory = (int)pre_memory - (int)post_memory; - info("testListDirectory: post-mem: " + std::to_string(post_memory)); - info("testListDirectory: diff-mem: " + std::to_string(diff_memory)); + INFO("testListDirectory: post-mem: " + std::to_string(post_memory)); + INFO("testListDirectory: diff-mem: " + std::to_string(diff_memory)); assert(diff_memory == 0); } void testFilesystem() { - RNS::head("Running testFilesystem...", RNS::LOG_EXTREME); + HEAD("Running testFilesystem...", RNS::LOG_TRACE); testListDirectory(); diff --git a/examples/test/TestOS.cpp b/examples/test/TestOS.cpp index 27fe808..8e13c63 100644 --- a/examples/test/TestOS.cpp +++ b/examples/test/TestOS.cpp @@ -34,7 +34,7 @@ void testTime() } void testOS() { - RNS::head("Running testOS...", RNS::LOG_EXTREME); + HEAD("Running testOS...", RNS::LOG_TRACE); testTime(); } diff --git a/examples/test/TestPersistence.cpp b/examples/test/TestPersistence.cpp index 126beed..5349a81 100644 --- a/examples/test/TestPersistence.cpp +++ b/examples/test/TestPersistence.cpp @@ -686,7 +686,7 @@ void testDeserializeDestinationTable() { void testPersistence() { - RNS::head("Running testPersistence...", RNS::LOG_EXTREME); + HEAD("Running testPersistence...", RNS::LOG_TRACE); testWrite(); testRead(); testSerializeObject(); diff --git a/examples/test/TestReference.cpp b/examples/test/TestReference.cpp index 7369a5d..9a7234b 100644 --- a/examples/test/TestReference.cpp +++ b/examples/test/TestReference.cpp @@ -6,7 +6,7 @@ #include void testReference() { - RNS::head("Running testReference...", RNS::LOG_EXTREME); + HEAD("Running testReference...", RNS::LOG_TRACE); RNS::Reticulum reticulum_default; assert(reticulum_default); @@ -21,7 +21,7 @@ void testReference() { assert(!reticulum_none_copy); /* - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); TestInterface testinterface; std::set, std::less> interfaces; @@ -35,7 +35,7 @@ void testReference() { return 0; */ /* - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); TestInterface testinterface; std::set, std::less> interfaces; @@ -48,7 +48,7 @@ void testReference() { return 0; */ /* - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); TestInterface testinterface; std::list> interfaces; @@ -62,7 +62,7 @@ void testReference() { return 0; */ /* - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); TestInterface testinterface; std::list> interfaces; @@ -78,7 +78,7 @@ void testReference() { /* std::list> interfaces; { - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); TestInterface testinterface; interfaces.push_back(testinterface); for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { @@ -97,7 +97,7 @@ void testReference() { return 0; */ /* - RNS::head("Testing map...", RNS::LOG_EXTREME); + HEAD("Testing map...", RNS::LOG_TRACE); { std::map destinations; destinations.insert({destination.hash(), destination}); diff --git a/examples/test/TestReticulum.cpp b/examples/test/TestReticulum.cpp index ddec622..ef31c0a 100644 --- a/examples/test/TestReticulum.cpp +++ b/examples/test/TestReticulum.cpp @@ -13,7 +13,7 @@ void testDestinationTable() { } void testReticulum() { - RNS::head("Running testReticulum...", RNS::LOG_EXTREME); + HEAD("Running testReticulum...", RNS::LOG_TRACE); reticulum = RNS::Reticulum(); reticulum.transport_enabled(true); diff --git a/examples/test/main.cpp b/examples/test/main.cpp index a5a3c23..35d0c00 100644 --- a/examples/test/main.cpp +++ b/examples/test/main.cpp @@ -35,11 +35,11 @@ void setup() { Serial.print("Hello from T-Beam on PlatformIO!\n"); #endif - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); //RNS::loglevel(RNS::LOG_MEM); if (filesystem) { - RNS::info("Filesystem exists"); + INFO("Filesystem exists"); filesystem.init(); } RNS::Utilities::OS::register_filesystem(filesystem); @@ -49,7 +49,7 @@ void setup() { TRACE("Running tests..."); RNS::LogLevel loglevel = RNS::loglevel(); //RNS::loglevel(RNS::LOG_WARNING); - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); // all tests //test(); @@ -67,7 +67,7 @@ void setup() { //return; } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in test: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in test: ") + e.what() + " !!!"); } #ifdef ARDUINO diff --git a/examples/udp/UDPInterface.cpp b/examples/udp/UDPInterface.cpp index 62a0f11..830d3a9 100644 --- a/examples/udp/UDPInterface.cpp +++ b/examples/udp/UDPInterface.cpp @@ -125,7 +125,7 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p if (inet_aton(_local_host.c_str(), &local_addr) == 0) { struct hostent* host_ent = gethostbyname(_local_host.c_str()); if (host_ent == nullptr || host_ent->h_addr_list[0] == nullptr) { - error("Unable to resolve local host " + std::string(_local_host)); + ERROR("Unable to resolve local host " + std::string(_local_host)); return false; } _local_address = *((in_addr_t*)(host_ent->h_addr_list[0])); @@ -139,7 +139,7 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p if (inet_aton(_remote_host.c_str(), &remote_addr) == 0) { struct hostent* host_ent = gethostbyname(_remote_host.c_str()); if (host_ent == nullptr || host_ent->h_addr_list[0] == nullptr) { - error("Unable to resolve remote host " + std::string(_remote_host)); + ERROR("Unable to resolve remote host " + std::string(_remote_host)); return false; } _remote_address = *((in_addr_t*)(host_ent->h_addr_list[0])); @@ -152,7 +152,7 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p 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)); + ERROR("Unable to create socket with error " + std::to_string(errno)); return false; } @@ -161,7 +161,7 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p setsockopt(_socket, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)); // bind to udp socket for listening - info("Binding UDP socket " + std::to_string(_socket) + " to " + std::string(_local_host) + ":" + std::to_string(_local_port)); + INFO("Binding UDP socket " + std::to_string(_socket) + " to " + std::string(_local_host) + ":" + std::to_string(_local_port)); sockaddr_in bind_addr; bind_addr.sin_family = AF_INET; bind_addr.sin_addr.s_addr = _local_address; @@ -169,7 +169,7 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p if (bind(_socket, (struct sockaddr*)&bind_addr, sizeof(bind_addr)) == -1) { close(_socket); _socket = -1; - error("Unable to bind socket with error " + std::to_string(errno)); + ERROR("Unable to bind socket with error " + std::to_string(errno)); return false; } #endif @@ -246,6 +246,6 @@ void UDPInterface::loop() { Interface::on_outgoing(data); } catch (std::exception& e) { - error("Could not transmit on " + toString() + ". The contained exception was: " + e.what()); + ERROR("Could not transmit on " + toString() + ". The contained exception was: " + e.what()); } } diff --git a/examples/udp/main.cpp b/examples/udp/main.cpp index 820c0a5..41d61cf 100644 --- a/examples/udp/main.cpp +++ b/examples/udp/main.cpp @@ -54,35 +54,35 @@ public: ExampleAnnounceHandler(const char* aspect_filter = nullptr) : AnnounceHandler(aspect_filter) {} virtual ~ExampleAnnounceHandler() {} virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); if (announced_identity) { - RNS::info("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); - RNS::info("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); + INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); + INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); } if (app_data) { - RNS::info("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); + INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); } - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } }; // Test packet receive callback void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("onPacket: data: " + data.toHex()); - RNS::info("onPacket: text: \"" + data.toString() + "\""); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("onPacket: data: " + data.toHex()); + INFO("onPacket: text: \"" + data.toString() + "\""); //TRACE("onPacket: " + packet.debugString()); - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } // Ping packet receive callback void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - RNS::info("onPingPacket: data: " + data.toHex()); - RNS::info("onPingPacket: text: \"" + data.toString() + "\""); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("onPingPacket: data: " + data.toHex()); + INFO("onPingPacket: text: \"" + data.toString() + "\""); //TRACE("onPingPacket: " + packet.debugString()); - RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -98,7 +98,7 @@ RNS::HAnnounceHandler announce_handler(new ExampleAnnounceHandler()); void reticulum_announce() { if (destination) { - RNS::head("Announcing destination...", RNS::LOG_EXTREME); + HEAD("Announcing destination...", RNS::LOG_TRACE); //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7])); // test path //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]), true, nullptr, RNS::bytesFromString("test_tag")); @@ -108,7 +108,7 @@ void reticulum_announce() { } void reticulum_setup() { - RNS::info("Setting up Reticulum..."); + INFO("Setting up Reticulum..."); try { @@ -120,14 +120,14 @@ void reticulum_setup() { // 21.8% baseline here with serial - RNS::head("Registering Interface instances with Transport...", RNS::LOG_EXTREME); + HEAD("Registering Interface instances with Transport...", RNS::LOG_TRACE); udp_interface.mode(RNS::Type::Interface::MODE_GATEWAY); RNS::Transport::register_interface(udp_interface); - RNS::head("Starting UDPInterface...", RNS::LOG_EXTREME); + HEAD("Starting UDPInterface...", RNS::LOG_TRACE); udp_interface.start("wifi_ssid", "wifi_password", 4242); - RNS::head("Creating Reticulum instance...", RNS::LOG_EXTREME); + HEAD("Creating Reticulum instance...", RNS::LOG_TRACE); //RNS::Reticulum reticulum; reticulum = RNS::Reticulum(); reticulum.transport_enabled(true); @@ -135,7 +135,7 @@ void reticulum_setup() { //return; // 21.9% (+0.1%) - RNS::head("Creating Identity instance...", RNS::LOG_EXTREME); + HEAD("Creating Identity instance...", RNS::LOG_TRACE); // new identity //RNS::Identity identity; //identity = RNS::Identity(); @@ -151,31 +151,31 @@ void reticulum_setup() { identity.load_private_key(prv_bytes); // 22.6% (+0.7%) - RNS::head("Creating Destination instance...", RNS::LOG_EXTREME); + HEAD("Creating Destination instance...", RNS::LOG_TRACE); //RNS::Destination destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "app", "aspects"); destination = RNS::Destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "app", "aspects"); // 23.0% (+0.4%) // Register DATA packet callback - RNS::head("Registering packet callback with Destination...", RNS::LOG_EXTREME); + HEAD("Registering packet callback with Destination...", RNS::LOG_TRACE); destination.set_packet_callback(onPacket); destination.set_proof_strategy(RNS::Type::Destination::PROVE_ALL); { // Register PING packet callback - RNS::head("Creating PING Destination instance...", RNS::LOG_EXTREME); + HEAD("Creating PING Destination instance...", RNS::LOG_TRACE); RNS::Destination ping_destination(identity, RNS::Type::Destination::IN, RNS::Type::Destination::SINGLE, "example_utilities", "echo.request"); - RNS::head("Registering packet callback with PING Destination...", RNS::LOG_EXTREME); + HEAD("Registering packet callback with PING Destination...", RNS::LOG_TRACE); ping_destination.set_packet_callback(onPingPacket); ping_destination.set_proof_strategy(RNS::Type::Destination::PROVE_ALL); } - RNS::head("Registering announce handler with Transport...", RNS::LOG_EXTREME); + HEAD("Registering announce handler with Transport...", RNS::LOG_TRACE); RNS::Transport::register_announce_handler(announce_handler); /* - RNS::head("Announcing destination...", RNS::LOG_EXTREME); + HEAD("Announcing destination...", RNS::LOG_TRACE); //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7])); // test path //destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]), true, nullptr, RNS::bytesFromString("test_tag")); @@ -186,49 +186,49 @@ void reticulum_setup() { #if defined (RETICULUM_PACKET_TEST) // test data send packet - RNS::head("Creating send packet...", RNS::LOG_EXTREME); + HEAD("Creating send packet...", RNS::LOG_TRACE); RNS::Packet send_packet(destination, "The quick brown fox jumps over the lazy dog"); - RNS::head("Sending send packet...", RNS::LOG_EXTREME); + HEAD("Sending send packet...", RNS::LOG_TRACE); send_packet.pack(); #ifndef NDEBUG TRACE("Test send_packet: " + send_packet.debugString()); #endif - RNS::head("Creating recv packet...", RNS::LOG_EXTREME); + HEAD("Creating recv packet...", RNS::LOG_TRACE); RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw()); recv_packet.unpack(); #ifndef NDEBUG TRACE("Test recv_packet: " + recv_packet.debugString()); #endif - RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME); + HEAD("Spoofing recv packet to destination...", RNS::LOG_TRACE); destination.receive(recv_packet); #endif - RNS::head("Ready!", RNS::LOG_EXTREME); + HEAD("Ready!", RNS::LOG_TRACE); } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in reticulum_setup: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in reticulum_setup: ") + e.what() + " !!!"); } } void reticulum_teardown() { - RNS::info("Tearing down Reticulum..."); + INFO("Tearing down Reticulum..."); RNS::Transport::save_path_table(); try { - RNS::head("Deregistering announce handler with Transport...", RNS::LOG_EXTREME); + HEAD("Deregistering announce handler with Transport...", RNS::LOG_TRACE); RNS::Transport::deregister_announce_handler(announce_handler); - RNS::head("Deregistering Interface instances with Transport...", RNS::LOG_EXTREME); + HEAD("Deregistering Interface instances with Transport...", RNS::LOG_TRACE); RNS::Transport::deregister_interface(udp_interface); } catch (std::exception& e) { - RNS::error(std::string("!!! Exception in reticulum_teardown: ") + e.what() + " !!!"); + ERROR(std::string("!!! Exception in reticulum_teardown: ") + e.what() + " !!!"); } } @@ -255,14 +255,14 @@ void setup() { // Setup filesystem if (!SPIFFS.begin(true, "")){ - RNS::error("SPIFFS filesystem mount failed"); + ERROR("SPIFFS filesystem mount failed"); } else { DEBUG("SPIFFS filesystem is ready"); } #endif - RNS::loglevel(RNS::LOG_EXTREME); + RNS::loglevel(RNS::LOG_TRACE); //RNS::loglevel(RNS::LOG_MEM); /* diff --git a/src/Bytes.cpp b/src/Bytes.cpp index d450062..20ddfff 100644 --- a/src/Bytes.cpp +++ b/src/Bytes.cpp @@ -11,7 +11,7 @@ void Bytes::newData(size_t 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); if (data == nullptr) { - error("Bytes failed to allocate data buffer"); + ERROR("Bytes failed to allocate data buffer"); throw std::runtime_error("Failed to allocate data buffer"); } _data = SharedData(data); @@ -19,7 +19,7 @@ void Bytes::newData(size_t size /*= 0*/) { else { Data* data = new Data(); if (data == nullptr) { - error("Bytes failed to allocate empty data buffer"); + ERROR("Bytes failed to allocate empty data buffer"); throw std::runtime_error("Failed to allocate empty data buffer"); } _data = SharedData(data); @@ -42,7 +42,7 @@ void Bytes::exclusiveData(bool copy /*= true*/, size_t size /*= 0*/) { //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"); + ERROR("Bytes failed to duplicate data buffer"); throw std::runtime_error("Failed to duplicate data buffer"); } if (size > 0) { @@ -55,7 +55,7 @@ void Bytes::exclusiveData(bool copy /*= true*/, size_t size /*= 0*/) { //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"); + // ERROR("Bytes failed to allocate empty data buffer"); // throw std::runtime_error("Failed to allocate empty data buffer"); //} //_data = SharedData(data); diff --git a/src/Cryptography/Fernet.cpp b/src/Cryptography/Fernet.cpp index 0ee5c0f..f70bc6e 100644 --- a/src/Cryptography/Fernet.cpp +++ b/src/Cryptography/Fernet.cpp @@ -110,7 +110,7 @@ const Bytes Fernet::decrypt(const Bytes& token) { return plaintext; } catch (std::exception& e) { - warning("Could not decrypt Fernet token"); + WARNING("Could not decrypt Fernet token"); throw std::runtime_error("Could not decrypt Fernet token"); } } \ No newline at end of file diff --git a/src/Identity.cpp b/src/Identity.cpp index a35adcd..7a55b27 100644 --- a/src/Identity.cpp +++ b/src/Identity.cpp @@ -57,7 +57,7 @@ void Identity::createKeys() { update_hashes(); - verbose("Identity keys created for " + _object->_hash.toHex()); + VERBOSE("Identity keys created for " + _object->_hash.toHex()); } /* @@ -95,8 +95,8 @@ bool Identity::load_private_key(const Bytes& prv_bytes) { } catch (std::exception& e) { //p raise e - error("Failed to load identity key"); - error("The contained exception was: " + std::string(e.what())); + ERROR("Failed to load identity key"); + ERROR("The contained exception was: " + std::string(e.what())); return false; } } @@ -126,7 +126,7 @@ void Identity::load_public_key(const Bytes& pub_bytes) { update_hashes(); } catch (std::exception& e) { - error("Error while loading public key, the contained exception was: " + std::string(e.what())); + ERROR("Error while loading public key, the contained exception was: " + std::string(e.what())); } } @@ -142,8 +142,8 @@ bool Identity::load(const char* path) { } } catch (std::exception& e) { - error("Error while loading identity from " + std::string(path)); - error("The contained exception was: " + std::string(e.what())); + ERROR("Error while loading identity from " + std::string(path)); + ERROR("The contained exception was: " + std::string(e.what())); } return false; } @@ -162,8 +162,8 @@ bool Identity::to_file(const char* path) { return (OS::write_file(path, get_private_key()) == get_private_key().size()); } catch (std::exception& e) { - error("Error while saving identity to " + std::string(path)); - error("The contained exception was: " + std::string(e.what())); + ERROR("Error while saving identity to " + std::string(path)); + ERROR("The contained exception was: " + std::string(e.what())); } return false; } @@ -263,7 +263,7 @@ Recall last heard app_data for a destination hash. while (_saving_known_destinations) { OS::sleep(wait_interval); if (OS::time() > (wait_start + wait_timeout)) { - error("Could not save known destinations to storage, waiting for previous save operation timed out."); + ERROR("Could not save known destinations to storage, waiting for previous save operation timed out."); return false; } } @@ -315,7 +315,7 @@ Recall last heard app_data for a destination hash. success = true; } catch (std::exception& e) { - error("Error while saving known destinations to disk, the contained exception was: " + std::string(e.what())); + ERROR("Error while saving known destinations to disk, the contained exception was: " + std::string(e.what())); } _saving_known_destinations = false; @@ -365,7 +365,7 @@ Recall last heard app_data for a destination hash. TRACE("Transport::cull_path_table: Removing destination " + destination_hash.toHex() + " from known destinations"); // Remove destination from known destinations if (_known_destinations.erase(destination_hash) < 1) { - warning("Failed to remove destination " + destination_hash.toHex() + " from known destinations"); + WARNING("Failed to remove destination " + destination_hash.toHex() + " from known destinations"); } ++count; if (_known_destinations.size() <= _known_destinations_maxsize) { @@ -422,8 +422,8 @@ Recall last heard app_data for a destination hash. if (public_key != identity_entry._public_key) { // In reality, this should never occur, but in the odd case // that someone manages a hash collision, we reject the announce. - critical("Received announce with valid signature and destination hash, but announced public key does not match already known public key."); - critical("This may indicate an attempt to modify network paths, or a random hash collision. The announce was rejected."); + CRITICAL("Received announce with valid signature and destination hash, but announced public key does not match already known public key."); + CRITICAL("This may indicate an attempt to modify network paths, or a random hash collision. The announce was rejected."); return false; } } @@ -469,7 +469,7 @@ Recall last heard app_data for a destination hash. } } catch (std::exception& e) { - error("Error occurred while validating announce. The contained exception was: " + std::string(e.what())); + ERROR("Error occurred while validating announce. The contained exception was: " + std::string(e.what())); return false; } return false; @@ -595,7 +595,7 @@ const Bytes Identity::sign(const Bytes& message) const { return _object->_sig_prv->sign(message); } catch (std::exception& e) { - error("The identity " + toString() + " could not sign the requested message. The contained exception was: " + e.what()); + ERROR("The identity " + toString() + " could not sign the requested message. The contained exception was: " + e.what()); throw e; } } diff --git a/src/Log.cpp b/src/Log.cpp index c9b7867..588cbe5 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -9,7 +9,7 @@ using namespace RNS; //LogLevel _level = LOG_VERBOSE; -LogLevel _level = LOG_EXTREME; +LogLevel _level = LOG_TRACE; //LogLevel _level = LOG_MEM; RNS::log_callback _on_log = nullptr; char _datetime[20]; @@ -30,7 +30,7 @@ const char* RNS::getLevelName(LogLevel level) { return "VRB"; case LOG_DEBUG: return "DBG"; - case LOG_EXTREME: + case LOG_TRACE: return "---"; case LOG_MEM: return "..."; @@ -96,7 +96,7 @@ void RNS::doLog(const char* msg, LogLevel level) { #endif } -void RNS::head(const char* msg, LogLevel level) { +void HEAD(const char* msg, LogLevel level) { if (level > _level) { return; } diff --git a/src/Log.h b/src/Log.h index 2844065..46397c5 100644 --- a/src/Log.h +++ b/src/Log.h @@ -6,9 +6,17 @@ #include +#define LOG(msg, level) (RNS::log(msg, level)) +#define HEAD(msg, level) (RNS::head(msg, level)) +#define CRITICAL(msg) (RNS::critical(msg)) +#define ERROR(msg) (RNS::error(msg)) +#define WARNING(msg) (RNS::warning(msg)) +#define NOTICE(msg) (RNS::notice(msg)) +#define INFO(msg) (RNS::info(msg)) +#define VERBOSE(msg) (RNS::verbose(msg)) #ifndef NDEBUG #define DEBUG(msg) (RNS::debug(msg)) - #define TRACE(msg) (RNS::extreme(msg)) + #define TRACE(msg) (RNS::trace(msg)) //#define MEM(msg) (RNS::mem(msg)) #define MEM(ignore) ((void)0) #else @@ -28,7 +36,7 @@ namespace RNS { LOG_INFO = 5, LOG_VERBOSE = 6, LOG_DEBUG = 7, - LOG_EXTREME = 8, + LOG_TRACE = 8, LOG_MEM = 9 }; @@ -52,6 +60,9 @@ namespace RNS { #endif inline void log(const std::string& msg, LogLevel level = LOG_NOTICE) { doLog(msg.c_str(), level); } + void head(const char* msg, LogLevel level = LOG_NOTICE); + inline void head(const std::string& msg, LogLevel level = LOG_NOTICE) { head(msg.c_str(), level); } + inline void critical(const char* msg) { doLog(msg, LOG_CRITICAL); } inline void critical(const std::string& msg) { doLog(msg.c_str(), LOG_CRITICAL); } @@ -73,13 +84,10 @@ namespace RNS { inline void debug(const char* msg) { doLog(msg, LOG_DEBUG); } inline void debug(const std::string& msg) { doLog(msg.c_str(), LOG_DEBUG); } - inline void extreme(const char* msg) { doLog(msg, LOG_EXTREME); } - inline void extreme(const std::string& msg) { doLog(msg.c_str(), LOG_EXTREME); } + inline void trace(const char* msg) { doLog(msg, LOG_TRACE); } + inline void trace(const std::string& msg) { doLog(msg.c_str(), LOG_TRACE); } inline void mem(const char* msg) { doLog(msg, LOG_MEM); } inline void mem(const std::string& msg) { doLog(msg.c_str(), LOG_MEM); } - void head(const char* msg, LogLevel level = LOG_NOTICE); - inline void head(const std::string& msg, LogLevel level = LOG_NOTICE) { head(msg.c_str(), level); } - } diff --git a/src/Packet.cpp b/src/Packet.cpp index 3000af5..71b7ffa 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -420,7 +420,7 @@ bool Packet::send() { return true; } else { - error("No interfaces could process the outbound packet"); + ERROR("No interfaces could process the outbound packet"); _object->_sent = false; //z _receipt = None; return false; @@ -449,7 +449,7 @@ bool Packet::resend() { return true; } else { - error("No interfaces could process the outbound packet"); + ERROR("No interfaces could process the outbound packet"); _object->_sent = false; //z self.receipt = None; return false; @@ -471,7 +471,7 @@ void Packet::prove(const Destination& destination /*= {Type::NONE}*/) { _object->_link.prove_packet(*this); } else { - error("Could not prove packet associated with neither a destination nor a link"); + ERROR("Could not prove packet associated with neither a destination nor a link"); } } @@ -802,8 +802,8 @@ bool PacketReceipt::validate_link_proof(const Bytes& proof, const Link& link, co _object->_callbacks._delivery(*this); } catch (std::exception& e) { - error("An error occurred while evaluating external delivery callback for " + link.toString()); - error("The contained exception was: " + std::string(e.what())); + ERROR("An error occurred while evaluating external delivery callback for " + link.toString()); + ERROR("The contained exception was: " + std::string(e.what())); } } return true; @@ -862,7 +862,7 @@ bool PacketReceipt::validate_proof(const Bytes& proof, const Packet& proof_packe _object->_callbacks._delivery(*this); } catch (std::exception& e) { - error("Error while executing proof validated callback. The contained exception was: " + std::string(e.what())); + ERROR("Error while executing proof validated callback. The contained exception was: " + std::string(e.what())); } } return true; @@ -893,7 +893,7 @@ bool PacketReceipt::validate_proof(const Bytes& proof, const Packet& proof_packe _object->_callbacks._delivery(*this); } catch (std::exception& e) { - error("Error while executing proof validated callback. The contained exception was: " + std::string(e.what())); + ERROR("Error while executing proof validated callback. The contained exception was: " + std::string(e.what())); } } return true; diff --git a/src/Reticulum.cpp b/src/Reticulum.cpp index 681f9eb..dcc203a 100644 --- a/src/Reticulum.cpp +++ b/src/Reticulum.cpp @@ -39,8 +39,8 @@ pass any traffic before being instantiated. 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())); - info("Total memory: " + std::to_string(OS::heap_available())); - info("Total flash: " + std::to_string(OS::storage_available())); + INFO("Total memory: " + std::to_string(OS::heap_available())); + INFO("Total flash: " + std::to_string(OS::storage_available())); // Initialize random number generator TRACE("Initializing RNG..."); @@ -98,7 +98,7 @@ Reticulum::Reticulum() : _object(new Object()) { } } catch (std::exception& e) { - error("Failed to load time offset, the contained exception was: " + std::string(e.what())); + ERROR("Failed to load time offset, the contained exception was: " + std::string(e.what())); } #endif @@ -192,7 +192,7 @@ Reticulum::Reticulum() : _object(new Object()) { */ void Reticulum::start() { - info("Starting Transport..."); + INFO("Starting Transport..."); Transport::start(*this); } @@ -219,7 +219,7 @@ void Reticulum::jobs() { if (OS::heap_size() > 0) { uint8_t remaining = (uint8_t)((double)OS::heap_available() / (double)OS::heap_size() * 100.0); if (remaining <= 10) { - head("DETECTED LOW-MEMORY CONDITION (" + std::to_string(remaining) + "%), RESETTING!!!", LOG_WARNING); + head("DETECTED LOW-MEMORY CONDITION (" + std::to_string(remaining) + "%), RESETTING!!!", LOG_CRITICAL); persist_data(); #if defined(ESP32) ESP.restart(); @@ -261,7 +261,7 @@ void Reticulum::persist_data() { OS::write_file(time_offset_path.c_str(), buf); } catch (std::exception& e) { - error("Failed to write time offset, the contained exception was: " + std::string(e.what())); + ERROR("Failed to write time offset, the contained exception was: " + std::string(e.what())); } #endif @@ -286,7 +286,7 @@ void Reticulum::clean_caches() { } } catch (std::exception& e) { - error("Error while cleaning resources cache, the contained exception was: " + std::string(e.what())); + ERROR("Error while cleaning resources cache, the contained exception was: " + std::string(e.what())); } } @@ -303,7 +303,7 @@ void Reticulum::clean_caches() { } } catch (std::exception& e) { - error("Error while cleaning packet cache, the contained exception was: " + std::string(e.what())); + ERROR("Error while cleaning packet cache, the contained exception was: " + std::string(e.what())); } } */ @@ -331,6 +331,6 @@ void Reticulum::clear_caches() { #endif } catch (std::exception& e) { - error("Failed to clear cache file(s), the contained exception was: " + std::string(e.what())); + ERROR("Failed to clear cache file(s), the contained exception was: " + std::string(e.what())); } } diff --git a/src/Transport.cpp b/src/Transport.cpp index 26136b0..ebf76bc 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -109,7 +109,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); /*static*/ size_t Transport::_last_flash = 0; /*static*/ void Transport::start(const Reticulum& reticulum_instance) { - info("Transport starting..."); + INFO("Transport starting..."); _jobs_running = true; _owner = reticulum_instance; @@ -123,7 +123,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); // ensure required directories exist if (!OS::directory_exists(Reticulum::_cachepath.c_str())) { - verbose("No cache directory, creating..."); + VERBOSE("No cache directory, creating..."); OS::create_directory(Reticulum::_cachepath.c_str()); } @@ -136,16 +136,16 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } if (!_identity) { - verbose("No valid Transport Identity in storage, creating..."); + VERBOSE("No valid Transport Identity in storage, creating..."); _identity = Identity(); _identity.to_file(transport_identity_path.c_str()); } else { - verbose("Loaded Transport Identity from storage"); + VERBOSE("Loaded Transport Identity from storage"); } } catch (std::exception& e) { - error("Failed to check for transport identity, the contained exception was: " + std::string(e.what())); + ERROR("Failed to check for transport identity, the contained exception was: " + std::string(e.what())); } } @@ -160,7 +160,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); file.close(); } catch (std::exception& e) { - error("Could not load packet hashlist from storage, the contained exception was: " + std::string(e.what())); + ERROR("Could not load packet hashlist from storage, the contained exception was: " + std::string(e.what())); } } } @@ -193,7 +193,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); //p thread.start() if (Reticulum::transport_enabled()) { - info("Transport mode is enabled"); + INFO("Transport mode is enabled"); // Read in path table and then write and clean in case any entries are invalid read_path_table(); @@ -209,10 +209,10 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); probe_destination.set_proof_strategy(Type::Destination::PROVE_ALL); DEBUG("Created probe responder destination " + probe_destination.hash().toHex()); probe_destination.announce(); - notice("Transport Instance will respond to probe requests on " + probe_destination.toString()); + NOTICE("Transport Instance will respond to probe requests on " + probe_destination.toString()); } - verbose("Transport instance " + _identity.toString() + " started"); + VERBOSE("Transport instance " + _identity.toString() + " started"); _start_time = OS::time(); } @@ -636,8 +636,8 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } catch (std::exception& e) { - error("An exception occurred while running Transport jobs."); - error("The contained exception was: " + std::string(e.what())); + ERROR("An exception occurred while running Transport jobs."); + ERROR("The contained exception was: " + std::string(e.what())); } _jobs_running = false; @@ -711,7 +711,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } catch (std::exception& e) { - error("Error while transmitting on " + interface.toString() + ". The contained exception was: " + e.what()); + ERROR("Error while transmitting on " + interface.toString() + ". The contained exception was: " + e.what()); } } @@ -721,7 +721,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); if (!packet.destination()) { //throw std::invalid_argument("Can not send packet with no destination."); - error("Can not send packet with no destination"); + ERROR("Can not send packet with no destination"); return false; } @@ -1266,7 +1266,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } if (!_identity) { - warning("Transport::inbound: No identity!"); + WARNING("Transport::inbound: No identity!"); return; } @@ -1274,7 +1274,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); Packet packet({Type::NONE}, raw); if (!packet.unpack()) { - warning("Transport::inbound: Packet unpack failed!"); + WARNING("Transport::inbound: Packet unpack failed!"); return; } #ifndef NDEBUG @@ -2057,8 +2057,8 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } catch (std::exception& e) { - error("Error while processing external announce callback."); - error("The contained exception was: " + std::string(e.what())); + ERROR("Error while processing external announce callback."); + ERROR("The contained exception was: " + std::string(e.what())); } } } @@ -2146,7 +2146,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } catch (std::exception& e) { - error(std::string("Error while executing proof request callback. The contained exception was: ") + e.what()); + ERROR(std::string("Error while executing proof request callback. The contained exception was: ") + e.what()); } } } @@ -2197,7 +2197,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); } } catch (std::exception& e) { - error("Error while transporting link request proof. The contained exception was: " + std::string(e.what())); + ERROR("Error while transporting link request proof. The contained exception was: " + std::string(e.what())); } } else { @@ -2541,7 +2541,7 @@ extern uint8_t crypto_crc8(uint8_t tag, const void *data, unsigned size); link.status(Type::Link::ACTIVE); } else { - error("Attempted to activate a link that was not in the pending table"); + ERROR("Attempted to activate a link that was not in the pending table"); } */ } @@ -2619,7 +2619,7 @@ Deregisters an announce handler. return Persistence::serialize(packet, packet_cache_path.c_str()); } catch (std::exception& e) { - error("Error writing packet to cache. The contained exception was: " + std::string(e.what())); + ERROR("Error writing packet to cache. The contained exception was: " + std::string(e.what())); } } return false; @@ -2657,8 +2657,8 @@ Deregisters an announce handler. return packet; } catch (std::exception& e) { - error("Exception occurred while getting cached packet."); - error("The contained exception was: " + std::string(e.what())); + ERROR("Exception occurred while getting cached packet."); + ERROR("The contained exception was: " + std::string(e.what())); } return {Type::NONE}; } @@ -2678,8 +2678,8 @@ Deregisters an announce handler. } } catch (std::exception& e) { - error("Exception occurred while clearing cached packet."); - error("The contained exception was: " + std::string(e.what())); + ERROR("Exception occurred while clearing cached packet."); + ERROR("The contained exception was: " + std::string(e.what())); } return false; } @@ -2929,7 +2929,7 @@ will announce it. } } catch (std::exception& e) { - error("Error while handling path request. The contained exception was: " + std::string(e.what())); + ERROR("Error while handling path request. The contained exception was: " + std::string(e.what())); } } @@ -3374,13 +3374,13 @@ TRACE("Transport::start: buffer size " + std::to_string(Persistence::_buffer.siz // CBA If announce packet load fails then remove destination entry (it's useless without announce packet) if (!destination_entry.announce_packet()) { // remove destination - RNS::warning("Transport::start: removing invalid path to " + destination_hash.toHex() + " due to missing announce packet"); + WARNING("Transport::start: removing invalid path to " + destination_hash.toHex() + " due to missing announce packet"); invalid_paths.push_back(destination_hash); } // CBA If receiving interface is not found then remove destination entry (it's useless without interface) if (!destination_entry.receiving_interface()) { // remove destination - RNS::warning("Transport::start: removing invalid path to " + destination_hash.toHex() + " due to missing receiving interface"); + WARNING("Transport::start: removing invalid path to " + destination_hash.toHex() + " due to missing receiving interface"); invalid_paths.push_back(destination_hash); } } @@ -3396,11 +3396,11 @@ TRACE("Transport::start: buffer size " + std::to_string(Persistence::_buffer.siz else { TRACE("Transport::start: destination table read failed"); } - verbose("Loaded " + std::to_string(_destination_table.size()) + " valid path table entries from storage"); + VERBOSE("Loaded " + std::to_string(_destination_table.size()) + " valid path table entries from storage"); } catch (std::exception& e) { - error("Could not load destination table from storage, the contained exception was: " + std::string(e.what())); + ERROR("Could not load destination table from storage, the contained exception was: " + std::string(e.what())); } } return false; @@ -3422,7 +3422,7 @@ TRACE("Transport::start: buffer size " + std::to_string(Persistence::_buffer.siz while (_saving_path_table) { OS::sleep(wait_interval); if (OS::time() > (wait_start + wait_timeout)) { - error("Could not save path table to storage, waiting for previous save operation timed out."); + ERROR("Could not save path table to storage, waiting for previous save operation timed out."); return false; } } @@ -3542,7 +3542,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: } } catch (std::exception& e) { - error("Could not save path table to storage, the contained exception was: " + std::string(e.what())); + ERROR("Could not save path table to storage, the contained exception was: " + std::string(e.what())); } _saving_path_table = false; @@ -3715,7 +3715,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: /*static*/ void Transport::dump_stats() { #if defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_NRF52_ADAFRUIT) - if (loglevel() == LOG_EXTREME) { + if (loglevel() == LOG_TRACE) { dbgMemInfo(); } #endif @@ -3737,7 +3737,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: // _reverse_table // _announce_table // _held_announces - head("mem: " + std::to_string(memory) + " (" + std::to_string((int)((double)memory / (double)OS::heap_size() * 100.0)) + "%) [" + std::to_string((int)memory - (int)_last_memory) + "] flash: " + std::to_string(flash) + " (" + std::to_string((int)((double)flash / (double)OS::storage_size() * 100.0)) + "%) [" + std::to_string((int)flash - (int)_last_flash) + "] paths: " + std::to_string(_destination_table.size()) + " dsts: " + std::to_string(_destinations.size()) + " revr: " + std::to_string(_reverse_table.size()) + " annc: " + std::to_string(_announce_table.size()) + " held: " + std::to_string(_held_announces.size()), LOG_VERBOSE); + HEAD("mem: " + std::to_string(memory) + " (" + std::to_string((int)((double)memory / (double)OS::heap_size() * 100.0)) + "%) [" + std::to_string((int)memory - (int)_last_memory) + "] flash: " + std::to_string(flash) + " (" + std::to_string((int)((double)flash / (double)OS::storage_size() * 100.0)) + "%) [" + std::to_string((int)flash - (int)_last_flash) + "] paths: " + std::to_string(_destination_table.size()) + " dsts: " + std::to_string(_destinations.size()) + " revr: " + std::to_string(_reverse_table.size()) + " annc: " + std::to_string(_announce_table.size()) + " held: " + std::to_string(_held_announces.size()), LOG_VERBOSE); // _path_requests // _discovery_path_requests @@ -3745,7 +3745,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: // _discovery_pr_tags // _control_destinations // _control_hashes - verbose("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())); + VERBOSE("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 @@ -3761,8 +3761,8 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: for (auto& [interface_hash, interface] : _interfaces) { interface_announces += interface.announce_queue().size(); } - verbose("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())); - verbose("pin: " + std::to_string(_packets_received) + " pout: " + std::to_string(_packets_sent) + " dadd: " + std::to_string(_destinations_added) + " dpr: " + std::to_string(destination_path_responses) + " ikd: " + std::to_string(Identity::_known_destinations.size()) + " ia: " + std::to_string(interface_announces) + "\r\n"); + VERBOSE("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())); + VERBOSE("pin: " + std::to_string(_packets_received) + " pout: " + std::to_string(_packets_sent) + " dadd: " + std::to_string(_destinations_added) + " dpr: " + std::to_string(destination_path_responses) + " ikd: " + std::to_string(Identity::_known_destinations.size()) + " ia: " + std::to_string(interface_announces) + "\r\n"); _last_memory = memory; _last_flash = flash; @@ -3815,11 +3815,11 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: 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"); + WARNING("Failed to remove destination " + announce_packet.destination_hash().toHex() + " from path table"); } // Remove announce packet from packet table if (_packet_table.erase(destination_entry._announce_packet) < 1) { - warning("Failed to remove packet " + destination_entry._announce_packet.toHex() + " from packet table"); + WARNING("Failed to remove packet " + destination_entry._announce_packet.toHex() + " from packet table"); } // Remove cached packet file std::string packet_cache_path = Reticulum::_cachepath + "/" + destination_entry._announce_packet.toHex(); @@ -3848,11 +3848,11 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: 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"); + WARNING("Failed to remove destination " + destination_hash.toHex() + " from path table"); } // Remove announce packet from packet table if (_packet_table.erase(destination_entry._announce_packet) < 1) { - warning("Failed to remove packet " + destination_entry._announce_packet.toHex() + " from packet table"); + WARNING("Failed to remove packet " + destination_entry._announce_packet.toHex() + " from packet table"); } // Remove cached packet file std::string packet_cache_path = Reticulum::_cachepath + "/" + destination_entry._announce_packet.toHex(); diff --git a/src/Utilities/OS.cpp b/src/Utilities/OS.cpp index 70873e8..e356ef6 100644 --- a/src/Utilities/OS.cpp +++ b/src/Utilities/OS.cpp @@ -30,7 +30,7 @@ using namespace RNS::Utilities; /*static*/ bool OS::file_exists(const char* file_path) { if (!_filesystem) { - warning("file_exists: filesystem not registered"); + WARNING("file_exists: filesystem not registered"); throw std::runtime_error("Filesystem has not been registered"); } return _filesystem.do_file_exists(file_path);