mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-22 23:10:38 +00:00
WIP: Added support for RNS packet context_flag
Added support for new `context_flag` in RNS packet header that is used to indicate the use of ratchets. Note that ratchet support is still missing from the implementation, but this fix enables received ratchets to be able to handled gracefully.
This commit is contained in:
1 parent
838cede2e1
commit
cddc86e8c0
10 files changed
+49
-29
No files matched your search
@@ -2,13 +2,16 @@
|
||||
|
||||
Port of Reticulum Network Stack to C++ specifically but not exclusively targeting 32-bit and better MCUs.
|
||||
|
||||
Note that this is a library implementing the Reticulum Network Stack and not a useful application on its own. For an actual application, see [microReticulum_Firmware](https://github.com/attermann/microReticulum_Firmware) which is a version of RNode firmware that implements a Reticulm Transport Node.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Build environment is configured for use in [VSCode](https://code.visualstudio.com/) and [PlatformIO](https://platformio.org/).
|
||||
|
||||
This API is dependent on the following external libraries:
|
||||
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson)
|
||||
- [rweather/Crypto](https://github.com/rweather/arduinolibs)
|
||||
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson)
|
||||
- [MsgPack](https://github.com/hideakitai/MsgPack)
|
||||
|
||||
## Build Options
|
||||
|
||||
|
||||
@@ -40,9 +40,16 @@ bool LoRaInterface::start() {
|
||||
INFO("LoRa initializing...");
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
#ifdef BOARD_NRF52
|
||||
SPI.setPins(RADIO_MISO_PIN, RADIO_SCLK_PIN, RADIO_MOSI_PIN);
|
||||
SPI.begin();
|
||||
#else
|
||||
//SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN);
|
||||
SPI.begin();
|
||||
delay(1500);
|
||||
#endif
|
||||
|
||||
delay(1500);
|
||||
|
||||
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
|
||||
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "microReticulum",
|
||||
"version": "0.2.2",
|
||||
"version": "0.2.3",
|
||||
"description": "Port of Reticulum Network Stack to C++ specifically but not exclusively targeting 32-bit and better MCUs",
|
||||
"keywords": "reticulum, rns, mcu, esp32, nrf52",
|
||||
"keywords": "reticulum, rns, mesh, embedded, mcu, esp32, nrf52, native",
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
name=microReticulum
|
||||
version=0.2.2
|
||||
version=0.2.3
|
||||
author=Chad Attermann <attermann@gmail.com>
|
||||
maintainer=Chad Attermann <attermann@gmail.com>
|
||||
sentence=Port of Reticulum Network Stack to C++
|
||||
paragraph=Port of Reticulum Network Stack to C++ specifically but not exclusively targeting 32-bit and better MCUs
|
||||
paragraph=Specifically but not exclusively targeting 32-bit and better MCUs
|
||||
category=Communication
|
||||
url=https://github.com/attermann/microReticulum.git
|
||||
architectures=*
|
||||
depends=ArduinoJson
|
||||
depends=ArduinoJson,MsgPack
|
||||
+1
-1
@@ -53,7 +53,7 @@ namespace RNS {
|
||||
// CBA Internal method to handle housekeeping for data going out on interface
|
||||
void handle_outgoing(const Bytes& data);
|
||||
// CBA Internal method to handle data coming in on interface and pass on to transport
|
||||
void handle_incoming(const Bytes& data);
|
||||
virtual void handle_incoming(const Bytes& data);
|
||||
|
||||
virtual const Bytes get_hash() const {
|
||||
return Identity::full_hash({toString()});
|
||||
|
||||
+6
-5
@@ -18,7 +18,7 @@ ProofDestination::ProofDestination(const Packet& packet) : Destination({Type::NO
|
||||
{
|
||||
}
|
||||
|
||||
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*/, context_flag context_flag /*= FLAG_UNSET*/) :
|
||||
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*/, context_flags context_flag /*= FLAG_UNSET*/) :
|
||||
_object(new Object(destination, attached_interface))
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ Packet::Packet(const Destination& destination, const Interface& attached_interfa
|
||||
}
|
||||
|
||||
// CBA LINK
|
||||
Packet::Packet(const Link& link, const Bytes& data, Type::Packet::types packet_type /*= Type::Packet::DATA*/, Type::Packet::context_types context /*= Type::Packet::CONTEXT_NONE*/, context_flag context_flag /*= FLAG_UNSET*/) :
|
||||
Packet::Packet(const Link& link, const Bytes& data, Type::Packet::types packet_type /*= Type::Packet::DATA*/, Type::Packet::context_types context /*= Type::Packet::CONTEXT_NONE*/, context_flags context_flag /*= FLAG_UNSET*/) :
|
||||
//_object(new Object(link))
|
||||
//Packet(link.destination(), data, packet_type, context, Type::Transport::BROADCAST, Type::Packet::HEADER_1, {Bytes::NONE}, true, context_flag)
|
||||
// CBA Must use a destination that targets the Link itself instead of the original destination used to create the link
|
||||
@@ -79,14 +79,14 @@ uint8_t Packet::get_packed_flags() {
|
||||
uint8_t packed_flags = 0;
|
||||
if (_object->_context == LRPROOF) {
|
||||
TRACE("***** Packing with LINK type");
|
||||
packed_flags = (_object->_header_type << 6) | (_object->_transport_type << 4) | (Type::Destination::LINK << 2) | _object->_packet_type;
|
||||
packed_flags = (_object->_header_type << 6) | (_object->_context_flag << 5) | (_object->_transport_type << 4) | (Type::Destination::LINK << 2) | _object->_packet_type;
|
||||
}
|
||||
else {
|
||||
if (!_object->_destination) {
|
||||
throw std::logic_error("Packet destination is required");
|
||||
}
|
||||
TRACEF("***** Packing with %d type", _object->_destination.type());
|
||||
packed_flags = (_object->_header_type << 6) | (_object->_transport_type << 4) | (_object->_destination.type() << 2) | _object->_packet_type;
|
||||
packed_flags = (_object->_header_type << 6) | (_object->_context_flag << 5) | (_object->_transport_type << 4) | (_object->_destination.type() << 2) | _object->_packet_type;
|
||||
}
|
||||
return packed_flags;
|
||||
}
|
||||
@@ -94,7 +94,8 @@ TRACEF("***** Packing with %d type", _object->_destination.type());
|
||||
void Packet::unpack_flags(uint8_t flags) {
|
||||
assert(_object);
|
||||
_object->_header_type = static_cast<header_types>((flags & 0b01000000) >> 6);
|
||||
_object->_transport_type = static_cast<Type::Transport::types>((flags & 0b00110000) >> 4);
|
||||
_object->_context_flag = static_cast<Type::Packet::context_flags>((flags & 0b00100000) >> 5);
|
||||
_object->_transport_type = static_cast<Type::Transport::types>((flags & 0b00010000) >> 4);
|
||||
_object->_destination_type = static_cast<Type::Destination::types>((flags & 0b00001100) >> 2);
|
||||
_object->_packet_type = static_cast<types>(flags & 0b00000011);
|
||||
}
|
||||
|
||||
+5
-4
@@ -160,7 +160,7 @@ namespace RNS {
|
||||
Type::Packet::header_types header_type = Type::Packet::HEADER_1,
|
||||
const Bytes& transport_id = {Bytes::NONE},
|
||||
bool create_receipt = true,
|
||||
Type::Packet::context_flag context_flag = Type::Packet::FLAG_UNSET
|
||||
Type::Packet::context_flags context_flag = Type::Packet::FLAG_UNSET
|
||||
);
|
||||
Packet(
|
||||
const Destination& destination,
|
||||
@@ -171,7 +171,7 @@ namespace RNS {
|
||||
Type::Packet::header_types header_type = Type::Packet::HEADER_1,
|
||||
const Bytes& transport_id = {Bytes::NONE},
|
||||
bool create_receipt = true,
|
||||
Type::Packet::context_flag context_flag = Type::Packet::FLAG_UNSET
|
||||
Type::Packet::context_flags context_flag = Type::Packet::FLAG_UNSET
|
||||
) : Packet(destination, {Type::NONE}, data, packet_type, context, transport_type, header_type, transport_id, create_receipt, context_flag) {}
|
||||
// CBA LINK
|
||||
Packet(
|
||||
@@ -179,7 +179,7 @@ namespace RNS {
|
||||
const Bytes& data,
|
||||
Type::Packet::types packet_type = Type::Packet::DATA,
|
||||
Type::Packet::context_types context = Type::Packet::CONTEXT_NONE,
|
||||
Type::Packet::context_flag context_flag = Type::Packet::FLAG_UNSET
|
||||
Type::Packet::context_flags context_flag = Type::Packet::FLAG_UNSET
|
||||
);
|
||||
virtual ~Packet() {
|
||||
MEM("Packet object destroyed, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_object.get()));
|
||||
@@ -229,6 +229,7 @@ namespace RNS {
|
||||
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 Type::Packet::header_types header_type() const { assert(_object); return _object->_header_type; }
|
||||
inline Type::Packet::context_flags context_flag() const { assert(_object); return _object->_context_flag; }
|
||||
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; }
|
||||
inline Type::Packet::types packet_type() const { assert(_object); return _object->_packet_type; }
|
||||
@@ -293,7 +294,7 @@ namespace RNS {
|
||||
Type::Destination::types _destination_type = Type::Destination::SINGLE;
|
||||
Type::Packet::types _packet_type = Type::Packet::DATA;
|
||||
Type::Packet::context_types _context = Type::Packet::CONTEXT_NONE;
|
||||
uint8_t _context_flag = Type::Packet::FLAG_UNSET;
|
||||
Type::Packet::context_flags _context_flag = Type::Packet::FLAG_UNSET;
|
||||
|
||||
uint8_t _flags = 0;
|
||||
uint8_t _hops = 0;
|
||||
|
||||
+13
-5
@@ -374,7 +374,9 @@ using namespace RNS::Utilities;
|
||||
announce_context,
|
||||
Type::Transport::TRANSPORT,
|
||||
Type::Packet::HEADER_2,
|
||||
Transport::_identity.hash()
|
||||
Transport::_identity.hash(),
|
||||
true,
|
||||
announce_entry._packet.context_flag()
|
||||
);
|
||||
|
||||
new_packet.hops(announce_entry._hops);
|
||||
@@ -1151,7 +1153,7 @@ using namespace RNS::Utilities;
|
||||
}
|
||||
|
||||
/*static*/ void Transport::inbound(const Bytes& raw, const Interface& interface /*= {Type::NONE}*/) {
|
||||
TRACE("Transport::inbound()");
|
||||
TRACEF("Transport::inbound: received %d bytes", raw.size());
|
||||
++_packets_received;
|
||||
// CBA
|
||||
if (_callbacks._receive_packet) {
|
||||
@@ -1891,7 +1893,9 @@ using namespace RNS::Utilities;
|
||||
announce_context,
|
||||
Type::Transport::TRANSPORT,
|
||||
Type::Packet::HEADER_2,
|
||||
_identity.hash()
|
||||
_identity.hash(),
|
||||
true,
|
||||
packet.context_flag()
|
||||
);
|
||||
|
||||
new_announce.hops(packet.hops());
|
||||
@@ -1910,7 +1914,9 @@ using namespace RNS::Utilities;
|
||||
announce_context,
|
||||
Type::Transport::TRANSPORT,
|
||||
Type::Packet::HEADER_2,
|
||||
_identity.hash()
|
||||
_identity.hash(),
|
||||
true,
|
||||
packet.context_flag()
|
||||
);
|
||||
|
||||
new_announce.hops(packet.hops());
|
||||
@@ -1945,7 +1951,9 @@ using namespace RNS::Utilities;
|
||||
Type::Packet::PATH_RESPONSE,
|
||||
Type::Transport::TRANSPORT,
|
||||
Type::Packet::HEADER_2,
|
||||
_identity.hash()
|
||||
_identity.hash(),
|
||||
true,
|
||||
packet.context_flag()
|
||||
);
|
||||
|
||||
new_announce.hops(packet.hops());
|
||||
|
||||
+1
-1
@@ -345,7 +345,7 @@ namespace RNS { namespace Type {
|
||||
};
|
||||
|
||||
// Context flag values
|
||||
enum context_flag {
|
||||
enum context_flags {
|
||||
FLAG_SET = 0x01,
|
||||
FLAG_UNSET = 0x00,
|
||||
};
|
||||
|
||||
@@ -469,7 +469,7 @@ namespace RNS { namespace Persistence {
|
||||
static Bytes _buffer(Type::Persistence::BUFFER_MAXSIZE);
|
||||
|
||||
template <typename T> size_t crc(const T& obj) {
|
||||
TRACE("Persistence::crc<T>");
|
||||
//TRACE("Persistence::crc<T>");
|
||||
_document.set(obj);
|
||||
size_t size = _buffer.capacity();
|
||||
#ifdef USE_MSGPACK
|
||||
@@ -485,7 +485,7 @@ namespace RNS { namespace Persistence {
|
||||
}
|
||||
|
||||
template <typename T> size_t serialize(const T& obj, const char* file_path) {
|
||||
TRACE("Persistence::serialize<T>");
|
||||
//TRACE("Persistence::serialize<T>");
|
||||
_document.set(obj);
|
||||
size_t size = _buffer.capacity();
|
||||
#ifdef USE_MSGPACK
|
||||
@@ -516,7 +516,7 @@ namespace RNS { namespace Persistence {
|
||||
}
|
||||
|
||||
template <typename T> size_t deserialize(T& obj, const char* file_path) {
|
||||
TRACE("Persistence::deserialize<T>");
|
||||
//TRACE("Persistence::deserialize<T>");
|
||||
size_t read = RNS::Utilities::OS::read_file(file_path, _buffer);
|
||||
if (read > 0) {
|
||||
TRACEF("Persistence::deserialize: read: %d bytes", _buffer.size());
|
||||
@@ -547,7 +547,7 @@ namespace RNS { namespace Persistence {
|
||||
|
||||
#if 1
|
||||
template <typename T> size_t crc(std::map<Bytes, T>& map) {
|
||||
TRACE("Persistence::crc<map<Bytes, T>>");
|
||||
//TRACE("Persistence::crc<map<Bytes, T>>");
|
||||
|
||||
uint32_t crc = 0;
|
||||
crc = Utilities::Crc::crc32(crc, '{');
|
||||
@@ -583,7 +583,7 @@ namespace RNS { namespace Persistence {
|
||||
}
|
||||
|
||||
template <typename T> size_t serialize(std::map<Bytes, T>& map, const char* file_path, uint32_t& crc) {
|
||||
TRACE("Persistence::serialize<map<Bytes,T>>");
|
||||
//TRACE("Persistence::serialize<map<Bytes,T>>");
|
||||
|
||||
// CBA TODO: Use stream here instead to avoid having to buffer entire structure
|
||||
RNS::FileStream stream = RNS::Utilities::OS::open_file(file_path, RNS::FileStream::MODE_WRITE);
|
||||
@@ -626,7 +626,7 @@ namespace RNS { namespace Persistence {
|
||||
}
|
||||
|
||||
template <typename T> size_t deserialize(std::map<Bytes, T>& map, const char* file_path, uint32_t& crc) {
|
||||
TRACE("Persistence::deserialize<map<Bytes,T>>");
|
||||
//TRACE("Persistence::deserialize<map<Bytes,T>>");
|
||||
|
||||
// CBA TODO: Use stream here instead to avoid having to buffer entire structure
|
||||
RNS::FileStream stream = RNS::Utilities::OS::open_file(file_path, RNS::FileStream::MODE_READ);
|
||||
|
||||
Reference in new issue
Block a user