refactor(BaseChatMesh): extract onDiscoveredAdvert to keep upstream signature

Reverts onDiscoveredContact to the upstream 4-param signature, adding a
separate virtual onDiscoveredAdvert(bool was_flood) with a default no-op
implementation. Only MyMesh overrides the new virtual; simple_secure_chat
and any future implementors need no changes on upstream merges.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-06-08 20:37:22 +02:00
parent ceea1df196
commit 2d6d35192b
5 changed files with 16 additions and 9 deletions

View File

@@ -360,9 +360,11 @@ void MyMesh::onContactsFull() {
} }
} }
void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path, bool was_flood) { void MyMesh::onDiscoveredAdvert(bool was_flood) {
if (_ui) _ui->notify(was_flood ? UIEventType::advertReceivedFlood : UIEventType::advertReceivedZeroHop); if (_ui) _ui->notify(was_flood ? UIEventType::advertReceivedFlood : UIEventType::advertReceivedZeroHop);
}
void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) {
if (_serial->isConnected()) { if (_serial->isConnected()) {
if (is_new) { if (is_new) {
writeContactRespFrame(PUSH_CODE_NEW_ADVERT, contact); writeContactRespFrame(PUSH_CODE_NEW_ADVERT, contact);

View File

@@ -165,7 +165,8 @@ protected:
void onContactsFull() override; void onContactsFull() override;
void onContactOverwrite(const uint8_t* pub_key) override; void onContactOverwrite(const uint8_t* pub_key) override;
bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override; bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path, bool was_flood) override; void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
void onDiscoveredAdvert(bool was_flood) override;
void onContactPathUpdated(const ContactInfo &contact) override; void onContactPathUpdated(const ContactInfo &contact) override;
ContactInfo* processAck(const uint8_t *data) override; ContactInfo* processAck(const uint8_t *data) override;
void queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packet *pkt, uint32_t sender_timestamp, void queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packet *pkt, uint32_t sender_timestamp,

View File

@@ -202,11 +202,10 @@ protected:
return true; return true;
} }
void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path, bool was_flood) override { void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) override {
(void)is_new; (void)is_new;
(void)path_len; (void)path_len;
(void)path; (void)path;
(void)was_flood;
// TODO: if not in favs, prompt to add as fav(?) // TODO: if not in favs, prompt to add as fav(?)
Serial.printf("ADVERT from -> %s\n", contact.name); Serial.printf("ADVERT from -> %s\n", contact.name);

View File

@@ -144,7 +144,8 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
if (!shouldAutoAddContactType(parser.getType())) { if (!shouldAutoAddContactType(parser.getType())) {
ContactInfo ci; ContactInfo ci;
populateContactFromAdvert(ci, id, parser, timestamp); populateContactFromAdvert(ci, id, parser, timestamp);
onDiscoveredContact(ci, true, packet->path_len, packet->path, packet->isRouteFlood()); // let UI know onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know
onDiscoveredAdvert(packet->isRouteFlood());
return; return;
} }
@@ -153,7 +154,8 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
if (max_hops > 0 && packet->getPathHashCount() >= max_hops) { if (max_hops > 0 && packet->getPathHashCount() >= max_hops) {
ContactInfo ci; ContactInfo ci;
populateContactFromAdvert(ci, id, parser, timestamp); populateContactFromAdvert(ci, id, parser, timestamp);
onDiscoveredContact(ci, true, packet->path_len, packet->path, packet->isRouteFlood()); // let UI know onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know
onDiscoveredAdvert(packet->isRouteFlood());
return; return;
} }
@@ -161,7 +163,8 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
if (from == NULL) { if (from == NULL) {
ContactInfo ci; ContactInfo ci;
populateContactFromAdvert(ci, id, parser, timestamp); populateContactFromAdvert(ci, id, parser, timestamp);
onDiscoveredContact(ci, true, packet->path_len, packet->path, packet->isRouteFlood()); onDiscoveredContact(ci, true, packet->path_len, packet->path);
onDiscoveredAdvert(packet->isRouteFlood());
onContactsFull(); onContactsFull();
MESH_DEBUG_PRINTLN("onAdvertRecv: unable to allocate contact slot for new contact"); MESH_DEBUG_PRINTLN("onAdvertRecv: unable to allocate contact slot for new contact");
return; return;
@@ -183,7 +186,8 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
from->last_advert_timestamp = timestamp; from->last_advert_timestamp = timestamp;
from->lastmod = getRTCClock()->getCurrentTime(); from->lastmod = getRTCClock()->getCurrentTime();
onDiscoveredContact(*from, is_new, packet->path_len, packet->path, packet->isRouteFlood()); // let UI know onDiscoveredContact(*from, is_new, packet->path_len, packet->path); // let UI know
onDiscoveredAdvert(packet->isRouteFlood());
} }
int BaseChatMesh::searchPeersByHash(const uint8_t* hash) { int BaseChatMesh::searchPeersByHash(const uint8_t* hash) {

View File

@@ -102,7 +102,8 @@ protected:
virtual bool shouldOverwriteWhenFull() const { return false; } virtual bool shouldOverwriteWhenFull() const { return false; }
virtual uint8_t getAutoAddMaxHops() const { return 0; } // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops virtual uint8_t getAutoAddMaxHops() const { return 0; } // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops
virtual void onContactOverwrite(const uint8_t* pub_key) {}; virtual void onContactOverwrite(const uint8_t* pub_key) {};
virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path, bool was_flood) = 0; virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
virtual void onDiscoveredAdvert(bool was_flood) {}
virtual ContactInfo* processAck(const uint8_t *data) = 0; virtual ContactInfo* processAck(const uint8_t *data) = 0;
virtual void onContactPathUpdated(const ContactInfo& contact) = 0; virtual void onContactPathUpdated(const ContactInfo& contact) = 0;
virtual bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len); virtual bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len);