@@ -158,6 +158,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
158158 data[len] = 0 ; // need to make a C string again, with null terminator
159159
160160 if (flags == TXT_TYPE_PLAIN) {
161+ from.lastmod = getRTCClock ()->getCurrentTime (); // update last heard time
161162 onMessageRecv (from, packet, timestamp, (const char *) &data[5 ]); // let UI know
162163
163164 uint32_t ack_hash; // calc truncated hash of the message timestamp + text + sender pub_key, to prove to sender that we got it
@@ -184,6 +185,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
184185 if (timestamp > from.sync_since ) { // make sure 'sync_since' is up-to-date
185186 from.sync_since = timestamp;
186187 }
188+ from.lastmod = getRTCClock ()->getCurrentTime (); // update last heard time
187189 onSignedMessageRecv (from, packet, timestamp, &data[5 ], (const char *) &data[9 ]); // let UI know
188190
189191 uint32_t ack_hash; // calc truncated hash of the message timestamp + text + OUR pub_key, to prove to sender that we got it
@@ -223,6 +225,10 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
223225 }
224226 } else if (type == PAYLOAD_TYPE_RESPONSE && len > 0 ) {
225227 onContactResponse (from, data, len);
228+ if (packet->isRouteFlood () && from.out_path_len >= 0 ) {
229+ // we have direct path, but other node is still sending flood response, so maybe they didn't receive reciprocal path properly(?)
230+ handleReturnPathRetry (from, packet->path , packet->path_len );
231+ }
226232 }
227233}
228234
@@ -248,7 +254,7 @@ bool BaseChatMesh::onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_
248254
249255 if (extra_type == PAYLOAD_TYPE_ACK && extra_len >= 4 ) {
250256 // also got an encoded ACK!
251- if (processAck (extra)) {
257+ if (processAck (extra) != NULL ) {
252258 txt_send_timeout = 0 ; // matched one we're waiting for, cancel timeout timer
253259 }
254260 } else if (extra_type == PAYLOAD_TYPE_RESPONSE && extra_len > 0 ) {
@@ -258,12 +264,25 @@ bool BaseChatMesh::onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_
258264}
259265
260266void BaseChatMesh::onAckRecv (mesh::Packet* packet, uint32_t ack_crc) {
261- if (processAck ((uint8_t *)&ack_crc)) {
267+ ContactInfo* from;
268+ if ((from = processAck ((uint8_t *)&ack_crc)) != NULL ) {
262269 txt_send_timeout = 0 ; // matched one we're waiting for, cancel timeout timer
263270 packet->markDoNotRetransmit (); // ACK was for this node, so don't retransmit
271+
272+ if (packet->isRouteFlood () && from->out_path_len >= 0 ) {
273+ // we have direct path, but other node is still sending flood, so maybe they didn't receive reciprocal path properly(?)
274+ handleReturnPathRetry (*from, packet->path , packet->path_len );
275+ }
264276 }
265277}
266278
279+ void BaseChatMesh::handleReturnPathRetry (const ContactInfo& contact, const uint8_t * path, uint8_t path_len) {
280+ // NOTE: simplest impl is just to re-send a reciprocal return path to sender (DIRECTLY)
281+ // override this method in various firmwares, if there's a better strategy
282+ mesh::Packet* rpath = createPathReturn (contact.id , contact.shared_secret , path, path_len, 0 , NULL , 0 );
283+ if (rpath) sendDirect (rpath, contact.out_path , contact.out_path_len , 3000 ); // 3 second delay
284+ }
285+
267286#ifdef MAX_GROUP_CHANNELS
268287int BaseChatMesh::searchChannelsByHash (const uint8_t * hash, mesh::GroupChannel dest[], int max_matches) {
269288 int n = 0 ;
@@ -550,7 +569,7 @@ void BaseChatMesh::markConnectionActive(const ContactInfo& contact) {
550569 }
551570}
552571
553- bool BaseChatMesh::checkConnectionsAck (const uint8_t * data) {
572+ ContactInfo* BaseChatMesh::checkConnectionsAck (const uint8_t * data) {
554573 for (int i = 0 ; i < MAX_CONNECTIONS; i++) {
555574 if (connections[i].keep_alive_millis > 0 && memcmp (&connections[i].expected_ack , data, 4 ) == 0 ) {
556575 // yes, got an ack for our keep_alive request!
@@ -559,10 +578,12 @@ bool BaseChatMesh::checkConnectionsAck(const uint8_t* data) {
559578
560579 // re-schedule next KEEP_ALIVE, now that we have heard from server
561580 connections[i].next_ping = futureMillis (connections[i].keep_alive_millis );
562- return true ; // yes, a match
581+
582+ auto id = &connections[i].server_id ;
583+ return lookupContactByPubKey (id->pub_key , PUB_KEY_SIZE); // yes, a match
563584 }
564585 }
565- return false ; // / no match
586+ return NULL ; // / no match
566587}
567588
568589void BaseChatMesh::checkConnections () {
0 commit comments