feat: implement RNS transport (Smol Mail 1.2) over microReticulum
This commit is contained in:
parent
af1d31be83
commit
7203556186
19 changed files with 1939 additions and 1141 deletions
64
shim/udp_interface.h
Normal file
64
shim/udp_interface.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* UDP interface for the bunshin RNS shim, adapted from microReticulum's
|
||||
* examples/common/udp_interface (Apache-2.0). The example version hardcodes
|
||||
* compile-time defaults; this one takes its endpoints from the caller, and
|
||||
* with no forward target configured it sends to the source address of the
|
||||
* last datagram received, so a listen-only server can answer any client.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <microReticulum/Interface.h>
|
||||
#include <microReticulum/Bytes.h>
|
||||
#include <microReticulum/Type.h>
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include <WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
class UDPInterface : public RNS::InterfaceImpl {
|
||||
|
||||
public:
|
||||
static const uint32_t BITRATE_GUESS = 10*1000*1000;
|
||||
|
||||
UDPInterface(const char* name,
|
||||
const std::string& local_host, int local_port,
|
||||
const std::string& remote_host, int remote_port);
|
||||
virtual ~UDPInterface();
|
||||
|
||||
virtual bool start();
|
||||
virtual void stop();
|
||||
virtual void loop();
|
||||
|
||||
virtual inline std::string toString() const { return "UDPInterface[" + _name + "/" + _local_host + ":" + std::to_string(_local_port) + "]"; }
|
||||
|
||||
protected:
|
||||
virtual bool send_outgoing(const RNS::Bytes& data);
|
||||
void on_incoming(const RNS::Bytes& data);
|
||||
|
||||
private:
|
||||
RNS::Bytes _buffer;
|
||||
|
||||
std::string _local_host;
|
||||
int _local_port;
|
||||
std::string _remote_host;
|
||||
int _remote_port;
|
||||
|
||||
bool _forward_configured = false;
|
||||
|
||||
#ifdef ARDUINO
|
||||
WiFiUDP udp;
|
||||
#else
|
||||
int _socket = -1;
|
||||
in_addr_t _local_address = INADDR_ANY;
|
||||
in_addr_t _remote_address = INADDR_NONE;
|
||||
sockaddr_in _last_src_addr = {};
|
||||
bool _have_src = false;
|
||||
#endif
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue