mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 17:52:35 +00:00
re-add namespacing in protobufs. Let's see what i missed. Portduino likely ...
Checking in generated on purpose.
This commit is contained in:
@@ -35,9 +35,9 @@ extern "C" {
|
||||
2) // max number of packets which can be in flight (either queued from reception or queued for sending)
|
||||
|
||||
// static MemoryPool<MeshPacket> staticPool(MAX_PACKETS);
|
||||
static MemoryDynamic<MeshPacket> staticPool;
|
||||
static MemoryDynamic<meshtastic_MeshPacket> staticPool;
|
||||
|
||||
Allocator<MeshPacket> &packetPool = staticPool;
|
||||
Allocator<meshtastic_MeshPacket> &packetPool = staticPool;
|
||||
|
||||
static uint8_t bytes[MAX_RHPACKETLEN];
|
||||
|
||||
@@ -63,7 +63,7 @@ Router::Router() : concurrency::OSThread("Router"), fromRadioQueue(MAX_RX_FROMRA
|
||||
*/
|
||||
int32_t Router::runOnce()
|
||||
{
|
||||
MeshPacket *mp;
|
||||
meshtastic_MeshPacket *mp;
|
||||
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL) {
|
||||
// printPacket("handle fromRadioQ", mp);
|
||||
perhapsHandleReceived(mp);
|
||||
@@ -77,7 +77,7 @@ int32_t Router::runOnce()
|
||||
* RadioInterface calls this to queue up packets that have been received from the radio. The router is now responsible for
|
||||
* freeing the packet
|
||||
*/
|
||||
void Router::enqueueReceivedMessage(MeshPacket *p)
|
||||
void Router::enqueueReceivedMessage(meshtastic_MeshPacket *p)
|
||||
{
|
||||
if (fromRadioQueue.enqueue(p, 0)) { // NOWAIT - fixme, if queue is full, delete older messages
|
||||
|
||||
@@ -112,11 +112,11 @@ PacketId generatePacketId()
|
||||
return id;
|
||||
}
|
||||
|
||||
MeshPacket *Router::allocForSending()
|
||||
meshtastic_MeshPacket *Router::allocForSending()
|
||||
{
|
||||
MeshPacket *p = packetPool.allocZeroed();
|
||||
meshtastic_MeshPacket *p = packetPool.allocZeroed();
|
||||
|
||||
p->which_payload_variant = MeshPacket_decoded_tag; // Assume payload is decoded at start.
|
||||
p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Assume payload is decoded at start.
|
||||
p->from = nodeDB.getNodeNum();
|
||||
p->to = NODENUM_BROADCAST;
|
||||
p->hop_limit = (config.lora.hop_limit >= HOP_MAX) ? HOP_MAX : config.lora.hop_limit;
|
||||
@@ -130,12 +130,12 @@ MeshPacket *Router::allocForSending()
|
||||
/**
|
||||
* Send an ack or a nak packet back towards whoever sent idFrom
|
||||
*/
|
||||
void Router::sendAckNak(Routing_Error err, NodeNum to, PacketId idFrom, ChannelIndex chIndex)
|
||||
void Router::sendAckNak(meshtastic_Routing_Error err, NodeNum to, PacketId idFrom, ChannelIndex chIndex)
|
||||
{
|
||||
routingModule->sendAckNak(err, to, idFrom, chIndex);
|
||||
}
|
||||
|
||||
void Router::abortSendAndNak(Routing_Error err, MeshPacket *p)
|
||||
void Router::abortSendAndNak(meshtastic_Routing_Error err, meshtastic_MeshPacket *p)
|
||||
{
|
||||
LOG_ERROR("Error=%d, returning NAK and dropping packet.\n", err);
|
||||
sendAckNak(err, getFrom(p), p->id, p->channel);
|
||||
@@ -149,12 +149,12 @@ void Router::setReceivedMessage()
|
||||
runASAP = true;
|
||||
}
|
||||
|
||||
QueueStatus Router::getQueueStatus()
|
||||
meshtastic_QueueStatus Router::getQueueStatus()
|
||||
{
|
||||
return iface->getQueueStatus();
|
||||
}
|
||||
|
||||
ErrorCode Router::sendLocal(MeshPacket *p, RxSource src)
|
||||
ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src)
|
||||
{
|
||||
// No need to deliver externally if the destination is the local node
|
||||
if (p->to == nodeDB.getNodeNum()) {
|
||||
@@ -163,7 +163,7 @@ ErrorCode Router::sendLocal(MeshPacket *p, RxSource src)
|
||||
return ERRNO_OK;
|
||||
} else if (!iface) {
|
||||
// We must be sending to remote nodes also, fail if no interface found
|
||||
abortSendAndNak(Routing_Error_NO_INTERFACE, p);
|
||||
abortSendAndNak(meshtastic_Routing_Error_NO_INTERFACE, p);
|
||||
|
||||
return ERRNO_NO_INTERFACES;
|
||||
} else {
|
||||
@@ -190,12 +190,12 @@ void printBytes(const char *label, const uint8_t *p, size_t numbytes)
|
||||
* later free() the packet to pool. This routine is not allowed to stall.
|
||||
* If the txmit queue is full it might return an error.
|
||||
*/
|
||||
ErrorCode Router::send(MeshPacket *p)
|
||||
ErrorCode Router::send(meshtastic_MeshPacket *p)
|
||||
{
|
||||
if (p->to == nodeDB.getNodeNum()) {
|
||||
LOG_ERROR("BUG! send() called with packet destined for local node!\n");
|
||||
packetPool.release(p);
|
||||
return Routing_Error_BAD_REQUEST;
|
||||
return meshtastic_Routing_Error_BAD_REQUEST;
|
||||
} // should have already been handled by sendLocal
|
||||
|
||||
// Abort sending if we are violating the duty cycle
|
||||
@@ -204,7 +204,7 @@ ErrorCode Router::send(MeshPacket *p)
|
||||
if (hourlyTxPercent > myRegion->dutyCycle) {
|
||||
uint8_t silentMinutes = airTime->getSilentMinutes(hourlyTxPercent, myRegion->dutyCycle);
|
||||
LOG_WARN("Duty cycle limit exceeded. Aborting send for now, you can send again in %d minutes.\n", silentMinutes);
|
||||
Routing_Error err = Routing_Error_DUTY_CYCLE_LIMIT;
|
||||
meshtastic_Routing_Error err = meshtastic_Routing_Error_DUTY_CYCLE_LIMIT;
|
||||
if (getFrom(p) == nodeDB.getNodeNum()) { // only send NAK to API, not to the mesh
|
||||
abortSendAndNak(err, p);
|
||||
} else {
|
||||
@@ -228,11 +228,11 @@ ErrorCode Router::send(MeshPacket *p)
|
||||
|
||||
// If the packet hasn't yet been encrypted, do so now (it might already be encrypted if we are just forwarding it)
|
||||
|
||||
assert(p->which_payload_variant == MeshPacket_encrypted_tag ||
|
||||
p->which_payload_variant == MeshPacket_decoded_tag); // I _think_ all packets should have a payload by now
|
||||
assert(p->which_payload_variant == meshtastic_MeshPacket_encrypted_tag ||
|
||||
p->which_payload_variant == meshtastic_MeshPacket_decoded_tag); // I _think_ all packets should have a payload by now
|
||||
|
||||
// If the packet is not yet encrypted, do so now
|
||||
if (p->which_payload_variant == MeshPacket_decoded_tag) {
|
||||
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
||||
ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it
|
||||
|
||||
bool shouldActuallyEncrypt = true;
|
||||
@@ -264,7 +264,7 @@ ErrorCode Router::send(MeshPacket *p)
|
||||
#endif
|
||||
|
||||
auto encodeResult = perhapsEncode(p);
|
||||
if (encodeResult != Routing_Error_NONE) {
|
||||
if (encodeResult != meshtastic_Routing_Error_NONE) {
|
||||
abortSendAndNak(encodeResult, p);
|
||||
return encodeResult; // FIXME - this isn't a valid ErrorCode
|
||||
}
|
||||
@@ -293,17 +293,17 @@ bool Router::cancelSending(NodeNum from, PacketId id)
|
||||
* Every (non duplicate) packet this node receives will be passed through this method. This allows subclasses to
|
||||
* update routing tables etc... based on what we overhear (even for messages not destined to our node)
|
||||
*/
|
||||
void Router::sniffReceived(const MeshPacket *p, const Routing *c)
|
||||
void Router::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c)
|
||||
{
|
||||
// FIXME, update nodedb here for any packet that passes through us
|
||||
}
|
||||
|
||||
bool perhapsDecode(MeshPacket *p)
|
||||
bool perhapsDecode(meshtastic_MeshPacket *p)
|
||||
{
|
||||
|
||||
// LOG_DEBUG("\n\n** perhapsDecode payloadVariant - %d\n\n", p->which_payloadVariant);
|
||||
|
||||
if (p->which_payload_variant == MeshPacket_decoded_tag)
|
||||
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag)
|
||||
return true; // If packet was already decoded just return
|
||||
|
||||
// assert(p->which_payloadVariant == MeshPacket_encrypted_tag);
|
||||
@@ -323,20 +323,20 @@ bool perhapsDecode(MeshPacket *p)
|
||||
|
||||
// Take those raw bytes and convert them back into a well structured protobuf we can understand
|
||||
memset(&p->decoded, 0, sizeof(p->decoded));
|
||||
if (!pb_decode_from_bytes(bytes, rawSize, &Data_msg, &p->decoded)) {
|
||||
if (!pb_decode_from_bytes(bytes, rawSize, &meshtastic_Data_msg, &p->decoded)) {
|
||||
LOG_ERROR("Invalid protobufs in received mesh packet (bad psk?)!\n");
|
||||
} else if (p->decoded.portnum == PortNum_UNKNOWN_APP) {
|
||||
} else if (p->decoded.portnum == meshtastic_PortNum_UNKNOWN_APP) {
|
||||
LOG_ERROR("Invalid portnum (bad psk?)!\n");
|
||||
} else {
|
||||
// parsing was successful
|
||||
p->which_payload_variant = MeshPacket_decoded_tag; // change type to decoded
|
||||
p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // change type to decoded
|
||||
p->channel = chIndex; // change to store the index instead of the hash
|
||||
|
||||
// Decompress if needed. jm
|
||||
if (p->decoded.portnum == PortNum_TEXT_MESSAGE_COMPRESSED_APP) {
|
||||
if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_COMPRESSED_APP) {
|
||||
// Decompress the payload
|
||||
char compressed_in[Constants_DATA_PAYLOAD_LEN] = {};
|
||||
char decompressed_out[Constants_DATA_PAYLOAD_LEN] = {};
|
||||
char compressed_in[meshtastic_Constants_DATA_PAYLOAD_LEN] = {};
|
||||
char decompressed_out[meshtastic_Constants_DATA_PAYLOAD_LEN] = {};
|
||||
int decompressed_len;
|
||||
|
||||
memcpy(compressed_in, p->decoded.payload.bytes, p->decoded.payload.size);
|
||||
@@ -348,7 +348,7 @@ bool perhapsDecode(MeshPacket *p)
|
||||
memcpy(p->decoded.payload.bytes, decompressed_out, decompressed_len);
|
||||
|
||||
// Switch the port from PortNum_TEXT_MESSAGE_COMPRESSED_APP to PortNum_TEXT_MESSAGE_APP
|
||||
p->decoded.portnum = PortNum_TEXT_MESSAGE_APP;
|
||||
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
|
||||
}
|
||||
|
||||
printPacket("decoded message", p);
|
||||
@@ -363,21 +363,21 @@ bool perhapsDecode(MeshPacket *p)
|
||||
|
||||
/** Return 0 for success or a Routing_Errror code for failure
|
||||
*/
|
||||
Routing_Error perhapsEncode(MeshPacket *p)
|
||||
meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p)
|
||||
{
|
||||
// If the packet is not yet encrypted, do so now
|
||||
if (p->which_payload_variant == MeshPacket_decoded_tag) {
|
||||
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
||||
|
||||
size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), &Data_msg, &p->decoded);
|
||||
size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_Data_msg, &p->decoded);
|
||||
|
||||
// Only allow encryption on the text message app.
|
||||
// TODO: Allow modules to opt into compression.
|
||||
if (p->decoded.portnum == PortNum_TEXT_MESSAGE_APP) {
|
||||
if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) {
|
||||
|
||||
char original_payload[Constants_DATA_PAYLOAD_LEN];
|
||||
char original_payload[meshtastic_Constants_DATA_PAYLOAD_LEN];
|
||||
memcpy(original_payload, p->decoded.payload.bytes, p->decoded.payload.size);
|
||||
|
||||
char compressed_out[Constants_DATA_PAYLOAD_LEN] = {0};
|
||||
char compressed_out[meshtastic_Constants_DATA_PAYLOAD_LEN] = {0};
|
||||
|
||||
int compressed_len;
|
||||
compressed_len = unishox2_compress_simple(original_payload, p->decoded.payload.size, compressed_out);
|
||||
@@ -401,12 +401,12 @@ Routing_Error perhapsEncode(MeshPacket *p)
|
||||
p->decoded.payload.size = compressed_len;
|
||||
memcpy(p->decoded.payload.bytes, compressed_out, compressed_len);
|
||||
|
||||
p->decoded.portnum = PortNum_TEXT_MESSAGE_COMPRESSED_APP;
|
||||
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_COMPRESSED_APP;
|
||||
}
|
||||
}
|
||||
|
||||
if (numbytes > MAX_RHPACKETLEN)
|
||||
return Routing_Error_TOO_LARGE;
|
||||
return meshtastic_Routing_Error_TOO_LARGE;
|
||||
|
||||
// printBytes("plaintext", bytes, numbytes);
|
||||
|
||||
@@ -414,7 +414,7 @@ Routing_Error perhapsEncode(MeshPacket *p)
|
||||
auto hash = channels.setActiveByIndex(chIndex);
|
||||
if (hash < 0)
|
||||
// No suitable channel could be found for sending
|
||||
return Routing_Error_NO_CHANNEL;
|
||||
return meshtastic_Routing_Error_NO_CHANNEL;
|
||||
|
||||
// Now that we are encrypting the packet channel should be the hash (no longer the index)
|
||||
p->channel = hash;
|
||||
@@ -423,10 +423,10 @@ Routing_Error perhapsEncode(MeshPacket *p)
|
||||
// Copy back into the packet and set the variant type
|
||||
memcpy(p->encrypted.bytes, bytes, numbytes);
|
||||
p->encrypted.size = numbytes;
|
||||
p->which_payload_variant = MeshPacket_encrypted_tag;
|
||||
p->which_payload_variant = meshtastic_MeshPacket_encrypted_tag;
|
||||
}
|
||||
|
||||
return Routing_Error_NONE;
|
||||
return meshtastic_Routing_Error_NONE;
|
||||
}
|
||||
|
||||
NodeNum Router::getNodeNum()
|
||||
@@ -438,7 +438,7 @@ NodeNum Router::getNodeNum()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
*/
|
||||
void Router::handleReceived(MeshPacket *p, RxSource src)
|
||||
void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src)
|
||||
{
|
||||
// Also, we should set the time from the ISR and it should have msec level resolution
|
||||
p->rx_time = getValidTime(RTCQualityFromNet); // store the arrival timestamp for the phone
|
||||
@@ -461,7 +461,7 @@ void Router::handleReceived(MeshPacket *p, RxSource src)
|
||||
MeshModule::callPlugins(*p, src);
|
||||
}
|
||||
|
||||
void Router::perhapsHandleReceived(MeshPacket *p)
|
||||
void Router::perhapsHandleReceived(meshtastic_MeshPacket *p)
|
||||
{
|
||||
// assert(radioConfig.has_preferences);
|
||||
bool ignore = is_in_repeated(config.lora.ignore_incoming, p->from);
|
||||
|
||||
Reference in New Issue
Block a user