WIP: More refactoring to reduce need for headers

This commit is contained in:
attermann 2023-11-19 13:17:42 -07:00
parent 33fda8a7f9
commit 9f1602067d
13 changed files with 77 additions and 46 deletions

View File

@ -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 <vector>
#include <time.h>
#include <string.h>
#include <vector>
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<api-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.

View File

@ -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.

View File

@ -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});
}

View File

@ -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 <memory>
@ -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; }

View File

@ -1,6 +1,6 @@
#include "Interface.h"
#include "../Transport.h"
#include "Transport.h"
using namespace RNS;
using namespace RNS::Type::Interface;

View File

@ -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 <list>
#include <memory>

View File

@ -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:

View File

@ -1,5 +1,6 @@
#include "Packet.h"
#include "Transport.h"
#include "Identity.h"
#include "Log.h"

View File

@ -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 <memory>
#include <stdint.h>
@ -19,7 +16,6 @@ namespace RNS {
class PacketReceipt;
class Packet;
class ProofDestination {
};

View File

@ -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
}

View File

@ -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:

View File

@ -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 <memory>
@ -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);

View File

@ -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 <Arduino.h>