@@ -129,7 +129,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
129129 }
130130
131131 if (is_flood) {
132- client->out_path_len = - 1 ; // need to rediscover out_path
132+ client->out_path_len = OUT_PATH_UNKNOWN ; // need to rediscover out_path
133133 }
134134
135135 uint32_t now = getRTCClock ()->getCurrentTimeUnique ();
@@ -147,9 +147,12 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
147147uint8_t MyMesh::handleAnonRegionsReq (const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t * data) {
148148 if (anon_limiter.allow (rtc_clock.getCurrentTime ())) {
149149 // request data has: {reply-path-len}{reply-path}
150- reply_path_len = *data++ & 0x3F ;
151- memcpy (reply_path, data, reply_path_len);
152- // data += reply_path_len;
150+ reply_path_len = *data & 63 ;
151+ reply_path_hash_size = (*data >> 6 ) + 1 ;
152+ data++;
153+
154+ memcpy (reply_path, data, ((uint8_t )reply_path_len) * reply_path_hash_size);
155+ // data += (uint8_t)reply_path_len * reply_path_hash_size;
153156
154157 memcpy (reply_data, &sender_timestamp, 4 ); // prefix with sender_timestamp, like a tag
155158 uint32_t now = getRTCClock ()->getCurrentTime ();
@@ -163,9 +166,12 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send
163166uint8_t MyMesh::handleAnonOwnerReq (const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t * data) {
164167 if (anon_limiter.allow (rtc_clock.getCurrentTime ())) {
165168 // request data has: {reply-path-len}{reply-path}
166- reply_path_len = *data++ & 0x3F ;
167- memcpy (reply_path, data, reply_path_len);
168- // data += reply_path_len;
169+ reply_path_len = *data & 63 ;
170+ reply_path_hash_size = (*data >> 6 ) + 1 ;
171+ data++;
172+
173+ memcpy (reply_path, data, ((uint8_t )reply_path_len) * reply_path_hash_size);
174+ // data += (uint8_t)reply_path_len * reply_path_hash_size;
169175
170176 memcpy (reply_data, &sender_timestamp, 4 ); // prefix with sender_timestamp, like a tag
171177 uint32_t now = getRTCClock ()->getCurrentTime ();
@@ -180,9 +186,12 @@ uint8_t MyMesh::handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender
180186uint8_t MyMesh::handleAnonClockReq (const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t * data) {
181187 if (anon_limiter.allow (rtc_clock.getCurrentTime ())) {
182188 // request data has: {reply-path-len}{reply-path}
183- reply_path_len = *data++ & 0x3F ;
184- memcpy (reply_path, data, reply_path_len);
185- // data += reply_path_len;
189+ reply_path_len = *data & 63 ;
190+ reply_path_hash_size = (*data >> 6 ) + 1 ;
191+ data++;
192+
193+ memcpy (reply_path, data, ((uint8_t )reply_path_len) * reply_path_hash_size);
194+ // data += (uint8_t)reply_path_len * reply_path_hash_size;
186195
187196 memcpy (reply_data, &sender_timestamp, 4 ); // prefix with sender_timestamp, like a tag
188197 uint32_t now = getRTCClock ()->getCurrentTime ();
@@ -389,7 +398,7 @@ File MyMesh::openAppend(const char *fname) {
389398
390399bool MyMesh::allowPacketForward (const mesh::Packet *packet) {
391400 if (_prefs.disable_fwd ) return false ;
392- if (packet->isRouteFlood () && packet->path_len >= _prefs.flood_max ) return false ;
401+ if (packet->isRouteFlood () && packet->getPathHashCount () >= _prefs.flood_max ) return false ;
393402 if (packet->isRouteFlood () && recv_pkt_region == NULL ) {
394403 MESH_DEBUG_PRINTLN (" allowPacketForward: unknown transport code, or wildcard not allowed for FLOOD packet" );
395404 return false ;
@@ -484,11 +493,11 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
484493}
485494
486495uint32_t MyMesh::getRetransmitDelay (const mesh::Packet *packet) {
487- uint32_t t = (_radio->getEstAirtimeFor (packet->path_len + packet->payload_len + 2 ) * _prefs.tx_delay_factor );
496+ uint32_t t = (_radio->getEstAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 ) * _prefs.tx_delay_factor );
488497 return getRNG ()->nextInt (0 , 5 *t + 1 );
489498}
490499uint32_t MyMesh::getDirectRetransmitDelay (const mesh::Packet *packet) {
491- uint32_t t = (_radio->getEstAirtimeFor (packet->path_len + packet->payload_len + 2 ) * _prefs.direct_tx_delay_factor );
500+ uint32_t t = (_radio->getEstAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 ) * _prefs.direct_tx_delay_factor );
492501 return getRNG ()->nextInt (0 , 5 *t + 1 );
493502}
494503
@@ -538,13 +547,14 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
538547 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
539548 mesh::Packet* path = createPathReturn (sender, secret, packet->path , packet->path_len ,
540549 PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
541- if (path) sendFlood (path, SERVER_RESPONSE_DELAY);
550+ if (path) sendFlood (path, SERVER_RESPONSE_DELAY, packet-> getPathHashSize () );
542551 } else if (reply_path_len < 0 ) {
543552 mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
544- if (reply) sendFlood (reply, SERVER_RESPONSE_DELAY);
553+ if (reply) sendFlood (reply, SERVER_RESPONSE_DELAY, packet-> getPathHashSize () );
545554 } else {
546555 mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
547- if (reply) sendDirect (reply, reply_path, reply_path_len, SERVER_RESPONSE_DELAY);
556+ uint8_t path_len = ((reply_path_hash_size - 1 ) << 6 ) | (reply_path_len & 63 );
557+ if (reply) sendDirect (reply, reply_path, path_len, SERVER_RESPONSE_DELAY);
548558 }
549559 }
550560}
@@ -613,15 +623,15 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
613623 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
614624 mesh::Packet *path = createPathReturn (client->id , secret, packet->path , packet->path_len ,
615625 PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
616- if (path) sendFlood (path, SERVER_RESPONSE_DELAY);
626+ if (path) sendFlood (path, SERVER_RESPONSE_DELAY, packet-> getPathHashSize () );
617627 } else {
618628 mesh::Packet *reply =
619629 createDatagram (PAYLOAD_TYPE_RESPONSE, client->id , secret, reply_data, reply_len);
620630 if (reply) {
621- if (client->out_path_len >= 0 ) { // we have an out_path, so send DIRECT
631+ if (client->out_path_len != OUT_PATH_UNKNOWN ) { // we have an out_path, so send DIRECT
622632 sendDirect (reply, client->out_path , client->out_path_len , SERVER_RESPONSE_DELAY);
623633 } else {
624- sendFlood (reply, SERVER_RESPONSE_DELAY);
634+ sendFlood (reply, SERVER_RESPONSE_DELAY, packet-> getPathHashSize () );
625635 }
626636 }
627637 }
@@ -651,8 +661,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
651661
652662 mesh::Packet *ack = createAck (ack_hash);
653663 if (ack) {
654- if (client->out_path_len < 0 ) {
655- sendFlood (ack, TXT_ACK_DELAY);
664+ if (client->out_path_len == OUT_PATH_UNKNOWN ) {
665+ sendFlood (ack, TXT_ACK_DELAY, packet-> getPathHashSize () );
656666 } else {
657667 sendDirect (ack, client->out_path , client->out_path_len , TXT_ACK_DELAY);
658668 }
@@ -679,8 +689,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
679689
680690 auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG, client->id , secret, temp, 5 + text_len);
681691 if (reply) {
682- if (client->out_path_len < 0 ) {
683- sendFlood (reply, CLI_REPLY_DELAY_MILLIS);
692+ if (client->out_path_len == OUT_PATH_UNKNOWN ) {
693+ sendFlood (reply, CLI_REPLY_DELAY_MILLIS, packet-> getPathHashSize () );
684694 } else {
685695 sendDirect (reply, client->out_path , client->out_path_len , CLI_REPLY_DELAY_MILLIS);
686696 }
@@ -701,7 +711,8 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t
701711 MESH_DEBUG_PRINTLN (" PATH to client, path_len=%d" , (uint32_t )path_len);
702712 auto client = acl.getClientByIdx (i);
703713
704- memcpy (client->out_path , path, client->out_path_len = path_len); // store a copy of path, for sendDirect()
714+ // store a copy of path, for sendDirect()
715+ client->out_path_len = mesh::Packet::copyPath (client->out_path , path, path_len);
705716 client->last_activity = getRTCClock ()->getCurrentTime ();
706717 } else {
707718 MESH_DEBUG_PRINTLN (" onPeerPathRecv: invalid peer idx: %d" , i);
@@ -906,7 +917,7 @@ void MyMesh::sendSelfAdvertisement(int delay_millis, bool flood) {
906917 mesh::Packet *pkt = createSelfAdvert ();
907918 if (pkt) {
908919 if (flood) {
909- sendFlood (pkt, delay_millis);
920+ sendFlood (pkt, delay_millis, _prefs. path_hash_mode + 1 );
910921 } else {
911922 sendZeroHop (pkt, delay_millis);
912923 }
0 commit comments