mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* onPeerPathRecv() refactored: 'reciprocal path' now handled in Mesh class, not in application layer
This commit is contained in:
parent
de27dfacb6
commit
96724cd26a
8 changed files with 30 additions and 28 deletions
|
|
@ -81,21 +81,16 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
void onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
// must be from server_id
|
||||
Serial.printf("PATH to server, path_len=%d\n", (uint32_t) path_len);
|
||||
|
||||
memcpy(server_path, path, server_path_len = path_len); // store a copy of path, for sendDirect()
|
||||
|
||||
if (packet->isRouteFlood()) {
|
||||
// send a reciprocal return path to sender, but send DIRECTLY!
|
||||
mesh::Packet* rpath = createPathReturn(server_id, secret, packet->path, packet->path_len, 0, NULL, 0);
|
||||
if (rpath) sendDirect(rpath, path, path_len);
|
||||
}
|
||||
|
||||
if (extra_type == PAYLOAD_TYPE_RESPONSE) {
|
||||
if (extra_type == PAYLOAD_TYPE_RESPONSE && extra_len > 0) {
|
||||
Serial.println("Received PING Reply!");
|
||||
}
|
||||
return true; // send reciprocal path if necessary
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
void onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
if (sender_idx >= 0 && sender_idx < MAX_CLIENTS) {
|
||||
Serial.printf("PATH to client, path_len=%d\n", (uint32_t) path_len);
|
||||
|
||||
|
|
@ -134,6 +134,7 @@ protected:
|
|||
}
|
||||
|
||||
// NOTE: no reciprocal path send!!
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
void onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
// TODO: prevent replay attacks
|
||||
int i = matching_peer_indexes[sender_idx];
|
||||
|
||||
|
|
@ -312,6 +312,7 @@ protected:
|
|||
}
|
||||
|
||||
// NOTE: no reciprocal path send!!
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -191,11 +191,11 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
void onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
int i = matching_peer_indexes[sender_idx];
|
||||
if (i < 0 || i >= num_contacts) {
|
||||
MESH_DEBUG_PRINTLN("onPeerPathRecv: Invalid sender idx: %d", i);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
ContactInfo& from = contacts[i];
|
||||
|
|
@ -205,16 +205,11 @@ protected:
|
|||
// FUTURE: could store multiple out_paths per contact, and try to find which is the 'best'(?)
|
||||
memcpy(from.out_path, path, from.out_path_len = path_len); // store a copy of path, for sendDirect()
|
||||
|
||||
if (packet->isRouteFlood()) {
|
||||
// send a reciprocal return path to sender, but send DIRECTLY!
|
||||
mesh::Packet* rpath = createPathReturn(from.id, secret, packet->path, packet->path_len, 0, NULL, 0);
|
||||
if (rpath) sendDirect(rpath, path, path_len);
|
||||
}
|
||||
|
||||
if (extra_type == PAYLOAD_TYPE_ACK && extra_len >= 4) {
|
||||
// also got an encoded ACK!
|
||||
processAck(extra);
|
||||
}
|
||||
return true; // send reciprocal path if necessary
|
||||
}
|
||||
|
||||
void onAckRecv(mesh::Packet* packet, uint32_t ack_crc) override {
|
||||
|
|
|
|||
|
|
@ -135,21 +135,16 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
void onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override {
|
||||
// must be from server_id
|
||||
Serial.printf("PATH to repeater, path_len=%d\n", (uint32_t) path_len);
|
||||
|
||||
memcpy(server_path, path, server_path_len = path_len); // store a copy of path, for sendDirect()
|
||||
|
||||
if (packet->isRouteFlood()) {
|
||||
// send a reciprocal return path to sender, but send DIRECTLY!
|
||||
mesh::Packet* rpath = createPathReturn(server_id, secret, packet->path, packet->path_len, 0, NULL, 0);
|
||||
if (rpath) sendDirect(rpath, path, path_len);
|
||||
}
|
||||
|
||||
if (extra_type == PAYLOAD_TYPE_RESPONSE) {
|
||||
handleResponse(extra, extra_len);
|
||||
}
|
||||
return true; // send reciprocal path if necessary
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue