Skip to content

Commit 6a29480

Browse files
committed
sneaky mode refactor - hide in payload v1, don't use v2
1 parent d189d8a commit 6a29480

9 files changed

Lines changed: 196 additions & 171 deletions

File tree

examples/simple_repeater/MyMesh.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,17 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
530530

531531
if (reply_len == 0) return; // invalid request
532532

533-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
533+
bool use_chacha = peerSupportsCHACHA(sender);
534534
if (packet->isRouteFlood()) {
535535
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
536536
mesh::Packet* path = createPathReturn(sender, secret, packet->path, packet->path_len,
537-
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_v2);
537+
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_chacha);
538538
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
539539
} else if (reply_path_len < 0) {
540-
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, use_v2);
540+
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, use_chacha);
541541
if (reply) sendFlood(reply, SERVER_RESPONSE_DELAY);
542542
} else {
543-
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, use_v2);
543+
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, use_chacha);
544544
if (reply) sendDirect(reply, reply_path, reply_path_len, SERVER_RESPONSE_DELAY);
545545
}
546546
}
@@ -624,15 +624,15 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
624624
client->last_timestamp = timestamp;
625625
client->last_activity = getRTCClock()->getCurrentTime();
626626

627-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
627+
bool use_chacha = client->supports_chacha;
628628
if (packet->isRouteFlood()) {
629629
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
630630
mesh::Packet *path = createPathReturn(client->id, secret, packet->path, packet->path_len,
631-
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_v2);
631+
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_chacha);
632632
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
633633
} else {
634634
mesh::Packet *reply =
635-
createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len, use_v2);
635+
createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len, use_chacha);
636636
if (reply) {
637637
if (client->out_path_len >= 0) { // we have an out_path, so send DIRECT
638638
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
@@ -693,8 +693,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
693693
memcpy(temp, &timestamp, 4); // mostly an extra blob to help make packet_hash unique
694694
temp[4] = (TXT_TYPE_CLI_DATA << 2); // NOTE: legacy was: TXT_TYPE_PLAIN
695695

696-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
697-
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len, use_v2);
696+
bool use_chacha = client->supports_chacha;
697+
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len, use_chacha);
698698
if (reply) {
699699
if (client->out_path_len < 0) {
700700
sendFlood(reply, CLI_REPLY_DELAY_MILLIS);

examples/simple_room_server/MyMesh.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ void MyMesh::pushPostToClient(ClientInfo *client, PostInfo &post) {
7171
mesh::Utils::sha256((uint8_t *)&client->extra.room.pending_ack, 4, reply_data, len, client->id.pub_key, PUB_KEY_SIZE);
7272
client->extra.room.push_post_timestamp = post.post_timestamp;
7373

74-
bool use_v2 = client->supports_chacha;
75-
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, client->shared_secret, reply_data, len, use_v2);
74+
bool use_chacha = client->supports_chacha;
75+
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, client->shared_secret, reply_data, len, use_chacha);
7676
if (reply) {
7777
if (client->out_path_len < 0) {
7878
sendFlood(reply);
@@ -350,14 +350,14 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
350350

351351
next_push = futureMillis(PUSH_NOTIFY_DELAY_MILLIS); // delay next push, give RESPONSE packet time to arrive first
352352

353-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
353+
bool use_chacha = client->supports_chacha;
354354
if (packet->isRouteFlood()) {
355355
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
356356
mesh::Packet *path = createPathReturn(sender, client->shared_secret, packet->path, packet->path_len,
357-
PAYLOAD_TYPE_RESPONSE, reply_data, 13, use_v2);
357+
PAYLOAD_TYPE_RESPONSE, reply_data, 13, use_chacha);
358358
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
359359
} else {
360-
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, client->shared_secret, reply_data, 13, use_v2);
360+
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, client->shared_secret, reply_data, 13, use_chacha);
361361
if (reply) {
362362
if (client->out_path_len >= 0) { // we have an out_path, so send DIRECT
363363
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
@@ -506,8 +506,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
506506
// mesh::Utils::sha256((uint8_t *)&expected_ack_crc, 4, temp, 5 + text_len, self_id.pub_key,
507507
// PUB_KEY_SIZE);
508508

509-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
510-
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len, use_v2);
509+
bool use_chacha = client->supports_chacha;
510+
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len, use_chacha);
511511
if (reply) {
512512
if (client->out_path_len < 0) {
513513
sendFlood(reply, delay_millis + SERVER_RESPONSE_DELAY);
@@ -561,14 +561,14 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
561561
} else {
562562
int reply_len = handleRequest(client, sender_timestamp, &data[4], len - 4);
563563
if (reply_len > 0) { // valid command
564-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
564+
bool use_chacha = client->supports_chacha;
565565
if (packet->isRouteFlood()) {
566566
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
567567
mesh::Packet *path = createPathReturn(client->id, secret, packet->path, packet->path_len,
568-
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_v2);
568+
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_chacha);
569569
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
570570
} else {
571-
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len, use_v2);
571+
mesh::Packet *reply = createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len, use_chacha);
572572
if (reply) {
573573
if (client->out_path_len >= 0) { // we have an out_path, so send DIRECT
574574
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);

examples/simple_sensor/SensorMesh.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ void SensorMesh::sendAlert(const ClientInfo* c, Trigger* t) {
256256
mesh::Utils::sha256((uint8_t *)&t->expected_acks[t->attempt], 4, data, 5 + text_len, self_id.pub_key, PUB_KEY_SIZE);
257257
t->attempt++;
258258

259-
bool use_v2 = c->supports_chacha;
260-
auto pkt = createDatagram(PAYLOAD_TYPE_TXT_MSG, c->id, c->shared_secret, data, 5 + text_len, use_v2);
259+
bool use_chacha = c->supports_chacha;
260+
auto pkt = createDatagram(PAYLOAD_TYPE_TXT_MSG, c->id, c->shared_secret, data, 5 + text_len, use_chacha);
261261
if (pkt) {
262262
if (c->out_path_len >= 0) { // we have an out_path, so send DIRECT
263263
sendDirect(pkt, c->out_path, c->out_path_len);
@@ -465,14 +465,14 @@ void SensorMesh::onAnonDataRecv(mesh::Packet* packet, const uint8_t* secret, con
465465

466466
if (reply_len == 0) return; // invalid request
467467

468-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
468+
bool use_chacha = peerSupportsCHACHA(sender);
469469
if (packet->isRouteFlood()) {
470470
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
471471
mesh::Packet* path = createPathReturn(sender, secret, packet->path, packet->path_len,
472-
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_v2);
472+
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_chacha);
473473
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
474474
} else {
475-
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, use_v2);
475+
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, use_chacha);
476476
if (reply) sendFlood(reply, SERVER_RESPONSE_DELAY);
477477
}
478478
}
@@ -559,14 +559,14 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
559559
from->last_timestamp = timestamp;
560560
from->last_activity = getRTCClock()->getCurrentTime();
561561

562-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
562+
bool use_chacha = from->supports_chacha;
563563
if (packet->isRouteFlood()) {
564564
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
565565
mesh::Packet* path = createPathReturn(from->id, secret, packet->path, packet->path_len,
566-
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_v2);
566+
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, use_chacha);
567567
if (path) sendFlood(path, SERVER_RESPONSE_DELAY);
568568
} else {
569-
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, from->id, secret, reply_data, reply_len, use_v2);
569+
mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, from->id, secret, reply_data, reply_len, use_chacha);
570570
if (reply) {
571571
if (from->out_path_len >= 0) { // we have an out_path, so send DIRECT
572572
sendDirect(reply, from->out_path, from->out_path_len, SERVER_RESPONSE_DELAY);
@@ -592,9 +592,9 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
592592

593593
if (packet->isRouteFlood()) {
594594
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
595-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
595+
bool use_chacha = from->supports_chacha;
596596
mesh::Packet* path = createPathReturn(from->id, secret, packet->path, packet->path_len,
597-
PAYLOAD_TYPE_ACK, (uint8_t *) &ack_hash, 4, use_v2);
597+
PAYLOAD_TYPE_ACK, (uint8_t *) &ack_hash, 4, use_chacha);
598598
if (path) sendFlood(path, TXT_ACK_DELAY);
599599
} else {
600600
sendAckTo(*from, ack_hash);
@@ -622,8 +622,8 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
622622
memcpy(temp, &timestamp, 4); // mostly an extra blob to help make packet_hash unique
623623
temp[4] = (TXT_TYPE_CLI_DATA << 2);
624624

625-
bool use_v2 = (packet->getPayloadVer() == PAYLOAD_VER_2);
626-
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, from->id, secret, temp, 5 + text_len, use_v2);
625+
bool use_chacha = from->supports_chacha;
626+
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, from->id, secret, temp, 5 + text_len, use_chacha);
627627
if (reply) {
628628
if (from->out_path_len < 0) {
629629
sendFlood(reply, CLI_REPLY_DELAY_MILLIS);

0 commit comments

Comments
 (0)