* simple_secure_chat: bug fixes
This commit is contained in:
@@ -53,7 +53,6 @@ struct ContactInfo {
|
|||||||
class MyMesh : public mesh::Mesh {
|
class MyMesh : public mesh::Mesh {
|
||||||
public:
|
public:
|
||||||
SimpleSeenTable* _table;
|
SimpleSeenTable* _table;
|
||||||
mesh::LocalIdentity self_id;
|
|
||||||
ContactInfo contacts[MAX_CONTACTS];
|
ContactInfo contacts[MAX_CONTACTS];
|
||||||
int num_contacts;
|
int num_contacts;
|
||||||
|
|
||||||
@@ -128,11 +127,11 @@ protected:
|
|||||||
// len can be > original length, but 'text' will be padded with zeroes
|
// len can be > original length, but 'text' will be padded with zeroes
|
||||||
data[len] = 0; // need to make a C string again, with null terminator
|
data[len] = 0; // need to make a C string again, with null terminator
|
||||||
|
|
||||||
Serial.printf("MSG -> from %s\n", from.name);
|
Serial.printf("(%s) MSG -> from %s\n", packet->isRouteFlood() ? "FLOOD" : "DIRECT", from.name);
|
||||||
Serial.printf(" %s\n", (const char *) &data[4]);
|
Serial.printf(" %s\n", (const char *) &data[4]);
|
||||||
|
|
||||||
uint32_t ack_hash; // calc truncated hash of the message timestamp + text + sender pub_key, to prove to sender that we got it
|
uint32_t ack_hash; // calc truncated hash of the message timestamp + text + sender pub_key, to prove to sender that we got it
|
||||||
mesh::Utils::sha256((uint8_t *) &ack_hash, 4, data, len, from.id.pub_key, PUB_KEY_SIZE);
|
mesh::Utils::sha256((uint8_t *) &ack_hash, 4, data, 4 + strlen((char *)&data[4]), from.id.pub_key, PUB_KEY_SIZE);
|
||||||
|
|
||||||
if (packet->isRouteFlood()) {
|
if (packet->isRouteFlood()) {
|
||||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
|
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
|
||||||
@@ -190,6 +189,10 @@ protected:
|
|||||||
// NOTE: the same ACK can be received multiple times!
|
// NOTE: the same ACK can be received multiple times!
|
||||||
expected_ack_crc = 0; // reset our expected hash, now that we have received ACK
|
expected_ack_crc = 0; // reset our expected hash, now that we have received ACK
|
||||||
txt_send_timeout = 0;
|
txt_send_timeout = 0;
|
||||||
|
} else {
|
||||||
|
uint32_t crc;
|
||||||
|
memcpy(&crc, data, 4);
|
||||||
|
MESH_DEBUG_PRINTLN(" unknown ACK received: %08X (expected: %08X)", crc, expected_ack_crc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,10 +212,10 @@ public:
|
|||||||
uint8_t temp[4+MAX_TEXT_LEN+1];
|
uint8_t temp[4+MAX_TEXT_LEN+1];
|
||||||
uint32_t timestamp = getRTCClock()->getCurrentTime();
|
uint32_t timestamp = getRTCClock()->getCurrentTime();
|
||||||
memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique
|
memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique
|
||||||
memcpy(&temp[4], text, text_len);
|
memcpy(&temp[4], text, text_len + 1);
|
||||||
|
|
||||||
// calc expected ACK reply
|
// calc expected ACK reply
|
||||||
mesh::Utils::sha256((uint8_t *)&expected_ack_crc, 4, (const uint8_t *) temp, 4 + text_len, self_id.pub_key, PUB_KEY_SIZE);
|
mesh::Utils::sha256((uint8_t *)&expected_ack_crc, 4, temp, 4 + text_len, self_id.pub_key, PUB_KEY_SIZE);
|
||||||
|
|
||||||
return createDatagram(PAYLOAD_TYPE_TXT_MSG, recipient.id, recipient.shared_secret, temp, 4 + text_len);
|
return createDatagram(PAYLOAD_TYPE_TXT_MSG, recipient.id, recipient.shared_secret, temp, 4 + text_len);
|
||||||
}
|
}
|
||||||
@@ -303,11 +306,12 @@ void loop() {
|
|||||||
if (recipient.out_path_len < 0) {
|
if (recipient.out_path_len < 0) {
|
||||||
the_mesh.sendFlood(pkt);
|
the_mesh.sendFlood(pkt);
|
||||||
txt_send_timeout = the_mesh.futureMillis(FLOOD_SEND_TIMEOUT_MILLIS);
|
txt_send_timeout = the_mesh.futureMillis(FLOOD_SEND_TIMEOUT_MILLIS);
|
||||||
|
Serial.println(" (message sent - FLOOD)");
|
||||||
} else {
|
} else {
|
||||||
the_mesh.sendDirect(pkt, recipient.out_path, recipient.out_path_len);
|
the_mesh.sendDirect(pkt, recipient.out_path, recipient.out_path_len);
|
||||||
txt_send_timeout = the_mesh.futureMillis(DIRECT_TIMEOUT_FACTOR*recipient.out_path_len + DIRECT_TIMEOUT_BASE);
|
txt_send_timeout = the_mesh.futureMillis(DIRECT_TIMEOUT_FACTOR*recipient.out_path_len + DIRECT_TIMEOUT_BASE);
|
||||||
|
Serial.println(" (message sent - DIRECT)");
|
||||||
}
|
}
|
||||||
Serial.println(" (message sent)");
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println(" ERROR: unable to create packet.");
|
Serial.println(" ERROR: unable to create packet.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ build_flags =
|
|||||||
${Heltec_lora32_v3.build_flags}
|
${Heltec_lora32_v3.build_flags}
|
||||||
-D RUN_AS_ALICE=true
|
-D RUN_AS_ALICE=true
|
||||||
; -D NODE_ID=1
|
; -D NODE_ID=1
|
||||||
|
-D MESH_DEBUG=1
|
||||||
build_src_filter = ${Heltec_lora32_v3.build_src_filter} +<../examples/simple_secure_chat/main.cpp>
|
build_src_filter = ${Heltec_lora32_v3.build_src_filter} +<../examples/simple_secure_chat/main.cpp>
|
||||||
|
|
||||||
[env:Heltec_v3_chat_bob]
|
[env:Heltec_v3_chat_bob]
|
||||||
@@ -81,6 +82,7 @@ build_flags =
|
|||||||
${Heltec_lora32_v3.build_flags}
|
${Heltec_lora32_v3.build_flags}
|
||||||
-D RUN_AS_ALICE=false
|
-D RUN_AS_ALICE=false
|
||||||
; -D NODE_ID=3
|
; -D NODE_ID=3
|
||||||
|
-D MESH_DEBUG=1
|
||||||
build_src_filter = ${Heltec_lora32_v3.build_src_filter} +<../examples/simple_secure_chat/main.cpp>
|
build_src_filter = ${Heltec_lora32_v3.build_src_filter} +<../examples/simple_secure_chat/main.cpp>
|
||||||
|
|
||||||
[env:Heltec_v3_test_admin]
|
[env:Heltec_v3_test_admin]
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
// scan contacts DB, for all matching hashes of 'src_hash' (max 4 matches supported ATM)
|
// scan contacts DB, for all matching hashes of 'src_hash' (max 4 matches supported ATM)
|
||||||
int num = searchPeersByHash(&src_hash);
|
int num = searchPeersByHash(&src_hash);
|
||||||
// for each matching contact, try to decrypt data
|
// for each matching contact, try to decrypt data
|
||||||
|
bool found = false;
|
||||||
for (int j = 0; j < num; j++) {
|
for (int j = 0; j < num; j++) {
|
||||||
uint8_t secret[PUB_KEY_SIZE];
|
uint8_t secret[PUB_KEY_SIZE];
|
||||||
getPeerSharedSecret(secret, j);
|
getPeerSharedSecret(secret, j);
|
||||||
@@ -89,9 +90,13 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
|||||||
} else {
|
} else {
|
||||||
onPeerDataRecv(pkt, pkt->getPayloadType(), j, data, len);
|
onPeerDataRecv(pkt, pkt->getPayloadType(), j, data, len);
|
||||||
}
|
}
|
||||||
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!found) {
|
||||||
|
MESH_DEBUG_PRINTLN("recv matches no peers, src_hash=%02X", (uint32_t)src_hash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
action = routeRecvPacket(pkt);
|
action = routeRecvPacket(pkt);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user