WIP: Switched to macros for build control of logs

This commit is contained in:
Chad Attermann committed 2024-07-01 20:25:46 -06:00
1 parent cc25dbab8f
commit 518db13ec8
36 files changed
+719 -718

No files matched your search

+6 -6
View File
@@ -58,7 +58,7 @@ bool LoRaInterface::start() {
LoRa.setTxPower(power);
info("LoRa init succeeded.");
extreme("LoRa bandwidth is " + std::to_string(Utilities::OS::round(bitrate()/1000.0, 2)) + " Kbps");
TRACE("LoRa bandwidth is " + std::to_string(Utilities::OS::round(bitrate()/1000.0, 2)) + " Kbps");
#endif
online(true);
@@ -80,7 +80,7 @@ void LoRaInterface::loop() {
#ifdef ARDUINO
int available = LoRa.parsePacket();
if (available > 0) {
extreme("LoRaInterface: receiving bytes...");
TRACE("LoRaInterface: receiving bytes...");
// read header (for detecting split packets)
uint8_t header = LoRa.read();
@@ -103,15 +103,15 @@ void LoRaInterface::loop() {
}
/*virtual*/ void LoRaInterface::on_incoming(const Bytes& data) {
debug(toString() + ".on_incoming: data: " + data.toHex());
DEBUG(toString() + ".on_incoming: data: " + data.toHex());
Interface::on_incoming(data);
}
/*virtual*/ void LoRaInterface::on_outgoing(const Bytes& data) {
debug(toString() + ".on_outgoing: data: " + data.toHex());
DEBUG(toString() + ".on_outgoing: data: " + data.toHex());
try {
if (online()) {
extreme("LoRaInterface: sending " + std::to_string(data.size()) + " bytes...");
TRACE("LoRaInterface: sending " + std::to_string(data.size()) + " bytes...");
// Send packet
#ifdef ARDUINO
@@ -132,7 +132,7 @@ void LoRaInterface::loop() {
LoRa.endPacket(); // finish packet and send it
#endif
extreme("LoRaInterface: sent bytes");
TRACE("LoRaInterface: sent bytes");
}
Interface::on_outgoing(data);
}
+5 -5
View File
@@ -71,7 +71,7 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
RNS::info("onPacket: data: " + data.toHex());
RNS::info("onPacket: text: \"" + data.toString() + "\"");
//RNS::extreme("onPacket: " + packet.debugString());
//TRACE("onPacket: " + packet.debugString());
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -80,7 +80,7 @@ void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
RNS::info("onPingPacket: data: " + data.toHex());
RNS::info("onPingPacket: text: \"" + data.toString() + "\"");
//RNS::extreme("onPingPacket: " + packet.debugString());
//TRACE("onPingPacket: " + packet.debugString());
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -191,14 +191,14 @@ void reticulum_setup() {
RNS::head("Sending send packet...", RNS::LOG_EXTREME);
send_packet.pack();
#ifndef NDEBUG
RNS::extreme("Test send_packet: " + send_packet.debugString());
TRACE("Test send_packet: " + send_packet.debugString());
#endif
RNS::head("Creating recv packet...", RNS::LOG_EXTREME);
RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw());
recv_packet.unpack();
#ifndef NDEBUG
RNS::extreme("Test recv_packet: " + recv_packet.debugString());
TRACE("Test recv_packet: " + recv_packet.debugString());
#endif
RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME);
@@ -257,7 +257,7 @@ void setup() {
RNS::error("SPIFFS filesystem mount failed");
}
else {
RNS::debug("SPIFFS filesystem is ready");
DEBUG("SPIFFS filesystem is ready");
}
#endif
+7 -7
View File
@@ -83,7 +83,7 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
RNS::info("onPacket: data: " + data.toHex());
RNS::info("onPacket: text: \"" + data.toString() + "\"");
//RNS::extreme("onPacket: " + packet.debugString());
//TRACE("onPacket: " + packet.debugString());
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -92,7 +92,7 @@ void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
RNS::info("onPingPacket: data: " + data.toHex());
RNS::info("onPingPacket: text: \"" + data.toString() + "\"");
//RNS::extreme("onPingPacket: " + packet.debugString());
//TRACE("onPingPacket: " + packet.debugString());
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -122,7 +122,7 @@ void run_tests() {
try {
RNS::extreme("Running tests...");
TRACE("Running tests...");
RNS::LogLevel loglevel = RNS::loglevel();
//RNS::loglevel(RNS::LOG_WARNING);
RNS::loglevel(RNS::LOG_EXTREME);
@@ -131,7 +131,7 @@ void run_tests() {
//testCrypto();
testPersistence();
RNS::loglevel(loglevel);
RNS::extreme("Finished running tests");
TRACE("Finished running tests");
//return;
}
catch (std::exception& e) {
@@ -258,14 +258,14 @@ void reticulum_setup() {
RNS::head("Sending send packet...", RNS::LOG_EXTREME);
send_packet.pack();
#ifndef NDEBUG
RNS::extreme("Test send_packet: " + send_packet.debugString());
TRACE("Test send_packet: " + send_packet.debugString());
#endif
RNS::head("Creating recv packet...", RNS::LOG_EXTREME);
RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw());
recv_packet.unpack();
#ifndef NDEBUG
RNS::extreme("Test recv_packet: " + recv_packet.debugString());
TRACE("Test recv_packet: " + recv_packet.debugString());
#endif
RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME);
@@ -333,7 +333,7 @@ void setup() {
RNS::error("SPIFFS filesystem mount failed");
}
else {
RNS::debug("SPIFFS filesystem is ready");
DEBUG("SPIFFS filesystem is ready");
}
#endif
+40 -40
View File
@@ -16,7 +16,7 @@ RNS::Bytes ref("Test");
const RNS::Bytes& testBytesReference() {
// NOTE: Can NOT return local instance as reference!!!
//RNS::Bytes ref("Test");
RNS::extreme("returning...");
TRACE("returning...");
return ref;
}
@@ -51,18 +51,18 @@ void testBytesMain() {
assert(prebuf != postbuf);
if (prebuf == postbuf) {
RNS::extreme("bytess are the same");
TRACE("bytess are the same");
}
else {
RNS::extreme("bytess are different");
TRACE("bytess are different");
}
bytes += prebuf + postbuf;
assert(bytes.size() == 11);
assert(memcmp(bytes.data(), "Hello World", bytes.size()) == 0);
RNS::extreme("assign bytes: " + bytes.toString());
RNS::extreme("assign prebuf: " + prebuf.toString());
RNS::extreme("assign postbuf: " + postbuf.toString());
TRACE("assign bytes: " + bytes.toString());
TRACE("assign prebuf: " + prebuf.toString());
TRACE("assign postbuf: " + postbuf.toString());
// test string assignment
bytes = "Foo";
@@ -84,56 +84,56 @@ void testBytesMain() {
// test left in range
{
RNS::Bytes left(bytes.left(5));
RNS::extreme("left: " + left.toString());
TRACE("left: " + left.toString());
assert(left.size() == 5);
assert(memcmp(left.data(), "Hello", left.size()) == 0);
}
// test left oob
{
RNS::Bytes left(bytes.left(20));
RNS::extreme("oob left: " + left.toString());
TRACE("oob left: " + left.toString());
assert(left.size() == 11);
assert(memcmp(left.data(), "Hello World", left.size()) == 0);
}
// test right in range
{
RNS::Bytes right(bytes.right(5));
RNS::extreme("right: " + right.toString());
TRACE("right: " + right.toString());
assert(right.size() == 5);
assert(memcmp(right.data(), "World", right.size()) == 0);
}
// test right oob
{
RNS::Bytes right(bytes.right(20));
RNS::extreme("oob right: " + right.toString());
TRACE("oob right: " + right.toString());
assert(right.size() == 11);
assert(memcmp(right.data(), "Hello World", right.size()) == 0);
}
// test mid in range
{
RNS::Bytes mid(bytes.mid(3, 5));
RNS::extreme("mid: " + mid.toString());
TRACE("mid: " + mid.toString());
assert(mid.size() == 5);
assert(memcmp(mid.data(), "lo Wo", mid.size()) == 0);
}
// test mid oob pos
{
RNS::Bytes mid(bytes.mid(20, 5));
RNS::extreme("oob pos mid: " + mid.toString());
TRACE("oob pos mid: " + mid.toString());
assert(!mid);
assert(mid.size() == 0);
}
// test mid oob pos
{
RNS::Bytes mid(bytes.mid(3, 20));
RNS::extreme("oob len mid: " + mid.toString());
TRACE("oob len mid: " + mid.toString());
assert(mid.size() == 8);
assert(memcmp(mid.data(), "lo World", mid.size()) == 0);
}
// test mid to end variant
{
RNS::Bytes mid(bytes.mid(3));
RNS::extreme("end mid: " + mid.toString());
TRACE("end mid: " + mid.toString());
assert(mid.size() == 8);
assert(memcmp(mid.data(), "lo World", mid.size()) == 0);
}
@@ -142,7 +142,7 @@ void testBytesMain() {
{
RNS::Bytes shrink(bytes);
shrink.resize(5);
RNS::extreme("shrink: " + shrink.toString());
TRACE("shrink: " + shrink.toString());
assert(shrink.size() == 5);
assert(memcmp(shrink.data(), "Hello", shrink.size()) == 0);
}
@@ -151,9 +151,9 @@ void testBytesMain() {
{
RNS::Bytes strmbuf;
strmbuf << prebuf << postbuf;
RNS::extreme("stream prebuf: " + prebuf.toString());
RNS::extreme("stream postbuf: " + postbuf.toString());
RNS::extreme("stream strmbuf: " + strmbuf.toString());
TRACE("stream prebuf: " + prebuf.toString());
TRACE("stream postbuf: " + postbuf.toString());
TRACE("stream strmbuf: " + strmbuf.toString());
assert(strmbuf.size() == 11);
assert(memcmp(strmbuf.data(), "Hello World", strmbuf.size()) == 0);
assert(prebuf.size() == 5);
@@ -170,9 +170,9 @@ void testBytesMain() {
assert(memcmp(strmbuf.data(), "Stream ", strmbuf.size()) == 0);
strmbuf << prebuf << postbuf;
RNS::extreme("stream prebuf: " + prebuf.toString());
RNS::extreme("stream postbuf: " + postbuf.toString());
RNS::extreme("stream strmbuf: " + strmbuf.toString());
TRACE("stream prebuf: " + prebuf.toString());
TRACE("stream postbuf: " + postbuf.toString());
TRACE("stream strmbuf: " + strmbuf.toString());
assert(strmbuf.size() == 18);
assert(memcmp(strmbuf.data(), "Stream Hello World", strmbuf.size()) == 0);
assert(prebuf.size() == 5);
@@ -190,9 +190,9 @@ void testBytesMain() {
const RNS::Bytes post(" World");
assert(post.size() == 6);
RNS::Bytes strmbuf = pre << post;
RNS::extreme("stream pre: " + prebuf.toString());
RNS::extreme("stream post: " + postbuf.toString());
RNS::extreme("stream strmbuf: " + strmbuf.toString());
TRACE("stream pre: " + prebuf.toString());
TRACE("stream post: " + postbuf.toString());
TRACE("stream strmbuf: " + strmbuf.toString());
assert(strmbuf.size() == 11);
assert(memcmp(strmbuf.data(), "Hello World", strmbuf.size()) == 0);
assert(pre.size() == 11);
@@ -234,14 +234,14 @@ void testBytesMain() {
}
// function default argument
RNS::extreme("TestBytes: function default argument");
TRACE("TestBytes: function default argument");
testBytesDefault();
// function reference return
RNS::extreme("TestBytes: function reference return");
TRACE("TestBytes: function reference return");
{
RNS::Bytes test = testBytesReference();
RNS::extreme("returned");
TRACE("returned");
assert(test);
assert(test.size() == 4);
assert(memcmp(test.data(), "Test", test.size()) == 0);
@@ -267,9 +267,9 @@ void testCowBytes() {
assert(memcmp(bytes3.data(), "1", bytes3.size()) == 0);
assert(bytes3.data() == bytes2.data());
RNS::extreme("pre bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString());
RNS::extreme("pre bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString());
RNS::extreme("pre bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString());
TRACE("pre bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString());
TRACE("pre bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString());
TRACE("pre bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString());
//bytes1.append("mississippi");
//assert(bytes1.size() == 12);
@@ -286,9 +286,9 @@ void testCowBytes() {
assert(memcmp(bytes3.data(), "mississippi", bytes3.size()) == 0);
assert(bytes3.data() != bytes2.data());
RNS::extreme("post bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString());
RNS::extreme("post bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString());
RNS::extreme("post bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString());
TRACE("post bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString());
TRACE("post bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString());
TRACE("post bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString());
}
void testBytesConversion() {
@@ -296,14 +296,14 @@ void testBytesConversion() {
{
RNS::Bytes bytes("Hello World");
std::string hex = bytes.toHex(true);
RNS::extreme("text: \"" + bytes.toString() + "\" upper hex: \"" + hex + "\"");
TRACE("text: \"" + bytes.toString() + "\" upper hex: \"" + hex + "\"");
assert(hex.length() == 22);
assert(hex.compare("48656C6C6F20576F726C64") == 0);
}
{
RNS::Bytes bytes("Hello World");
std::string hex = bytes.toHex(false);
RNS::extreme("text: \"" + bytes.toString() + "\" lower hex: \"" + hex + "\"");
TRACE("text: \"" + bytes.toString() + "\" lower hex: \"" + hex + "\"");
assert(hex.length() == 22);
assert(hex.compare("48656c6c6f20576f726c64") == 0);
}
@@ -312,7 +312,7 @@ void testBytesConversion() {
RNS::Bytes bytes;
bytes.assignHex(hex.c_str());
std::string text = bytes.toString();
RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\"");
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
assert(text.length() == 11);
assert(text.compare("Hello World") == 0);
}
@@ -321,19 +321,19 @@ void testBytesConversion() {
RNS::Bytes bytes;
bytes.assignHex(hex.c_str());
std::string text = bytes.toString();
RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\"");
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
assert(text.length() == 11);
assert(text.compare("Hello World") == 0);
bytes.assignHex(hex.c_str());
text = bytes.toString();
RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\"");
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
assert(text.length() == 11);
assert(text.compare("Hello World") == 0);
bytes.appendHex(hex.c_str());
text = bytes.toString();
RNS::extreme("hex: \"" + hex + "\" text: \"" + text + "\"");
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
assert(text.length() == 22);
assert(text.compare("Hello WorldHello World") == 0);
}
@@ -341,7 +341,7 @@ void testBytesConversion() {
}
void testBytesResize() {
RNS::extreme("Testing downsize of Bytes with initial capacity");
TRACE("Testing downsize of Bytes with initial capacity");
RNS::Bytes bytes(1024);
assert(!bytes);
+8 -8
View File
@@ -29,14 +29,14 @@ void testBytesMap()
assert(preit != map.end());
assert((*preit).second.compare("hello") == 0);
if (preit != map.end()) {
RNS::extreme(std::string("found prebuf: ") + (*preit).second);
TRACE(std::string("found prebuf: ") + (*preit).second);
}
auto postit = map.find(postbuf);
assert(postit != map.end());
assert((*postit).second.compare("world") == 0);
if (postit != map.end()) {
RNS::extreme(std::string("found postbuf: ") + (*postit).second);
TRACE(std::string("found postbuf: ") + (*postit).second);
}
const uint8_t newstr[] = "World";
@@ -47,7 +47,7 @@ void testBytesMap()
assert(newit != map.end());
assert((*newit).second.compare("world") == 0);
if (newit != map.end()) {
RNS::extreme(std::string("found newbuf: ") + (*newit).second);
TRACE(std::string("found newbuf: ") + (*newit).second);
}
std::string str = map["World"];
@@ -59,9 +59,9 @@ class Entry {
public:
// CBA for some reason default constructor is required for map index reference/asign to work
// ("error: no matching constructor for initialization of 'Entry'" results otherwise)
Entry() { RNS::extreme("Entry: default constructor"); }
Entry(const Entry& entry) : _hash(entry._hash) { RNS::extreme("Entry: copy constructor"); }
Entry(const char* hash) : _hash(hash) { RNS::extreme("Entry: hash constructor"); }
Entry() { TRACE("Entry: default constructor"); }
Entry(const Entry& entry) : _hash(entry._hash) { TRACE("Entry: copy constructor"); }
Entry(const char* hash) : _hash(hash) { TRACE("Entry: hash constructor"); }
RNS::Bytes _hash;
};
@@ -86,7 +86,7 @@ void testOldMap() {
}
}
for (auto& pair : entries) {
RNS::extreme("entries: " + pair.second._hash.toString());
TRACE("entries: " + pair.second._hash.toString());
}
assert(entries.size() == 2);
assert(other_entries.size() == 2);
@@ -114,7 +114,7 @@ void testNewMap() {
}
}
for (auto& [hash, entry] : entries) {
RNS::extreme("entries: " + entry._hash.toString());
TRACE("entries: " + entry._hash.toString());
}
assert(entries.size() == 2);
assert(other_entries.size() == 2);
+2 -2
View File
@@ -43,10 +43,10 @@ void testHMAC() {
RNS::Bytes key(keystr);
RNS::Bytes data(datastr);
RNS::Bytes hash(hasharr, sizeof(hasharr));
RNS::extreme("expected hash: " + hash.toHex());
TRACE("expected hash: " + hash.toHex());
RNS::Cryptography::HMAC hmac(key, data);
RNS::Bytes result = hmac.digest();
RNS::extreme("result hash: " + result.toHex());
TRACE("result hash: " + result.toHex());
assert(memcmp(hash.data(), result.data(), result.size()) == 0);
}
}
+7 -7
View File
@@ -46,7 +46,7 @@ void listDir(char * dir){
#endif
TestFilesystem::TestFilesystem() : Filesystem() {
extreme("TestFilesystem initializing...");
TRACE("TestFilesystem initializing...");
#ifdef ARDUINO
#ifdef ESP32
@@ -73,7 +73,7 @@ TestFilesystem::TestFilesystem() : Filesystem() {
else {
OS::remove_file("/test");
}
debug("SPIFFS filesystem is ready");
DEBUG("SPIFFS filesystem is ready");
#elif NRF52
// Initialize Internal File System
info("InternalFS mounting filesystem");
@@ -103,7 +103,7 @@ TestFilesystem::TestFilesystem() : Filesystem() {
FILE* file = fopen(file_path, "r");
if (file != nullptr) {
#endif
//extreme("file_exists: file exists, closing file");
//TRACE("file_exists: file exists, closing file");
#ifdef ARDUINO
#ifdef ESP32
file.close();
@@ -147,12 +147,12 @@ TestFilesystem::TestFilesystem() : Filesystem() {
//size_t read = fread(data.writable(size), size, 1, file);
size_t read = fread(data.writable(size), 1, size, file);
#endif
extreme("read_file: read " + std::to_string(read) + " Bytes from file " + std::string(file_path));
TRACE("read_file: read " + std::to_string(read) + " Bytes from file " + std::string(file_path));
if (read != size) {
error("read_file: failed to read file " + std::string(file_path));
data.clear();
}
//extreme("read_file: closing input file");
//TRACE("read_file: closing input file");
#ifdef ARDUINO
#ifdef ESP32
file.close();
@@ -189,11 +189,11 @@ TestFilesystem::TestFilesystem() : Filesystem() {
//size_t wrote = fwrite(data.data(), data.size(), 1, file);
size_t wrote = fwrite(data.data(), 1, data.size(), file);
#endif
extreme("write_file: wrote " + std::to_string(wrote) + " Bytes to file " + std::string(file_path));
TRACE("write_file: wrote " + std::to_string(wrote) + " Bytes to file " + std::string(file_path));
if (wrote < data.size()) {
warning("write_file: not all data was written to file " + std::string(file_path));
}
//extreme("write_file: closing output file");
//TRACE("write_file: closing output file");
#ifdef ARDUINO
#ifdef ESP32
file.close();
+2 -2
View File
@@ -22,12 +22,12 @@ void testTime()
double diff_time;
diff_time = (double)(end_ltime - start_ltime) / 1000.0;
RNS::extreme(std::string("ltime diff: ") + std::to_string(diff_time));
TRACE(std::string("ltime diff: ") + std::to_string(diff_time));
assert(diff_time > sleep_time * 0.99);
assert(diff_time < sleep_time * 1.01);
diff_time = end_dtime - start_dtime;
RNS::extreme(std::string("dtime diff: ") + std::to_string(diff_time));
TRACE(std::string("dtime diff: ") + std::to_string(diff_time));
assert(diff_time > sleep_time * 0.99);
assert(diff_time < sleep_time * 1.01);
+83 -83
View File
@@ -28,11 +28,11 @@ public:
private:
virtual void on_incoming(const RNS::Bytes& data) {
RNS::debug(toString() + ".on_incoming: data: " + data.toHex());
DEBUG(toString() + ".on_incoming: data: " + data.toHex());
Interface::on_incoming(data);
}
virtual void on_outgoing(const RNS::Bytes& data) {
RNS::debug(toString() + ".on_outgoing: data: " + data.toHex());
DEBUG(toString() + ".on_outgoing: data: " + data.toHex());
Interface::on_outgoing(data);
}
@@ -82,10 +82,10 @@ const char test_file_data[] = "test data";
void testWrite() {
RNS::Bytes data(test_file_data);
if (RNS::Utilities::OS::write_file(test_file_path, data) == data.size()) {
RNS::extreme("wrote: " + std::to_string(data.size()) + " bytes");
TRACE("wrote: " + std::to_string(data.size()) + " bytes");
}
else {
RNS::extreme("write failed");
TRACE("write failed");
assert(false);
}
}
@@ -93,14 +93,14 @@ void testWrite() {
void testRead() {
RNS::Bytes data;
if (RNS::Utilities::OS::read_file(test_file_path, data) > 0) {
RNS::extreme("read: " + std::to_string(data.size()) + " bytes");
RNS::extreme("data: " + data.toString());
TRACE("read: " + std::to_string(data.size()) + " bytes");
TRACE("data: " + data.toString());
assert(data.size() == strlen(test_file_data));
assert(memcmp(data.data(), test_file_data, strlen(test_file_data)) == 0);
//assert(RNS::Utilities::OS::remove_file(test_file_path));
}
else {
RNS::extreme("read failed");
TRACE("read failed");
assert(false);
}
}
@@ -127,18 +127,18 @@ void testSerializeObject() {
if (length < size) {
data.resize(length);
}
RNS::extreme("serialized " + std::to_string(length) + " bytes");
TRACE("serialized " + std::to_string(length) + " bytes");
if (length > 0) {
if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) {
RNS::extreme("wrote: " + std::to_string(data.size()) + " bytes");
TRACE("wrote: " + std::to_string(data.size()) + " bytes");
}
else {
RNS::extreme("write failed");
TRACE("write failed");
assert(false);
}
}
else {
RNS::extreme("failed to serialize");
TRACE("failed to serialize");
assert(false);
}
@@ -152,24 +152,24 @@ void testDeserializeObject() {
RNS::Bytes data;
if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) {
if (data) {
RNS::extreme("read: " + std::to_string(data.size()) + " bytes");
//RNS::extreme("data: " + data.toString());
TRACE("read: " + std::to_string(data.size()) + " bytes");
//TRACE("data: " + data.toString());
DeserializationError error = deserializeJson(doc, data.data());
//DeserializationError error = deserializeMsgPack(doc, data.data());
if (!error) {
JsonObject root = doc.as<JsonObject>();
for (JsonPair kv : root) {
RNS::extreme("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
}
}
else {
RNS::extreme("failed to deserialize");
TRACE("failed to deserialize");
assert(false);
}
//assert(RNS::Utilities::OS::remove_file(test_object_path));
}
else {
RNS::extreme("read failed");
TRACE("read failed");
assert(false);
}
@@ -179,7 +179,7 @@ void testSerializeObject() {
std::vector<std::string> vec({"one", "two"});
TestObject test("test", vec);
RNS::extreme("serializeObject: test: " + test.toString());
TRACE("serializeObject: test: " + test.toString());
StaticJsonDocument<1024> doc;
doc = test;
@@ -191,18 +191,18 @@ void testSerializeObject() {
if (length < size) {
data.resize(length);
}
RNS::extreme("serialized " + std::to_string(length) + " bytes");
TRACE("serialized " + std::to_string(length) + " bytes");
if (length > 0) {
if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) {
RNS::extreme("wrote: " + std::to_string(data.size()) + " bytes");
TRACE("wrote: " + std::to_string(data.size()) + " bytes");
}
else {
RNS::extreme("write failed");
TRACE("write failed");
assert(false);
}
}
else {
RNS::extreme("failed to serialize");
TRACE("failed to serialize");
assert(false);
}
@@ -215,26 +215,26 @@ void testDeserializeObject() {
RNS::Bytes data;
if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) {
RNS::extreme("read: " + std::to_string(data.size()) + " bytes");
//RNS::extreme("data: " + data.toString());
TRACE("read: " + std::to_string(data.size()) + " bytes");
//TRACE("data: " + data.toString());
DeserializationError error = deserializeJson(doc, data.data());
//DeserializationError error = deserializeMsgPack(doc, data.data());
if (!error) {
//JsonObject root = doc.as<JsonObject>();
//for (JsonPair kv : root) {
// RNS::extreme("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
// TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
//}
TestObject test = doc.as<TestObject>();
RNS::extreme("testDeserializeObject: test: " + test.toString());
TRACE("testDeserializeObject: test: " + test.toString());
}
else {
RNS::extreme("failed to deserialize");
TRACE("failed to deserialize");
assert(false);
}
//assert(RNS::Utilities::OS::remove_file(test_object_path));
}
else {
RNS::extreme("read failed");
TRACE("read failed");
assert(false);
}
@@ -289,18 +289,18 @@ void testSerializeVector() {
if (length < size) {
data.resize(length);
}
RNS::extreme("testSerializeVector: serialized " + std::to_string(length) + " bytes");
TRACE("testSerializeVector: serialized " + std::to_string(length) + " bytes");
if (length > 0) {
if (RNS::Utilities::OS::write_file(test_vector_path, data) == data.size()) {
RNS::extreme("testSerializeVector: wrote: " + std::to_string(data.size()) + " bytes");
TRACE("testSerializeVector: wrote: " + std::to_string(data.size()) + " bytes");
}
else {
RNS::extreme("testSerializeVector: write failed");
TRACE("testSerializeVector: write failed");
assert(false);
}
}
else {
RNS::extreme("testSerializeVector: failed to serialize");
TRACE("testSerializeVector: failed to serialize");
assert(false);
}
@@ -319,31 +319,31 @@ void testDeserializeVector() {
RNS::Bytes data;
if (RNS::Utilities::OS::read_file(test_vector_path, data) > 0) {
RNS::extreme("testDeserializeVector: read: " + std::to_string(data.size()) + " bytes");
//RNS::extreme("testDeserializeVector: data: " + data.toString());
TRACE("testDeserializeVector: read: " + std::to_string(data.size()) + " bytes");
//TRACE("testDeserializeVector: data: " + data.toString());
DeserializationError error = deserializeJson(doc, data.data());
//DeserializationError error = deserializeMsgPack(doc, data.data());
if (!error) {
RNS::extreme("testDeserializeVector: successfully deserialized");
TRACE("testDeserializeVector: successfully deserialized");
std::vector<TestObject> vector = doc.as<std::vector<TestObject>>();
for (auto& test : vector) {
RNS::extreme("testDeserializeVector: entry: " + test.toString());
TRACE("testDeserializeVector: entry: " + test.toString());
}
//JsonArray arr = doc.as<JsonArray>();
//for (JsonVariant elem : arr) {
// RNS::extreme("testDeserializeVector: entry: " + elem.as<TestObject>().toString());
// TRACE("testDeserializeVector: entry: " + elem.as<TestObject>().toString());
//}
}
else {
RNS::extreme("testDeserializeVector: failed to deserialize");
TRACE("testDeserializeVector: failed to deserialize");
assert(false);
}
//assert(RNS::Utilities::OS::remove_file(test_vector_path));
}
else {
RNS::extreme("testDeserializeVector: read failed");
TRACE("testDeserializeVector: read failed");
assert(false);
}
@@ -386,18 +386,18 @@ void testSerializeSet() {
if (length < size) {
data.resize(length);
}
RNS::extreme("testSerializeSet: serialized " + std::to_string(length) + " bytes");
TRACE("testSerializeSet: serialized " + std::to_string(length) + " bytes");
if (length > 0) {
if (RNS::Utilities::OS::write_file(test_set_path, data) == data.size()) {
RNS::extreme("testSerializeSet: wrote: " + std::to_string(data.size()) + " bytes");
TRACE("testSerializeSet: wrote: " + std::to_string(data.size()) + " bytes");
}
else {
RNS::extreme("testSerializeSet: write failed");
TRACE("testSerializeSet: write failed");
assert(false);
}
}
else {
RNS::extreme("testSerializeSet: failed to serialize");
TRACE("testSerializeSet: failed to serialize");
assert(false);
}
@@ -416,31 +416,31 @@ void testDeserializeSet() {
RNS::Bytes data;
if (RNS::Utilities::OS::read_file(test_set_path, data) > 0) {
RNS::extreme("testDeserializeSet: read: " + std::to_string(data.size()) + " bytes");
//RNS::extreme("testDeserializeSet: data: " + data.toString());
TRACE("testDeserializeSet: read: " + std::to_string(data.size()) + " bytes");
//TRACE("testDeserializeSet: data: " + data.toString());
DeserializationError error = deserializeJson(doc, data.data());
//DeserializationError error = deserializeMsgPack(doc, data.data());
if (!error) {
RNS::extreme("testDeserializeSet: successfully deserialized");
TRACE("testDeserializeSet: successfully deserialized");
std::set<TestObject> set = doc.as<std::set<TestObject>>();
for (auto& test : set) {
RNS::extreme("testDeserializeSet: entry: " + test.toString());
TRACE("testDeserializeSet: entry: " + test.toString());
}
//JsonArray arr = doc.as<JsonArray>();
//for (JsonVariant elem : arr) {
// RNS::extreme("testDeserializeSet: entry: " + elem.as<TestObject>().toString());
// TRACE("testDeserializeSet: entry: " + elem.as<TestObject>().toString());
//}
}
else {
RNS::extreme("testDeserializeSet: failed to deserialize");
TRACE("testDeserializeSet: failed to deserialize");
assert(false);
}
//assert(RNS::Utilities::OS::remove_file(test_set_path));
}
else {
RNS::extreme("testDeserializeSet: read failed");
TRACE("testDeserializeSet: read failed");
assert(false);
}
@@ -475,18 +475,18 @@ void testSerializeMap() {
if (length < size) {
data.resize(length);
}
RNS::extreme("testSerializeMap: serialized " + std::to_string(length) + " bytes");
TRACE("testSerializeMap: serialized " + std::to_string(length) + " bytes");
if (length > 0) {
if (RNS::Utilities::OS::write_file(test_map_path, data) == data.size()) {
RNS::extreme("testSerializeMap: wrote: " + std::to_string(data.size()) + " bytes");
TRACE("testSerializeMap: wrote: " + std::to_string(data.size()) + " bytes");
}
else {
RNS::extreme("testSerializeMap: write failed");
TRACE("testSerializeMap: write failed");
assert(false);
}
}
else {
RNS::extreme("testSerializeMap: failed to serialize");
TRACE("testSerializeMap: failed to serialize");
assert(false);
}
@@ -505,31 +505,31 @@ void testDeserializeMap() {
RNS::Bytes data;
if (RNS::Utilities::OS::read_file(test_map_path, data) > 0) {
RNS::extreme("testDeserializeMap: read: " + std::to_string(data.size()) + " bytes");
//RNS::extreme("testDeserializeMap: data: " + data.toString());
TRACE("testDeserializeMap: read: " + std::to_string(data.size()) + " bytes");
//TRACE("testDeserializeMap: data: " + data.toString());
DeserializationError error = deserializeJson(doc, data.data());
//DeserializationError error = deserializeMsgPack(doc, data.data());
if (!error) {
RNS::extreme("testDeserializeMap: successfully deserialized");
TRACE("testDeserializeMap: successfully deserialized");
std::map<std::string, TestObject> map(doc.as<std::map<std::string, TestObject>>());
for (auto& [str, test] : map) {
RNS::extreme("testDeserializeMap: entry: " + str + " = " + test.toString());
TRACE("testDeserializeMap: entry: " + str + " = " + test.toString());
}
//JsonObject root = doc.as<JsonObject>();
//for (JsonPair kv : root) {
// RNS::extreme("testDeserializeMap: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as<TestObject>().toString());
// TRACE("testDeserializeMap: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as<TestObject>().toString());
//}
}
else {
RNS::extreme("testDeserializeMap: failed to deserialize");
TRACE("testDeserializeMap: failed to deserialize");
assert(false);
}
//assert(RNS::Utilities::OS::remove_file(test_map_path));
}
else {
RNS::extreme("testDeserializeMap: read failed");
TRACE("testDeserializeMap: read failed");
assert(false);
}
@@ -586,13 +586,13 @@ void testSerializeDestinationTable() {
}
for (auto& [hash, test] : map) {
RNS::extreme("testSerializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString());
TRACE("testSerializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString());
}
//StaticJsonDocument<1024> doc;
//doc = map;
RNS::extreme("testSerializeDestinationTable: JSON_OBJECT_SIZE " + std::to_string(JSON_OBJECT_SIZE(1)) + " bytes");
RNS::extreme("testSerializeDestinationTable: JSON_ARRAY_SIZE " + std::to_string(JSON_ARRAY_SIZE(1)) + " bytes");
TRACE("testSerializeDestinationTable: JSON_OBJECT_SIZE " + std::to_string(JSON_OBJECT_SIZE(1)) + " bytes");
TRACE("testSerializeDestinationTable: JSON_ARRAY_SIZE " + std::to_string(JSON_ARRAY_SIZE(1)) + " bytes");
int calcsize = 0;
for (auto& [destination_hash, destination_entry] : map) {
// entry
@@ -604,39 +604,39 @@ void testSerializeDestinationTable() {
// blobs
calcsize += JSON_ARRAY_SIZE(destination_entry._random_blobs.size());
}
RNS::extreme("testSerializeDestinationTable: calcsize " + std::to_string(calcsize) + " bytes");
TRACE("testSerializeDestinationTable: calcsize " + std::to_string(calcsize) + " bytes");
const int BUFFER_SIZE = (JSON_OBJECT_SIZE(9) + JSON_ARRAY_SIZE(2)) * map.size() + JSON_ARRAY_SIZE(map.size());
RNS::extreme("testSerializeDestinationTable: BUFFER_SIZE " + std::to_string(BUFFER_SIZE) + " bytes");
TRACE("testSerializeDestinationTable: BUFFER_SIZE " + std::to_string(BUFFER_SIZE) + " bytes");
//DynamicJsonDocument doc(32768);
//DynamicJsonDocument doc(BUFFER_SIZE);
DynamicJsonDocument doc(calcsize);
doc.set(map);
RNS::extreme("testSerializeDestinationTable: doc size " + std::to_string(doc.size()));
RNS::extreme("testSerializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage()));
TRACE("testSerializeDestinationTable: doc size " + std::to_string(doc.size()));
TRACE("testSerializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage()));
RNS::Bytes data;
// /size_t size = 1024;
//size_t size = calcsize;
size_t size = doc.memoryUsage();
RNS::extreme("testSerializeDestinationTable: buffer size " + std::to_string(size) + " bytes");
TRACE("testSerializeDestinationTable: buffer size " + std::to_string(size) + " bytes");
size_t length = serializeJson(doc, data.writable(size), size);
//size_t length = serializeMsgPack(doc, data.writable(size), size);
if (length < size) {
data.resize(length);
}
RNS::extreme("testSerializeDestinationTable: serialized " + std::to_string(length) + " bytes");
TRACE("testSerializeDestinationTable: serialized " + std::to_string(length) + " bytes");
if (length > 0) {
RNS::extreme("json: " + data.toString());
TRACE("json: " + data.toString());
if (RNS::Utilities::OS::write_file(test_destination_table_path, data) == data.size()) {
RNS::extreme("testSerializeDestinationTable: wrote: " + std::to_string(data.size()) + " bytes");
TRACE("testSerializeDestinationTable: wrote: " + std::to_string(data.size()) + " bytes");
}
else {
RNS::extreme("testSerializeDestinationTable: write failed");
TRACE("testSerializeDestinationTable: write failed");
assert(false);
}
}
else {
RNS::extreme("testSerializeDestinationTable: failed to serialize");
TRACE("testSerializeDestinationTable: failed to serialize");
assert(false);
}
@@ -651,34 +651,34 @@ void testDeserializeDestinationTable() {
int calcsize = data.size() * 1.5;
DynamicJsonDocument doc(calcsize);
RNS::extreme("testDeserializeDestinationTable: read: " + std::to_string(data.size()) + " bytes");
//RNS::extreme("testDeserializeVector: data: " + data.toString());
TRACE("testDeserializeDestinationTable: read: " + std::to_string(data.size()) + " bytes");
//TRACE("testDeserializeVector: data: " + data.toString());
DeserializationError error = deserializeJson(doc, data.data());
//DeserializationError error = deserializeMsgPack(doc, data.data());
RNS::extreme("testDeserializeDestinationTable: doc size " + std::to_string(doc.size()));
RNS::extreme("testDeserializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage()));
TRACE("testDeserializeDestinationTable: doc size " + std::to_string(doc.size()));
TRACE("testDeserializeDestinationTable: doc memory " + std::to_string(doc.memoryUsage()));
if (!error) {
RNS::extreme("testDeserializeDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes");
RNS::extreme("json: " + data.toString());
TRACE("testDeserializeDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes");
TRACE("json: " + data.toString());
static std::map<RNS::Bytes, RNS::Transport::DestinationEntry> map(doc.as<std::map<RNS::Bytes, RNS::Transport::DestinationEntry>>());
for (auto& [hash, test] : map) {
RNS::extreme("testDeserializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString());
TRACE("testDeserializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString());
}
//JsonObject root = doc.as<JsonObject>();
//for (JsonPair kv : root) {
// RNS::extreme("testDeserializeDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as<TestObject>().toString());
// TRACE("testDeserializeDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as<TestObject>().toString());
//}
}
else {
RNS::extreme("testDeserializeDestinationTable: failed to deserialize");
TRACE("testDeserializeDestinationTable: failed to deserialize");
assert(false);
}
//assert(RNS::Utilities::OS::remove_file(test_destination_table_path));
}
else {
RNS::extreme("testDeserializeDestinationTable: read failed");
TRACE("testDeserializeDestinationTable: read failed");
assert(false);
}
+8 -8
View File
@@ -28,7 +28,7 @@ void testReference() {
interfaces.insert(testinterface);
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface& interface = (*iter);
RNS::extreme("Found interface: " + interface.toString());
TRACE("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).on_outgoing(data);
}
@@ -41,7 +41,7 @@ void testReference() {
std::set<std::reference_wrapper<RNS::Interface>, std::less<RNS::Interface>> interfaces;
interfaces.insert(testinterface);
for (auto& interface : interfaces) {
RNS::extreme("Found interface: " + interface.toString());
TRACE("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).on_outgoing(data);
}
@@ -55,7 +55,7 @@ void testReference() {
interfaces.push_back(testinterface);
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface& interface = (*iter);
RNS::extreme("Found interface: " + interface.toString());
TRACE("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).on_outgoing(data);
}
@@ -69,7 +69,7 @@ void testReference() {
interfaces.push_back(testinterface);
//for (auto& interface : interfaces) {
for (RNS::Interface& interface : interfaces) {
RNS::extreme("Found interface: " + interface.toString());
TRACE("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).on_outgoing(data);
}
@@ -83,14 +83,14 @@ void testReference() {
interfaces.push_back(testinterface);
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface& interface = (*iter);
RNS::extreme("1 Found interface: " + interface.toString());
TRACE("1 Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).on_outgoing(data);
}
}
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface& interface = (*iter);
RNS::extreme("2 Found interface: " + interface.toString());
TRACE("2 Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).on_outgoing(data);
}
@@ -103,13 +103,13 @@ void testReference() {
destinations.insert({destination.hash(), destination});
//for (RNS::Destination& destination : destinations) {
for (auto& [hash, destination] : destinations) {
RNS::extreme("Iterated destination: " + destination.toString());
TRACE("Iterated destination: " + destination.toString());
}
RNS::Bytes hash = destination.hash();
auto iter = destinations.find(hash);
if (iter != destinations.end()) {
RNS::Destination& destination = (*iter).second;
RNS::extreme("Found destination: " + destination.toString());
TRACE("Found destination: " + destination.toString());
}
return;
}
+2 -2
View File
@@ -41,7 +41,7 @@ void setup() {
try {
RNS::extreme("Running tests...");
TRACE("Running tests...");
RNS::LogLevel loglevel = RNS::loglevel();
//RNS::loglevel(RNS::LOG_WARNING);
RNS::loglevel(RNS::LOG_EXTREME);
@@ -56,7 +56,7 @@ void setup() {
testBytes();
RNS::loglevel(loglevel);
RNS::extreme("Finished running tests");
TRACE("Finished running tests");
//return;
}
catch (std::exception& e) {
+11 -11
View File
@@ -57,12 +57,12 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p
}
_local_port = port;
_remote_port = port;
extreme("UDPInterface: wifi ssid: " + _wifi_ssid);
extreme("UDPInterface: wifi password: " + _wifi_password);
extreme("UDPInterface: local host: " + _local_host);
extreme("UDPInterface: local port: " + std::to_string(_local_port));
extreme("UDPInterface: remote host: " + _remote_host);
extreme("UDPInterface: remote port: " + std::to_string(_remote_port));
TRACE("UDPInterface: wifi ssid: " + _wifi_ssid);
TRACE("UDPInterface: wifi password: " + _wifi_password);
TRACE("UDPInterface: local host: " + _local_host);
TRACE("UDPInterface: local port: " + std::to_string(_local_port));
TRACE("UDPInterface: remote host: " + _remote_host);
TRACE("UDPInterface: remote port: " + std::to_string(_remote_port));
#ifdef ARDUINO
// Connect to the WiFi network
@@ -149,7 +149,7 @@ bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int p
}
// open udp socket
extreme("Opening UDP socket");
TRACE("Opening UDP socket");
_socket = socket( PF_INET, SOCK_DGRAM, 0 );
if (_socket < 0) {
error("Unable to create socket with error " + std::to_string(errno));
@@ -219,12 +219,12 @@ void UDPInterface::loop() {
}
/*virtual*/ void UDPInterface::on_incoming(const Bytes& data) {
debug(toString() + ".on_incoming: data: " + data.toHex());
DEBUG(toString() + ".on_incoming: data: " + data.toHex());
Interface::on_incoming(data);
}
/*virtual*/ void UDPInterface::on_outgoing(const Bytes& data) {
debug(toString() + ".on_outgoing: data: " + data.toHex());
DEBUG(toString() + ".on_outgoing: data: " + data.toHex());
try {
if (online()) {
// Send packet
@@ -233,13 +233,13 @@ void UDPInterface::loop() {
udp.write(data.data(), data.size());
udp.endPacket();
#else
extreme("Sending UDP packet to " + std::string(_remote_host) + ":" + std::to_string(_remote_port));
TRACE("Sending UDP packet to " + std::string(_remote_host) + ":" + std::to_string(_remote_port));
sockaddr_in sock_addr;
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = _remote_address;
sock_addr.sin_port = htons(_remote_port);
int sent = sendto(_socket, data.data(), data.size(), 0, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
extreme("Sent " + std::to_string(sent) + " bytes to " + std::string(_remote_host) + ":" + std::to_string(_remote_port));
TRACE("Sent " + std::to_string(sent) + " bytes to " + std::string(_remote_host) + ":" + std::to_string(_remote_port));
#endif
}
+5 -5
View File
@@ -72,7 +72,7 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
RNS::info("onPacket: data: " + data.toHex());
RNS::info("onPacket: text: \"" + data.toString() + "\"");
//RNS::extreme("onPacket: " + packet.debugString());
//TRACE("onPacket: " + packet.debugString());
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -81,7 +81,7 @@ void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
RNS::info("onPingPacket: data: " + data.toHex());
RNS::info("onPingPacket: text: \"" + data.toString() + "\"");
//RNS::extreme("onPingPacket: " + packet.debugString());
//TRACE("onPingPacket: " + packet.debugString());
RNS::info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -192,14 +192,14 @@ void reticulum_setup() {
RNS::head("Sending send packet...", RNS::LOG_EXTREME);
send_packet.pack();
#ifndef NDEBUG
RNS::extreme("Test send_packet: " + send_packet.debugString());
TRACE("Test send_packet: " + send_packet.debugString());
#endif
RNS::head("Creating recv packet...", RNS::LOG_EXTREME);
RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw());
recv_packet.unpack();
#ifndef NDEBUG
RNS::extreme("Test recv_packet: " + recv_packet.debugString());
TRACE("Test recv_packet: " + recv_packet.debugString());
#endif
RNS::head("Spoofing recv packet to destination...", RNS::LOG_EXTREME);
@@ -258,7 +258,7 @@ void setup() {
RNS::error("SPIFFS filesystem mount failed");
}
else {
RNS::debug("SPIFFS filesystem is ready");
DEBUG("SPIFFS filesystem is ready");
}
#endif
+3 -3
View File
@@ -6,7 +6,7 @@ using namespace RNS;
// - If size is specified (>0) then create shared data with initial size
// - If size is not specified (<=0) then create empty shared data
void Bytes::newData(size_t size /*= 0*/) {
//mem("Bytes is creating its own data");
MEM("Bytes is creating its own data");
if (size > 0) {
// CBA Note that this method of construction creates vector with specified and initializes all eleemtnets with default values
Data* data = new Data(size);
@@ -39,7 +39,7 @@ void Bytes::exclusiveData(bool copy /*= true*/, size_t size /*= 0*/) {
else if (!_exclusive) {
Data *data;
if (copy && !_data->empty()) {
//extreme("Bytes is creating a writable copy of its shared data");
//TRACE("Bytes is creating a writable copy of its shared data");
data = new Data(*_data.get());
if (data == nullptr) {
error("Bytes failed to duplicate data buffer");
@@ -52,7 +52,7 @@ void Bytes::exclusiveData(bool copy /*= true*/, size_t size /*= 0*/) {
_exclusive = true;
}
else {
//extreme("Bytes is creating its own data because shared is empty");
//TRACE("Bytes is creating its own data because shared is empty");
//data = new Data();
//if (data == nullptr) {
// error("Bytes failed to allocate empty data buffer");
+10 -10
View File
@@ -31,35 +31,35 @@ namespace RNS {
public:
Bytes() {
//mem("Bytes object created from default, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM("Bytes object created from default, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
Bytes(const NoneConstructor none) {
//mem("Bytes object created from NONE, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM("Bytes object created from NONE, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
Bytes(const Bytes& bytes) {
//mem("Bytes is using shared data");
MEM("Bytes is using shared data");
assign(bytes);
//mem("Bytes object copy created from bytes \"" + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM("Bytes object copy created from bytes \"" + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
Bytes(const uint8_t* chunk, size_t size) {
assign(chunk, size);
//mem(std::string("Bytes object created from chunk \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM(std::string("Bytes object created from chunk \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
Bytes(const char* string) {
assign(string);
//mem(std::string("Bytes object created from string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM(std::string("Bytes object created from string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
Bytes(const std::string& string) {
assign(string);
//mem(std::string("Bytes object created from std::string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM(std::string("Bytes object created from std::string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
Bytes(size_t capacity) {
newData();
reserve(capacity);
//mem(std::string("Bytes object created with capacity ") + std::to_string(capacity) + ", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM(std::string("Bytes object created with capacity ") + std::to_string(capacity) + ", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
virtual ~Bytes() {
//mem(std::string("Bytes object destroyed \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
MEM(std::string("Bytes object destroyed \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
inline const Bytes& operator = (const Bytes& bytes) {
@@ -94,7 +94,7 @@ namespace RNS {
private:
inline SharedData shareData() const {
//mem("Bytes is sharing its own data");
MEM("Bytes is sharing its own data");
_exclusive = false;
return _data;
}
+17 -17
View File
@@ -26,11 +26,11 @@ Fernet::Fernet(const Bytes& key) {
//self._encryption_key = key[16:]
_encryption_key = key.mid(16);
mem("Fernet object created");
MEM("Fernet object created");
}
Fernet::~Fernet() {
mem("Fernet object destroyed");
MEM("Fernet object destroyed");
}
bool Fernet::verify_hmac(const Bytes& token) {
@@ -41,44 +41,44 @@ bool Fernet::verify_hmac(const Bytes& token) {
//received_hmac = token[-32:]
Bytes received_hmac = token.right(32);
debug("Fernet::verify_hmac: received_hmac: " + received_hmac.toHex());
DEBUG("Fernet::verify_hmac: received_hmac: " + received_hmac.toHex());
//expected_hmac = HMAC.new(self._signing_key, token[:-32]).digest()
Bytes expected_hmac = HMAC::generate(_signing_key, token.left(token.size()-32))->digest();
debug("Fernet::verify_hmac: expected_hmac: " + expected_hmac.toHex());
DEBUG("Fernet::verify_hmac: expected_hmac: " + expected_hmac.toHex());
return (received_hmac == expected_hmac);
}
const Bytes Fernet::encrypt(const Bytes& data) {
debug("Fernet::encrypt: plaintext length: " + std::to_string(data.size()));
DEBUG("Fernet::encrypt: plaintext length: " + std::to_string(data.size()));
Bytes iv = random(16);
//double current_time = OS::time();
extreme("Fernet::encrypt: iv: " + iv.toHex());
TRACE("Fernet::encrypt: iv: " + iv.toHex());
extreme("Fernet::encrypt: plaintext: " + data.toHex());
TRACE("Fernet::encrypt: plaintext: " + data.toHex());
Bytes ciphertext = AES_128_CBC::encrypt(
PKCS7::pad(data),
_encryption_key,
iv
);
debug("Fernet::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size()));
extreme("Fernet::encrypt: ciphertext: " + ciphertext.toHex());
DEBUG("Fernet::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size()));
TRACE("Fernet::encrypt: ciphertext: " + ciphertext.toHex());
Bytes signed_parts = iv + ciphertext;
//return signed_parts + HMAC::generate(_signing_key, signed_parts)->digest();
Bytes sig(HMAC::generate(_signing_key, signed_parts)->digest());
extreme("Fernet::encrypt: sig: " + sig.toHex());
TRACE("Fernet::encrypt: sig: " + sig.toHex());
Bytes token(signed_parts + sig);
debug("Fernet::encrypt: token length: " + std::to_string(token.size()));
DEBUG("Fernet::encrypt: token length: " + std::to_string(token.size()));
return token;
}
const Bytes Fernet::decrypt(const Bytes& token) {
debug("Fernet::decrypt: token length: " + std::to_string(token.size()));
DEBUG("Fernet::decrypt: token length: " + std::to_string(token.size()));
if (token.size() < 48) {
throw std::invalid_argument("Cannot decrypt token of only " + std::to_string(token.size()) + " bytes");
}
@@ -89,11 +89,11 @@ const Bytes Fernet::decrypt(const Bytes& token) {
//iv = token[:16]
Bytes iv = token.left(16);
extreme("Fernet::decrypt: iv: " + iv.toHex());
TRACE("Fernet::decrypt: iv: " + iv.toHex());
//ciphertext = token[16:-32]
Bytes ciphertext = token.mid(16, token.size()-48);
extreme("Fernet::decrypt: ciphertext: " + ciphertext.toHex());
TRACE("Fernet::decrypt: ciphertext: " + ciphertext.toHex());
try {
Bytes plaintext = PKCS7::unpad(
@@ -103,10 +103,10 @@ const Bytes Fernet::decrypt(const Bytes& token) {
iv
)
);
debug("Fernet::encrypt: unpadded plaintext length: " + std::to_string(plaintext.size()));
extreme("Fernet::decrypt: plaintext: " + plaintext.toHex());
DEBUG("Fernet::encrypt: unpadded plaintext length: " + std::to_string(plaintext.size()));
TRACE("Fernet::decrypt: plaintext: " + plaintext.toHex());
debug("Fernet::decrypt: plaintext length: " + std::to_string(plaintext.size()));
DEBUG("Fernet::decrypt: plaintext length: " + std::to_string(plaintext.size()));
return plaintext;
}
catch (std::exception& e) {
+3 -3
View File
@@ -15,13 +15,13 @@ calls in RNS end up here.
*/
const Bytes RNS::Cryptography::sha256(const Bytes& data) {
//extreme("Cryptography::sha256: data: " + data.toHex() );
//TRACE("Cryptography::sha256: data: " + data.toHex() );
SHA256 digest;
digest.reset();
digest.update(data.data(), data.size());
Bytes hash;
digest.finalize(hash.writable(32), 32);
//extreme("Cryptography::sha256: hash: " + hash.toHex() );
//TRACE("Cryptography::sha256: hash: " + hash.toHex() );
return hash;
}
@@ -31,6 +31,6 @@ const Bytes RNS::Cryptography::sha512(const Bytes& data) {
digest.update(data.data(), data.size());
Bytes hash;
digest.finalize(hash.writable(64), 64);
//extreme("Cryptography::sha512: hash: " + hash.toHex() );
//TRACE("Cryptography::sha512: hash: " + hash.toHex() );
return hash;
}
+6 -6
View File
@@ -28,9 +28,9 @@ namespace RNS { namespace Cryptography {
// updates passed buffer
static inline void inplace_pad(Bytes& data, size_t bs = BLOCKSIZE) {
size_t len = data.size();
//debug("PKCS7::pad: len: " + std::to_string(len));
//DEBUG("PKCS7::pad: len: " + std::to_string(len));
size_t padlen = bs - (len % bs);
//debug("PKCS7::pad: pad len: " + std::to_string(padlen));
//DEBUG("PKCS7::pad: pad len: " + std::to_string(padlen));
// create zero-filled byte padding array of size padlen
//p v = bytes([padlen])
//uint8_t pad[padlen] = {0};
@@ -41,24 +41,24 @@ namespace RNS { namespace Cryptography {
// concatenate data with padding
//p return data+v*padlen
data.append(pad, padlen);
//debug("PKCS7::pad: data size: " + std::to_string(data.size()));
//DEBUG("PKCS7::pad: data size: " + std::to_string(data.size()));
}
// updates passed buffer
static inline void inplace_unpad(Bytes& data, size_t bs = BLOCKSIZE) {
size_t len = data.size();
//debug("PKCS7::unpad: len: " + std::to_string(len));
//DEBUG("PKCS7::unpad: len: " + std::to_string(len));
// read last byte which is pad length
//pad = data[-1]
size_t padlen = (size_t)data.data()[data.size()-1];
//debug("PKCS7::unpad: pad len: " + std::to_string(padlen));
//DEBUG("PKCS7::unpad: pad len: " + std::to_string(padlen));
if (padlen > bs) {
throw std::runtime_error("Cannot unpad, invalid padding length of " + std::to_string(padlen) + " bytes");
}
// truncate data to strip padding
//return data[:len-padlen]
data.resize(len - padlen);
//debug("PKCS7::unpad: data size: " + std::to_string(data.size()));
//DEBUG("PKCS7::unpad: data size: " + std::to_string(data.size()));
}
};
+10 -10
View File
@@ -169,26 +169,26 @@ namespace RNS { namespace Cryptography {
}
*/
inline const Bytes exchange(const Bytes& peer_public_key) {
debug("X25519PublicKey::exchange: public key: " + _publicKey.toHex());
debug("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex());
debug("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex());
DEBUG("X25519PublicKey::exchange: public key: " + _publicKey.toHex());
DEBUG("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex());
DEBUG("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex());
Bytes sharedKey;
if (!Curve25519::eval(sharedKey.writable(32), _privateKey.data(), peer_public_key.data())) {
throw std::runtime_error("Peer key is invalid");
}
debug("X25519PublicKey::exchange: shared key: " + sharedKey.toHex());
debug("X25519PublicKey::exchange: post private key: " + _privateKey.toHex());
DEBUG("X25519PublicKey::exchange: shared key: " + sharedKey.toHex());
DEBUG("X25519PublicKey::exchange: post private key: " + _privateKey.toHex());
return sharedKey;
}
inline bool verify(const Bytes& peer_public_key) {
debug("X25519PublicKey::exchange: public key: " + _publicKey.toHex());
debug("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex());
debug("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex());
DEBUG("X25519PublicKey::exchange: public key: " + _publicKey.toHex());
DEBUG("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex());
DEBUG("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex());
Bytes sharedKey(peer_public_key);
bool success = Curve25519::dh2(sharedKey.writable(32), _privateKey.writable(32));
debug("X25519PublicKey::exchange: shared key: " + sharedKey.toHex());
debug("X25519PublicKey::exchange: post private key: " + _privateKey.toHex());
DEBUG("X25519PublicKey::exchange: shared key: " + sharedKey.toHex());
DEBUG("X25519PublicKey::exchange: post private key: " + _privateKey.toHex());
return success;
}
+49 -49
View File
@@ -15,52 +15,52 @@ using namespace RNS::Utilities;
Destination::Destination(const Identity& identity, const directions direction, const types type, const char* app_name, const char* aspects) : _object(new Object(identity)) {
assert(_object);
mem("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
// Check input values and build name string
if (strchr(app_name, '.') != nullptr) {
throw std::invalid_argument("Dots can't be used in app names");
}
//extreme("Destination::Destination: app name: " + std::string(app_name));
//TRACE("Destination::Destination: app name: " + std::string(app_name));
_object->_type = type;
_object->_direction = direction;
std::string fullaspects(aspects);
if (!identity && direction == IN && _object->_type != PLAIN) {
extreme("Destination::Destination: identity not provided, creating new one");
TRACE("Destination::Destination: identity not provided, creating new one");
_object->_identity = Identity();
// CBA TODO determine why identity.hexhash is added both here and by expand_name called below
fullaspects += "." + _object->_identity.hexhash();
}
//extreme("Destination::Destination: full aspects: " + fullaspects);
//TRACE("Destination::Destination: full aspects: " + fullaspects);
if (_object->_identity && _object->_type == PLAIN) {
throw std::invalid_argument("Selected destination type PLAIN cannot hold an identity");
}
_object->_name = expand_name(_object->_identity, app_name, fullaspects.c_str());
//extreme("Destination::Destination: name: " + _object->_name);
//TRACE("Destination::Destination: name: " + _object->_name);
// Generate the destination address hash
//extreme("Destination::Destination: creating hash...");
//TRACE("Destination::Destination: creating hash...");
_object->_hash = hash(_object->_identity, app_name, fullaspects.c_str());
_object->_hexhash = _object->_hash.toHex();
extreme("Destination::Destination: hash: " + _object->_hash.toHex());
//extreme("Destination::Destination: creating name hash...");
TRACE("Destination::Destination: hash: " + _object->_hash.toHex());
//TRACE("Destination::Destination: creating name hash...");
//p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
_object->_name_hash = name_hash(app_name, aspects);
//extreme("Destination::Destination: name hash: " + _object->_name_hash.toHex());
//TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex());
//extreme("Destination::Destination: calling register_destination");
//TRACE("Destination::Destination: calling register_destination");
Transport::register_destination(*this);
mem("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Destination::Destination(const Identity& identity, const Type::Destination::directions direction, const Type::Destination::types type, const Bytes& hash) : _object(new Object(identity)) {
assert(_object);
mem("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
_object->_type = type;
_object->_direction = direction;
@@ -71,26 +71,26 @@ Destination::Destination(const Identity& identity, const Type::Destination::dire
_object->_hash = hash;
_object->_hexhash = _object->_hash.toHex();
extreme("Destination::Destination: hash: " + _object->_hash.toHex());
//extreme("Destination::Destination: creating name hash...");
TRACE("Destination::Destination: hash: " + _object->_hash.toHex());
//TRACE("Destination::Destination: creating name hash...");
//p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
_object->_name_hash = name_hash("unknown", "unknown");
//extreme("Destination::Destination: name hash: " + _object->_name_hash.toHex());
//TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex());
//extreme("Destination::Destination: calling register_destination");
//TRACE("Destination::Destination: calling register_destination");
Transport::register_destination(*this);
mem("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
/*virtual*/ Destination::~Destination() {
mem("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
if (_object && _object.use_count() == 1) {
mem("Destination object has last data reference");
MEM("Destination object has last data reference");
// CBA Can't call deregister_destination here because it's possible (likely even) that Destination
// is being destructed from that same collection which will result in a llop and memory errors.
//extreme("Destination::~Destination: calling deregister_destination");
//TRACE("Destination::~Destination: calling deregister_destination");
//Transport::deregister_destination(*this);
}
}
@@ -184,7 +184,7 @@ relevant interfaces. Application specific data can be added to the announce.
//Packet Destination::announce(const Bytes& app_data /*= {}*/, bool path_response /*= false*/, const Interface& attached_interface /*= {Type::NONE}*/, const Bytes& tag /*= {}*/, bool send /*= true*/) {
Packet Destination::announce(const Bytes& app_data, bool path_response, const Interface& attached_interface, const Bytes& tag /*= {}*/, bool send /*= true*/) {
assert(_object);
extreme("Destination::announce: announcing destination...");
TRACE("Destination::announce: announcing destination...");
if (_object->_type != SINGLE) {
throw std::invalid_argument("Only SINGLE destination types can be announced");
@@ -213,29 +213,29 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
/*
// CBA TEST
extreme("Destination::announce: performing path test...");
extreme("Destination::announce: inserting path...");
TRACE("Destination::announce: performing path test...");
TRACE("Destination::announce: inserting path...");
_object->_path_responses.insert({Bytes("foo_tag"), {0, Bytes("this is foo tag")}});
extreme("Destination::announce: inserting path...");
TRACE("Destination::announce: inserting path...");
_object->_path_responses.insert({Bytes("test_tag"), {0, Bytes("this is test tag")}});
if (path_response) {
extreme("Destination::announce: path_response is true");
TRACE("Destination::announce: path_response is true");
}
if (!tag.empty()) {
extreme("Destination::announce: tag is specified");
TRACE("Destination::announce: tag is specified");
std::string tagstr((const char*)tag.data(), tag.size());
debug(std::string("Destination::announce: tag: ") + tagstr);
debug(std::string("Destination::announce: tag len: ") + std::to_string(tag.size()));
extreme("Destination::announce: searching for tag...");
DEBUG(std::string("Destination::announce: tag: ") + tagstr);
DEBUG(std::string("Destination::announce: tag len: ") + std::to_string(tag.size()));
TRACE("Destination::announce: searching for tag...");
if (_object->_path_responses.find(tag) != _object->_path_responses.end()) {
extreme("Destination::announce: found tag in _path_responses");
debug(std::string("Destination::announce: data: ") +_object->_path_responses[tag].second.toString());
TRACE("Destination::announce: found tag in _path_responses");
DEBUG(std::string("Destination::announce: data: ") +_object->_path_responses[tag].second.toString());
}
else {
extreme("Destination::announce: tag not found in _path_responses");
TRACE("Destination::announce: tag not found in _path_responses");
}
}
extreme("Destination::announce: path test finished");
TRACE("Destination::announce: path test finished");
*/
if (path_response && !tag.empty() && _object->_path_responses.find(tag) != _object->_path_responses.end()) {
@@ -247,7 +247,7 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
// received via multiple paths. The difference in reception time will
// potentially also be useful in determining characteristics of the
// multiple available paths, and to choose the best one.
//z extreme("Using cached announce data for answering path request with tag "+RNS.prettyhexrep(tag));
//z TRACE("Using cached announce data for answering path request with tag "+RNS.prettyhexrep(tag));
announce_data << _object->_path_responses[tag].second;
}
else {
@@ -262,20 +262,20 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
}
Bytes signed_data;
//extreme("Destination::announce: hash: " + _object->_hash.toHex());
//extreme("Destination::announce: public key: " + _object->_identity.get_public_key().toHex());
//extreme("Destination::announce: name hash: " + _object->_name_hash.toHex());
//extreme("Destination::announce: random hash: " + random_hash.toHex());
//extreme("Destination::announce: app data: " + new_app_data.toHex());
//extreme("Destination::announce: app data text:" + new_app_data.toString());
//TRACE("Destination::announce: hash: " + _object->_hash.toHex());
//TRACE("Destination::announce: public key: " + _object->_identity.get_public_key().toHex());
//TRACE("Destination::announce: name hash: " + _object->_name_hash.toHex());
//TRACE("Destination::announce: random hash: " + random_hash.toHex());
//TRACE("Destination::announce: app data: " + new_app_data.toHex());
//TRACE("Destination::announce: app data text:" + new_app_data.toString());
signed_data << _object->_hash << _object->_identity.get_public_key() << _object->_name_hash << random_hash;
if (new_app_data) {
signed_data << new_app_data;
}
//extreme("Destination::announce: signed data: " + signed_data.toHex());
//TRACE("Destination::announce: signed data: " + signed_data.toHex());
Bytes signature(_object->_identity.sign(signed_data));
//extreme("Destination::announce: signature: " + signature.toHex());
//TRACE("Destination::announce: signature: " + signature.toHex());
announce_data << _object->_identity.get_public_key() << _object->_name_hash << random_hash << signature;
@@ -285,20 +285,20 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
_object->_path_responses.insert({tag, {OS::time(), announce_data}});
}
//extreme("Destination::announce: announce_data:" + announce_data.toHex());
//TRACE("Destination::announce: announce_data:" + announce_data.toHex());
Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE;
if (path_response) {
announce_context = Type::Packet::PATH_RESPONSE;
}
//extreme("Destination::announce: creating announce packet...");
//TRACE("Destination::announce: creating announce packet...");
//p announce_packet = RNS.Packet(self, announce_data, RNS.Packet.ANNOUNCE, context = announce_context, attached_interface = attached_interface)
//Packet announce_packet(*this, announce_data, Type::Packet::ANNOUNCE, announce_context, Type::Transport::BROADCAST, Type::Packet::HEADER_1, nullptr, attached_interface);
Packet announce_packet(*this, attached_interface, announce_data, Type::Packet::ANNOUNCE, announce_context, Type::Transport::BROADCAST, Type::Packet::HEADER_1);
if (send) {
extreme("Destination::announce: sending announce packet...");
TRACE("Destination::announce: sending announce packet...");
announce_packet.send();
return {Type::NONE};
}
@@ -362,7 +362,7 @@ void Destination::receive(const Packet& packet) {
else {
// CBA TODO Why isn't the Packet decrypting itself?
Bytes plaintext(decrypt(packet.data()));
//extreme("Destination::receive: decrypted data: " + plaintext.toHex());
//TRACE("Destination::receive: decrypted data: " + plaintext.toHex());
if (plaintext) {
if (packet.packet_type() == Type::Packet::DATA) {
if (_object->_callbacks._packet) {
@@ -370,7 +370,7 @@ void Destination::receive(const Packet& packet) {
_object->_callbacks._packet(plaintext, packet);
}
catch (std::exception& e) {
debug("Error while executing receive callback from " + toString() + ". The contained exception was: " + e.what());
DEBUG("Error while executing receive callback from " + toString() + ". The contained exception was: " + e.what());
}
}
}
@@ -396,7 +396,7 @@ Encrypts information for ``RNS.Destination.SINGLE`` or ``RNS.Destination.GROUP``
*/
/*virtual*/ const Bytes Destination::encrypt(const Bytes& data) {
assert(_object);
extreme("Destination::encrypt: encrypting data...");
TRACE("Destination::encrypt: encrypting data...");
if (_object->_type == PLAIN) {
return data;
@@ -433,7 +433,7 @@ Decrypts information for ``RNS.Destination.SINGLE`` or ``RNS.Destination.GROUP``
*/
/*virtual*/ const Bytes Destination::decrypt(const Bytes& data) {
assert(_object);
extreme("Destination::decrypt: decrypting data...");
TRACE("Destination::decrypt: decrypting data...");
if (_object->_type == PLAIN) {
return data;
+5 -5
View File
@@ -55,10 +55,10 @@ namespace RNS {
public:
Destination(Type::NoneConstructor none) {
mem("Destination NONE object created, this: " + std::to_string((uintptr_t)this));
MEM("Destination NONE object created, this: " + std::to_string((uintptr_t)this));
}
Destination(const Destination& destination) : _object(destination._object) {
mem("Destination object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Destination object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Destination(
const Identity& identity,
@@ -77,7 +77,7 @@ namespace RNS {
inline Destination& operator = (const Destination& destination) {
_object = destination._object;
mem("Destination object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Destination object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
}
inline operator bool() const {
@@ -179,8 +179,8 @@ namespace RNS {
private:
class Object {
public:
Object(const Identity& identity) : _identity(identity) { mem("Destination::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { mem("Destination::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
Object(const Identity& identity) : _identity(identity) { MEM("Destination::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { MEM("Destination::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
private:
bool _accept_link_requests = true;
Callbacks _callbacks;
+16 -16
View File
@@ -18,51 +18,51 @@ namespace RNS {
public:
Filesystem(Type::NoneConstructor none) {
mem("Filesystem object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Filesystem(const Filesystem& filesystem) : _object(filesystem._object) {
mem("Filesystem object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Filesystem() : _object(new Object(this)), _creator(true) {
mem("Filesystem object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
virtual ~Filesystem() {
if (_creator) {
mem("Filesystem object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
// clear reference to parent in object foir safety
assert(_object);
_object->_parent = nullptr;
}
mem("Filesystem object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
inline Filesystem& operator = (const Filesystem& filesystem) {
_object = filesystem._object;
mem("Filesystem object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
if (_creator) {
mem("Filesystem object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
_creator = false;
}
return *this;
}
inline operator bool() const {
mem("Filesystem object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() != nullptr;
}
inline bool operator < (const Filesystem& filesystem) const {
mem("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() < filesystem._object.get();
}
inline bool operator > (const Filesystem& filesystem) const {
mem("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() > filesystem._object.get();
}
inline bool operator == (const Filesystem& filesystem) const {
mem("Filesystem object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() == filesystem._object.get();
}
inline bool operator != (const Filesystem& filesystem) const {
mem("Filesystem object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Filesystem object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() != filesystem._object.get();
}
@@ -76,7 +76,7 @@ namespace RNS {
virtual bool directory_exists(const char* directory_path) { return false; }
virtual bool create_directory(const char* directory_path) { return false; }
virtual bool remove_directory(const char* directory_path) { return false; }
virtual std::list<std::string> list_directory(const char* directory_path) { extreme("list_directory: empty"); return _empty; }
virtual std::list<std::string> list_directory(const char* directory_path) { TRACE("list_directory: empty"); return _empty; }
public:
inline bool do_file_exists(const char* file_path) { assert(_object); return _object->do_file_exists(file_path); }
@@ -107,9 +107,9 @@ namespace RNS {
private:
class Object {
public:
Object(Filesystem* parent) : _parent(parent) { mem("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); }
Object(Filesystem* parent, const char* name) : _parent(parent) { mem("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { mem("Filesystem::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
Object(Filesystem* parent) : _parent(parent) { MEM("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); }
Object(Filesystem* parent, const char* name) : _parent(parent) { MEM("Filesystem::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { MEM("Filesystem::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
private:
virtual inline bool do_file_exists(const char* file_path) { if (_parent == nullptr) return false; return _parent->file_exists(file_path); }
virtual inline size_t do_read_file(const char* file_path, Bytes& data) { if (_parent == nullptr) return {Bytes::NONE}; return _parent->read_file(file_path, data); }
+59 -59
View File
@@ -25,7 +25,7 @@ Identity::Identity(bool create_keys /*= true*/) : _object(new Object()) {
if (create_keys) {
createKeys();
}
mem("Identity object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Identity object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
void Identity::createKeys() {
@@ -34,22 +34,22 @@ void Identity::createKeys() {
// CRYPTO: create encryption private keys
_object->_prv = Cryptography::X25519PrivateKey::generate();
_object->_prv_bytes = _object->_prv->private_bytes();
//extreme("Identity::createKeys: prv bytes: " + _object->_prv_bytes.toHex());
//TRACE("Identity::createKeys: prv bytes: " + _object->_prv_bytes.toHex());
// CRYPTO: create signature private keys
_object->_sig_prv = Cryptography::Ed25519PrivateKey::generate();
_object->_sig_prv_bytes = _object->_sig_prv->private_bytes();
//extreme("Identity::createKeys: sig prv bytes: " + _object->_sig_prv_bytes.toHex());
//TRACE("Identity::createKeys: sig prv bytes: " + _object->_sig_prv_bytes.toHex());
// CRYPTO: create encryption public keys
_object->_pub = _object->_prv->public_key();
_object->_pub_bytes = _object->_pub->public_bytes();
//extreme("Identity::createKeys: pub bytes: " + _object->_pub_bytes.toHex());
//TRACE("Identity::createKeys: pub bytes: " + _object->_pub_bytes.toHex());
// CRYPTO: create signature public keys
_object->_sig_pub = _object->_sig_prv->public_key();
_object->_sig_pub_bytes = _object->_sig_pub->public_bytes();
//extreme("Identity::createKeys: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
//TRACE("Identity::createKeys: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
update_hashes();
@@ -70,20 +70,20 @@ bool Identity::load_private_key(const Bytes& prv_bytes) {
//p self.prv_bytes = prv_bytes[:Identity.KEYSIZE//8//2]
_object->_prv_bytes = prv_bytes.left(Type::Identity::KEYSIZE/8/2);
_object->_prv = X25519PrivateKey::from_private_bytes(_object->_prv_bytes);
//extreme("Identity::load_private_key: prv bytes: " + _object->_prv_bytes.toHex());
//TRACE("Identity::load_private_key: prv bytes: " + _object->_prv_bytes.toHex());
//p self.sig_prv_bytes = prv_bytes[Identity.KEYSIZE//8//2:]
_object->_sig_prv_bytes = prv_bytes.mid(Type::Identity::KEYSIZE/8/2);
_object->_sig_prv = Ed25519PrivateKey::from_private_bytes(_object->_sig_prv_bytes);
//extreme("Identity::load_private_key: sig prv bytes: " + _object->_sig_prv_bytes.toHex());
//TRACE("Identity::load_private_key: sig prv bytes: " + _object->_sig_prv_bytes.toHex());
_object->_pub = _object->_prv->public_key();
_object->_pub_bytes = _object->_pub->public_bytes();
//extreme("Identity::load_private_key: pub bytes: " + _object->_pub_bytes.toHex());
//TRACE("Identity::load_private_key: pub bytes: " + _object->_pub_bytes.toHex());
_object->_sig_pub = _object->_sig_prv->public_key();
_object->_sig_pub_bytes = _object->_sig_pub->public_bytes();
//extreme("Identity::load_private_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
//TRACE("Identity::load_private_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
update_hashes();
@@ -110,11 +110,11 @@ void Identity::load_public_key(const Bytes& pub_bytes) {
//_pub_bytes = pub_bytes[:Identity.KEYSIZE//8//2]
_object->_pub_bytes = pub_bytes.left(Type::Identity::KEYSIZE/8/2);
//extreme("Identity::load_public_key: pub bytes: " + _object->_pub_bytes.toHex());
//TRACE("Identity::load_public_key: pub bytes: " + _object->_pub_bytes.toHex());
//_sig_pub_bytes = pub_bytes[Identity.KEYSIZE//8//2:]
_object->_sig_pub_bytes = pub_bytes.mid(Type::Identity::KEYSIZE/8/2);
//extreme("Identity::load_public_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
//TRACE("Identity::load_public_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
_object->_pub = X25519PublicKey::from_public_bytes(_object->_pub_bytes);
_object->_sig_pub = Ed25519PublicKey::from_public_bytes(_object->_sig_pub_bytes);
@@ -127,7 +127,7 @@ void Identity::load_public_key(const Bytes& pub_bytes) {
}
bool Identity::load(const char* path) {
extreme("Reading identity key from storage...");
TRACE("Reading identity key from storage...");
try {
Bytes prv_bytes;
if (OS::read_file(path, prv_bytes) > 0) {
@@ -153,7 +153,7 @@ communication for the identity. Be very careful with this method.
:returns: True if the file was saved, otherwise False.
*/
bool Identity::to_file(const char* path) {
extreme("Writing identity key to storage...");
TRACE("Writing identity key to storage...");
try {
return (OS::write_file(path, get_private_key()) == get_private_key().size());
}
@@ -197,10 +197,10 @@ Recall identity for a destination hash.
:returns: An :ref:`RNS.Identity<api-identity>` instance that can be used to create an outgoing :ref:`RNS.Destination<api-destination>`, or *None* if the destination is unknown.
*/
/*static*/ Identity Identity::recall(const Bytes& destination_hash) {
extreme("Identity::recall...");
TRACE("Identity::recall...");
auto iter = _known_destinations.find(destination_hash);
if (iter != _known_destinations.end()) {
extreme("Identity::recall: Found identity entry for destination " + destination_hash.toHex());
TRACE("Identity::recall: Found identity entry for destination " + destination_hash.toHex());
const IdentityEntry& identity_data = (*iter).second;
Identity identity(false);
identity.load_public_key(identity_data._public_key);
@@ -208,16 +208,16 @@ Recall identity for a destination hash.
return identity;
}
else {
extreme("Identity::recall: Unable to find identity entry for destination " + destination_hash.toHex() + ", performing destination lookup...");
TRACE("Identity::recall: Unable to find identity entry for destination " + destination_hash.toHex() + ", performing destination lookup...");
Destination registered_destination(Transport::find_destination_from_hash(destination_hash));
if (registered_destination) {
extreme("Identity::recall: Found destination " + destination_hash.toHex());
TRACE("Identity::recall: Found destination " + destination_hash.toHex());
Identity identity(false);
identity.load_public_key(registered_destination.identity().get_public_key());
identity.app_data({Bytes::NONE});
return identity;
}
extreme("Identity::recall: Unable to find destination " + destination_hash.toHex());
TRACE("Identity::recall: Unable to find destination " + destination_hash.toHex());
return {Type::NONE};
}
}
@@ -229,15 +229,15 @@ Recall last heard app_data for a destination hash.
:returns: *Bytes* containing app_data, or *None* if the destination is unknown.
*/
/*static*/ Bytes Identity::recall_app_data(const Bytes& destination_hash) {
extreme("Identity::recall_app_data...");
TRACE("Identity::recall_app_data...");
auto iter = _known_destinations.find(destination_hash);
if (iter != _known_destinations.end()) {
extreme("Identity::recall_app_data: Found identity entry for destination " + destination_hash.toHex());
TRACE("Identity::recall_app_data: Found identity entry for destination " + destination_hash.toHex());
const IdentityEntry& identity_data = (*iter).second;
return identity_data._app_data;
}
else {
extreme("Identity::recall_app_data: Unable to find identity entry for destination " + destination_hash.toHex());
TRACE("Identity::recall_app_data: Unable to find identity entry for destination " + destination_hash.toHex());
return {Bytes::NONE};
}
}
@@ -289,7 +289,7 @@ Recall last heard app_data for a destination hash.
// TODO
/*
debug("Saving " + std::to_string(_known_destinations.size()) + " known destinations to storage...");
DEBUG("Saving " + std::to_string(_known_destinations.size()) + " known destinations to storage...");
file = open(RNS.Reticulum.storagepath+"/known_destinations","wb")
umsgpack.dump(Identity.known_destinations, file)
file.close()
@@ -304,7 +304,7 @@ Recall last heard app_data for a destination hash.
time_str = std::to_string(OS::round(save_time, 1)) + " s";
}
debug("Saved known destinations to storage in " + time_str);
DEBUG("Saved known destinations to storage in " + time_str);
success = true;
}
@@ -344,25 +344,25 @@ Recall last heard app_data for a destination hash.
try {
if (packet.packet_type() == Type::Packet::ANNOUNCE) {
Bytes destination_hash = packet.destination_hash();
//extreme("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex());
//TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex());
Bytes public_key = packet.data().left(KEYSIZE/8);
//extreme("Identity::validate_announce: public_key: " + public_key.toHex());
//TRACE("Identity::validate_announce: public_key: " + public_key.toHex());
Bytes name_hash = packet.data().mid(KEYSIZE/8, NAME_HASH_LENGTH/8);
//extreme("Identity::validate_announce: name_hash: " + name_hash.toHex());
//TRACE("Identity::validate_announce: name_hash: " + name_hash.toHex());
Bytes random_hash = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8, RANDOM_HASH_LENGTH/8);
//extreme("Identity::validate_announce: random_hash: " + random_hash.toHex());
//TRACE("Identity::validate_announce: random_hash: " + random_hash.toHex());
Bytes signature = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8, SIGLENGTH/8);
//extreme("Identity::validate_announce: signature: " + signature.toHex());
//TRACE("Identity::validate_announce: signature: " + signature.toHex());
Bytes app_data;
if (packet.data().size() > (KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8)) {
app_data = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8);
}
//extreme("Identity::validate_announce: app_data: " + app_data.toHex());
//extreme("Identity::validate_announce: app_data text: " + app_data.toString());
//TRACE("Identity::validate_announce: app_data: " + app_data.toHex());
//TRACE("Identity::validate_announce: app_data text: " + app_data.toString());
Bytes signed_data;
signed_data << packet.destination_hash() << public_key << name_hash << random_hash+app_data;
//extreme("Identity::validate_announce: signed_data: " + signed_data.toHex());
//TRACE("Identity::validate_announce: signed_data: " + signed_data.toHex());
if (packet.data().size() <= KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8) {
app_data.clear();
@@ -374,8 +374,8 @@ Recall last heard app_data for a destination hash.
if (announced_identity.pub() && announced_identity.validate(signature, signed_data)) {
Bytes hash_material = name_hash << announced_identity.hash();
Bytes expected_hash = full_hash(hash_material).left(Type::Reticulum::TRUNCATED_HASHLENGTH/8);
//extreme("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex());
//extreme("Identity::validate_announce: expected_hash: " + expected_hash.toHex());
//TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex());
//TRACE("Identity::validate_announce: expected_hash: " + expected_hash.toHex());
if (packet.destination_hash() == expected_hash) {
// Check if we already have a public key for this destination
@@ -412,21 +412,21 @@ Recall last heard app_data for a destination hash.
*/
if (packet.transport_id()) {
extreme("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received via " + packet.transport_id().toHex() + " on " + packet.receiving_interface().toString() + signal_str);
TRACE("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received via " + packet.transport_id().toHex() + " on " + packet.receiving_interface().toString() + signal_str);
}
else {
extreme("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received on " + packet.receiving_interface().toString() + signal_str);
TRACE("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received on " + packet.receiving_interface().toString() + signal_str);
}
return true;
}
else {
debug("Received invalid announce for " + packet.destination_hash().toHex() + ": Destination mismatch.");
DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Destination mismatch.");
return false;
}
}
else {
debug("Received invalid announce for " + packet.destination_hash().toHex() + ": Invalid signature.");
DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Invalid signature.");
//p del announced_identity
return false;
}
@@ -458,18 +458,18 @@ Encrypts information for the identity.
*/
const Bytes Identity::encrypt(const Bytes& plaintext) const {
assert(_object);
extreme("Identity::encrypt: encrypting data...");
TRACE("Identity::encrypt: encrypting data...");
if (!_object->_pub) {
throw std::runtime_error("Encryption failed because identity does not hold a public key");
}
Cryptography::X25519PrivateKey::Ptr ephemeral_key = Cryptography::X25519PrivateKey::generate();
Bytes ephemeral_pub_bytes = ephemeral_key->public_key()->public_bytes();
extreme("Identity::encrypt: ephemeral public key: " + ephemeral_pub_bytes.toHex());
TRACE("Identity::encrypt: ephemeral public key: " + ephemeral_pub_bytes.toHex());
// CRYPTO: create shared key for key exchange using own public key
//shared_key = ephemeral_key.exchange(self.pub)
Bytes shared_key = ephemeral_key->exchange(_object->_pub_bytes);
extreme("Identity::encrypt: shared key: " + shared_key.toHex());
TRACE("Identity::encrypt: shared key: " + shared_key.toHex());
Bytes derived_key = Cryptography::hkdf(
32,
@@ -477,13 +477,13 @@ const Bytes Identity::encrypt(const Bytes& plaintext) const {
get_salt(),
get_context()
);
extreme("Identity::encrypt: derived key: " + derived_key.toHex());
TRACE("Identity::encrypt: derived key: " + derived_key.toHex());
Cryptography::Fernet fernet(derived_key);
extreme("Identity::encrypt: Fernet encrypting data of length " + std::to_string(plaintext.size()));
extreme("Identity::encrypt: plaintext: " + plaintext.toHex());
TRACE("Identity::encrypt: Fernet encrypting data of length " + std::to_string(plaintext.size()));
TRACE("Identity::encrypt: plaintext: " + plaintext.toHex());
Bytes ciphertext = fernet.encrypt(plaintext);
extreme("Identity::encrypt: ciphertext: " + ciphertext.toHex());
TRACE("Identity::encrypt: ciphertext: " + ciphertext.toHex());
return ephemeral_pub_bytes + ciphertext;
}
@@ -498,12 +498,12 @@ Decrypts information for the identity.
*/
const Bytes Identity::decrypt(const Bytes& ciphertext_token) const {
assert(_object);
extreme("Identity::decrypt: decrypting data...");
TRACE("Identity::decrypt: decrypting data...");
if (!_object->_prv) {
throw std::runtime_error("Decryption failed because identity does not hold a private key");
}
if (ciphertext_token.size() <= Type::Identity::KEYSIZE/8/2) {
debug("Decryption failed because the token size " + std::to_string(ciphertext_token.size()) + " was invalid.");
DEBUG("Decryption failed because the token size " + std::to_string(ciphertext_token.size()) + " was invalid.");
return {Bytes::NONE};
}
Bytes plaintext;
@@ -512,12 +512,12 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const {
Bytes peer_pub_bytes = ciphertext_token.left(Type::Identity::KEYSIZE/8/2);
//peer_pub = X25519PublicKey.from_public_bytes(peer_pub_bytes)
//Cryptography::X25519PublicKey::Ptr peer_pub = Cryptography::X25519PublicKey::from_public_bytes(peer_pub_bytes);
extreme("Identity::decrypt: peer public key: " + peer_pub_bytes.toHex());
TRACE("Identity::decrypt: peer public key: " + peer_pub_bytes.toHex());
// CRYPTO: create shared key for key exchange using peer public key
//shared_key = _object->_prv->exchange(peer_pub);
Bytes shared_key = _object->_prv->exchange(peer_pub_bytes);
extreme("Identity::decrypt: shared key: " + shared_key.toHex());
TRACE("Identity::decrypt: shared key: " + shared_key.toHex());
Bytes derived_key = Cryptography::hkdf(
32,
@@ -525,19 +525,19 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const {
get_salt(),
get_context()
);
extreme("Identity::decrypt: derived key: " + derived_key.toHex());
TRACE("Identity::decrypt: derived key: " + derived_key.toHex());
Cryptography::Fernet fernet(derived_key);
//ciphertext = ciphertext_token[Identity.KEYSIZE//8//2:]
Bytes ciphertext(ciphertext_token.mid(Type::Identity::KEYSIZE/8/2));
extreme("Identity::decrypt: Fernet decrypting data of length " + std::to_string(ciphertext.size()));
extreme("Identity::decrypt: ciphertext: " + ciphertext.toHex());
TRACE("Identity::decrypt: Fernet decrypting data of length " + std::to_string(ciphertext.size()));
TRACE("Identity::decrypt: ciphertext: " + ciphertext.toHex());
plaintext = fernet.decrypt(ciphertext);
extreme("Identity::decrypt: plaintext: " + plaintext.toHex());
//extreme("Identity::decrypt: Fernet decrypted data of length " + std::to_string(plaintext.size()));
TRACE("Identity::decrypt: plaintext: " + plaintext.toHex());
//TRACE("Identity::decrypt: Fernet decrypted data of length " + std::to_string(plaintext.size()));
}
catch (std::exception& e) {
debug("Decryption by " + toString() + " failed: " + e.what());
DEBUG("Decryption by " + toString() + " failed: " + e.what());
}
return plaintext;
@@ -576,7 +576,7 @@ bool Identity::validate(const Bytes& signature, const Bytes& message) const {
assert(_object);
if (_object->_pub) {
try {
extreme("Identity::validate: Attempting to verify signature: " + signature.toHex() + " and message: " + message.toHex());
TRACE("Identity::validate: Attempting to verify signature: " + signature.toHex() + " and message: " + message.toHex());
_object->_sig_pub->verify(signature, message);
return true;
}
@@ -595,21 +595,21 @@ void Identity::prove(const Packet& packet, const Destination& destination /*= {T
Bytes proof_data;
if (RNS::Reticulum::should_use_implicit_proof()) {
proof_data = signature;
extreme("Identity::prove: implicit proof data: " + proof_data.toHex());
TRACE("Identity::prove: implicit proof data: " + proof_data.toHex());
}
else {
proof_data = packet.packet_hash() + signature;
extreme("Identity::prove: explicit proof data: " + proof_data.toHex());
TRACE("Identity::prove: explicit proof data: " + proof_data.toHex());
}
if (!destination) {
extreme("Identity::prove: proving packet with proof destination...");
TRACE("Identity::prove: proving packet with proof destination...");
ProofDestination proof_destination = packet.generate_proof_destination();
Packet proof(proof_destination, packet.receiving_interface(), proof_data, Type::Packet::PROOF);
proof.send();
}
else {
extreme("Identity::prove: proving packet with specified destination...");
TRACE("Identity::prove: proving packet with specified destination...");
Packet proof(destination, packet.receiving_interface(), proof_data, Type::Packet::PROOF);
proof.send();
}
+7 -7
View File
@@ -43,19 +43,19 @@ namespace RNS {
public:
Identity(Type::NoneConstructor none) {
mem("Identity NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Identity NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Identity(const Identity& identity) : _object(identity._object) {
mem("Identity object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Identity object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Identity(bool create_keys = true);
virtual ~Identity() {
mem("Identity object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Identity object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
inline Identity& operator = (const Identity& identity) {
_object = identity._object;
mem("Identity object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Identity object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
}
inline operator bool() const {
@@ -87,7 +87,7 @@ namespace RNS {
inline void update_hashes() {
assert(_object);
_object->_hash = truncated_hash(get_public_key());
extreme("Identity::update_hashes: hash: " + _object->_hash.toHex());
TRACE("Identity::update_hashes: hash: " + _object->_hash.toHex());
_object->_hexhash = _object->_hash.toHex();
};
bool load(const char* path);
@@ -161,8 +161,8 @@ namespace RNS {
private:
class Object {
public:
Object() { mem("Identity::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { mem("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
Object() { MEM("Identity::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { MEM("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
private:
Cryptography::X25519PrivateKey::Ptr _prv;
+11 -11
View File
@@ -10,17 +10,17 @@ using namespace RNS::Type::Interface;
Interface::Interface() : _object(new Object(this)), _creator(true) {
_object->_hash = Identity::full_hash({toString()});
mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Interface::Interface(const char* name) : _object(new Object(this, name)), _creator(true) {
_object->_hash = Identity::full_hash({toString()});
mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
/*virtual*/ inline void Interface::on_incoming(const Bytes& data) {
//extreme("Interface.on_incoming: data: " + data.toHex());
extreme("Interface.on_incoming");
//TRACE("Interface.on_incoming: data: " + data.toHex());
TRACE("Interface.on_incoming");
assert(_object);
_object->_rxb += data.size();
// CBA TODO implement concept of owner or a callback mechanism for incoming data
@@ -29,8 +29,8 @@ Interface::Interface(const char* name) : _object(new Object(this, name)), _creat
}
/*virtual*/ inline void Interface::on_outgoing(const Bytes& data) {
//extreme("Interface.on_outgoing: data: " + data.toHex());
extreme("Interface.on_outgoing");
//TRACE("Interface.on_outgoing: data: " + data.toHex());
TRACE("Interface.on_outgoing");
assert(_object);
_object->_txb += data.size();
}
@@ -90,19 +90,19 @@ void Interface::process_announce_queue() {
/*
void ArduinoJson::convertFromJson(JsonVariantConst src, RNS::Interface& dst) {
RNS::extreme(">>> Deserializing Interface");
RNS::extreme(">>> Interface pre: " + dst.debugString());
TRACE(">>> Deserializing Interface");
TRACE(">>> Interface pre: " + dst.debugString());
if (!src.isNull()) {
RNS::Bytes hash;
hash.assignHex(src.as<const char*>());
RNS::extreme(">>> Querying Transport for Interface hash " + hash.toHex());
TRACE(">>> Querying Transport for Interface hash " + hash.toHex());
// Query transport for matching interface
dst = Transport::find_interface_from_hash(hash);
RNS::extreme(">>> Interface post: " + dst.debugString());
TRACE(">>> Interface post: " + dst.debugString());
}
else {
dst = {RNS::Type::NONE};
RNS::extreme(">>> Interface post: " + dst.debugString());
TRACE(">>> Interface post: " + dst.debugString());
}
}
*/
+19 -19
View File
@@ -43,50 +43,50 @@ namespace RNS {
public:
Interface(Type::NoneConstructor none) {
mem("Interface object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object NONE created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Interface(const Interface& interface) : _object(interface._object) {
mem("Interface object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Interface();
Interface(const char* name);
virtual ~Interface() {
if (_creator) {
mem("Interface object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object clearing parent reference, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
// clear reference to parent in object foir safety
assert(_object);
_object->_parent = nullptr;
}
mem("Interface object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
inline Interface& operator = (const Interface& interface) {
_object = interface._object;
mem("Interface object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
if (_creator) {
mem("Interface object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object clearing creator flag, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
_creator = false;
}
return *this;
}
inline operator bool() const {
mem("Interface object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() != nullptr;
}
inline bool operator < (const Interface& interface) const {
mem("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() < interface._object.get();
}
inline bool operator > (const Interface& interface) const {
mem("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() > interface._object.get();
}
inline bool operator == (const Interface& interface) const {
mem("Interface object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() == interface._object.get();
}
inline bool operator != (const Interface& interface) const {
mem("Interface object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Interface object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return _object.get() != interface._object.get();
}
@@ -147,9 +147,9 @@ namespace RNS {
private:
class Object {
public:
Object(Interface* parent) : _parent(parent) { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
Object(Interface* parent, const char* name) : _parent(parent), _name(name) { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { mem("Interface::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
Object(Interface* parent) : _parent(parent) { MEM("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
Object(Interface* parent, const char* name) : _parent(parent), _name(name) { MEM("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { MEM("Interface::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
private:
//virtual inline void process_incoming(const Bytes& data) { if (_parent != nullptr) { _parent->on_incoming(data); } }
virtual inline void process_outgoing(const Bytes& data) { if (_parent != nullptr) { _parent->on_outgoing(data); } }
@@ -187,11 +187,11 @@ namespace RNS {
/*
namespace ArduinoJson {
inline bool convertToJson(const RNS::Interface& src, JsonVariant dst) {
RNS::extreme("<<< Serializing Interface");
TRACE("<<< Serializing Interface");
if (!src) {
return dst.set(nullptr);
}
RNS::extreme("<<< Interface hash " + src.get_hash().toHex());
TRACE("<<< Interface hash " + src.get_hash().toHex());
return dst.set(src.get_hash().toHex());
}
void convertFromJson(JsonVariantConst src, RNS::Interface& dst);
@@ -208,15 +208,15 @@ namespace ArduinoJson {
if (!src) {
return dst.set(nullptr);
}
RNS::extreme("<<< Serializing interface hash " + src.get_hash().toHex());
TRACE("<<< Serializing interface hash " + src.get_hash().toHex());
return dst.set(src.get_hash().toHex());
}
static RNS::Interface fromJson(JsonVariantConst src) {
if (!src.isNull()) {
RNS::Bytes hash;
hash.assignHex(src.as<const char*>());
RNS::extreme(">>> Deserialized interface hash " + hash.toHex());
RNS::extreme(">>> Querying transport for interface");
TRACE(">>> Deserialized interface hash " + hash.toHex());
TRACE(">>> Querying transport for interface");
// Query transport for matching interface
return RNS::Interface::find_interface_from_hash(hash);
}
+1 -1
View File
@@ -9,7 +9,7 @@ using namespace RNS::Type::Link;
Link::Link(const Destination& destination) : _object(new Object(destination)) {
assert(_object);
mem("Link object created");
MEM("Link object created");
}
+3 -3
View File
@@ -22,14 +22,14 @@ namespace RNS {
public:
Link(Type::NoneConstructor none) {
mem("Link NONE object created");
MEM("Link NONE object created");
}
Link(const Link& link) : _object(link._object) {
mem("Link object copy created");
MEM("Link object copy created");
}
Link(const Destination& destination);
virtual ~Link(){
mem("Link object destroyed");
MEM("Link object destroyed");
}
inline Link& operator = (const Link& link) {
+7 -6
View File
@@ -7,13 +7,14 @@
#include <string>
#ifndef NDEBUG
#define DEBUG(msg) (RNS::debug(msg))
#define TRACE(msg) (RNS::extreme(msg))
#define MEM(msg) (RNS::mem(msg))
#define DEBUG(msg) (RNS::debug(msg))
#define TRACE(msg) (RNS::extreme(msg))
//#define MEM(msg) (RNS::mem(msg))
#define MEM(ignore) ((void)0)
#else
#define DEBUG(ignore) ((void)0)
#define TRACE(ignore) ((void)0)
#define MEM(ignore) ((void)0)
#define DEBUG(ignore) ((void)0)
#define TRACE(ignore) ((void)0)
#define MEM(ignore) ((void)0)
#endif
namespace RNS {
+16 -16
View File
@@ -20,7 +20,7 @@ ProofDestination::ProofDestination(const Packet& packet) : Destination({Type::NO
Packet::Packet(const Destination& destination, const Interface& attached_interface, const Bytes& data, types packet_type /*= DATA*/, context_types context /*= CONTEXT_NONE*/, Type::Transport::types transport_type /*= Type::Transport::BROADCAST*/, header_types header_type /*= HEADER_1*/, const Bytes& transport_id /*= {Bytes::NONE}*/, bool create_receipt /*= true*/) : _object(new Object(destination, attached_interface)) {
if (_object->_destination) {
extreme("Creating packet with destination...");
TRACE("Creating packet with destination...");
// CBA Should never see empty transport_type
//if (transport_type == NONE) {
// transport_type = Type::Transport::BROADCAST;
@@ -41,13 +41,13 @@ Packet::Packet(const Destination& destination, const Interface& attached_interfa
_object->_create_receipt = create_receipt;
}
else {
extreme("Creating packet without destination...");
TRACE("Creating packet without destination...");
_object->_raw = data;
_object->_packed = true;
_object->_fromPacked = true;
_object->_create_receipt = false;
}
mem("Packet object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Packet object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
@@ -241,7 +241,7 @@ but excluding any interface access codes.
void Packet::pack() {
assert(_object);
extreme("Packet::pack: packing packet...");
TRACE("Packet::pack: packing packet...");
if (!_object->_destination) {
throw std::logic_error("Packet destination is required");
@@ -255,14 +255,14 @@ void Packet::pack() {
_object->_raw << _object->_hops;
if (_object->_context == LRPROOF) {
extreme("Packet::pack: destination link id: " + _object->_destination.link_id().toHex() );
TRACE("Packet::pack: destination link id: " + _object->_destination.link_id().toHex() );
_object->_raw << _object->_destination.link_id();
_object->_raw << (uint8_t)_object->_context;
_object->_raw << _object->_data;
}
else {
if (_object->_header_type == HEADER_1) {
extreme("Packet::pack: destination hash: " + _object->_destination.hash().toHex() );
TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() );
_object->_raw << _object->_destination.hash();
_object->_raw << (uint8_t)_object->_context;
@@ -307,8 +307,8 @@ void Packet::pack() {
if (!_object->_transport_id) {
throw std::invalid_argument("Packet with header type 2 must have a transport ID");
}
extreme("Packet::pack: transport id: " + _object->_transport_id.toHex() );
extreme("Packet::pack: destination hash: " + _object->_destination.hash().toHex() );
TRACE("Packet::pack: transport id: " + _object->_transport_id.toHex() );
TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() );
_object->_raw << _object->_transport_id;
_object->_raw << _object->_destination.hash();
_object->_raw << (uint8_t)_object->_context;
@@ -333,7 +333,7 @@ void Packet::pack() {
bool Packet::unpack() {
assert(_object);
extreme("Packet::unpack: unpacking packet...");
TRACE("Packet::unpack: unpacking packet...");
try {
if (_object->_raw.size() < Type::Reticulum::HEADER_MINSIZE) {
throw std::length_error("Packet size of " + std::to_string(_object->_raw.size()) + " does not meet minimum header size of " + std::to_string(Type::Reticulum::HEADER_MINSIZE) +" bytes");
@@ -391,7 +391,7 @@ Sends the packet.
*/
bool Packet::send() {
assert(_object);
extreme("Packet::send: sending packet...");
TRACE("Packet::send: sending packet...");
if (_object->_sent) {
throw std::logic_error("Packet was already sent");
}
@@ -414,7 +414,7 @@ bool Packet::send() {
}
if (Transport::outbound(*this)) {
extreme("Packet::send: successfully sent packet!!!");
TRACE("Packet::send: successfully sent packet!!!");
//z return self.receipt
// MOCK
return true;
@@ -434,7 +434,7 @@ Re-sends the packet.
*/
bool Packet::resend() {
assert(_object);
extreme("Packet::resend: re-sending packet...");
TRACE("Packet::resend: re-sending packet...");
if (!_object->_sent) {
throw std::logic_error("Packet was not sent yet");
}
@@ -443,7 +443,7 @@ bool Packet::resend() {
pack();
if (Transport::outbound(*this)) {
extreme("Packet::resend: successfully sent packet!!!");
TRACE("Packet::resend: successfully sent packet!!!");
//z return self.receipt
// MOCK
return true;
@@ -458,7 +458,7 @@ bool Packet::resend() {
void Packet::prove(const Destination& destination /*= {Type::NONE}*/) {
assert(_object);
extreme("Packet::prove: proving packet...");
TRACE("Packet::prove: proving packet...");
if (!_object->_destination) {
throw std::logic_error("Packet destination is required");
}
@@ -780,7 +780,7 @@ bool PacketReceipt::validate_link_proof(const Bytes& proof, const Link& link) {
}
bool PacketReceipt::validate_link_proof(const Bytes& proof, const Link& link, const Packet& proof_packet) {
assert(_object);
extreme("PacketReceipt::validate_link_proof: validating link proof...");
TRACE("PacketReceipt::validate_link_proof: validating link proof...");
// TODO: Hardcoded as explicit proofs for now
if (true || proof.size() == EXPL_LENGTH) {
// This is an explicit proof
@@ -843,7 +843,7 @@ bool PacketReceipt::validate_proof(const Bytes& proof) {
}
bool PacketReceipt::validate_proof(const Bytes& proof, const Packet& proof_packet) {
assert(_object);
extreme("PacketReceipt::validate_proof: validating proof...");
TRACE("PacketReceipt::validate_proof: validating proof...");
if (proof.size() == EXPL_LENGTH) {
// This is an explicit proof
Bytes proof_hash = proof.left(Type::Identity::HASHLENGTH/8);
+9 -9
View File
@@ -136,10 +136,10 @@ namespace RNS {
public:
Packet(Type::NoneConstructor none) {
mem("Packet NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Packet NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Packet(const Packet& packet) : _object(packet._object) {
mem("Packet object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Packet object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Packet(
const Destination& destination,
@@ -163,12 +163,12 @@ namespace RNS {
bool create_receipt = true
) : Packet(destination, {Type::NONE}, data, packet_type, context, transport_type, header_type, transport_id, create_receipt) {}
virtual ~Packet() {
mem("Packet object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Packet object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
inline Packet& operator = (const Packet& packet) {
_object = packet._object;
mem("Packet object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Packet object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
}
inline operator bool() const {
@@ -244,8 +244,8 @@ namespace RNS {
private:
class Object {
public:
Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) { mem("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { mem("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) { MEM("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); }
virtual ~Object() { MEM("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
private:
Destination _destination = {Type::NONE};
Link _link = {Type::NONE};
@@ -314,15 +314,15 @@ namespace ArduinoJson {
if (!src) {
return dst.set(nullptr);
}
RNS::extreme("<<< Serializing packet hash " + src.get_hash().toHex());
TRACE("<<< Serializing packet hash " + src.get_hash().toHex());
return dst.set(src.get_hash().toHex());
}
static RNS::Packet fromJson(JsonVariantConst src) {
if (!src.isNull()) {
RNS::Bytes hash;
hash.assignHex(src.as<const char*>());
RNS::extreme(">>> Deserialized packet hash " + hash.toHex());
RNS::extreme(">>> Querying transport for cached packet");
TRACE(">>> Deserialized packet hash " + hash.toHex());
TRACE(">>> Querying transport for cached packet");
// Query transport for matching interface
return RNS::Packet::get_cached_packet(hash);
}
+9 -9
View File
@@ -37,12 +37,12 @@ pass any traffic before being instantiated.
*/
//def __init__(self,configdir=None, loglevel=None, logdest=None, verbosity=None):
Reticulum::Reticulum() : _object(new Object()) {
mem("Reticulum default object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Reticulum default object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
// Initialize random number generator
extreme("Initializing RNG...");
TRACE("Initializing RNG...");
RNG.begin("Reticulum");
extreme("RNG initial random value: " + std::to_string(Cryptography::randomnum()));
TRACE("RNG initial random value: " + std::to_string(Cryptography::randomnum()));
#ifdef ARDUINO
// Add a noise source to the list of sources known to RNG.
@@ -89,7 +89,7 @@ Reticulum::Reticulum() : _object(new Object()) {
Bytes buf;
if (OS::read_file(time_offset_path.c_str(), buf) == 8) {
uint64_t offset = *(uint64_t*)buf.data();
debug("Read time offset of " + std::to_string(offset) + " from file");
DEBUG("Read time offset of " + std::to_string(offset) + " from file");
OS::setTimeOffset(offset);
}
}
@@ -154,7 +154,7 @@ Reticulum::Reticulum() : _object(new Object()) {
signal.signal(signal.SIGTERM, Reticulum.sigterm_handler)
*/
mem("Reticulum default object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Reticulum default object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
/*p TODO
@@ -229,7 +229,7 @@ void Reticulum::should_persist_data() {
}
void Reticulum::persist_data() {
extreme("Persisting transport and identity data...");
TRACE("Persisting transport and identity data...");
Transport::persist_data();
Identity::persist_data();
@@ -238,7 +238,7 @@ void Reticulum::persist_data() {
try {
std::string time_offset_path = Reticulum::_storagepath + "/time_offset";
uint64_t offset = OS::ltime();
debug("Writing time offset of " + std::to_string(offset) + " to file");
DEBUG("Writing time offset of " + std::to_string(offset) + " to file");
Bytes buf((uint8_t*)&offset, sizeof(offset));
OS::write_file(time_offset_path.c_str(), buf);
}
@@ -251,7 +251,7 @@ void Reticulum::persist_data() {
}
void Reticulum::clean_caches() {
extreme("Cleaning resource and packet caches...");
TRACE("Cleaning resource and packet caches...");
double now = OS::time();
/*
@@ -295,7 +295,7 @@ void Reticulum::clean_caches() {
}
void Reticulum::clear_caches() {
extreme("Clearing resource and packet caches...");
TRACE("Clearing resource and packet caches...");
try {
std::string destination_table_path = _storagepath + "/destination_table";
+6 -6
View File
@@ -36,19 +36,19 @@ namespace RNS {
public:
Reticulum(Type::NoneConstructor none) {
mem("Reticulum NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Reticulum NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Reticulum(const Reticulum& reticulum) : _object(reticulum._object) {
mem("Reticulum object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Reticulum object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Reticulum();
virtual ~Reticulum() {
mem("Reticulum object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Reticulum object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
inline Reticulum& operator = (const Reticulum& reticulum) {
_object = reticulum._object;
mem("Reticulum object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
MEM("Reticulum object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
}
inline operator bool() const {
@@ -97,10 +97,10 @@ namespace RNS {
class Object {
public:
Object() {
mem("Reticulum data object created, this: " + std::to_string((uintptr_t)this));
MEM("Reticulum data object created, this: " + std::to_string((uintptr_t)this));
}
virtual ~Object() {
mem("Reticulum data object destroyed, this: " + std::to_string((uintptr_t)this));
MEM("Reticulum data object destroyed, this: " + std::to_string((uintptr_t)this));
}
private:
+237 -237
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -19,12 +19,12 @@ using namespace RNS::Utilities;
/*static*/ uint64_t OS::timeOffset = 0;
/*static*/ void OS::register_filesystem(Filesystem& filesystem) {
extreme("Registering filesystem...");
TRACE("Registering filesystem...");
OS::filesystem = filesystem;
}
/*static*/ void OS::deregister_filesystem() {
extreme("Deregistering filesystem...");
TRACE("Deregistering filesystem...");
OS::filesystem = {Type::NONE};
}
+28 -28
View File
@@ -122,15 +122,15 @@ namespace ArduinoJson {
if (!src) {
return dst.set(nullptr);
}
RNS::extreme("<<< Serializing interface hash " + src.get_hash().toHex());
TRACE("<<< Serializing interface hash " + src.get_hash().toHex());
return dst.set(src.get_hash().toHex());
}
static RNS::Interface fromJson(JsonVariantConst src) {
if (!src.isNull()) {
RNS::Bytes hash;
hash.assignHex(src.as<const char*>());
RNS::extreme(">>> Deserialized interface hash " + hash.toHex());
RNS::extreme(">>> Querying transport for interface");
TRACE(">>> Deserialized interface hash " + hash.toHex());
TRACE(">>> Querying transport for interface");
// Query transport for matching interface
return RNS::Transport::find_interface_from_hash(hash);
}
@@ -152,7 +152,7 @@ namespace ArduinoJson {
if (!src) {
return dst.set(nullptr);
}
RNS::extreme("<<< Serializing packet hash " + src.get_hash().toHex());
TRACE("<<< Serializing packet hash " + src.get_hash().toHex());
// Whenever a reference to a packet is serialized we must ensure that packet itself also gets serialized separately
RNS::Transport::cache_packet(src, true);
return dst.set(src.get_hash().toHex());
@@ -161,8 +161,8 @@ namespace ArduinoJson {
if (!src.isNull()) {
RNS::Bytes hash;
hash.assignHex(src.as<const char*>());
RNS::extreme(">>> Deserialized packet hash " + hash.toHex());
RNS::extreme(">>> Querying transport for cached packet");
TRACE(">>> Deserialized packet hash " + hash.toHex());
TRACE(">>> Querying transport for cached packet");
// Query transport for matching packet
return RNS::Transport::get_cached_packet(hash);
}
@@ -179,16 +179,16 @@ namespace ArduinoJson {
template <>
struct Converter<RNS::Packet> {
static bool toJson(const RNS::Packet& src, JsonVariant dst) {
RNS::extreme("<<< Serializing Packet");
TRACE("<<< Serializing Packet");
//dst["hash"] = src.get_hash();
dst["raw"] = src.raw();
dst["sent_at"] = src.sent_at();
dst["destination_hash"] = src.get_hash();
RNS::extreme("<<< Finished serializing Packet");
TRACE("<<< Finished serializing Packet");
return true;
}
static RNS::Packet fromJson(JsonVariantConst src) {
RNS::extreme(">>> Deserializing Packet");
TRACE(">>> Deserializing Packet");
RNS::Bytes raw = src["raw"];
RNS::Packet packet(
{RNS::Type::NONE},
@@ -199,7 +199,7 @@ namespace ArduinoJson {
RNS::Bytes destination_hash = src["destination_hash"];
// set cached flag since pcket was read from cache
packet.cached(true);
RNS::extreme(">>> Finished deserializing Packet");
TRACE(">>> Finished deserializing Packet");
return packet;
}
static bool checkJson(JsonVariantConst src) {
@@ -215,16 +215,16 @@ namespace ArduinoJson {
template <>
struct Converter<RNS::Transport::PacketEntry> {
static bool toJson(const RNS::Transport::PacketEntry& src, JsonVariant dst) {
RNS::extreme("<<< Serializing Transport::PacketEntry");
TRACE("<<< Serializing Transport::PacketEntry");
//dst["hash"] = src._hash;
dst["raw"] = src._raw;
dst["sent_at"] = src._sent_at;
dst["destination_hash"] = src._destination_hash;
RNS::extreme("<<< Finished serializing Transport::PacketEntry");
TRACE("<<< Finished serializing Transport::PacketEntry");
return true;
}
static RNS::Transport::PacketEntry fromJson(JsonVariantConst src) {
RNS::extreme(">>> Deserializing Transport::PacketEntry");
TRACE(">>> Deserializing Transport::PacketEntry");
RNS::Transport::PacketEntry dst;
//dst._hash = src["hash"];
dst._raw = src["raw"];
@@ -232,7 +232,7 @@ namespace ArduinoJson {
dst._destination_hash = src["destination_hash"];
// set cached flag since pcket was read from cache
dst._cached = true;
RNS::extreme(">>> Finished deserializing Transport::PacketEntry");
TRACE(">>> Finished deserializing Transport::PacketEntry");
return dst;
}
static bool checkJson(JsonVariantConst src) {
@@ -248,7 +248,7 @@ namespace ArduinoJson {
template <>
struct Converter<RNS::Transport::DestinationEntry> {
static bool toJson(const RNS::Transport::DestinationEntry& src, JsonVariant dst) {
RNS::extreme("<<< Serializing Transport::DestinationEntry");
TRACE("<<< Serializing Transport::DestinationEntry");
dst["timestamp"] = src._timestamp;
dst["received_from"] = src._received_from;
dst["announce_hops"] = src._hops;
@@ -275,7 +275,7 @@ namespace ArduinoJson {
}
}
else {
RNS::extreme("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached");
TRACE("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached");
}
}
else {
@@ -284,11 +284,11 @@ namespace ArduinoJson {
*/
dst["interface_hash"] = src._receiving_interface;
dst["packet_hash"] = src._announce_packet;
RNS::extreme("<<< Finished Serializing Transport::DestinationEntry");
TRACE("<<< Finished Serializing Transport::DestinationEntry");
return true;
}
static RNS::Transport::DestinationEntry fromJson(JsonVariantConst src) {
RNS::extreme(">>> Deserializing Transport::DestinationEntry");
TRACE(">>> Deserializing Transport::DestinationEntry");
RNS::Transport::DestinationEntry dst;
dst._timestamp = src["timestamp"];
dst._received_from = src["received_from"];
@@ -323,7 +323,7 @@ namespace ArduinoJson {
src["packet"].as<RNS::Packet>()
);
*/
RNS::extreme(">>> Finished Deserializing Transport::DestinationEntry");
TRACE(">>> Finished Deserializing Transport::DestinationEntry");
return dst;
}
static bool checkJson(JsonVariantConst src) {
@@ -356,42 +356,42 @@ namespace RNS { namespace Persistence {
if (length < size) {
_buffer.resize(length);
}
RNS::extreme("Persistence::serialize: serialized " + std::to_string(length) + " bytes");
TRACE("Persistence::serialize: serialized " + std::to_string(length) + " bytes");
if (length > 0) {
if (RNS::Utilities::OS::write_file(file_path, _buffer) == _buffer.size()) {
RNS::extreme("Persistence::serialize: wrote " + std::to_string(_buffer.size()) + " bytes");
TRACE("Persistence::serialize: wrote " + std::to_string(_buffer.size()) + " bytes");
}
else {
RNS::extreme("Persistence::serialize: write failed");
TRACE("Persistence::serialize: write failed");
return false;
}
}
else {
RNS::extreme("Persistence::serialize: failed to serialize");
TRACE("Persistence::serialize: failed to serialize");
return false;
}
return true;
}
template <typename T> bool deserialize(T& obj, const char* file_path) {
if (RNS::Utilities::OS::read_file(file_path, _buffer) > 0) {
RNS::extreme("Persistence::deserialize: read: " + std::to_string(_buffer.size()) + " bytes");
//RNS::extreme("testDeserializeVector: data: " + _buffer.toString());
TRACE("Persistence::deserialize: read: " + std::to_string(_buffer.size()) + " bytes");
//TRACE("testDeserializeVector: data: " + _buffer.toString());
#ifdef USE_MSGPACK
DeserializationError error = deserializeMsgPack(_document, _buffer.data());
#else
DeserializationError error = deserializeJson(_document, _buffer.data());
#endif
if (!error) {
RNS::extreme("Persistence::deserialize: successfully deserialized");
TRACE("Persistence::deserialize: successfully deserialized");
obj = _document.as<T>();
return true;
}
else {
RNS::extreme("Persistence::deserialize: failed to deserialize");
TRACE("Persistence::deserialize: failed to deserialize");
}
}
else {
RNS::extreme("Persistence::deserialize: read failed");
TRACE("Persistence::deserialize: read failed");
}
return false;;
}