@@ -223,6 +223,10 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
223223 }
224224 } else if (type == PAYLOAD_TYPE_RESPONSE && len > 0 ) {
225225 onContactResponse (from, data, len);
226+ if (packet->isRouteFlood () && from.out_path_len >= 0 ) {
227+ // we have direct path, but other node is still sending flood response, so maybe they didn't receive reciprocal path properly(?)
228+ handleReturnPathRetry (from, packet->path , packet->path_len );
229+ }
226230 }
227231}
228232
@@ -248,7 +252,7 @@ bool BaseChatMesh::onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_
248252
249253 if (extra_type == PAYLOAD_TYPE_ACK && extra_len >= 4 ) {
250254 // also got an encoded ACK!
251- if (processAck (extra)) {
255+ if (processAck (extra) != NULL ) {
252256 txt_send_timeout = 0 ; // matched one we're waiting for, cancel timeout timer
253257 }
254258 } else if (extra_type == PAYLOAD_TYPE_RESPONSE && extra_len > 0 ) {
@@ -258,12 +262,25 @@ bool BaseChatMesh::onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_
258262}
259263
260264void BaseChatMesh::onAckRecv (mesh::Packet* packet, uint32_t ack_crc) {
261- if (processAck ((uint8_t *)&ack_crc)) {
265+ ContactInfo* from;
266+ if ((from = processAck ((uint8_t *)&ack_crc)) != NULL ) {
262267 txt_send_timeout = 0 ; // matched one we're waiting for, cancel timeout timer
263268 packet->markDoNotRetransmit (); // ACK was for this node, so don't retransmit
269+
270+ if (packet->isRouteFlood () && from->out_path_len >= 0 ) {
271+ // we have direct path, but other node is still sending flood, so maybe they didn't receive reciprocal path properly(?)
272+ handleReturnPathRetry (*from, packet->path , packet->path_len );
273+ }
264274 }
265275}
266276
277+ void BaseChatMesh::handleReturnPathRetry (const ContactInfo& contact, const uint8_t * path, uint8_t path_len) {
278+ // NOTE: simplest impl is just to re-send a reciprocal return path to sender (DIRECTLY)
279+ // override this method in various firmwares, if there's a better strategy
280+ mesh::Packet* rpath = createPathReturn (contact.id , contact.shared_secret , path, path_len, 0 , NULL , 0 );
281+ if (rpath) sendDirect (rpath, contact.out_path , contact.out_path_len , 3000 ); // 3 second delay
282+ }
283+
267284#ifdef MAX_GROUP_CHANNELS
268285int BaseChatMesh::searchChannelsByHash (const uint8_t * hash, mesh::GroupChannel dest[], int max_matches) {
269286 int n = 0 ;
@@ -550,7 +567,7 @@ void BaseChatMesh::markConnectionActive(const ContactInfo& contact) {
550567 }
551568}
552569
553- bool BaseChatMesh::checkConnectionsAck (const uint8_t * data) {
570+ ContactInfo* BaseChatMesh::checkConnectionsAck (const uint8_t * data) {
554571 for (int i = 0 ; i < MAX_CONNECTIONS; i++) {
555572 if (connections[i].keep_alive_millis > 0 && memcmp (&connections[i].expected_ack , data, 4 ) == 0 ) {
556573 // yes, got an ack for our keep_alive request!
@@ -559,10 +576,12 @@ bool BaseChatMesh::checkConnectionsAck(const uint8_t* data) {
559576
560577 // re-schedule next KEEP_ALIVE, now that we have heard from server
561578 connections[i].next_ping = futureMillis (connections[i].keep_alive_millis );
562- return true ; // yes, a match
579+
580+ auto id = &connections[i].server_id ;
581+ return lookupContactByPubKey (id->pub_key , PUB_KEY_SIZE); // yes, a match
563582 }
564583 }
565- return false ; // / no match
584+ return NULL ; // / no match
566585}
567586
568587void BaseChatMesh::checkConnections () {
0 commit comments