Files
pyxis/lib/microreticulum-shim/FileSystem.h
T
torlando-agent[bot]andClaude Opus 4.8 70d4aa6be9 feat: graft pyxis onto upstream microReticulum 0.4.1
Repins microReticulum + microLXMF onto the upstream-0.4.1 graft and adapts
pyxis to the new src/microReticulum/ layout and 0.4.x APIs. The far-diverged
0.3.0 fork's Resource/Transport/Identity work is subsumed by upstream's
reimplementation; only the still-needed fixes ride on the pinned branches
(PKCS7/HMAC/X25519 crypto -- proven byte-identical to python RNS 1.3.1 --
Packet link-proof callback, Identity short-sig guard, and the bz2 layer +
decompress-on-receive in Resource::assemble()).

Consumer-side changes:
- platformio.ini: pin microReticulum @2f21fee (pyxis-fixes-on-0.4.1) and
  microLXMF @33760d0 (chore/microreticulum-0.4.1-layout); bump microStore
  ceea8f5 -> c5fb69d (0.4.x requires the new BasicFileStore::init API);
  -std=gnu++11 -> gnu++17 (upstream requires C++17).
- Namespace all microReticulum includes (angle + quote) to <microReticulum/...>
  for the relocated layout; shim-local Utilities/Stream.h|Print.h preserved.
- Interface::send_outgoing now returns bool: update TCP/BLE/SX1262/Auto
  overrides with correct success/failure returns.
- SDArchiveFileSystem::init(bool reformatOnFail=true) to match new microStore.
- Static Transport::get_path_table() -> path_table(); instance getter unchanged.
- Remove duplicate shim Cryptography/BZ2 (microReticulum provides it now; keep
  lib/libbz2 as the ESP32 bzlib provider).
- patch_littlefs_paths.py: normalize microStore's LittleFS adapter paths to a
  leading "/" -- ESP32 Arduino LittleFS rejects "./"-prefixed paths, which
  silently broke the path store (no peer paths learned, all messaging blocked).

Validated on T-Deck Plus: builds (RAM 27.5% / Flash 77.7%), boots stable
(no WDT/panic), and a full on-device LXMF e2e (DIRECT + OPPORTUNISTIC +
bz2-compressed-Resource receive) passes 5/5.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWZuYkHBRqNb6BZHV8sTG5
2026-06-19 15:49:44 -04:00

130 lines
5.1 KiB
C++

#pragma once
#include "FileStream.h"
#include <microReticulum/Log.h>
#include <microReticulum/Bytes.h>
#include <microReticulum/Type.h>
#include <list>
#include <memory>
#include <cassert>
#include <stdint.h>
namespace RNS {
class FileSystemImpl {
protected:
FileSystemImpl() { MEMF("FileSystem::FileSystemImpl object created, this: 0x%X", this); }
public:
virtual ~FileSystemImpl() { MEMF("FileSystem::FileSystemImpl object destroyed, this: 0x%X", this); }
protected:
virtual bool init() { return true; }
virtual void loop() {}
virtual bool file_exists(const char* file_path) = 0;
virtual size_t read_file(const char* file_path, Bytes& data) = 0;
virtual size_t write_file(const char* file_path, const Bytes& data) = 0;
virtual FileStream open_file(const char* file_path, FileStream::MODE file_mode) = 0;
virtual bool remove_file(const char* file_path) = 0;
virtual bool rename_file(const char* from_file_path, const char* to_file_path) = 0;
virtual bool directory_exists(const char* directory_path) = 0;
virtual bool create_directory(const char* directory_path) = 0;
virtual bool remove_directory(const char* directory_path) = 0;
virtual std::list<std::string> list_directory(const char* directory_path) = 0;
virtual size_t storage_size() = 0;
virtual size_t storage_available() = 0;
friend class FileSystem;
};
class FileSystem {
public:
FileSystem(Type::NoneConstructor none) {
MEMF("FileSystem NONE object created, this: 0x%X, impl: 0x%X", this, _impl.get());
}
FileSystem(const FileSystem& obj) : _impl(obj._impl) {
MEMF("FileSystem object copy created, this: 0x%X, impl: 0x%X", this, _impl.get());
}
FileSystem(FileSystemImpl* impl) : _impl(impl) {
MEMF("FileSystem object impl created, this: 0x%X, impl: 0x%X", this, _impl.get());
}
virtual ~FileSystem() {
MEMF("FileSystem object destroyed, this: 0x%X, impl: 0x%X", this, _impl.get());
}
inline FileSystem& operator = (const FileSystem& obj) {
_impl = obj._impl;
MEMF("FileSystem object copy created by assignment, this: 0x%X, impl: 0x%X", this, _impl.get());
return *this;
}
inline FileSystem& operator = (FileSystemImpl* impl) {
_impl.reset(impl);
MEMF("FileSystem object copy created by impl assignment, this: 0x%X, impl: 0x%X", this, _impl.get());
return *this;
}
inline operator bool() const {
MEMF("FileSystem object bool, this: 0x%X, impl: 0x%X", this, _impl.get());
return _impl.get() != nullptr;
}
inline bool operator < (const FileSystem& obj) const {
MEMF("FileSystem object <, this: 0x%X, impl: 0x%X", this, _impl.get());
return _impl.get() < obj._impl.get();
}
inline bool operator > (const FileSystem& obj) const {
MEMF("FileSystem object <, this: 0x%X, impl: 0x%X", this, _impl.get());
return _impl.get() > obj._impl.get();
}
inline bool operator == (const FileSystem& obj) const {
MEMF("FileSystem object ==, this: 0x%X, impl: 0x%X", this, _impl.get());
return _impl.get() == obj._impl.get();
}
inline bool operator != (const FileSystem& obj) const {
MEMF("FileSystem object !=, this: 0x%X, impl: 0x%X", this, _impl.get());
return _impl.get() != obj._impl.get();
}
inline FileSystemImpl* get() {
return _impl.get();
}
inline void clear() {
_impl.reset();
}
public:
inline bool init() { assert(_impl); return _impl->init(); }
inline void loop() { assert(_impl); return _impl->loop(); }
inline bool file_exists(const char* file_path) { assert(_impl); return _impl->file_exists(file_path); }
inline size_t read_file(const char* file_path, Bytes& data) { assert(_impl); return _impl->read_file(file_path, data); }
inline size_t write_file(const char* file_path, const Bytes& data) { assert(_impl); return _impl->write_file(file_path, data); }
inline FileStream open_file(const char* file_path, FileStream::MODE file_mode) { return _impl->open_file(file_path, file_mode); }
inline bool remove_file(const char* file_path) { assert(_impl); return _impl->remove_file(file_path); }
inline bool rename_file(const char* from_file_path, const char* to_file_path) { assert(_impl); return _impl->rename_file(from_file_path, to_file_path); }
inline bool directory_exists(const char* directory_path) { assert(_impl); return _impl->directory_exists(directory_path); }
inline bool create_directory(const char* directory_path) { assert(_impl); return _impl->create_directory(directory_path); }
inline bool remove_directory(const char* directory_path) { assert(_impl); return _impl->remove_directory(directory_path); }
inline std::list<std::string> list_directory(const char* directory_path) { assert(_impl); return _impl->list_directory(directory_path); }
inline size_t storage_size() { assert(_impl); return _impl->storage_size(); }
inline size_t storage_available() { assert(_impl); return _impl->storage_available(); }
private:
std::list<std::string> _empty;
// getters/setters
protected:
public:
#ifndef NDEBUG
inline std::string debugString() const {
std::string dump;
dump = "FileSystem object, this: " + std::to_string((uintptr_t)this) + ", data: " + std::to_string((uintptr_t)_impl.get());
return dump;
}
#endif
protected:
std::shared_ptr<FileSystemImpl> _impl;
};
}