mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-22 23:10:38 +00:00
WIP: Fixes for link validation and announce retries
Fix for link validation failure when poackets contain new MTU in payload from RNS 1.0 (courtesy of @jlpoolen). Optimization of announce re-broadcasts from RNS 1.0.
This commit is contained in:
1 parent
3cc7c2a55d
commit
3c4978f294
8 files changed
+68
-10
No files matched your search
@@ -26,6 +26,7 @@
|
||||
#include <termios.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -34,6 +35,7 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
// Let's define an app name. We'll use this for all
|
||||
// destinations we create. Since this echo example
|
||||
@@ -328,11 +330,27 @@ void cleanup_handler(int signum) {
|
||||
// starts up the desired program mode.
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
bool log_trace = false;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (argv[i] && strcasecmp(argv[i], "--log_trace") == 0) {
|
||||
log_trace = true;
|
||||
for (int j = i; j < argc - 1; ++j) {
|
||||
argv[j] = argv[j + 1];
|
||||
}
|
||||
--argc;
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(RNS_MEM_LOG)
|
||||
RNS::loglevel(RNS::LOG_MEM);
|
||||
#else
|
||||
RNS::loglevel(RNS::LOG_NOTICE);
|
||||
//RNS::loglevel(RNS::LOG_TRACE);
|
||||
if (log_trace) {
|
||||
RNS::loglevel(RNS::LOG_TRACE);
|
||||
}
|
||||
else {
|
||||
RNS::loglevel(RNS::LOG_NOTICE);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Register the signal handler for SIGINT
|
||||
|
||||
@@ -18,8 +18,6 @@ monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
build_type = debug
|
||||
build_flags =
|
||||
-DRNS_USE_ALLOCATOR=1
|
||||
-DRNS_USE_TLSF=1
|
||||
;-DRNS_MEM_LOG
|
||||
lib_deps =
|
||||
ArduinoJson@^7.4.2
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "microReticulum",
|
||||
"version": "0.2.3",
|
||||
"version": "0.2.4",
|
||||
"description": "Port of Reticulum Network Stack to C++ specifically but not exclusively targeting 32-bit and better MCUs",
|
||||
"keywords": "reticulum, rns, mesh, embedded, mcu, esp32, nrf52, native",
|
||||
"repository":
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=microReticulum
|
||||
version=0.2.3
|
||||
version=0.2.4
|
||||
author=Chad Attermann <attermann@gmail.com>
|
||||
maintainer=Chad Attermann <attermann@gmail.com>
|
||||
sentence=Port of Reticulum Network Stack to C++
|
||||
|
||||
+32
-2
@@ -176,14 +176,34 @@ Link::Link(const Destination& destination /*= {Type::NONE}*/, Callbacks::establi
|
||||
}
|
||||
|
||||
/*static*/ Link Link::validate_request( const Destination& owner, const Bytes& data, const Packet& packet) {
|
||||
if (data.size() == ECPUBSIZE) {
|
||||
if (data.size() == ECPUBSIZE || data.size() == ECPUBSIZE + LINK_MTU_SIZE) {
|
||||
try {
|
||||
Link link({Type::NONE}, nullptr, nullptr, owner, data.left(ECPUBSIZE/2), data.mid(ECPUBSIZE/2, ECPUBSIZE/2));
|
||||
link.set_link_id(packet);
|
||||
|
||||
if (data.size() == ECPUBSIZE + LINK_MTU_SIZE) {
|
||||
DEBUG("Link request includes MTU signalling"); // TODO: Remove debug
|
||||
try {
|
||||
uint16_t mtu = mtu_from_lr_packet(packet);
|
||||
link.mtu((mtu != 0) ? mtu : Type::Reticulum::MTU);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ERRORF("An error ocurred while validating link request %s", link.link_id().toHex().c_str());
|
||||
link.mtu(Type::Reticulum::MTU);
|
||||
}
|
||||
}
|
||||
|
||||
link.mode(mode_from_lr_packet(packet));
|
||||
|
||||
// TODO: Remove debug
|
||||
DEBUGF("Incoming link request with mode %d", link.get_mode());
|
||||
|
||||
link.update_mdu();
|
||||
link.destination(packet.destination());
|
||||
link.establishment_timeout(ESTABLISHMENT_TIMEOUT_PER_HOP * std::max((uint8_t)1, packet.hops()) + KEEPALIVE);
|
||||
link.establishment_cost(link.establishment_cost() + packet.raw().size());
|
||||
VERBOSEF("Validating link request %s", link.link_id().toHex().c_str());
|
||||
TRACEF("Link MTU configured to %d", link.mtu());
|
||||
TRACEF("Establishment timeout is %f for incoming link request %s", link.establishment_timeout(), link.link_id().toHex().c_str());
|
||||
link.handshake();
|
||||
link.attached_interface(packet.receiving_interface());
|
||||
@@ -202,7 +222,7 @@ Link::Link(const Destination& destination /*= {Type::NONE}*/, Callbacks::establi
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUG("Invalid link request payload size, dropping request");
|
||||
DEBUGF("Invalid link request payload size (%zu), dropping request", data.size());
|
||||
return {Type::NONE};
|
||||
}
|
||||
}
|
||||
@@ -1564,6 +1584,16 @@ void Link::status(Type::Link::status status) {
|
||||
_object->_status = status;
|
||||
}
|
||||
|
||||
void Link::mtu(uint16_t mtu) {
|
||||
assert(_object);
|
||||
_object->_mtu = mtu;
|
||||
}
|
||||
|
||||
void Link::mode(RNS::Type::Link::link_mode mode) {
|
||||
assert(_object);
|
||||
_object->_mode = mode;
|
||||
}
|
||||
|
||||
|
||||
//RequestReceipt::RequestReceipt(const Link& link, const PacketReceipt& packet_receipt /*= {Type::NONE}*/, const Resource& resource /*= {Type::NONE}*/, RequestReceipt::Callbacks::response response_callback /*= nullptr*/, RequestReceipt::Callbacks::failed failed_callback /*= nullptr*/, RequestReceipt::Callbacks::progress progress_callback /*= nullptr*/, double timeout /*= 0.0*/, int request_size /*= 0*/) :
|
||||
RequestReceipt::RequestReceipt(const Link& link, const PacketReceipt& packet_receipt, const Resource& resource, RequestReceipt::Callbacks::response response_callback /*= nullptr*/, RequestReceipt::Callbacks::failed failed_callback /*= nullptr*/, RequestReceipt::Callbacks::progress progress_callback /*= nullptr*/, double timeout /*= 0.0*/, int request_size /*= 0*/) :
|
||||
|
||||
+3
-1
@@ -198,7 +198,7 @@ namespace RNS {
|
||||
void teardown_packet(const Packet& packet);
|
||||
void link_closed();
|
||||
void start_watchdog();
|
||||
void __watchdog_job();
|
||||
void __watchdog_job();
|
||||
void send_keepalive();
|
||||
void handle_request(const Bytes& request_id, const ResourceRequest& unpacked_request);
|
||||
void handle_response(const Bytes& request_id, const Bytes& response_data, size_t response_size, size_t response_transfer_size);
|
||||
@@ -259,6 +259,8 @@ namespace RNS {
|
||||
void increment_tx();
|
||||
void increment_txbytes(uint16_t bytes);
|
||||
void status(Type::Link::status status);
|
||||
void mtu(uint16_t mtu);
|
||||
void mode(RNS::Type::Link::link_mode mode);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<LinkData> _object;
|
||||
|
||||
+7
-1
@@ -334,7 +334,13 @@ using namespace RNS::Utilities;
|
||||
// auto& announce_entry = pair.second;
|
||||
//TRACE("[0] announce entry data size: " + std::to_string(announce_entry._packet.data().size()));
|
||||
//p announce_entry = Transport.announce_table[destination_hash]
|
||||
if (announce_entry._retries > Type::Transport::PATHFINDER_R) {
|
||||
if (announce_entry._retries > 0 && announce_entry._retries >= Type::Transport::LOCAL_REBROADCASTS_MAX) {
|
||||
TRACE("Completed announce processing for " + destination_hash.toHex() + ", local rebroadcast limit reached");
|
||||
// CBA OK to modify collection here since we're immediately exiting iteration
|
||||
_announce_table.erase(destination_hash);
|
||||
break;
|
||||
}
|
||||
else if (announce_entry._retries > Type::Transport::PATHFINDER_R) {
|
||||
TRACE("Completed announce processing for " + destination_hash.toHex() + ", retry limit reached");
|
||||
// CBA OK to modify collection here since we're immediately exiting iteration
|
||||
_announce_table.erase(destination_hash);
|
||||
|
||||
@@ -71,6 +71,10 @@ void* operator new(size_t size) {
|
||||
_buffer_size = (size_t)(_buffer_size / 1024) * 1024;
|
||||
TRACEF("buffer_size: %u", _buffer_size);
|
||||
void* raw_buffer = malloc(_buffer_size);
|
||||
#else
|
||||
_buffer_size = (size_t)BUFFER_SIZE;
|
||||
TRACEF("buffer_size: %u", _buffer_size);
|
||||
void* raw_buffer = malloc(_buffer_size);
|
||||
#endif
|
||||
if (raw_buffer == nullptr) {
|
||||
ERROR("-- allocation for tlsf FAILED");
|
||||
|
||||
Reference in new issue
Block a user