diff --git a/pyproject.toml b/pyproject.toml index 2d37a5b..c626710 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "meshcore" -version = "2.1.19" +version = "2.1.20" authors = [ { name="Florent de Lamotte", email="florent@frizoncorrea.fr" }, { name="Alex Wolden", email="awolden@gmail.com" }, diff --git a/src/meshcore/commands/messaging.py b/src/meshcore/commands/messaging.py index 65b5cce..fb5ef12 100644 --- a/src/meshcore/commands/messaging.py +++ b/src/meshcore/commands/messaging.py @@ -1,8 +1,10 @@ import logging import random from typing import Optional, Union +from hashlib import sha256 from ..events import Event, EventType +from ..packets import PacketType from .base import CommandHandlerBase, DestinationType, _validate_destination logger = logging.getLogger("meshcore") @@ -209,3 +211,20 @@ class MessagingCommands(CommandHandlerBase): return Event(EventType.ERROR, {"reason": "unsupported_path_type"}) return await self.send(cmd_data, [EventType.MSG_SENT, EventType.ERROR]) + + async def set_flood_scope(self, scope): + if scope.startswith("#"): # an hash + logger.debug(f"Setting scope from hash {scope}") + scope_key = sha256(scope.encode("utf-8")).digest()[0:16] + elif scope == "0" or scope == "None": # disable + scope_key = b"\0"*16 + else: # assume the key has been sent directly + scope_key = scope.encode("utf-8") + + logger.debug(f"Setting scope to {scope_key.hex()}") + + cmd_data = bytearray([PacketType.SET_FLOOD_SCOPE.value]) + cmd_data.extend(b"\0") + cmd_data.extend(scope_key) + + return await self.send(cmd_data, [EventType.OK, EventType.ERROR]) diff --git a/src/meshcore/packets.py b/src/meshcore/packets.py index ce0e797..9ca0809 100644 --- a/src/meshcore/packets.py +++ b/src/meshcore/packets.py @@ -33,6 +33,8 @@ class PacketType(Enum): CUSTOM_VARS = 21 BINARY_REQ = 50 FACTORY_RESET = 51 + PATH_DISCOVERY = 52 + SET_FLOOD_SCOPE = 54 # Push notifications ADVERTISEMENT = 0x80