Initial support for transport codes : set_flood_scope

This commit is contained in:
Florent de Lamotte 2025-11-05 16:31:34 +01:00
parent 97a53ec32b
commit 5a5f97322d
3 changed files with 22 additions and 1 deletions

View file

@ -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" },

View file

@ -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])

View file

@ -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