mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
add pending_contacts_list and track adverts and path changes
This commit is contained in:
parent
f534b1898b
commit
d7de28d7f9
3 changed files with 30 additions and 2 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue