mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* Companion: Now using transport codes { 0, 0 } when Share contact zero hop.
* Repeater: onAdvertRecv(), adverts via Share now NOT added to neighbours table
This commit is contained in:
parent
ef752926c9
commit
7755400a35
4 changed files with 40 additions and 5 deletions
|
|
@ -448,12 +448,19 @@ void MyMesh::getPeerSharedSecret(uint8_t *dest_secret, int peer_idx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isShare(const mesh::Packet *packet) {
|
||||||
|
if (packet->hasTransportCodes()) {
|
||||||
|
return packet->transport_codes[0] == 0 && packet->transport_codes[1] == 0; // codes { 0, 0 } means 'send to nowhere'
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void MyMesh::onAdvertRecv(mesh::Packet *packet, const mesh::Identity &id, uint32_t timestamp,
|
void MyMesh::onAdvertRecv(mesh::Packet *packet, const mesh::Identity &id, uint32_t timestamp,
|
||||||
const uint8_t *app_data, size_t app_data_len) {
|
const uint8_t *app_data, size_t app_data_len) {
|
||||||
mesh::Mesh::onAdvertRecv(packet, id, timestamp, app_data, app_data_len); // chain to super impl
|
mesh::Mesh::onAdvertRecv(packet, id, timestamp, app_data, app_data_len); // chain to super impl
|
||||||
|
|
||||||
// if this a zero hop advert, add it to neighbours
|
// if this a zero hop advert (and not via 'Share'), add it to neighbours
|
||||||
if (packet->path_len == 0) {
|
if (packet->path_len == 0 && !isShare(packet)) {
|
||||||
AdvertDataParser parser(app_data, app_data_len);
|
AdvertDataParser parser(app_data, app_data_len);
|
||||||
if (parser.isValid() && parser.getType() == ADV_TYPE_REPEATER) { // just keep neigbouring Repeaters
|
if (parser.isValid() && parser.getType() == ADV_TYPE_REPEATER) { // just keep neigbouring Repeaters
|
||||||
putNeighbour(id, timestamp, packet->getSNR());
|
putNeighbour(id, timestamp, packet->getSNR());
|
||||||
|
|
|
||||||
13
src/Mesh.cpp
13
src/Mesh.cpp
|
|
@ -645,4 +645,17 @@ void Mesh::sendZeroHop(Packet* packet, uint32_t delay_millis) {
|
||||||
sendPacket(packet, 0, delay_millis);
|
sendPacket(packet, 0, delay_millis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mesh::sendZeroHop(Packet* packet, uint16_t* transport_codes, uint32_t delay_millis) {
|
||||||
|
packet->header &= ~PH_ROUTE_MASK;
|
||||||
|
packet->header |= ROUTE_TYPE_TRANSPORT_DIRECT;
|
||||||
|
packet->transport_codes[0] = transport_codes[0];
|
||||||
|
packet->transport_codes[1] = transport_codes[1];
|
||||||
|
|
||||||
|
packet->path_len = 0; // path_len of zero means Zero Hop
|
||||||
|
|
||||||
|
_tables->hasSeen(packet); // mark this packet as already sent in case it is rebroadcast back to us
|
||||||
|
|
||||||
|
sendPacket(packet, 0, delay_millis);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -196,6 +196,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void sendZeroHop(Packet* packet, uint32_t delay_millis=0);
|
void sendZeroHop(Packet* packet, uint32_t delay_millis=0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief send a locally-generated Packet to just neigbor nodes (zero hops), with specific transort codes
|
||||||
|
* \param transport_codes array of 2 codes to attach to packet
|
||||||
|
*/
|
||||||
|
void sendZeroHop(Packet* packet, uint16_t* transport_codes, uint32_t delay_millis=0);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,16 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
|
||||||
}
|
}
|
||||||
|
|
||||||
// save a copy of raw advert packet (to support "Share..." function)
|
// save a copy of raw advert packet (to support "Share..." function)
|
||||||
int plen = packet->writeTo(temp_buf);
|
int plen;
|
||||||
|
{
|
||||||
|
uint8_t save = packet->header;
|
||||||
|
packet->header &= ~PH_ROUTE_MASK;
|
||||||
|
packet->header |= ROUTE_TYPE_FLOOD; // make sure transport codes are NOT saved
|
||||||
|
plen = packet->writeTo(temp_buf);
|
||||||
|
packet->header = save;
|
||||||
|
}
|
||||||
putBlobByKey(id.pub_key, PUB_KEY_SIZE, temp_buf, plen);
|
putBlobByKey(id.pub_key, PUB_KEY_SIZE, temp_buf, plen);
|
||||||
|
|
||||||
bool is_new = false;
|
bool is_new = false;
|
||||||
if (from == NULL) {
|
if (from == NULL) {
|
||||||
if (!isAutoAddEnabled()) {
|
if (!isAutoAddEnabled()) {
|
||||||
|
|
@ -405,7 +412,9 @@ bool BaseChatMesh::shareContactZeroHop(const ContactInfo& contact) {
|
||||||
if (packet == NULL) return false; // no Packets available
|
if (packet == NULL) return false; // no Packets available
|
||||||
|
|
||||||
packet->readFrom(temp_buf, plen); // restore Packet from 'blob'
|
packet->readFrom(temp_buf, plen); // restore Packet from 'blob'
|
||||||
sendZeroHop(packet);
|
uint16_t codes[2];
|
||||||
|
codes[0] = codes[1] = 0; // { 0, 0 } means 'send this nowhere'
|
||||||
|
sendZeroHop(packet, codes);
|
||||||
return true; // success
|
return true; // success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue