mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-27 13:52:14 +00:00
Replace string-concatenation logging with printf-style F-variants
Converted log calls across src/, examples/, and test/ to use DEBUGF/TRACEF/ERRORF/etc. macros instead of std::string + operator+. This eliminates temporary heap allocations on every log call, which matters on memory-constrained MCUs.
This commit is contained in:
1 parent
3babdc001d
commit
79b75bbd4e
35 files changed
+595
-604
No files matched your search
+2
-2
@@ -39,8 +39,8 @@ namespace RNS {
|
||||
private:
|
||||
class Object {
|
||||
public:
|
||||
Object() { MEM("Channel::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||
virtual ~Object() { MEM("Channel::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
|
||||
Object() { MEMF("Channel::Data object created, this: %p", (void*)this); }
|
||||
virtual ~Object() { MEMF("Channel::Data object destroyed, this: %p", (void*)this); }
|
||||
private:
|
||||
|
||||
friend class Channel;
|
||||
|
||||
+15
-15
@@ -41,44 +41,44 @@ bool Fernet::verify_hmac(const Bytes& token) {
|
||||
|
||||
//received_hmac = token[-32:]
|
||||
Bytes received_hmac = token.right(32);
|
||||
DEBUG("Fernet::verify_hmac: received_hmac: " + received_hmac.toHex());
|
||||
DEBUGF("Fernet::verify_hmac: received_hmac: %s", received_hmac.toHex().c_str());
|
||||
//expected_hmac = HMAC.new(self._signing_key, token[:-32]).digest()
|
||||
Bytes expected_hmac = HMAC::generate(_signing_key, token.left(token.size()-32))->digest();
|
||||
DEBUG("Fernet::verify_hmac: expected_hmac: " + expected_hmac.toHex());
|
||||
DEBUGF("Fernet::verify_hmac: expected_hmac: %s", expected_hmac.toHex().c_str());
|
||||
|
||||
return (received_hmac == expected_hmac);
|
||||
}
|
||||
|
||||
const Bytes Fernet::encrypt(const Bytes& data) {
|
||||
|
||||
DEBUG("Fernet::encrypt: plaintext length: " + std::to_string(data.size()));
|
||||
DEBUGF("Fernet::encrypt: plaintext length: %zu", data.size());
|
||||
Bytes iv = random(16);
|
||||
//double current_time = OS::time();
|
||||
TRACE("Fernet::encrypt: iv: " + iv.toHex());
|
||||
TRACEF("Fernet::encrypt: iv: %s", iv.toHex().c_str());
|
||||
|
||||
TRACE("Fernet::encrypt: plaintext: " + data.toHex());
|
||||
TRACEF("Fernet::encrypt: plaintext: %s", data.toHex().c_str());
|
||||
Bytes ciphertext = AES_128_CBC::encrypt(
|
||||
PKCS7::pad(data),
|
||||
_encryption_key,
|
||||
iv
|
||||
);
|
||||
DEBUG("Fernet::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size()));
|
||||
TRACE("Fernet::encrypt: ciphertext: " + ciphertext.toHex());
|
||||
DEBUGF("Fernet::encrypt: padded ciphertext length: %zu", ciphertext.size());
|
||||
TRACEF("Fernet::encrypt: ciphertext: %s", ciphertext.toHex().c_str());
|
||||
|
||||
Bytes signed_parts = iv + ciphertext;
|
||||
|
||||
//return signed_parts + HMAC::generate(_signing_key, signed_parts)->digest();
|
||||
Bytes sig(HMAC::generate(_signing_key, signed_parts)->digest());
|
||||
TRACE("Fernet::encrypt: sig: " + sig.toHex());
|
||||
TRACEF("Fernet::encrypt: sig: %s", sig.toHex().c_str());
|
||||
Bytes token(signed_parts + sig);
|
||||
DEBUG("Fernet::encrypt: token length: " + std::to_string(token.size()));
|
||||
DEBUGF("Fernet::encrypt: token length: %zu", token.size());
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
const Bytes Fernet::decrypt(const Bytes& token) {
|
||||
|
||||
DEBUG("Fernet::decrypt: token length: " + std::to_string(token.size()));
|
||||
DEBUGF("Fernet::decrypt: token length: %zu", token.size());
|
||||
if (token.size() < 48) {
|
||||
throw std::invalid_argument("Cannot decrypt token of only " + std::to_string(token.size()) + " bytes");
|
||||
}
|
||||
@@ -89,11 +89,11 @@ const Bytes Fernet::decrypt(const Bytes& token) {
|
||||
|
||||
//iv = token[:16]
|
||||
Bytes iv = token.left(16);
|
||||
TRACE("Fernet::decrypt: iv: " + iv.toHex());
|
||||
TRACEF("Fernet::decrypt: iv: %s", iv.toHex().c_str());
|
||||
|
||||
//ciphertext = token[16:-32]
|
||||
Bytes ciphertext = token.mid(16, token.size()-48);
|
||||
TRACE("Fernet::decrypt: ciphertext: " + ciphertext.toHex());
|
||||
TRACEF("Fernet::decrypt: ciphertext: %s", ciphertext.toHex().c_str());
|
||||
|
||||
try {
|
||||
Bytes plaintext = PKCS7::unpad(
|
||||
@@ -103,10 +103,10 @@ const Bytes Fernet::decrypt(const Bytes& token) {
|
||||
iv
|
||||
)
|
||||
);
|
||||
DEBUG("Fernet::encrypt: unpadded plaintext length: " + std::to_string(plaintext.size()));
|
||||
TRACE("Fernet::decrypt: plaintext: " + plaintext.toHex());
|
||||
DEBUGF("Fernet::encrypt: unpadded plaintext length: %zu", plaintext.size());
|
||||
TRACEF("Fernet::decrypt: plaintext: %s", plaintext.toHex().c_str());
|
||||
|
||||
DEBUG("Fernet::decrypt: plaintext length: " + std::to_string(plaintext.size()));
|
||||
DEBUGF("Fernet::decrypt: plaintext length: %zu", plaintext.size());
|
||||
return plaintext;
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
|
||||
@@ -15,13 +15,13 @@ calls in RNS end up here.
|
||||
*/
|
||||
|
||||
const Bytes RNS::Cryptography::sha256(const Bytes& data) {
|
||||
//TRACE("Cryptography::sha256: data: " + data.toHex() );
|
||||
//TRACEF("Cryptography::sha256: data: %s", data.toHex().c_str());
|
||||
SHA256 digest;
|
||||
digest.reset();
|
||||
digest.update(data.data(), data.size());
|
||||
Bytes hash;
|
||||
digest.finalize(hash.writable(32), 32);
|
||||
//TRACE("Cryptography::sha256: hash: " + hash.toHex() );
|
||||
//TRACEF("Cryptography::sha256: hash: %s", hash.toHex().c_str());
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ const Bytes RNS::Cryptography::sha512(const Bytes& data) {
|
||||
digest.update(data.data(), data.size());
|
||||
Bytes hash;
|
||||
digest.finalize(hash.writable(64), 64);
|
||||
//TRACE("Cryptography::sha512: hash: " + hash.toHex() );
|
||||
//TRACEF("Cryptography::sha512: hash: %s", hash.toHex().c_str());
|
||||
return hash;
|
||||
}
|
||||
@@ -28,9 +28,9 @@ namespace RNS { namespace Cryptography {
|
||||
// updates passed buffer
|
||||
static inline void inplace_pad(Bytes& data, size_t bs = BLOCKSIZE) {
|
||||
size_t len = data.size();
|
||||
//DEBUG("PKCS7::pad: len: " + std::to_string(len));
|
||||
//DEBUGF("PKCS7::pad: len: %zu", len);
|
||||
size_t padlen = bs - (len % bs);
|
||||
//DEBUG("PKCS7::pad: pad len: " + std::to_string(padlen));
|
||||
//DEBUGF("PKCS7::pad: pad len: %zu", padlen);
|
||||
// create zero-filled byte padding array of size padlen
|
||||
//p v = bytes([padlen])
|
||||
//uint8_t pad[padlen] = {0};
|
||||
@@ -41,24 +41,24 @@ namespace RNS { namespace Cryptography {
|
||||
// concatenate data with padding
|
||||
//p return data+v*padlen
|
||||
data.append(pad, padlen);
|
||||
//DEBUG("PKCS7::pad: data size: " + std::to_string(data.size()));
|
||||
//DEBUGF("PKCS7::pad: data size: %zu", data.size());
|
||||
}
|
||||
|
||||
// updates passed buffer
|
||||
static inline void inplace_unpad(Bytes& data, size_t bs = BLOCKSIZE) {
|
||||
size_t len = data.size();
|
||||
//DEBUG("PKCS7::unpad: len: " + std::to_string(len));
|
||||
//DEBUGF("PKCS7::unpad: len: %zu", len);
|
||||
// read last byte which is pad length
|
||||
//pad = data[-1]
|
||||
size_t padlen = (size_t)data.data()[data.size()-1];
|
||||
//DEBUG("PKCS7::unpad: pad len: " + std::to_string(padlen));
|
||||
//DEBUGF("PKCS7::unpad: pad len: %zu", padlen);
|
||||
if (padlen > bs) {
|
||||
throw std::runtime_error("Cannot unpad, invalid padding length of " + std::to_string(padlen) + " bytes");
|
||||
}
|
||||
// truncate data to strip padding
|
||||
//return data[:len-padlen]
|
||||
data.resize(len - padlen);
|
||||
//DEBUG("PKCS7::unpad: data size: " + std::to_string(data.size()));
|
||||
//DEBUGF("PKCS7::unpad: data size: %zu", data.size());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+15
-15
@@ -56,22 +56,22 @@ bool Token::verify_hmac(const Bytes& token) {
|
||||
|
||||
//received_hmac = token[-32:]
|
||||
Bytes received_hmac = token.right(32);
|
||||
DEBUG("Token::verify_hmac: received_hmac: " + received_hmac.toHex());
|
||||
DEBUGF("Token::verify_hmac: received_hmac: %s", received_hmac.toHex().c_str());
|
||||
//expected_hmac = HMAC.new(self._signing_key, token[:-32]).digest()
|
||||
Bytes expected_hmac = HMAC::generate(_signing_key, token.left(token.size()-32))->digest();
|
||||
DEBUG("Token::verify_hmac: expected_hmac: " + expected_hmac.toHex());
|
||||
DEBUGF("Token::verify_hmac: expected_hmac: %s", expected_hmac.toHex().c_str());
|
||||
|
||||
return (received_hmac == expected_hmac);
|
||||
}
|
||||
|
||||
const Bytes Token::encrypt(const Bytes& data) {
|
||||
|
||||
DEBUG("Token::encrypt: plaintext length: " + std::to_string(data.size()));
|
||||
DEBUGF("Token::encrypt: plaintext length: %zu", data.size());
|
||||
Bytes iv = random(16);
|
||||
//double current_time = OS::time();
|
||||
TRACE("Token::encrypt: iv: " + iv.toHex());
|
||||
TRACEF("Token::encrypt: iv: %s", iv.toHex().c_str());
|
||||
|
||||
TRACE("Token::encrypt: plaintext: " + data.toHex());
|
||||
TRACEF("Token::encrypt: plaintext: %s", data.toHex().c_str());
|
||||
Bytes ciphertext;
|
||||
if (_mode == MODE_AES_128_CBC) {
|
||||
ciphertext = AES_128_CBC::encrypt(
|
||||
@@ -90,23 +90,23 @@ const Bytes Token::encrypt(const Bytes& data) {
|
||||
else {
|
||||
throw new std::invalid_argument("Invalid token mode "+std::to_string(_mode));
|
||||
}
|
||||
DEBUG("Token::encrypt: padded ciphertext length: " + std::to_string(ciphertext.size()));
|
||||
TRACE("Token::encrypt: ciphertext: " + ciphertext.toHex());
|
||||
DEBUGF("Token::encrypt: padded ciphertext length: %zu", ciphertext.size());
|
||||
TRACEF("Token::encrypt: ciphertext: %s", ciphertext.toHex().c_str());
|
||||
|
||||
Bytes signed_parts = iv + ciphertext;
|
||||
|
||||
//return signed_parts + HMAC::generate(_signing_key, signed_parts)->digest();
|
||||
Bytes sig(HMAC::generate(_signing_key, signed_parts)->digest());
|
||||
TRACE("Token::encrypt: sig: " + sig.toHex());
|
||||
TRACEF("Token::encrypt: sig: %s", sig.toHex().c_str());
|
||||
Bytes token(signed_parts + sig);
|
||||
DEBUG("Token::encrypt: token length: " + std::to_string(token.size()));
|
||||
DEBUGF("Token::encrypt: token length: %zu", token.size());
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
const Bytes Token::decrypt(const Bytes& token) {
|
||||
|
||||
DEBUG("Token::decrypt: token length: " + std::to_string(token.size()));
|
||||
DEBUGF("Token::decrypt: token length: %zu", token.size());
|
||||
if (token.size() < 48) {
|
||||
throw std::invalid_argument("Cannot decrypt token of only " + std::to_string(token.size()) + " bytes");
|
||||
}
|
||||
@@ -117,11 +117,11 @@ const Bytes Token::decrypt(const Bytes& token) {
|
||||
|
||||
//iv = token[:16]
|
||||
Bytes iv = token.left(16);
|
||||
TRACE("Token::decrypt: iv: " + iv.toHex());
|
||||
TRACEF("Token::decrypt: iv: %s", iv.toHex().c_str());
|
||||
|
||||
//ciphertext = token[16:-32]
|
||||
Bytes ciphertext = token.mid(16, token.size()-48);
|
||||
TRACE("Token::decrypt: ciphertext: " + ciphertext.toHex());
|
||||
TRACEF("Token::decrypt: ciphertext: %s", ciphertext.toHex().c_str());
|
||||
|
||||
try {
|
||||
Bytes plaintext;
|
||||
@@ -146,10 +146,10 @@ const Bytes Token::decrypt(const Bytes& token) {
|
||||
else {
|
||||
throw new std::invalid_argument("Invalid token mode "+std::to_string(_mode));
|
||||
}
|
||||
DEBUG("Token::encrypt: unpadded plaintext length: " + std::to_string(plaintext.size()));
|
||||
TRACE("Token::decrypt: plaintext: " + plaintext.toHex());
|
||||
DEBUGF("Token::encrypt: unpadded plaintext length: %zu", plaintext.size());
|
||||
TRACEF("Token::decrypt: plaintext: %s", plaintext.toHex().c_str());
|
||||
|
||||
DEBUG("Token::decrypt: plaintext length: " + std::to_string(plaintext.size()));
|
||||
DEBUGF("Token::decrypt: plaintext length: %zu", plaintext.size());
|
||||
return plaintext;
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
|
||||
+10
-10
@@ -170,26 +170,26 @@ namespace RNS { namespace Cryptography {
|
||||
}
|
||||
*/
|
||||
inline const Bytes exchange(const Bytes& peer_public_key) {
|
||||
DEBUG("X25519PublicKey::exchange: public key: " + _publicKey.toHex());
|
||||
DEBUG("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex());
|
||||
DEBUG("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex());
|
||||
DEBUGF("X25519PublicKey::exchange: public key: %s", _publicKey.toHex().c_str());
|
||||
DEBUGF("X25519PublicKey::exchange: peer public key: %s", peer_public_key.toHex().c_str());
|
||||
DEBUGF("X25519PublicKey::exchange: pre private key: %s", _privateKey.toHex().c_str());
|
||||
Bytes sharedKey;
|
||||
if (!Curve25519::eval(sharedKey.writable(32), _privateKey.data(), peer_public_key.data())) {
|
||||
throw std::runtime_error("Peer key is invalid");
|
||||
}
|
||||
DEBUG("X25519PublicKey::exchange: shared key: " + sharedKey.toHex());
|
||||
DEBUG("X25519PublicKey::exchange: post private key: " + _privateKey.toHex());
|
||||
DEBUGF("X25519PublicKey::exchange: shared key: %s", sharedKey.toHex().c_str());
|
||||
DEBUGF("X25519PublicKey::exchange: post private key: %s", _privateKey.toHex().c_str());
|
||||
return sharedKey;
|
||||
}
|
||||
|
||||
inline bool verify(const Bytes& peer_public_key) {
|
||||
DEBUG("X25519PublicKey::exchange: public key: " + _publicKey.toHex());
|
||||
DEBUG("X25519PublicKey::exchange: peer public key: " + peer_public_key.toHex());
|
||||
DEBUG("X25519PublicKey::exchange: pre private key: " + _privateKey.toHex());
|
||||
DEBUGF("X25519PublicKey::exchange: public key: %s", _publicKey.toHex().c_str());
|
||||
DEBUGF("X25519PublicKey::exchange: peer public key: %s", peer_public_key.toHex().c_str());
|
||||
DEBUGF("X25519PublicKey::exchange: pre private key: %s", _privateKey.toHex().c_str());
|
||||
Bytes sharedKey(peer_public_key);
|
||||
bool success = Curve25519::dh2(sharedKey.writable(32), _privateKey.writable(32));
|
||||
DEBUG("X25519PublicKey::exchange: shared key: " + sharedKey.toHex());
|
||||
DEBUG("X25519PublicKey::exchange: post private key: " + _privateKey.toHex());
|
||||
DEBUGF("X25519PublicKey::exchange: shared key: %s", sharedKey.toHex().c_str());
|
||||
DEBUGF("X25519PublicKey::exchange: post private key: %s", _privateKey.toHex().c_str());
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
+32
-32
@@ -15,13 +15,13 @@ using namespace RNS::Utilities;
|
||||
|
||||
Destination::Destination(const Identity& identity, const directions direction, const types type, const char* app_name, const char* aspects) : _object(new Object(identity)) {
|
||||
assert(_object);
|
||||
MEM("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Destination object creating..., this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
|
||||
// Check input values and build name string
|
||||
if (strchr(app_name, '.') != nullptr) {
|
||||
throw std::invalid_argument("Dots can't be used in app names");
|
||||
}
|
||||
//TRACE("Destination::Destination: app name: " + std::string(app_name));
|
||||
//TRACEF("Destination::Destination: app name: %s", app_name);
|
||||
|
||||
_object->_type = type;
|
||||
_object->_direction = direction;
|
||||
@@ -33,34 +33,34 @@ Destination::Destination(const Identity& identity, const directions direction, c
|
||||
// CBA TODO determine why identity.hexhash is added both here and by expand_name called below
|
||||
fullaspects += "." + _object->_identity.hexhash();
|
||||
}
|
||||
//TRACE("Destination::Destination: full aspects: " + fullaspects);
|
||||
//TRACEF("Destination::Destination: full aspects: %s", fullaspects.c_str());
|
||||
|
||||
if (_object->_identity && _object->_type == PLAIN) {
|
||||
throw std::invalid_argument("Selected destination type PLAIN cannot hold an identity");
|
||||
}
|
||||
|
||||
_object->_name = expand_name(_object->_identity, app_name, fullaspects.c_str());
|
||||
//TRACE("Destination::Destination: name: " + _object->_name);
|
||||
//TRACEF("Destination::Destination: name: %s", _object->_name.c_str());
|
||||
|
||||
// Generate the destination address hash
|
||||
//TRACE("Destination::Destination: creating hash...");
|
||||
_object->_hash = hash(_object->_identity, app_name, fullaspects.c_str());
|
||||
_object->_hexhash = _object->_hash.toHex();
|
||||
TRACE("Destination::Destination: hash: " + _object->_hash.toHex());
|
||||
TRACEF("Destination::Destination: hash: %s", _object->_hash.toHex().c_str());
|
||||
//TRACE("Destination::Destination: creating name hash...");
|
||||
//p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
|
||||
_object->_name_hash = name_hash(app_name, aspects);
|
||||
//TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex());
|
||||
//TRACEF("Destination::Destination: name hash: %s", _object->_name_hash.toHex().c_str());
|
||||
|
||||
//TRACE("Destination::Destination: calling register_destination");
|
||||
Transport::register_destination(*this);
|
||||
|
||||
MEM("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Destination object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
Destination::Destination(const Identity& identity, const Type::Destination::directions direction, const Type::Destination::types type, const Bytes& hash) : _object(new Object(identity)) {
|
||||
assert(_object);
|
||||
MEM("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Destination object creating..., this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
|
||||
_object->_type = type;
|
||||
_object->_direction = direction;
|
||||
@@ -71,20 +71,20 @@ Destination::Destination(const Identity& identity, const Type::Destination::dire
|
||||
|
||||
_object->_hash = hash;
|
||||
_object->_hexhash = _object->_hash.toHex();
|
||||
TRACE("Destination::Destination: hash: " + _object->_hash.toHex());
|
||||
TRACEF("Destination::Destination: hash: %s", _object->_hash.toHex().c_str());
|
||||
//TRACE("Destination::Destination: creating name hash...");
|
||||
//p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
|
||||
_object->_name_hash = name_hash("unknown", "unknown");
|
||||
//TRACE("Destination::Destination: name hash: " + _object->_name_hash.toHex());
|
||||
//TRACEF("Destination::Destination: name hash: %s", _object->_name_hash.toHex().c_str());
|
||||
|
||||
//TRACE("Destination::Destination: calling register_destination");
|
||||
Transport::register_destination(*this);
|
||||
|
||||
MEM("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Destination object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
/*virtual*/ Destination::~Destination() {
|
||||
MEM("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Destination object destroyed, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
if (_object && _object.use_count() == 1) {
|
||||
MEM("Destination object has last data reference");
|
||||
|
||||
@@ -225,12 +225,12 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
|
||||
if (!tag.empty()) {
|
||||
TRACE("Destination::announce: tag is specified");
|
||||
std::string tagstr((const char*)tag.data(), tag.size());
|
||||
DEBUG(std::string("Destination::announce: tag: ") + tagstr);
|
||||
DEBUG(std::string("Destination::announce: tag len: ") + std::to_string(tag.size()));
|
||||
DEBUGF("Destination::announce: tag: %s", tagstr.c_str());
|
||||
DEBUGF("Destination::announce: tag len: %zu", tag.size());
|
||||
TRACE("Destination::announce: searching for tag...");
|
||||
if (_object->_path_responses.find(tag) != _object->_path_responses.end()) {
|
||||
TRACE("Destination::announce: found tag in _path_responses");
|
||||
DEBUG(std::string("Destination::announce: data: ") +_object->_path_responses[tag].second.toString());
|
||||
DEBUGF("Destination::announce: data: %s", _object->_path_responses[tag].second.toString().c_str());
|
||||
}
|
||||
else {
|
||||
TRACE("Destination::announce: tag not found in _path_responses");
|
||||
@@ -248,7 +248,7 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
|
||||
// received via multiple paths. The difference in reception time will
|
||||
// potentially also be useful in determining characteristics of the
|
||||
// multiple available paths, and to choose the best one.
|
||||
//z TRACE("Using cached announce data for answering path request with tag "+RNS.prettyhexrep(tag));
|
||||
//z TRACEF("Using cached announce data for answering path request with tag %s", RNS.prettyhexrep(tag).c_str());
|
||||
announce_data << _object->_path_responses[tag].second;
|
||||
}
|
||||
else {
|
||||
@@ -263,20 +263,20 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
|
||||
}
|
||||
|
||||
Bytes signed_data;
|
||||
//TRACE("Destination::announce: hash: " + _object->_hash.toHex());
|
||||
//TRACE("Destination::announce: public key: " + _object->_identity.get_public_key().toHex());
|
||||
//TRACE("Destination::announce: name hash: " + _object->_name_hash.toHex());
|
||||
//TRACE("Destination::announce: random hash: " + random_hash.toHex());
|
||||
//TRACE("Destination::announce: app data: " + new_app_data.toHex());
|
||||
//TRACE("Destination::announce: app data text:" + new_app_data.toString());
|
||||
//TRACEF("Destination::announce: hash: %s", _object->_hash.toHex().c_str());
|
||||
//TRACEF("Destination::announce: public key: %s", _object->_identity.get_public_key().toHex().c_str());
|
||||
//TRACEF("Destination::announce: name hash: %s", _object->_name_hash.toHex().c_str());
|
||||
//TRACEF("Destination::announce: random hash: %s", random_hash.toHex().c_str());
|
||||
//TRACEF("Destination::announce: app data: %s", new_app_data.toHex().c_str());
|
||||
//TRACEF("Destination::announce: app data text:%s", new_app_data.toString().c_str());
|
||||
signed_data << _object->_hash << _object->_identity.get_public_key() << _object->_name_hash << random_hash;
|
||||
if (new_app_data) {
|
||||
signed_data << new_app_data;
|
||||
}
|
||||
//TRACE("Destination::announce: signed data: " + signed_data.toHex());
|
||||
//TRACEF("Destination::announce: signed data: %s", signed_data.toHex().c_str());
|
||||
|
||||
Bytes signature(_object->_identity.sign(signed_data));
|
||||
//TRACE("Destination::announce: signature: " + signature.toHex());
|
||||
//TRACEF("Destination::announce: signature: %s", signature.toHex().c_str());
|
||||
|
||||
announce_data << _object->_identity.get_public_key() << _object->_name_hash << random_hash << signature;
|
||||
|
||||
@@ -289,13 +289,13 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
|
||||
_object->_path_responses.insert({tag, {OS::time(), announce_data}});
|
||||
}
|
||||
catch (const std::bad_alloc&) {
|
||||
ERROR("announce: bad_alloc - out of memory, path response not stored for " + _object->_hash.toHex());
|
||||
ERRORF("announce: bad_alloc - out of memory, path response not stored for %s", _object->_hash.toHex().c_str());
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("announce: exception storing path response: ") + e.what());
|
||||
ERRORF("announce: exception storing path response: %s", e.what());
|
||||
}
|
||||
}
|
||||
//TRACE("Destination::announce: announce_data:" + announce_data.toHex());
|
||||
//TRACEF("Destination::announce: announce_data:%s", announce_data.toHex().c_str());
|
||||
|
||||
Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE;
|
||||
if (path_response) {
|
||||
@@ -317,11 +317,11 @@ Packet Destination::announce(const Bytes& app_data, bool path_response, const In
|
||||
}
|
||||
}
|
||||
catch (const std::bad_alloc&) {
|
||||
ERROR("announce: bad_alloc - out of memory, announce not sent for " + _object->_hash.toHex());
|
||||
ERRORF("announce: bad_alloc - out of memory, announce not sent for %s", _object->_hash.toHex().c_str());
|
||||
return {Type::NONE};
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("announce: exception during announce: ") + e.what());
|
||||
ERRORF("announce: exception during announce: %s", e.what());
|
||||
return {Type::NONE};
|
||||
}
|
||||
}
|
||||
@@ -381,7 +381,7 @@ void Destination::receive(const Packet& packet) {
|
||||
else {
|
||||
// CBA TODO Why isn't the Packet decrypting itself?
|
||||
Bytes plaintext(decrypt(packet.data()));
|
||||
//TRACE("Destination::receive: decrypted data: " + plaintext.toHex());
|
||||
//TRACEF("Destination::receive: decrypted data: %s", plaintext.toHex().c_str());
|
||||
if (plaintext) {
|
||||
if (packet.packet_type() == Type::Packet::DATA) {
|
||||
if (_object->_callbacks._packet) {
|
||||
@@ -389,7 +389,7 @@ void Destination::receive(const Packet& packet) {
|
||||
_object->_callbacks._packet(plaintext, packet);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
DEBUG("Error while executing receive callback from " + toString() + ". The contained exception was: " + e.what());
|
||||
DEBUGF("Error while executing receive callback from %s. The contained exception was: %s", toString().c_str(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -410,7 +410,7 @@ TRACE("***** Accepting link request");
|
||||
ERROR("incoming_link_request: bad_alloc - out of memory, link not tracked");
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("incoming_link_request: exception tracking link: ") + e.what());
|
||||
ERRORF("incoming_link_request: exception tracking link: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -73,10 +73,10 @@ namespace RNS {
|
||||
|
||||
public:
|
||||
Destination(Type::NoneConstructor none) {
|
||||
MEM("Destination NONE object created, this: " + std::to_string((uintptr_t)this));
|
||||
MEMF("Destination NONE object created, this: %p", (void*)this);
|
||||
}
|
||||
Destination(const Destination& destination) : _object(destination._object) {
|
||||
MEM("Destination object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Destination object copy created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
Destination(
|
||||
const Identity& identity,
|
||||
@@ -95,7 +95,7 @@ namespace RNS {
|
||||
|
||||
inline Destination& operator = (const Destination& destination) {
|
||||
_object = destination._object;
|
||||
MEM("Destination object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Destination object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
return *this;
|
||||
}
|
||||
inline operator bool() const {
|
||||
@@ -212,8 +212,8 @@ namespace RNS {
|
||||
private:
|
||||
class Object {
|
||||
public:
|
||||
Object(const Identity& identity) : _identity(identity) { MEM("Destination::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||
virtual ~Object() { MEM("Destination::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
|
||||
Object(const Identity& identity) : _identity(identity) { MEMF("Destination::Data object created, this: %p", (void*)this); }
|
||||
virtual ~Object() { MEMF("Destination::Data object destroyed, this: %p", (void*)this); }
|
||||
private:
|
||||
bool _accept_link_requests = true;
|
||||
Callbacks _callbacks;
|
||||
|
||||
+61
-61
@@ -33,7 +33,7 @@ Identity::Identity(bool create_keys /*= true*/) : _object(new Object()) {
|
||||
if (create_keys) {
|
||||
createKeys();
|
||||
}
|
||||
MEM("Identity object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Identity object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
void Identity::createKeys() {
|
||||
@@ -42,26 +42,26 @@ void Identity::createKeys() {
|
||||
// CRYPTO: create encryption private keys
|
||||
_object->_prv = Cryptography::X25519PrivateKey::generate();
|
||||
_object->_prv_bytes = _object->_prv->private_bytes();
|
||||
//TRACE("Identity::createKeys: prv bytes: " + _object->_prv_bytes.toHex());
|
||||
//TRACEF("Identity::createKeys: prv bytes: %s", _object->_prv_bytes.toHex().c_str());
|
||||
|
||||
// CRYPTO: create signature private keys
|
||||
_object->_sig_prv = Cryptography::Ed25519PrivateKey::generate();
|
||||
_object->_sig_prv_bytes = _object->_sig_prv->private_bytes();
|
||||
//TRACE("Identity::createKeys: sig prv bytes: " + _object->_sig_prv_bytes.toHex());
|
||||
//TRACEF("Identity::createKeys: sig prv bytes: %s", _object->_sig_prv_bytes.toHex().c_str());
|
||||
|
||||
// CRYPTO: create encryption public keys
|
||||
_object->_pub = _object->_prv->public_key();
|
||||
_object->_pub_bytes = _object->_pub->public_bytes();
|
||||
//TRACE("Identity::createKeys: pub bytes: " + _object->_pub_bytes.toHex());
|
||||
//TRACEF("Identity::createKeys: pub bytes: %s", _object->_pub_bytes.toHex().c_str());
|
||||
|
||||
// CRYPTO: create signature public keys
|
||||
_object->_sig_pub = _object->_sig_prv->public_key();
|
||||
_object->_sig_pub_bytes = _object->_sig_pub->public_bytes();
|
||||
//TRACE("Identity::createKeys: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
|
||||
//TRACEF("Identity::createKeys: sig pub bytes: %s", _object->_sig_pub_bytes.toHex().c_str());
|
||||
|
||||
update_hashes();
|
||||
|
||||
VERBOSE("Identity keys created for " + _object->_hash.toHex());
|
||||
VERBOSEF("Identity keys created for %s", _object->_hash.toHex().c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -78,20 +78,20 @@ bool Identity::load_private_key(const Bytes& prv_bytes) {
|
||||
//p self.prv_bytes = prv_bytes[:Identity.KEYSIZE//8//2]
|
||||
_object->_prv_bytes = prv_bytes.left(Type::Identity::KEYSIZE/8/2);
|
||||
_object->_prv = X25519PrivateKey::from_private_bytes(_object->_prv_bytes);
|
||||
//TRACE("Identity::load_private_key: prv bytes: " + _object->_prv_bytes.toHex());
|
||||
//TRACEF("Identity::load_private_key: prv bytes: %s", _object->_prv_bytes.toHex().c_str());
|
||||
|
||||
//p self.sig_prv_bytes = prv_bytes[Identity.KEYSIZE//8//2:]
|
||||
_object->_sig_prv_bytes = prv_bytes.mid(Type::Identity::KEYSIZE/8/2);
|
||||
_object->_sig_prv = Ed25519PrivateKey::from_private_bytes(_object->_sig_prv_bytes);
|
||||
//TRACE("Identity::load_private_key: sig prv bytes: " + _object->_sig_prv_bytes.toHex());
|
||||
//TRACEF("Identity::load_private_key: sig prv bytes: %s", _object->_sig_prv_bytes.toHex().c_str());
|
||||
|
||||
_object->_pub = _object->_prv->public_key();
|
||||
_object->_pub_bytes = _object->_pub->public_bytes();
|
||||
//TRACE("Identity::load_private_key: pub bytes: " + _object->_pub_bytes.toHex());
|
||||
//TRACEF("Identity::load_private_key: pub bytes: %s", _object->_pub_bytes.toHex().c_str());
|
||||
|
||||
_object->_sig_pub = _object->_sig_prv->public_key();
|
||||
_object->_sig_pub_bytes = _object->_sig_pub->public_bytes();
|
||||
//TRACE("Identity::load_private_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
|
||||
//TRACEF("Identity::load_private_key: sig pub bytes: %s", _object->_sig_pub_bytes.toHex().c_str());
|
||||
|
||||
update_hashes();
|
||||
|
||||
@@ -118,11 +118,11 @@ void Identity::load_public_key(const Bytes& pub_bytes) {
|
||||
|
||||
//_pub_bytes = pub_bytes[:Identity.KEYSIZE//8//2]
|
||||
_object->_pub_bytes = pub_bytes.left(Type::Identity::KEYSIZE/8/2);
|
||||
//TRACE("Identity::load_public_key: pub bytes: " + _object->_pub_bytes.toHex());
|
||||
//TRACEF("Identity::load_public_key: pub bytes: ", _object->_pub_bytes.toHex().c_str());
|
||||
|
||||
//_sig_pub_bytes = pub_bytes[Identity.KEYSIZE//8//2:]
|
||||
_object->_sig_pub_bytes = pub_bytes.mid(Type::Identity::KEYSIZE/8/2);
|
||||
//TRACE("Identity::load_public_key: sig pub bytes: " + _object->_sig_pub_bytes.toHex());
|
||||
//TRACEF("Identity::load_public_key: sig pub bytes: ", _object->_sig_pub_bytes.toHex().c_str());
|
||||
|
||||
_object->_pub = X25519PublicKey::from_public_bytes(_object->_pub_bytes);
|
||||
_object->_sig_pub = Ed25519PublicKey::from_public_bytes(_object->_sig_pub_bytes);
|
||||
@@ -147,7 +147,7 @@ bool Identity::load(const char* path) {
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERROR("Error while loading identity from " + std::string(path));
|
||||
ERRORF("Error while loading identity from %s", path);
|
||||
ERRORF("The contained exception was: %s", e.what());
|
||||
}
|
||||
#endif
|
||||
@@ -205,10 +205,10 @@ Can be used to load previously created and saved identities into Reticulum.
|
||||
cull_known_destinations();
|
||||
}
|
||||
catch (const std::bad_alloc&) {
|
||||
ERROR("remember: bad_alloc - out of memory, identity not stored for " + destination_hash.toHex());
|
||||
ERRORF("remember: bad_alloc - out of memory, identity not stored for %s", destination_hash.toHex().c_str());
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("remember: exception storing identity: ") + e.what());
|
||||
ERRORF("remember: exception storing identity: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ Recall identity for a destination hash.
|
||||
TRACE("Identity::recall...");
|
||||
auto iter = _known_destinations.find(destination_hash);
|
||||
if (iter != _known_destinations.end()) {
|
||||
TRACE("Identity::recall: Found identity entry for destination " + destination_hash.toHex());
|
||||
TRACEF("Identity::recall: Found identity entry for destination %s", destination_hash.toHex().c_str());
|
||||
const IdentityEntry& identity_data = (*iter).second;
|
||||
Identity identity(false);
|
||||
identity.load_public_key(identity_data._public_key);
|
||||
@@ -231,16 +231,16 @@ Recall identity for a destination hash.
|
||||
return identity;
|
||||
}
|
||||
else {
|
||||
TRACE("Identity::recall: Unable to find identity entry for destination " + destination_hash.toHex() + ", performing destination lookup...");
|
||||
TRACEF("Identity::recall: Unable to find identity entry for destination %s, performing destination lookup...", destination_hash.toHex().c_str());
|
||||
Destination registered_destination(Transport::find_destination_from_hash(destination_hash));
|
||||
if (registered_destination) {
|
||||
TRACE("Identity::recall: Found destination " + destination_hash.toHex());
|
||||
TRACEF("Identity::recall: Found destination %s", destination_hash.toHex().c_str());
|
||||
Identity identity(false);
|
||||
identity.load_public_key(registered_destination.identity().get_public_key());
|
||||
identity.app_data({Bytes::NONE});
|
||||
return identity;
|
||||
}
|
||||
TRACE("Identity::recall: Unable to find destination " + destination_hash.toHex());
|
||||
TRACEF("Identity::recall: Unable to find destination %s", destination_hash.toHex().c_str());
|
||||
return {Type::NONE};
|
||||
}
|
||||
}
|
||||
@@ -255,12 +255,12 @@ Recall last heard app_data for a destination hash.
|
||||
TRACE("Identity::recall_app_data...");
|
||||
auto iter = _known_destinations.find(destination_hash);
|
||||
if (iter != _known_destinations.end()) {
|
||||
TRACE("Identity::recall_app_data: Found identity entry for destination " + destination_hash.toHex());
|
||||
TRACEF("Identity::recall_app_data: Found identity entry for destination %s", destination_hash.toHex().c_str());
|
||||
const IdentityEntry& identity_data = (*iter).second;
|
||||
return identity_data._app_data;
|
||||
}
|
||||
else {
|
||||
TRACE("Identity::recall_app_data: Unable to find identity entry for destination " + destination_hash.toHex());
|
||||
TRACEF("Identity::recall_app_data: Unable to find identity entry for destination %s", destination_hash.toHex().c_str());
|
||||
return {Bytes::NONE};
|
||||
}
|
||||
}
|
||||
@@ -315,7 +315,7 @@ Recall last heard app_data for a destination hash.
|
||||
|
||||
// TODO
|
||||
/*
|
||||
DEBUG("Saving " + std::to_string(_known_destinations.size()) + " known destinations to storage...");
|
||||
DEBUGF("Saving %zu known destinations to storage...", _known_destinations.size());
|
||||
file = open(RNS.Reticulum.storagepath+"/known_destinations","wb")
|
||||
umsgpack.dump(Identity.known_destinations, file)
|
||||
file.close()
|
||||
@@ -330,7 +330,7 @@ Recall last heard app_data for a destination hash.
|
||||
time_str = std::to_string(OS::round(save_time, 1)) + " s";
|
||||
}
|
||||
|
||||
DEBUG("Saved known destinations to storage in " + time_str);
|
||||
DEBUGF("Saved known destinations to storage in %s", time_str.c_str());
|
||||
|
||||
success = true;
|
||||
}
|
||||
@@ -382,16 +382,16 @@ Recall last heard app_data for a destination hash.
|
||||
|
||||
uint16_t count = 0;
|
||||
for (const auto& [timestamp, destination_hash] : sorted_keys) {
|
||||
TRACE("Identity::cull_known_destinations: Removing destination " + destination_hash.toHex() + " from known destinations");
|
||||
TRACEF("Identity::cull_known_destinations: Removing destination %s from known destinations", destination_hash.toHex().c_str());
|
||||
if (_known_destinations.erase(destination_hash) < 1) {
|
||||
WARNING("Failed to remove destination " + destination_hash.toHex() + " from known destinations");
|
||||
WARNINGF("Failed to remove destination %s from known destinations", destination_hash.toHex().c_str());
|
||||
}
|
||||
++count;
|
||||
if (_known_destinations.size() <= _known_destinations_maxsize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DEBUG("Removed " + std::to_string(count) + " path(s) from known destinations");
|
||||
DEBUGF("Removed %d path(s) from known destinations", count);
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
ERROR("cull_known_destinations: bad_alloc - out of memory building sort index, falling back to single erase");
|
||||
@@ -408,7 +408,7 @@ Recall last heard app_data for a destination hash.
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("cull_known_destinations: exception: ") + e.what());
|
||||
ERRORF("cull_known_destinations: exception: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,25 +417,25 @@ Recall last heard app_data for a destination hash.
|
||||
try {
|
||||
if (packet.packet_type() == Type::Packet::ANNOUNCE) {
|
||||
Bytes destination_hash = packet.destination_hash();
|
||||
//TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex());
|
||||
//TRACEF("Identity::validate_announce: destination_hash: %s", packet.destination_hash().toHex().c_str());
|
||||
Bytes public_key = packet.data().left(KEYSIZE/8);
|
||||
//TRACE("Identity::validate_announce: public_key: " + public_key.toHex());
|
||||
//TRACEF("Identity::validate_announce: public_key: %s", public_key.toHex().c_str());
|
||||
Bytes name_hash = packet.data().mid(KEYSIZE/8, NAME_HASH_LENGTH/8);
|
||||
//TRACE("Identity::validate_announce: name_hash: " + name_hash.toHex());
|
||||
//TRACEF("Identity::validate_announce: name_hash: %s", name_hash.toHex().c_str());
|
||||
Bytes random_hash = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8, RANDOM_HASH_LENGTH/8);
|
||||
//TRACE("Identity::validate_announce: random_hash: " + random_hash.toHex());
|
||||
//TRACEF("Identity::validate_announce: random_hash: %s", random_hash.toHex().c_str());
|
||||
Bytes signature = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8, SIGLENGTH/8);
|
||||
//TRACE("Identity::validate_announce: signature: " + signature.toHex());
|
||||
//TRACEF("Identity::validate_announce: signature: %s", signature.toHex().c_str());
|
||||
Bytes app_data;
|
||||
if (packet.data().size() > (KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8)) {
|
||||
app_data = packet.data().mid(KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8);
|
||||
}
|
||||
//TRACE("Identity::validate_announce: app_data: " + app_data.toHex());
|
||||
//TRACE("Identity::validate_announce: app_data text: " + app_data.toString());
|
||||
//TRACEF("Identity::validate_announce: app_data: %s", app_data.toHex().c_str());
|
||||
//TRACEF("Identity::validate_announce: app_data text: %s", app_data.toString().c_str());
|
||||
|
||||
Bytes signed_data;
|
||||
signed_data << packet.destination_hash() << public_key << name_hash << random_hash+app_data;
|
||||
//TRACE("Identity::validate_announce: signed_data: " + signed_data.toHex());
|
||||
//TRACEF("Identity::validate_announce: signed_data: %s", signed_data.toHex().c_str());
|
||||
|
||||
if (packet.data().size() <= KEYSIZE/8 + NAME_HASH_LENGTH/8 + RANDOM_HASH_LENGTH/8 + SIGLENGTH/8) {
|
||||
app_data.clear();
|
||||
@@ -447,8 +447,8 @@ Recall last heard app_data for a destination hash.
|
||||
if (announced_identity.pub() && announced_identity.validate(signature, signed_data)) {
|
||||
Bytes hash_material = name_hash << announced_identity.hash();
|
||||
Bytes expected_hash = full_hash(hash_material).left(Type::Reticulum::TRUNCATED_HASHLENGTH/8);
|
||||
//TRACE("Identity::validate_announce: destination_hash: " + packet.destination_hash().toHex());
|
||||
//TRACE("Identity::validate_announce: expected_hash: " + expected_hash.toHex());
|
||||
//TRACEF("Identity::validate_announce: destination_hash: %s", packet.destination_hash().toHex().c_str());
|
||||
//TRACEF("Identity::validate_announce: expected_hash: %s", expected_hash.toHex().c_str());
|
||||
|
||||
if (packet.destination_hash() == expected_hash) {
|
||||
// Check if we already have a public key for this destination
|
||||
@@ -485,28 +485,28 @@ Recall last heard app_data for a destination hash.
|
||||
*/
|
||||
|
||||
if (packet.transport_id()) {
|
||||
TRACE("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received via " + packet.transport_id().toHex() + " on " + packet.receiving_interface().toString() + signal_str);
|
||||
TRACEF("Valid announce for %s %d hops away, received via %s on %s%s", packet.destination_hash().toHex().c_str(), packet.hops(), packet.transport_id().toHex().c_str(), packet.receiving_interface().toString().c_str(), signal_str.c_str());
|
||||
}
|
||||
else {
|
||||
TRACE("Valid announce for " + packet.destination_hash().toHex() + " " + std::to_string(packet.hops()) + " hops away, received on " + packet.receiving_interface().toString() + signal_str);
|
||||
TRACEF("Valid announce for %s %d hops away, received on %s%s", packet.destination_hash().toHex().c_str(), packet.hops(), packet.receiving_interface().toString().c_str(), signal_str.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Destination mismatch.");
|
||||
DEBUGF("Received invalid announce for %s: Destination mismatch.", packet.destination_hash().toHex().c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUG("Received invalid announce for " + packet.destination_hash().toHex() + ": Invalid signature.");
|
||||
DEBUGF("Received invalid announce for %s: Invalid signature.", packet.destination_hash().toHex().c_str());
|
||||
//p del announced_identity
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERROR("Error occurred while validating announce. The contained exception was: " + std::string(e.what()));
|
||||
ERRORF("Error occurred while validating announce. The contained exception was: %s", e.what());
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -537,12 +537,12 @@ const Bytes Identity::encrypt(const Bytes& plaintext) const {
|
||||
}
|
||||
Cryptography::X25519PrivateKey::Ptr ephemeral_key = Cryptography::X25519PrivateKey::generate();
|
||||
Bytes ephemeral_pub_bytes = ephemeral_key->public_key()->public_bytes();
|
||||
TRACE("Identity::encrypt: ephemeral public key: " + ephemeral_pub_bytes.toHex());
|
||||
TRACEF("Identity::encrypt: ephemeral public key: %s", ephemeral_pub_bytes.toHex().c_str());
|
||||
|
||||
// CRYPTO: create shared key for key exchange using own public key
|
||||
//shared_key = ephemeral_key.exchange(self.pub)
|
||||
Bytes shared_key = ephemeral_key->exchange(_object->_pub_bytes);
|
||||
TRACE("Identity::encrypt: shared key: " + shared_key.toHex());
|
||||
TRACEF("Identity::encrypt: shared key: %s", shared_key.toHex().c_str());
|
||||
|
||||
Bytes derived_key = Cryptography::hkdf(
|
||||
DERIVED_KEY_LENGTH,
|
||||
@@ -550,13 +550,13 @@ const Bytes Identity::encrypt(const Bytes& plaintext) const {
|
||||
get_salt(),
|
||||
get_context()
|
||||
);
|
||||
TRACE("Identity::encrypt: derived key: " + derived_key.toHex());
|
||||
TRACEF("Identity::encrypt: derived key: %s", derived_key.toHex().c_str());
|
||||
|
||||
Cryptography::Token token(derived_key);
|
||||
TRACE("Identity::encrypt: Token encrypting data of length " + std::to_string(plaintext.size()));
|
||||
TRACE("Identity::encrypt: plaintext: " + plaintext.toHex());
|
||||
TRACEF("Identity::encrypt: Token encrypting data of length %zu", plaintext.size());
|
||||
TRACEF("Identity::encrypt: plaintext: %s", plaintext.toHex().c_str());
|
||||
Bytes ciphertext = token.encrypt(plaintext);
|
||||
TRACE("Identity::encrypt: ciphertext: " + ciphertext.toHex());
|
||||
TRACEF("Identity::encrypt: ciphertext: %s", ciphertext.toHex().c_str());
|
||||
|
||||
return ephemeral_pub_bytes + ciphertext;
|
||||
}
|
||||
@@ -576,7 +576,7 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const {
|
||||
throw std::runtime_error("Decryption failed because identity does not hold a private key");
|
||||
}
|
||||
if (ciphertext_token.size() <= Type::Identity::KEYSIZE/8/2) {
|
||||
DEBUG("Decryption failed because the token size " + std::to_string(ciphertext_token.size()) + " was invalid.");
|
||||
DEBUGF("Decryption failed because the token size %zu was invalid.", ciphertext_token.size());
|
||||
return {Bytes::NONE};
|
||||
}
|
||||
Bytes plaintext;
|
||||
@@ -585,12 +585,12 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const {
|
||||
Bytes peer_pub_bytes = ciphertext_token.left(Type::Identity::KEYSIZE/8/2);
|
||||
//peer_pub = X25519PublicKey.from_public_bytes(peer_pub_bytes)
|
||||
//Cryptography::X25519PublicKey::Ptr peer_pub = Cryptography::X25519PublicKey::from_public_bytes(peer_pub_bytes);
|
||||
TRACE("Identity::decrypt: peer public key: " + peer_pub_bytes.toHex());
|
||||
TRACEF("Identity::decrypt: peer public key: %s", peer_pub_bytes.toHex().c_str());
|
||||
|
||||
// CRYPTO: create shared key for key exchange using peer public key
|
||||
//shared_key = _object->_prv->exchange(peer_pub);
|
||||
Bytes shared_key = _object->_prv->exchange(peer_pub_bytes);
|
||||
TRACE("Identity::decrypt: shared key: " + shared_key.toHex());
|
||||
TRACEF("Identity::decrypt: shared key: %s", shared_key.toHex().c_str());
|
||||
|
||||
Bytes derived_key = Cryptography::hkdf(
|
||||
DERIVED_KEY_LENGTH,
|
||||
@@ -598,19 +598,19 @@ const Bytes Identity::decrypt(const Bytes& ciphertext_token) const {
|
||||
get_salt(),
|
||||
get_context()
|
||||
);
|
||||
TRACE("Identity::decrypt: derived key: " + derived_key.toHex());
|
||||
TRACEF("Identity::decrypt: derived key: %s", derived_key.toHex().c_str());
|
||||
|
||||
Cryptography::Token token(derived_key);
|
||||
//ciphertext = ciphertext_token[Identity.KEYSIZE//8//2:]
|
||||
Bytes ciphertext(ciphertext_token.mid(Type::Identity::KEYSIZE/8/2));
|
||||
TRACE("Identity::decrypt: Token decrypting data of length " + std::to_string(ciphertext.size()));
|
||||
TRACE("Identity::decrypt: ciphertext: " + ciphertext.toHex());
|
||||
TRACEF("Identity::decrypt: Token decrypting data of length %zu", ciphertext.size());
|
||||
TRACEF("Identity::decrypt: ciphertext: %s", ciphertext.toHex().c_str());
|
||||
plaintext = token.decrypt(ciphertext);
|
||||
TRACE("Identity::decrypt: plaintext: " + plaintext.toHex());
|
||||
//TRACE("Identity::decrypt: Token decrypted data of length " + std::to_string(plaintext.size()));
|
||||
TRACEF("Identity::decrypt: plaintext: %s", plaintext.toHex().c_str());
|
||||
//TRACEF("Identity::decrypt: Token decrypted data of length %s", std::to_string(plaintext.size()).c_str());
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
DEBUG("Decryption by " + toString() + " failed: " + e.what());
|
||||
DEBUGF("Decryption by %s failed: %s", toString().c_str(), e.what());
|
||||
}
|
||||
|
||||
return plaintext;
|
||||
@@ -632,7 +632,7 @@ const Bytes Identity::sign(const Bytes& message) const {
|
||||
return _object->_sig_prv->sign(message);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERROR("The identity " + toString() + " could not sign the requested message. The contained exception was: " + e.what());
|
||||
ERRORF("The identity %s could not sign the requested message. The contained exception was: %s", toString().c_str(), e.what());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -649,7 +649,7 @@ bool Identity::validate(const Bytes& signature, const Bytes& message) const {
|
||||
assert(_object);
|
||||
if (_object->_pub) {
|
||||
try {
|
||||
TRACE("Identity::validate: Attempting to verify signature: " + signature.toHex() + " and message: " + message.toHex());
|
||||
TRACEF("Identity::validate: Attempting to verify signature: %s and message: %s", signature.toHex().c_str(), message.toHex().c_str());
|
||||
_object->_sig_pub->verify(signature, message);
|
||||
return true;
|
||||
}
|
||||
@@ -668,11 +668,11 @@ void Identity::prove(const Packet& packet, const Destination& destination /*= {T
|
||||
Bytes proof_data;
|
||||
if (RNS::Reticulum::should_use_implicit_proof()) {
|
||||
proof_data = signature;
|
||||
TRACE("Identity::prove: implicit proof data: " + proof_data.toHex());
|
||||
TRACEF("Identity::prove: implicit proof data: %s", proof_data.toHex().c_str());
|
||||
}
|
||||
else {
|
||||
proof_data = packet.packet_hash() + signature;
|
||||
TRACE("Identity::prove: explicit proof data: " + proof_data.toHex());
|
||||
TRACEF("Identity::prove: explicit proof data: %s", proof_data.toHex().c_str());
|
||||
}
|
||||
|
||||
if (!destination) {
|
||||
|
||||
+7
-7
@@ -46,18 +46,18 @@ namespace RNS {
|
||||
public:
|
||||
Identity(bool create_keys = true);
|
||||
Identity(Type::NoneConstructor none) {
|
||||
MEM("Identity NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Identity NONE object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
Identity(const Identity& identity) : _object(identity._object) {
|
||||
MEM("Identity object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Identity object copy created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
virtual ~Identity() {
|
||||
MEM("Identity object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Identity object destroyed, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
inline Identity& operator = (const Identity& identity) {
|
||||
_object = identity._object;
|
||||
MEM("Identity object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Identity object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
return *this;
|
||||
}
|
||||
inline operator bool() const {
|
||||
@@ -89,7 +89,7 @@ namespace RNS {
|
||||
inline void update_hashes() {
|
||||
assert(_object);
|
||||
_object->_hash = truncated_hash(get_public_key());
|
||||
TRACE("Identity::update_hashes: hash: " + _object->_hash.toHex());
|
||||
TRACEF("Identity::update_hashes: hash: %s", _object->_hash.toHex().c_str());
|
||||
_object->_hexhash = _object->_hash.toHex();
|
||||
};
|
||||
bool load(const char* path);
|
||||
@@ -172,8 +172,8 @@ namespace RNS {
|
||||
private:
|
||||
class Object {
|
||||
public:
|
||||
Object() { MEM("Identity::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||
virtual ~Object() { MEM("Identity::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
|
||||
Object() { MEMF("Identity::Data object created, this: %p", (void*)this); }
|
||||
virtual ~Object() { MEMF("Identity::Data object destroyed, this: %p", (void*)this); }
|
||||
private:
|
||||
|
||||
Cryptography::X25519PrivateKey::Ptr _prv;
|
||||
|
||||
+7
-7
@@ -9,13 +9,13 @@ using namespace RNS::Type::Interface;
|
||||
/*static*/ uint8_t Interface::DISCOVER_PATHS_FOR = MODE_ACCESS_POINT | MODE_GATEWAY;
|
||||
|
||||
void InterfaceImpl::handle_outgoing(const Bytes& data) {
|
||||
//TRACE("InterfaceImpl.handle_outgoing: data: " + data.toHex());
|
||||
//TRACEF("InterfaceImpl.handle_outgoing: data: %s", data.toHex().c_str());
|
||||
TRACE("InterfaceImpl.handle_outgoing");
|
||||
_txb += data.size();
|
||||
}
|
||||
|
||||
void InterfaceImpl::handle_incoming(const Bytes& data) {
|
||||
//TRACE("InterfaceImpl.handle_incoming: data: " + data.toHex());
|
||||
//TRACEF("InterfaceImpl.handle_incoming: data: %s", data.toHex().c_str());
|
||||
TRACE("InterfaceImpl.handle_incoming");
|
||||
_rxb += data.size();
|
||||
// Create temporary Interface encapsulating our own shared impl
|
||||
@@ -26,7 +26,7 @@ void InterfaceImpl::handle_incoming(const Bytes& data) {
|
||||
}
|
||||
|
||||
void Interface::handle_incoming(const Bytes& data) {
|
||||
//TRACE("Interface.handle_incoming: data: " + data.toHex());
|
||||
//TRACEF("Interface.handle_incoming: data: %s", data.toHex().c_str());
|
||||
TRACE("Interface.handle_incoming");
|
||||
assert(_impl);
|
||||
/*
|
||||
@@ -87,18 +87,18 @@ void Interface::process_announce_queue() {
|
||||
/*
|
||||
void ArduinoJson::convertFromJson(JsonVariantConst src, RNS::Interface& dst) {
|
||||
TRACE(">>> Deserializing Interface");
|
||||
TRACE(">>> Interface pre: " + dst.debugString());
|
||||
TRACEF(">>> Interface pre: %s", dst.debugString().c_str());
|
||||
if (!src.isNull()) {
|
||||
RNS::Bytes hash;
|
||||
hash.assignHex(src.as<const char*>());
|
||||
TRACE(">>> Querying Transport for Interface hash " + hash.toHex());
|
||||
TRACEF(">>> Querying Transport for Interface hash %s", hash.toHex().c_str());
|
||||
// Query transport for matching interface
|
||||
dst = Transport::find_interface_from_hash(hash);
|
||||
TRACE(">>> Interface post: " + dst.debugString());
|
||||
TRACEF(">>> Interface post: %s", dst.debugString().c_str());
|
||||
}
|
||||
else {
|
||||
dst = {RNS::Type::NONE};
|
||||
TRACE(">>> Interface post: " + dst.debugString());
|
||||
TRACEF(">>> Interface post: %s", dst.debugString().c_str());
|
||||
}
|
||||
}
|
||||
*/
|
||||
+3
-3
@@ -224,7 +224,7 @@ namespace ArduinoJson {
|
||||
if (!src) {
|
||||
return dst.set(nullptr);
|
||||
}
|
||||
TRACE("<<< Interface hash " + src.get_hash().toHex());
|
||||
TRACEF("<<< Interface hash %s", src.get_hash().toHex().c_str());
|
||||
return dst.set(src.get_hash().toHex());
|
||||
}
|
||||
void convertFromJson(JsonVariantConst src, RNS::Interface& dst);
|
||||
@@ -241,14 +241,14 @@ namespace ArduinoJson {
|
||||
if (!src) {
|
||||
return dst.set(nullptr);
|
||||
}
|
||||
TRACE("<<< Serializing interface hash " + src.get_hash().toHex());
|
||||
TRACEF("<<< Serializing interface hash %s", src.get_hash().toHex().c_str());
|
||||
return dst.set(src.get_hash().toHex());
|
||||
}
|
||||
static RNS::Interface fromJson(JsonVariantConst src) {
|
||||
if (!src.isNull()) {
|
||||
RNS::Bytes hash;
|
||||
hash.assignHex(src.as<const char*>());
|
||||
TRACE(">>> Deserialized interface hash " + hash.toHex());
|
||||
TRACEF(">>> Deserialized interface hash %s", hash.toHex().c_str());
|
||||
TRACE(">>> Querying transport for interface");
|
||||
// Query transport for matching interface
|
||||
return RNS::Interface::find_interface_from_hash(hash);
|
||||
|
||||
@@ -92,11 +92,11 @@ namespace RNS {
|
||||
#endif
|
||||
|
||||
inline void log(const char* msg, LogLevel level = LOG_NOTICE) { doLog(level, msg); }
|
||||
inline void log(const std::string& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); }
|
||||
//inline void log(const std::string& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); }
|
||||
inline void logf(LogLevel level, const char* msg, ...) { va_list vlist; va_start(vlist, msg); doLog(level, msg, vlist); va_end(vlist); }
|
||||
#ifdef ARDUINO
|
||||
inline void log(const String& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); }
|
||||
inline void log(const StringSumHelper& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); }
|
||||
//inline void log(const String& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); }
|
||||
//inline void log(const StringSumHelper& msg, LogLevel level = LOG_NOTICE) { doLog(level, msg.c_str()); }
|
||||
//inline void log(const __FlashStringHelper* msg, LogLevel level = LOG_NOTICE) { doLog(level, msg); }
|
||||
//inline void logf(LogLevel level, const __FlashStringHelper* msg, ...) { va_list vlist; va_start(vlist, msg); doLog(level, msg, vlist); va_end(vlist); }
|
||||
#endif
|
||||
|
||||
+11
-11
@@ -55,7 +55,7 @@ Packet::Packet(const Destination& destination, const Interface& attached_interfa
|
||||
_object->_create_receipt = false;
|
||||
}
|
||||
|
||||
MEM("Packet object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Packet object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
// CBA LINK
|
||||
@@ -70,7 +70,7 @@ Packet::Packet(const Link& link, const Bytes& data, Type::Packet::types packet_t
|
||||
_object->_MTU = link.mtu();
|
||||
// CBA HACK: Need to re-build packed flags since Link was assigned
|
||||
_object->_flags = get_packed_flags();
|
||||
MEM("Packet link object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Packet link object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
|
||||
@@ -283,13 +283,13 @@ void Packet::pack() {
|
||||
// CBA LINK
|
||||
if (_object->_context == LRPROOF) {
|
||||
if (!_object->_destination_link) throw std::invalid_argument("Packet is not associated with a Link");
|
||||
TRACE("Packet::pack: destination link id: " + _object->_destination_link.link_id().toHex() );
|
||||
TRACEF("Packet::pack: destination link id: %s", _object->_destination_link.link_id().toHex().c_str());
|
||||
_object->_header << _object->_destination_link.link_id();
|
||||
_object->_ciphertext = _object->_data;
|
||||
}
|
||||
else {
|
||||
if (_object->_header_type == HEADER_1) {
|
||||
TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() );
|
||||
TRACEF("Packet::pack: destination hash: %s", _object->_destination.hash().toHex().c_str());
|
||||
_object->_header << _object->_destination.hash();
|
||||
|
||||
if (_object->_packet_type == ANNOUNCE) {
|
||||
@@ -348,8 +348,8 @@ TRACEF("***** Destination Data: %s", _object->_ciphertext.toHex().c_str());
|
||||
if (!_object->_transport_id) {
|
||||
throw std::invalid_argument("Packet with header type 2 must have a transport ID");
|
||||
}
|
||||
TRACE("Packet::pack: transport id: " + _object->_transport_id.toHex() );
|
||||
TRACE("Packet::pack: destination hash: " + _object->_destination.hash().toHex() );
|
||||
TRACEF("Packet::pack: transport id: %s", _object->_transport_id.toHex().c_str());
|
||||
TRACEF("Packet::pack: destination hash: %s", _object->_destination.hash().toHex().c_str());
|
||||
_object->_header << _object->_transport_id;
|
||||
_object->_header << _object->_destination.hash();
|
||||
|
||||
@@ -424,7 +424,7 @@ bool Packet::unpack() {
|
||||
return false;
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERROR(std::string("Received malformed packet, dropping it. The contained exception was: ") + e.what());
|
||||
ERRORF("Received malformed packet, dropping it. The contained exception was: %s", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -856,8 +856,8 @@ bool PacketReceipt::validate_link_proof(const Bytes& proof, const Link& link, co
|
||||
_object->_callbacks._delivery(*this);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERROR("An error occurred while evaluating external delivery callback for " + link.toString());
|
||||
ERROR("The contained exception was: " + std::string(e.what()));
|
||||
ERRORF("An error occurred while evaluating external delivery callback for %s", link.toString().c_str());
|
||||
ERRORF("The contained exception was: %s", e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -918,7 +918,7 @@ bool PacketReceipt::validate_proof(const Bytes& proof, const Packet& proof_packe
|
||||
_object->_callbacks._delivery(*this);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERROR("Error while executing proof validated callback. The contained exception was: " + std::string(e.what()));
|
||||
ERRORF("Error while executing proof validated callback. The contained exception was: %s", e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -949,7 +949,7 @@ bool PacketReceipt::validate_proof(const Bytes& proof, const Packet& proof_packe
|
||||
_object->_callbacks._delivery(*this);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERROR("Error while executing proof validated callback. The contained exception was: " + std::string(e.what()));
|
||||
ERRORF("Error while executing proof validated callback. The contained exception was: %s", e.what());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+10
-10
@@ -145,10 +145,10 @@ namespace RNS {
|
||||
|
||||
public:
|
||||
Packet(Type::NoneConstructor none) {
|
||||
MEM("Packet NONE object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Packet NONE object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
Packet(const Packet& packet) : _object(packet._object) {
|
||||
MEM("Packet object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Packet object copy created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
Packet(
|
||||
const Destination& destination,
|
||||
@@ -182,12 +182,12 @@ namespace RNS {
|
||||
Type::Packet::context_flags context_flag = Type::Packet::FLAG_UNSET
|
||||
);
|
||||
virtual ~Packet() {
|
||||
MEM("Packet object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Packet object destroyed, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
inline Packet& operator = (const Packet& packet) {
|
||||
_object = packet._object;
|
||||
MEM("Packet object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Packet object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
return *this;
|
||||
}
|
||||
inline operator bool() const {
|
||||
@@ -272,11 +272,11 @@ namespace RNS {
|
||||
private:
|
||||
class Object {
|
||||
public:
|
||||
Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) { MEM("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||
Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) { MEMF("Packet::Data object created, this: %p", (void*)this); }
|
||||
// CBA LINK
|
||||
//Object(const Destination& destination, const Link& destination_link) : _destination(destination), _destination_link(destination_link) { MEM("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||
//Object(const Link& link) : _destination(link.destination()), _destination_link(link) { MEM("Packet::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||
virtual ~Object() { MEM("Packet::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
|
||||
//Object(const Destination& destination, const Link& destination_link) : _destination(destination), _destination_link(destination_link) { MEMF("Packet::Data object created, this: %p", (void*)this); }
|
||||
//Object(const Link& link) : _destination(link.destination()), _destination_link(link) { MEMF("Packet::Data object created, this: %p", (void*)this); }
|
||||
virtual ~Object() { MEMF("Packet::Data object destroyed, this: %p", (void*)this); }
|
||||
private:
|
||||
Destination _destination = {Type::NONE};
|
||||
|
||||
@@ -358,14 +358,14 @@ namespace ArduinoJson {
|
||||
if (!src) {
|
||||
return dst.set(nullptr);
|
||||
}
|
||||
TRACE("<<< Serializing packet hash " + src.get_hash().toHex());
|
||||
TRACEF("<<< Serializing packet hash %s", src.get_hash().toHex().c_str());
|
||||
return dst.set(src.get_hash().toHex());
|
||||
}
|
||||
static RNS::Packet fromJson(JsonVariantConst src) {
|
||||
if (!src.isNull()) {
|
||||
RNS::Bytes hash;
|
||||
hash.assignHex(src.as<const char*>());
|
||||
TRACE(">>> Deserialized packet hash " + hash.toHex());
|
||||
TRACEF(">>> Deserialized packet hash %s", hash.toHex().c_str());
|
||||
TRACE(">>> Querying transport for cached packet");
|
||||
// Query transport for matching interface
|
||||
return RNS::Packet::get_cached_packet(hash);
|
||||
|
||||
+7
-7
@@ -67,12 +67,12 @@ void Reticulum::sigterm_handler(signal, frame):
|
||||
|
||||
//def __init__(self,configdir=None, loglevel=None, logdest=None, verbosity=None):
|
||||
Reticulum::Reticulum() : _object(new Object()) {
|
||||
MEM("Reticulum default object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Reticulum default object creating..., this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
|
||||
// Initialize random number generator
|
||||
TRACE("Initializing RNG...");
|
||||
RNG.begin("Reticulum");
|
||||
TRACE("RNG initial random value: " + std::to_string(Cryptography::randomnum()));
|
||||
TRACEF("RNG initial random value: %d", Cryptography::randomnum());
|
||||
|
||||
#ifdef ARDUINO
|
||||
// Add a noise source to the list of sources known to RNG.
|
||||
@@ -125,7 +125,7 @@ Reticulum::Reticulum() : _object(new Object()) {
|
||||
Bytes buf;
|
||||
if (OS::read_file(time_offset_path, buf) == 8) {
|
||||
uint64_t offset = *(uint64_t*)buf.data();
|
||||
DEBUG("Read time offset of " + std::to_string(offset) + " from file");
|
||||
DEBUGF("Read time offset of %llu from file", offset);
|
||||
OS::setTimeOffset(offset);
|
||||
}
|
||||
}
|
||||
@@ -191,13 +191,13 @@ Reticulum::Reticulum() : _object(new Object()) {
|
||||
signal.signal(signal.SIGTERM, Reticulum.sigterm_handler)
|
||||
*/
|
||||
|
||||
MEM("Reticulum default object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Reticulum default object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
void Reticulum::start() {
|
||||
|
||||
INFO("Total memory: " + std::to_string(OS::heap_size()));
|
||||
INFO("Total flash: " + std::to_string(OS::storage_size()));
|
||||
INFOF("Total memory: %zu", OS::heap_size());
|
||||
INFOF("Total flash: %zu", OS::storage_size());
|
||||
|
||||
INFO("Starting Transport...");
|
||||
Transport::start(*this);
|
||||
@@ -241,7 +241,7 @@ void Reticulum::jobs() {
|
||||
if (OS::heap_size() > 0) {
|
||||
uint8_t remaining = (uint8_t)((double)OS::heap_available() / (double)OS::heap_size() * 100.0);
|
||||
if (remaining <= 2) {
|
||||
head("DETECTED LOW-MEMORY CONDITION (" + std::to_string(remaining) + "%), RESETTING!!!", LOG_CRITICAL);
|
||||
HEADF(LOG_CRITICAL, "DETECTED LOW-MEMORY CONDITION (%d%%), RESETTING!!!", remaining);
|
||||
persist_data();
|
||||
#if defined(ESP32)
|
||||
ESP.restart();
|
||||
|
||||
+6
-6
@@ -49,18 +49,18 @@ namespace RNS {
|
||||
public:
|
||||
Reticulum();
|
||||
Reticulum(Type::NoneConstructor none) {
|
||||
MEM("Reticulum empty object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Reticulum empty object created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
Reticulum(const Reticulum& reticulum) : _object(reticulum._object) {
|
||||
MEM("Reticulum object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Reticulum object copy created, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
virtual ~Reticulum() {
|
||||
MEM("Reticulum object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Reticulum object destroyed, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
}
|
||||
|
||||
inline Reticulum& operator = (const Reticulum& reticulum) {
|
||||
_object = reticulum._object;
|
||||
MEM("Reticulum object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
MEMF("Reticulum object copy created by assignment, this: %p, data: %p", (void*)this, (void*)_object.get());
|
||||
return *this;
|
||||
}
|
||||
inline operator bool() const {
|
||||
@@ -149,10 +149,10 @@ namespace RNS {
|
||||
class Object {
|
||||
public:
|
||||
Object() {
|
||||
MEM("Reticulum data object created, this: " + std::to_string((uintptr_t)this));
|
||||
MEMF("Reticulum data object created, this: %p", (void*)this);
|
||||
}
|
||||
virtual ~Object() {
|
||||
MEM("Reticulum data object destroyed, this: " + std::to_string((uintptr_t)this));
|
||||
MEMF("Reticulum data object destroyed, this: %p", (void*)this);
|
||||
}
|
||||
private:
|
||||
|
||||
|
||||
+158
-158
File diff suppressed because it is too large.
Load diff
@@ -148,14 +148,14 @@ namespace ArduinoJson {
|
||||
if (!src) {
|
||||
return dst.set(nullptr);
|
||||
}
|
||||
//TRACE("<<< Serializing interface hash " + src.get_hash().toHex());
|
||||
//TRACEF("<<< Serializing interface hash %s", src.get_hash().toHex().c_str());
|
||||
return dst.set(src.get_hash().toHex());
|
||||
}
|
||||
static RNS::Interface fromJson(JsonVariantConst src) {
|
||||
if (!src.isNull()) {
|
||||
RNS::Bytes hash;
|
||||
hash.assignHex(src.as<const char*>());
|
||||
//TRACE(">>> Deserialized interface hash " + hash.toHex());
|
||||
//TRACEF(">>> Deserialized interface hash %s", hash.toHex().c_str());
|
||||
//TRACE(">>> Querying transport for interface");
|
||||
// Query transport for matching interface
|
||||
return RNS::Transport::find_interface_from_hash(hash);
|
||||
@@ -178,7 +178,7 @@ namespace ArduinoJson {
|
||||
if (!src) {
|
||||
return dst.set(nullptr);
|
||||
}
|
||||
//TRACE("<<< Serializing packet hash " + src.get_hash().toHex());
|
||||
//TRACEF("<<< Serializing packet hash %s", src.get_hash().toHex().c_str());
|
||||
// Whenever a reference to a packet is serialized we must ensure that packet itself also gets serialized separately
|
||||
RNS::Transport::cache_packet(src, true);
|
||||
return dst.set(src.get_hash().toHex());
|
||||
@@ -187,7 +187,7 @@ namespace ArduinoJson {
|
||||
if (!src.isNull()) {
|
||||
RNS::Bytes hash;
|
||||
hash.assignHex(src.as<const char*>());
|
||||
//TRACE(">>> Deserialized packet hash " + hash.toHex());
|
||||
//TRACEF(">>> Deserialized packet hash %s", hash.toHex().c_str());
|
||||
//TRACE(">>> Querying transport for cached packet");
|
||||
// Query transport for matching packet
|
||||
return RNS::Transport::get_cached_packet(hash);
|
||||
@@ -300,7 +300,7 @@ namespace ArduinoJson {
|
||||
}
|
||||
}
|
||||
else {
|
||||
TRACE("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached");
|
||||
TRACEF("Destination announce packet %s is already cached", src._announce_packet.get_hash().toHex().c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -397,7 +397,7 @@ namespace RNS {
|
||||
}
|
||||
}
|
||||
else {
|
||||
TRACE("Destination announce packet " + src._announce_packet.get_hash().toHex() + " is already cached");
|
||||
TRACEF("Destination announce packet %s is already cached", src._announce_packet.get_hash().toHex().c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -520,7 +520,7 @@ namespace RNS { namespace Persistence {
|
||||
size_t read = RNS::Utilities::OS::read_file(file_path, _buffer);
|
||||
if (read > 0) {
|
||||
TRACEF("Persistence::deserialize: read: %d bytes", _buffer.size());
|
||||
//TRACE("testDeserializeVector: data: " + _buffer.toString());
|
||||
//TRACEF("testDeserializeVector: data: %s", _buffer.toString().c_str());
|
||||
#ifdef USE_MSGPACK
|
||||
DeserializationError error = deserializeMsgPack(_document, _buffer.data());
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user