mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-18 00:32:38 +00:00
addFromContact: Don't auto-favorite when CLIENT_BASE; don't update last_heard unless CLIENT_BASE (#8495)
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
@@ -1638,13 +1638,32 @@ void NodeDB::addFromContact(meshtastic_SharedContact contact)
|
|||||||
// If should_ignore is set,
|
// If should_ignore is set,
|
||||||
// we need to clear the public key and other cruft, in addition to setting the node as ignored
|
// we need to clear the public key and other cruft, in addition to setting the node as ignored
|
||||||
info->is_ignored = true;
|
info->is_ignored = true;
|
||||||
|
info->is_favorite = false;
|
||||||
info->has_device_metrics = false;
|
info->has_device_metrics = false;
|
||||||
info->has_position = false;
|
info->has_position = false;
|
||||||
info->user.public_key.size = 0;
|
info->user.public_key.size = 0;
|
||||||
info->user.public_key.bytes[0] = 0;
|
info->user.public_key.bytes[0] = 0;
|
||||||
} else {
|
} else {
|
||||||
info->last_heard = getValidTime(RTCQualityNTP);
|
/* Clients are sending add_contact before every text message DM (because clients may hold a larger node database with
|
||||||
info->is_favorite = true;
|
* public keys than the radio holds). However, we don't want to update last_heard just because we sent someone a DM!
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* "Boring old nodes" are the first to be evicted out of the node database when full. This includes a newly-zeroed
|
||||||
|
* nodeinfo because it has: !is_favorite && last_heard==0. To keep this from happening when we addFromContact, we set the
|
||||||
|
* new node as a favorite, and we leave last_heard alone (even if it's zero).
|
||||||
|
*/
|
||||||
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_CLIENT_BASE) {
|
||||||
|
// Special case for CLIENT_BASE: is_favorite has special meaning, and we don't want to automatically set it
|
||||||
|
// without the user doing so deliberately. We don't normally expect users to use a CLIENT_BASE to send DMs or to add
|
||||||
|
// contacts, but we should make sure it doesn't auto-favorite in case they do. Instead, as a workaround, we'll set
|
||||||
|
// last_heard to now, so that the add_contact node doesn't immediately get evicted.
|
||||||
|
info->last_heard = getTime();
|
||||||
|
} else {
|
||||||
|
// Normal case: set is_favorite to prevent expiration.
|
||||||
|
// last_heard will remain as-is (or remain 0 if this entry wasn't in the nodeDB).
|
||||||
|
info->is_favorite = true;
|
||||||
|
}
|
||||||
|
|
||||||
// As the clients will begin sending the contact with DMs, we want to strictly check if the node is manually verified
|
// As the clients will begin sending the contact with DMs, we want to strictly check if the node is manually verified
|
||||||
if (contact.manually_verified) {
|
if (contact.manually_verified) {
|
||||||
info->bitfield |= NODEINFO_BITFIELD_IS_KEY_MANUALLY_VERIFIED_MASK;
|
info->bitfield |= NODEINFO_BITFIELD_IS_KEY_MANUALLY_VERIFIED_MASK;
|
||||||
|
|||||||
@@ -104,9 +104,18 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
|
|||||||
(config.security.admin_key[2].size == 32 &&
|
(config.security.admin_key[2].size == 32 &&
|
||||||
memcmp(mp.public_key.bytes, config.security.admin_key[2].bytes, 32) == 0)) {
|
memcmp(mp.public_key.bytes, config.security.admin_key[2].bytes, 32) == 0)) {
|
||||||
LOG_INFO("PKC admin payload with authorized sender key");
|
LOG_INFO("PKC admin payload with authorized sender key");
|
||||||
|
|
||||||
|
// Automatically favorite the node that is using the admin key
|
||||||
auto remoteNode = nodeDB->getMeshNode(mp.from);
|
auto remoteNode = nodeDB->getMeshNode(mp.from);
|
||||||
if (remoteNode && !remoteNode->is_favorite) {
|
if (remoteNode && !remoteNode->is_favorite) {
|
||||||
remoteNode->is_favorite = true;
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_CLIENT_BASE) {
|
||||||
|
// Special case for CLIENT_BASE: is_favorite has special meaning, and we don't want to automatically set it
|
||||||
|
// without the user doing so deliberately.
|
||||||
|
LOG_INFO("PKC admin valid, but not auto-favoriting node %x because role==CLIENT_BASE", mp.from);
|
||||||
|
} else {
|
||||||
|
LOG_INFO("PKC admin valid. Auto-favoriting node %x", mp.from);
|
||||||
|
remoteNode->is_favorite = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
myReply = allocErrorResponse(meshtastic_Routing_Error_ADMIN_PUBLIC_KEY_UNAUTHORIZED, &mp);
|
myReply = allocErrorResponse(meshtastic_Routing_Error_ADMIN_PUBLIC_KEY_UNAUTHORIZED, &mp);
|
||||||
|
|||||||
Reference in New Issue
Block a user