implementing default_flood_scope

This commit is contained in:
Florent
2026-04-25 17:10:00 +02:00
parent f538062546
commit 0e453f7c5d
4 changed files with 43 additions and 0 deletions

View File

@@ -349,3 +349,36 @@ class MessagingCommands(CommandHandlerBase):
cmd_data.extend(scope_key)
return await self.send(cmd_data, [EventType.OK, EventType.ERROR])
async def set_default_flood_scope(self, scope):
if scope is None:
logger.debug(f"Resetting default scope")
scope_key = b"\0"*16
scope_name = ""
elif isinstance (scope, str):
if scope == "0" or scope == "None" or scope == "*" or scope == "": # disable
logger.debug ("Resetting default scope")
scope_key = b"\0"*16
scope_name = ""
else:
logger.debug (f"Setting scope to {scope}")
if scope[0] != "#":
scope = "#" + scope
scope_name = scope
scope_key = sha256(scope.encode("utf-8")).digest()[0:16]
else:
raise TypeError(f"set_flood_scope: unsupported scope type {type(scope).__name__}")
logger.debug(f"Setting scope key to {scope_key.hex()}")
cmd_data = bytearray([CommandType.SET_DEFAULT_FLOOD_SCOPE.value])
cmd_data.extend(scope_name.encode("utf-8"))
cmd_data.extend((31-len(scope))*b'\0')
cmd_data.extend(scope_key)
return await self.send(cmd_data, [EventType.OK, EventType.ERROR])
async def get_default_flood_scope(self):
logger.debug(f"Getting default flood scope")
cmd_data = bytearray([CommandType.GET_DEFAULT_FLOOD_SCOPE.value])
return await self.send(cmd_data, [EventType.DEFAULT_FLOOD_SCOPE, EventType.ERROR])

View File

@@ -58,6 +58,7 @@ class EventType(Enum):
SIGN_START = "sign_start"
SIGNATURE = "signature"
ALLOWED_REPEAT_FREQ = "allowed_repeat_freq"
DEFAULT_FLOOD_SCOPE = "default_flood_scope"
# Command response types
OK = "command_ok"

View File

@@ -73,6 +73,8 @@ class CommandType(Enum):
GET_ALLOWED_REPEAT_FREQ = 60
GET_STATS = 56 # R04: CMD_GET_STATS — used by get_stats_core/radio/packets
SET_PATH_HASH_MODE = 61
SET_DEFAULT_FLOOD_SCOPE = 63
GET_DEFAULT_FLOOD_SCOPE = 64
# Packet prefixes for the protocol
class PacketType(Enum):
@@ -103,6 +105,7 @@ class PacketType(Enum):
STATS = 24
AUTOADD_CONFIG = 25
ALLOWED_REPEAT_FREQ = 26
DEFAULT_FLOOD_SCOPE = 28
# Push notifications
ADVERTISEMENT = 0x80

View File

@@ -182,6 +182,12 @@ class MessageReader:
self_info["name"] = dbuf.read().decode("utf-8", "ignore")
await self.dispatcher.dispatch(Event(EventType.SELF_INFO, self_info))
elif packet_type_value == PacketType.DEFAULT_FLOOD_SCOPE.value:
res = {}
res["scope_name"] = dbuf.read(31).decode("utf-8", "ignore").replace("\0", "")
res["scope_key"] = dbuf.read(16).hex()
await self.dispatcher.dispatch(Event(EventType.DEFAULT_FLOOD_SCOPE, res))
elif packet_type_value == PacketType.MSG_SENT.value:
res = {}
res["type"] = dbuf.read(1)[0]