Skip to content

Commit 085c20c

Browse files
committed
im confused
Signed-off-by: faradaym <rcheyenne.truss@gmail.com>
1 parent 015d182 commit 085c20c

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

src/Ducks/DuckLink.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,19 @@ class DuckLink : public Duck<WifiCapability, RadioType> {
9292
this->sendRouteResponse(lastInPath, rreqDoc.asString());
9393
this->router.insertIntoRoutingTable(rxPacket.sduid, lastInPath, this->getSignalScore());
9494
}
95+
Serial.println(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ this is really weird");
9596
}
9697
break;
9798
case reservedTopic::rrep: {
9899
//we still need to recieve rreps in case of ttl expiry
99100
RouteJSON rrepDoc = RouteJSON(rxPacket.data);
100-
loginfo_ln("Received Route Response from DUID: %s", rxPacket.sduid.data());
101+
loginfo_ln("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Received Route Response from DUID: %s", rxPacket.sduid.data());
101102
//destination = sender of the rrep -> the last hop to current duck
102103
std::optional<Duid> last = rrepDoc.getlastInPath();
103-
std::string packetString(rxPacket.data.begin(), rxPacket.data.end());
104104
Duid lastInPath = last.value();
105-
this->router.insertIntoRoutingTable(rrepDoc.getOriginOfRrep(), lastInPath, this->getSignalScore());
105+
106+
rrepDoc.convertReqToRep();
107+
this->router.insertIntoRoutingTable(rrepDoc.getOrigin(), lastInPath, this->getSignalScore());
106108
}
107109
break;
108110
default:

src/Ducks/MamaDuck.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ private :
115115
//addToPath
116116
if(!relay) {
117117
loginfo_ln("handleReceivedPacket: Sending RREP");
118+
rreqDoc.convertReqToRep();
118119
rxPacket.data = duckutils::stringToByteVector(rreqDoc.addToPath(this->duid));
119120
this->sendRouteResponse(lastInPath, rreqDoc.asString());
120121
} else {
@@ -136,15 +137,16 @@ private :
136137
RouteJSON rrepDoc = RouteJSON(rxPacket.data);
137138
std::optional<Duid> last = rrepDoc.getlastInPath();
138139
Duid lastInPath = last.has_value() ? last.value() : rxPacket.sduid;
139-
if(relay){
140+
if(rrepDoc.getDestination() != this->duid){
140141
loginfo_ln("Received Route Response from DUID: %s", rxPacket.sduid.data(), rxPacket.sduid.size());
141142

142143
rrepDoc.removeFromPath(this->duid);
143144
//route responses need a way to keep tray of who relayed the packet, but a response needs to be directed and not broadly relayed
144145
this->sendRouteResponse(lastInPath, rrepDoc.asString()); //so here the relaying duck is known from sduid
145146
}
147+
Serial.println(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rrep already seen");
146148
//destination = sender of the rrep -> the last hop to current duck
147-
this->router.insertIntoRoutingTable(rrepDoc.getOriginOfRrep(), last.value(), this->getSignalScore());
149+
this->router.insertIntoRoutingTable(rrepDoc.getOrigin(), lastInPath, this->getSignalScore());
148150
}
149151
break;
150152
case reservedTopic::ping:
@@ -170,6 +172,7 @@ private :
170172
break;
171173
default:
172174
if(relay){
175+
Serial.println(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ default behavior");
173176
this->forwardPacket(rxPacket);
174177
}
175178
}

src/Ducks/PapaDuck.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ void ifNotBroadcast(CdpPacket rxPacket, int err, bool relay = false) {
108108
switch(rxPacket.topic) {
109109
case reservedTopic::rreq: {
110110
RouteJSON rreqDoc = RouteJSON(rxPacket.data);
111+
112+
//route requests are just forwarded so we can use the sduid as the origin
113+
std::optional<Duid> last = rreqDoc.getlastInPath();
114+
Duid lastInPath = last.has_value() ? last.value() : rxPacket.sduid;
111115
if(!relay) {
112116
loginfo_ln("handleReceivedPacket: Sending RREP");
113-
this->sendRouteResponse(rreqDoc.getlastInPath(), rreqDoc.asString());
117+
rreqDoc.convertReqToRep();
118+
rxPacket.data = duckutils::stringToByteVector(rreqDoc.addToPath(this->duid));
119+
this->sendRouteResponse(lastInPath, rreqDoc.asString());
114120
} else {
115121
loginfo_ln("RREQ received for relay. Relaying!");
116122
rxPacket.data = duckutils::stringToByteVector(rreqDoc.addToPath(this->duid)); //why is this different from stringToArray
@@ -130,15 +136,15 @@ void ifNotBroadcast(CdpPacket rxPacket, int err, bool relay = false) {
130136
RouteJSON rrepDoc = RouteJSON(rxPacket.data);
131137
std::optional<Duid> last = rrepDoc.getlastInPath();
132138
Duid lastInPath = last.has_value() ? last.value() : rxPacket.sduid;
133-
if(relay){
139+
if(rrepDoc.getDestination() != this->duid){
134140
loginfo_ln("Received Route Response from DUID: %s", rxPacket.sduid.data(), rxPacket.sduid.size());
135141

136142
rrepDoc.removeFromPath(this->duid);
137143
//route responses need a way to keep track of who relayed the packet, but a response needs to be directed and not broadly relayed
138144
this->sendRouteResponse(lastInPath, rrepDoc.asString()); //so here the relaying duck is known from sduid
139145
}
140146
//destination = sender of the rrep -> the last hop to current duck
141-
this->router.insertIntoRoutingTable(rrepDoc.getOriginOfRrep(), last.value(), this->getSignalScore());
147+
this->router.insertIntoRoutingTable(rrepDoc.getOrigin(), lastInPath, this->getSignalScore());
142148
}
143149
break;
144150
case reservedTopic::ping:

src/radio/DuckLoRa.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "DuckLoRa.h"
2-
#include <random>
32
#ifdef CDPCFG_RADIO_SX1262
43
#define DUCK_RADIO_IRQ_TIMEOUT RADIOLIB_SX126X_IRQ_TIMEOUT
54
#define DUCK_RADIO_IRQ_TX_DONE RADIOLIB_SX126X_IRQ_TX_DONE

src/routing/RouteJSON.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,28 @@ class RouteJSON {
5555
return json.as<std::string>();
5656
}
5757

58-
Duid getOriginOfRrep(){
58+
void convertReqToRep(){
5959
std::string oldOrigin = origin;
60-
Duid newOriginDuid;
61-
std::copy(destination.begin(), destination.end(), newOriginDuid.begin());
6260
//update rreq to rrep
6361
origin = destination;
6462
destination = oldOrigin;
6563

6664
std::string log;
6765
serializeJson(json, log);
68-
loginfo_ln("RREP Doc Updated: %s", log.c_str());
69-
70-
return newOriginDuid;
66+
loginfo_ln(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ RREP Doc Updated: %s", log.c_str());
67+
logdbg_ln("LOG OF JSON !!!!!1: %s",json.as<std::string>().c_str());
68+
Serial.println("===================================================================================================");
69+
}
70+
Duid getOrigin(){
71+
Duid originDuid;
72+
std::copy(origin.begin(), origin.end(), originDuid.begin());
73+
return originDuid;
74+
}
75+
Duid getDestination(){
76+
Duid destinationDuid;
77+
std::copy(destination.begin(), destination.end(), destinationDuid.begin());
78+
return destinationDuid;
7179
}
72-
// Duid getDestination(){
73-
// Duid destinationDuid;
74-
// std::copy(destination.begin(), destination.end(), destinationDuid.begin());
75-
// return destinationDuid;
76-
// }
7780

7881
/**
7982
* @brief add a duck node to the path to route the request path

0 commit comments

Comments
 (0)