@@ -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);
@@ -280,7 +280,7 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
280280}
281281
282282void MyMesh::onAnonDataRecv (mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender,
283- uint8_t *data, size_t len) {
283+ uint8_t *data, size_t len, bool decrypted_with_chacha ) {
284284 if (packet->getPayloadType () == PAYLOAD_TYPE_ANON_REQ ) { // received an initial request by a possible admin
285285 // client (unknown at this stage)
286286 uint32_t sender_timestamp, sender_sync_since;
@@ -350,14 +350,17 @@ 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+ // Mark peer as ChaCha-capable if we decoded their packet with ChaCha
354+ if (decrypted_with_chacha) client->supports_chacha = true ;
355+
356+ bool use_chacha = client->supports_chacha ;
354357 if (packet->isRouteFlood ()) {
355358 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
356359 mesh::Packet *path = createPathReturn (sender, client->shared_secret , packet->path , packet->path_len ,
357- PAYLOAD_TYPE_RESPONSE , reply_data, 13 , use_v2 );
360+ PAYLOAD_TYPE_RESPONSE , reply_data, 13 , use_chacha );
358361 if (path) sendFlood (path, SERVER_RESPONSE_DELAY );
359362 } else {
360- mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , sender, client->shared_secret , reply_data, 13 , use_v2 );
363+ mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , sender, client->shared_secret , reply_data, 13 , use_chacha );
361364 if (reply) {
362365 if (client->out_path_len >= 0 ) { // we have an out_path, so send DIRECT
363366 sendDirect (reply, client->out_path , client->out_path_len , SERVER_RESPONSE_DELAY );
@@ -395,10 +398,24 @@ bool MyMesh::peerSupportsCHACHA(const mesh::Identity& dest) {
395398 if (client) {
396399 return client->supports_chacha ;
397400 }
398- // Unknown peer - default to v1 (safe fallback)
401+ // Unknown peer - default to AES (safe fallback)
399402 return false ;
400403}
401404
405+ void MyMesh::setPeerSupportsCHACHA (const mesh::Identity* id, int peer_idx) {
406+ if (peer_idx >= 0 ) {
407+ int i = matching_peer_indexes[peer_idx];
408+ if (i >= 0 && i < acl.getNumClients ()) {
409+ acl.getClientByIdx (i)->supports_chacha = true ;
410+ }
411+ } else if (id != nullptr ) {
412+ ClientInfo* client = acl.getClient (id->pub_key , PUB_KEY_SIZE );
413+ if (client) {
414+ client->supports_chacha = true ;
415+ }
416+ }
417+ }
418+
402419void MyMesh::onAdvertRecv (mesh::Packet *packet, const mesh::Identity &id, uint32_t timestamp,
403420 const uint8_t *app_data, size_t app_data_len) {
404421 mesh::Mesh::onAdvertRecv (packet, id, timestamp, app_data, app_data_len); // chain to super impl
@@ -506,8 +523,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
506523 // mesh::Utils::sha256((uint8_t *)&expected_ack_crc, 4, temp, 5 + text_len, self_id.pub_key,
507524 // PUB_KEY_SIZE);
508525
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 );
526+ bool use_chacha = client-> supports_chacha ;
527+ auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG , client->id , secret, temp, 5 + text_len, use_chacha );
511528 if (reply) {
512529 if (client->out_path_len < 0 ) {
513530 sendFlood (reply, delay_millis + SERVER_RESPONSE_DELAY );
@@ -561,14 +578,14 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
561578 } else {
562579 int reply_len = handleRequest (client, sender_timestamp, &data[4 ], len - 4 );
563580 if (reply_len > 0 ) { // valid command
564- bool use_v2 = (packet-> getPayloadVer () == PAYLOAD_VER_2 ) ;
581+ bool use_chacha = client-> supports_chacha ;
565582 if (packet->isRouteFlood ()) {
566583 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
567584 mesh::Packet *path = createPathReturn (client->id , secret, packet->path , packet->path_len ,
568- PAYLOAD_TYPE_RESPONSE , reply_data, reply_len, use_v2 );
585+ PAYLOAD_TYPE_RESPONSE , reply_data, reply_len, use_chacha );
569586 if (path) sendFlood (path, SERVER_RESPONSE_DELAY );
570587 } else {
571- mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , client->id , secret, reply_data, reply_len, use_v2 );
588+ mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , client->id , secret, reply_data, reply_len, use_chacha );
572589 if (reply) {
573590 if (client->out_path_len >= 0 ) { // we have an out_path, so send DIRECT
574591 sendDirect (reply, client->out_path , client->out_path_len , SERVER_RESPONSE_DELAY );
0 commit comments