diff --git a/src/Destination.cpp b/src/Destination.cpp index c66c88d..f755e28 100644 --- a/src/Destination.cpp +++ b/src/Destination.cpp @@ -1,13 +1,13 @@ #include "Destination.h" -#include "Log.h" #include "Transport.h" +#include "Interface.h" #include "Packet.h" -#include "Interfaces/Interface.h" +#include "Log.h" +#include #include #include -#include using namespace RNS; using namespace RNS::Type::Destination; @@ -103,7 +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`. Ignore. */ -Packet Destination::announce(const Bytes &app_data, bool path_response, Interface *attached_interface, const Bytes &tag, bool send) { +//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..."); @@ -212,7 +213,9 @@ Packet Destination::announce(const Bytes &app_data, bool path_response, Interfac } debug("Destination::announce: creating announce packet..."); - Packet announce_packet(*this, announce_data, Type::Packet::ANNOUNCE, announce_context, Type::Transport::BROADCAST, Type::Packet::HEADER_1, nullptr, attached_interface); + //p announce_packet = RNS.Packet(self, announce_data, RNS.Packet.ANNOUNCE, context = announce_context, attached_interface = attached_interface) + //Packet announce_packet(*this, announce_data, Type::Packet::ANNOUNCE, announce_context, Type::Transport::BROADCAST, Type::Packet::HEADER_1, nullptr, attached_interface); + Packet announce_packet(*this, attached_interface, announce_data, Type::Packet::ANNOUNCE, announce_context, Type::Transport::BROADCAST, Type::Packet::HEADER_1); if (send) { debug("Destination::announce: sending announce packet..."); @@ -224,6 +227,10 @@ Packet Destination::announce(const Bytes &app_data, bool path_response, Interfac } } +Packet Destination::announce(const Bytes &app_data /*= {}*/, bool path_response /*= false*/) { + return announce(app_data, path_response, {Type::NONE}); +} + /* Registers a request handler. diff --git a/src/Destination.h b/src/Destination.h index bd5d4f1..12635bc 100644 --- a/src/Destination.h +++ b/src/Destination.h @@ -1,7 +1,8 @@ #pragma once -#include "Reticulum.h" -#include "Link.h" +//#include "Reticulum.h" +//#include "Link.h" +//#include "Interface.h" #include "Identity.h" #include "Bytes.h" #include "Type.h" @@ -16,9 +17,8 @@ namespace RNS { class Interface; - class Packet; class Link; - class Identity; + class Packet; /** * @brief A class used to describe endpoints in a Reticulum Network. Destination @@ -83,7 +83,9 @@ namespace RNS { 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, Interface *attached_interface = nullptr, const Bytes &tag = {}, bool send = true); + //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. diff --git a/src/Identity.cpp b/src/Identity.cpp index 70c5eb8..c80ba3e 100644 --- a/src/Identity.cpp +++ b/src/Identity.cpp @@ -264,7 +264,7 @@ bool Identity::validate(const Bytes &signature, const Bytes &message) { } } -void Identity::prove(const Packet &packet, const Destination &destination /*= {Destination::NONE}*/) { +void Identity::prove(const Packet &packet, const Destination &destination /*= {Type::NONE}*/) { assert(_object); Bytes signature(sign(packet.packet_hash())); Bytes proof_data; @@ -275,10 +275,14 @@ void Identity::prove(const Packet &packet, const Destination &destination /*= {D proof_data = packet.packet_hash() + signature; } - //zif (!destination) { - //z destination = packet.generate_proof_destination(); - //z} + //z if (!destination) { + //z destination = packet.generate_proof_destination(); + //z } Packet proof(destination, packet.receiving_interface(), proof_data, Type::Packet::PROOF); proof.send(); } + +void Identity::prove(const Packet &packet) { + prove(packet, {Type::NONE}); +} diff --git a/src/Identity.h b/src/Identity.h index b156c61..87c7bd4 100644 --- a/src/Identity.h +++ b/src/Identity.h @@ -1,14 +1,12 @@ #pragma once -#include "Reticulum.h" -//#include "Destination.h" #include "Log.h" #include "Bytes.h" +#include "Type.h" #include "Cryptography/Hashes.h" #include "Cryptography/Ed25519.h" #include "Cryptography/X25519.h" #include "Cryptography/Fernet.h" -#include "Type.h" #include @@ -99,8 +97,10 @@ namespace RNS { Bytes decrypt(const Bytes &ciphertext_token); Bytes sign(const Bytes &message); bool validate(const Bytes &signature, const Bytes &message); - //void prove(const Packet &packet, const Destination &destination = {Destination::NONE}); + // 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); // getters/setters inline Bytes encryptionPrivateKey() const { assert(_object); return _object->_prv_bytes; } diff --git a/src/Interfaces/Interface.cpp b/src/Interface.cpp similarity index 98% rename from src/Interfaces/Interface.cpp rename to src/Interface.cpp index a617e0c..f1e85b7 100644 --- a/src/Interfaces/Interface.cpp +++ b/src/Interface.cpp @@ -1,6 +1,6 @@ #include "Interface.h" -#include "../Transport.h" +#include "Transport.h" using namespace RNS; using namespace RNS::Type::Interface; diff --git a/src/Interfaces/Interface.h b/src/Interface.h similarity index 98% rename from src/Interfaces/Interface.h rename to src/Interface.h index e55cde8..4355a0f 100644 --- a/src/Interfaces/Interface.h +++ b/src/Interface.h @@ -1,8 +1,8 @@ #pragma once -#include "../Log.h" -#include "../Bytes.h" -#include "../Type.h" +#include "Log.h" +#include "Bytes.h" +#include "Type.h" #include #include diff --git a/src/Link.h b/src/Link.h index de0fdd5..1dbfa01 100644 --- a/src/Link.h +++ b/src/Link.h @@ -1,9 +1,5 @@ #pragma once -#include "Reticulum.h" -#include "Identity.h" -// CBA TODO resolve circular dependency with following header file -//#include "Packet.h" #include "Bytes.h" #include "Type.h" @@ -11,6 +7,8 @@ namespace RNS { + class Packet; + class Link { public: diff --git a/src/Packet.cpp b/src/Packet.cpp index 18b48ca..9f2d1b8 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -1,5 +1,6 @@ #include "Packet.h" +#include "Transport.h" #include "Identity.h" #include "Log.h" diff --git a/src/Packet.h b/src/Packet.h index 0ec5258..e55b10e 100644 --- a/src/Packet.h +++ b/src/Packet.h @@ -1,13 +1,10 @@ #pragma once -#include "Transport.h" -#include "Reticulum.h" -//#include "Link.h" -#include "Identity.h" #include "Destination.h" -#include "Interfaces/Interface.h" -#include "Utilities/OS.h" +#include "Link.h" +#include "Interface.h" #include "Type.h" +#include "Utilities/OS.h" #include #include @@ -19,7 +16,6 @@ namespace RNS { class PacketReceipt; class Packet; - class ProofDestination { }; diff --git a/src/Test/TestBytes.cpp b/src/Test/TestBytes.cpp index 4e149e2..693f552 100644 --- a/src/Test/TestBytes.cpp +++ b/src/Test/TestBytes.cpp @@ -173,6 +173,14 @@ void testBytes() { assert(memcmp(postbuf.data(), " World", postbuf.size()) == 0); } + // test creating bytes from default + { + RNS::Bytes bytes; + assert(!bytes); + assert(bytes.size() == 0); + assert(bytes.data() == nullptr); + } + // test creating bytes from nullptr { RNS::Bytes bytes = nullptr; @@ -189,6 +197,14 @@ void testBytes() { assert(bytes.data() == nullptr); } + // test creating bytes from empty + { + RNS::Bytes bytes = {}; + assert(!bytes); + assert(bytes.size() == 0); + assert(bytes.data() == nullptr); + } + // TODO test comparison } diff --git a/src/Transport.cpp b/src/Transport.cpp index 0e816a9..17f586f 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -4,8 +4,8 @@ #include "Destination.h" #include "Identity.h" #include "Packet.h" +#include "Interface.h" #include "Log.h" -#include "Interfaces/Interface.h" #include "Cryptography/Random.h" #include "Utilities/OS.h" @@ -2354,7 +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 /*= {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() @@ -2398,6 +2399,10 @@ will announce it. */ } +/*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) { /* try: diff --git a/src/Transport.h b/src/Transport.h index 3a78f5c..4c1b0bf 100644 --- a/src/Transport.h +++ b/src/Transport.h @@ -1,11 +1,6 @@ #pragma once -#include "Reticulum.h" -#include "Link.h" -// CBA TODO resolve circular dependency with following header file -#include "Packet.h" #include "Bytes.h" -#include "Interfaces/Interface.h" #include "Type.h" #include @@ -18,12 +13,13 @@ namespace RNS { - class Packet; - class PacketReceipt; + class Reticulum; + class Identity; class Destination; class Interface; class Link; - class Identity; + class Packet; + class PacketReceipt; class AnnounceHandler { public: @@ -183,7 +179,9 @@ namespace RNS { 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 = {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); @@ -206,7 +204,9 @@ namespace RNS { 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 = {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); diff --git a/src/main.cpp b/src/main.cpp index a7e0db4..72d60ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,8 +6,10 @@ #include "Identity.h" #include "Destination.h" #include "Packet.h" -#include "Interfaces/Interface.h" +#include "Transport.h" +#include "Interface.h" #include "Bytes.h" +#include "Type.h" #ifndef NATIVE #include