Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/modules/NeighborInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ void NeighborInfoModule::cleanUpNeighbors()
}

/* Send neighbor info to the mesh */
void NeighborInfoModule::sendNeighborInfo(NodeNum dest, bool wantReplies)
void NeighborInfoModule::sendNeighborInfo(NodeNum dest, bool wantReplies, bool sendEmpty)
{
meshtastic_NeighborInfo neighborInfo = meshtastic_NeighborInfo_init_zero;
collectNeighborInfo(&neighborInfo);
// only send neighbours if we have some to send
if (neighborInfo.neighbors_count > 0) {
if (neighborInfo.neighbors_count > 0 or sendEmpty) {
meshtastic_MeshPacket *p = allocDataProtobuf(neighborInfo);
p->to = dest;
p->decoded.want_response = wantReplies;
Expand Down Expand Up @@ -138,13 +138,19 @@ Pass it to an upper client; do not persist this data on the mesh
*/
bool NeighborInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_NeighborInfo *np)
{
LOG_DEBUG("NeighborInfo: handleRecievedProtobuf");
if (np) {
printNeighborInfo("RECEIVED", np);
updateNeighbors(mp, np);
} else if (mp.hop_start != 0 && mp.hop_start == mp.hop_limit) {
// If the hopLimit is the same as hopStart, then it is a neighbor
getOrCreateNeighbor(mp.from, mp.from, 0, mp.rx_snr); // Set the broadcast interval to 0, as we don't know it
}
if (mp.decoded.want_response && np->neighbors_count == 0) { // want response, and is otherwise empty.
LOG_INFO("NeighborInfoRequested.");
sendNeighborInfo(mp.from, false, true); // do we want this to be dm, or broadcast?
// sendNeighborInfo(NODENUM_BROADCAST, false); // do we want this to be dm, or broadcast?
}
// Allow others to handle this packet
return false;
}
Expand All @@ -168,6 +174,7 @@ void NeighborInfoModule::resetNeighbors()

void NeighborInfoModule::updateNeighbors(const meshtastic_MeshPacket &mp, const meshtastic_NeighborInfo *np)
{
LOG_DEBUG("updateNeighbors");
// The last sent ID will be 0 if the packet is from the phone, which we don't count as
// an edge. So we assume that if it's zero, then this packet is from our node.
if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.from) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/NeighborInfoModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NeighborInfoModule : public ProtobufModule<meshtastic_NeighborInfo>, priva
/*
* Send info on our node's neighbors into the mesh
*/
void sendNeighborInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
void sendNeighborInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false, bool sendEmpty = false);

/* update neighbors with subpacket sniffed from network */
void updateNeighbors(const meshtastic_MeshPacket &mp, const meshtastic_NeighborInfo *np);
Expand Down