mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
implement advert_path
This commit is contained in:
parent
0769afa475
commit
462c4311d3
5 changed files with 24 additions and 1 deletions
|
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||
|
||||
[project]
|
||||
name = "meshcore"
|
||||
version = "2.2.25"
|
||||
version = "2.2.26"
|
||||
authors = [
|
||||
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
||||
{ name="Alex Wolden", email="awolden@gmail.com" },
|
||||
|
|
|
|||
|
|
@ -182,3 +182,9 @@ class ContactCommands(CommandHandlerBase):
|
|||
async def get_autoadd_config(self) -> Event:
|
||||
data = b"\x3B"
|
||||
return await self.send(data, [EventType.AUTOADD_CONFIG, EventType.ERROR])
|
||||
|
||||
async def get_advert_path(self, key: DestinationType) -> Event:
|
||||
key_bytes = _validate_destination(key, prefix_length=32)
|
||||
logger.debug(f"getting advert path for: {key} {key_bytes.hex()}")
|
||||
data = b"\x2a\0" + key_bytes
|
||||
return await self.send(data, [EventType.ADVERT_PATH, EventType.ERROR])
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class EventType(Enum):
|
|||
NEW_CONTACT = "new_contact"
|
||||
NEXT_CONTACT = "next_contact"
|
||||
AUTOADD_CONFIG = "autoadd_config"
|
||||
ADVERT_PATH = "advert_path"
|
||||
|
||||
# Push notifications
|
||||
ADVERTISEMENT = "advertisement"
|
||||
|
|
|
|||
|
|
@ -97,6 +97,8 @@ class PacketType(Enum):
|
|||
SIGN_START = 19
|
||||
SIGNATURE = 20
|
||||
CUSTOM_VARS = 21
|
||||
ADVERT_PATH = 22
|
||||
TUNING_PARAMS = 23
|
||||
STATS = 24
|
||||
AUTOADD_CONFIG = 25
|
||||
ALLOWED_REPEAT_FREQ = 26
|
||||
|
|
|
|||
|
|
@ -123,6 +123,20 @@ class MessageReader:
|
|||
await self.dispatcher.dispatch(Event(EventType.NEXT_CONTACT, c))
|
||||
self.contacts[c["public_key"]] = c
|
||||
|
||||
elif packet_type_value == PacketType.ADVERT_PATH.value :
|
||||
r = {}
|
||||
r["timestamp"] = int.from_bytes(dbuf.read(4), "little", signed=False)
|
||||
plen = int.from_bytes(dbuf.read(1), "little", signed=False)
|
||||
if plen == 255: # flood, should not happen
|
||||
r["path_hash_mode"] = -1
|
||||
r["path_len"] = -1
|
||||
else:
|
||||
r["path_hash_mode"] = plen >> 6 # 2 upper bytes
|
||||
r["path_len"] = plen & 0x3F
|
||||
r["path"] = dbuf.read().replace(b"\0", b"").hex()
|
||||
|
||||
await self.dispatcher.dispatch(Event(EventType.ADVERT_PATH, r))
|
||||
|
||||
elif packet_type_value == PacketType.CONTACT_END.value:
|
||||
lastmod = int.from_bytes(dbuf.read(4), byteorder="little")
|
||||
attributes = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue