add pending_contacts_list and track adverts and path changes

This commit is contained in:
Florent 2025-07-11 10:04:21 +02:00
parent f534b1898b
commit d7de28d7f9
3 changed files with 30 additions and 2 deletions

View file

@ -294,10 +294,16 @@ class CommandHandler:
else :
out_path_hex = path
out_path_len = int(len(path) / 2)
# reflect the change
contact["out_path"] = out_path_hex
contact["out_path_len"] = out_path_len
out_path_hex = out_path_hex + (128-len(out_path_hex)) * "0"
if flags is None :
flags = contact["flags"]
else :
# reflect the change
contact["flags"] = flags
adv_name_hex = contact["adv_name"].encode().hex()
adv_name_hex = adv_name_hex + (64-len(adv_name_hex)) * "0"

View file

@ -43,6 +43,8 @@ class MeshCore:
# Initialize state (private)
self._contacts = {}
self._contacts_ok = False
self._pending_contacts = {}
self._self_info = {}
self._time = 0
@ -178,6 +180,14 @@ class MeshCore:
"""Set up event subscriptions to track data internally"""
async def _update_contacts(event):
self._contacts = event.payload
self._contacts_ok = True
async def _add_pending_contact(event):
c = event.payload
self._pending_contacts[c["public_key"]] = c
async def _contact_change(event):
self._contacts_ok = False
async def _update_self_info(event):
self._self_info = event.payload
@ -187,14 +197,27 @@ class MeshCore:
# Subscribe to events to update internal state
self.subscribe(EventType.CONTACTS, _update_contacts)
self.subscribe(EventType.NEW_CONTACT, _add_pending_contact)
self.subscribe(EventType.SELF_INFO, _update_self_info)
self.subscribe(EventType.CURRENT_TIME, _update_time)
self.subscribe(EventType.ADVERTISEMENT, _contact_change)
self.subscribe(EventType.PATH_UPDATE, _contact_change)
# Getter methods for state
@property
def contacts(self):
"""Get the current contacts"""
return self._contacts
@property
def contacts_ok(self):
"""Get wether contact list is in sync"""
return self._contacts_ok
@property
def pending_contacts(self):
"""Get pending contacts"""
return self._pending_contacts
@property
def self_info(self):
@ -323,7 +346,7 @@ class MeshCore:
async def ensure_contacts(self):
"""Ensure contacts are fetched"""
if not self._contacts:
if not self._contacts or not self._contacts_ok :
await self.commands.get_contacts()
return True
return False

View file

@ -65,7 +65,6 @@ class MessageReader:
elif packet_type_value == PacketType.CONTACT_END.value:
await self.dispatcher.dispatch(Event(EventType.CONTACTS, self.contacts))
elif packet_type_value == PacketType.SELF_INFO.value:
self_info = {}
self_info["adv_type"] = data[1]