mirror of
https://github.com/markqvist/reticulum-cpp.git
synced 2024-10-01 02:55:46 -04:00
WIP: Fixed archictectural flaw with Interfaces
Fixed packet transmit issue caused by fundamental issue of attempting to send on a copy of an interface which is not properly associated with the actual method overrides of the derived class (the interface implementation). Fix was to use methods in the Object data to callback to the original (implementation) instance of the object. General clean-up to remove some early testing code.
This commit is contained in:
parent
9f0e71bb81
commit
c39e9e7fee
@ -47,7 +47,6 @@ Destination::Destination(const Identity& identity, const directions direction, c
|
|||||||
_object->_hash = hash(_object->_identity, app_name, fullaspects.c_str());
|
_object->_hash = hash(_object->_identity, app_name, fullaspects.c_str());
|
||||||
_object->_hexhash = _object->_hash.toHex();
|
_object->_hexhash = _object->_hash.toHex();
|
||||||
debug("Destination::Destination: hash: " + _object->_hash.toHex());
|
debug("Destination::Destination: hash: " + _object->_hash.toHex());
|
||||||
// CBA TEST CRASH
|
|
||||||
debug("Destination::Destination: creating name hash...");
|
debug("Destination::Destination: creating name hash...");
|
||||||
//p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
|
//p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
|
||||||
_object->_name_hash = name_hash(app_name, aspects);
|
_object->_name_hash = name_hash(app_name, aspects);
|
||||||
@ -59,6 +58,31 @@ Destination::Destination(const Identity& identity, const directions direction, c
|
|||||||
mem("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
mem("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Destination::Destination(const Identity& identity, const Type::Destination::directions direction, const Type::Destination::types type, const Bytes& hash) : _object(new Object(identity)) {
|
||||||
|
assert(_object);
|
||||||
|
mem("Destination object creating..., this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
|
|
||||||
|
_object->_type = type;
|
||||||
|
_object->_direction = direction;
|
||||||
|
|
||||||
|
if (_object->_identity && _object->_type == PLAIN) {
|
||||||
|
throw std::invalid_argument("Selected destination type PLAIN cannot hold an identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
_object->_hash = hash;
|
||||||
|
_object->_hexhash = _object->_hash.toHex();
|
||||||
|
debug("Destination::Destination: hash: " + _object->_hash.toHex());
|
||||||
|
debug("Destination::Destination: creating name hash...");
|
||||||
|
//p self.name_hash = RNS.Identity.full_hash(self.expand_name(None, app_name, *aspects).encode("utf-8"))[:(RNS.Identity.NAME_HASH_LENGTH//8)]
|
||||||
|
_object->_name_hash = name_hash("unknown", "unknown");
|
||||||
|
debug("Destination::Destination: name hash: " + _object->_name_hash.toHex());
|
||||||
|
|
||||||
|
debug("Destination::Destination: calling register_destination");
|
||||||
|
Transport::register_destination(*this);
|
||||||
|
|
||||||
|
mem("Destination object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
|
}
|
||||||
|
|
||||||
/*virtual*/ Destination::~Destination() {
|
/*virtual*/ Destination::~Destination() {
|
||||||
mem("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
mem("Destination object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
if (_object && _object.use_count() == 1) {
|
if (_object && _object.use_count() == 1) {
|
||||||
|
@ -66,6 +66,12 @@ namespace RNS {
|
|||||||
const char* app_name,
|
const char* app_name,
|
||||||
const char* aspects
|
const char* aspects
|
||||||
);
|
);
|
||||||
|
Destination(
|
||||||
|
const Identity& identity,
|
||||||
|
const Type::Destination::directions direction,
|
||||||
|
const Type::Destination::types type,
|
||||||
|
const Bytes& hash
|
||||||
|
);
|
||||||
virtual ~Destination();
|
virtual ~Destination();
|
||||||
|
|
||||||
inline Destination& operator = (const Destination& destination) {
|
inline Destination& operator = (const Destination& destination) {
|
||||||
@ -158,7 +164,8 @@ namespace RNS {
|
|||||||
inline Type::Destination::directions direction() const { assert(_object); return _object->_direction; }
|
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 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& hash() const { assert(_object); return _object->_hash; }
|
||||||
inline void hash(const Bytes& hash) { assert(_object); _object->_hash = hash; _object->_hexhash = _object->_hash.toHex(); }
|
// CBA Don't allow changing destination after construction since it's used as key in collections
|
||||||
|
//inline void hash(const Bytes& hash) { assert(_object); _object->_hash = hash; _object->_hexhash = _object->_hash.toHex(); }
|
||||||
inline const Bytes& link_id() const { assert(_object); return _object->_link_id; }
|
inline const Bytes& link_id() const { assert(_object); return _object->_link_id; }
|
||||||
inline uint16_t mtu() const { assert(_object); return _object->_mtu; }
|
inline uint16_t mtu() const { assert(_object); return _object->_mtu; }
|
||||||
inline void mtu(uint16_t mtu) { assert(_object); _object->_mtu = mtu; }
|
inline void mtu(uint16_t mtu) { assert(_object); _object->_mtu = mtu; }
|
||||||
|
@ -8,8 +8,8 @@ using namespace RNS::Type::Interface;
|
|||||||
|
|
||||||
/*static*/ uint8_t Interface::DISCOVER_PATHS_FOR = MODE_ACCESS_POINT | MODE_GATEWAY;
|
/*static*/ uint8_t Interface::DISCOVER_PATHS_FOR = MODE_ACCESS_POINT | MODE_GATEWAY;
|
||||||
|
|
||||||
/*virtual*/ inline void Interface::processIncoming(const Bytes& data) {
|
/*virtual*/ inline void Interface::on_incoming(const Bytes& data) {
|
||||||
extreme("Interface::processIncoming: data: " + data.toHex());
|
extreme("Interface::on_incoming: data: " + data.toHex());
|
||||||
assert(_object);
|
assert(_object);
|
||||||
_object->_rxb += data.size();
|
_object->_rxb += data.size();
|
||||||
// CBA TODO implement concept of owner or a callback mechanism for incoming data
|
// CBA TODO implement concept of owner or a callback mechanism for incoming data
|
||||||
@ -17,8 +17,8 @@ using namespace RNS::Type::Interface;
|
|||||||
Transport::inbound(data, *this);
|
Transport::inbound(data, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ inline void Interface::processOutgoing(const Bytes& data) {
|
/*virtual*/ inline void Interface::on_outgoing(const Bytes& data) {
|
||||||
extreme("Interface::processOutgoing: data: " + data.toHex());
|
extreme("Interface::on_outgoing: data: " + data.toHex());
|
||||||
assert(_object);
|
assert(_object);
|
||||||
_object->_txb += data.size();
|
_object->_txb += data.size();
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ void Interface::process_announce_queue() {
|
|||||||
}
|
}
|
||||||
_object->_announce_allowed_at = now + wait_time;
|
_object->_announce_allowed_at = now + wait_time;
|
||||||
|
|
||||||
self.processOutgoing(selected["raw"])
|
self.on_outgoing(selected["raw"])
|
||||||
|
|
||||||
if selected in self.announce_queue:
|
if selected in self.announce_queue:
|
||||||
self.announce_queue.remove(selected)
|
self.announce_queue.remove(selected)
|
||||||
|
@ -45,13 +45,18 @@ namespace RNS {
|
|||||||
Interface(const Interface& interface) : _object(interface._object) {
|
Interface(const Interface& interface) : _object(interface._object) {
|
||||||
mem("Interface object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
mem("Interface object copy created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
}
|
}
|
||||||
Interface() : _object(new Object()) {
|
Interface() : _object(new Object(*this)) {
|
||||||
mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
}
|
}
|
||||||
Interface(const char* name) : _object(new Object(name)) {
|
Interface(const char* name) : _object(new Object(*this, name)), _creator(true) {
|
||||||
mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
mem("Interface object created, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
}
|
}
|
||||||
virtual ~Interface() {
|
virtual ~Interface() {
|
||||||
|
if (_creator) {
|
||||||
|
// clear reference to parent in object foir safety
|
||||||
|
assert(_object);
|
||||||
|
_object->_parent = {Type::NONE};
|
||||||
|
}
|
||||||
mem("Interface object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
mem("Interface object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,22 +66,42 @@ namespace RNS {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline operator bool() const {
|
inline operator bool() const {
|
||||||
|
extreme("Interface object bool, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
return _object.get() != nullptr;
|
return _object.get() != nullptr;
|
||||||
}
|
}
|
||||||
inline bool operator < (const Interface& interface) const {
|
inline bool operator < (const Interface& interface) const {
|
||||||
|
extreme("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
return _object.get() < interface._object.get();
|
return _object.get() < interface._object.get();
|
||||||
}
|
}
|
||||||
|
inline bool operator > (const Interface& interface) const {
|
||||||
|
extreme("Interface object <, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
|
return _object.get() > interface._object.get();
|
||||||
|
}
|
||||||
|
inline bool operator == (const Interface& interface) const {
|
||||||
|
extreme("Interface object ==, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
|
return _object.get() == interface._object.get();
|
||||||
|
}
|
||||||
|
inline bool operator != (const Interface& interface) const {
|
||||||
|
extreme("Interface object !=, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||||
|
return _object.get() != interface._object.get();
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Bytes get_hash() const;
|
const Bytes get_hash() const;
|
||||||
void process_announce_queue();
|
void process_announce_queue();
|
||||||
inline void detach() {}
|
inline void detach() {}
|
||||||
|
|
||||||
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); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// CBA TODO these should NOT called internally, and should likely be protected (only to be overridden and called by Object)
|
||||||
|
virtual void on_incoming(const Bytes& data);
|
||||||
|
virtual void on_outgoing(const Bytes& data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//inline void process_incoming(const Bytes& data) { assert(_object); _object->process_incoming(data); }
|
||||||
|
inline void process_outgoing(const Bytes& data) { assert(_object); _object->process_outgoing(data); }
|
||||||
|
|
||||||
// getters/setters
|
// getters/setters
|
||||||
protected:
|
protected:
|
||||||
inline void IN(bool IN) { assert(_object); _object->_IN = IN; }
|
inline void IN(bool IN) { assert(_object); _object->_IN = IN; }
|
||||||
@ -116,10 +141,14 @@ namespace RNS {
|
|||||||
private:
|
private:
|
||||||
class Object {
|
class Object {
|
||||||
public:
|
public:
|
||||||
Object() { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
Object(Interface& parent) : _parent(parent) { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||||
Object(const char* name) : _name(name) { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
Object(Interface& parent, const char* name) : _parent(parent), _name(name) { mem("Interface::Data object created, this: " + std::to_string((uintptr_t)this)); }
|
||||||
virtual ~Object() { mem("Interface::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
|
virtual ~Object() { mem("Interface::Data object destroyed, this: " + std::to_string((uintptr_t)this)); }
|
||||||
private:
|
private:
|
||||||
|
//virtual inline void process_incoming(const Bytes& data) { if (_parent) { _parent.on_incoming(data); } }
|
||||||
|
virtual inline void process_outgoing(const Bytes& data) { if (_parent) { _parent.on_outgoing(data); } }
|
||||||
|
private:
|
||||||
|
Interface& _parent;
|
||||||
bool _IN = false;
|
bool _IN = false;
|
||||||
bool _OUT = false;
|
bool _OUT = false;
|
||||||
bool _FWD = false;
|
bool _FWD = false;
|
||||||
@ -141,6 +170,7 @@ namespace RNS {
|
|||||||
friend class Interface;
|
friend class Interface;
|
||||||
};
|
};
|
||||||
std::shared_ptr<Object> _object;
|
std::shared_ptr<Object> _object;
|
||||||
|
bool _creator = false;
|
||||||
|
|
||||||
friend class Transport;
|
friend class Transport;
|
||||||
};
|
};
|
||||||
|
@ -92,19 +92,19 @@ Serial.println(available);
|
|||||||
Serial.println("RSSI: " + String(LoRa.packetRssi()));
|
Serial.println("RSSI: " + String(LoRa.packetRssi()));
|
||||||
Serial.println("Snr: " + String(LoRa.packetSnr()));
|
Serial.println("Snr: " + String(LoRa.packetSnr()));
|
||||||
|
|
||||||
processIncoming(buffer);
|
on_incoming(buffer);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ void LoRaInterface::processIncoming(const Bytes& data) {
|
/*virtual*/ void LoRaInterface::on_incoming(const Bytes& data) {
|
||||||
debug("LoRaInterface.processIncoming: data: " + data.toHex());
|
debug("LoRaInterface.on_incoming: data: " + data.toHex());
|
||||||
Interface::processIncoming(data);
|
Interface::on_incoming(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ void LoRaInterface::processOutgoing(const Bytes& data) {
|
/*virtual*/ void LoRaInterface::on_outgoing(const Bytes& data) {
|
||||||
debug("LoRaInterface.processOutgoing: data: " + data.toHex());
|
debug("LoRaInterface.on_outgoing: data: " + data.toHex());
|
||||||
try {
|
try {
|
||||||
if (online()) {
|
if (online()) {
|
||||||
extreme("LoRaInterface: sending " + std::to_string(data.size()) + " bytes...");
|
extreme("LoRaInterface: sending " + std::to_string(data.size()) + " bytes...");
|
||||||
@ -124,7 +124,7 @@ Serial.println(available);
|
|||||||
#endif
|
#endif
|
||||||
extreme("LoRaInterface: sent bytes");
|
extreme("LoRaInterface: sent bytes");
|
||||||
}
|
}
|
||||||
Interface::processOutgoing(data);
|
Interface::on_outgoing(data);
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
error("Could not transmit on " + toString() + ". The contained exception was: " + e.what());
|
error("Could not transmit on " + toString() + ". The contained exception was: " + e.what());
|
||||||
|
@ -38,11 +38,12 @@ namespace RNS { namespace Interfaces {
|
|||||||
void stop();
|
void stop();
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
virtual void processIncoming(const Bytes& data);
|
|
||||||
virtual void processOutgoing(const Bytes& data);
|
|
||||||
|
|
||||||
virtual inline std::string toString() const { return "LoRaInterface[" + name() + "]"; }
|
virtual inline std::string toString() const { return "LoRaInterface[" + name() + "]"; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void on_incoming(const Bytes& data);
|
||||||
|
virtual void on_outgoing(const Bytes& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint16_t HW_MTU = 508;
|
const uint16_t HW_MTU = 508;
|
||||||
//uint8_t buffer[Type::Reticulum::MTU] = {0};
|
//uint8_t buffer[Type::Reticulum::MTU] = {0};
|
||||||
|
@ -200,7 +200,7 @@ void UDPInterface::loop() {
|
|||||||
size_t len = udp.read(_buffer.writable(Type::Reticulum::MTU), Type::Reticulum::MTU);
|
size_t len = udp.read(_buffer.writable(Type::Reticulum::MTU), Type::Reticulum::MTU);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
_buffer.resize(len);
|
_buffer.resize(len);
|
||||||
processIncoming(_buffer);
|
on_incoming(_buffer);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
size_t available = 0;
|
size_t available = 0;
|
||||||
@ -211,20 +211,20 @@ void UDPInterface::loop() {
|
|||||||
if (len < available) {
|
if (len < available) {
|
||||||
_buffer.resize(len);
|
_buffer.resize(len);
|
||||||
}
|
}
|
||||||
processIncoming(_buffer);
|
on_incoming(_buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ void UDPInterface::processIncoming(const Bytes& data) {
|
/*virtual*/ void UDPInterface::on_incoming(const Bytes& data) {
|
||||||
debug("UDPInterface.processIncoming: data: " + data.toHex());
|
debug("UDPInterface.on_incoming: data: " + data.toHex());
|
||||||
Interface::processIncoming(data);
|
Interface::on_incoming(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ void UDPInterface::processOutgoing(const Bytes& data) {
|
/*virtual*/ void UDPInterface::on_outgoing(const Bytes& data) {
|
||||||
debug("UDPInterface.processOutgoing: data: " + data.toHex());
|
debug("UDPInterface.on_outgoing: data: " + data.toHex());
|
||||||
try {
|
try {
|
||||||
if (online()) {
|
if (online()) {
|
||||||
// Send packet
|
// Send packet
|
||||||
@ -243,7 +243,7 @@ void UDPInterface::loop() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Interface::processOutgoing(data);
|
Interface::on_outgoing(data);
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
error("Could not transmit on " + toString() + ". The contained exception was: " + e.what());
|
error("Could not transmit on " + toString() + ". The contained exception was: " + e.what());
|
||||||
|
@ -37,12 +37,13 @@ namespace RNS { namespace Interfaces {
|
|||||||
void stop();
|
void stop();
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
virtual void processIncoming(const Bytes& data);
|
|
||||||
virtual void processOutgoing(const Bytes& data);
|
|
||||||
|
|
||||||
//virtual inline std::string toString() const { return "UDPInterface[" + name() + "/" + bind_ip + ":" + bind_port + "]"; }
|
//virtual inline std::string toString() const { return "UDPInterface[" + name() + "/" + bind_ip + ":" + bind_port + "]"; }
|
||||||
virtual inline std::string toString() const { return "UDPInterface[" + name() + "]"; }
|
virtual inline std::string toString() const { return "UDPInterface[" + name() + "]"; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void on_incoming(const Bytes& data);
|
||||||
|
virtual void on_outgoing(const Bytes& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint16_t HW_MTU = 1064;
|
const uint16_t HW_MTU = 1064;
|
||||||
//uint8_t buffer[Type::Reticulum::MTU] = {0};
|
//uint8_t buffer[Type::Reticulum::MTU] = {0};
|
||||||
|
@ -30,7 +30,7 @@ void testReference() {
|
|||||||
RNS::Interface& interface = (*iter);
|
RNS::Interface& interface = (*iter);
|
||||||
RNS::extreme("Found interface: " + interface.toString());
|
RNS::extreme("Found interface: " + interface.toString());
|
||||||
RNS::Bytes data;
|
RNS::Bytes data;
|
||||||
const_cast<RNS::Interface&>(interface).processOutgoing(data);
|
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
*/
|
*/
|
||||||
@ -43,7 +43,7 @@ void testReference() {
|
|||||||
for (auto& interface : interfaces) {
|
for (auto& interface : interfaces) {
|
||||||
RNS::extreme("Found interface: " + interface.toString());
|
RNS::extreme("Found interface: " + interface.toString());
|
||||||
RNS::Bytes data;
|
RNS::Bytes data;
|
||||||
const_cast<RNS::Interface&>(interface).processOutgoing(data);
|
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
*/
|
*/
|
||||||
@ -57,7 +57,7 @@ void testReference() {
|
|||||||
RNS::Interface& interface = (*iter);
|
RNS::Interface& interface = (*iter);
|
||||||
RNS::extreme("Found interface: " + interface.toString());
|
RNS::extreme("Found interface: " + interface.toString());
|
||||||
RNS::Bytes data;
|
RNS::Bytes data;
|
||||||
const_cast<RNS::Interface&>(interface).processOutgoing(data);
|
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
*/
|
*/
|
||||||
@ -71,7 +71,7 @@ void testReference() {
|
|||||||
for (RNS::Interface& interface : interfaces) {
|
for (RNS::Interface& interface : interfaces) {
|
||||||
RNS::extreme("Found interface: " + interface.toString());
|
RNS::extreme("Found interface: " + interface.toString());
|
||||||
RNS::Bytes data;
|
RNS::Bytes data;
|
||||||
const_cast<RNS::Interface&>(interface).processOutgoing(data);
|
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
*/
|
*/
|
||||||
@ -85,14 +85,14 @@ void testReference() {
|
|||||||
RNS::Interface& interface = (*iter);
|
RNS::Interface& interface = (*iter);
|
||||||
RNS::extreme("1 Found interface: " + interface.toString());
|
RNS::extreme("1 Found interface: " + interface.toString());
|
||||||
RNS::Bytes data;
|
RNS::Bytes data;
|
||||||
const_cast<RNS::Interface&>(interface).processOutgoing(data);
|
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
|
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::extreme("2 Found interface: " + interface.toString());
|
||||||
RNS::Bytes data;
|
RNS::Bytes data;
|
||||||
const_cast<RNS::Interface&>(interface).processOutgoing(data);
|
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
*/
|
*/
|
||||||
|
@ -368,8 +368,9 @@ using namespace RNS::Utilities;
|
|||||||
}
|
}
|
||||||
//p announce_data = packet.data
|
//p announce_data = packet.data
|
||||||
Identity announce_identity(Identity::recall(announce_entry._packet.destination_hash()));
|
Identity announce_identity(Identity::recall(announce_entry._packet.destination_hash()));
|
||||||
Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, "unknown", "unknown");
|
//Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, "unknown", "unknown");
|
||||||
announce_destination.hash(announce_entry._packet.destination_hash());
|
//announce_destination.hash(announce_entry._packet.destination_hash());
|
||||||
|
Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, announce_entry._packet.destination_hash());
|
||||||
//P announce_destination.hexhash = announce_destination.hash.hex()
|
//P announce_destination.hexhash = announce_destination.hash.hex()
|
||||||
|
|
||||||
//if (announce_entry._attached_interface) {
|
//if (announce_entry._attached_interface) {
|
||||||
@ -686,11 +687,12 @@ using namespace RNS::Utilities;
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
// Send it
|
// Send it
|
||||||
interface.processOutgoing(masked_raw)
|
interface.on_outgoing(masked_raw)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
interface.processOutgoing(raw);
|
//interface.on_outgoing(raw);
|
||||||
|
interface.process_outgoing(raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
@ -1463,6 +1465,7 @@ using namespace RNS::Utilities;
|
|||||||
);
|
);
|
||||||
_reverse_table.insert({packet.getTruncatedHash(), reverse_entry});
|
_reverse_table.insert({packet.getTruncatedHash(), reverse_entry});
|
||||||
}
|
}
|
||||||
|
extreme("Transport::outbound: Sending packet to next hop...");
|
||||||
#if defined(INTERFACES_SET)
|
#if defined(INTERFACES_SET)
|
||||||
transmit(const_cast<Interface&>(outbound_interface), new_raw);
|
transmit(const_cast<Interface&>(outbound_interface), new_raw);
|
||||||
#else
|
#else
|
||||||
@ -1812,8 +1815,9 @@ using namespace RNS::Utilities;
|
|||||||
// transmit the announce to them immediately
|
// transmit the announce to them immediately
|
||||||
if (_local_client_interfaces.size() > 0) {
|
if (_local_client_interfaces.size() > 0) {
|
||||||
Identity announce_identity(Identity::recall(packet.destination_hash()));
|
Identity announce_identity(Identity::recall(packet.destination_hash()));
|
||||||
Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, "unknown", "unknown");
|
//Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, "unknown", "unknown");
|
||||||
announce_destination.hash(packet.destination_hash());
|
//announce_destination.hash(packet.destination_hash());
|
||||||
|
Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, packet.destination_hash());
|
||||||
//announce_destination.hexhash(announce_destination.hash().toHex());
|
//announce_destination.hexhash(announce_destination.hash().toHex());
|
||||||
Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE;
|
Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE;
|
||||||
Bytes announce_data = packet.data();
|
Bytes announce_data = packet.data();
|
||||||
@ -1869,8 +1873,9 @@ using namespace RNS::Utilities;
|
|||||||
|
|
||||||
debug("Got matching announce, answering waiting discovery path request for " + packet.destination_hash().toHex() + " on " + attached_interface.toString());
|
debug("Got matching announce, answering waiting discovery path request for " + packet.destination_hash().toHex() + " on " + attached_interface.toString());
|
||||||
Identity announce_identity(Identity::recall(packet.destination_hash()));
|
Identity announce_identity(Identity::recall(packet.destination_hash()));
|
||||||
Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, "unknown", "unknown");
|
//Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, "unknown", "unknown");
|
||||||
announce_destination.hash(packet.destination_hash());
|
//announce_destination.hash(packet.destination_hash());
|
||||||
|
Destination announce_destination(announce_identity, Type::Destination::OUT, Type::Destination::SINGLE, packet.destination_hash());
|
||||||
//announce_destination.hexhash(announce_destination.hash().toHex());
|
//announce_destination.hexhash(announce_destination.hash().toHex());
|
||||||
Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE;
|
Type::Packet::context_types announce_context = Type::Packet::CONTEXT_NONE;
|
||||||
Bytes announce_data = packet.data();
|
Bytes announce_data = packet.data();
|
||||||
@ -2327,6 +2332,9 @@ using namespace RNS::Utilities;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
extreme("Transport:register_destination: Skipping registraion (not direction IN) of destination " + destination.toString());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#if defined(DESTINATIONS_SET)
|
#if defined(DESTINATIONS_SET)
|
||||||
@ -2901,12 +2909,12 @@ will announce it.
|
|||||||
}
|
}
|
||||||
else if (should_search_for_unknown) {
|
else if (should_search_for_unknown) {
|
||||||
if (_discovery_path_requests.find(destination_hash) != _discovery_path_requests.end()) {
|
if (_discovery_path_requests.find(destination_hash) != _discovery_path_requests.end()) {
|
||||||
debug("There is already a waiting path request for destination " + destination_hash.toHex() + " on behalf of path request " + interface_str);
|
debug("There is already a waiting path request for destination " + destination_hash.toHex() + " on behalf of path request" + interface_str);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Forward path request on all interfaces
|
// Forward path request on all interfaces
|
||||||
// except the requestor interface
|
// except the requestor interface
|
||||||
debug("Attempting to discover unknown path to destination " + destination_hash.toHex() + " on behalf of path request " + interface_str);
|
debug("Attempting to discover unknown path to destination " + destination_hash.toHex() + " on behalf of path request" + interface_str);
|
||||||
//p pr_entry = { "destination_hash": destination_hash, "timeout": time.time()+Transport.PATH_REQUEST_TIMEOUT, "requesting_interface": attached_interface }
|
//p pr_entry = { "destination_hash": destination_hash, "timeout": time.time()+Transport.PATH_REQUEST_TIMEOUT, "requesting_interface": attached_interface }
|
||||||
//p _discovery_path_requests[destination_hash] = pr_entry;
|
//p _discovery_path_requests[destination_hash] = pr_entry;
|
||||||
_discovery_path_requests.insert({destination_hash, {
|
_discovery_path_requests.insert({destination_hash, {
|
||||||
@ -2923,6 +2931,7 @@ will announce it.
|
|||||||
for (auto& [hash, interface] : _interfaces) {
|
for (auto& [hash, interface] : _interfaces) {
|
||||||
#endif
|
#endif
|
||||||
if (interface != attached_interface) {
|
if (interface != attached_interface) {
|
||||||
|
extreme("Transport::path_request: requesting path on interface " + interface.toString());
|
||||||
// Use the previously extracted tag from this path request
|
// Use the previously extracted tag from this path request
|
||||||
// on the new path requests as well, to avoid potential loops
|
// on the new path requests as well, to avoid potential loops
|
||||||
request_path(destination_hash, interface, tag, true);
|
request_path(destination_hash, interface, tag, true);
|
||||||
|
134
src/main.cpp
134
src/main.cpp
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#else
|
||||||
|
#include <termios.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -52,94 +56,6 @@ const char* noble_gases[] = {"Helium", "Neon", "Argon", "Krypton", "Xenon", "Rad
|
|||||||
double last_announce = 0.0;
|
double last_announce = 0.0;
|
||||||
bool send_announce = false;
|
bool send_announce = false;
|
||||||
|
|
||||||
class TestInterface : public RNS::Interface {
|
|
||||||
public:
|
|
||||||
TestInterface() : RNS::Interface("TestInterface") {
|
|
||||||
IN(true);
|
|
||||||
OUT(true);
|
|
||||||
}
|
|
||||||
TestInterface(const char* name) : RNS::Interface(name) {
|
|
||||||
IN(true);
|
|
||||||
OUT(true);
|
|
||||||
}
|
|
||||||
virtual ~TestInterface() {
|
|
||||||
name("deleted");
|
|
||||||
}
|
|
||||||
virtual void processIncoming(const RNS::Bytes& data) {
|
|
||||||
RNS::extreme("TestInterface.processIncoming: data: " + data.toHex());
|
|
||||||
}
|
|
||||||
virtual void processOutgoing(const RNS::Bytes& data) {
|
|
||||||
RNS::extreme("TestInterface.processOutgoing: data: " + data.toHex());
|
|
||||||
}
|
|
||||||
virtual inline std::string toString() const { return "TestInterface[" + name() + "]"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestLoopbackInterface : public RNS::Interface {
|
|
||||||
public:
|
|
||||||
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) {
|
|
||||||
IN(true);
|
|
||||||
OUT(true);
|
|
||||||
}
|
|
||||||
virtual ~TestLoopbackInterface() {
|
|
||||||
name("deleted");
|
|
||||||
}
|
|
||||||
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) {
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestOutInterface : public RNS::Interface {
|
|
||||||
public:
|
|
||||||
TestOutInterface() : RNS::Interface("TestOutInterface") {
|
|
||||||
OUT(true);
|
|
||||||
IN(false);
|
|
||||||
}
|
|
||||||
TestOutInterface(const char* name) : RNS::Interface(name) {
|
|
||||||
OUT(true);
|
|
||||||
IN(false);
|
|
||||||
}
|
|
||||||
virtual ~TestOutInterface() {
|
|
||||||
name("(deleted)");
|
|
||||||
}
|
|
||||||
virtual void processOutgoing(const RNS::Bytes& data) {
|
|
||||||
RNS::head("TestOutInterface.processOutgoing: data: " + data.toHex(), RNS::LOG_EXTREME);
|
|
||||||
RNS::Interface::processOutgoing(data);
|
|
||||||
}
|
|
||||||
virtual inline std::string toString() const { return "TestOutInterface[" + name() + "]"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestInInterface : public RNS::Interface {
|
|
||||||
public:
|
|
||||||
TestInInterface() : RNS::Interface("TestInInterface") {
|
|
||||||
OUT(false);
|
|
||||||
IN(true);
|
|
||||||
}
|
|
||||||
TestInInterface(const char* name) : RNS::Interface(name) {
|
|
||||||
OUT(false);
|
|
||||||
IN(true);
|
|
||||||
}
|
|
||||||
virtual ~TestInInterface() {
|
|
||||||
name("(deleted)");
|
|
||||||
}
|
|
||||||
virtual void processIncoming(const RNS::Bytes& data) {
|
|
||||||
RNS::head("TestInInterface.processIncoming: data: " + data.toHex(), RNS::LOG_INFO);
|
|
||||||
RNS::Interface::processIncoming(data);
|
|
||||||
}
|
|
||||||
virtual inline std::string toString() const { return "TestInInterface[" + name() + "]"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Test AnnounceHandler
|
// Test AnnounceHandler
|
||||||
class ExampleAnnounceHandler : public RNS::AnnounceHandler {
|
class ExampleAnnounceHandler : public RNS::AnnounceHandler {
|
||||||
public:
|
public:
|
||||||
@ -183,10 +99,6 @@ RNS::Reticulum reticulum({RNS::Type::NONE});
|
|||||||
RNS::Identity identity({RNS::Type::NONE});
|
RNS::Identity identity({RNS::Type::NONE});
|
||||||
RNS::Destination destination({RNS::Type::NONE});
|
RNS::Destination destination({RNS::Type::NONE});
|
||||||
|
|
||||||
//TestInterface interface;
|
|
||||||
TestOutInterface outinterface;
|
|
||||||
TestInInterface ininterface;
|
|
||||||
TestLoopbackInterface loopinterface(ininterface);
|
|
||||||
#ifdef UDP_INTERFACE
|
#ifdef UDP_INTERFACE
|
||||||
RNS::Interfaces::UDPInterface udp_interface;
|
RNS::Interfaces::UDPInterface udp_interface;
|
||||||
#endif
|
#endif
|
||||||
@ -254,10 +166,6 @@ void setup_reticulum() {
|
|||||||
// 21.9% (+0.1%)
|
// 21.9% (+0.1%)
|
||||||
|
|
||||||
RNS::head("Registering Interface instances with Transport...", RNS::LOG_EXTREME);
|
RNS::head("Registering Interface instances with Transport...", RNS::LOG_EXTREME);
|
||||||
//RNS::Transport::register_interface(interface);
|
|
||||||
RNS::Transport::register_interface(outinterface);
|
|
||||||
RNS::Transport::register_interface(ininterface);
|
|
||||||
RNS::Transport::register_interface(loopinterface);
|
|
||||||
#ifdef UDP_INTERFACE
|
#ifdef UDP_INTERFACE
|
||||||
udp_interface.mode(RNS::Type::Interface::MODE_GATEWAY);
|
udp_interface.mode(RNS::Type::Interface::MODE_GATEWAY);
|
||||||
RNS::Transport::register_interface(udp_interface);
|
RNS::Transport::register_interface(udp_interface);
|
||||||
@ -324,7 +232,6 @@ void setup_reticulum() {
|
|||||||
destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]));
|
destination.announce(RNS::bytesFromString(fruits[RNS::Cryptography::randomnum() % 7]));
|
||||||
// 23.9% (+0.8%)
|
// 23.9% (+0.8%)
|
||||||
*/
|
*/
|
||||||
reticulum_announce();
|
|
||||||
|
|
||||||
#if defined (RETICULUM_PACKET_TEST)
|
#if defined (RETICULUM_PACKET_TEST)
|
||||||
// test data send packet
|
// test data send packet
|
||||||
@ -365,10 +272,6 @@ void teardown_reticulum() {
|
|||||||
#ifdef LORA_INTERFACE
|
#ifdef LORA_INTERFACE
|
||||||
RNS::Transport::deregister_interface(lora_interface);
|
RNS::Transport::deregister_interface(lora_interface);
|
||||||
#endif
|
#endif
|
||||||
RNS::Transport::deregister_interface(loopinterface);
|
|
||||||
RNS::Transport::deregister_interface(ininterface);
|
|
||||||
RNS::Transport::deregister_interface(outinterface);
|
|
||||||
//RNS::Transport::deregister_interface(interface);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
@ -451,15 +354,42 @@ void loop() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef ARDUINO
|
||||||
|
int getch( ) {
|
||||||
|
termios oldt;
|
||||||
|
termios newt;
|
||||||
|
tcgetattr( STDIN_FILENO, &oldt );
|
||||||
|
newt = oldt;
|
||||||
|
newt.c_lflag &= ~( ICANON | ECHO );
|
||||||
|
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
|
||||||
|
fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK);
|
||||||
|
int ch = getchar();
|
||||||
|
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
printf("Hello from Native on PlatformIO!\n");
|
printf("Hello from Native on PlatformIO!\n");
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
while (true) {
|
bool run = true;
|
||||||
|
while (run) {
|
||||||
loop();
|
loop();
|
||||||
|
int ch = getch();
|
||||||
|
if (ch > 0) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'a':
|
||||||
|
reticulum_announce();
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
run = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
RNS::Utilities::OS::sleep(0.01);
|
RNS::Utilities::OS::sleep(0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Goodbye from Native on PlatformIO!\n");
|
printf("Goodbye from Native on PlatformIO!\n");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user