diff --git a/pyproject.toml b/pyproject.toml index 82e523c..baead3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, diff --git a/src/meshcore/commands/contact.py b/src/meshcore/commands/contact.py index 38282cf..517eef8 100644 --- a/src/meshcore/commands/contact.py +++ b/src/meshcore/commands/contact.py @@ -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]) diff --git a/src/meshcore/events.py b/src/meshcore/events.py index 01a4a86..00bde4a 100644 --- a/src/meshcore/events.py +++ b/src/meshcore/events.py @@ -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" diff --git a/src/meshcore/packets.py b/src/meshcore/packets.py index 077739a..b5cef23 100644 --- a/src/meshcore/packets.py +++ b/src/meshcore/packets.py @@ -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 diff --git a/src/meshcore/reader.py b/src/meshcore/reader.py index 54052a5..254b488 100644 --- a/src/meshcore/reader.py +++ b/src/meshcore/reader.py @@ -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 = {