diff --git a/examples/common/lora_interface/LoRaInterface.cpp b/examples/common/lora_interface/LoRaInterface.cpp index 207ad6cf..89d3c176 100644 --- a/examples/common/lora_interface/LoRaInterface.cpp +++ b/examples/common/lora_interface/LoRaInterface.cpp @@ -66,7 +66,7 @@ delay(1500); LoRa.setTxPower(power); INFO("LoRa init succeeded."); - TRACE("LoRa bandwidth is " + std::to_string(Utilities::OS::round(_bitrate/1000.0, 2)) + " Kbps"); + TRACEF("LoRa bandwidth is %s Kbps", std::to_string(Utilities::OS::round(_bitrate/1000.0, 2)).c_str()); #endif _online = true; @@ -111,10 +111,10 @@ void LoRaInterface::loop() { } /*virtual*/ void LoRaInterface::send_outgoing(const Bytes& data) { - DEBUG(toString() + ".on_outgoing: data: " + data.toHex()); + DEBUGF("%s.on_outgoing: data: %s", toString().c_str(), data.toHex().c_str()); try { if (_online) { - TRACE("LoRaInterface: sending " + std::to_string(data.size()) + " bytes..."); + TRACEF("LoRaInterface: sending %zu bytes...", data.size()); // Send packet #ifdef ARDUINO @@ -142,12 +142,12 @@ void LoRaInterface::loop() { InterfaceImpl::handle_outgoing(data); } catch (std::exception& e) { - ERROR("Could not transmit on " + toString() + ". The contained exception was: " + e.what()); + ERRORF("Could not transmit on %s. The contained exception was: %s", toString().c_str(), e.what()); } } /*virtual*/ void LoRaInterface::on_incoming(const Bytes& data) { - DEBUG(toString() + ".on_incoming: data: " + data.toHex()); + DEBUGF("%s.on_incoming: data: %s", toString().c_str(), data.toHex().c_str()); // Pass received data on to transport InterfaceImpl::handle_incoming(data); } diff --git a/examples/common/udp_interface/UDPInterface.cpp b/examples/common/udp_interface/UDPInterface.cpp index 3c52a227..8fa83f92 100644 --- a/examples/common/udp_interface/UDPInterface.cpp +++ b/examples/common/udp_interface/UDPInterface.cpp @@ -64,14 +64,14 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa } _local_port = port; _remote_port = port; - 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)); + TRACEF("UDPInterface: local host: %s", _local_host.c_str()); + TRACEF("UDPInterface: local port: %d", _local_port); + TRACEF("UDPInterface: remote host: %s", _remote_host.c_str()); + TRACEF("UDPInterface: remote port: %d", _remote_port); #ifdef ARDUINO - TRACE("UDPInterface: wifi ssid: " + _wifi_ssid); - TRACE("UDPInterface: wifi password: " + _wifi_password); + TRACEF("UDPInterface: wifi ssid: %s", _wifi_ssid.c_str()); + TRACEF("UDPInterface: wifi password: %s", _wifi_password.c_str()); // Connect to the WiFi network WiFi.begin(_wifi_ssid.c_str(), _wifi_password.c_str()); @@ -133,7 +133,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa 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)); + ERRORF("Unable to resolve local host %s", _local_host.c_str()); return false; } _local_address = *((in_addr_t*)(host_ent->h_addr_list[0])); @@ -147,7 +147,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa 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)); + ERRORF("Unable to resolve remote host %s", _remote_host.c_str()); return false; } _remote_address = *((in_addr_t*)(host_ent->h_addr_list[0])); @@ -160,7 +160,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa 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)); + ERRORF("Unable to create socket with error %d", errno); return false; } @@ -176,7 +176,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa #endif // bind to interface for listening - INFO("Binding UDP socket " + std::to_string(_socket) + " to " + std::string(_local_host) + ":" + std::to_string(_local_port)); + INFOF("Binding UDP socket %d to %s:%d", _socket, _local_host.c_str(), _local_port); sockaddr_in bind_addr; bind_addr.sin_family = AF_INET; bind_addr.sin_addr.s_addr = _local_address; @@ -184,7 +184,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa 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)); + ERRORF("Unable to bind socket with error %d", errno); return false; } #endif @@ -234,7 +234,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa } /*virtual*/ void UDPInterface::send_outgoing(const Bytes& data) { - DEBUG(toString() + ".on_outgoing: data: " + data.toHex()); + DEBUGF("%s.on_outgoing: data: %s", toString().c_str(), data.toHex().c_str()); try { if (_online) { // Send packet @@ -243,13 +243,13 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa udp.write(data.data(), data.size()); udp.endPacket(); #else - TRACE("Sending UDP packet to " + std::string(_remote_host) + ":" + std::to_string(_remote_port)); + TRACEF("Sending UDP packet to %s:%d", _remote_host.c_str(), _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)); - TRACE("Sent " + std::to_string(sent) + " bytes to " + std::string(_remote_host) + ":" + std::to_string(_remote_port)); + TRACEF("Sent %d bytes to %s:%d", sent, _remote_host.c_str(), _remote_port); #endif } @@ -257,12 +257,12 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa InterfaceImpl::handle_outgoing(data); } catch (std::exception& e) { - ERROR("Could not transmit on " + toString() + ". The contained exception was: " + e.what()); + ERRORF("Could not transmit on %s. The contained exception was: %s", toString().c_str(), e.what()); } } void UDPInterface::on_incoming(const Bytes& data) { - DEBUG(toString() + ".on_incoming: data: " + data.toHex()); + DEBUGF("%s.on_incoming: data: %s", toString().c_str(), data.toHex().c_str()); // Pass received data on to transport InterfaceImpl::handle_incoming(data); } diff --git a/examples/common/universal_filesystem/UniversalFileSystem.cpp b/examples/common/universal_filesystem/UniversalFileSystem.cpp index 80b0ae3f..e79d8edd 100644 --- a/examples/common/universal_filesystem/UniversalFileSystem.cpp +++ b/examples/common/universal_filesystem/UniversalFileSystem.cpp @@ -121,7 +121,7 @@ void UniversalFileSystem::listDir(const char* dir) { return true; } else { - ERROR("file_exists: failed to open file " + std::string(file_path)); + ERRORF("file_exists: failed to open file %s", file_path); return false; } } @@ -155,9 +155,9 @@ void UniversalFileSystem::listDir(const char* dir) { //size_t read = fread(data.writable(size), size, 1, file); read = fread(data.writable(size), 1, size, file); #endif - TRACE("read_file: read " + std::to_string(read) + " bytes from file " + std::string(file_path)); + TRACEF("read_file: read %zu bytes from file %s", read, file_path); if (read != size) { - ERROR("read_file: failed to read file " + std::string(file_path)); + ERRORF("read_file: failed to read file %s", file_path); data.clear(); } //TRACE("read_file: closing input file"); @@ -173,7 +173,7 @@ void UniversalFileSystem::listDir(const char* dir) { #endif } else { - ERROR("read_file: failed to open input file " + std::string(file_path)); + ERRORF("read_file: failed to open input file %s", file_path); } return read; } @@ -201,9 +201,9 @@ void UniversalFileSystem::listDir(const char* dir) { //size_t wrote = fwrite(data.data(), data.size(), 1, file); wrote = fwrite(data.data(), 1, data.size(), file); #endif - TRACE("write_file: wrote " + std::to_string(wrote) + " bytes to file " + std::string(file_path)); + TRACEF("write_file: wrote %zu bytes to file %s", wrote, file_path); if (wrote < data.size()) { - WARNING("write_file: not all data was written to file " + std::string(file_path)); + WARNINGF("write_file: not all data was written to file %s", file_path); } //TRACE("write_file: closing output file"); #ifdef ARDUINO @@ -218,7 +218,7 @@ void UniversalFileSystem::listDir(const char* dir) { #endif } else { - ERROR("write_file: failed to open output file " + std::string(file_path)); + ERRORF("write_file: failed to open output file %s", file_path); } return wrote; } @@ -348,7 +348,7 @@ void UniversalFileSystem::listDir(const char* dir) { } /*virtua*/ bool UniversalFileSystem::directory_exists(const char* directory_path) { - TRACE("directory_exists: checking for existence of directory " + std::string(directory_path)); + TRACEF("directory_exists: checking for existence of directory %s", directory_path); #ifdef ARDUINO #ifdef BOARD_ESP32 File file = SPIFFS.open(directory_path, FILE_READ); @@ -382,13 +382,13 @@ void UniversalFileSystem::listDir(const char* dir) { #ifdef ARDUINO #ifdef BOARD_ESP32 if (!SPIFFS.mkdir(directory_path)) { - ERROR("create_directory: failed to create directorty " + std::string(directory_path)); + ERRORF("create_directory: failed to create directorty %s", directory_path); return false; } return true; #elif BOARD_NRF52 if (!InternalFS.mkdir(directory_path)) { - ERROR("create_directory: failed to create directorty " + std::string(directory_path)); + ERRORF("create_directory: failed to create directorty %s", directory_path); return false; } return true; @@ -406,18 +406,18 @@ void UniversalFileSystem::listDir(const char* dir) { } /*virtua*/ bool UniversalFileSystem::remove_directory(const char* directory_path) { - TRACE("remove_directory: removing directory " + std::string(directory_path)); + TRACEF("remove_directory: removing directory %s", directory_path); #ifdef ARDUINO #ifdef BOARD_ESP32 //if (!LittleFS.rmdir_r(directory_path)) { if (!SPIFFS.rmdir(directory_path)) { - ERROR("remove_directory: failed to remove directorty " + std::string(directory_path)); + ERRORF("remove_directory: failed to remove directorty %s", directory_path); return false; } return true; #elif BOARD_NRF52 if (!InternalFS.rmdir_r(directory_path)) { - ERROR("remove_directory: failed to remove directory " + std::string(directory_path)); + ERRORF("remove_directory: failed to remove directory %s", directory_path); return false; } return true; @@ -431,7 +431,7 @@ void UniversalFileSystem::listDir(const char* dir) { } /*virtua*/ std::list UniversalFileSystem::list_directory(const char* directory_path) { - TRACE("list_directory: listing directory " + std::string(directory_path)); + TRACEF("list_directory: listing directory %s", directory_path); std::list files; #ifdef ARDUINO #ifdef BOARD_ESP32 @@ -440,7 +440,7 @@ void UniversalFileSystem::listDir(const char* dir) { File root = InternalFS.open(directory_path); #endif if (!root) { - ERROR("list_directory: failed to open directory " + std::string(directory_path)); + ERRORF("list_directory: failed to open directory %s", directory_path); return files; } File file = root.openNextFile(); diff --git a/examples/link_native/main.cpp b/examples/link_native/main.cpp index 7b62a1c3..19c84e4e 100644 --- a/examples/link_native/main.cpp +++ b/examples/link_native/main.cpp @@ -65,7 +65,7 @@ void server_packet_received(const RNS::Bytes& message, const RNS::Packet& packet // it will all be directed to the last client // that connected. std::string text = message.toString(); - RNS::log("Received data on the link: "+text); + RNS::logf(RNS::LOG_NOTICE, "Received data on the link: %s", text.c_str()); std::string reply_text = "I received \""+text+"\" over the link"; RNS::Bytes reply_data(reply_text); @@ -86,11 +86,7 @@ void client_connected(RNS::Link& link) { void server_loop(RNS::Destination& destination) { // Let the user know that everything is ready - RNS::log( - "Link example <"+ - destination.hash().toHex()+ - "> running, waiting for a connection." - ); + RNS::logf(RNS::LOG_NOTICE, "Link example <%s> running, waiting for a connection.", destination.hash().toHex().c_str()); RNS::log("Hit enter to manually send an announce (Ctrl-C to quit)"); @@ -105,7 +101,7 @@ void server_loop(RNS::Destination& destination) { while (read(STDIN_FILENO, &ch, 1) > 0) { if (ch == '\n') { destination.announce(); - RNS::log("Sent announce from "+destination.hash().toHex()); + RNS::logf(RNS::LOG_NOTICE, "Sent announce from %s", destination.hash().toHex().c_str()); } } } @@ -182,7 +178,7 @@ void link_closed(RNS::Link& link) { // simply print out the data. void client_packet_received(const RNS::Bytes& message, const RNS::Packet& packet) { std::string text = message.toString(); - RNS::log("Received data on the link: "+text); + RNS::logf(RNS::LOG_NOTICE, "Received data on the link: %s", text.c_str()); printf("> "); fflush(stdout); } @@ -223,12 +219,7 @@ printf("(sending data: %s)\n", text.c_str()); RNS::Packet(server_link, data).send(); } else { - RNS::log( - "Cannot send this packet, the data size of "+ - std::to_string(data.size())+" bytes exceeds the link packet MDU of "+ - std::to_string(RNS::Type::Link::MDU)+" bytes", - RNS::LOG_ERROR - ); + RNS::logf(RNS::LOG_ERROR, "Cannot send this packet, the data size of %zu bytes exceeds the link packet MDU of %zu bytes", data.size(), (size_t)RNS::Type::Link::MDU); } } diff --git a/examples/lora_announce/main.cpp b/examples/lora_announce/main.cpp index 7faba987..4314fbd4 100644 --- a/examples/lora_announce/main.cpp +++ b/examples/lora_announce/main.cpp @@ -55,13 +55,13 @@ class ExampleAnnounceHandler : public RNS::AnnounceHandler { virtual ~ExampleAnnounceHandler() {} virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); + INFOF("ExampleAnnounceHandler: destination hash: %s", destination_hash.toHex().c_str()); if (announced_identity) { - INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); - INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); + INFOF("ExampleAnnounceHandler: announced identity hash: %s", announced_identity.hash().toHex().c_str()); + INFOF("ExampleAnnounceHandler: announced identity app data: %s", announced_identity.app_data().toHex().c_str()); } if (app_data) { - INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); + INFOF("ExampleAnnounceHandler: app data text: \"%s\"", app_data.toString().c_str()); } INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -70,18 +70,18 @@ class ExampleAnnounceHandler : public RNS::AnnounceHandler { // Test packet receive callback void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("onPacket: data: " + data.toHex()); - INFO("onPacket: text: \"" + data.toString() + "\""); - //TRACE("onPacket: " + packet.debugString()); + INFOF("onPacket: data: %s", data.toHex().c_str()); + INFOF("onPacket: text: \"%s\"", data.toString().c_str()); + //TRACEF("onPacket: %s", packet.debugString().c_str()); INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } // Ping packet receive callback void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("onPingPacket: data: " + data.toHex()); - INFO("onPingPacket: text: \"" + data.toString() + "\""); - //TRACE("onPingPacket: " + packet.debugString()); + INFOF("onPingPacket: data: %s", data.toHex().c_str()); + INFOF("onPingPacket: text: \"%s\"", data.toString().c_str()); + //TRACEF("onPingPacket: %s", packet.debugString().c_str()); INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -205,14 +205,14 @@ void reticulum_setup() { HEAD("Sending send packet...", RNS::LOG_TRACE); send_packet.pack(); #ifndef NDEBUG - TRACE("Test send_packet: " + send_packet.debugString()); + TRACEF("Test send_packet: %s", send_packet.debugString().c_str()); #endif 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()); + TRACEF("Test recv_packet: %s", recv_packet.debugString().c_str()); #endif HEAD("Spoofing recv packet to destination...", RNS::LOG_TRACE); diff --git a/examples/udp_announce/main.cpp b/examples/udp_announce/main.cpp index 25cf5d27..c3b16795 100644 --- a/examples/udp_announce/main.cpp +++ b/examples/udp_announce/main.cpp @@ -56,13 +56,13 @@ class ExampleAnnounceHandler : public RNS::AnnounceHandler { virtual ~ExampleAnnounceHandler() {} virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); + INFOF("ExampleAnnounceHandler: destination hash: %s", destination_hash.toHex().c_str()); if (announced_identity) { - INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); - INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); + INFOF("ExampleAnnounceHandler: announced identity hash: %s", announced_identity.hash().toHex().c_str()); + INFOF("ExampleAnnounceHandler: announced identity app data: %s", announced_identity.app_data().toHex().c_str()); } if (app_data) { - INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); + INFOF("ExampleAnnounceHandler: app data text: \"%s\"", app_data.toString().c_str()); } INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -71,18 +71,18 @@ class ExampleAnnounceHandler : public RNS::AnnounceHandler { // Test packet receive callback void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("onPacket: data: " + data.toHex()); - INFO("onPacket: text: \"" + data.toString() + "\""); - //TRACE("onPacket: " + packet.debugString()); + INFOF("onPacket: data: %s", data.toHex().c_str()); + INFOF("onPacket: text: \"%s\"", data.toString().c_str()); + //TRACEF("onPacket: %s", packet.debugString().c_str()); INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } // Ping packet receive callback void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("onPingPacket: data: " + data.toHex()); - INFO("onPingPacket: text: \"" + data.toString() + "\""); - //TRACE("onPingPacket: " + packet.debugString()); + INFOF("onPingPacket: data: %s", data.toHex().c_str()); + INFOF("onPingPacket: text: \"%s\"", data.toString().c_str()); + //TRACEF("onPingPacket: %s", packet.debugString().c_str()); INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -198,14 +198,14 @@ void reticulum_setup() { HEAD("Sending send packet...", RNS::LOG_TRACE); send_packet.pack(); #ifndef NDEBUG - TRACE("Test send_packet: " + send_packet.debugString()); + TRACEF("Test send_packet: %s", send_packet.debugString().c_str()); #endif 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()); + TRACEF("Test recv_packet: %s", recv_packet.debugString().c_str()); #endif HEAD("Spoofing recv packet to destination...", RNS::LOG_TRACE); diff --git a/src/Channel.h b/src/Channel.h index 4425be7b..4cbe7927 100644 --- a/src/Channel.h +++ b/src/Channel.h @@ -39,8 +39,8 @@ namespace RNS { private: class Object { public: - Object() { MEM("Channel::Data object created, this: " + std::to_string((uintptr_t)this)); } - virtual ~Object() { MEM("Channel::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } + Object() { MEMF("Channel::Data object created, this: %p", (void*)this); } + virtual ~Object() { MEMF("Channel::Data object destroyed, this: %p", (void*)this); } private: friend class Channel; diff --git a/src/Cryptography/Fernet.cpp b/src/Cryptography/Fernet.cpp index f70bc6e5..a6faf20d 100644 --- a/src/Cryptography/Fernet.cpp +++ b/src/Cryptography/Fernet.cpp @@ -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()); + DEBUGF("Fernet::verify_hmac: received_hmac: %s", received_hmac.toHex().c_str()); //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()); + DEBUGF("Fernet::verify_hmac: expected_hmac: %s", expected_hmac.toHex().c_str()); return (received_hmac == expected_hmac); } const Bytes Fernet::encrypt(const Bytes& data) { - DEBUG("Fernet::encrypt: plaintext length: " + std::to_string(data.size())); + DEBUGF("Fernet::encrypt: plaintext length: %zu", data.size()); Bytes iv = random(16); //double current_time = OS::time(); - TRACE("Fernet::encrypt: iv: " + iv.toHex()); + TRACEF("Fernet::encrypt: iv: %s", iv.toHex().c_str()); - TRACE("Fernet::encrypt: plaintext: " + data.toHex()); + TRACEF("Fernet::encrypt: plaintext: %s", data.toHex().c_str()); Bytes ciphertext = AES_128_CBC::encrypt( PKCS7::pad(data), _encryption_key, iv ); - DEBUG("Fernet::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size())); - TRACE("Fernet::encrypt: ciphertext: " + ciphertext.toHex()); + DEBUGF("Fernet::encrypt: padded ciphertext length: %zu", ciphertext.size()); + TRACEF("Fernet::encrypt: ciphertext: %s", ciphertext.toHex().c_str()); Bytes signed_parts = iv + ciphertext; //return signed_parts + HMAC::generate(_signing_key, signed_parts)->digest(); Bytes sig(HMAC::generate(_signing_key, signed_parts)->digest()); - TRACE("Fernet::encrypt: sig: " + sig.toHex()); + TRACEF("Fernet::encrypt: sig: %s", sig.toHex().c_str()); Bytes token(signed_parts + sig); - DEBUG("Fernet::encrypt: token length: " + std::to_string(token.size())); + DEBUGF("Fernet::encrypt: token length: %zu", token.size()); return token; } const Bytes Fernet::decrypt(const Bytes& token) { - DEBUG("Fernet::decrypt: token length: " + std::to_string(token.size())); + DEBUGF("Fernet::decrypt: token length: %zu", 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); - TRACE("Fernet::decrypt: iv: " + iv.toHex()); + TRACEF("Fernet::decrypt: iv: %s", iv.toHex().c_str()); //ciphertext = token[16:-32] Bytes ciphertext = token.mid(16, token.size()-48); - TRACE("Fernet::decrypt: ciphertext: " + ciphertext.toHex()); + TRACEF("Fernet::decrypt: ciphertext: %s", ciphertext.toHex().c_str()); 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())); - TRACE("Fernet::decrypt: plaintext: " + plaintext.toHex()); + DEBUGF("Fernet::encrypt: unpadded plaintext length: %zu", plaintext.size()); + TRACEF("Fernet::decrypt: plaintext: %s", plaintext.toHex().c_str()); - DEBUG("Fernet::decrypt: plaintext length: " + std::to_string(plaintext.size())); + DEBUGF("Fernet::decrypt: plaintext length: %zu", plaintext.size()); return plaintext; } catch (std::exception& e) { diff --git a/src/Cryptography/Hashes.cpp b/src/Cryptography/Hashes.cpp index 5687efa3..b7fd4f86 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) { - //TRACE("Cryptography::sha256: data: " + data.toHex() ); + //TRACEF("Cryptography::sha256: data: %s", data.toHex().c_str()); SHA256 digest; digest.reset(); digest.update(data.data(), data.size()); Bytes hash; digest.finalize(hash.writable(32), 32); - //TRACE("Cryptography::sha256: hash: " + hash.toHex() ); + //TRACEF("Cryptography::sha256: hash: %s", hash.toHex().c_str()); 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); - //TRACE("Cryptography::sha512: hash: " + hash.toHex() ); + //TRACEF("Cryptography::sha512: hash: %s", hash.toHex().c_str()); return hash; } diff --git a/src/Cryptography/PKCS7.h b/src/Cryptography/PKCS7.h index 4167d31e..475e6fa7 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)); + //DEBUGF("PKCS7::pad: len: %zu", len); size_t padlen = bs - (len % bs); - //DEBUG("PKCS7::pad: pad len: " + std::to_string(padlen)); + //DEBUGF("PKCS7::pad: pad len: %zu", 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())); + //DEBUGF("PKCS7::pad: data size: %zu", 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)); + //DEBUGF("PKCS7::unpad: len: %zu", 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)); + //DEBUGF("PKCS7::unpad: pad len: %zu", 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())); + //DEBUGF("PKCS7::unpad: data size: %zu", data.size()); } }; diff --git a/src/Cryptography/Token.cpp b/src/Cryptography/Token.cpp index e91c7e80..18c9079d 100644 --- a/src/Cryptography/Token.cpp +++ b/src/Cryptography/Token.cpp @@ -56,22 +56,22 @@ bool Token::verify_hmac(const Bytes& token) { //received_hmac = token[-32:] Bytes received_hmac = token.right(32); - DEBUG("Token::verify_hmac: received_hmac: " + received_hmac.toHex()); + DEBUGF("Token::verify_hmac: received_hmac: %s", received_hmac.toHex().c_str()); //expected_hmac = HMAC.new(self._signing_key, token[:-32]).digest() Bytes expected_hmac = HMAC::generate(_signing_key, token.left(token.size()-32))->digest(); - DEBUG("Token::verify_hmac: expected_hmac: " + expected_hmac.toHex()); + DEBUGF("Token::verify_hmac: expected_hmac: %s", expected_hmac.toHex().c_str()); return (received_hmac == expected_hmac); } const Bytes Token::encrypt(const Bytes& data) { - DEBUG("Token::encrypt: plaintext length: " + std::to_string(data.size())); + DEBUGF("Token::encrypt: plaintext length: %zu", data.size()); Bytes iv = random(16); //double current_time = OS::time(); - TRACE("Token::encrypt: iv: " + iv.toHex()); + TRACEF("Token::encrypt: iv: %s", iv.toHex().c_str()); - TRACE("Token::encrypt: plaintext: " + data.toHex()); + TRACEF("Token::encrypt: plaintext: %s", data.toHex().c_str()); Bytes ciphertext; if (_mode == MODE_AES_128_CBC) { ciphertext = AES_128_CBC::encrypt( @@ -90,23 +90,23 @@ const Bytes Token::encrypt(const Bytes& data) { else { throw new std::invalid_argument("Invalid token mode "+std::to_string(_mode)); } - DEBUG("Token::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size())); - TRACE("Token::encrypt: ciphertext: " + ciphertext.toHex()); + DEBUGF("Token::encrypt: padded ciphertext length: %zu", ciphertext.size()); + TRACEF("Token::encrypt: ciphertext: %s", ciphertext.toHex().c_str()); Bytes signed_parts = iv + ciphertext; //return signed_parts + HMAC::generate(_signing_key, signed_parts)->digest(); Bytes sig(HMAC::generate(_signing_key, signed_parts)->digest()); - TRACE("Token::encrypt: sig: " + sig.toHex()); + TRACEF("Token::encrypt: sig: %s", sig.toHex().c_str()); Bytes token(signed_parts + sig); - DEBUG("Token::encrypt: token length: " + std::to_string(token.size())); + DEBUGF("Token::encrypt: token length: %zu", token.size()); return token; } const Bytes Token::decrypt(const Bytes& token) { - DEBUG("Token::decrypt: token length: " + std::to_string(token.size())); + DEBUGF("Token::decrypt: token length: %zu", token.size()); if (token.size() < 48) { throw std::invalid_argument("Cannot decrypt token of only " + std::to_string(token.size()) + " bytes"); } @@ -117,11 +117,11 @@ const Bytes Token::decrypt(const Bytes& token) { //iv = token[:16] Bytes iv = token.left(16); - TRACE("Token::decrypt: iv: " + iv.toHex()); + TRACEF("Token::decrypt: iv: %s", iv.toHex().c_str()); //ciphertext = token[16:-32] Bytes ciphertext = token.mid(16, token.size()-48); - TRACE("Token::decrypt: ciphertext: " + ciphertext.toHex()); + TRACEF("Token::decrypt: ciphertext: %s", ciphertext.toHex().c_str()); try { Bytes plaintext; @@ -146,10 +146,10 @@ const Bytes Token::decrypt(const Bytes& token) { else { throw new std::invalid_argument("Invalid token mode "+std::to_string(_mode)); } - DEBUG("Token::encrypt: unpadded plaintext length: " + std::to_string(plaintext.size())); - TRACE("Token::decrypt: plaintext: " + plaintext.toHex()); + DEBUGF("Token::encrypt: unpadded plaintext length: %zu", plaintext.size()); + TRACEF("Token::decrypt: plaintext: %s", plaintext.toHex().c_str()); - DEBUG("Token::decrypt: plaintext length: " + std::to_string(plaintext.size())); + DEBUGF("Token::decrypt: plaintext length: %zu", plaintext.size()); return plaintext; } catch (std::exception& e) { diff --git a/src/Cryptography/X25519.h b/src/Cryptography/X25519.h index 75c009b1..f1628db5 100644 --- a/src/Cryptography/X25519.h +++ b/src/Cryptography/X25519.h @@ -170,26 +170,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()); + DEBUGF("X25519PublicKey::exchange: public key: %s", _publicKey.toHex().c_str()); + DEBUGF("X25519PublicKey::exchange: peer public key: %s", peer_public_key.toHex().c_str()); + DEBUGF("X25519PublicKey::exchange: pre private key: %s", _privateKey.toHex().c_str()); 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()); + DEBUGF("X25519PublicKey::exchange: shared key: %s", sharedKey.toHex().c_str()); + DEBUGF("X25519PublicKey::exchange: post private key: %s", _privateKey.toHex().c_str()); 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()); + DEBUGF("X25519PublicKey::exchange: public key: %s", _publicKey.toHex().c_str()); + DEBUGF("X25519PublicKey::exchange: peer public key: %s", peer_public_key.toHex().c_str()); + DEBUGF("X25519PublicKey::exchange: pre private key: %s", _privateKey.toHex().c_str()); 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()); + DEBUGF("X25519PublicKey::exchange: shared key: %s", sharedKey.toHex().c_str()); + DEBUGF("X25519PublicKey::exchange: post private key: %s", _privateKey.toHex().c_str()); return success; } diff --git a/src/Destination.cpp b/src/Destination.cpp index 957d05d8..88c0e97b 100644 --- a/src/Destination.cpp +++ b/src/Destination.cpp @@ -15,13 +15,13 @@ 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())); + MEMF("Destination object creating..., this: %p, data: %p", (void*)this, (void*)_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"); } - //TRACE("Destination::Destination: app name: " + std::string(app_name)); + //TRACEF("Destination::Destination: app name: %s", app_name); _object->_type = type; _object->_direction = direction; @@ -33,34 +33,34 @@ Destination::Destination(const Identity& identity, const directions direction, c // CBA TODO determine why identity.hexhash is added both here and by expand_name called below fullaspects += "." + _object->_identity.hexhash(); } - //TRACE("Destination::Destination: full aspects: " + fullaspects); + //TRACEF("Destination::Destination: full aspects: %s", fullaspects.c_str()); 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()); - //TRACE("Destination::Destination: name: " + _object->_name); + //TRACEF("Destination::Destination: name: %s", _object->_name.c_str()); // Generate the destination address hash //TRACE("Destination::Destination: creating hash..."); _object->_hash = hash(_object->_identity, app_name, fullaspects.c_str()); _object->_hexhash = _object->_hash.toHex(); - TRACE("Destination::Destination: hash: " + _object->_hash.toHex()); + TRACEF("Destination::Destination: hash: %s", _object->_hash.toHex().c_str()); //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); - //TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex()); + //TRACEF("Destination::Destination: name hash: %s", _object->_name_hash.toHex().c_str()); //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())); + MEMF("Destination object created, this: %p, data: %p", (void*)this, (void*)_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())); + MEMF("Destination object creating..., this: %p, data: %p", (void*)this, (void*)_object.get()); _object->_type = type; _object->_direction = direction; @@ -71,20 +71,20 @@ Destination::Destination(const Identity& identity, const Type::Destination::dire _object->_hash = hash; _object->_hexhash = _object->_hash.toHex(); - TRACE("Destination::Destination: hash: " + _object->_hash.toHex()); + TRACEF("Destination::Destination: hash: %s", _object->_hash.toHex().c_str()); //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"); - //TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex()); + //TRACEF("Destination::Destination: name hash: %s", _object->_name_hash.toHex().c_str()); //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())); + MEMF("Destination object created, this: %p, data: %p", (void*)this, (void*)_object.get()); } /*virtual*/ Destination::~Destination() { - MEM("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Destination object destroyed, this: %p, data: %p", (void*)this, (void*)_object.get()); if (_object && _object.use_count() == 1) { MEM("Destination object has last data reference"); @@ -225,12 +225,12 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In if (!tag.empty()) { 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())); + DEBUGF("Destination::announce: tag: %s", tagstr.c_str()); + DEBUGF("Destination::announce: tag len: %zu", tag.size()); TRACE("Destination::announce: searching for tag..."); if (_object->_path_responses.find(tag) != _object->_path_responses.end()) { TRACE("Destination::announce: found tag in _path_responses"); - DEBUG(std::string("Destination::announce: data: ") +_object->_path_responses[tag].second.toString()); + DEBUGF("Destination::announce: data: %s", _object->_path_responses[tag].second.toString().c_str()); } else { TRACE("Destination::announce: tag not found in _path_responses"); @@ -248,7 +248,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 TRACE("Using cached announce data for answering path request with tag "+RNS.prettyhexrep(tag)); + //z TRACEF("Using cached announce data for answering path request with tag %s", RNS.prettyhexrep(tag).c_str()); announce_data << _object->_path_responses[tag].second; } else { @@ -263,20 +263,20 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In } Bytes signed_data; - //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()); + //TRACEF("Destination::announce: hash: %s", _object->_hash.toHex().c_str()); + //TRACEF("Destination::announce: public key: %s", _object->_identity.get_public_key().toHex().c_str()); + //TRACEF("Destination::announce: name hash: %s", _object->_name_hash.toHex().c_str()); + //TRACEF("Destination::announce: random hash: %s", random_hash.toHex().c_str()); + //TRACEF("Destination::announce: app data: %s", new_app_data.toHex().c_str()); + //TRACEF("Destination::announce: app data text:%s", new_app_data.toString().c_str()); signed_data << _object->_hash << _object->_identity.get_public_key() << _object->_name_hash << random_hash; if (new_app_data) { signed_data << new_app_data; } - //TRACE("Destination::announce: signed data: " + signed_data.toHex()); + //TRACEF("Destination::announce: signed data: %s", signed_data.toHex().c_str()); Bytes signature(_object->_identity.sign(signed_data)); - //TRACE("Destination::announce: signature: " + signature.toHex()); + //TRACEF("Destination::announce: signature: %s", signature.toHex().c_str()); announce_data << _object->_identity.get_public_key() << _object->_name_hash << random_hash << signature; @@ -289,13 +289,13 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In _object->_path_responses.insert({tag, {OS::time(), announce_data}}); } catch (const std::bad_alloc&) { - ERROR("announce: bad_alloc - out of memory, path response not stored for " + _object->_hash.toHex()); + ERRORF("announce: bad_alloc - out of memory, path response not stored for %s", _object->_hash.toHex().c_str()); } catch (const std::exception& e) { - ERROR(std::string("announce: exception storing path response: ") + e.what()); + ERRORF("announce: exception storing path response: %s", e.what()); } } - //TRACE("Destination::announce: announce_data:" + announce_data.toHex()); + //TRACEF("Destination::announce: announce_data:%s", announce_data.toHex().c_str()); Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE; if (path_response) { @@ -317,11 +317,11 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In } } catch (const std::bad_alloc&) { - ERROR("announce: bad_alloc - out of memory, announce not sent for " + _object->_hash.toHex()); + ERRORF("announce: bad_alloc - out of memory, announce not sent for %s", _object->_hash.toHex().c_str()); return {Type::NONE}; } catch (const std::exception& e) { - ERROR(std::string("announce: exception during announce: ") + e.what()); + ERRORF("announce: exception during announce: %s", e.what()); return {Type::NONE}; } } @@ -381,7 +381,7 @@ void Destination::receive(const Packet& packet) { else { // CBA TODO Why isn't the Packet decrypting itself? Bytes plaintext(decrypt(packet.data())); - //TRACE("Destination::receive: decrypted data: " + plaintext.toHex()); + //TRACEF("Destination::receive: decrypted data: %s", plaintext.toHex().c_str()); if (plaintext) { if (packet.packet_type() == Type::Packet::DATA) { if (_object->_callbacks._packet) { @@ -389,7 +389,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()); + DEBUGF("Error while executing receive callback from %s. The contained exception was: %s", toString().c_str(), e.what()); } } } @@ -410,7 +410,7 @@ TRACE("***** Accepting link request"); ERROR("incoming_link_request: bad_alloc - out of memory, link not tracked"); } catch (const std::exception& e) { - ERROR(std::string("incoming_link_request: exception tracking link: ") + e.what()); + ERRORF("incoming_link_request: exception tracking link: %s", e.what()); } } } diff --git a/src/Destination.h b/src/Destination.h index f741c9ca..6eba0a61 100644 --- a/src/Destination.h +++ b/src/Destination.h @@ -73,10 +73,10 @@ namespace RNS { public: Destination(Type::NoneConstructor none) { - MEM("Destination NONE object created, this: " + std::to_string((uintptr_t)this)); + MEMF("Destination NONE object created, this: %p", (void*)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())); + MEMF("Destination object copy created, this: %p, data: %p", (void*)this, (void*)_object.get()); } Destination( const Identity& identity, @@ -95,7 +95,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())); + MEMF("Destination object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get()); return *this; } inline operator bool() const { @@ -212,8 +212,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) { MEMF("Destination::Data object created, this: %p", (void*)this); } + virtual ~Object() { MEMF("Destination::Data object destroyed, this: %p", (void*)this); } private: bool _accept_link_requests = true; Callbacks _callbacks; diff --git a/src/Identity.cpp b/src/Identity.cpp index d2ac586e..03b84f11 100644 --- a/src/Identity.cpp +++ b/src/Identity.cpp @@ -33,7 +33,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())); + MEMF("Identity object created, this: %p, data: %p", (void*)this, (void*)_object.get()); } void Identity::createKeys() { @@ -42,26 +42,26 @@ void Identity::createKeys() { // CRYPTO: create encryption private keys _object->_prv = Cryptography::X25519PrivateKey::generate(); _object->_prv_bytes = _object->_prv->private_bytes(); - //TRACE("Identity::createKeys: prv bytes: " + _object->_prv_bytes.toHex()); + //TRACEF("Identity::createKeys: prv bytes: %s", _object->_prv_bytes.toHex().c_str()); // CRYPTO: create signature private keys _object->_sig_prv = Cryptography::Ed25519PrivateKey::generate(); _object->_sig_prv_bytes = _object->_sig_prv->private_bytes(); - //TRACE("Identity::createKeys: sig prv bytes: " + _object->_sig_prv_bytes.toHex()); + //TRACEF("Identity::createKeys: sig prv bytes: %s", _object->_sig_prv_bytes.toHex().c_str()); // CRYPTO: create encryption public keys _object->_pub = _object->_prv->public_key(); _object->_pub_bytes = _object->_pub->public_bytes(); - //TRACE("Identity::createKeys: pub bytes: " + _object->_pub_bytes.toHex()); + //TRACEF("Identity::createKeys: pub bytes: %s", _object->_pub_bytes.toHex().c_str()); // CRYPTO: create signature public keys _object->_sig_pub = _object->_sig_prv->public_key(); _object->_sig_pub_bytes = _object->_sig_pub->public_bytes(); - //TRACE("Identity::createKeys: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); + //TRACEF("Identity::createKeys: sig pub bytes: %s", _object->_sig_pub_bytes.toHex().c_str()); update_hashes(); - VERBOSE("Identity keys created for " + _object->_hash.toHex()); + VERBOSEF("Identity keys created for %s", _object->_hash.toHex().c_str()); } /* @@ -78,20 +78,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); - //TRACE("Identity::load_private_key: prv bytes: " + _object->_prv_bytes.toHex()); + //TRACEF("Identity::load_private_key: prv bytes: %s", _object->_prv_bytes.toHex().c_str()); //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); - //TRACE("Identity::load_private_key: sig prv bytes: " + _object->_sig_prv_bytes.toHex()); + //TRACEF("Identity::load_private_key: sig prv bytes: %s", _object->_sig_prv_bytes.toHex().c_str()); _object->_pub = _object->_prv->public_key(); _object->_pub_bytes = _object->_pub->public_bytes(); - //TRACE("Identity::load_private_key: pub bytes: " + _object->_pub_bytes.toHex()); + //TRACEF("Identity::load_private_key: pub bytes: %s", _object->_pub_bytes.toHex().c_str()); _object->_sig_pub = _object->_sig_prv->public_key(); _object->_sig_pub_bytes = _object->_sig_pub->public_bytes(); - //TRACE("Identity::load_private_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); + //TRACEF("Identity::load_private_key: sig pub bytes: %s", _object->_sig_pub_bytes.toHex().c_str()); update_hashes(); @@ -118,11 +118,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); - //TRACE("Identity::load_public_key: pub bytes: " + _object->_pub_bytes.toHex()); + //TRACEF("Identity::load_public_key: pub bytes: ", _object->_pub_bytes.toHex().c_str()); //_sig_pub_bytes = pub_bytes[Identity.KEYSIZE//8//2:] _object->_sig_pub_bytes = pub_bytes.mid(Type::Identity::KEYSIZE/8/2); - //TRACE("Identity::load_public_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex()); + //TRACEF("Identity::load_public_key: sig pub bytes: ", _object->_sig_pub_bytes.toHex().c_str()); _object->_pub = X25519PublicKey::from_public_bytes(_object->_pub_bytes); _object->_sig_pub = Ed25519PublicKey::from_public_bytes(_object->_sig_pub_bytes); @@ -147,7 +147,7 @@ bool Identity::load(const char* path) { } } catch (std::exception& e) { - ERROR("Error while loading identity from " + std::string(path)); + ERRORF("Error while loading identity from %s", path); ERRORF("The contained exception was: %s", e.what()); } #endif @@ -205,10 +205,10 @@ Can be used to load previously created and saved identities into Reticulum. cull_known_destinations(); } catch (const std::bad_alloc&) { - ERROR("remember: bad_alloc - out of memory, identity not stored for " + destination_hash.toHex()); + ERRORF("remember: bad_alloc - out of memory, identity not stored for %s", destination_hash.toHex().c_str()); } catch (const std::exception& e) { - ERROR(std::string("remember: exception storing identity: ") + e.what()); + ERRORF("remember: exception storing identity: %s", e.what()); } } } @@ -223,7 +223,7 @@ Recall identity for a destination hash. TRACE("Identity::recall..."); auto iter = _known_destinations.find(destination_hash); if (iter != _known_destinations.end()) { - TRACE("Identity::recall: Found identity entry for destination " + destination_hash.toHex()); + TRACEF("Identity::recall: Found identity entry for destination %s", destination_hash.toHex().c_str()); const IdentityEntry& identity_data = (*iter).second; Identity identity(false); identity.load_public_key(identity_data._public_key); @@ -231,16 +231,16 @@ Recall identity for a destination hash. return identity; } else { - TRACE("Identity::recall: Unable to find identity entry for destination " + destination_hash.toHex() + ", performing destination lookup..."); + TRACEF("Identity::recall: Unable to find identity entry for destination %s, performing destination lookup...", destination_hash.toHex().c_str()); Destination registered_destination(Transport::find_destination_from_hash(destination_hash)); if (registered_destination) { - TRACE("Identity::recall: Found destination " + destination_hash.toHex()); + TRACEF("Identity::recall: Found destination %s", destination_hash.toHex().c_str()); Identity identity(false); identity.load_public_key(registered_destination.identity().get_public_key()); identity.app_data({Bytes::NONE}); return identity; } - TRACE("Identity::recall: Unable to find destination " + destination_hash.toHex()); + TRACEF("Identity::recall: Unable to find destination %s", destination_hash.toHex().c_str()); return {Type::NONE}; } } @@ -255,12 +255,12 @@ Recall last heard app_data for a destination hash. TRACE("Identity::recall_app_data..."); auto iter = _known_destinations.find(destination_hash); if (iter != _known_destinations.end()) { - TRACE("Identity::recall_app_data: Found identity entry for destination " + destination_hash.toHex()); + TRACEF("Identity::recall_app_data: Found identity entry for destination %s", destination_hash.toHex().c_str()); const IdentityEntry& identity_data = (*iter).second; return identity_data._app_data; } else { - TRACE("Identity::recall_app_data: Unable to find identity entry for destination " + destination_hash.toHex()); + TRACEF("Identity::recall_app_data: Unable to find identity entry for destination %s", destination_hash.toHex().c_str()); return {Bytes::NONE}; } } @@ -315,7 +315,7 @@ Recall last heard app_data for a destination hash. // TODO /* - DEBUG("Saving " + std::to_string(_known_destinations.size()) + " known destinations to storage..."); + DEBUGF("Saving %zu known destinations to storage...", _known_destinations.size()); file = open(RNS.Reticulum.storagepath+"/known_destinations","wb") umsgpack.dump(Identity.known_destinations, file) file.close() @@ -330,7 +330,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); + DEBUGF("Saved known destinations to storage in %s", time_str.c_str()); success = true; } @@ -382,16 +382,16 @@ Recall last heard app_data for a destination hash. uint16_t count = 0; for (const auto& [timestamp, destination_hash] : sorted_keys) { - TRACE("Identity::cull_known_destinations: Removing destination " + destination_hash.toHex() + " from known destinations"); + TRACEF("Identity::cull_known_destinations: Removing destination %s from known destinations", destination_hash.toHex().c_str()); if (_known_destinations.erase(destination_hash) < 1) { - WARNING("Failed to remove destination " + destination_hash.toHex() + " from known destinations"); + WARNINGF("Failed to remove destination %s from known destinations", destination_hash.toHex().c_str()); } ++count; if (_known_destinations.size() <= _known_destinations_maxsize) { break; } } - DEBUG("Removed " + std::to_string(count) + " path(s) from known destinations"); + DEBUGF("Removed %d path(s) from known destinations", count); } catch (const std::bad_alloc& e) { ERROR("cull_known_destinations: bad_alloc - out of memory building sort index, falling back to single erase"); @@ -408,7 +408,7 @@ Recall last heard app_data for a destination hash. } } catch (const std::exception& e) { - ERROR(std::string("cull_known_destinations: exception: ") + e.what()); + ERRORF("cull_known_destinations: exception: %s", e.what()); } } } @@ -417,25 +417,25 @@ Recall last heard app_data for a destination hash. try { if (packet.packet_type() == Type::Packet::ANNOUNCE) { Bytes destination_hash = packet.destination_hash(); - //TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex()); + //TRACEF("Identity::validate_announce: destination_hash: %s", packet.destination_hash().toHex().c_str()); Bytes public_key = packet.data().left(KEYSIZE/8); - //TRACE("Identity::validate_announce: public_key: " + public_key.toHex()); + //TRACEF("Identity::validate_announce: public_key: %s", public_key.toHex().c_str()); Bytes name_hash = packet.data().mid(KEYSIZE/8, NAME_HASH_LENGTH/8); - //TRACE("Identity::validate_announce: name_hash: " + name_hash.toHex()); + //TRACEF("Identity::validate_announce: name_hash: %s", name_hash.toHex().c_str()); Bytes random_hash = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8, RANDOM_HASH_LENGTH/8); - //TRACE("Identity::validate_announce: random_hash: " + random_hash.toHex()); + //TRACEF("Identity::validate_announce: random_hash: %s", random_hash.toHex().c_str()); Bytes signature = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8, SIGLENGTH/8); - //TRACE("Identity::validate_announce: signature: " + signature.toHex()); + //TRACEF("Identity::validate_announce: signature: %s", signature.toHex().c_str()); 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); } - //TRACE("Identity::validate_announce: app_data: " + app_data.toHex()); - //TRACE("Identity::validate_announce: app_data text: " + app_data.toString()); + //TRACEF("Identity::validate_announce: app_data: %s", app_data.toHex().c_str()); + //TRACEF("Identity::validate_announce: app_data text: %s", app_data.toString().c_str()); Bytes signed_data; signed_data << packet.destination_hash() << public_key << name_hash << random_hash+app_data; - //TRACE("Identity::validate_announce: signed_data: " + signed_data.toHex()); + //TRACEF("Identity::validate_announce: signed_data: %s", signed_data.toHex().c_str()); if (packet.data().size() <= KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8) { app_data.clear(); @@ -447,8 +447,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); - //TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex()); - //TRACE("Identity::validate_announce: expected_hash: " + expected_hash.toHex()); + //TRACEF("Identity::validate_announce: destination_hash: %s", packet.destination_hash().toHex().c_str()); + //TRACEF("Identity::validate_announce: expected_hash: %s", expected_hash.toHex().c_str()); if (packet.destination_hash() == expected_hash) { // Check if we already have a public key for this destination @@ -485,28 +485,28 @@ Recall last heard app_data for a destination hash. */ if (packet.transport_id()) { - 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); + TRACEF("Valid announce for %s %d hops away, received via %s on %s%s", packet.destination_hash().toHex().c_str(), packet.hops(), packet.transport_id().toHex().c_str(), packet.receiving_interface().toString().c_str(), signal_str.c_str()); } else { - TRACE("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received on " + packet.receiving_interface().toString() + signal_str); + TRACEF("Valid announce for %s %d hops away, received on %s%s", packet.destination_hash().toHex().c_str(), packet.hops(), packet.receiving_interface().toString().c_str(), signal_str.c_str()); } return true; } else { - DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Destination mismatch."); + DEBUGF("Received invalid announce for %s: Destination mismatch.", packet.destination_hash().toHex().c_str()); return false; } } else { - DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Invalid signature."); + DEBUGF("Received invalid announce for %s: Invalid signature.", packet.destination_hash().toHex().c_str()); //p del announced_identity return false; } } } catch (std::exception& e) { - ERROR("Error occurred while validating announce. The contained exception was: " + std::string(e.what())); + ERRORF("Error occurred while validating announce. The contained exception was: %s", e.what()); return false; } return false; @@ -537,12 +537,12 @@ const Bytes Identity::encrypt(const Bytes& plaintext) const { } Cryptography::X25519PrivateKey::Ptr ephemeral_key = Cryptography::X25519PrivateKey::generate(); Bytes ephemeral_pub_bytes = ephemeral_key->public_key()->public_bytes(); - TRACE("Identity::encrypt: ephemeral public key: " + ephemeral_pub_bytes.toHex()); + TRACEF("Identity::encrypt: ephemeral public key: %s", ephemeral_pub_bytes.toHex().c_str()); // 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); - TRACE("Identity::encrypt: shared key: " + shared_key.toHex()); + TRACEF("Identity::encrypt: shared key: %s", shared_key.toHex().c_str()); Bytes derived_key = Cryptography::hkdf( DERIVED_KEY_LENGTH, @@ -550,13 +550,13 @@ const Bytes Identity::encrypt(const Bytes& plaintext) const { get_salt(), get_context() ); - TRACE("Identity::encrypt: derived key: " + derived_key.toHex()); + TRACEF("Identity::encrypt: derived key: %s", derived_key.toHex().c_str()); Cryptography::Token token(derived_key); - TRACE("Identity::encrypt: Token encrypting data of length " + std::to_string(plaintext.size())); - TRACE("Identity::encrypt: plaintext: " + plaintext.toHex()); + TRACEF("Identity::encrypt: Token encrypting data of length %zu", plaintext.size()); + TRACEF("Identity::encrypt: plaintext: %s", plaintext.toHex().c_str()); Bytes ciphertext = token.encrypt(plaintext); - TRACE("Identity::encrypt: ciphertext: " + ciphertext.toHex()); + TRACEF("Identity::encrypt: ciphertext: %s", ciphertext.toHex().c_str()); return ephemeral_pub_bytes + ciphertext; } @@ -576,7 +576,7 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const { 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."); + DEBUGF("Decryption failed because the token size %zu was invalid.", ciphertext_token.size()); return {Bytes::NONE}; } Bytes plaintext; @@ -585,12 +585,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); - TRACE("Identity::decrypt: peer public key: " + peer_pub_bytes.toHex()); + TRACEF("Identity::decrypt: peer public key: %s", peer_pub_bytes.toHex().c_str()); // 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); - TRACE("Identity::decrypt: shared key: " + shared_key.toHex()); + TRACEF("Identity::decrypt: shared key: %s", shared_key.toHex().c_str()); Bytes derived_key = Cryptography::hkdf( DERIVED_KEY_LENGTH, @@ -598,19 +598,19 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const { get_salt(), get_context() ); - TRACE("Identity::decrypt: derived key: " + derived_key.toHex()); + TRACEF("Identity::decrypt: derived key: %s", derived_key.toHex().c_str()); Cryptography::Token token(derived_key); //ciphertext = ciphertext_token[Identity.KEYSIZE//8//2:] Bytes ciphertext(ciphertext_token.mid(Type::Identity::KEYSIZE/8/2)); - TRACE("Identity::decrypt: Token decrypting data of length " + std::to_string(ciphertext.size())); - TRACE("Identity::decrypt: ciphertext: " + ciphertext.toHex()); + TRACEF("Identity::decrypt: Token decrypting data of length %zu", ciphertext.size()); + TRACEF("Identity::decrypt: ciphertext: %s", ciphertext.toHex().c_str()); plaintext = token.decrypt(ciphertext); - TRACE("Identity::decrypt: plaintext: " + plaintext.toHex()); - //TRACE("Identity::decrypt: Token decrypted data of length " + std::to_string(plaintext.size())); + TRACEF("Identity::decrypt: plaintext: %s", plaintext.toHex().c_str()); + //TRACEF("Identity::decrypt: Token decrypted data of length %s", std::to_string(plaintext.size()).c_str()); } catch (std::exception& e) { - DEBUG("Decryption by " + toString() + " failed: " + e.what()); + DEBUGF("Decryption by %s failed: %s", toString().c_str(), e.what()); } return plaintext; @@ -632,7 +632,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()); + ERRORF("The identity %s could not sign the requested message. The contained exception was: %s", toString().c_str(), e.what()); throw e; } } @@ -649,7 +649,7 @@ bool Identity::validate(const Bytes& signature, const Bytes& message) const { assert(_object); if (_object->_pub) { try { - TRACE("Identity::validate: Attempting to verify signature: " + signature.toHex() + " and message: " + message.toHex()); + TRACEF("Identity::validate: Attempting to verify signature: %s and message: %s", signature.toHex().c_str(), message.toHex().c_str()); _object->_sig_pub->verify(signature, message); return true; } @@ -668,11 +668,11 @@ void Identity::prove(const Packet& packet, const Destination& destination /*= {T Bytes proof_data; if (RNS::Reticulum::should_use_implicit_proof()) { proof_data = signature; - TRACE("Identity::prove: implicit proof data: " + proof_data.toHex()); + TRACEF("Identity::prove: implicit proof data: %s", proof_data.toHex().c_str()); } else { proof_data = packet.packet_hash() + signature; - TRACE("Identity::prove: explicit proof data: " + proof_data.toHex()); + TRACEF("Identity::prove: explicit proof data: %s", proof_data.toHex().c_str()); } if (!destination) { diff --git a/src/Identity.h b/src/Identity.h index 84efeffc..bd67b9f1 100644 --- a/src/Identity.h +++ b/src/Identity.h @@ -46,18 +46,18 @@ namespace RNS { public: Identity(bool create_keys = true); Identity(Type::NoneConstructor none) { - MEM("Identity NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Identity NONE object created, this: %p, data: %p", (void*)this, (void*)_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())); + MEMF("Identity object copy created, this: %p, data: %p", (void*)this, (void*)_object.get()); } virtual ~Identity() { - MEM("Identity object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Identity object destroyed, this: %p, data: %p", (void*)this, (void*)_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())); + MEMF("Identity object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get()); return *this; } inline operator bool() const { @@ -89,7 +89,7 @@ namespace RNS { inline void update_hashes() { assert(_object); _object->_hash = truncated_hash(get_public_key()); - TRACE("Identity::update_hashes: hash: " + _object->_hash.toHex()); + TRACEF("Identity::update_hashes: hash: %s", _object->_hash.toHex().c_str()); _object->_hexhash = _object->_hash.toHex(); }; bool load(const char* path); @@ -172,8 +172,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() { MEMF("Identity::Data object created, this: %p", (void*)this); } + virtual ~Object() { MEMF("Identity::Data object destroyed, this: %p", (void*)this); } private: Cryptography::X25519PrivateKey::Ptr _prv; diff --git a/src/Interface.cpp b/src/Interface.cpp index 18bde300..d299f892 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -9,13 +9,13 @@ using namespace RNS::Type::Interface; /*static*/ uint8_t Interface::DISCOVER_PATHS_FOR = MODE_ACCESS_POINT | MODE_GATEWAY; void InterfaceImpl::handle_outgoing(const Bytes& data) { - //TRACE("InterfaceImpl.handle_outgoing: data: " + data.toHex()); + //TRACEF("InterfaceImpl.handle_outgoing: data: %s", data.toHex().c_str()); TRACE("InterfaceImpl.handle_outgoing"); _txb += data.size(); } void InterfaceImpl::handle_incoming(const Bytes& data) { - //TRACE("InterfaceImpl.handle_incoming: data: " + data.toHex()); + //TRACEF("InterfaceImpl.handle_incoming: data: %s", data.toHex().c_str()); TRACE("InterfaceImpl.handle_incoming"); _rxb += data.size(); // Create temporary Interface encapsulating our own shared impl @@ -26,7 +26,7 @@ void InterfaceImpl::handle_incoming(const Bytes& data) { } void Interface::handle_incoming(const Bytes& data) { - //TRACE("Interface.handle_incoming: data: " + data.toHex()); + //TRACEF("Interface.handle_incoming: data: %s", data.toHex().c_str()); TRACE("Interface.handle_incoming"); assert(_impl); /* @@ -87,18 +87,18 @@ void Interface::process_announce_queue() { /* void ArduinoJson::convertFromJson(JsonVariantConst src, RNS::Interface& dst) { TRACE(">>> Deserializing Interface"); -TRACE(">>> Interface pre: " + dst.debugString()); +TRACEF(">>> Interface pre: %s", dst.debugString().c_str()); if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - TRACE(">>> Querying Transport for Interface hash " + hash.toHex()); + TRACEF(">>> Querying Transport for Interface hash %s", hash.toHex().c_str()); // Query transport for matching interface dst = Transport::find_interface_from_hash(hash); -TRACE(">>> Interface post: " + dst.debugString()); +TRACEF(">>> Interface post: %s", dst.debugString().c_str()); } else { dst = {RNS::Type::NONE}; -TRACE(">>> Interface post: " + dst.debugString()); +TRACEF(">>> Interface post: %s", dst.debugString().c_str()); } } */ diff --git a/src/Interface.h b/src/Interface.h index 7ec2de2d..df5edbd9 100644 --- a/src/Interface.h +++ b/src/Interface.h @@ -224,7 +224,7 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - TRACE("<<< Interface hash " + src.get_hash().toHex()); + TRACEF("<<< Interface hash %s", src.get_hash().toHex().c_str()); return dst.set(src.get_hash().toHex()); } void convertFromJson(JsonVariantConst src, RNS::Interface& dst); @@ -241,14 +241,14 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - TRACE("<<< Serializing interface hash " + src.get_hash().toHex()); + TRACEF("<<< Serializing interface hash %s", src.get_hash().toHex().c_str()); return dst.set(src.get_hash().toHex()); } static RNS::Interface fromJson(JsonVariantConst src) { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - TRACE(">>> Deserialized interface hash " + hash.toHex()); + TRACEF(">>> Deserialized interface hash %s", hash.toHex().c_str()); TRACE(">>> Querying transport for interface"); // Query transport for matching interface return RNS::Interface::find_interface_from_hash(hash); diff --git a/src/Log.h b/src/Log.h index 34f44c0d..4b9b9ebd 100644 --- a/src/Log.h +++ b/src/Log.h @@ -92,11 +92,11 @@ namespace RNS { #endif inline void log(const char* msg, LogLevel level = LOG_NOTICE) { doLog(level, msg); } - inline void log(const std::string& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); } + //inline void log(const std::string& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); } inline void logf(LogLevel level, const char* msg, ...) { va_list vlist; va_start(vlist, msg); doLog(level, msg, vlist); va_end(vlist); } #ifdef ARDUINO - inline void log(const String& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); } - inline void log(const StringSumHelper& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); } + //inline void log(const String& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); } + //inline void log(const StringSumHelper& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); } //inline void log(const __FlashStringHelper* msg, LogLevel level = LOG_NOTICE) { doLog(level, msg); } //inline void logf(LogLevel level, const __FlashStringHelper* msg, ...) { va_list vlist; va_start(vlist, msg); doLog(level, msg, vlist); va_end(vlist); } #endif diff --git a/src/Packet.cpp b/src/Packet.cpp index a3111404..707ec9b6 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -55,7 +55,7 @@ Packet::Packet(const Destination& destination, const Interface& attached_interfa _object->_create_receipt = false; } - MEM("Packet object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Packet object created, this: %p, data: %p", (void*)this, (void*)_object.get()); } // CBA LINK @@ -70,7 +70,7 @@ Packet::Packet(const Link& link, const Bytes& data, Type::Packet::types packet_t _object->_MTU = link.mtu(); // CBA HACK: Need to re-build packed flags since Link was assigned _object->_flags = get_packed_flags(); - MEM("Packet link object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Packet link object created, this: %p, data: %p", (void*)this, (void*)_object.get()); } @@ -283,13 +283,13 @@ void Packet::pack() { // CBA LINK if (_object->_context == LRPROOF) { if (!_object->_destination_link) throw std::invalid_argument("Packet is not associated with a Link"); - TRACE("Packet::pack: destination link id: " + _object->_destination_link.link_id().toHex() ); + TRACEF("Packet::pack: destination link id: %s", _object->_destination_link.link_id().toHex().c_str()); _object->_header << _object->_destination_link.link_id(); _object->_ciphertext = _object->_data; } else { if (_object->_header_type == HEADER_1) { - TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() ); + TRACEF("Packet::pack: destination hash: %s", _object->_destination.hash().toHex().c_str()); _object->_header << _object->_destination.hash(); if (_object->_packet_type == ANNOUNCE) { @@ -348,8 +348,8 @@ TRACEF("***** Destination Data: %s", _object->_ciphertext.toHex().c_str()); if (!_object->_transport_id) { throw std::invalid_argument("Packet with header type 2 must have a transport ID"); } - TRACE("Packet::pack: transport id: " + _object->_transport_id.toHex() ); - TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() ); + TRACEF("Packet::pack: transport id: %s", _object->_transport_id.toHex().c_str()); + TRACEF("Packet::pack: destination hash: %s", _object->_destination.hash().toHex().c_str()); _object->_header << _object->_transport_id; _object->_header << _object->_destination.hash(); @@ -424,7 +424,7 @@ bool Packet::unpack() { return false; } catch (std::exception& e) { - ERROR(std::string("Received malformed packet, dropping it. The contained exception was: ") + e.what()); + ERRORF("Received malformed packet, dropping it. The contained exception was: %s", e.what()); return false; } @@ -856,8 +856,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())); + ERRORF("An error occurred while evaluating external delivery callback for %s", link.toString().c_str()); + ERRORF("The contained exception was: %s", e.what()); } } return true; @@ -918,7 +918,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())); + ERRORF("Error while executing proof validated callback. The contained exception was: %s", e.what()); } } return true; @@ -949,7 +949,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())); + ERRORF("Error while executing proof validated callback. The contained exception was: %s", e.what()); } } return true; diff --git a/src/Packet.h b/src/Packet.h index c6898ef4..b7ca023c 100644 --- a/src/Packet.h +++ b/src/Packet.h @@ -145,10 +145,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())); + MEMF("Packet NONE object created, this: %p, data: %p", (void*)this, (void*)_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())); + MEMF("Packet object copy created, this: %p, data: %p", (void*)this, (void*)_object.get()); } Packet( const Destination& destination, @@ -182,12 +182,12 @@ namespace RNS { Type::Packet::context_flags context_flag = Type::Packet::FLAG_UNSET ); virtual ~Packet() { - MEM("Packet object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Packet object destroyed, this: %p, data: %p", (void*)this, (void*)_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())); + MEMF("Packet object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get()); return *this; } inline operator bool() const { @@ -272,11 +272,11 @@ 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)); } + Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) { MEMF("Packet::Data object created, this: %p", (void*)this); } // CBA LINK - //Object(const Destination& destination, const Link& destination_link) : _destination(destination), _destination_link(destination_link) { MEM("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); } - //Object(const Link& link) : _destination(link.destination()), _destination_link(link) { MEM("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); } - virtual ~Object() { MEM("Packet::Data object destroyed, this: " + std::to_string((uintptr_t)this)); } + //Object(const Destination& destination, const Link& destination_link) : _destination(destination), _destination_link(destination_link) { MEMF("Packet::Data object created, this: %p", (void*)this); } + //Object(const Link& link) : _destination(link.destination()), _destination_link(link) { MEMF("Packet::Data object created, this: %p", (void*)this); } + virtual ~Object() { MEMF("Packet::Data object destroyed, this: %p", (void*)this); } private: Destination _destination = {Type::NONE}; @@ -358,14 +358,14 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - TRACE("<<< Serializing packet hash " + src.get_hash().toHex()); + TRACEF("<<< Serializing packet hash %s", src.get_hash().toHex().c_str()); return dst.set(src.get_hash().toHex()); } static RNS::Packet fromJson(JsonVariantConst src) { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - TRACE(">>> Deserialized packet hash " + hash.toHex()); + TRACEF(">>> Deserialized packet hash %s", hash.toHex().c_str()); 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 0e49c1b8..62b187dd 100644 --- a/src/Reticulum.cpp +++ b/src/Reticulum.cpp @@ -67,12 +67,12 @@ void Reticulum::sigterm_handler(signal, frame): //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())); + MEMF("Reticulum default object creating..., this: %p, data: %p", (void*)this, (void*)_object.get()); // Initialize random number generator TRACE("Initializing RNG..."); RNG.begin("Reticulum"); - TRACE("RNG initial random value: " + std::to_string(Cryptography::randomnum())); + TRACEF("RNG initial random value: %d", Cryptography::randomnum()); #ifdef ARDUINO // Add a noise source to the list of sources known to RNG. @@ -125,7 +125,7 @@ Reticulum::Reticulum() : _object(new Object()) { Bytes buf; if (OS::read_file(time_offset_path, buf) == 8) { uint64_t offset = *(uint64_t*)buf.data(); - DEBUG("Read time offset of " + std::to_string(offset) + " from file"); + DEBUGF("Read time offset of %llu from file", offset); OS::setTimeOffset(offset); } } @@ -191,13 +191,13 @@ 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())); + MEMF("Reticulum default object created, this: %p, data: %p", (void*)this, (void*)_object.get()); } void Reticulum::start() { - INFO("Total memory: " + std::to_string(OS::heap_size())); - INFO("Total flash: " + std::to_string(OS::storage_size())); + INFOF("Total memory: %zu", OS::heap_size()); + INFOF("Total flash: %zu", OS::storage_size()); INFO("Starting Transport..."); Transport::start(*this); @@ -241,7 +241,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 <= 2) { - head("DETECTED LOW-MEMORY CONDITION (" + std::to_string(remaining) + "%), RESETTING!!!", LOG_CRITICAL); + HEADF(LOG_CRITICAL, "DETECTED LOW-MEMORY CONDITION (%d%%), RESETTING!!!", remaining); persist_data(); #if defined(ESP32) ESP.restart(); diff --git a/src/Reticulum.h b/src/Reticulum.h index 6cd12afd..d5728986 100644 --- a/src/Reticulum.h +++ b/src/Reticulum.h @@ -49,18 +49,18 @@ namespace RNS { public: Reticulum(); Reticulum(Type::NoneConstructor none) { - MEM("Reticulum empty object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Reticulum empty object created, this: %p, data: %p", (void*)this, (void*)_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())); + MEMF("Reticulum object copy created, this: %p, data: %p", (void*)this, (void*)_object.get()); } virtual ~Reticulum() { - MEM("Reticulum object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get())); + MEMF("Reticulum object destroyed, this: %p, data: %p", (void*)this, (void*)_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())); + MEMF("Reticulum object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get()); return *this; } inline operator bool() const { @@ -149,10 +149,10 @@ namespace RNS { class Object { public: Object() { - MEM("Reticulum data object created, this: " + std::to_string((uintptr_t)this)); + MEMF("Reticulum data object created, this: %p", (void*)this); } virtual ~Object() { - MEM("Reticulum data object destroyed, this: " + std::to_string((uintptr_t)this)); + MEMF("Reticulum data object destroyed, this: %p", (void*)this); } private: diff --git a/src/Transport.cpp b/src/Transport.cpp index 372ff833..46220ec0 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -190,7 +190,7 @@ using namespace RNS::Utilities; _control_destinations.insert(path_request_destination); // CBA ACCUMULATES _control_hashes.insert(path_request_destination.hash()); - DEBUG("Created transport-specific path request destination " + path_request_destination.hash().toHex()); + DEBUGF("Created transport-specific path request destination %s", path_request_destination.hash().toHex().c_str()); // Create transport-specific destination for tunnel synthesize Destination tunnel_synthesize_destination({Type::NONE}, Type::Destination::IN, Type::Destination::PLAIN, APP_NAME, "tunnel.synthesize"); @@ -201,7 +201,7 @@ using namespace RNS::Utilities; _control_destinations.insert(tunnel_synthesize_destination); // CBA ACCUMULATES _control_hashes.insert(tunnel_synthesize_destination.hash()); - DEBUG("Created transport-specific tunnel synthesize destination " + tunnel_synthesize_destination.hash().toHex()); + DEBUGF("Created transport-specific tunnel synthesize destination %s", tunnel_synthesize_destination.hash().toHex().c_str()); _jobs_running = false; @@ -225,12 +225,12 @@ using namespace RNS::Utilities; 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()); + DEBUGF("Created probe responder destination %s", probe_destination.hash().toHex().c_str()); probe_destination.announce(); - NOTICE("Transport Instance will respond to probe requests on " + probe_destination.toString()); + NOTICEF("Transport Instance will respond to probe requests on %s", probe_destination.toString().c_str()); } - VERBOSE("Transport instance " + _identity.toString() + " started"); + VERBOSEF("Transport instance %s started", _identity.toString().c_str()); _start_time = OS::time(); } @@ -289,7 +289,7 @@ using namespace RNS::Utilities; } 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"); + DEBUGF("Trying to rediscover path for %s since an attempted link was never established", link.destination().hash().toHex().c_str()); //if (path_requests.find(link.destination().hash()) == path_requests.end()) { if (path_requests.count(link.destination().hash()) == 0) { // CBA ACCUMULATES @@ -346,23 +346,23 @@ using namespace RNS::Utilities; //for (auto& pair : _announce_table) { // const auto& destination_hash = pair.first; // auto& announce_entry = pair.second; -//TRACE("[0] announce entry data size: " + std::to_string(announce_entry._packet.data().size())); +//TRACEF("[0] announce entry data size: %u", announce_entry._packet.data().size()); //p announce_entry = Transport.announce_table[destination_hash] if (announce_entry._retries > 0 && announce_entry._retries >= Type::Transport::LOCAL_REBROADCASTS_MAX) { - TRACE("Completed announce processing for " + destination_hash.toHex() + ", local rebroadcast limit reached"); + TRACEF("Completed announce processing for %s, local rebroadcast limit reached", destination_hash.toHex().c_str()); // CBA OK to modify collection here since we're immediately exiting iteration _announce_table.erase(destination_hash); break; } else if (announce_entry._retries > Type::Transport::PATHFINDER_R) { - TRACE("Completed announce processing for " + destination_hash.toHex() + ", retry limit reached"); + TRACEF("Completed announce processing for %s, retry limit reached", destination_hash.toHex().c_str()); // 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) { - TRACE("Performing announce processing for " + destination_hash.toHex() + "..."); + TRACEF("Performing announce processing for %s...", destination_hash.toHex().c_str()); announce_entry._retransmit_timeout = OS::time() + Type::Transport::PATHFINDER_G + Type::Transport::PATHFINDER_RW; announce_entry._retries += 1; //p packet = announce_entry[5] @@ -381,8 +381,8 @@ using namespace RNS::Utilities; //if (announce_entry._attached_interface) { //TRACE("[1] interface is valid"); -//TRACE("[1] interface: " + announce_entry._attached_interface.debugString()); -//TRACE("[1] interface: " + announce_entry._attached_interface.toString()); +//TRACEF("[1] interface: %s", announce_entry._attached_interface.debugString().c_str()); +//TRACEF("[1] interface: %s", announce_entry._attached_interface.toString().c_str()); //} Packet new_packet( announce_destination, @@ -401,10 +401,10 @@ using namespace RNS::Utilities; 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())); + DEBUGF("Rebroadcasting announce as path response for %s with hop count %d", announce_destination.hash().toHex().c_str(), new_packet.hops()); } else { - DEBUG("Rebroadcasting announce for " + announce_destination.hash().toHex() + " with hop count " + std::to_string(new_packet.hops())); + DEBUGF("Rebroadcasting announce for %s with hop count %d", announce_destination.hash().toHex().c_str(), new_packet.hops()); } outgoing.push_back(new_packet); @@ -473,7 +473,7 @@ using namespace RNS::Utilities; ERROR("jobs: bad_alloc - out of memory culling reverse table"); } catch (const std::exception& e) { - ERROR("jobs: failed to cull reverse table: " + std::string(e.what())); + ERRORF("jobs: failed to cull reverse table: %s", e.what()); } // Cull the link table according to timeout @@ -504,7 +504,7 @@ using namespace RNS::Utilities; // 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"); + DEBUGF("Trying to rediscover path for %s since an attempted link was never established, and path is now missing", link_entry._destination_hash.toHex().c_str()); path_request_conditions = true; } @@ -512,7 +512,7 @@ using namespace RNS::Utilities; // 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"); + DEBUGF("Trying to rediscover path for %s since an attempted local client link was never established", link_entry._destination_hash.toHex().c_str()); path_request_conditions = true; } @@ -521,7 +521,7 @@ using namespace RNS::Utilities; // 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"); + DEBUGF("Trying to rediscover path for %s since an attempted link was never established, and destination was previously local to an interface on this instance", link_entry._destination_hash.toHex().c_str()); path_request_conditions = true; } @@ -530,7 +530,7 @@ using namespace RNS::Utilities; // 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"); + DEBUGF("Trying to rediscover path for %s since an attempted link was never established, and link initiator is local to an interface on this instance", link_entry._destination_hash.toHex().c_str()); path_request_conditions = true; } @@ -556,7 +556,7 @@ using namespace RNS::Utilities; ERROR("jobs: bad_alloc - out of memory culling link table"); } catch (const std::exception& e) { - ERROR("jobs: failed to cull link table: " + std::string(e.what())); + ERRORF("jobs: failed to cull link table: %s", e.what()); } // Cull the path table @@ -578,11 +578,11 @@ using namespace RNS::Utilities; if (OS::time() > destination_expiry) { stale_paths.push_back(destination_hash); - DEBUG("Path to " + destination_hash.toHex() + " timed out and was removed"); + DEBUGF("Path to %s timed out and was removed", destination_hash.toHex().c_str()); } 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"); + DEBUGF("Path to %s was removed since the attached interface no longer exists", destination_hash.toHex().c_str()); } } remove_paths(stale_paths); @@ -591,7 +591,7 @@ using namespace RNS::Utilities; ERROR("jobs: bad_alloc - out of memory culling path table"); } catch (const std::exception& e) { - ERROR("jobs: failed to cull path table: " + std::string(e.what())); + ERRORF("jobs: failed to cull path table: %s", e.what()); } // Cull the pending discovery path requests table @@ -601,7 +601,7 @@ using namespace RNS::Utilities; 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"); + DEBUGF("Waiting path request for %s timed out and was removed", destination_hash.toString().c_str()); } } remove_discovery_path_requests(stale_discovery_path_requests); @@ -610,7 +610,7 @@ using namespace RNS::Utilities; ERROR("jobs: bad_alloc - out of memory culling discovery path requests"); } catch (const std::exception& e) { - ERROR("jobs: failed to cull discovery path requests: " + std::string(e.what())); + ERRORF("jobs: failed to cull discovery path requests: %s", e.what()); } // Cull the tunnel table @@ -621,14 +621,14 @@ using namespace RNS::Utilities; for (const auto& [tunnel_id, tunnel_entry] : _tunnels) { if (OS::time() > tunnel_entry._expires) { stale_tunnels.push_back(tunnel_id); - TRACE("Tunnel " + tunnel_id.toHex() + " timed out and was removed"); + TRACEF("Tunnel %s timed out and was removed", tunnel_id.toHex().c_str()); } 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); - TRACE("Tunnel path to " + destination_hash.toHex() + " timed out and was removed"); + TRACEF("Tunnel path to %s timed out and was removed", destination_hash.toHex().c_str()); } } @@ -640,7 +640,7 @@ using namespace RNS::Utilities; } } if (count > 0) { - TRACE("Removed " + std::to_string(count) + " tunnel paths"); + TRACEF("Removed %d tunnel paths", count); } remove_tunnels(stale_tunnels); } @@ -648,7 +648,7 @@ using namespace RNS::Utilities; ERROR("jobs: bad_alloc - out of memory culling tunnel table"); } catch (const std::exception& e) { - ERROR("jobs: failed to cull tunnel table: " + std::string(e.what())); + ERRORF("jobs: failed to cull tunnel table: %s", e.what()); } //#ifndef NDEBUG @@ -695,7 +695,7 @@ using namespace RNS::Utilities; _callbacks._transmit_packet(raw, interface); } catch (std::exception& e) { - DEBUG("Error while executing transmit packet callback. The contained exception was: " + std::string(e.what())); + DEBUGF("Error while executing transmit packet callback. The contained exception was: %s", e.what()); } } try { @@ -744,7 +744,7 @@ using namespace RNS::Utilities; } } catch (std::exception& e) { - ERROR("Error while transmitting on " + interface.toString() + ". The contained exception was: " + e.what()); + ERRORF("Error while transmitting on %s. The contained exception was: %s", interface.toString().c_str(), e.what()); } } @@ -758,7 +758,7 @@ using namespace RNS::Utilities; return false; } - TRACE("Transport::outbound: destination=" + packet.destination_hash().toHex() + " hops=" + std::to_string(packet.hops())); + TRACEF("Transport::outbound: destination=%s hops=%d", packet.destination_hash().toHex().c_str(), packet.hops()); while (_jobs_running) { TRACE("Transport::outbound: sleeping..."); @@ -863,7 +863,7 @@ using namespace RNS::Utilities; #elif defined(INTERFACES_MAP) for (auto& [hash, interface] : _interfaces) { #endif - TRACE("Transport::outbound: Checking interface " + interface.toString()); + TRACEF("Transport::outbound: Checking interface %s", interface.toString().c_str()); if (interface.OUT()) { bool should_transmit = true; @@ -888,7 +888,7 @@ using namespace RNS::Utilities; if (!packet.attached_interface()) { TRACE("Transport::outbound: Packet has no attached interface"); if (interface.mode() == Type::Interface::MODE_ACCESS_POINT) { - TRACE("Blocking announce broadcast on " + interface.toString() + " due to AP mode"); + TRACEF("Blocking announce broadcast on %s due to AP mode", interface.toString().c_str()); should_transmit = false; } else if (interface.mode() == Type::Interface::MODE_ROAMING) { @@ -921,19 +921,19 @@ using namespace RNS::Utilities; if (!from_interface || from_interface.mode() == Type::Interface::MODE_NONE) { should_transmit = false; if (!from_interface) { - TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface doesn't exist"); + TRACEF("Blocking announce broadcast on %s since next hop interface doesn't exist", interface.toString().c_str()); } else if (from_interface.mode() == Type::Interface::MODE_NONE) { - TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface has no mode configured"); + TRACEF("Blocking announce broadcast on %s since next hop interface has no mode configured", interface.toString().c_str()); } } else { if (from_interface.mode() == Type::Interface::MODE_ROAMING) { - TRACE("Blocking announce broadcast on " + interface.toString() + " due to roaming-mode next-hop interface"); + TRACEF("Blocking announce broadcast on %s due to roaming-mode next-hop interface", interface.toString().c_str()); should_transmit = false; } else if (from_interface.mode() == Type::Interface::MODE_BOUNDARY) { - TRACE("Blocking announce broadcast on " + interface.toString() + " due to boundary-mode next-hop interface"); + TRACEF("Blocking announce broadcast on %s due to boundary-mode next-hop interface", interface.toString().c_str()); should_transmit = false; } } @@ -969,15 +969,15 @@ using namespace RNS::Utilities; if (!from_interface || from_interface.mode() == Type::Interface::MODE_NONE) { should_transmit = false; if (!from_interface) { - TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface doesn't exist"); + TRACEF("Blocking announce broadcast on %s since next hop interface doesn't exist", interface.toString().c_str()); } else if (from_interface.mode() == Type::Interface::MODE_NONE) { - TRACE("Blocking announce broadcast on " + interface.toString() + " since next hop interface has no mode configured"); + TRACEF("Blocking announce broadcast on %s since next hop interface has no mode configured", interface.toString().c_str()); } } else { if (from_interface.mode() == Type::Interface::MODE_ROAMING) { - TRACE("Blocking announce broadcast on " + interface.toString() + " due to roaming-mode next-hop interface"); + TRACEF("Blocking announce broadcast on %s due to roaming-mode next-hop interface", interface.toString().c_str()); should_transmit = false; } } @@ -1056,19 +1056,19 @@ using namespace RNS::Utilities; //z timer.start() if (wait_time < 1000) { - 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"); + TRACEF("Added announce to queue (height %zu) on %s for processing in %d ms", interface.announce_queue().size(), interface.toString().c_str(), (int)wait_time); } else { - 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"); + TRACEF("Added announce to queue (height %zu) on %s for processing in %.1f s", interface.announce_queue().size(), interface.toString().c_str(), OS::round(wait_time/1000,1)); } } else { double wait_time = std::max(interface.announce_allowed_at() - OS::time(), (double)0); if (wait_time < 1000) { - 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"); + TRACEF("Added announce to queue (height %zu) on %s for processing in %d ms", interface.announce_queue().size(), interface.toString().c_str(), (int)wait_time); } else { - 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"); + TRACEF("Added announce to queue (height %zu) on %s for processing in %.1f s", interface.announce_queue().size(), interface.toString().c_str(), OS::round(wait_time/1000,1)); } } } @@ -1168,7 +1168,7 @@ using namespace RNS::Utilities; 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"); + DEBUGF("Dropped PLAIN packet %s with %d hops", packet.packet_hash().toHex().c_str(), packet.hops()); return false; } else { @@ -1184,7 +1184,7 @@ using namespace RNS::Utilities; 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"); + DEBUGF("Dropped GROUP packet %s with %d hops", packet.packet_hash().toHex().c_str(), packet.hops()); return false; } else { @@ -1214,7 +1214,7 @@ using namespace RNS::Utilities; } } - DEBUG("Filtered packet with hash " + packet.packet_hash().toHex()); + DEBUGF("Filtered packet with hash %s", packet.packet_hash().toHex().c_str()); return false; } @@ -1227,7 +1227,7 @@ using namespace RNS::Utilities; _callbacks._receive_packet(raw, interface); } catch (std::exception& e) { - DEBUG("Error while executing receive packet callback. The contained exception was: " + std::string(e.what())); + DEBUGF("Error while executing receive packet callback. The contained exception was: %s", e.what()); } } // TODO @@ -1316,10 +1316,10 @@ using namespace RNS::Utilities; return; } #ifndef NDEBUG - TRACE("Transport::inbound: packet: " + packet.debugString()); + TRACEF("Transport::inbound: packet: %s", packet.debugString().c_str()); #endif - TRACE("Transport::inbound: destination=" + packet.destination_hash().toHex() + " hops=" + std::to_string(packet.hops())); + TRACEF("Transport::inbound: destination=%s hops=%d", packet.destination_hash().toHex().c_str(), packet.hops()); packet.receiving_interface(interface); packet.hops(packet.hops() + 1); @@ -1364,7 +1364,7 @@ using namespace RNS::Utilities; accept = _callbacks._filter_packet(packet); } catch (std::exception& e) { - DEBUG("Error while executing filter packet callback. The contained exception was: " + std::string(e.what())); + DEBUGF("Error while executing filter packet callback. The contained exception was: %s", e.what()); } } if (accept) { @@ -1440,7 +1440,7 @@ using namespace RNS::Utilities; for (auto& [hash, interface] : _interfaces) { #endif if (interface != packet.receiving_interface()) { - TRACE("Transport::inbound: Broadcasting packet on " + interface.toString()); + TRACEF("Transport::inbound: Broadcasting packet on %s", interface.toString().c_str()); #if defined(INTERFACES_SET) transmit(const_cast(interface), packet.raw()); #else @@ -1453,7 +1453,7 @@ using namespace RNS::Utilities; // it directly to all local clients else { for (const Interface& interface : _local_client_interfaces) { - TRACE("Transport::inbound: Broadcasting packet on " + interface.toString()); + TRACEF("Transport::inbound: Broadcasting packet on %s", interface.toString().c_str()); transmit(const_cast(interface), packet.raw()); } } @@ -1583,7 +1583,7 @@ using namespace RNS::Utilities; // TODO: There should probably be some kind of REJECT // mechanism here, to signal to the source that their // expected path failed. - TRACE("Got packet in transport, but no known path to final destination " + packet.destination_hash().toHex() + ". Dropping packet."); + TRACEF("Got packet in transport, but no known path to final destination %s. Dropping packet.", packet.destination_hash().toHex().c_str()); } } else { @@ -1696,10 +1696,10 @@ using namespace RNS::Utilities; bool announce_erased = false; if ((packet.hops() - 1) == announce_entry._hops) { - DEBUG("Heard a local rebroadcast of announce for " + packet.destination_hash().toHex()); + DEBUGF("Heard a local rebroadcast of announce for %s", packet.destination_hash().toHex().c_str()); 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"); + DEBUGF("Max local rebroadcasts of announce for %s reached, dropping announce from our table", packet.destination_hash().toHex().c_str()); _announce_table.erase(packet.destination_hash()); announce_erased = true; } @@ -1709,7 +1709,7 @@ using namespace RNS::Utilities; if (!announce_erased && (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"); + DEBUGF("Rebroadcasted announce for %s has been passed on to another node, no further tries needed", packet.destination_hash().toHex().c_str()); _announce_table.erase(packet.destination_hash()); announce_erased = true; } @@ -1795,7 +1795,7 @@ using namespace RNS::Utilities; 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"); + DEBUGF("Replacing destination table entry for %s with new announce due to expired path", packet.destination_hash().toHex().c_str()); should_add = true; } else { @@ -1805,7 +1805,7 @@ using namespace RNS::Utilities; 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"); + DEBUGF("Replacing destination table entry for %s with new announce, since it was more recently emitted", packet.destination_hash().toHex().c_str()); should_add = true; } else { @@ -1887,7 +1887,7 @@ using namespace RNS::Utilities; // 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"); + DEBUGF("Blocking rebroadcast of announce from %s due to excessive announce rate", packet.destination_hash().toHex().c_str()); } else { if (Transport::from_local_client(packet)) { @@ -2008,7 +2008,7 @@ using namespace RNS::Utilities; 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()); + DEBUGF("Got matching announce, answering waiting discovery path request for %s on %s", packet.destination_hash().toHex().c_str(), attached_interface.toString().c_str()); 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()); @@ -2035,15 +2035,15 @@ using namespace RNS::Utilities; } // CBA Culling before adding to esnure table does not exceed maxsize - TRACE("Caching packet " + packet.get_hash().toHex()); + TRACEF("Caching packet %s", packet.get_hash().toHex().c_str()); if (RNS::Transport::cache_packet(packet, true)) { packet.cached(true); } - //TRACE("Adding packet " + packet.get_hash().toHex() + " to packet table"); + //TRACEF("Adding packet %s to packet table", packet.get_hash().toHex().c_str()); //PacketEntry packet_entry(packet); // CBA ACCUMULATES //_packet_table.insert({packet.get_hash(), packet_entry}); - TRACE("Adding destination " + packet.destination_hash().toHex() + " to path table"); + TRACEF("Adding destination %s to path table", packet.destination_hash().toHex().c_str()); DestinationEntry destination_table_entry( now, received_from, @@ -2061,25 +2061,25 @@ using namespace RNS::Utilities; // CBA First remove any existing path before inserting new one remove_path(packet.destination_hash()); if (_destination_table.insert({packet.destination_hash(), destination_table_entry}).second) { - TRACE("Added destination " + packet.destination_hash().toHex() + " to path table!"); + TRACEF("Added destination %s to path table!", packet.destination_hash().toHex().c_str()); ++_destinations_added; // CBA IMMEDIATE CULL cull_path_table(); } else { - ERROR("Failed to add destination " + packet.destination_hash().toHex() + " to path table!"); + ERRORF("Failed to add destination %s to path table!", packet.destination_hash().toHex().c_str()); } } catch (const std::bad_alloc&) { ERROR("inbound: bad_alloc - out of memory storing destination entry"); } catch (const std::exception& e) { - ERROR(std::string("inbound: exception storing destination entry: ") + e.what()); + ERRORF("inbound: exception storing destination entry: %s", e.what()); } - 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()); + DEBUGF("Destination %s is now %d hops away via %s on %s", packet.destination_hash().toHex().c_str(), announce_hops, received_from.toHex().c_str(), packet.receiving_interface().toString().c_str()); + //TRACEF("Transport::inbound: Destination %s has data: %s", packet.destination_hash().toHex().c_str(), packet.data().toHex().c_str()); + //TRACEF("Transport::inbound: Destination %s has text: %s", packet.destination_hash().toHex().c_str(), packet.data().toString().c_str()); // TODO /* @@ -2091,7 +2091,7 @@ using namespace RNS::Utilities; 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()); + DEBUGF("Path to %s associated with tunnel %s", packet.destination_hash().toHex().c_str(), packet.receiving_interface().tunnel_id().toHex().c_str()); } */ @@ -2195,10 +2195,10 @@ using namespace RNS::Utilities; 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"); + DEBUGF("Packet destination %s found, destination is local", packet.destination_hash().toHex().c_str()); auto& destination = (*iter).second; if (destination.type() == packet.destination_type()) { - TRACE("Transport::inbound: Packet destination type " + std::to_string(packet.destination_type()) + " matched, processing"); + TRACEF("Transport::inbound: Packet destination type %d matched, processing", packet.destination_type()); #endif packet.destination(destination); #if defined(DESTINATIONS_SET) @@ -2218,17 +2218,17 @@ using namespace RNS::Utilities; } } catch (std::exception& e) { - ERROR(std::string("Error while executing proof request callback. The contained exception was: ") + e.what()); + ERRORF("Error while executing proof request callback. The contained exception was: %s", e.what()); } } } } else { - DEBUG("Transport::inbound: Packet destination type " + std::to_string(packet.destination_type()) + " mismatch, ignoring"); + DEBUGF("Transport::inbound: Packet destination type %d mismatch, ignoring", packet.destination_type()); } } else { - DEBUG("Transport::inbound: Local destination " + packet.destination_hash().toHex() + " not found, not handling packet locally"); + DEBUGF("Transport::inbound: Local destination %s not found, not handling packet locally", packet.destination_hash().toHex().c_str()); } } } @@ -2254,7 +2254,7 @@ using namespace RNS::Utilities; Bytes signature = packet.data().left(Type::Identity::SIGLENGTH/8); if (peer_identity.validate(signature, signed_data)) { - TRACE("Link request proof validated for transport via " + link_entry._receiving_interface.toString()); + TRACEF("Link request proof validated for transport via %s", link_entry._receiving_interface.toString().c_str()); //p new_raw = packet.raw[0:1] // CBA RESERVE //Bytes new_raw = packet.raw().left(1); @@ -2268,12 +2268,12 @@ using namespace RNS::Utilities; transmit(link_entry._receiving_interface, new_raw); } else { - DEBUG("Invalid link request proof in transport for link " + packet.destination_hash().toHex() + ", dropping proof."); + DEBUGF("Invalid link request proof in transport for link %s, dropping proof.", packet.destination_hash().toHex().c_str()); } } } catch (std::exception& e) { - ERROR("Error while transporting link request proof. The contained exception was: " + std::string(e.what())); + ERRORF("Error while transporting link request proof. The contained exception was: %s", e.what()); } } else { @@ -2325,7 +2325,7 @@ using namespace RNS::Utilities; 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) { - TRACE("Proof received on correct interface, transporting it via " + reverse_entry._receiving_interface.toString()); + TRACEF("Proof received on correct interface, transporting it via %s", reverse_entry._receiving_interface.toString().c_str()); //p new_raw = packet.raw[0:1] // CBA RESERVE //Bytes new_raw = packet.raw().left(1); @@ -2488,7 +2488,7 @@ using namespace RNS::Utilities; } /*static*/ void Transport::register_interface(Interface& interface) { - TRACE("Transport: Registering interface " + interface.get_hash().toHex() + " " + interface.toString()); + TRACEF("Transport: Registering interface %s %s", interface.get_hash().toHex().c_str(), interface.toString().c_str()); #if defined(INTERFACES_SET) _interfaces.insert(interface); #elif defined(INTERFACES_LIST) @@ -2500,11 +2500,11 @@ using namespace RNS::Utilities; } /*static*/ void Transport::deregister_interface(const Interface& interface) { - TRACE("Transport: Deregistering interface " + interface.toString()); + TRACEF("Transport: Deregistering interface %s", interface.toString().c_str()); #if defined(INTERFACES_SET) //for (auto iter = _interfaces.begin(); iter != _interfaces.end(); ++iter) { // if ((*iter).get() == interface) { - // TRACE("Transport::deregister_interface: Found and removing interface " + (*iter).get().toString()); + // TRACEF("Transport::deregister_interface: Found and removing interface %s", (*iter).get().toString().c_str()); // _interfaces.erase(iter); // break; // } @@ -2512,13 +2512,13 @@ using namespace RNS::Utilities; //auto iter = _interfaces.find(interface); auto iter = _interfaces.find(const_cast(interface)); if (iter != _interfaces.end()) { - TRACE("Transport::deregister_interface: Found and removing interface " + (*iter).get().toString()); + TRACEF("Transport::deregister_interface: Found and removing interface %s", (*iter).get().toString().c_str()); _interfaces.erase(iter); } #elif defined(INTERFACES_LIST) for (auto iter = _interfaces.begin(); iter != _interfaces.end(); ++iter) { if ((*iter).get() == interface) { - TRACE("Transport::deregister_interface: Found and removing interface " + (*iter).get().toString()); + TRACEF("Transport::deregister_interface: Found and removing interface %s", (*iter).get().toString().c_str()); _interfaces.erase(iter); break; } @@ -2526,7 +2526,7 @@ using namespace RNS::Utilities; #elif defined(INTERFACES_MAP) auto iter = _interfaces.find(interface.get_hash()); if (iter != _interfaces.end()) { - TRACE("Transport::deregister_interface: Found and removing interface " + (*iter).second.toString()); + TRACEF("Transport::deregister_interface: Found and removing interface %s", (*iter).second.toString().c_str()); _interfaces.erase(iter); } #endif @@ -2534,7 +2534,7 @@ using namespace RNS::Utilities; /*static*/ void Transport::register_destination(Destination& destination) { //TRACE("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - TRACE("Transport: Registering destination " + destination.toString()); + TRACEF("Transport: Registering destination %s", destination.toString().c_str()); destination.mtu(Type::Reticulum::MTU); if (destination.direction() == Type::Destination::IN) { #if defined(DESTINATIONS_SET) @@ -2560,13 +2560,13 @@ using namespace RNS::Utilities; if (_owner && _owner.is_connected_to_shared_instance()) { if (destination.type() == Type::Destination::SINGLE) { - TRACE("Transport:register_destination: Announcing destination " + destination.toString()); + TRACEF("Transport:register_destination: Announcing destination %s", destination.toString().c_str()); destination.announce({}, true); } } } else { - TRACE("Transport:register_destination: Skipping registration (not direction IN) of destination " + destination.toString()); + TRACEF("Transport:register_destination: Skipping registration (not direction IN) of destination %s", destination.toString().c_str()); } /* @@ -2575,30 +2575,30 @@ using namespace RNS::Utilities; #elif defined(DESTINATIONS_MAP) for (auto& [hash, destination] : _destinations) { #endif - TRACE("Transport::register_destination: Listed destination " + destination.toString()); + TRACEF("Transport::register_destination: Listed destination %s", destination.toString().c_str()); } */ //TRACE("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } /*static*/ void Transport::deregister_destination(const Destination& destination) { - TRACE("Transport: Deregistering destination " + destination.toString()); + TRACEF("Transport: Deregistering destination %s", destination.toString().c_str()); #if defined(DESTINATIONS_SET) if (_destinations.find(destination) != _destinations.end()) { - TRACE("Transport::deregister_destination: Found and removing destination " + destination.toString()); + TRACEF("Transport::deregister_destination: Found and removing destination %s", destination.toString().c_str()); _destinations.erase(destination); } #elif defined(DESTINATIONS_MAP) auto iter = _destinations.find(destination.hash()); if (iter != _destinations.end()) { - TRACE("Transport::deregister_destination: Found and removing destination " + (*iter).second.toString()); + TRACEF("Transport::deregister_destination: Found and removing destination %s", (*iter).second.toString().c_str()); _destinations.erase(iter); } #endif } /*static*/ void Transport::register_link(Link& link) { - TRACE("Transport: Registering link " + link.toString()); + TRACEF("Transport: Registering link %s", link.toString().c_str()); if (link.initiator()) { // CBA ACCUMULATES _pending_links.insert(link); @@ -2610,7 +2610,7 @@ using namespace RNS::Utilities; } /*static*/ void Transport::activate_link(Link& link) { - TRACE("Transport: Activating link " + link.toString()); + TRACEF("Transport: Activating link %s", link.toString().c_str()); if (_pending_links.find(link) != _pending_links.end()) { if (link.status() != Type::Link::ACTIVE) { throw std::runtime_error("Invalid link state for link activation: " + std::to_string(link.status())); @@ -2631,7 +2631,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) { - TRACE("Transport: Registering announce handler " + handler->aspect_filter()); + TRACEF("Transport: Registering announce handler %s", handler->aspect_filter().c_str()); _announce_handlers.insert(handler); } @@ -2641,9 +2641,9 @@ Deregisters an announce handler. :param handler: The announce handler to be deregistered. */ /*static*/ void Transport::deregister_announce_handler(HAnnounceHandler handler) { - TRACE("Transport: Deregistering announce handler " + handler->aspect_filter()); + TRACEF("Transport: Deregistering announce handler %s", handler->aspect_filter().c_str()); if (_announce_handlers.find(handler) != _announce_handlers.end()) { - TRACE("Transport::deregister_announce_handler: Found and removing handler" + handler->aspect_filter()); + TRACEF("Transport::deregister_announce_handler: Found and removing handler%s", handler->aspect_filter().c_str()); _announce_handlers.erase(handler); } } @@ -2652,21 +2652,21 @@ Deregisters an announce handler. #if defined(INTERFACES_SET) for (const Interface& interface : _interfaces) { if (interface.get_hash() == interface_hash) { - //TRACE("Transport::find_interface_from_hash: Found interface " + interface.toString()); + //TRACEF("Transport::find_interface_from_hash: Found interface %s", interface.toString().c_str()); return interface; } } #elif defined(INTERFACES_LIST) for (Interface& interface : _interfaces) { if (interface.get_hash() == interface_hash) { - //TRACE("Transport::find_interface_from_hash: Found interface " + interface.toString()); + //TRACEF("Transport::find_interface_from_hash: Found interface %s", interface.toString().c_str()); return interface; } } #elif defined(INTERFACES_MAP) auto iter = _interfaces.find(interface_hash); if (iter != _interfaces.end()) { - //TRACE("Transport::find_interface_from_hash: Found interface " + (*iter).second.toString()); + //TRACEF("Transport::find_interface_from_hash: Found interface %s", (*iter).second.toString().c_str()); return (*iter).second; } #endif @@ -2690,17 +2690,17 @@ 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*/) { - TRACE("Checking to see if packet " + packet.get_hash().toHex() + " should be cached"); + TRACEF("Checking to see if packet %s should be cached", packet.get_hash().toHex().c_str()); #if defined(RNS_USE_FS) && defined(RNS_PERSIST_PATHS) if (should_cache_packet(packet) || force_cache) { - TRACE("Saving packet " + packet.get_hash().toHex() + " to storage"); + TRACEF("Saving packet %s to storage", packet.get_hash().toHex().c_str()); try { char packet_cache_path[Type::Reticulum::FILEPATH_MAXSIZE]; snprintf(packet_cache_path, Type::Reticulum::FILEPATH_MAXSIZE, "%s/%s", Reticulum::_cachepath, packet.get_hash().toHex().c_str()); return (Persistence::serialize(packet, packet_cache_path) > 0); } catch (std::exception& e) { - ERROR("Error writing packet to cache. The contained exception was: " + std::string(e.what())); + ERRORF("Error writing packet to cache. The contained exception was: %s", e.what()); } } #endif @@ -2708,7 +2708,7 @@ Deregisters an announce handler. } /*static*/ Packet Transport::get_cached_packet(const Bytes& packet_hash) { - TRACE("Loading packet " + packet_hash.toHex() + " from cache storage"); + TRACEF("Loading packet %s from cache storage", packet_hash.toHex().c_str()); #if defined(RNS_USE_FS) && defined(RNS_PERSIST_PATHS) try { /*p @@ -2748,7 +2748,7 @@ Deregisters an announce handler. } /*static*/ bool Transport::clear_cached_packet(const Bytes& packet_hash) { - TRACE("Clearing packet " + packet_hash.toHex() + " from cache storage"); + TRACEF("Clearing packet %s from cache storage", packet_hash.toHex().c_str()); #if defined(RNS_USE_FS) && defined(RNS_PERSIST_PATHS) try { char packet_cache_path[Type::Reticulum::FILEPATH_MAXSIZE]; @@ -2757,10 +2757,10 @@ Deregisters an announce handler. bool success = RNS::Utilities::OS::remove_file(packet_cache_path); 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"); + DEBUGF("Remove cached packet in %d ms", (int)(diff_time*1000)); } else { - DEBUG("Remove cached packet in " + std::to_string(diff_time) + " s"); + DEBUGF("Remove cached packet in %f s", diff_time); } } catch (std::exception& e) { @@ -2817,7 +2817,7 @@ Deregisters an announce handler. OS::remove_file(packet_cache_path); } if (_destination_table.erase(destination_hash) < 1) { - WARNING("Failed to remove destination " + destination_hash.toHex() + " from path table"); + WARNINGF("Failed to remove destination %s from path table", destination_hash.toHex().c_str()); } return true; } @@ -3035,13 +3035,13 @@ will announce it. bool queued_announces = (on_interface.announce_queue().size() > 0); if (queued_announces) { - TRACE("Blocking recursive path request on " + on_interface.toString() + " due to queued announces"); + TRACEF("Blocking recursive path request on %s due to queued announces", on_interface.toString().c_str()); return; } else { double now = OS::time(); if (now < on_interface.announce_allowed_at()) { - TRACE("Blocking recursive path request on " + on_interface.toString() + " due to active announce cap"); + TRACEF("Blocking recursive path request on %s due to active announce cap", on_interface.toString().c_str()); return; } else { @@ -3072,7 +3072,7 @@ will announce it. // destination being requested. if (data.size() >= Type::Identity::TRUNCATED_HASHLENGTH/8) { Bytes destination_hash = data.left(Type::Identity::TRUNCATED_HASHLENGTH/8); - //TRACE("Transport::path_request_handler: destination_hash: " + destination_hash.toHex()); + //TRACEF("Transport::path_request_handler: destination_hash: %s", destination_hash.toHex().c_str()); // 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 @@ -3080,7 +3080,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); - //TRACE("Transport::path_request_handler: requesting_transport_instance: " + requesting_transport_instance.toHex()); + //TRACEF("Transport::path_request_handler: requesting_transport_instance: %s", requesting_transport_instance.toHex().c_str()); } Bytes tag_bytes; @@ -3092,13 +3092,13 @@ will announce it. } if (tag_bytes) { - //TRACE("Transport::path_request_handler: tag_bytes: " + tag_bytes.toHex()); + //TRACEF("Transport::path_request_handler: tag_bytes: %s", tag_bytes.toHex().c_str()); 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; - //TRACE("Transport::path_request_handler: unique_tag: " + unique_tag.toHex()); + //TRACEF("Transport::path_request_handler: unique_tag: %s", unique_tag.toHex().c_str()); if (_discovery_pr_tags.find(unique_tag) == _discovery_pr_tags.end()) { // CBA ACCUMULATES @@ -3113,16 +3113,16 @@ will announce it. ); } else { - DEBUG("Ignoring duplicate path request for " + destination_hash.toHex() + " with tag " + unique_tag.toHex()); + DEBUGF("Ignoring duplicate path request for %s with tag %s", destination_hash.toHex().c_str(), unique_tag.toHex().c_str()); } } else { - DEBUG("Ignoring tagless path request for " + destination_hash.toHex()); + DEBUGF("Ignoring tagless path request for %s", destination_hash.toHex().c_str()); } } } catch (std::exception& e) { - ERROR("Error while handling path request. The contained exception was: " + std::string(e.what())); + ERRORF("Error while handling path request. The contained exception was: %s", e.what()); } } @@ -3140,13 +3140,13 @@ will announce it. interface_str = " on " + attached_interface.toString(); } - DEBUG("Path request for destination " + destination_hash.toHex() + interface_str); + DEBUGF("Path request for destination %s%s", destination_hash.toHex().c_str(), interface_str.c_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()) { - TRACE("Transport::path_request_handler: entry found for destination " + destination_hash.toHex()); + TRACEF("Transport::path_request_handler: entry found for destination %s", destination_hash.toHex().c_str()); DestinationEntry& destination_entry = (*iter).second; if (is_local_client_interface(destination_entry.receiving_interface())) { destination_exists_on_local_client = true; @@ -3155,7 +3155,7 @@ will announce it. } } else { - TRACE("Transport::path_request_handler: entry not found for destination " + destination_hash.toHex()); + TRACEF("Transport::path_request_handler: entry not found for destination %s", destination_hash.toHex().c_str()); } } @@ -3177,11 +3177,11 @@ 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"); + DEBUGF("Answering path request for destination %s%s, destination is local to this system", destination_hash.toHex().c_str(), interface_str.c_str()); } //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()) { - TRACE("Transport::path_request_handler: entry found for destination " + destination_hash.toHex()); + TRACEF("Transport::path_request_handler: entry found for destination %s", destination_hash.toHex().c_str()); DestinationEntry& destination_entry = (*destination_iter).second; const Packet& announce_packet = destination_entry.announce_packet(); const Bytes& next_hop = destination_entry._received_from; @@ -3198,10 +3198,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"); + DEBUGF("Not answering path request for destination %s%s, since next hop is the requestor", destination_hash.toHex().c_str(), interface_str.c_str()); } else { - DEBUG("Answering path request for destination " + destination_hash.toHex() + interface_str + ", path is known"); + DEBUGF("Answering path request for destination %s%s, path is known", destination_hash.toHex().c_str(), interface_str.c_str()); double now = OS::time(); uint8_t retries = Type::Transport::PATHFINDER_R; @@ -3271,7 +3271,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"); + DEBUGF("Forwarding path request from local client for destination %s%s to all other interfaces", destination_hash.toHex().c_str(), interface_str.c_str()); Bytes request_tag = Identity::get_random_hash(); #if defined(INTERFACES_SET) for (const Interface& interface : _interfaces) { @@ -3286,14 +3286,14 @@ will announce it. } } else if (should_search_for_unknown) { - TRACE("Transport::path_request_handler: searching for unknown path to " + destination_hash.toHex()); + TRACEF("Transport::path_request_handler: searching for unknown path to %s", destination_hash.toHex().c_str()); 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); + DEBUGF("There is already a waiting path request for destination %s on behalf of path request%s", destination_hash.toHex().c_str(), interface_str.c_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); + DEBUGF("Attempting to discover unknown path to destination %s on behalf of path request%s", destination_hash.toHex().c_str(), interface_str.c_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; // CBA ACCUMULATES @@ -3314,13 +3314,13 @@ will announce it. // path-finding over LoRa mesh //if (interface != attached_interface) { if (true) { - TRACE("Transport::path_request: requesting path on interface " + interface.toString()); + TRACEF("Transport::path_request: requesting path on interface %s", interface.toString().c_str()); // 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 { - TRACE("Transport::path_request: not requesting path on same interface " + interface.toString()); + TRACEF("Transport::path_request: not requesting path on same interface %s", interface.toString().c_str()); } } } @@ -3328,13 +3328,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"); + DEBUGF("Forwarding path request for destination %s%s to local clients", destination_hash.toHex().c_str(), interface_str.c_str()); 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"); + DEBUGF("Ignoring path request for destination %s%s, no path known", destination_hash.toHex().c_str(), interface_str.c_str()); } } @@ -3552,7 +3552,7 @@ TRACEF("Transport::start: buffer capacity %d bytes", Persistence::_buffer.capaci TRACEF("Transport::start: buffer addr: 0x%X", Persistence::_buffer.data()); TRACEF("Transport::start: buffer size %d bytes", Persistence::_buffer.size()); //TRACE("SERIALIZED: destination_table"); - //TRACE(Persistence::_buffer.toString()); + //TRACE(Persistence::_buffer.toString().c_str()); #endif #ifdef USE_MSGPACK DeserializationError error = deserializeMsgPack(Persistence::_document, Persistence::_buffer.data()); @@ -3690,9 +3690,9 @@ TRACEF("Transport::start: buffer size %d bytes", Persistence::_buffer.size()); //size_t size = 8192; size_t size = Persistence::_buffer.capacity(); -TRACE("Transport::write_path_table: obtaining buffer size " + std::to_string(size) + " bytes"); +TRACEF("Transport::write_path_table: obtaining buffer size %zu bytes", size); uint8_t* buffer = Persistence::_buffer.writable(size); -TRACE("Transport::write_path_table: buffer addr: " + std::to_string((long)buffer)); +TRACEF("Transport::write_path_table: buffer addr: %ld", (long)buffer); #ifdef USE_MSGPACK size_t length = serializeMsgPack(Persistence::_document, buffer, size); #else @@ -3708,10 +3708,10 @@ TRACE("Transport::write_path_table: buffer addr: " + std::to_string((long)buffer snprintf(destination_table_path, Type::Reticulum::FILEPATH_MAXSIZE, "%s/destination_table", Reticulum::_storagepath); #ifndef NDEBUG // CBA DEBUG Dump path table -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"); +TRACEF("Transport::write_path_table: buffer addr: %ld", (long)Persistence::_buffer.data()); +TRACEF("Transport::write_path_table: buffer size %zu bytes", Persistence::_buffer.size()); //TRACE("SERIALIZED: destination_table"); - //TRACE(Persistence::_buffer.toString()); + //TRACE(Persistence::_buffer.toString().c_str()); #endif // Check crc to see if data has changed before writing uint32_t crc = Crc::crc32(0, Persistence::_buffer.data(), Persistence::_buffer.size()); @@ -3727,7 +3727,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: // CBA DEBUG Dump path table //TRACE("FILE: destination_table"); //if (OS::read_file("/destination_table", Persistence::_buffer) > 0) { - // TRACE(Persistence::_buffer.toString()); + // TRACE(Persistence::_buffer.toString().c_str()); //} #endif } @@ -3757,12 +3757,12 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: 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"); - DEBUGF("Saved %d path table entries in %d ms", _destination_table.size(), (int)(save_time*1000)); + //DEBUGF("Saved %zu path table entries in %.1f ms", _destination_table.size(), OS::round(save_time * 1000, 1)); + DEBUGF("Saved %zu path table entries in %.1f ms", _destination_table.size(), OS::round(save_time * 1000, 1)); } else { - //DEBUG("Saved " + std::to_string(_destination_table.size()) + " path table entries in " + std::to_string(OS::round(save_time, 1)) + " s"); - DEBUGF("Saved %d path table entries in %d s", _destination_table.size(), save_time); + //DEBUGF("Saved %zu path table entries in %.1f s", _destination_table.size(), OS::round(save_time, 1)); + DEBUGF("Saved %zu path table entries in %.1f s", _destination_table.size(), OS::round(save_time, 1)); } } } @@ -3927,7 +3927,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: // CBA Remove cached packets no longer in path list std::list files = OS::list_directory(Reticulum::_cachepath); for (auto& file : files) { - TRACE("Transport::clean_caches: Checking for use of cached packet " + file); + TRACEF("Transport::clean_caches: Checking for use of cached packet %s", file.c_str()); bool found = false; for (auto& [destination_hash, destination_entry] : _destination_table) { if (file.compare(destination_entry._announce_packet.toHex()) == 0) { @@ -3936,7 +3936,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: } } if (!found) { - TRACE("Transport::clean_caches: No matching path found, removing cached packet " + file); + TRACEF("Transport::clean_caches: No matching path found, removing cached packet %s", file.c_str()); char packet_cache_path[Type::Reticulum::FILEPATH_MAXSIZE]; snprintf(packet_cache_path, Type::Reticulum::FILEPATH_MAXSIZE, "%s/%s", Reticulum::_cachepath, file.c_str()); OS::remove_file(packet_cache_path); @@ -4006,18 +4006,18 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: } /*static*/ Destination Transport::find_destination_from_hash(const Bytes& destination_hash) { - TRACE("Transport::find_destination_from_hash: Searching for destination " + destination_hash.toHex()); + TRACEF("Transport::find_destination_from_hash: Searching for destination %s", destination_hash.toHex().c_str()); #if defined(DESTINATIONS_SET) for (const Destination& destination : _destinations) { if (destination.get_hash() == destination_hash) { - TRACE("Transport::find_destination_from_hash: Found destination " + destination.toString()); + TRACEF("Transport::find_destination_from_hash: Found destination %s", destination.toString().c_str()); return destination; } } #elif defined(DESTINATIONS_MAP) auto iter = _destinations.find(destination_hash); if (iter != _destinations.end()) { - TRACE("Transport::find_destination_from_hash: Found destination " + (*iter).second.toString()); + TRACEF("Transport::find_destination_from_hash: Found destination %s", (*iter).second.toString().c_str()); return (*iter).second; } #endif @@ -4042,7 +4042,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: uint16_t count = 0; for (const auto& [timestamp, destination_hash] : sorted_keys) { - TRACE("Transport::cull_path_table: Removing destination " + destination_hash.toHex() + " from path table"); + TRACEF("Transport::cull_path_table: Removing destination %s from path table", destination_hash.toHex().c_str()); #if defined(RNS_USE_FS) && defined(RNS_PERSIST_PATHS) auto it = _destination_table.find(destination_hash); if (it != _destination_table.end()) { @@ -4055,14 +4055,14 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: } #endif if (_destination_table.erase(destination_hash) < 1) { - WARNING("Failed to remove destination " + destination_hash.toHex() + " from path table"); + WARNINGF("Failed to remove destination %s from path table", destination_hash.toHex().c_str()); } ++count; if (_destination_table.size() <= _path_table_maxsize) { break; } } - DEBUG("Removed " + std::to_string(count) + " path(s) from path table"); + DEBUGF("Removed %d path(s) from path table", count); } catch (const std::bad_alloc& e) { ERROR("cull_path_table: bad_alloc - out of memory building sort index, falling back to single erase"); @@ -4079,7 +4079,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: } } catch (const std::exception& e) { - ERROR(std::string("cull_path_table: exception: ") + e.what()); + ERRORF("cull_path_table: exception: %s", e.what()); } } } @@ -4101,16 +4101,16 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: uint16_t count = 0; for (const auto& [timestamp, destination_hash] : sorted_keys) { - TRACE("Transport::cull_announce_table: Removing destination " + destination_hash.toHex() + " from path table"); + TRACEF("Transport::cull_announce_table: Removing destination %s from path table", destination_hash.toHex().c_str()); if (_announce_table.erase(destination_hash) < 1) { - WARNING("Failed to remove destination " + destination_hash.toHex() + " from path table"); + WARNINGF("Failed to remove destination %s from path table", destination_hash.toHex().c_str()); } ++count; if (_announce_table.size() <= _path_table_maxsize) { break; } } - DEBUG("Removed " + std::to_string(count) + " path(s) from path table"); + DEBUGF("Removed %d path(s) from path table", count); } catch (const std::bad_alloc& e) { ERROR("cull_announce_table: bad_alloc - out of memory building sort index, falling back to single erase"); @@ -4127,7 +4127,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence:: } } catch (const std::exception& e) { - ERROR(std::string("cull_announce_table: exception: ") + e.what()); + ERRORF("cull_announce_table: exception: %s", e.what()); } } } diff --git a/src/Utilities/Persistence.h b/src/Utilities/Persistence.h index 3c006e07..bda8b102 100644 --- a/src/Utilities/Persistence.h +++ b/src/Utilities/Persistence.h @@ -148,14 +148,14 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - //TRACE("<<< Serializing interface hash " + src.get_hash().toHex()); + //TRACEF("<<< Serializing interface hash %s", src.get_hash().toHex().c_str()); return dst.set(src.get_hash().toHex()); } static RNS::Interface fromJson(JsonVariantConst src) { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - //TRACE(">>> Deserialized interface hash " + hash.toHex()); + //TRACEF(">>> Deserialized interface hash %s", hash.toHex().c_str()); //TRACE(">>> Querying transport for interface"); // Query transport for matching interface return RNS::Transport::find_interface_from_hash(hash); @@ -178,7 +178,7 @@ namespace ArduinoJson { if (!src) { return dst.set(nullptr); } - //TRACE("<<< Serializing packet hash " + src.get_hash().toHex()); + //TRACEF("<<< Serializing packet hash %s", src.get_hash().toHex().c_str()); // 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()); @@ -187,7 +187,7 @@ namespace ArduinoJson { if (!src.isNull()) { RNS::Bytes hash; hash.assignHex(src.as()); - //TRACE(">>> Deserialized packet hash " + hash.toHex()); + //TRACEF(">>> Deserialized packet hash %s", hash.toHex().c_str()); //TRACE(">>> Querying transport for cached packet"); // Query transport for matching packet return RNS::Transport::get_cached_packet(hash); @@ -300,7 +300,7 @@ namespace ArduinoJson { } } else { - TRACE("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached"); + TRACEF("Destination announce packet %s is already cached", src._announce_packet.get_hash().toHex().c_str()); } } else { @@ -397,7 +397,7 @@ namespace RNS { } } else { - TRACE("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached"); + TRACEF("Destination announce packet %s is already cached", src._announce_packet.get_hash().toHex().c_str()); } } else { @@ -520,7 +520,7 @@ namespace RNS { namespace Persistence { size_t read = RNS::Utilities::OS::read_file(file_path, _buffer); if (read > 0) { TRACEF("Persistence::deserialize: read: %d bytes", _buffer.size()); - //TRACE("testDeserializeVector: data: " + _buffer.toString()); + //TRACEF("testDeserializeVector: data: %s", _buffer.toString().c_str()); #ifdef USE_MSGPACK DeserializationError error = deserializeMsgPack(_document, _buffer.data()); #else diff --git a/test/common/filesystem/FileSystem.h b/test/common/filesystem/FileSystem.h index 6df3cdaf..c74e65c6 100644 --- a/test/common/filesystem/FileSystem.h +++ b/test/common/filesystem/FileSystem.h @@ -147,7 +147,7 @@ class FileSystem : public RNS::FileSystemImpl { return true; } else { - ERROR("file_exists: failed to open file " + std::string(file_path)); + ERRORF("file_exists: failed to open file %s", file_path); return false; } } @@ -181,9 +181,9 @@ class FileSystem : public RNS::FileSystemImpl { //size_t read = fread(data.writable(size), size, 1, file); read = fread(data.writable(size), 1, size, file); #endif - TRACE("read_file: read " + std::to_string(read) + " bytes from file " + std::string(file_path)); + TRACEF("read_file: read %zu bytes from file %s", read, file_path); if (read != size) { - ERROR("read_file: failed to read file " + std::string(file_path)); + ERRORF("read_file: failed to read file %s", file_path); data.clear(); } //TRACE("read_file: closing input file"); @@ -199,7 +199,7 @@ class FileSystem : public RNS::FileSystemImpl { #endif } else { - ERROR("read_file: failed to open input file " + std::string(file_path)); + ERRORF("read_file: failed to open input file %s", file_path); } return read; } @@ -227,9 +227,9 @@ class FileSystem : public RNS::FileSystemImpl { //size_t wrote = fwrite(data.data(), data.size(), 1, file); wrote = fwrite(data.data(), 1, data.size(), file); #endif - TRACE("write_file: wrote " + std::to_string(wrote) + " bytes to file " + std::string(file_path)); + TRACEF("write_file: wrote %zu bytes to file %s", wrote, file_path); if (wrote < data.size()) { - WARNING("write_file: not all data was written to file " + std::string(file_path)); + WARNINGF("write_file: not all data was written to file %s", file_path); } //TRACE("write_file: closing output file"); #ifdef ARDUINO @@ -244,7 +244,7 @@ class FileSystem : public RNS::FileSystemImpl { #endif } else { - ERROR("write_file: failed to open output file " + std::string(file_path)); + ERRORF("write_file: failed to open output file %s", file_path); } return wrote; } @@ -374,7 +374,7 @@ class FileSystem : public RNS::FileSystemImpl { } /*virtua*/ bool directory_exists(const char* directory_path) { - TRACE("directory_exists: checking for existence of directory " + std::string(directory_path)); + TRACEF("directory_exists: checking for existence of directory %s", directory_path); #ifdef ARDUINO #ifdef BOARD_ESP32 File file = SPIFFS.open(directory_path, FILE_READ); @@ -409,13 +409,13 @@ class FileSystem : public RNS::FileSystemImpl { #ifdef ARDUINO #ifdef BOARD_ESP32 if (!SPIFFS.mkdir(directory_path)) { - ERROR("create_directory: failed to create directorty " + std::string(directory_path)); + ERRORF("create_directory: failed to create directorty %s", directory_path); return false; } return true; #elif BOARD_NRF52 if (!InternalFS.mkdir(directory_path)) { - ERROR("create_directory: failed to create directorty " + std::string(directory_path)); + ERRORF("create_directory: failed to create directorty %s", directory_path); return false; } return true; @@ -433,18 +433,18 @@ class FileSystem : public RNS::FileSystemImpl { } /*virtua*/ bool remove_directory(const char* directory_path) { - TRACE("remove_directory: removing directory " + std::string(directory_path)); + TRACEF("remove_directory: removing directory %s", directory_path); #ifdef ARDUINO #ifdef BOARD_ESP32 //if (!LittleFS.rmdir_r(directory_path)) { if (!SPIFFS.rmdir(directory_path)) { - ERROR("remove_directory: failed to remove directorty " + std::string(directory_path)); + ERRORF("remove_directory: failed to remove directorty %s", directory_path); return false; } return true; #elif BOARD_NRF52 if (!InternalFS.rmdir_r(directory_path)) { - ERROR("remove_directory: failed to remove directory " + std::string(directory_path)); + ERRORF("remove_directory: failed to remove directory %s", directory_path); return false; } return true; @@ -454,7 +454,7 @@ class FileSystem : public RNS::FileSystemImpl { #else // Native if (rmdir(directory_path) == 0) { - ERROR("remove_directory: failed to remove directory " + std::string(directory_path)); + ERRORF("remove_directory: failed to remove directory %s", directory_path); return false; } return true; @@ -462,7 +462,7 @@ class FileSystem : public RNS::FileSystemImpl { } /*virtua*/ std::list list_directory(const char* directory_path) { - TRACE("list_directory: listing directory " + std::string(directory_path)); + TRACEF("list_directory: listing directory %s", directory_path); std::list files; #ifdef ARDUINO #ifdef BOARD_ESP32 @@ -471,7 +471,7 @@ class FileSystem : public RNS::FileSystemImpl { File root = InternalFS.open(directory_path); #endif if (!root) { - ERROR("list_directory: failed to open directory " + std::string(directory_path)); + ERRORF("list_directory: failed to open directory %s", directory_path); return files; } File file = root.openNextFile(); @@ -491,7 +491,7 @@ class FileSystem : public RNS::FileSystemImpl { // Native DIR *dir = opendir(directory_path); if (dir == NULL) { - ERROR("list_directory: failed to open directory " + std::string(directory_path)); + ERRORF("list_directory: failed to open directory %s", directory_path); return files; } struct dirent *entry; @@ -503,7 +503,7 @@ class FileSystem : public RNS::FileSystemImpl { files.push_back(name); } if (closedir(dir) == -1) { - ERROR("list_directory: failed to close directory " + std::string(directory_path)); + ERRORF("list_directory: failed to close directory %s", directory_path); } return files; diff --git a/test/test_bytes/test_main.cpp b/test/test_bytes/test_main.cpp index 6bb25805..5ec85937 100644 --- a/test/test_bytes/test_main.cpp +++ b/test/test_bytes/test_main.cpp @@ -64,9 +64,9 @@ void testBytesMain() { bytes += prebuf + postbuf; TEST_ASSERT_EQUAL_size_t(14, bytes.size()); TEST_ASSERT_EQUAL_MEMORY("FooHello World", bytes.data(), bytes.size()); - TRACE("assign bytes: " + bytes.toString()); - TRACE("assign prebuf: " + prebuf.toString()); - TRACE("assign postbuf: " + postbuf.toString()); + TRACEF("assign bytes: %s", bytes.toString().c_str()); + TRACEF("assign prebuf: %s", prebuf.toString().c_str()); + TRACEF("assign postbuf: %s", postbuf.toString().c_str()); // test string assignment with addition bytes = prebuf + postbuf; @@ -83,56 +83,56 @@ void testBytesMain() { // test left in range { RNS::Bytes left(bytes.left(5)); - TRACE("left: " + left.toString()); + TRACEF("left: %s", left.toString().c_str()); TEST_ASSERT_EQUAL_size_t(5, left.size()); TEST_ASSERT_EQUAL_MEMORY("Hello", left.data(), left.size()); } // test left oob { RNS::Bytes left(bytes.left(20)); - TRACE("oob left: " + left.toString()); + TRACEF("oob left: %s", left.toString().c_str()); TEST_ASSERT_EQUAL_size_t(11, left.size()); TEST_ASSERT_EQUAL_MEMORY("Hello World", left.data(), left.size()); } // test right in range { RNS::Bytes right(bytes.right(5)); - TRACE("right: " + right.toString()); + TRACEF("right: %s", right.toString().c_str()); TEST_ASSERT_EQUAL_size_t(5, right.size()); TEST_ASSERT_EQUAL_MEMORY("World", right.data(), right.size()); } // test right oob { RNS::Bytes right(bytes.right(20)); - TRACE("oob right: " + right.toString()); + TRACEF("oob right: %s", right.toString().c_str()); TEST_ASSERT_EQUAL_size_t(11, right.size()); TEST_ASSERT_EQUAL_MEMORY("Hello World", right.data(), right.size()); } // test mid in range { RNS::Bytes mid(bytes.mid(3, 5)); - TRACE("mid: " + mid.toString()); + TRACEF("mid: %s", mid.toString().c_str()); TEST_ASSERT_EQUAL_size_t(5, mid.size()); TEST_ASSERT_EQUAL_MEMORY("lo Wo", mid.data(), mid.size()); } // test mid oob pos { RNS::Bytes mid(bytes.mid(20, 5)); - TRACE("oob pos mid: " + mid.toString()); + TRACEF("oob pos mid: %s", mid.toString().c_str()); TEST_ASSERT_FALSE(mid); TEST_ASSERT_EQUAL_size_t(0, mid.size()); } // test mid oob pos { RNS::Bytes mid(bytes.mid(3, 20)); - TRACE("oob len mid: " + mid.toString()); + TRACEF("oob len mid: %s", mid.toString().c_str()); TEST_ASSERT_EQUAL_size_t(8, mid.size()); TEST_ASSERT_EQUAL_MEMORY("lo World", mid.data(), mid.size()); } // test mid to end variant { RNS::Bytes mid(bytes.mid(3)); - TRACE("end mid: " + mid.toString()); + TRACEF("end mid: %s", mid.toString().c_str()); TEST_ASSERT_EQUAL_size_t(8, mid.size()); TEST_ASSERT_EQUAL_MEMORY("lo World", mid.data(), mid.size()); } @@ -142,7 +142,7 @@ void testBytesMain() { { RNS::Bytes shrink(bytes); shrink.resize(5); - TRACE("shrink: " + shrink.toString()); + TRACEF("shrink: %s", shrink.toString().c_str()); TEST_ASSERT_EQUAL_size_t(5, shrink.size()); TEST_ASSERT_EQUAL_MEMORY("Hello", shrink.data(), shrink.size()); } @@ -151,11 +151,11 @@ void testBytesMain() { HEAD("TestBytes: trim", RNS::LOG_TRACE); { RNS::Bytes bytes("Hello World"); - TRACE("orig: " + bytes.toString()); + TRACEF("orig: %s", bytes.toString().c_str()); TEST_ASSERT_EQUAL_size_t(11, bytes.size()); TEST_ASSERT_EQUAL_MEMORY("Hello World", bytes.data(), bytes.size()); bytes = bytes.left(5); - TRACE("trim: " + bytes.toString()); + TRACEF("trim: %s", bytes.toString().c_str()); TEST_ASSERT_EQUAL_size_t(5, bytes.size()); TEST_ASSERT_EQUAL_MEMORY("Hello", bytes.data(), bytes.size()); } @@ -226,9 +226,9 @@ void testCowBytes() { TEST_ASSERT_EQUAL_MEMORY("1", bytes3.data(), bytes3.size()); TEST_ASSERT_EQUAL_PTR(bytes2.data(), bytes3.data()); - 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()); + TRACEF("pre bytes1 ptr: %p data: %s", (void*)bytes1.data(), bytes1.toString().c_str()); + TRACEF("pre bytes2 ptr: %p data: %s", (void*)bytes2.data(), bytes2.toString().c_str()); + TRACEF("pre bytes3 ptr: %p data: %s", (void*)bytes3.data(), bytes3.toString().c_str()); //bytes1.append("mississippi"); //assert(bytes1.size() == 12); @@ -245,9 +245,9 @@ void testCowBytes() { TEST_ASSERT_EQUAL_MEMORY("mississippi", bytes3.data(), bytes3.size()); TEST_ASSERT_NOT_EQUAL(bytes2.data(), bytes3.data()); - 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()); + TRACEF("post bytes1 ptr: %p data: %s", (void*)bytes1.data(), bytes1.toString().c_str()); + TRACEF("post bytes2 ptr: %p data: %s", (void*)bytes2.data(), bytes2.toString().c_str()); + TRACEF("post bytes3 ptr: %p data: %s", (void*)bytes3.data(), bytes3.toString().c_str()); } void testBytesConversion() { @@ -255,14 +255,14 @@ void testBytesConversion() { { RNS::Bytes bytes("Hello World"); std::string hex = bytes.toHex(true); - TRACE("text: \"" + bytes.toString() + "\" upper hex: \"" + hex + "\""); + TRACEF("text: \"%s\" upper hex: \"%s\"", bytes.toString().c_str(), hex.c_str()); TEST_ASSERT_EQUAL_size_t(22, hex.length()); TEST_ASSERT_EQUAL_STRING("48656C6C6F20576F726C64", hex.c_str()); } { RNS::Bytes bytes("Hello World"); std::string hex = bytes.toHex(false); - TRACE("text: \"" + bytes.toString() + "\" lower hex: \"" + hex + "\""); + TRACEF("text: \"%s\" lower hex: \"%s\"", bytes.toString().c_str(), hex.c_str()); TEST_ASSERT_EQUAL_size_t(22, hex.length()); TEST_ASSERT_EQUAL_STRING("48656c6c6f20576f726c64", hex.c_str()); } @@ -271,7 +271,7 @@ void testBytesConversion() { RNS::Bytes bytes; bytes.assignHex(hex.c_str()); std::string text = bytes.toString(); - TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); TEST_ASSERT_EQUAL_size_t(11, text.length()); TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str()); } @@ -280,21 +280,21 @@ void testBytesConversion() { RNS::Bytes bytes; bytes.assignHex(hex.c_str()); std::string text = bytes.toString(); - TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); TEST_ASSERT_EQUAL_size_t(11, text.length()); TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str()); // overwrite bytes.assignHex(hex.c_str()); text = bytes.toString(); - TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); TEST_ASSERT_EQUAL_size_t(11, text.length()); TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str()); // apend bytes.appendHex(hex.c_str()); text = bytes.toString(); - TRACE("hex: \"" + hex + "\" text: \"" + text + "\""); + TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); TEST_ASSERT_EQUAL_size_t(22, text.length()); TEST_ASSERT_EQUAL_STRING("Hello WorldHello World", text.c_str()); } diff --git a/test/test_collections/test_main.cpp b/test/test_collections/test_main.cpp index db476535..b6c8bbf3 100644 --- a/test/test_collections/test_main.cpp +++ b/test/test_collections/test_main.cpp @@ -28,14 +28,14 @@ void testBytesMap() TEST_ASSERT_NOT_EQUAL(map.end(), preit); TEST_ASSERT_EQUAL_STRING("hello", (*preit).second.c_str()); if (preit != map.end()) { - TRACE(std::string("found prebuf: ") + (*preit).second); + TRACEF("found prebuf: %s", (*preit).second.c_str()); } auto postit = map.find(postbuf); TEST_ASSERT_NOT_EQUAL(map.end(), postit); TEST_ASSERT_EQUAL_STRING("world", (*postit).second.c_str()); if (postit != map.end()) { - TRACE(std::string("found postbuf: ") + (*postit).second); + TRACEF("found postbuf: %s", (*postit).second.c_str()); } const uint8_t newstr[] = "World"; @@ -46,7 +46,7 @@ void testBytesMap() TEST_ASSERT_NOT_EQUAL(map.end(), newit); TEST_ASSERT_EQUAL_STRING("world", (*newit).second.c_str()); if (newit != map.end()) { - TRACE(std::string("found newbuf: ") + (*newit).second); + TRACEF("found newbuf: %s", (*newit).second.c_str()); } std::string str = map["World"]; @@ -85,7 +85,7 @@ void testOldMap() { } } for (auto& pair : entries) { - TRACE("entries: " + pair.second._hash.toString()); + TRACEF("entries: %s", pair.second._hash.toString().c_str()); } TEST_ASSERT_EQUAL_size_t(2, entries.size()); TEST_ASSERT_EQUAL_size_t(2, other_entries.size()); @@ -113,7 +113,7 @@ void testNewMap() { } } for (auto& [hash, entry] : entries) { - TRACE("entries: " + entry._hash.toString()); + TRACEF("entries: %s", entry._hash.toString().c_str()); } TEST_ASSERT_EQUAL_size_t(2, entries.size()); TEST_ASSERT_EQUAL_size_t(2, other_entries.size()); diff --git a/test/test_filesystem/test_main.cpp b/test/test_filesystem/test_main.cpp index 36077dfd..17a2ad7e 100644 --- a/test/test_filesystem/test_main.cpp +++ b/test/test_filesystem/test_main.cpp @@ -165,22 +165,22 @@ void readFileStream(const char* file_path) { void testListDirectory() { size_t pre_memory = RNS::Utilities::OS::heap_available(); - INFO("testListDirectory: pre-mem: " + std::to_string(pre_memory)); + INFOF("testListDirectory: pre-mem: %zu", pre_memory); { for (int i = 0; i < 1; i++) { std::list files; files = RNS::Utilities::OS::list_directory("/"); for (auto& file : files) { - INFO("FILE: " + file); + INFOF("FILE: %s", file.c_str()); } } } size_t post_memory = RNS::Utilities::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)); + INFOF("testListDirectory: post-mem: %zu", post_memory); + INFOF("testListDirectory: diff-mem: %zu", diff_memory); TEST_ASSERT_EQUAL_size_t(0, diff_memory); } diff --git a/test/test_os/test_main.cpp b/test/test_os/test_main.cpp index 96b06347..dbfa7778 100644 --- a/test/test_os/test_main.cpp +++ b/test/test_os/test_main.cpp @@ -20,12 +20,12 @@ void testTime() double diff_time; diff_time = (double)(end_ltime - start_ltime) / 1000.0; - TRACE(std::string("ltime diff: ") + std::to_string(diff_time)); + TRACEF("ltime diff: %f", diff_time); TEST_ASSERT_TRUE(diff_time > sleep_time * 0.99); TEST_ASSERT_TRUE(diff_time < sleep_time * 1.01); diff_time = end_dtime - start_dtime; - TRACE(std::string("dtime diff: ") + std::to_string(diff_time)); + TRACEF("dtime diff: %f", diff_time); TEST_ASSERT_TRUE(diff_time > sleep_time * 0.99); TEST_ASSERT_TRUE(diff_time < sleep_time * 1.01); diff --git a/test/test_persistence/test_main.cpp b/test/test_persistence/test_main.cpp index ed6d6feb..d47d2fbe 100644 --- a/test/test_persistence/test_main.cpp +++ b/test/test_persistence/test_main.cpp @@ -26,12 +26,12 @@ class TestInterface : public RNS::InterfaceImpl { private: virtual void send_outgoing(const RNS::Bytes& data) { - DEBUG("TestInterface.send_outgoing: data: " + data.toHex()); + DEBUGF("TestInterface.send_outgoing: data: %s", data.toHex().c_str()); // Perform post-send housekeeping InterfaceImpl::handle_outgoing(data); } void on_incoming(const RNS::Bytes& data) { - DEBUG("TestInterface.on_incoming: data: " + data.toHex()); + DEBUGF("TestInterface.on_incoming: data: %s", data.toHex().c_str()); // Pass received data on to transport InterfaceImpl::handle_incoming(data); } @@ -82,7 +82,7 @@ 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()) { - TRACE("wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("wrote: %zu bytes", data.size()); } else { TRACE("write failed"); @@ -93,8 +93,8 @@ void testWrite() { void testRead() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_file_path, data) > 0) { - TRACE("read: " + std::to_string(data.size()) + " bytes"); - TRACE("data: " + data.toString()); + TRACEF("read: %zu bytes", data.size()); + TRACEF("data: %s", data.toString().c_str()); TEST_ASSERT_EQUAL_size_t(strlen(test_file_data), data.size()); TEST_ASSERT_NOT_NULL(data.data()); TEST_ASSERT_EQUAL_MEMORY(test_file_data, data.data(), strlen(test_file_data)); @@ -132,10 +132,10 @@ void testSerializeObject() { if (length < size) { data.resize(length); } - TRACE("serialized " + std::to_string(length) + " bytes"); + TRACEF("serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) { - TRACE("wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("wrote: %zu bytes", data.size()); } else { TRACE("write failed"); @@ -157,14 +157,14 @@ void testDeserializeObject() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) { if (data) { - TRACE("read: " + std::to_string(data.size()) + " bytes"); - //TRACE("data: " + data.toString()); + TRACEF("read: %zu bytes", data.size()); + //TRACEF("data: %s", data.toString().c_str()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { JsonObject root = doc.as(); for (JsonPair kv : root) { - TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); + TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as()); } } else { @@ -184,7 +184,7 @@ void testSerializeObject() { std::vector vec({"one", "two"}); TestObject test("test", vec); - TRACE("testSerializeObject: test: " + test.toString()); + TRACEF("testSerializeObject: test: %s", test.toString().c_str()); JsonDocument doc; doc.set(test); @@ -196,10 +196,10 @@ void testSerializeObject() { if (length < size) { data.resize(length); } - TRACE("testSerializeObject: serialized " + std::to_string(length) + " bytes"); + TRACEF("testSerializeObject: serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) { - TRACE("testSerializeObject: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testSerializeObject: wrote: %zu bytes", data.size()); } else { TRACE("testSerializeObject: write failed"); @@ -219,17 +219,17 @@ void testDeserializeObject() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) { - TRACE("testDeserializeObject: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("data: " + data.toString()); + TRACEF("testDeserializeObject: read: %zu bytes", data.size()); + //TRACEF("data: %s", data.toString().c_str()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); + // TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as()); //} TestObject test = doc.as(); - TRACE("testDeserializeObject: test: " + test.toString()); + TRACEF("testDeserializeObject: test: %s", test.toString().c_str()); } else { TRACE("testDeserializeObject: failed to deserialize"); @@ -292,10 +292,10 @@ void testSerializeVector() { if (length < size) { data.resize(length); } - TRACE("testSerializeVector: serialized " + std::to_string(length) + " bytes"); + TRACEF("testSerializeVector: serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_vector_path, data) == data.size()) { - TRACE("testSerializeVector: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testSerializeVector: wrote: %zu bytes", data.size()); } else { TRACE("testSerializeVector: write failed"); @@ -315,8 +315,8 @@ void testDeserializeVector() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_vector_path, data) > 0) { - TRACE("testDeserializeVector: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("testDeserializeVector: data: " + data.toString()); + TRACEF("testDeserializeVector: read: %zu bytes", data.size()); + //TRACEF("testDeserializeVector: data: %s", data.toString().c_str()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { @@ -324,12 +324,12 @@ void testDeserializeVector() { std::vector vector = doc.as>(); for (auto& test : vector) { - TRACE("testDeserializeVector: entry: " + test.toString()); + TRACEF("testDeserializeVector: entry: %s", test.toString().c_str()); } //JsonArray arr = doc.as(); //for (JsonVariant elem : arr) { - // TRACE("testDeserializeVector: entry: " + elem.as().toString()); + // TRACEF("testDeserializeVector: entry: %s", elem.as().toString().c_str()); //} } else { @@ -381,10 +381,10 @@ void testSerializeSet() { if (length < size) { data.resize(length); } - TRACE("testSerializeSet: serialized " + std::to_string(length) + " bytes"); + TRACEF("testSerializeSet: serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_set_path, data) == data.size()) { - TRACE("testSerializeSet: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testSerializeSet: wrote: %zu bytes", data.size()); } else { TRACE("testSerializeSet: write failed"); @@ -404,8 +404,8 @@ void testDeserializeSet() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_set_path, data) > 0) { - TRACE("testDeserializeSet: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("testDeserializeSet: data: " + data.toString()); + TRACEF("testDeserializeSet: read: %zu bytes", data.size()); + //TRACEF("testDeserializeSet: data: %s", data.toString().c_str()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { @@ -413,12 +413,12 @@ void testDeserializeSet() { std::set set = doc.as>(); for (auto& test : set) { - TRACE("testDeserializeSet: entry: " + test.toString()); + TRACEF("testDeserializeSet: entry: %s", test.toString().c_str()); } //JsonArray arr = doc.as(); //for (JsonVariant elem : arr) { - // TRACE("testDeserializeSet: entry: " + elem.as().toString()); + // TRACEF("testDeserializeSet: entry: %s", elem.as().toString().c_str()); //} } else { @@ -463,10 +463,10 @@ void testSerializeMap() { if (length < size) { data.resize(length); } - TRACE("testSerializeMap: serialized " + std::to_string(length) + " bytes"); + TRACEF("testSerializeMap: serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_map_path, data) == data.size()) { - TRACE("testSerializeMap: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testSerializeMap: wrote: %zu bytes", data.size()); } else { TRACE("testSerializeMap: write failed"); @@ -486,8 +486,8 @@ void testDeserializeMap() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_map_path, data) > 0) { - TRACE("testDeserializeMap: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("testDeserializeMap: data: " + data.toString()); + TRACEF("testDeserializeMap: read: %zu bytes", data.size()); + //TRACEF("testDeserializeMap: data: %s", data.toString().c_str()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { @@ -495,12 +495,12 @@ void testDeserializeMap() { std::map map(doc.as>()); for (auto& [str, test] : map) { - TRACE("testDeserializeMap: entry: " + str + " = " + test.toString()); + TRACEF("testDeserializeMap: entry: %s = %s", str.c_str(), test.toString().c_str()); } //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // TRACE("testDeserializeMap: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as().toString()); + // TRACEF("testDeserializeMap: entry: %s = %s", kv.key().c_str(), kv.value().as().toString().c_str()); //} } else { @@ -569,27 +569,27 @@ void testSerializeDestinationTable() { } for (auto& [hash, test] : map) { - TRACE("testSerializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString()); + TRACEF("testSerializeDestinationTable: entry: %s = %s", hash.toHex().c_str(), test.debugString().c_str()); } JsonDocument doc; doc.set(map); - TRACE("testSerializeDestinationTable: doc size " + std::to_string(doc.size())); + TRACEF("testSerializeDestinationTable: doc size %zu", doc.size()); RNS::Bytes data; size_t size = 32768; //size_t size = BUFFER_SIZE; - TRACE("testSerializeDestinationTable: buffer size " + std::to_string(size) + " bytes"); + TRACEF("testSerializeDestinationTable: buffer size %zu bytes", size); size_t length = serializeJson(doc, data.writable(size), size); //size_t length = serializeMsgPack(doc, data.writable(size), size); if (length < size) { data.resize(length); } - TRACE("testSerializeDestinationTable: serialized " + std::to_string(length) + " bytes"); + TRACEF("testSerializeDestinationTable: serialized %zu bytes", length); if (length > 0) { - TRACE("testSerializeDestinationTable: json: " + data.toString()); + TRACEF("testSerializeDestinationTable: json: %s", data.toString().c_str()); if (RNS::Utilities::OS::write_file(test_destination_table_path, data) == data.size()) { - TRACE("testSerializeDestinationTable: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testSerializeDestinationTable: wrote: %zu bytes", data.size()); } else { TRACE("testSerializeDestinationTable: write failed"); @@ -607,27 +607,27 @@ void testDeserializeDestinationTable() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_destination_table_path, data) > 0) { - TRACE("testDeserializeDestinationTable: read: " + std::to_string(data.size()) + " bytes"); - TRACE("testDeserializeDestinationTable: json: " + data.toString()); + TRACEF("testDeserializeDestinationTable: read: %zu bytes", data.size()); + TRACEF("testDeserializeDestinationTable: json: %s", data.toString().c_str()); JsonDocument doc; - //TRACE("testDeserializeVector: data: " + data.toString()); + //TRACEF("testDeserializeVector: data: %s", data.toString().c_str()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); - TRACE("testDeserializeDestinationTable: doc size " + std::to_string(doc.size())); + TRACEF("testDeserializeDestinationTable: doc size %zu", doc.size()); if (!error) { - TRACE("testDeserializeDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes"); - //TRACE("testDeserializeDestinationTable: json: " + data.toString()); + TRACEF("testDeserializeDestinationTable: successfully deserialized %zu bytes", data.size()); + //TRACEF("testDeserializeDestinationTable: json: %s", data.toString().c_str()); static std::map map(doc.as>()); TEST_ASSERT_EQUAL_size_t(22, map.size()); for (auto& [hash, test] : map) { - TRACE("testDeserializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString()); + TRACEF("testDeserializeDestinationTable: entry: %s = %s", hash.toHex().c_str(), test.debugString().c_str()); } //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // TRACE("testDeserializeDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as().toString()); + // TRACEF("testDeserializeDestinationTable: entry: %s = %s", kv.key().c_str(), kv.value().as().toString().c_str()); //} } else { @@ -651,26 +651,26 @@ void testDeserializeEmptyDestinationTable() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_empty_destination_table_path, data) > 0) { - TRACE("testDeserializeEmptyDestinationTable: read: " + std::to_string(data.size()) + " bytes"); + TRACEF("testDeserializeEmptyDestinationTable: read: %zu bytes", data.size()); JsonDocument doc; - //TRACE("testDeserializeVector: data: " + data.toString()); + //TRACEF("testDeserializeVector: data: %s", data.toString().c_str()); DeserializationError error = deserializeJson(doc, data.data()); //DeserializationError error = deserializeMsgPack(doc, data.data()); - TRACE("testDeserializeEmptyDestinationTable: doc size " + std::to_string(doc.size())); + TRACEF("testDeserializeEmptyDestinationTable: doc size %zu", doc.size()); if (!error) { - TRACE("testDeserializeEmptyDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes"); - TRACE("testDeserializeEmptyDestinationTable: json: " + data.toString()); + TRACEF("testDeserializeEmptyDestinationTable: successfully deserialized %zu bytes", data.size()); + TRACEF("testDeserializeEmptyDestinationTable: json: %s", data.toString().c_str()); static std::map map(doc.as>()); TEST_ASSERT_EQUAL_size_t(0, map.size()); for (auto& [hash, test] : map) { - TRACE("testDeserializeEmptyDestinationTable: entry: " + hash.toHex() + " = " + test.debugString()); + TRACEF("testDeserializeEmptyDestinationTable: entry: %s = %s", hash.toHex().c_str(), test.debugString().c_str()); } //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // TRACE("testDeserializeEmptyDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as().toString()); + // TRACEF("testDeserializeEmptyDestinationTable: entry: %s = %s", kv.key().c_str(), kv.value().as().toString().c_str()); //} } else { @@ -715,7 +715,7 @@ void testJsonMsgpackSerializeObject() { std::vector vec({"one", "two"}); TestObject test("test", vec); - TRACE("testJsonMsgpackSerializeObject: test: " + test.toString()); + TRACEF("testJsonMsgpackSerializeObject: test: %s", test.toString().c_str()); JsonDocument doc; doc.set(test); @@ -726,10 +726,10 @@ void testJsonMsgpackSerializeObject() { if (length < size) { data.resize(length); } - TRACE("testJsonMsgpackSerializeObject: serialized " + std::to_string(length) + " bytes"); + TRACEF("testJsonMsgpackSerializeObject: serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) { - TRACE("testJsonMsgpackSerializeObject: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testJsonMsgpackSerializeObject: wrote: %zu bytes", data.size()); } else { TRACE("testJsonMsgpackSerializeObject: write failed"); @@ -749,16 +749,16 @@ void testJsonMsgpackDeserializeObject() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) { - TRACE("testJsonMsgpackDeserializeObject: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("data: " + data.toString()); + TRACEF("testJsonMsgpackDeserializeObject: read: %zu bytes", data.size()); + //TRACEF("data: %s", data.toString().c_str()); DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); + // TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as()); //} TestObject test = doc.as(); - TRACE("testJsonMsgpackDeserializeObject: test: " + test.toString()); + TRACEF("testJsonMsgpackDeserializeObject: test: %s", test.toString().c_str()); } else { TRACE("testJsonMsgpackDeserializeObject: failed to deserialize"); @@ -809,10 +809,10 @@ void testJsonMsgpackSerializeArray() { if (length < size) { data.resize(length); } - TRACE("testJsonMsgpackSerializeArray: serialized " + std::to_string(length) + " bytes"); + TRACEF("testJsonMsgpackSerializeArray: serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_array_path, data) == data.size()) { - TRACE("testJsonMsgpackSerializeArray: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testJsonMsgpackSerializeArray: wrote: %zu bytes", data.size()); } else { TRACE("testJsonMsgpackSerializeArray: write failed"); @@ -832,8 +832,8 @@ void testJsonMsgpackDeserializeArray() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_array_path, data) > 0) { - TRACE("testJsonMsgpackDeserializeArray: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("data: " + data.toString()); + TRACEF("testJsonMsgpackDeserializeArray: read: %zu bytes", data.size()); + //TRACEF("data: %s", data.toString().c_str()); DeserializationError error = deserializeMsgPack(doc, data.data(), data.size()); if (!error) { JsonArray array = doc.as(); @@ -869,7 +869,7 @@ void testMsgpackSerializeObject() { std::vector vec({"one", "two"}); TestObject test("test", vec); - TRACE("testMsgpackSerializeObject: test: " + test.toString()); + TRACEF("testMsgpackSerializeObject: test: %s", test.toString().c_str()); JsonDocument doc; @@ -879,10 +879,10 @@ void testMsgpackSerializeObject() { if (length < size) { data.resize(length); } - TRACE("testMsgpackSerializeObject: serialized " + std::to_string(length) + " bytes"); + TRACEF("testMsgpackSerializeObject: serialized %zu bytes", length); if (length > 0) { if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) { - TRACE("testMsgpackSerializeObject: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testMsgpackSerializeObject: wrote: %zu bytes", data.size()); } else { TRACE("testMsgpackSerializeObject: write failed"); @@ -902,16 +902,16 @@ void testMsgpackDeserializeObject() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) { - TRACE("testMsgpackDeserializeObject: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("data: " + data.toString()); + TRACEF("testMsgpackDeserializeObject: read: %zu bytes", data.size()); + //TRACEF("data: %s", data.toString().c_str()); DeserializationError error = deserializeMsgPack(doc, data.data()); if (!error) { //JsonObject root = doc.as(); //for (JsonPair kv : root) { - // TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as()); + // TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as()); //} TestObject test = doc.as(); - TRACE("testMsgpackDeserializeObject: test: " + test.toString()); + TRACEF("testMsgpackDeserializeObject: test: %s", test.toString().c_str()); } else { TRACE("testMsgpackDeserializeObject: failed to deserialize"); @@ -951,10 +951,10 @@ void testMsgpackSerializeArray() { //packer.to_array(time, one.collection(), two.collection()); RNS::Bytes data(packer.data(), packer.size()); - TRACE("testMsgpackSerializeArray: serialized " + std::to_string(data.size()) + " bytes"); + TRACEF("testMsgpackSerializeArray: serialized %zu bytes", data.size()); if (packer.size() > 0) { if (RNS::Utilities::OS::write_file(test_array_path, data) == data.size()) { - TRACE("testMsgpackSerializeArray: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testMsgpackSerializeArray: wrote: %zu bytes", data.size()); } else { TRACE("testMsgpackSerializeArray: write failed"); @@ -974,8 +974,8 @@ void testMsgpackDeserializeArray() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_array_path, data) > 0) { - TRACE("testMsgpackDeserializeArray: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("data: " + data.toString()); + TRACEF("testMsgpackDeserializeArray: read: %zu bytes", data.size()); + //TRACEF("data: %s", data.toString().c_str()); MsgPack::Unpacker unpacker; unpacker.feed(data.data(), data.size()); double time; @@ -1018,10 +1018,10 @@ void testMsgpackSerializeSeries() { //packer.serialize(time, one.collection(), two.collection()); RNS::Bytes data(packer.data(), packer.size()); - TRACE("testMsgpackSerializeSeries: serialized " + std::to_string(data.size()) + " bytes"); + TRACEF("testMsgpackSerializeSeries: serialized %zu bytes", data.size()); if (packer.size() > 0) { if (RNS::Utilities::OS::write_file(test_series_path, data) == data.size()) { - TRACE("testMsgpackSerializeSeries: wrote: " + std::to_string(data.size()) + " bytes"); + TRACEF("testMsgpackSerializeSeries: wrote: %zu bytes", data.size()); } else { TRACE("testMsgpackSerializeSeries: write failed"); @@ -1041,8 +1041,8 @@ void testMsgpackDeserializeSeries() { RNS::Bytes data; if (RNS::Utilities::OS::read_file(test_series_path, data) > 0) { - TRACE("testMsgpackDeserializeSeries: read: " + std::to_string(data.size()) + " bytes"); - //TRACE("data: " + data.toString()); + TRACEF("testMsgpackDeserializeSeries: read: %zu bytes", data.size()); + //TRACEF("data: %s", data.toString().c_str()); MsgPack::Unpacker unpacker; unpacker.feed(data.data(), data.size()); double time; diff --git a/test/test_reference/test_main.cpp b/test/test_reference/test_main.cpp index a79a78dd..977bc427 100644 --- a/test/test_reference/test_main.cpp +++ b/test/test_reference/test_main.cpp @@ -26,7 +26,7 @@ void testReference() { interfaces.insert(testinterface); for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - TRACE("Found interface: " + interface.toString()); + TRACEF("Found interface: %s", interface.toString().c_str()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -39,7 +39,7 @@ void testReference() { std::set, std::less> interfaces; interfaces.insert(testinterface); for (auto& interface : interfaces) { - TRACE("Found interface: " + interface.toString()); + TRACEF("Found interface: %s", interface.toString().c_str()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -53,7 +53,7 @@ void testReference() { interfaces.push_back(testinterface); for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - TRACE("Found interface: " + interface.toString()); + TRACEF("Found interface: %s", interface.toString().c_str()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -67,7 +67,7 @@ void testReference() { interfaces.push_back(testinterface); //for (auto& interface : interfaces) { for (RNS::Interface& interface : interfaces) { - TRACE("Found interface: " + interface.toString()); + TRACEF("Found interface: %s", interface.toString().c_str()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -81,14 +81,14 @@ void testReference() { interfaces.push_back(testinterface); for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - TRACE("1 Found interface: " + interface.toString()); + TRACEF("1 Found interface: %s", interface.toString().c_str()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } } for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) { RNS::Interface& interface = (*iter); - TRACE("2 Found interface: " + interface.toString()); + TRACEF("2 Found interface: %s", interface.toString().c_str()); RNS::Bytes data; const_cast(interface).on_outgoing(data); } @@ -101,13 +101,13 @@ void testReference() { destinations.insert({destination.hash(), destination}); //for (RNS::Destination& destination : destinations) { for (auto& [hash, destination] : destinations) { - TRACE("Iterated destination: " + destination.toString()); + TRACEF("Iterated destination: %s", destination.toString().c_str()); } RNS::Bytes hash = destination.hash(); auto iter = destinations.find(hash); if (iter != destinations.end()) { RNS::Destination& destination = (*iter).second; - TRACE("Found destination: " + destination.toString()); + TRACEF("Found destination: %s", destination.toString().c_str()); } return; } diff --git a/test/test_rns_loopback/test_main.cpp b/test/test_rns_loopback/test_main.cpp index dab42451..7bd2f984 100644 --- a/test/test_rns_loopback/test_main.cpp +++ b/test/test_rns_loopback/test_main.cpp @@ -36,7 +36,7 @@ class OutInterface : public RNS::InterfaceImpl { _name = "(deleted)"; } virtual void send_outgoing(const RNS::Bytes &data) { - HEAD("OutInterface.send_outgoing: data: " + data.toHex(), RNS::LOG_TRACE); + HEADF(RNS::LOG_TRACE, "OutInterface.send_outgoing: data: %s", data.toHex().c_str()); // Loop data back to InInterface for testing // NOTE: This sends the incoming data directory to RNS::Interface (which relays to Transport) @@ -57,13 +57,13 @@ class ExampleAnnounceHandler : public RNS::AnnounceHandler { virtual ~ExampleAnnounceHandler() {} virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex()); + INFOF("ExampleAnnounceHandler: destination hash: %s", destination_hash.toHex().c_str()); if (announced_identity) { - INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex()); - INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex()); + INFOF("ExampleAnnounceHandler: announced identity hash: %s", announced_identity.hash().toHex().c_str()); + INFOF("ExampleAnnounceHandler: announced identity app data: %s", announced_identity.app_data().toHex().c_str()); } if (app_data) { - INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\""); + INFOF("ExampleAnnounceHandler: app data text: \"%s\"", app_data.toString().c_str()); } INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -77,9 +77,9 @@ RNS::HAnnounceHandler announce_handler(new ExampleAnnounceHandler()); //void(*)(const Bytes& data, const Packet& packet) void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("onPacket: data: " + data.toHex()); - INFO("onPacket: text: \"" + data.toString() + "\""); - //TRACE("onPacket: " + packet.debugString()); + INFOF("onPacket: data: %s", data.toHex().c_str()); + INFOF("onPacket: text: \"%s\"", data.toString().c_str()); + //TRACEF("onPacket: %s", packet.debugString().c_str()); INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } @@ -87,9 +87,9 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) { //void(*)(const Bytes& data, const Packet& packet) void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) { INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - INFO("onPingPacket: data: " + data.toHex()); - INFO("onPingPacket: text: \"" + data.toString() + "\""); - //TRACE("onPingPacket: " + packet.debugString()); + INFOF("onPingPacket: data: %s", data.toHex().c_str()); + INFOF("onPingPacket: text: \"%s\"", data.toString().c_str()); + //TRACEF("onPingPacket: %s", packet.debugString().c_str()); INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } diff --git a/test/test_rns_persistence/test_main.cpp b/test/test_rns_persistence/test_main.cpp index f13722b9..e319e304 100644 --- a/test/test_rns_persistence/test_main.cpp +++ b/test/test_rns_persistence/test_main.cpp @@ -23,12 +23,12 @@ class TestInterface : public RNS::InterfaceImpl { private: virtual void send_outgoing(const RNS::Bytes& data) { - DEBUG("TestInterface.send_outgoing: data: " + data.toHex()); + DEBUGF("TestInterface.send_outgoing: data: %s", data.toHex().c_str()); // Perform post-send housekeeping InterfaceImpl::handle_outgoing(data); } void on_incoming(const RNS::Bytes& data) { - DEBUG("TestInterface.on_incoming: data: " + data.toHex()); + DEBUGF("TestInterface.on_incoming: data: %s", data.toHex().c_str()); // Pass received data on to transport InterfaceImpl::handle_incoming(data); } diff --git a/test/test_transport/test_main.cpp b/test/test_transport/test_main.cpp index 357fc5a5..2e4656ff 100644 --- a/test/test_transport/test_main.cpp +++ b/test/test_transport/test_main.cpp @@ -33,7 +33,7 @@ class InInterface : public RNS::InterfaceImpl { ERROR("handle_incoming: bad_alloc - out of memory"); } catch (const std::exception& e) { - ERROR(std::string("handle_incoming: exception: ") + e.what()); + ERRORF("handle_incoming: exception: %s", e.what()); } } }; @@ -55,7 +55,7 @@ class OutInterface : public RNS::InterfaceImpl { ERROR("handle_outgoing: bad_alloc - out of memory"); } catch (const std::exception& e) { - ERROR(std::string("handle_outgoing: exception: ") + e.what()); + ERRORF("handle_outgoing: exception: %s", e.what()); } } private: @@ -133,7 +133,7 @@ void initRNS() { ERROR("initRNS: bad_alloc - out of memory"); } catch (const std::exception& e) { - ERROR(std::string("initRNS: exception: ") + e.what()); + ERRORF("initRNS: exception: %s", e.what()); } } @@ -538,7 +538,7 @@ void test_incoming_announce_stress() { break; } catch (const std::exception& e) { - ERROR(std::string("test_incoming_announce_stress: exception: ") + e.what()); + ERRORF("test_incoming_announce_stress: exception: %s", e.what()); break; } RNS::Utilities::OS::sleep(0.1);