37 Commits
Author SHA1 Message Date
DeFiDude b9bee2701b docs: refresh guides and reference help 2026-11-02 11:14:29 -07:00
DeFiDude 83b88146f4 transport: discover paths for roaming interfaces 2026-06-26 16:10:52 -06:00
DeFiDude 3ddf3c362b test: Ed25519 validate() rejects tampered signatures 2026-06-12 14:01:51 -06:00
dude.eth 15b9f13db6 Merge pull request #1 from 0x00001312/master
[Security Patch] Fixing Ed25519 signature verification bypass
2026-06-12 13:55:29 -06:00
DeFiDude 858010cee0 AutoInterface: carrier-change handling, configurable hops, port-collision guard 2026-05-01 16:06:36 -06:00
DeFiDude 670820a41e Add AutoInterface (IPv6 multicast LAN auto-discovery, Python-wire-compatible) 2026-04-25 20:36:59 -06:00
DeFiDude afc5496d0e build: restore native17 + ignore destination_table runtime cache 2026-04-25 20:36:11 -06:00
DeFiDude 290a1336eb Disable bz2 on Resource transfers — too heavy for MCU targets
- BZ2.cpp: no-op shim, keeps RNS::Compression symbols
- Stub the 7 vendored bzip2 1.0.8 .c files (~4500 lines removed)
- OutboundResource::init always sends uncompressed; default flipped
- InboundResource drops compressed payloads with a WARNING (no decode)
- library.json: defensive build.srcFilter excluding bzip2 sources

Companion fix lives in firmware repos: announce app_data must
advertise an empty supported_functionality list so Python LXMF
disables auto_compress for our destinations.
2026-04-23 17:38:07 -06:00
DeFiDude 1cadb453eb Fix Python Reticulum interop: announce timestamps, link deadlock, packet routing
- Announce timestamps now use Unix epoch (time()) instead of OS::time()
  which returned uptime on Arduino. Python Transport compares announce
  emission timestamps for freshness — uptime-based values caused
  re-announces to be rejected by nodes with cached epoch timestamps.

- Remove blocking while(_jobs_running) waits in Transport::outbound()
  and Transport::inbound(). On single-threaded ESP32, these deadlock
  when outbound() is called from within jobs() (e.g. link proof retry).

- Fix missing _jobs_locked=false on early returns in Transport::inbound()
  which would permanently lock the transport after unpack failures,
  cache requests, or announce rate limiting.

- Link packets now inherit attached_interface from the Link object via
  the Packet(Link,...) constructor. This ensures TCP link traffic stays
  on TCP and LoRa link traffic stays on LoRa — critical for devices
  with multiple interfaces.

- Implement Link::attached_interface() const getter (was declared but
  missing implementation).

- Only apply collision-avoidance delay in Link::prove() for non-TCP
  interfaces where half-duplex radio collisions are a real concern.
2026-04-05 19:20:11 -06:00
DeFiDude e13b300b0c Fix link proof signature and add proof retry for LoRa reliability
Link proof was signing with ephemeral Ed25519 key instead of destination
identity key, causing Python clients to reject the proof. Add proof retry
with exponential backoff for LoRa packet loss recovery.
2026-04-02 22:53:25 -06:00
DeFiDude 753dce608e Gate dump_stats() behind verbose log level (4.2s heap introspection freeze on ESP32) 2026-03-28 22:32:52 -06:00
DeFiDude 9d6bbac9a6 Add timing instrumentation to jobs() table cull cycle 2026-03-28 22:27:07 -06:00
DeFiDude e93e71dc69 Fix: use Reticulum::transport_enabled() not _transport_enabled 2026-03-28 21:46:16 -06:00
DeFiDude b1071754be Skip packet cache writes on endpoint devices (fixes 2.3s flash freeze) 2026-03-28 21:44:17 -06:00
DeFiDude c877730b91 Cherry-pick 6 upstream transport and allocator fixes (attermann PRs #32-36, constexpr)
- Fix MTU clamp to zero when previous-hop interface has no HW_MTU (PR #32)
- Send immediate PATH_RESPONSE for local client path requests (PR #33)
- Fix LinkEntry copy-vs-reference: active links were culled after 15 min (PR #34)
- Defer packet hashlist insertion for link-table and LRPROOF packets (PR #35)
- Fix memory leaks in _pending_local_path_requests and _path_requests (PR #36)
- Add constexpr to pool_info constructor to prevent zero-size init race

Note: GPS time display needs further investigation — not showing on device
after flash, likely unrelated to these changes (fresh NVS has no stored epoch).
2026-03-26 16:16:19 -06:00
DeFiDude dd7c749ea3 Optimize announce processing for busy hubs
Skip Ed25519 signature verification for already-known identities in
validate_announce() — uses hash table lookup instead of ~150ms crypto.
On a busy hub with 50+ nodes, this eliminates 90%+ of CPU-blocking
verify work.

Add transport-layer rate limit (5 new verifies/sec) before crypto to
cap worst-case CPU usage for unknown identities.

Defer cull_known_destinations() and cull_announce_table() to periodic
jobs() instead of running O(n log n) sorts per inbound packet.
2026-03-24 22:22:53 -06:00
DeFiDude 352de23ed0 Add E2E loopback tests: 8 tests covering full protocol flow
Validates the complete C++ protocol stack without hardware:
1. testE2eSmallMessage — LXMF <263B pack/unpack/sign/verify
2. testE2eLargeMessage — LXMF >263B (resource-needed size)
3. testE2eImageField — LXMF with FIELD_IMAGE nested array
4. testE2eResourceRoundtrip — chunking + map hash + assembly
5. testE2eBz2Roundtrip — bz2 compress/decompress (1000B)
6. testE2eBz2DeterministicFixture — BZh magic + roundtrip (400x'A')
7. testE2eAnnounceWithRatchet — 180-byte announce with ratchet key
8. testE2eBidirectionalLxmf — two identities, A→B + B→A

All 8 tests pass on native17. Total: 145 C++ tests (144 pass).
2026-03-24 17:34:26 -06:00
DeFiDude 166083aba7 Add bz2 compression for Resource transfer + 3 compression tests
Vendor libbzip2 (1.0.8, BSD license) for ESP32-compatible bz2
compression/decompression. This matches Python's bz2.compress()
and Rust's bzip2 crate for cross-platform Resource transfers.

C++ wrapper (Compression/BZ2.h):
- bz2_compress() — compress with blockSize100k=9
- bz2_decompress() — decompress with progressive buffer sizing
- try_compress() — compress only if smaller than original

Resource integration:
- OutboundResource::init() now compresses with bz2 if beneficial
- InboundResource::assemble() decompresses if compressed flag set
- ResourceFlags.compressed bit tracks compression state

3 new tests (test_resource_transfer):
- testBz2CompressDecompress — roundtrip verification
- testTryCompress — beneficial vs non-beneficial compression
- testBz2CrossPlatformFormat — BZh magic bytes match Python/Rust

Total: 137 tests, 136 pass (1 pre-existing allocator).
2026-03-24 17:15:42 -06:00
DeFiDude 40eeccc646 Wire Resource transfer into Link: replace pseudocode with real handlers
Replace commented-out Python pseudocode (/*z ... //p ...) in Link::receive()
with working C++ resource handling:

- RESOURCE_ADV: decrypt, parse advertisement, create InboundResource,
  send initial ResourceReq
- RESOURCE_REQ: decrypt, find matching OutboundResource, send requested parts
- RESOURCE: receive part by map hash, assemble when complete, send proof
- RESOURCE_PRF: validate outbound resource proof
- RESOURCE_ICL: cancel inbound resource
- RESOURCE_HMU: stub (handled via ResourceReq)

Also:
- Fix ready_for_new_resource() inverted logic (was returning true when
  resources exist, now returns true when empty)
- Add start_resource_transfer() to Link for LXMFManager integration
- Add InboundResource/OutboundResource vectors to LinkData
- Remove stale Channel case comment block

134 total tests, 133 pass.
2026-03-24 17:02:57 -06:00
DeFiDude 798512e8f7 Implement Resource transfer: advertisement, map hash, chunking, assembly
Complete rewrite of Resource.h/cpp with full protocol implementation:

ResourceAdvertisement: msgpack map pack/unpack with 11 string keys
  (t,d,n,h,r,o,i,l,q,f,m) matching Python/Rust wire format.

OutboundResource (sender): compress → encrypt → chunk → hashmap → advertise.
  Splits encrypted blob into SDU-sized parts (263 bytes), computes
  SHA256(chunk||random_hash)[:4] map hashes, handles receiver requests.

InboundResource (receiver): accept advertisement → receive parts by map hash
  → assemble → decrypt → decompress. Sends initial request, generates proof.

Helper functions: get_map_hash(), compute_resource_hash(),
  compute_expected_proof() — all match Python/Rust implementations.

8 new tests (test_resource_transfer): advertisement roundtrip, map hash,
  resource hash, proof, flag encoding, nil/non-nil request_id.

Legacy Resource class preserved for Link.cpp compatibility.
2026-03-24 16:48:55 -06:00
DeFiDude 36d5241e9d Add receiveCounter field for Ratcom compatibility 2026-03-24 16:25:15 -06:00
DeFiDude 65ecaef894 Add test_announce_interop (6 tests) + test_protocol_edge_cases (6 tests)
Announce interop tests:
1. testAnnouncePack — 148-byte announce wire format
2. testAnnounceUnpack — verify field offsets + signature validation
3. testAnnounceWithRatchet — 180-byte announce with 32-byte ratchet key
4. testAppDataExtraction — msgpack and UTF-8 app_data formats
5. testDestHashFromIdentity — delivery + propagation dest hash computation
6. testNameHashes — lxmf.delivery, lxmf.propagation, nomadnetwork.node

Protocol edge case tests:
1. testPacketFlagCombinations — all critical flag byte values
2. testHashMasking — Header1 and Header2 produce same packet hash
3. testHopsDoNotAffectHash — hops excluded from hash computation
4. testMTUBoundary — 500 byte MTU, header sizes (19/35)
5. testIdentityHashLength — 16 bytes truncated, 64 bytes pubkey
6. testEncryptDecryptRoundtrip — ECIES token encrypt/decrypt

All 12 tests pass on native17.
2026-03-24 15:50:37 -06:00
DeFiDude ed362a52ee Add test_lxmf_interop: 10 cross-platform fixture + wire format tests
New test suite generating deterministic LXMF and protocol fixtures for
Rust validation:
1. testLxmfWithImageField — LXMF with FIELD_IMAGE (nested array)
2. testLxmfWithFileAttachment — LXMF with FIELD_FILE_ATTACHMENTS
3. testLxmfWithMultipleFields — LXMF with CUSTOM_TYPE + CUSTOM_DATA
4. testAnnounceUtf8AppData — announce with raw UTF-8 (Rust format)
5. testAnnounceMsgpackAppData — announce with msgpack array (Ratdeck format)
6. testOpportunisticWireNoDestHash — [src:16][sig:64][packed] format
7. testSignallingBytesPacking — mode+MTU bitfield encoding
8. testPacketFlagEncoding — all flag byte combinations
9. testTruncatedHashLengths — 16/32/10 byte hash outputs
10. testHeaderFormats — Header1 (19 bytes) vs Header2 (35 bytes)

All fixture values printed as hex for Rust cpp_interop_fields.rs to validate.
10/10 tests pass on native17.
2026-03-24 15:46:04 -06:00
DeFiDude fb76b6707b Add test_lxmf_codec: 10 LXMF packing/unpacking/signing tests
New test suite validating the LXMF message codec on native platform:
1. testPackContentRoundtrip — fixarray(4) structure
2. testPackContentBinEncoding — title/content as bin (0xC4), not str
3. testPackFullOpportunistic — wire: [src:16][sig:64][packed]
4. testPackFullDirect — wire: [dest:16][src:16][sig:64][packed]
5. testUnpackFull — pack → unpack → verify fields
6. testSignatureVerification — Ed25519 sign/verify roundtrip
7. testMessageIdComputation — deterministic SHA256 hash
8. testEmptyTitleAndContent — edge case: empty strings
9. testUnicodeContent — UTF-8 content round-trip
10. testMaxSizeContent — 280 bytes (near opportunistic limit)

All 10 tests pass on native17. Uses same deterministic seeds as
test_cross_compat for consistency.
2026-03-24 15:38:19 -06:00
DeFiDude 6f3c08de93 Add LXMFMessage codec to microReticulum library
Moves the LXMF message packing/unpacking/signing code from Ratdeck
into microReticulum as a shared library module. This enables:
- Native platform LXMF tests (pio test -e native17)
- Cross-implementation fixture validation
- Single source of truth for C++ LXMF wire format

The codec is adapted from Ratdeck's LXMFMessage.h/cpp with Arduino.h
dependency removed (replaced with cstdint for native platform support).

Wire format matches Python LXMF (LXMessage.py) and Rust (lxmf-core):
- Opportunistic: [src:16][sig:64][msgpack(ts, title, content, fields)]
- Direct: [dest:16][src:16][sig:64][msgpack(ts, title, content, fields)]
- Title/content encoded as MsgPack bin (0xC4/0xC5), not str

Note: Ratdeck will be updated to #include <LXMFMessage.h> from the
library (removing its local copy) after this change is pushed.
2026-03-24 15:31:05 -06:00
DeFiDude 8b052eb4c3 Disable ratchet encryption until Python-compatible (commented out for easy re-enable) 2026-03-21 14:29:05 -06:00
DeFiDude 7023c9444a Add link proof and context diagnostic logging 2026-03-21 13:38:12 -06:00
DeFiDude 1acd840182 Fix known_destinations LRU cull, revert endpoint caching regression, add proof diagnostics
Identity.cpp: OS::time() on Arduino returns seconds since boot, not epoch.
Persisted known_destinations entries carried timestamps from the previous
session (e.g., 5000s). On a fresh boot at 31s uptime, new announces got
timestamp 31.0 — the LRU cull saw this as "oldest" and removed it
immediately. Identity::recall() could never find the destination, breaking
all outbound LXMF messaging. Fix: normalize loaded timestamps to [1, now-1]
preserving relative order, so fresh announces are always newest.

Transport.cpp: Revert b44d374's endpoint caching skip — Ratdeck runs as
endpoint and needs cached announces for path table persistence across
reboots. Restore immediate cull behavior. Add DIAG-PROOF logging for
tracing link proof broadcast routing across interfaces.
2026-03-20 19:36:06 -06:00
DeFiDude b44d3743ec Fix announce flood performance: skip endpoint caching, defer culls, fix clean_caches
- Guard announce cache_packet(force=true) with transport_enabled() so
  endpoints skip 300-900ms flash writes per announce
- Defer cull_path_table/cull_announce_table until 10% over capacity
  instead of after every insert
- Rewrite clean_caches: endpoints just wipe stale files in one pass;
  transport nodes use std::set for O(N+M) instead of O(N*M) lookups
2026-03-19 15:24:10 -06:00
DeFiDude 813d9095d7 Fix PKCS7 padding, identity persistence, and packet routing 2026-03-13 04:20:04 -06:00
DeFiDude bb291795da Fix TCP outbound: stop get_path() from destroying valid routes + PSRAM allocator
- get_path(): Remove announce_packet null check that destroyed valid path
  entries when cache deserialization failed under heap pressure. Routing
  fields (_received_from, _hops, receiving_interface) are valid without it.
- hops_to(): Direct path table lookup instead of get_path() to avoid
  triggering expensive announce_packet lazy load from flash cache.
- path_request_handler(): Guard against null announce_packet gracefully.
- Persistence: Add PSRAM allocator for ArduinoJson JsonDocument on ESP32
  boards with PSRAM, preventing deserialization failures when heap is low.
2026-03-11 14:48:19 -06:00
DeFiDude bc33c0af64 Revert hops >= 1 to > 1 in Transport::outbound()
The >= 1 change made the hops==1 branch (hub topology) convert
packets to Header2 with potentially wrong transport_id before
send_outgoing() could apply the correct learned hub transport_id.
Reverting to > 1 matches the original Python logic and lets
hops==1 packets fall through as Header1 for proper wrapping.
2026-03-11 13:43:11 -06:00
DeFiDude 184e6b0250 Skip announce packet caching on non-transport endpoints
Only cache announce packets when transport is enabled, preventing
unnecessary storage on endpoint-only nodes that don't rebroadcast.
2026-03-10 22:40:57 -06:00
DeFiDude af9fbab780 Fix boot loop: Identity::remember() stale timestamp causes cull crash
std::map::insert() is a no-op for existing keys, so identities loaded
from persisted known_destinations kept their old timestamps. When
cull_known_destinations() ran after insert, it removed the "stale"
entry that was just validated — causing Identity::recall() to fail
and hexhash() to assert on a null identity.

Fix: use insert_or_assign() to always refresh the timestamp.

Also reverts the dead-code needs_transport_headers() virtual method
(the else-if at Transport.cpp:826 is unreachable because hops>=1
already catches hops==1 in the preceding if block).
2026-03-10 11:22:05 -06:00
DeFiDude 79271a018b Add needs_transport_headers() for TCP hub messaging fix
TCP interfaces behind a hub need HEADER_2 transport wrapping even at
hops==1, since the hub can't forward raw HEADER_1 packets. Added virtual
needs_transport_headers() to InterfaceImpl (defaults to false) so TCP
subclasses can override it without setting is_connected_to_shared_instance
(which would brick the device by skipping all Reticulum::loop processing).
2026-03-10 00:49:56 -06:00
DeFiDude 3bc64abbde Add Identity as friend of Reticulum for storagepath access 2026-03-08 22:42:34 -06:00
DeFiDude 425c2a9907 Fix TCP messaging via transport nodes and implement known_destinations persistence 2026-03-08 21:56:30 -06:00