@@ -208,6 +208,22 @@ void BaseChatMesh::getPeerSharedSecret(uint8_t* dest_secret, int peer_idx) {
208208 }
209209}
210210
211+ uint8_t BaseChatMesh::getPeerFlags (int peer_idx) {
212+ int i = matching_peer_indexes[peer_idx];
213+ if (i >= 0 && i < num_contacts) {
214+ return contacts[i].flags ;
215+ }
216+ return 0 ;
217+ }
218+
219+ uint16_t BaseChatMesh::getPeerNextAeadNonce (int peer_idx) {
220+ int i = matching_peer_indexes[peer_idx];
221+ if (i >= 0 && i < num_contacts) {
222+ return contacts[i].nextAeadNonce ();
223+ }
224+ return 0 ;
225+ }
226+
211227void BaseChatMesh::onPeerDataRecv (mesh::Packet* packet, uint8_t type, int sender_idx, const uint8_t * secret, uint8_t * data, size_t len) {
212228 int i = matching_peer_indexes[sender_idx];
213229 if (i < 0 || i >= num_contacts) {
@@ -235,7 +251,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
235251 if (packet->isRouteFlood ()) {
236252 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
237253 mesh::Packet* path = createPathReturn (from.id , secret, packet->path , packet->path_len ,
238- PAYLOAD_TYPE_ACK , (uint8_t *) &ack_hash, 4 );
254+ PAYLOAD_TYPE_ACK , (uint8_t *) &ack_hash, 4 , from. nextAeadNonce () );
239255 if (path) sendFloodScoped (from, path, TXT_ACK_DELAY );
240256 } else {
241257 sendAckTo (from, ack_hash);
@@ -246,7 +262,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
246262
247263 if (packet->isRouteFlood ()) {
248264 // let this sender know path TO here, so they can use sendDirect() (NOTE: no ACK as extra)
249- mesh::Packet* path = createPathReturn (from.id , secret, packet->path , packet->path_len , 0 , NULL , 0 );
265+ mesh::Packet* path = createPathReturn (from.id , secret, packet->path , packet->path_len , 0 , NULL , 0 , from. nextAeadNonce () );
250266 if (path) sendFloodScoped (from, path);
251267 }
252268 } else if (flags == TXT_TYPE_SIGNED_PLAIN ) {
@@ -262,7 +278,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
262278 if (packet->isRouteFlood ()) {
263279 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
264280 mesh::Packet* path = createPathReturn (from.id , secret, packet->path , packet->path_len ,
265- PAYLOAD_TYPE_ACK , (uint8_t *) &ack_hash, 4 );
281+ PAYLOAD_TYPE_ACK , (uint8_t *) &ack_hash, 4 , from. nextAeadNonce () );
266282 if (path) sendFloodScoped (from, path, TXT_ACK_DELAY );
267283 } else {
268284 sendAckTo (from, ack_hash);
@@ -278,10 +294,10 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
278294 if (packet->isRouteFlood ()) {
279295 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
280296 mesh::Packet* path = createPathReturn (from.id , secret, packet->path , packet->path_len ,
281- PAYLOAD_TYPE_RESPONSE , temp_buf, reply_len);
297+ PAYLOAD_TYPE_RESPONSE , temp_buf, reply_len, from. nextAeadNonce () );
282298 if (path) sendFloodScoped (from, path, SERVER_RESPONSE_DELAY );
283299 } else {
284- mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE , from.id , secret, temp_buf, reply_len);
300+ mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE , from.id , secret, temp_buf, reply_len, from. nextAeadNonce () );
285301 if (reply) {
286302 if (from.out_path_len != OUT_PATH_UNKNOWN ) { // we have an out_path, so send DIRECT
287303 sendDirect (reply, from.out_path , from.out_path_len , SERVER_RESPONSE_DELAY );
@@ -347,7 +363,7 @@ void BaseChatMesh::onAckRecv(mesh::Packet* packet, uint32_t ack_crc) {
347363void BaseChatMesh::handleReturnPathRetry (const ContactInfo& contact, const uint8_t * path, uint8_t path_len) {
348364 // NOTE: simplest impl is just to re-send a reciprocal return path to sender (DIRECTLY)
349365 // override this method in various firmwares, if there's a better strategy
350- mesh::Packet* rpath = createPathReturn (contact.id , contact.getSharedSecret (self_id), path, path_len, 0 , NULL , 0 );
366+ mesh::Packet* rpath = createPathReturn (contact.id , contact.getSharedSecret (self_id), path, path_len, 0 , NULL , 0 , contact. nextAeadNonce () );
351367 if (rpath) sendDirect (rpath, contact.out_path , contact.out_path_len , 3000 ); // 3 second delay
352368}
353369
@@ -396,7 +412,7 @@ mesh::Packet* BaseChatMesh::composeMsgPacket(const ContactInfo& recipient, uint3
396412 temp[len++] = attempt; // hide attempt number at tail end of payload
397413 }
398414
399- return createDatagram (PAYLOAD_TYPE_TXT_MSG , recipient.id , recipient.getSharedSecret (self_id), temp, len);
415+ return createDatagram (PAYLOAD_TYPE_TXT_MSG , recipient.id , recipient.getSharedSecret (self_id), temp, len, recipient. nextAeadNonce () );
400416}
401417
402418int BaseChatMesh::sendMessage (const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char * text, uint32_t & expected_ack, uint32_t & est_timeout) {
@@ -427,7 +443,7 @@ int BaseChatMesh::sendCommandData(const ContactInfo& recipient, uint32_t timest
427443 temp[4 ] = (attempt & 3 ) | (TXT_TYPE_CLI_DATA << 2 );
428444 memcpy (&temp[5 ], text, text_len + 1 );
429445
430- auto pkt = createDatagram (PAYLOAD_TYPE_TXT_MSG , recipient.id , recipient.getSharedSecret (self_id), temp, 5 + text_len);
446+ auto pkt = createDatagram (PAYLOAD_TYPE_TXT_MSG , recipient.id , recipient.getSharedSecret (self_id), temp, 5 + text_len, recipient. nextAeadNonce () );
431447 if (pkt == NULL ) return MSG_SEND_FAILED ;
432448
433449 uint32_t t = _radio->getEstAirtimeFor (pkt->getRawLength ());
@@ -568,7 +584,7 @@ int BaseChatMesh::sendRequest(const ContactInfo& recipient, const uint8_t* req_
568584 memcpy (temp, &tag, 4 ); // mostly an extra blob to help make packet_hash unique
569585 memcpy (&temp[4 ], req_data, data_len);
570586
571- pkt = createDatagram (PAYLOAD_TYPE_REQ , recipient.id , recipient.getSharedSecret (self_id), temp, 4 + data_len);
587+ pkt = createDatagram (PAYLOAD_TYPE_REQ , recipient.id , recipient.getSharedSecret (self_id), temp, 4 + data_len, recipient. nextAeadNonce () );
572588 }
573589 if (pkt) {
574590 uint32_t t = _radio->getEstAirtimeFor (pkt->getRawLength ());
@@ -595,7 +611,7 @@ int BaseChatMesh::sendRequest(const ContactInfo& recipient, uint8_t req_type, u
595611 memset (&temp[5 ], 0 , 4 ); // reserved (possibly for 'since' param)
596612 getRNG ()->random (&temp[9 ], 4 ); // random blob to help make packet-hash unique
597613
598- pkt = createDatagram (PAYLOAD_TYPE_REQ , recipient.id , recipient.getSharedSecret (self_id), temp, sizeof (temp));
614+ pkt = createDatagram (PAYLOAD_TYPE_REQ , recipient.id , recipient.getSharedSecret (self_id), temp, sizeof (temp), recipient. nextAeadNonce () );
599615 }
600616 if (pkt) {
601617 uint32_t t = _radio->getEstAirtimeFor (pkt->getRawLength ());
@@ -718,7 +734,7 @@ void BaseChatMesh::checkConnections() {
718734 // calc expected ACK reply
719735 mesh::Utils::sha256 ((uint8_t *)&connections[i].expected_ack , 4 , data, 9 , self_id.pub_key , PUB_KEY_SIZE );
720736
721- auto pkt = createDatagram (PAYLOAD_TYPE_REQ , contact->id , contact->getSharedSecret (self_id), data, 9 );
737+ auto pkt = createDatagram (PAYLOAD_TYPE_REQ , contact->id , contact->getSharedSecret (self_id), data, 9 , contact-> nextAeadNonce () );
722738 if (pkt) {
723739 sendDirect (pkt, contact->out_path , contact->out_path_len );
724740 }
0 commit comments