WIP: Refactor pointer/reference style.

This commit is contained in:
attermann 2023-11-20 10:51:56 -07:00
parent d09331ec0e
commit 263f589801
29 changed files with 347 additions and 347 deletions

View File

@ -21,7 +21,7 @@ void Bytes::ownData() {
}
}
int8_t Bytes::compare(const Bytes &bytes) const {
int8_t Bytes::compare(const Bytes& bytes) const {
if (_data == bytes._data) {
return 0;
}
@ -76,12 +76,12 @@ const char hex_lower_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
std::string RNS::hexFromByte(uint8_t byte, bool upper /*= true*/) {
std::string hex;
if (upper) {
hex += hex_upper_chars[ (byte & 0xF0) >> 4];
hex += hex_upper_chars[ (byte & 0x0F) >> 0];
hex += hex_upper_chars[ (byte& 0xF0) >> 4];
hex += hex_upper_chars[ (byte& 0x0F) >> 0];
}
else {
hex += hex_lower_chars[ (byte & 0xF0) >> 4];
hex += hex_lower_chars[ (byte & 0x0F) >> 0];
hex += hex_lower_chars[ (byte& 0xF0) >> 4];
hex += hex_lower_chars[ (byte& 0x0F) >> 0];
}
return hex;
}
@ -93,12 +93,12 @@ std::string Bytes::toHex(bool upper /*= true*/) const {
std::string hex;
for (uint8_t byte : *_data) {
if (upper) {
hex += hex_upper_chars[ (byte & 0xF0) >> 4];
hex += hex_upper_chars[ (byte & 0x0F) >> 0];
hex += hex_upper_chars[ (byte& 0xF0) >> 4];
hex += hex_upper_chars[ (byte& 0x0F) >> 0];
}
else {
hex += hex_lower_chars[ (byte & 0xF0) >> 4];
hex += hex_lower_chars[ (byte & 0x0F) >> 0];
hex += hex_lower_chars[ (byte& 0xF0) >> 4];
hex += hex_lower_chars[ (byte& 0x0F) >> 0];
}
}
return hex;

View File

@ -34,7 +34,7 @@ namespace RNS {
Bytes(NoneConstructor none) {
//extreme("Bytes object created from NONE, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
Bytes(const Bytes &bytes) {
Bytes(const Bytes& bytes) {
//extreme("Bytes is using shared data");
assign(bytes);
//extreme("Bytes object copy created from bytes \"" + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
@ -47,7 +47,7 @@ namespace RNS {
assign(string);
//extreme(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) {
Bytes(const std::string& string) {
assign(string);
//extreme(std::string("Bytes object created from std::string \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
@ -55,30 +55,30 @@ namespace RNS {
//extreme(std::string("Bytes object destroyed \"") + toString() + "\", this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((unsigned long)_data.get()));
}
inline Bytes& operator = (const Bytes &bytes) {
inline Bytes& operator = (const Bytes& bytes) {
assign(bytes);
return *this;
}
inline Bytes& operator += (const Bytes &bytes) {
inline Bytes& operator += (const Bytes& bytes) {
append(bytes);
return *this;
}
inline Bytes operator + (const Bytes &bytes) const {
inline Bytes operator + (const Bytes& bytes) const {
Bytes newbytes(*this);
newbytes.append(bytes);
return newbytes;
}
inline bool operator == (const Bytes &bytes) const {
inline bool operator == (const Bytes& bytes) const {
return compare(bytes) == 0;
}
inline bool operator != (const Bytes &bytes) const {
inline bool operator != (const Bytes& bytes) const {
return compare(bytes) != 0;
}
inline bool operator < (const Bytes &bytes) const {
inline bool operator < (const Bytes& bytes) const {
return compare(bytes) < 0;
}
inline bool operator > (const Bytes &bytes) const {
inline bool operator > (const Bytes& bytes) const {
return compare(bytes) > 0;
}
inline operator bool() const {
@ -144,7 +144,7 @@ namespace RNS {
newData();
_data->insert(_data->begin(), (uint8_t *)string, (uint8_t *)string + strlen(string));
}
inline void assign(const std::string &string) { assign(string.c_str()); }
inline void assign(const std::string& string) { assign(string.c_str()); }
void assignHex(const char* hex);
inline void append(const Bytes& bytes) {
@ -171,7 +171,7 @@ namespace RNS {
ownData();
_data->insert(_data->end(), (uint8_t *)string, (uint8_t *)string + strlen(string));
}
inline void append(const std::string &string) { append(string.c_str()); }
inline void append(const std::string& string) { append(string.c_str()); }
inline void append(uint8_t byte) {
ownData();
_data->push_back(byte);
@ -193,7 +193,7 @@ namespace RNS {
}
public:
int8_t compare(const Bytes &bytes) const;
int8_t compare(const Bytes& bytes) const;
inline size_t size() const { if (!_data) return 0; return _data->size(); }
inline bool empty() const { if (!_data) return true; return _data->empty(); }
inline size_t capacity() const { if (!_data) return 0; return _data->capacity(); }
@ -248,12 +248,12 @@ namespace RNS {
}
inline RNS::Bytes& operator << (RNS::Bytes &lhbytes, const RNS::Bytes &rhbytes) {
inline RNS::Bytes& operator << (RNS::Bytes& lhbytes, const RNS::Bytes& rhbytes) {
lhbytes.append(rhbytes);
return lhbytes;
}
inline RNS::Bytes& operator << (RNS::Bytes &lhbytes, uint8_t rhbyte) {
inline RNS::Bytes& operator << (RNS::Bytes& lhbytes, uint8_t rhbyte) {
lhbytes.append(rhbyte);
return lhbytes;
}

View File

@ -11,7 +11,7 @@ namespace RNS { namespace Cryptography {
class AES_128_CBC {
public:
static inline const Bytes encrypt(const Bytes &plaintext, const Bytes &key, const Bytes &iv) {
static inline const Bytes encrypt(const Bytes& plaintext, const Bytes& key, const Bytes& iv) {
CBC<AES128> cbc;
cbc.setKey(key.data(), key.size());
cbc.setIV(iv.data(), iv.size());
@ -20,7 +20,7 @@ namespace RNS { namespace Cryptography {
return ciphertext;
}
static inline const Bytes decrypt(const Bytes &ciphertext, const Bytes &key, const Bytes &iv) {
static inline const Bytes decrypt(const Bytes& ciphertext, const Bytes& key, const Bytes& iv) {
CBC<AES128> cbc;
cbc.setKey(key.data(), key.size());
cbc.setIV(iv.data(), iv.size());
@ -30,7 +30,7 @@ namespace RNS { namespace Cryptography {
}
// EXPERIMENTAL - overwrites passed buffer
static inline void inplace_encrypt(Bytes &plaintext, const Bytes &key, const Bytes &iv) {
static inline void inplace_encrypt(Bytes& plaintext, const Bytes& key, const Bytes& iv) {
CBC<AES128> cbc;
cbc.setKey(key.data(), key.size());
cbc.setIV(iv.data(), iv.size());
@ -38,7 +38,7 @@ namespace RNS { namespace Cryptography {
}
// EXPERIMENTAL - overwrites passed buffer
static inline void inplace_decrypt(Bytes &ciphertext, const Bytes &key, const Bytes &iv) {
static inline void inplace_decrypt(Bytes& ciphertext, const Bytes& key, const Bytes& iv) {
CBC<AES128> cbc;
cbc.setKey(key.data(), key.size());
cbc.setIV(iv.data(), iv.size());

View File

@ -17,7 +17,7 @@ namespace RNS { namespace Cryptography {
class Ed25519PublicKey {
public:
Ed25519PublicKey(const Bytes &publicKey) {
Ed25519PublicKey(const Bytes& publicKey) {
_publicKey = publicKey;
}
~Ed25519PublicKey() {}
@ -26,15 +26,15 @@ namespace RNS { namespace Cryptography {
public:
// creates a new instance with specified seed
static inline Ptr from_public_bytes(const Bytes &publicKey) {
static inline Ptr from_public_bytes(const Bytes& publicKey) {
return Ptr(new Ed25519PublicKey(publicKey));
}
inline const Bytes &public_bytes() {
inline const Bytes& public_bytes() {
return _publicKey;
}
inline bool verify(const Bytes &signature, const Bytes &message) {
inline bool verify(const Bytes& signature, const Bytes& message) {
return Ed25519::verify(signature.data(), _publicKey.data(), message.data(), message.size());
}
@ -46,7 +46,7 @@ namespace RNS { namespace Cryptography {
class Ed25519PrivateKey {
public:
Ed25519PrivateKey(const Bytes &privateKey) {
Ed25519PrivateKey(const Bytes& privateKey) {
if (privateKey) {
// use specified private key
_privateKey = privateKey;
@ -71,11 +71,11 @@ namespace RNS { namespace Cryptography {
}
// creates a new instance with specified seed
static inline Ptr from_private_bytes(const Bytes &privateKey) {
static inline Ptr from_private_bytes(const Bytes& privateKey) {
return Ptr(new Ed25519PrivateKey(privateKey));
}
inline const Bytes &private_bytes() {
inline const Bytes& private_bytes() {
return _privateKey;
}
@ -84,7 +84,7 @@ namespace RNS { namespace Cryptography {
return Ed25519PublicKey::from_public_bytes(_publicKey);
}
inline const Bytes sign(const Bytes &message) {
inline const Bytes sign(const Bytes& message) {
//zreturn _sk.sign(message);
Bytes signature;
Ed25519::sign(signature.writable(64), _privateKey.data(), _publicKey.data(), message.data(), message.size());

View File

@ -11,7 +11,7 @@
using namespace RNS;
using namespace RNS::Cryptography;
Fernet::Fernet(const Bytes &key) {
Fernet::Fernet(const Bytes& key) {
if (!key) {
throw std::invalid_argument("Fernet key cannot be None");
@ -33,7 +33,7 @@ Fernet::~Fernet() {
extreme("Fernet object destroyed");
}
bool Fernet::verify_hmac(const Bytes &token) {
bool Fernet::verify_hmac(const Bytes& token) {
if (token.size() <= 32) {
throw std::invalid_argument("Cannot verify HMAC on token of only " + std::to_string(token.size()) + " bytes");
@ -49,7 +49,7 @@ bool Fernet::verify_hmac(const Bytes &token) {
return (received_hmac == expected_hmac);
}
const Bytes Fernet::encrypt(const Bytes &data) {
const Bytes Fernet::encrypt(const Bytes& data) {
debug("Fernet::encrypt: plaintext length: " + std::to_string(data.size()));
Bytes iv = random(16);
@ -76,7 +76,7 @@ const Bytes Fernet::encrypt(const Bytes &data) {
}
const Bytes Fernet::decrypt(const Bytes &token) {
const Bytes Fernet::decrypt(const Bytes& token) {
debug("Fernet::decrypt: token length: " + std::to_string(token.size()));
if (token.size() < 48) {
@ -109,7 +109,7 @@ const Bytes Fernet::decrypt(const Bytes &token) {
debug("Fernet::decrypt: plaintext length: " + std::to_string(plaintext.size()));
return plaintext;
}
catch (std::exception &e) {
catch (std::exception& e) {
warning("Could not decrypt Fernet token");
throw std::runtime_error("Could not decrypt Fernet token");
}

View File

@ -25,13 +25,13 @@ namespace RNS { namespace Cryptography {
static inline const Bytes generate_key() { return random(32); }
public:
Fernet(const Bytes &key);
Fernet(const Bytes& key);
~Fernet();
public:
bool verify_hmac(const Bytes &token);
const Bytes encrypt(const Bytes &data);
const Bytes decrypt(const Bytes &token);
bool verify_hmac(const Bytes& token);
const Bytes encrypt(const Bytes& data);
const Bytes decrypt(const Bytes& token);
private:
Bytes _signing_key;

View File

@ -5,7 +5,7 @@
using namespace RNS;
const Bytes RNS::Cryptography::hkdf(size_t length, const Bytes &derive_from, const Bytes &salt /*= {Bytes::NONE}*/, const Bytes &context /*= {Bytes::NONE}*/) {
const Bytes RNS::Cryptography::hkdf(size_t length, const Bytes& derive_from, const Bytes& salt /*= {Bytes::NONE}*/, const Bytes& context /*= {Bytes::NONE}*/) {
if (length <= 0) {
throw std::invalid_argument("Invalid output key length");

View File

@ -4,6 +4,6 @@
namespace RNS { namespace Cryptography {
const Bytes hkdf(size_t length, const Bytes &derive_from, const Bytes &salt = {Bytes::NONE}, const Bytes &context = {Bytes::NONE});
const Bytes hkdf(size_t length, const Bytes& derive_from, const Bytes& salt = {Bytes::NONE}, const Bytes& context = {Bytes::NONE});
} }

View File

@ -28,7 +28,7 @@ namespace RNS { namespace Cryptography {
msg: bytes or buffer, Initial input for the hash or None.
digest: The underlying hash algorithm to use
*/
HMAC(const Bytes &key, const Bytes &msg = {Bytes::NONE}, Digest digest = DIGEST_SHA256) {
HMAC(const Bytes& key, const Bytes& msg = {Bytes::NONE}, Digest digest = DIGEST_SHA256) {
if (digest == DIGEST_NONE) {
throw std::invalid_argument("Cannot derive key from empty input material");
@ -56,7 +56,7 @@ namespace RNS { namespace Cryptography {
/*
Feed data from msg into this hashing object.
*/
void update(const Bytes &msg) {
void update(const Bytes& msg) {
assert(_hash);
_hash->update(msg.data(), msg.size());
}
@ -83,7 +83,7 @@ namespace RNS { namespace Cryptography {
method, and can ask for the hash value at any time by calling its digest()
method.
*/
static inline Ptr generate(const Bytes &key, const Bytes &msg = {Bytes::NONE}, Digest digest = DIGEST_SHA256) {
static inline Ptr generate(const Bytes& key, const Bytes& msg = {Bytes::NONE}, Digest digest = DIGEST_SHA256) {
return Ptr(new HMAC(key, msg, digest));
}
@ -99,7 +99,7 @@ namespace RNS { namespace Cryptography {
msg: bytes or buffer, Input message.
digest: The underlying hash algorithm to use.
*/
inline const Bytes digest(const Bytes &key, const Bytes &msg, HMAC::Digest digest = HMAC::DIGEST_SHA256) {
inline const Bytes digest(const Bytes& key, const Bytes& msg, HMAC::Digest digest = HMAC::DIGEST_SHA256) {
HMAC hmac(key, msg, digest);
hmac.update(msg);
return hmac.digest();

View File

@ -14,7 +14,7 @@ uses Python's internal SHA-256 implementation. All SHA-256
calls in RNS end up here.
*/
const Bytes RNS::Cryptography::sha256(const Bytes &data) {
const Bytes RNS::Cryptography::sha256(const Bytes& data) {
//extreme("Cryptography::sha256: data: " + data.toHex() );
SHA256 digest;
digest.reset();
@ -25,7 +25,7 @@ const Bytes RNS::Cryptography::sha256(const Bytes &data) {
return hash;
}
const Bytes RNS::Cryptography::sha512(const Bytes &data) {
const Bytes RNS::Cryptography::sha512(const Bytes& data) {
SHA512 digest;
digest.reset();
digest.update(data.data(), data.size());

View File

@ -6,7 +6,7 @@
namespace RNS { namespace Cryptography {
const Bytes sha256(const Bytes &data);
const Bytes sha512(const Bytes &data);
const Bytes sha256(const Bytes& data);
const Bytes sha512(const Bytes& data);
} }

View File

@ -13,20 +13,20 @@ namespace RNS { namespace Cryptography {
static const size_t BLOCKSIZE = 16;
static inline const Bytes pad(const Bytes &data, size_t bs = BLOCKSIZE) {
static inline const Bytes pad(const Bytes& data, size_t bs = BLOCKSIZE) {
Bytes padded(data);
inplace_pad(padded, bs);
return padded;
}
static inline const Bytes unpad(const Bytes &data, size_t bs = BLOCKSIZE) {
static inline const Bytes unpad(const Bytes& data, size_t bs = BLOCKSIZE) {
Bytes unpadded(data);
inplace_unpad(unpadded, bs);
return unpadded;
}
// updates passed buffer
static inline void inplace_pad(Bytes &data, size_t bs = BLOCKSIZE) {
static inline void inplace_pad(Bytes& data, size_t bs = BLOCKSIZE) {
size_t len = data.size();
//debug("PKCS7::pad: len: " + std::to_string(len));
size_t padlen = bs - (len % bs);
@ -45,7 +45,7 @@ namespace RNS { namespace Cryptography {
}
// updates passed buffer
static inline void inplace_unpad(Bytes &data, size_t bs = BLOCKSIZE) {
static inline void inplace_unpad(Bytes& data, size_t bs = BLOCKSIZE) {
size_t len = data.size();
//debug("PKCS7::unpad: len: " + std::to_string(len));
// read last byte which is pad length

View File

@ -15,11 +15,11 @@ namespace RNS { namespace Cryptography {
public:
/*
X25519PublicKey(const Bytes &x) {
X25519PublicKey(const Bytes& x) {
_x = x;
}
*/
X25519PublicKey(const Bytes &publicKey) {
X25519PublicKey(const Bytes& publicKey) {
_publicKey = publicKey;
}
~X25519PublicKey() {}
@ -29,11 +29,11 @@ namespace RNS { namespace Cryptography {
public:
// creates a new instance with specified seed
/*
static inline Ptr from_public_bytes(const Bytes &data) {
static inline Ptr from_public_bytes(const Bytes& data) {
return Ptr(new X25519PublicKey(_unpack_number(data)));
}
*/
static inline Ptr from_public_bytes(const Bytes &publicKey) {
static inline Ptr from_public_bytes(const Bytes& publicKey) {
return Ptr(new X25519PublicKey(publicKey));
}
@ -64,11 +64,11 @@ namespace RNS { namespace Cryptography {
public:
/*
X25519PrivateKey(const Bytes &a) {
X25519PrivateKey(const Bytes& a) {
_a = a;
}
*/
X25519PrivateKey(const Bytes &privateKey) {
X25519PrivateKey(const Bytes& privateKey) {
if (privateKey) {
// use specified private key
_privateKey = privateKey;
@ -102,11 +102,11 @@ namespace RNS { namespace Cryptography {
// creates a new instance with specified seed
/*
static inline Ptr from_private_bytes(const Bytes &data) {
static inline Ptr from_private_bytes(const Bytes& data) {
return Ptr(new X25519PrivateKey(_fix_secret(_unpack_number(data))));
}
*/
static inline Ptr from_private_bytes(const Bytes &privateKey) {
static inline Ptr from_private_bytes(const Bytes& privateKey) {
return Ptr(new X25519PrivateKey(privateKey));
}
@ -115,7 +115,7 @@ namespace RNS { namespace Cryptography {
return _pack_number(_a);
}
*/
inline const Bytes &private_bytes() {
inline const Bytes& private_bytes() {
return _privateKey;
}
@ -130,7 +130,7 @@ namespace RNS { namespace Cryptography {
}
/*
inline const Bytes exchange(const Bytes &peer_public_key) {
inline const Bytes exchange(const Bytes& peer_public_key) {
if isinstance(peer_public_key, bytes):
peer_public_key = X25519PublicKey.from_public_bytes(peer_public_key)
@ -168,7 +168,7 @@ namespace RNS { namespace Cryptography {
return shared
}
*/
inline const Bytes exchange(const Bytes &peer_public_key) {
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());
@ -181,7 +181,7 @@ namespace RNS { namespace Cryptography {
return sharedKey;
}
inline bool verify(const Bytes &peer_public_key) {
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());

View File

@ -12,7 +12,7 @@
using namespace RNS;
using namespace RNS::Type::Destination;
Destination::Destination(const Identity &identity, const directions direction, const types type, const char* app_name, const char *aspects) : _object(new Object(identity)) {
Destination::Destination(const Identity& identity, const directions direction, const types type, const char* app_name, const char *aspects) : _object(new Object(identity)) {
assert(_object);
// Check input values and build name string
@ -58,7 +58,7 @@ Destination::Destination(const Identity &identity, const directions direction, c
/*
:returns: A destination name in adressable hash form, for an app_name and a number of aspects.
*/
/*static*/ Bytes Destination::hash(const Identity &identity, const char *app_name, const char *aspects) {
/*static*/ Bytes Destination::hash(const Identity& identity, const char *app_name, const char *aspects) {
//name_hash = Identity::full_hash(Destination.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
//addr_hash_material = name_hash
Bytes addr_hash_material = Identity::truncated_hash(expand_name({Type::NONE}, app_name, aspects));
@ -77,7 +77,7 @@ Destination::Destination(const Identity &identity, const directions direction, c
/*
:returns: A string containing the full human-readable name of the destination, for an app_name and a number of aspects.
*/
/*static*/ std::string Destination::expand_name(const Identity &identity, const char *app_name, const char *aspects) {
/*static*/ std::string Destination::expand_name(const Identity& identity, const char *app_name, const char *aspects) {
if (strchr(app_name, '.') != nullptr) {
throw std::invalid_argument("Dots can't be used in app names");
@ -103,8 +103,8 @@ relevant interfaces. Application specific data can be added to the announce.
:param app_data: *bytes* containing the app_data.
:param path_response: Internal flag used by :ref:`RNS.Transport<api-transport>`. Ignore.
*/
//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*/) {
//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);
debug("Destination::announce: announcing destination...");
@ -120,9 +120,9 @@ Packet Destination::announce(const Bytes &app_data, bool path_response, const In
auto it = _object->_path_responses.begin();
while (it != _object->_path_responses.end()) {
// vector
//Response &entry = *it;
//Response& entry = *it;
// map
PathResponse &entry = (*it).second;
PathResponse& entry = (*it).second;
if (now > (entry.first + PR_TAG_WINDOW)) {
it = _object->_path_responses.erase(it);
}
@ -227,7 +227,7 @@ Packet Destination::announce(const Bytes &app_data, bool path_response, const In
}
}
Packet Destination::announce(const Bytes &app_data /*= {}*/, bool path_response /*= false*/) {
Packet Destination::announce(const Bytes& app_data /*= {}*/, bool path_response /*= false*/) {
return announce(app_data, path_response, {Type::NONE});
}
@ -242,7 +242,7 @@ Registers a request handler.
:raises: ``ValueError`` if any of the supplied arguments are invalid.
*/
/*
void Destination::register_request_handler(const Bytes &path, response_generator = None, request_policies allow = ALLOW_NONE, allowed_list = None) {
void Destination::register_request_handler(const Bytes& path, response_generator = None, request_policies allow = ALLOW_NONE, allowed_list = None) {
if path == None or path == "":
raise ValueError("Invalid path specified")
elif not callable(response_generator):
@ -263,7 +263,7 @@ Deregisters a request handler.
:returns: True if the handler was deregistered, otherwise False.
*/
/*
bool Destination::deregister_request_handler(const Bytes &path) {
bool Destination::deregister_request_handler(const Bytes& path) {
path_hash = RNS.Identity.truncated_hash(path.encode("utf-8"))
if path_hash in self.request_handlers:
self.request_handlers.pop(path_hash)
@ -273,7 +273,7 @@ bool Destination::deregister_request_handler(const Bytes &path) {
}
*/
void Destination::receive(const Packet &packet) {
void Destination::receive(const Packet& packet) {
assert(_object);
if (packet.packet_type() == Type::Packet::LINKREQUEST) {
Bytes plaintext(packet.data());
@ -289,7 +289,7 @@ void Destination::receive(const Packet &packet) {
try {
_object->_callbacks._packet(plaintext, packet);
}
catch (std::exception &e) {
catch (std::exception& e) {
debug("Error while executing receive callback from " + toString() + ". The contained exception was: " + e.what());
}
}
@ -298,7 +298,7 @@ void Destination::receive(const Packet &packet) {
}
}
void Destination::incoming_link_request(const Bytes &data, const Packet &packet) {
void Destination::incoming_link_request(const Bytes& data, const Packet& packet) {
assert(_object);
if (_object->_accept_link_requests) {
//z link = Link::validate_request(data, packet);
@ -314,7 +314,7 @@ Encrypts information for ``RNS.Destination.SINGLE`` or ``RNS.Destination.GROUP``
:param plaintext: A *bytes-like* containing the plaintext to be encrypted.
:raises: ``ValueError`` if destination does not hold a necessary key for encryption.
*/
const Bytes Destination::encrypt(const Bytes &data) {
const Bytes Destination::encrypt(const Bytes& data) {
assert(_object);
debug("Destination::encrypt: encrypting data...");
@ -348,7 +348,7 @@ Decrypts information for ``RNS.Destination.SINGLE`` or ``RNS.Destination.GROUP``
:param ciphertext: *Bytes* containing the ciphertext to be decrypted.
:raises: ``ValueError`` if destination does not hold a necessary key for decryption.
*/
const Bytes Destination::decrypt(const Bytes &data) {
const Bytes Destination::decrypt(const Bytes& data) {
assert(_object);
debug("Destination::decrypt: decrypting data...");
@ -382,7 +382,7 @@ Signs information for ``RNS.Destination.SINGLE`` type destination.
:param message: *Bytes* containing the message to be signed.
:returns: A *bytes-like* containing the message signature, or *None* if the destination could not sign the message.
*/
const Bytes Destination::sign(const Bytes &message) {
const Bytes Destination::sign(const Bytes& message) {
assert(_object);
if (_object->_type == SINGLE && _object->_identity) {
return _object->_identity.sign(message);

View File

@ -39,10 +39,10 @@ namespace RNS {
public:
class Callbacks {
public:
using link_established = void(*)(const Link &link);
using link_established = void(*)(const Link& link);
//using packet = void(*)(uint8_t *data, uint16_t data_len, Packet *packet);
using packet = void(*)(const Bytes &data, const Packet &packet);
using proof_requested = bool(*)(const Packet &packet);
using packet = void(*)(const Bytes& data, const Packet& packet);
using proof_requested = bool(*)(const Packet& packet);
public:
link_established _link_established = nullptr;
packet _packet = nullptr;
@ -58,15 +58,15 @@ namespace RNS {
Destination(Type::NoneConstructor none) {
extreme("Destination NONE object created");
}
Destination(const Destination &destination) : _object(destination._object) {
Destination(const Destination& destination) : _object(destination._object) {
extreme("Destination object copy created");
}
Destination(const Identity &identity, const Type::Destination::directions direction, const Type::Destination::types type, const char* app_name, const char *aspects);
Destination(const Identity& identity, const Type::Destination::directions direction, const Type::Destination::types type, const char* app_name, const char *aspects);
virtual ~Destination() {
extreme("Destination object destroyed");
}
inline Destination& operator = (const Destination &destination) {
inline Destination& operator = (const Destination& destination) {
_object = destination._object;
extreme("Destination object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
@ -74,18 +74,18 @@ namespace RNS {
inline operator bool() const {
return _object.get() != nullptr;
}
inline bool operator < (const Destination &destination) const {
inline bool operator < (const Destination& destination) const {
return _object.get() < destination._object.get();
}
public:
static Bytes hash(const Identity &identity, const char *app_name, const char *aspects);
static std::string expand_name(const Identity &identity, const char *app_name, const char *aspects);
static Bytes hash(const Identity& identity, const char *app_name, const char *aspects);
static std::string expand_name(const Identity& identity, const char *app_name, const char *aspects);
public:
//Packet announce(const Bytes &app_data = {}, bool path_response = false, const Interface &attached_interface = {Type::NONE}, const Bytes &tag = {}, bool send = true);
Packet announce(const Bytes &app_data, bool path_response, const Interface &attached_interface, const Bytes &tag = {}, bool send = true);
Packet announce(const Bytes &app_data = {}, bool path_response = false);
//Packet announce(const Bytes& app_data = {}, bool path_response = false, const Interface& attached_interface = {Type::NONE}, const Bytes& tag = {}, bool send = true);
Packet announce(const Bytes& app_data, bool path_response, const Interface& attached_interface, const Bytes& tag = {}, bool send = true);
Packet announce(const Bytes& app_data = {}, bool path_response = false);
/*
Set or query whether the destination accepts incoming link requests.
@ -141,31 +141,31 @@ namespace RNS {
_object->_proof_strategy = proof_strategy;
}
void receive(const Packet &packet);
void incoming_link_request(const Bytes &data, const Packet &packet);
void receive(const Packet& packet);
void incoming_link_request(const Bytes& data, const Packet& packet);
const Bytes encrypt(const Bytes &data);
const Bytes decrypt(const Bytes &data);
const Bytes sign(const Bytes &message);
const Bytes encrypt(const Bytes& data);
const Bytes decrypt(const Bytes& data);
const Bytes sign(const Bytes& message);
// getters/setters
inline Type::Destination::types type() const { assert(_object); return _object->_type; }
inline Type::Destination::directions direction() const { assert(_object); return _object->_direction; }
inline Type::Destination::proof_strategies proof_strategy() const { assert(_object); return _object->_proof_strategy; }
inline const Bytes &hash() const { assert(_object); return _object->_hash; }
inline const Bytes &link_id() const { assert(_object); return _object->_link_id; }
inline const Bytes& hash() const { assert(_object); return _object->_hash; }
inline const Bytes& link_id() const { assert(_object); return _object->_link_id; }
inline uint16_t mtu() const { assert(_object); return _object->_mtu; }
inline void mtu(uint16_t mtu) { assert(_object); _object->_mtu = mtu; }
inline Type::Link::status status() const { assert(_object); return _object->_status; }
inline const Callbacks &callbacks() const { assert(_object); return _object->_callbacks; }
inline const Identity &identity() const { assert(_object); return _object->_identity; }
inline const Callbacks& callbacks() const { assert(_object); return _object->_callbacks; }
inline const Identity& identity() const { assert(_object); return _object->_identity; }
inline std::string toString() const { assert(_object); return "{Destination:" + _object->_hash.toHex() + "}"; }
private:
class Object {
public:
Object(const Identity &identity) : _identity(identity) {}
Object(const Identity& identity) : _identity(identity) {}
virtual ~Object() {}
private:
bool _accept_link_requests = true;

View File

@ -50,7 +50,7 @@ void Identity::createKeys() {
}
/*static*/ bool Identity::validate_announce(const Packet &packet) {
/*static*/ bool Identity::validate_announce(const Packet& packet) {
/*
try:
if packet.packet_type == RNS.Packet.ANNOUNCE:
@ -132,7 +132,7 @@ Encrypts information for the identity.
:returns: Ciphertext token as *bytes*.
:raises: *KeyError* if the instance does not hold a public key.
*/
const Bytes Identity::encrypt(const Bytes &plaintext) {
const Bytes Identity::encrypt(const Bytes& plaintext) {
assert(_object);
debug("Identity::encrypt: encrypting data...");
if (!_object->_pub) {
@ -172,7 +172,7 @@ Decrypts information for the identity.
:returns: Plaintext as *bytes*, or *None* if decryption fails.
:raises: *KeyError* if the instance does not hold a private key.
*/
const Bytes Identity::decrypt(const Bytes &ciphertext_token) {
const Bytes Identity::decrypt(const Bytes& ciphertext_token) {
assert(_object);
debug("Identity::decrypt: decrypting data...");
if (!_object->_prv) {
@ -212,7 +212,7 @@ const Bytes Identity::decrypt(const Bytes &ciphertext_token) {
extreme("Identity::decrypt: plaintext: " + plaintext.toHex());
debug("Identity::decrypt: Fernet decrypted data of length " + std::to_string(plaintext.size()));
}
catch (std::exception &e) {
catch (std::exception& e) {
debug("Decryption by " + toString() + " failed: " + e.what());
}
@ -226,7 +226,7 @@ Signs information by the identity.
:returns: Signature as *bytes*.
:raises: *KeyError* if the instance does not hold a private key.
*/
const Bytes Identity::sign(const Bytes &message) {
const Bytes Identity::sign(const Bytes& message) {
assert(_object);
if (!_object->_sig_prv) {
throw std::runtime_error("Signing failed because identity does not hold a private key");
@ -234,7 +234,7 @@ const Bytes Identity::sign(const Bytes &message) {
try {
return _object->_sig_prv->sign(message);
}
catch (std::exception &e) {
catch (std::exception& e) {
error("The identity " + toString() + " could not sign the requested message. The contained exception was: " + e.what());
throw e;
}
@ -248,14 +248,14 @@ Validates the signature of a signed message.
:returns: True if the signature is valid, otherwise False.
:raises: *KeyError* if the instance does not hold a public key.
*/
bool Identity::validate(const Bytes &signature, const Bytes &message) {
bool Identity::validate(const Bytes& signature, const Bytes& message) {
assert(_object);
if (_object->_pub) {
try {
_object->_sig_pub->verify(signature, message);
return true;
}
catch (std::exception &e) {
catch (std::exception& e) {
return false;
}
}
@ -264,7 +264,7 @@ bool Identity::validate(const Bytes &signature, const Bytes &message) {
}
}
void Identity::prove(const Packet &packet, const Destination &destination /*= {Type::NONE}*/) {
void Identity::prove(const Packet& packet, const Destination& destination /*= {Type::NONE}*/) {
assert(_object);
Bytes signature(sign(packet.packet_hash()));
Bytes proof_data;
@ -283,6 +283,6 @@ void Identity::prove(const Packet &packet, const Destination &destination /*= {T
proof.send();
}
void Identity::prove(const Packet &packet) {
void Identity::prove(const Packet& packet) {
prove(packet, {Type::NONE});
}

View File

@ -23,7 +23,7 @@ namespace RNS {
Identity(Type::NoneConstructor none) {
extreme("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) {
Identity(const Identity& identity) : _object(identity._object) {
extreme("Identity object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
Identity(bool create_keys = true);
@ -31,7 +31,7 @@ namespace RNS {
extreme("Identity object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
}
inline Identity& operator = (const Identity &identity) {
inline Identity& operator = (const Identity& identity) {
_object = identity._object;
extreme("Identity object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
@ -39,7 +39,7 @@ namespace RNS {
inline operator bool() const {
return _object.get() != nullptr;
}
inline bool operator < (const Identity &identity) const {
inline bool operator < (const Identity& identity) const {
return _object.get() < identity._object.get();
}
@ -65,7 +65,7 @@ namespace RNS {
:param data: Data to be hashed as *bytes*.
:returns: SHA-256 hash as *bytes*
*/
static inline const Bytes full_hash(const Bytes &data) {
static inline const Bytes full_hash(const Bytes& data) {
return Cryptography::sha256(data);
}
/*
@ -74,7 +74,7 @@ namespace RNS {
:param data: Data to be hashed as *bytes*.
:returns: Truncated SHA-256 hash as *bytes*
*/
static inline const Bytes truncated_hash(const Bytes &data) {
static inline const Bytes truncated_hash(const Bytes& data) {
//return Identity.full_hash(data)[:(Identity.TRUNCATED_HASHLENGTH//8)]
return full_hash(data).left(Type::Identity::TRUNCATED_HASHLENGTH/8);
}
@ -88,26 +88,26 @@ namespace RNS {
return truncated_hash(Cryptography::random(Type::Identity::TRUNCATED_HASHLENGTH/8));
}
static bool validate_announce(const Packet &packet);
static bool validate_announce(const Packet& packet);
inline const Bytes get_salt() { assert(_object); return _object->_hash; }
inline const Bytes get_context() { return {Bytes::NONE}; }
const Bytes encrypt(const Bytes &plaintext);
const Bytes decrypt(const Bytes &ciphertext_token);
const Bytes sign(const Bytes &message);
bool validate(const Bytes &signature, const Bytes &message);
const Bytes encrypt(const Bytes& plaintext);
const Bytes decrypt(const Bytes& ciphertext_token);
const Bytes sign(const Bytes& message);
bool validate(const Bytes& signature, const Bytes& message);
// CBA following default for reference value requires inclusiion of header
//void prove(const Packet &packet, const Destination &destination = {Type::NONE});
void prove(const Packet &packet, const Destination &destination);
void prove(const Packet &packet);
//void prove(const Packet& packet, const Destination& destination = {Type::NONE});
void prove(const Packet& packet, const Destination& destination);
void prove(const Packet& packet);
// getters/setters
inline const Bytes &encryptionPrivateKey() const { assert(_object); return _object->_prv_bytes; }
inline const Bytes &signingPrivateKey() const { assert(_object); return _object->_sig_prv_bytes; }
inline const Bytes &encryptionPublicKey() const { assert(_object); return _object->_prv_bytes; }
inline const Bytes &signingPublicKey() const { assert(_object); return _object->_sig_prv_bytes; }
inline const Bytes &hash() const { assert(_object); return _object->_hash; }
inline const Bytes& encryptionPrivateKey() const { assert(_object); return _object->_prv_bytes; }
inline const Bytes& signingPrivateKey() const { assert(_object); return _object->_sig_prv_bytes; }
inline const Bytes& encryptionPublicKey() const { assert(_object); return _object->_prv_bytes; }
inline const Bytes& signingPublicKey() const { assert(_object); return _object->_sig_prv_bytes; }
inline const Bytes& hash() const { assert(_object); return _object->_hash; }
inline std::string hexhash() const { assert(_object); return _object->_hexhash; }
inline std::string toString() const { assert(_object); return "{Identity:" + _object->_hash.toHex() + "}"; }

View File

@ -6,7 +6,7 @@
using namespace RNS;
using namespace RNS::Type::Interface;
/*virtual*/ inline void Interface::processIncoming(const Bytes &data) {
/*virtual*/ inline void Interface::processIncoming(const Bytes& data) {
extreme("Interface::processIncoming: data: " + data.toHex());
assert(_object);
_object->_rxb += data.size();
@ -15,7 +15,7 @@ using namespace RNS::Type::Interface;
Transport::inbound(data, *this);
}
/*virtual*/ inline void Interface::processOutgoing(const Bytes &data) {
/*virtual*/ inline void Interface::processOutgoing(const Bytes& data) {
extreme("Interface::processOutgoing: data: " + data.toHex());
assert(_object);
_object->_txb += data.size();

View File

@ -16,7 +16,7 @@ namespace RNS {
class AnnounceEntry {
public:
AnnounceEntry() {}
AnnounceEntry(const Bytes &destination, uint64_t time, uint8_t hops, uint64_t emitted, const Bytes &raw) :
AnnounceEntry(const Bytes& destination, uint64_t time, uint8_t hops, uint64_t emitted, const Bytes& raw) :
_destination(destination),
_time(time),
_hops(hops),
@ -39,7 +39,7 @@ namespace RNS {
Interface(Type::NoneConstructor none) {
extreme("Interface object NONE created");
}
Interface(const Interface &interface) : _object(interface._object) {
Interface(const Interface& interface) : _object(interface._object) {
extreme("Interface object copy created");
}
Interface() : _object(new Object()) {
@ -52,7 +52,7 @@ namespace RNS {
extreme("Interface object destroyed");
}
inline Interface& operator = (const Interface &interface) {
inline Interface& operator = (const Interface& interface) {
_object = interface._object;
extreme("Interface object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
@ -60,7 +60,7 @@ namespace RNS {
inline operator bool() const {
return _object.get() != nullptr;
}
inline bool operator < (const Interface &interface) const {
inline bool operator < (const Interface& interface) const {
return _object.get() < interface._object.get();
}
@ -69,10 +69,10 @@ namespace RNS {
void process_announce_queue();
inline void detach() {}
virtual void processIncoming(const Bytes &data);
virtual void processOutgoing(const Bytes &data);
virtual void processIncoming(const Bytes& data);
virtual void processOutgoing(const Bytes& data);
inline void add_announce(AnnounceEntry &entry) { assert(_object); _object->_announce_queue.push_back(entry); }
inline void add_announce(AnnounceEntry& entry) { assert(_object); _object->_announce_queue.push_back(entry); }
// getters/setters
protected:
@ -87,13 +87,13 @@ namespace RNS {
inline bool FWD() const { assert(_object); return _object->_FWD; }
inline bool RPT() const { assert(_object); return _object->_RPT; }
inline std::string name() const { assert(_object); return _object->_name; }
inline const Bytes &ifac_identity() const { assert(_object); return _object->_ifac_identity; }
inline const Bytes& ifac_identity() const { assert(_object); return _object->_ifac_identity; }
inline Type::Interface::modes mode() const { assert(_object); return _object->_mode; }
inline uint32_t bitrate() const { assert(_object); return _object->_bitrate; }
inline uint64_t announce_allowed_at() const { assert(_object); return _object->_announce_allowed_at; }
inline void announce_allowed_at(uint64_t announce_allowed_at) { assert(_object); _object->_announce_allowed_at = announce_allowed_at; }
inline float announce_cap() const { assert(_object); return _object->_announce_cap; }
inline std::list<AnnounceEntry> &announce_queue() const { assert(_object); return _object->_announce_queue; }
inline std::list<AnnounceEntry>& announce_queue() const { assert(_object); return _object->_announce_queue; }
virtual inline std::string toString() const { assert(_object); return "Interface[" + _object->_name + "]"; }
@ -118,7 +118,7 @@ namespace RNS {
uint64_t _announce_allowed_at = 0;
float _announce_cap = 0.0;
std::list<AnnounceEntry> _announce_queue;
//Transport &_owner;
//Transport& _owner;
friend class Interface;
};
std::shared_ptr<Object> _object;

View File

@ -13,11 +13,11 @@ Link::Link() : _object(new Object()) {
}
void Link::set_link_id(const Packet &packet) {
void Link::set_link_id(const Packet& packet) {
assert(_object);
_object->_link_id = packet.getTruncatedHash();
_object->_hash = _object->_link_id;
}
void Link::receive(const Packet &packet) {
void Link::receive(const Packet& packet) {
}

View File

@ -22,7 +22,7 @@ namespace RNS {
Link(Type::NoneConstructor none) {
extreme("Link NONE object created");
}
Link(const Link &link) : _object(link._object) {
Link(const Link& link) : _object(link._object) {
extreme("Link object copy created");
}
Link();
@ -30,24 +30,24 @@ namespace RNS {
extreme("Link object destroyed");
}
inline Link& operator = (const Link &link) {
inline Link& operator = (const Link& link) {
_object = link._object;
return *this;
}
inline operator bool() const {
return _object.get() != nullptr;
}
inline bool operator < (const Link &link) const {
inline bool operator < (const Link& link) const {
return _object.get() < link._object.get();
}
public:
void set_link_id(const Packet &packet);
void receive(const Packet &packet);
void set_link_id(const Packet& packet);
void receive(const Packet& packet);
// getters/setters
inline const Bytes &link_id() const { assert(_object); return _object->_link_id; }
inline const Bytes &hash() const { assert(_object); return _object->_hash; }
inline const Bytes& link_id() const { assert(_object); return _object->_link_id; }
inline const Bytes& hash() const { assert(_object); return _object->_hash; }
inline std::string toString() const { assert(_object); return "{Link: unknown}"; }

View File

@ -28,33 +28,33 @@ namespace RNS {
#ifndef NATIVE
inline void log(const String msg, LogLevel level = LOG_NOTICE) { doLog(msg.c_str(), level); }
#endif
inline void log(const std::string &msg, LogLevel level = LOG_NOTICE) { doLog(msg.c_str(), level); }
inline void log(const std::string& msg, LogLevel level = LOG_NOTICE) { doLog(msg.c_str(), level); }
inline void critical(const char *msg) { doLog(msg, LOG_CRITICAL); }
inline void critical(const std::string &msg) { doLog(msg.c_str(), LOG_CRITICAL); }
inline void critical(const std::string& msg) { doLog(msg.c_str(), LOG_CRITICAL); }
inline void error(const char *msg) { doLog(msg, LOG_ERROR); }
inline void error(const std::string &msg) { doLog(msg.c_str(), LOG_ERROR); }
inline void error(const std::string& msg) { doLog(msg.c_str(), LOG_ERROR); }
inline void warning(const char *msg) { doLog(msg, LOG_WARNING); }
inline void warning(const std::string &msg) { doLog(msg.c_str(), LOG_WARNING); }
inline void warning(const std::string& msg) { doLog(msg.c_str(), LOG_WARNING); }
inline void notice(const char *msg) { doLog(msg, LOG_NOTICE); }
inline void notice(const std::string &msg) { doLog(msg.c_str(), LOG_NOTICE); }
inline void notice(const std::string& msg) { doLog(msg.c_str(), LOG_NOTICE); }
inline void info(const char *msg) { doLog(msg, LOG_INFO); }
inline void info(const std::string &msg) { doLog(msg.c_str(), LOG_INFO); }
inline void info(const std::string& msg) { doLog(msg.c_str(), LOG_INFO); }
inline void verbose(const char *msg) { doLog(msg, LOG_VERBOSE); }
inline void verbose(const std::string &msg) { doLog(msg.c_str(), LOG_VERBOSE); }
inline void verbose(const std::string& msg) { doLog(msg.c_str(), LOG_VERBOSE); }
inline void debug(const char *msg) { doLog(msg, LOG_DEBUG); }
inline void debug(const std::string &msg) { doLog(msg.c_str(), LOG_DEBUG); }
inline void debug(const std::string& msg) { doLog(msg.c_str(), LOG_DEBUG); }
inline void extreme(const char *msg) { doLog(msg, LOG_EXTREME); }
inline void extreme(const std::string &msg) { doLog(msg.c_str(), LOG_EXTREME); }
inline void extreme(const std::string& msg) { doLog(msg.c_str(), LOG_EXTREME); }
void head(const char *msg, LogLevel level = LOG_NOTICE);
inline void head(const std::string &msg, LogLevel level = LOG_NOTICE) { head(msg.c_str(), level); }
inline void head(const std::string& msg, LogLevel level = LOG_NOTICE) { head(msg.c_str(), level); }
}

View File

@ -11,7 +11,7 @@ using namespace RNS;
using namespace RNS::Type::PacketReceipt;
using namespace RNS::Type::Packet;
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)) {
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...");
@ -444,7 +444,7 @@ bool Packet::resend() {
}
}
void Packet::prove(const Destination &destination /*= {Type::NONE}*/) {
void Packet::prove(const Destination& destination /*= {Type::NONE}*/) {
/*
assert(_object);
if (_object->_fromPacked && _object->_destination) {
@ -495,7 +495,7 @@ const Bytes Packet::get_hashable_part() const {
// Generates a special destination that allows Reticulum
// to direct the proof back to the proved packet's sender
//ProofDestination &Packet::generate_proof_destination() {
//ProofDestination& Packet::generate_proof_destination() {
// return ProofDestination();
//}

View File

@ -31,8 +31,8 @@ namespace RNS {
public:
class Callbacks {
public:
using delivery = void(*)(const PacketReceipt &packet_receipt);
using timeout = void(*)(const PacketReceipt &packet_receipt);
using delivery = void(*)(const PacketReceipt& packet_receipt);
using timeout = void(*)(const PacketReceipt& packet_receipt);
public:
delivery _delivery = nullptr;
timeout _timeout = nullptr;
@ -41,18 +41,18 @@ namespace RNS {
public:
PacketReceipt(Type::NoneConstructor none) {}
PacketReceipt(const PacketReceipt &packet_receipt) : _object(packet_receipt._object) {}
PacketReceipt(const PacketReceipt& packet_receipt) : _object(packet_receipt._object) {}
PacketReceipt() : _object(new Object()) {}
PacketReceipt(const Packet &packet) {}
PacketReceipt(const Packet& packet) {}
inline PacketReceipt& operator = (const PacketReceipt &packet_receipt) {
inline PacketReceipt& operator = (const PacketReceipt& packet_receipt) {
_object = packet_receipt._object;
return *this;
}
inline operator bool() const {
return _object.get() != nullptr;
}
inline bool operator < (const PacketReceipt &packet_receipt) const {
inline bool operator < (const PacketReceipt& packet_receipt) const {
return _object.get() < packet_receipt._object.get();
}
@ -126,14 +126,14 @@ namespace RNS {
Packet(Type::NoneConstructor none) {
extreme("Packet NONE object created");
}
Packet(const Packet &packet) : _object(packet._object) {
Packet(const Packet& packet) : _object(packet._object) {
extreme("Packet object copy created");
}
Packet(const Destination &destination, const Interface &attached_interface, const Bytes &data, Type::Packet::types packet_type = Type::Packet::DATA, Type::Packet::context_types context = Type::Packet::CONTEXT_NONE, Type::Transport::types transport_type = Type::Transport::BROADCAST, Type::Packet::header_types header_type = Type::Packet::HEADER_1, const Bytes &transport_id = {Bytes::NONE}, bool create_receipt = true);
Packet(const Destination &destination, const Bytes &data, Type::Packet::types packet_type = Type::Packet::DATA, Type::Packet::context_types context = Type::Packet::CONTEXT_NONE, Type::Transport::types transport_type = Type::Transport::BROADCAST, Type::Packet::header_types header_type = Type::Packet::HEADER_1, const Bytes &transport_id = {Bytes::NONE}, bool create_receipt = true) : Packet(destination, {Type::NONE}, data, packet_type, context, transport_type, header_type, transport_id, create_receipt) {}
Packet(const Destination& destination, const Interface& attached_interface, const Bytes& data, Type::Packet::types packet_type = Type::Packet::DATA, Type::Packet::context_types context = Type::Packet::CONTEXT_NONE, Type::Transport::types transport_type = Type::Transport::BROADCAST, Type::Packet::header_types header_type = Type::Packet::HEADER_1, const Bytes& transport_id = {Bytes::NONE}, bool create_receipt = true);
Packet(const Destination& destination, const Bytes& data, Type::Packet::types packet_type = Type::Packet::DATA, Type::Packet::context_types context = Type::Packet::CONTEXT_NONE, Type::Transport::types transport_type = Type::Transport::BROADCAST, Type::Packet::header_types header_type = Type::Packet::HEADER_1, const Bytes& transport_id = {Bytes::NONE}, bool create_receipt = true) : Packet(destination, {Type::NONE}, data, packet_type, context, transport_type, header_type, transport_id, create_receipt) {}
virtual ~Packet();
inline Packet& operator = (const Packet &packet) {
inline Packet& operator = (const Packet& packet) {
_object = packet._object;
extreme("Packet object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
@ -141,7 +141,7 @@ namespace RNS {
inline operator bool() const {
return _object.get() != nullptr;
}
inline bool operator < (const Packet &packet) const {
inline bool operator < (const Packet& packet) const {
return _object.get() < packet._object.get();
}
@ -160,21 +160,21 @@ namespace RNS {
bool unpack();
bool send();
bool resend();
void prove(const Destination &destination = {Type::NONE});
void prove(const Destination& destination = {Type::NONE});
void update_hash();
const Bytes get_hash() const;
const Bytes getTruncatedHash() const;
const Bytes get_hashable_part() const;
//zProofDestination &generate_proof_destination();
//zProofDestination& generate_proof_destination();
// getters/setters
inline const Destination &destination() const { assert(_object); return _object->_destination; }
inline void destination(const Destination &destination) { assert(_object); _object->_destination = destination; }
inline const Link &link() const { assert(_object); return _object->_link; }
inline void link(const Link &link) { assert(_object); _object->_link = link; }
inline const Interface &attached_interface() const { assert(_object); return _object->_attached_interface; }
inline const Interface &receiving_interface() const { assert(_object); return _object->_receiving_interface; }
inline void receiving_interface(const Interface &receiving_interface) { assert(_object); _object->_receiving_interface = receiving_interface; }
inline const Destination& destination() const { assert(_object); return _object->_destination; }
inline void destination(const Destination& destination) { assert(_object); _object->_destination = destination; }
inline const Link& link() const { assert(_object); return _object->_link; }
inline void link(const Link& link) { assert(_object); _object->_link = link; }
inline const Interface& attached_interface() const { assert(_object); return _object->_attached_interface; }
inline const Interface& receiving_interface() const { assert(_object); return _object->_receiving_interface; }
inline void receiving_interface(const Interface& receiving_interface) { assert(_object); _object->_receiving_interface = receiving_interface; }
inline Type::Packet::header_types header_type() const { assert(_object); return _object->_header_type; }
inline Type::Transport::types transport_type() const { assert(_object); return _object->_transport_type; }
inline Type::Destination::types destination_type() const { assert(_object); return _object->_destination_type; }
@ -185,17 +185,17 @@ namespace RNS {
inline time_t sent_at() const { assert(_object); return _object->_sent_at; }
inline void sent_at(time_t sent_at) { assert(_object); _object->_sent_at = sent_at; }
inline bool create_receipt() const { assert(_object); return _object->_create_receipt; }
inline const PacketReceipt &receipt() const { assert(_object); return _object->_receipt; }
inline void receipt(const PacketReceipt &receipt) { assert(_object); _object->_receipt = receipt; }
inline const PacketReceipt& receipt() const { assert(_object); return _object->_receipt; }
inline void receipt(const PacketReceipt& receipt) { assert(_object); _object->_receipt = receipt; }
inline uint8_t flags() const { assert(_object); return _object->_flags; }
inline uint8_t hops() const { assert(_object); return _object->_hops; }
inline void hops(uint8_t hops) { assert(_object); _object->_hops = hops; }
inline const Bytes &packet_hash() const { assert(_object); return _object->_packet_hash; }
inline const Bytes &destination_hash() const { assert(_object); return _object->_destination_hash; }
inline const Bytes &transport_id() const { assert(_object); return _object->_transport_id; }
inline void transport_id(const Bytes &transport_id) { assert(_object); _object->_transport_id = transport_id; }
inline const Bytes &raw() const { assert(_object); return _object->_raw; }
inline const Bytes &data() const { assert(_object); return _object->_data; }
inline const Bytes& packet_hash() const { assert(_object); return _object->_packet_hash; }
inline const Bytes& destination_hash() const { assert(_object); return _object->_destination_hash; }
inline const Bytes& transport_id() const { assert(_object); return _object->_transport_id; }
inline void transport_id(const Bytes& transport_id) { assert(_object); _object->_transport_id = transport_id; }
inline const Bytes& raw() const { assert(_object); return _object->_raw; }
inline const Bytes& data() const { assert(_object); return _object->_data; }
inline std::string toString() const { assert(_object); return "{Packet:" + _object->_packet_hash.toHex() + "}"; }
@ -204,7 +204,7 @@ namespace RNS {
private:
class Object {
public:
Object(const Destination &destination, const Interface &attached_interface) : _destination(destination), _attached_interface(attached_interface) {}
Object(const Destination& destination, const Interface& attached_interface) : _destination(destination), _attached_interface(attached_interface) {}
virtual ~Object() {}
private:
Destination _destination = {Type::NONE};

View File

@ -21,13 +21,13 @@ namespace RNS {
Reticulum(Type::NoneConstructor none) {
extreme("Reticulum NONE object created");
}
Reticulum(const Reticulum &reticulum) : _object(reticulum._object) {
Reticulum(const Reticulum& reticulum) : _object(reticulum._object) {
extreme("Reticulum object copy created");
}
Reticulum();
virtual ~Reticulum();
inline Reticulum& operator = (const Reticulum &reticulum) {
inline Reticulum& operator = (const Reticulum& reticulum) {
_object = reticulum._object;
extreme("Reticulum object copy created by assignment, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
return *this;
@ -35,7 +35,7 @@ namespace RNS {
inline operator bool() const {
return _object.get() != nullptr;
}
inline bool operator < (const Reticulum &reticulum) const {
inline bool operator < (const Reticulum& reticulum) const {
return _object.get() < reticulum._object.get();
}

View File

@ -6,15 +6,15 @@
#include <map>
#include <assert.h>
//void testBytesDefault(const RNS::Bytes &bytes = {RNS::Bytes::NONE}) {
void testBytesDefault(const RNS::Bytes &bytes = {}) {
//void testBytesDefault(const RNS::Bytes& bytes = {RNS::Bytes::NONE}) {
void testBytesDefault(const RNS::Bytes& bytes = {}) {
assert(!bytes);
assert(bytes.size() == 0);
assert(bytes.data() == nullptr);
}
RNS::Bytes ref("Test");
const RNS::Bytes &testBytesReference() {
const RNS::Bytes& testBytesReference() {
// NOTE: Can NOT return local instance as reference!!!
//RNS::Bytes ref("Test");
RNS::extreme("returning...");

View File

@ -57,7 +57,7 @@ using namespace RNS::Utilities;
/*static*/ Reticulum Transport::_owner({Type::NONE});
/*static*/ Identity Transport::_identity({Type::NONE});
/*static*/ void Transport::start(const Reticulum &reticulum_instance) {
/*static*/ void Transport::start(const Reticulum& reticulum_instance) {
_jobs_running = true;
_owner = reticulum_instance;
@ -86,7 +86,7 @@ using namespace RNS::Utilities;
packet_hashlist = umsgpack.unpackb(file.read());
file.close();
}
catch (std::exception &e) {
catch (std::exception& e) {
error("Could not load packet hashlist from storage, the contained exception was: " + e.what());
}
}
@ -247,7 +247,7 @@ using namespace RNS::Utilities;
// Process active and pending link lists
if (time(nullptr) > _links_last_checked + Transport.links_check_interval) {
for (auto &link : _pending_links) {
for (auto& link : _pending_links) {
if link.status() == RNS.Link.CLOSED:
// If we are not a Transport Instance, finding a pending link
// that was never activated will trigger an expiry of the path
@ -270,7 +270,7 @@ using namespace RNS::Utilities;
Transport.pending_links.remove(link)
}
for (auto &link : _active_links) {
for (auto& link : _active_links) {
if link.status == RNS.Link.CLOSED:
Transport.active_links.remove(link)
}
@ -551,23 +551,23 @@ using namespace RNS::Utilities;
pass
*/
}
catch (std::exception &e) {
catch (std::exception& e) {
error("An exception occurred while running Transport jobs.");
error("The contained exception was: " + std::string(e.what()));
}
_jobs_running = false;
for (auto &packet : outgoing) {
for (auto& packet : outgoing) {
packet.send();
}
for (auto &destination_hash : path_requests) {
for (auto& destination_hash : path_requests) {
request_path(destination_hash);
}
}
/*static*/ void Transport::transmit(Interface &interface, const Bytes &raw) {
/*static*/ void Transport::transmit(Interface& interface, const Bytes& raw) {
try {
//if hasattr(interface, "ifac_identity") and interface.ifac_identity != None:
if (interface.ifac_identity()) {
@ -612,12 +612,12 @@ using namespace RNS::Utilities;
interface.processOutgoing(raw);
}
}
catch (std::exception &e) {
catch (std::exception& e) {
error("Error while transmitting on " + interface.toString() + ". The contained exception was: " + e.what());
}
}
/*static*/ bool Transport::outbound(Packet &packet) {
/*static*/ bool Transport::outbound(Packet& packet) {
extreme("Transport::outbound()");
extreme("Transport::outbound: destination=" + packet.destination_hash().toHex() + " hops=" + std::to_string(packet.hops()));
@ -638,7 +638,7 @@ using namespace RNS::Utilities;
extreme("Transport::outbound: Path to destination is known");
//outbound_interface = Transport.destination_table[packet.destination_hash][5]
DestinationEntry destination_entry = (*_destination_table.find(packet.destination_hash())).second;
Interface &outbound_interface = destination_entry._receiving_interface;
Interface& outbound_interface = destination_entry._receiving_interface;
// If there's more than one hop to the destination, and we know
// a path, we insert the packet into transport by adding the next
@ -714,7 +714,7 @@ using namespace RNS::Utilities;
else {
extreme("Transport::outbound: Path to destination is unknown");
bool stored_hash = false;
for (const Interface &interface : _interfaces) {
for (const Interface& interface : _interfaces) {
extreme("Transport::outbound: Checking interface " + interface.toString());
if (interface.OUT()) {
bool should_transmit = true;
@ -744,7 +744,7 @@ using namespace RNS::Utilities;
//local_destination = next((d for d in Transport.destinations if d.hash == packet.destination_hash), None)
//Destination local_destination({Type::NONE});
bool found_local = false;
for (auto &destination : _destinations) {
for (auto& destination : _destinations) {
if (destination.hash() == packet.destination_hash()) {
//local_destination = destination;
found_local = true;
@ -757,7 +757,7 @@ using namespace RNS::Utilities;
//extreme("Allowing announce broadcast on roaming-mode interface from instance-local destination");
}
else {
const Interface &from_interface = next_hop_interface(packet.destination_hash());
const Interface& from_interface = next_hop_interface(packet.destination_hash());
//if from_interface == None or not hasattr(from_interface, "mode"):
if (!from_interface || from_interface.mode() == Type::Interface::MODE_NONE) {
should_transmit = false;
@ -788,7 +788,7 @@ using namespace RNS::Utilities;
// CBA TODO confirm that above pattern just selects the first matching destination
//Destination local_destination({Typeestination::NONE});
bool found_local = false;
for (auto &destination : _destinations) {
for (auto& destination : _destinations) {
if (destination.hash() == packet.destination_hash()) {
//local_destination = destination;
found_local = true;
@ -801,7 +801,7 @@ using namespace RNS::Utilities;
//extreme("Allowing announce broadcast on boundary-mode interface from instance-local destination");
}
else {
const Interface &from_interface = next_hop_interface(packet.destination_hash());
const Interface& from_interface = next_hop_interface(packet.destination_hash());
if (!from_interface || from_interface.mode() == Type::Interface::MODE_NONE) {
should_transmit = false;
if (!from_interface) {
@ -846,7 +846,7 @@ using namespace RNS::Utilities;
should_transmit = false;
if (interface.announce_queue().size() < Type::Reticulum::MAX_QUEUED_ANNOUNCES) {
bool should_queue = true;
for (auto &entry : interface.announce_queue()) {
for (auto& entry : interface.announce_queue()) {
if (entry._destination == packet.destination_hash()) {
uint64_t emission_timestamp = announce_emitted(packet);
should_queue = false;
@ -967,7 +967,7 @@ using namespace RNS::Utilities;
return sent;
}
/*static*/ bool Transport::packet_filter(const Packet &packet) {
/*static*/ bool Transport::packet_filter(const Packet& packet) {
// TODO: Think long and hard about this.
// Is it even strictly necessary with the current
// transport rules?
@ -1041,7 +1041,7 @@ using namespace RNS::Utilities;
return false;
}
/*static*/ void Transport::inbound(const Bytes &raw, const Interface &interface /*= {Type::NONE}*/) {
/*static*/ void Transport::inbound(const Bytes& raw, const Interface& interface /*= {Type::NONE}*/) {
extreme("Transport::inbound()");
/*
// If interface access codes are enabled,
@ -1214,7 +1214,7 @@ using namespace RNS::Utilities;
if (packet.destination_type() == Type::Destination::PLAIN && packet.transport_type() == Type::Transport::BROADCAST) {
// Send to all interfaces except the originator
if (from_local_client) {
for (const Interface &interface : _interfaces) {
for (const Interface& interface : _interfaces) {
if (interface != packet.receiving_interface()) {
extreme("Transport::inbound: Broadcasting packet on " + interface.toString());
transmit(const_cast<Interface&>(interface), packet.raw());
@ -1224,7 +1224,7 @@ using namespace RNS::Utilities;
// If the packet was not from a local client, send
// it directly to all local clients
else {
for (auto &interface : _local_client_interfaces) {
for (auto& interface : _local_client_interfaces) {
extreme("Transport::inbound: Broadcasting packet on " + interface.toString());
transmit(const_cast<Interface&>(interface), packet.raw());
}
@ -1303,7 +1303,7 @@ using namespace RNS::Utilities;
new_raw << packet.raw().mid(2);
}
Interface &outbound_interface = destination_entry._receiving_interface;
Interface& outbound_interface = destination_entry._receiving_interface;
if (packet.packet_type() == Type::Packet::LINKREQUEST) {
uint64_t now = OS::time();
@ -1403,7 +1403,7 @@ using namespace RNS::Utilities;
//p local_destination = next((d for d in Transport.destinations if d.hash == packet.destination_hash), None)
//Destination local_destination({Type::NONE});
bool found_local = false;
for (auto &destination : _destinations) {
for (auto& destination : _destinations) {
if (destination.hash() == packet.destination_hash()) {
//local_destination = destination;
found_local = true;
@ -1421,8 +1421,8 @@ using namespace RNS::Utilities;
// another node. If it is, we're removing the
// announce in question from our pending table
if (Reticulum::transport_enabled() && _announce_table.count(packet.destination_hash()) > 0) {
//AnnounceEntry &announce_entry = _announce_table[packet.destination_hash()];
AnnounceEntry &announce_entry = (*_announce_table.find(packet.destination_hash())).second;
//AnnounceEntry& announce_entry = _announce_table[packet.destination_hash()];
AnnounceEntry& announce_entry = (*_announce_table.find(packet.destination_hash())).second;
if ((packet.hops() - 1) == announce_entry._hops) {
debug("Heard a local rebroadcast of announce for " + packet.destination_hash().toHex());
@ -1454,7 +1454,7 @@ using namespace RNS::Utilities;
// local to this system, and that hops are less than the max
//if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1):
bool found_local = false;
for (auto &destination : _destinations) {
for (auto& destination : _destinations) {
if (destination.hash() == packet.destination_hash()) {
found_local = true;
break;
@ -1499,7 +1499,7 @@ using namespace RNS::Utilities;
uint64_t path_expires = destination_entry._expires;
uint64_t path_announce_emitted = 0;
for (const Bytes &path_random_blob : destination_entry._random_blobs) {
for (const Bytes& path_random_blob : destination_entry._random_blobs) {
//path_announce_emitted = std::max(path_announce_emitted, int.from_bytes(path_random_blob[5:10], "big"))
//zpath_announce_emitted = std::max(path_announce_emitted, int.from_bytes(path_random_blob[5:10], "big"))
if (path_announce_emitted >= announce_emitted) {
@ -1666,7 +1666,7 @@ using namespace RNS::Utilities;
// TODO: Shouldn't the context be PATH_RESPONSE in the first case here?
if (from_local_client(packet) && packet.context() == Packet.PATH_RESPONSE) {
for (auto &local_interface : _local_client_interfaces) {
for (auto& local_interface : _local_client_interfaces) {
if packet.receiving_interface() != local_interface) {
Packet new_announce(
announce_destination,
@ -1685,7 +1685,7 @@ using namespace RNS::Utilities;
}
}
else {
for (auto &local_interface : _local_client_interfaces) {
for (auto& local_interface : _local_client_interfaces) {
if (packet.receiving_interface() != local_interface) {
Packet new_announce(
announce_destination,
@ -1764,7 +1764,7 @@ using namespace RNS::Utilities;
// Call externally registered callbacks from apps
// wanting to know when an announce arrives
if (packet.context() != Type::Packet::PATH_RESPONSE) {
for (auto &handler : Transport.announce_handlers) {
for (auto& handler : Transport.announce_handlers) {
try {
// Check that the announced destination matches
// the handlers aspect filter
@ -1789,7 +1789,7 @@ using namespace RNS::Utilities;
);
}
}
catch (std::exception &e) {
catch (std::exception& e) {
error("Error while processing external announce callback.");
error("The contained exception was: " + e.what();
}
@ -1811,7 +1811,7 @@ using namespace RNS::Utilities;
else if (packet.packet_type() == Type::Packet::LINKREQUEST) {
extreme("Transport::inbound: Packet is LINKREQUEST");
if (!packet.transport_id() || packet.transport_id() == _identity.hash()) {
for (auto &destination : _destinations) {
for (auto& destination : _destinations) {
if (destination.hash() == packet.destination_hash() && destination.type() == packet.destination_type()) {
packet.destination(destination);
// CBA iterator over std::set is always const so need to make temporarily mutable
@ -1826,7 +1826,7 @@ using namespace RNS::Utilities;
else if (packet.packet_type() == Type::Packet::DATA) {
extreme("Transport::inbound: Packet is DATA");
if (packet.destination_type() == Type::Destination::LINK) {
for (auto &link : _active_links) {
for (auto& link : _active_links) {
if (link.link_id() == packet.destination_hash()) {
packet.link(link);
const_cast<Link&>(link).receive(packet);
@ -1834,7 +1834,7 @@ using namespace RNS::Utilities;
}
}
else {
for (auto &destination : _destinations) {
for (auto& destination : _destinations) {
if (destination.hash() == packet.destination_hash() && destination.type() == packet.destination_type()) {
packet.destination(destination);
const_cast<Destination&>(destination).receive(packet);
@ -1849,7 +1849,7 @@ using namespace RNS::Utilities;
packet.prove();
}
}
catch (std::exception &e) {
catch (std::exception& e) {
error(std::string("Error while executing proof request callback. The contained exception was: ") + e.what());
}
}
@ -1952,7 +1952,7 @@ using namespace RNS::Utilities;
_jobs_locked = false;
}
/*static*/ void Transport::synthesize_tunnel(const Interface &interface) {
/*static*/ void Transport::synthesize_tunnel(const Interface& interface) {
/*
Bytes interface_hash = interface.get_hash();
Bytes public_key = _identity.get_public_key();
@ -1975,7 +1975,7 @@ using namespace RNS::Utilities;
*/
}
/*static*/ void Transport::tunnel_synthesize_handler(const Bytes &data, const Packet &packet) {
/*static*/ void Transport::tunnel_synthesize_handler(const Bytes& data, const Packet& packet) {
/*
try:
expected_length = RNS.Identity.KEYSIZE//8+RNS.Identity.HASHLENGTH//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8+RNS.Identity.SIGLENGTH//8
@ -2001,7 +2001,7 @@ using namespace RNS::Utilities;
*/
}
/*static*/ void Transport::handle_tunnel(const Bytes &tunnel_id, const Interface &interface) {
/*static*/ void Transport::handle_tunnel(const Bytes& tunnel_id, const Interface& interface) {
/*
expires = time.time() + Transport.DESTINATION_TIMEOUT
if not tunnel_id in Transport.tunnels:
@ -2055,17 +2055,17 @@ using namespace RNS::Utilities;
*/
}
/*static*/ void Transport::register_interface(Interface &interface) {
/*static*/ void Transport::register_interface(Interface& interface) {
extreme("Transport: Registering interface " + interface.toString());
_interfaces.push_back(interface);
extreme("Transport: Listing all registered interfaces...");
for (Interface &found_interface : _interfaces) {
for (Interface& found_interface : _interfaces) {
extreme("Transport: Found interface " + found_interface.toString());
}
// CBA TODO set or add transport as listener on interface to receive incoming packets
}
/*static*/ void Transport::deregister_interface(const Interface &interface) {
/*static*/ void Transport::deregister_interface(const Interface& interface) {
extreme("Transport: Deregistering interface " + interface.toString());
//if (_interfaces.find(interface) != _interfaces.end()) {
// _interfaces.erase(interface);
@ -2078,11 +2078,11 @@ using namespace RNS::Utilities;
}
}
/*static*/ void Transport::register_destination(Destination &destination) {
/*static*/ void Transport::register_destination(Destination& destination) {
extreme("Transport: Registering destination " + destination.toString());
destination.mtu(Type::Reticulum::MTU);
if (destination.direction() == Type::Destination::IN) {
for (auto &registered_destination : _destinations) {
for (auto& registered_destination : _destinations) {
if (destination.hash() == registered_destination.hash()) {
//raise KeyError("Attempt to register an already registered destination.")
throw std::runtime_error("Attempt to register an already registered destination.");
@ -2099,14 +2099,14 @@ using namespace RNS::Utilities;
}
}
/*static*/ void Transport::deregister_destination(const Destination &destination) {
/*static*/ void Transport::deregister_destination(const Destination& destination) {
extreme("Transport: Deregistering destination " + destination.toString());
if (_destinations.find(destination) != _destinations.end()) {
_destinations.erase(destination);
}
}
/*static*/ void Transport::register_link(const Link &link) {
/*static*/ void Transport::register_link(const Link& link) {
/*
extreme("Transport: Registering link " + link.toString());
if (link.initiator()) {
@ -2118,7 +2118,7 @@ using namespace RNS::Utilities;
*/
}
/*static*/ void Transport::activate_link(Link &link) {
/*static*/ void Transport::activate_link(Link& link) {
/*
extreme("Transport: Activating link " + link.toString());
if (_pending_links.find(link) != _pending_links.end()) {
@ -2159,8 +2159,8 @@ Deregisters an announce handler.
}
}
/*static*/ Interface Transport::find_interface_from_hash(const Bytes &interface_hash) {
for (const Interface &interface : _interfaces) {
/*static*/ Interface Transport::find_interface_from_hash(const Bytes& interface_hash) {
for (const Interface& interface : _interfaces) {
if (interface.get_hash() == interface_hash) {
return interface;
}
@ -2169,7 +2169,7 @@ Deregisters an announce handler.
return {Type::NONE};
}
/*static*/ bool Transport::should_cache(const Packet &packet) {
/*static*/ bool Transport::should_cache(const Packet& packet) {
// TODO: Rework the caching system. It's currently
// not very useful to even cache Resource proofs,
// disabling it for now, until redesigned.
@ -2184,7 +2184,7 @@ Deregisters an announce handler.
// means that they have not had their hop count
// increased yet! Take note of this when reading from
// the packet cache.
/*static*/ void Transport::cache(const Packet &packet, bool force_cache /*= false*/) {
/*static*/ void Transport::cache(const Packet& packet, bool force_cache /*= false*/) {
/*
if (should_cache(packet) || force_cache) {
try {
@ -2200,14 +2200,14 @@ Deregisters an announce handler.
file.write(umsgpack.packb([packet.raw, interface_reference]))
file.close()
}
catch (std::exception &e) {
catch (std::exception& e) {
error("Error writing packet to cache. The contained exception was: " + e.what());
}
}
*/
}
/*static*/ Packet Transport::get_cached_packet(const Bytes &packet_hash) {
/*static*/ Packet Transport::get_cached_packet(const Bytes& packet_hash) {
/*
try {
//packet_hash = RNS.hexrep(packet_hash, delimit=False)
@ -2230,7 +2230,7 @@ Deregisters an announce handler.
else:
return None
}
catch (std::exception &e) {
catch (std::exception& e) {
error("Exception occurred while getting cached packet.");
error("The contained exception was: " + e.what());
}
@ -2239,9 +2239,9 @@ Deregisters an announce handler.
return {Type::NONE};
}
/*static*/ bool Transport::cache_request_packet(const Packet &packet) {
/*static*/ bool Transport::cache_request_packet(const Packet& packet) {
if (packet.data().size() == Type::Identity::HASHLENGTH/8) {
const Packet &cached_packet = get_cached_packet(packet.data());
const Packet& cached_packet = get_cached_packet(packet.data());
if (cached_packet) {
// If the packet was retrieved from the local
@ -2260,8 +2260,8 @@ Deregisters an announce handler.
}
}
/*static*/ void Transport::cache_request(const Bytes &packet_hash, const Destination &destination) {
const Packet &cached_packet = get_cached_packet(packet_hash);
/*static*/ void Transport::cache_request(const Bytes& packet_hash, const Destination& destination) {
const Packet& cached_packet = get_cached_packet(packet_hash);
if (cached_packet) {
// The packet was found in the local cache,
// replay it to the Transport instance.
@ -2279,7 +2279,7 @@ Deregisters an announce handler.
:param destination_hash: A destination hash as *bytes*.
:returns: *True* if a path to the destination is known, otherwise *False*.
*/
/*static*/ bool Transport::has_path(const Bytes &destination_hash) {
/*static*/ bool Transport::has_path(const Bytes& destination_hash) {
if (_destination_table.find(destination_hash) != _destination_table.end()) {
return true;
}
@ -2292,7 +2292,7 @@ Deregisters an announce handler.
:param destination_hash: A destination hash as *bytes*.
:returns: The number of hops to the specified destination, or ``RNS.Transport.PATHFINDER_M`` if the number of hops is unknown.
*/
/*static*/ uint8_t Transport::hops_to(const Bytes &destination_hash) {
/*static*/ uint8_t Transport::hops_to(const Bytes& destination_hash) {
auto iter = _destination_table.find(destination_hash);
if (iter != _destination_table.end()) {
DestinationEntry destination_entry = (*iter).second;
@ -2307,7 +2307,7 @@ Deregisters an announce handler.
:param destination_hash: A destination hash as *bytes*.
:returns: The destination hash as *bytes* for the next hop to the specified destination, or *None* if the next hop is unknown.
*/
/*static*/ Bytes Transport::next_hop(const Bytes &destination_hash) {
/*static*/ Bytes Transport::next_hop(const Bytes& destination_hash) {
auto iter = _destination_table.find(destination_hash);
if (iter != _destination_table.end()) {
DestinationEntry destination_entry = (*iter).second;
@ -2322,7 +2322,7 @@ Deregisters an announce handler.
:param destination_hash: A destination hash as *bytes*.
:returns: The interface for the next hop to the specified destination, or *None* if the interface is unknown.
*/
/*static*/ Interface Transport::next_hop_interface(const Bytes &destination_hash) {
/*static*/ Interface Transport::next_hop_interface(const Bytes& destination_hash) {
auto iter = _destination_table.find(destination_hash);
if (iter != _destination_table.end()) {
DestinationEntry destination_entry = (*iter).second;
@ -2333,7 +2333,7 @@ Deregisters an announce handler.
}
}
/*static*/ bool Transport::expire_path(const Bytes &destination_hash) {
/*static*/ bool Transport::expire_path(const Bytes& destination_hash) {
auto iter = _destination_table.find(destination_hash);
if (iter != _destination_table.end()) {
DestinationEntry destination_entry = (*iter).second;
@ -2354,8 +2354,8 @@ will announce it.
:param destination_hash: A destination hash as *bytes*.
:param on_interface: If specified, the path request will only be sent on this interface. In normal use, Reticulum handles this automatically, and this parameter should not be used.
*/
///*static*/ void Transport::request_path(const Bytes &destination_hash, const Interface &on_interface /*= {Type::NONE}*/, const Bytes &tag /*= {}*/, bool recursive /*= false*/) {
/*static*/ void Transport::request_path(const Bytes &destination_hash, const Interface &on_interface, const Bytes &tag /*= {}*/, bool recursive /*= false*/) {
///*static*/ void Transport::request_path(const Bytes& destination_hash, const Interface& on_interface /*= {Type::NONE}*/, const Bytes& tag /*= {}*/, bool recursive /*= false*/) {
/*static*/ void Transport::request_path(const Bytes& destination_hash, const Interface& on_interface, const Bytes& tag /*= {}*/, bool recursive /*= false*/) {
/*
if tag == None:
request_tag = RNS.Identity.get_random_hash()
@ -2399,11 +2399,11 @@ will announce it.
*/
}
/*static*/ void Transport::request_path(const Bytes &destination_hash) {
/*static*/ void Transport::request_path(const Bytes& destination_hash) {
return request_path(destination_hash, {Type::NONE});
}
/*static*/ void Transport::path_request_handler(const Bytes &data, const Packet &packet) {
/*static*/ void Transport::path_request_handler(const Bytes& data, const Packet& packet) {
/*
try:
// If there is at least bytes enough for a destination
@ -2455,7 +2455,7 @@ will announce it.
*/
}
/*static*/ void Transport::path_request(const Bytes &destination_hash, bool is_from_local_client, const Interface &attached_interface, const Bytes &requestor_transport_id /*= {}*/, const Bytes &tag /*= {}*/) {
/*static*/ void Transport::path_request(const Bytes& destination_hash, bool is_from_local_client, const Interface& attached_interface, const Bytes& requestor_transport_id /*= {}*/, const Bytes& tag /*= {}*/) {
/*
should_search_for_unknown = False
@ -2480,7 +2480,7 @@ will announce it.
//local_destination = next((d for d in Transport.destinations if d.hash == destination_hash), None)
Destination local_destination({Type::NONE});
for (auto &destination : _destinations) {
for (auto& destination : _destinations) {
if (destination.hash() == destination_hash) {
local_destination = destination;
break;
@ -2573,7 +2573,7 @@ will announce it.
*/
}
/*static*/ bool Transport::from_local_client(const Packet &packet) {
/*static*/ bool Transport::from_local_client(const Packet& packet) {
/*
if hasattr(packet.receiving_interface, "parent_interface"):
return Transport.is_local_client_interface(packet.receiving_interface)
@ -2584,7 +2584,7 @@ will announce it.
return false;
}
/*static*/ bool Transport::is_local_client_interface(const Interface &interface) {
/*static*/ bool Transport::is_local_client_interface(const Interface& interface) {
/*
if hasattr(interface, "parent_interface"):
if hasattr(interface.parent_interface, "is_local_shared_instance"):
@ -2598,7 +2598,7 @@ will announce it.
return false;
}
/*static*/ bool Transport::interface_to_shared_instance(const Interface &interface) {
/*static*/ bool Transport::interface_to_shared_instance(const Interface& interface) {
/*
if hasattr(interface, "is_connected_to_shared_instance"):
return True
@ -2679,7 +2679,7 @@ will announce it.
*/
}
/*static*/ bool Transport::announce_emitted(const Packet &packet) {
/*static*/ bool Transport::announce_emitted(const Packet& packet) {
/*
random_blob = packet.data[RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8:RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8+10]
announce_emitted = int.from_bytes(random_blob[5:10], "big")

View File

@ -23,10 +23,10 @@ namespace RNS {
class AnnounceHandler {
public:
AnnounceHandler(const std::string &aspect_filter) {
AnnounceHandler(const std::string& aspect_filter) {
_aspect_filter = aspect_filter;
}
virtual void received_announce(const Bytes &destination_hash, const Identity &announced_identity, const Bytes &app_data) = 0;
virtual void received_announce(const Bytes& destination_hash, const Identity& announced_identity, const Bytes& app_data) = 0;
private:
std::string _aspect_filter;
};
@ -41,7 +41,7 @@ namespace RNS {
private:
class DestinationEntry {
public:
DestinationEntry(uint64_t time, Bytes received_from, uint8_t announce_hops, uint64_t expires, std::set<Bytes> random_blobs, Interface &receiving_interface, const Packet &packet) :
DestinationEntry(uint64_t time, Bytes received_from, uint8_t announce_hops, uint64_t expires, std::set<Bytes> random_blobs, Interface& receiving_interface, const Packet& packet) :
_timestamp(time),
_received_from(received_from),
_hops(announce_hops),
@ -57,13 +57,13 @@ namespace RNS {
uint8_t _hops = 0;
uint64_t _expires = 0;
std::set<Bytes> _random_blobs;
Interface &_receiving_interface;
const Packet &_packet;
Interface& _receiving_interface;
const Packet& _packet;
};
class AnnounceEntry {
public:
AnnounceEntry(uint64_t timestamp, uint16_t retransmit_timeout, uint8_t retries, Bytes received_from, uint8_t hops, const Packet &packet, uint8_t local_rebroadcasts, bool block_rebroadcasts, const Interface &attached_interface) :
AnnounceEntry(uint64_t timestamp, uint16_t retransmit_timeout, uint8_t retries, Bytes received_from, uint8_t hops, const Packet& packet, uint8_t local_rebroadcasts, bool block_rebroadcasts, const Interface& attached_interface) :
_timestamp(timestamp),
_retransmit_timeout(retransmit_timeout),
_retries(retries),
@ -81,15 +81,15 @@ namespace RNS {
uint8_t _retries = 0;
Bytes _received_from;
uint8_t _hops = 0;
const Packet &_packet;
const Packet& _packet;
uint8_t _local_rebroadcasts = 0;
bool _block_rebroadcasts = false;
const Interface &_attached_interface;
const Interface& _attached_interface;
};
class LinkEntry {
public:
LinkEntry(uint64_t timestamp, const Bytes &next_hop, const Interface &outbound_interface, uint8_t remaining_hops, const Interface &receiving_interface, uint8_t hops, const Bytes &destination_hash, bool validated, uint64_t proof_timeout) :
LinkEntry(uint64_t timestamp, const Bytes& next_hop, const Interface& outbound_interface, uint8_t remaining_hops, const Interface& receiving_interface, uint8_t hops, const Bytes& destination_hash, bool validated, uint64_t proof_timeout) :
_timestamp(timestamp),
_next_hop(next_hop),
_outbound_interface(outbound_interface),
@ -104,9 +104,9 @@ namespace RNS {
public:
uint64_t _timestamp = 0;
Bytes _next_hop;
const Interface &_outbound_interface;
const Interface& _outbound_interface;
uint8_t _remaining_hops = 0;
const Interface &_receiving_interface;
const Interface& _receiving_interface;
uint8_t _hops = 0;
Bytes _destination_hash;
bool _validated = false;
@ -115,15 +115,15 @@ namespace RNS {
class ReverseEntry {
public:
ReverseEntry(const Interface &receiving_interface, const Interface &outbound_interface, uint64_t timestamp) :
ReverseEntry(const Interface& receiving_interface, const Interface& outbound_interface, uint64_t timestamp) :
_receiving_interface(receiving_interface),
_outbound_interface(outbound_interface),
_timestamp(timestamp)
{
}
public:
const Interface &_receiving_interface;
const Interface &_outbound_interface;
const Interface& _receiving_interface;
const Interface& _outbound_interface;
uint64_t _timestamp = 0;
};
@ -173,50 +173,50 @@ namespace RNS {
static const uint8_t MAX_RATE_TIMESTAMPS = 16; // Maximum number of announce timestamps to keep per destination
public:
static void start(const Reticulum &reticulum_instance);
static void start(const Reticulum& reticulum_instance);
static void jobloop();
static void jobs();
static void transmit(Interface &interface, const Bytes &raw);
static bool outbound(Packet &packet);
static bool packet_filter(const Packet &packet);
//static void inbound(const Bytes &raw, const Interface &interface = {Type::NONE});
static void inbound(const Bytes &raw, const Interface &interface);
static void inbound(const Bytes &raw);
static void synthesize_tunnel(const Interface &interface);
static void tunnel_synthesize_handler(const Bytes &data, const Packet &packet);
static void handle_tunnel(const Bytes &tunnel_id, const Interface &interface);
static void register_interface(Interface &interface);
static void deregister_interface(const Interface &interface);
static void register_destination(Destination &destination);
static void deregister_destination(const Destination &destination);
static void register_link(const Link &link);
static void activate_link(Link &link);
static void transmit(Interface& interface, const Bytes& raw);
static bool outbound(Packet& packet);
static bool packet_filter(const Packet& packet);
//static void inbound(const Bytes& raw, const Interface& interface = {Type::NONE});
static void inbound(const Bytes& raw, const Interface& interface);
static void inbound(const Bytes& raw);
static void synthesize_tunnel(const Interface& interface);
static void tunnel_synthesize_handler(const Bytes& data, const Packet& packet);
static void handle_tunnel(const Bytes& tunnel_id, const Interface& interface);
static void register_interface(Interface& interface);
static void deregister_interface(const Interface& interface);
static void register_destination(Destination& destination);
static void deregister_destination(const Destination& destination);
static void register_link(const Link& link);
static void activate_link(Link& link);
static void register_announce_handler(HAnnounceHandler handler);
static void deregister_announce_handler(HAnnounceHandler handler);
static Interface find_interface_from_hash(const Bytes &interface_hash);
static bool should_cache(const Packet &packet);
static void cache(const Packet &packet, bool force_cache = false);
static Packet get_cached_packet(const Bytes &packet_hash);
static bool cache_request_packet(const Packet &packet);
static void cache_request(const Bytes &packet_hash, const Destination &destination);
static bool has_path(const Bytes &destination_hash);
static uint8_t hops_to(const Bytes &destination_hash);
static Bytes next_hop(const Bytes &destination_hash);
static Interface next_hop_interface(const Bytes &destination_hash);
static bool expire_path(const Bytes &destination_hash);
//static void request_path(const Bytes &destination_hash, const Interface &on_interface = {Type::NONE}, const Bytes &tag = {}, bool recursive = false);
static void request_path(const Bytes &destination_hash, const Interface &on_interface, const Bytes &tag = {}, bool recursive = false);
static void request_path(const Bytes &destination_hash);
static void path_request_handler(const Bytes &data, const Packet &packet);
static void path_request(const Bytes &destination_hash, bool is_from_local_client, const Interface &attached_interface, const Bytes &requestor_transport_id = {}, const Bytes &tag = {});
static bool from_local_client(const Packet &packet);
static bool is_local_client_interface(const Interface &interface);
static bool interface_to_shared_instance(const Interface &interface);
static Interface find_interface_from_hash(const Bytes& interface_hash);
static bool should_cache(const Packet& packet);
static void cache(const Packet& packet, bool force_cache = false);
static Packet get_cached_packet(const Bytes& packet_hash);
static bool cache_request_packet(const Packet& packet);
static void cache_request(const Bytes& packet_hash, const Destination& destination);
static bool has_path(const Bytes& destination_hash);
static uint8_t hops_to(const Bytes& destination_hash);
static Bytes next_hop(const Bytes& destination_hash);
static Interface next_hop_interface(const Bytes& destination_hash);
static bool expire_path(const Bytes& destination_hash);
//static void request_path(const Bytes& destination_hash, const Interface& on_interface = {Type::NONE}, const Bytes& tag = {}, bool recursive = false);
static void request_path(const Bytes& destination_hash, const Interface& on_interface, const Bytes& tag = {}, bool recursive = false);
static void request_path(const Bytes& destination_hash);
static void path_request_handler(const Bytes& data, const Packet& packet);
static void path_request(const Bytes& destination_hash, bool is_from_local_client, const Interface& attached_interface, const Bytes& requestor_transport_id = {}, const Bytes& tag = {});
static bool from_local_client(const Packet& packet);
static bool is_local_client_interface(const Interface& interface);
static bool interface_to_shared_instance(const Interface& interface);
static void detach_interfaces();
static void shared_connection_disappeared();
static void shared_connection_reappeared();
static void drop_announce_queues();
static bool announce_emitted(const Packet &packet);
static bool announce_emitted(const Packet& packet);
static void save_packet_hashlist();
static void save_path_table();
static void save_tunnel_table();

View File

@ -46,10 +46,10 @@ public:
virtual ~TestInterface() {
name("deleted");
}
virtual void processIncoming(const RNS::Bytes &data) {
virtual void processIncoming(const RNS::Bytes& data) {
RNS::extreme("TestInterface.processIncoming: data: " + data.toHex());
}
virtual void processOutgoing(const RNS::Bytes &data) {
virtual void processOutgoing(const RNS::Bytes& data) {
RNS::extreme("TestInterface.processOutgoing: data: " + data.toHex());
}
virtual inline std::string toString() const { return "TestInterface[" + name() + "]"; }
@ -57,28 +57,28 @@ public:
class TestLoopbackInterface : public RNS::Interface {
public:
TestLoopbackInterface(RNS::Interface &loopback_interface) : RNS::Interface("TestLoopbackInterface"), _loopback_interface(loopback_interface) {
TestLoopbackInterface(RNS::Interface& loopback_interface) : RNS::Interface("TestLoopbackInterface"), _loopback_interface(loopback_interface) {
IN(true);
OUT(true);
}
TestLoopbackInterface(RNS::Interface &loopback_interface, const char *name) : RNS::Interface(name), _loopback_interface(loopback_interface) {
TestLoopbackInterface(RNS::Interface& loopback_interface, const char *name) : RNS::Interface(name), _loopback_interface(loopback_interface) {
IN(true);
OUT(true);
}
virtual ~TestLoopbackInterface() {
name("deleted");
}
virtual void processIncoming(const RNS::Bytes &data) {
virtual void processIncoming(const RNS::Bytes& data) {
RNS::extreme("TestLoopbackInterface.processIncoming: data: " + data.toHex());
_loopback_interface.processOutgoing(data);
}
virtual void processOutgoing(const RNS::Bytes &data) {
virtual void processOutgoing(const RNS::Bytes& data) {
RNS::extreme("TestLoopbackInterface.processOutgoing: data: " + data.toHex());
_loopback_interface.processIncoming(data);
}
virtual inline std::string toString() const { return "TestLoopbackInterface[" + name() + "]"; }
private:
RNS::Interface &_loopback_interface;
RNS::Interface& _loopback_interface;
};
class TestOutInterface : public RNS::Interface {
@ -94,7 +94,7 @@ public:
virtual ~TestOutInterface() {
name("(deleted)");
}
virtual void processOutgoing(const RNS::Bytes &data) {
virtual void processOutgoing(const RNS::Bytes& data) {
RNS::head("TestOutInterface.processOutgoing: data: " + data.toHex(), RNS::LOG_EXTREME);
RNS::Interface::processOutgoing(data);
}
@ -114,14 +114,14 @@ public:
virtual ~TestInInterface() {
name("(deleted)");
}
virtual void processIncoming(const RNS::Bytes &data) {
virtual void processIncoming(const RNS::Bytes& data) {
RNS::head("TestInInterface.processIncoming: data: " + data.toHex(), RNS::LOG_EXTREME);
RNS::Interface::processIncoming(data);
}
virtual inline std::string toString() const { return "TestInInterface[" + name() + "]"; }
};
void onPacket(const RNS::Bytes &data, const RNS::Packet &packet) {
void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
RNS::head("onPacket: data: " + data.toHex(), RNS::LOG_EXTREME);
RNS::head("onPacket: data string: \"" + data.toString() + "\"", RNS::LOG_EXTREME);
//RNS::head("onPacket: " + packet.debugString(), RNS::LOG_EXTREME);
@ -186,14 +186,14 @@ void setup() {
{
std::map<RNS::Bytes, RNS::Destination&> destinations;
destinations.insert({destination.hash(), destination});
//for (RNS::Destination &destination : destinations) {
for (auto &[hash, destination] : destinations) {
//for (RNS::Destination& destination : destinations) {
for (auto& [hash, destination] : destinations) {
RNS::extreme("Iterated destination: " + destination.toString());
}
RNS::Bytes hash = destination.hash();
auto iter = destinations.find(hash);
if (iter != destinations.end()) {
RNS::Destination &destination = (*iter).second;
RNS::Destination& destination = (*iter).second;
RNS::extreme("Found destination: " + destination.toString());
}
return;
@ -261,7 +261,7 @@ int main(void) {
std::set<std::reference_wrapper<RNS::Interface>, std::less<RNS::Interface>> interfaces;
interfaces.insert(testinterface);
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface &interface = (*iter);
RNS::Interface& interface = (*iter);
RNS::extreme("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).processOutgoing(data);
@ -274,7 +274,7 @@ int main(void) {
std::set<std::reference_wrapper<RNS::Interface>, std::less<RNS::Interface>> interfaces;
interfaces.insert(testinterface);
for (auto &interface : interfaces) {
for (auto& interface : interfaces) {
RNS::extreme("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).processOutgoing(data);
@ -288,7 +288,7 @@ int main(void) {
std::list<std::reference_wrapper<RNS::Interface>> interfaces;
interfaces.push_back(testinterface);
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface &interface = (*iter);
RNS::Interface& interface = (*iter);
RNS::extreme("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).processOutgoing(data);
@ -301,8 +301,8 @@ int main(void) {
std::list<std::reference_wrapper<RNS::Interface>> interfaces;
interfaces.push_back(testinterface);
//for (auto &interface : interfaces) {
for (RNS::Interface &interface : interfaces) {
//for (auto& interface : interfaces) {
for (RNS::Interface& interface : interfaces) {
RNS::extreme("Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).processOutgoing(data);
@ -316,14 +316,14 @@ int main(void) {
TestInterface testinterface;
interfaces.push_back(testinterface);
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface &interface = (*iter);
RNS::Interface& interface = (*iter);
RNS::extreme("1 Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).processOutgoing(data);
}
}
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
RNS::Interface &interface = (*iter);
RNS::Interface& interface = (*iter);
RNS::extreme("2 Found interface: " + interface.toString());
RNS::Bytes data;
const_cast<RNS::Interface&>(interface).processOutgoing(data);