mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-01 07:30:33 +00:00
* Initial version of NextHopRouter * Set original hop limit in header flags * Short-circuit to FloodingRouter for broadcasts * If packet traveled 1 hop, set `relay_node` as `next_hop` for the original transmitter * Set last byte to 0xFF if it ended at 0x00 As per an idea of @S5NC * Also update next-hop based on received DM for us * temp * Add 1 retransmission for intermediate hops when using NextHopRouter * Add next_hop and relayed_by in PacketHistory for setting next-hop and handle flooding fallback * Update protos, store multiple relayers * Remove next-hop update logic from NeighborInfoModule * Fix retransmissions * Improve ACKs for repeated packets and responses * Stop retransmission even if there's not relay node * Revert perhapsRebroadcast() * Remove relayer if we cancel a transmission * Better checking for fallback to flooding * Fix newlines in traceroute print logs * Stop retransmission for original packet * Use relayID * Also when want_ack is set, we should try to retransmit * Fix cppcheck error * Fix 'router' not in scope error * Fix another cppcheck error * Check for hop_limit and also update next hop when `hop_start == hop_limit` on ACK Also check for broadcast in `getNextHop()` * Formatting and correct NUM_RETRANSMISSIONS * Update protos * Start retransmissions in NextHopRouter if ReliableRouter didn't do it * Handle repeated/fallback to flooding packets properly First check if it's not still in the TxQueue * Guard against clients setting `next_hop`/`relay_node` * Don't cancel relay if we were the assigned next-hop * Replies (e.g. tapback emoji) are also a valid confirmation of receipt --------- Co-authored-by: GUVWAF <thijs@havinga.eu> Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com> Co-authored-by: Tom Fifield <tom@tomfifield.net> Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
69 lines
2.6 KiB
C
69 lines
2.6 KiB
C
#pragma once
|
|
|
|
// low level types
|
|
|
|
#include "MemoryPool.h"
|
|
#include "mesh/mesh-pb-constants.h"
|
|
#include <Arduino.h>
|
|
|
|
typedef uint32_t NodeNum;
|
|
typedef uint32_t PacketId; // A packet sequence number
|
|
|
|
#define NODENUM_BROADCAST UINT32_MAX
|
|
#define NODENUM_BROADCAST_NO_LORA \
|
|
1 // Reserved to only deliver packets over high speed (non-lora) transports, such as MQTT or BLE mesh (not yet implemented)
|
|
#define ERRNO_OK 0
|
|
#define ERRNO_NO_INTERFACES 33
|
|
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
|
|
#define ERRNO_DISABLED 34 // the interface is disabled
|
|
#define ERRNO_SHOULD_RELEASE 35 // no error, but the packet should still be released
|
|
#define ID_COUNTER_MASK (UINT32_MAX >> 22) // mask to select the counter portion of the ID
|
|
|
|
/*
|
|
* Source of a received message
|
|
*/
|
|
enum RxSource {
|
|
RX_SRC_LOCAL, // message was generated locally
|
|
RX_SRC_RADIO, // message was received from radio mesh
|
|
RX_SRC_USER // message was received from end-user device
|
|
};
|
|
|
|
/**
|
|
* the max number of hops a message can pass through, used as the default max for hop_limit in MeshPacket.
|
|
*
|
|
* We reserve 3 bits in the header so this could be up to 7, but given the high range of lora and typical usecases, keeping
|
|
* maxhops to 3 should be fine for a while. This also serves to prevent routing/flooding attempts to be attempted for
|
|
* too long.
|
|
**/
|
|
#define HOP_MAX 7
|
|
|
|
/// We normally just use max 3 hops for sending reliable messages
|
|
#define HOP_RELIABLE 3
|
|
|
|
// For old firmware or when falling back to flooding, there is no next-hop preference
|
|
#define NO_NEXT_HOP_PREFERENCE 0
|
|
// For old firmware there is no relay node set
|
|
#define NO_RELAY_NODE 0
|
|
|
|
typedef int ErrorCode;
|
|
|
|
/// Alloc and free packets to our global, ISR safe pool
|
|
extern Allocator<meshtastic_MeshPacket> &packetPool;
|
|
using UniquePacketPoolPacket = Allocator<meshtastic_MeshPacket>::UniqueAllocation;
|
|
|
|
/**
|
|
* Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on
|
|
* the local node. If from is zero this function returns our node number instead
|
|
*/
|
|
NodeNum getFrom(const meshtastic_MeshPacket *p);
|
|
|
|
// Returns true if the packet originated from the local node
|
|
bool isFromUs(const meshtastic_MeshPacket *p);
|
|
|
|
// Returns true if the packet is destined to us
|
|
bool isToUs(const meshtastic_MeshPacket *p);
|
|
|
|
/* Some clients might not properly set priority, therefore we fix it here. */
|
|
void fixPriority(meshtastic_MeshPacket *p);
|
|
|
|
bool isBroadcast(uint32_t dest); |