Skip to content

Commit 0e453f7

Browse files
committed
implementing default_flood_scope
1 parent f538062 commit 0e453f7

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/meshcore/commands/messaging.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,36 @@ async def set_flood_scope(self, scope):
349349
cmd_data.extend(scope_key)
350350

351351
return await self.send(cmd_data, [EventType.OK, EventType.ERROR])
352+
353+
async def set_default_flood_scope(self, scope):
354+
if scope is None:
355+
logger.debug(f"Resetting default scope")
356+
scope_key = b"\0"*16
357+
scope_name = ""
358+
elif isinstance (scope, str):
359+
if scope == "0" or scope == "None" or scope == "*" or scope == "": # disable
360+
logger.debug ("Resetting default scope")
361+
scope_key = b"\0"*16
362+
scope_name = ""
363+
else:
364+
logger.debug (f"Setting scope to {scope}")
365+
if scope[0] != "#":
366+
scope = "#" + scope
367+
scope_name = scope
368+
scope_key = sha256(scope.encode("utf-8")).digest()[0:16]
369+
else:
370+
raise TypeError(f"set_flood_scope: unsupported scope type {type(scope).__name__}")
371+
372+
logger.debug(f"Setting scope key to {scope_key.hex()}")
373+
374+
cmd_data = bytearray([CommandType.SET_DEFAULT_FLOOD_SCOPE.value])
375+
cmd_data.extend(scope_name.encode("utf-8"))
376+
cmd_data.extend((31-len(scope))*b'\0')
377+
cmd_data.extend(scope_key)
378+
379+
return await self.send(cmd_data, [EventType.OK, EventType.ERROR])
380+
381+
async def get_default_flood_scope(self):
382+
logger.debug(f"Getting default flood scope")
383+
cmd_data = bytearray([CommandType.GET_DEFAULT_FLOOD_SCOPE.value])
384+
return await self.send(cmd_data, [EventType.DEFAULT_FLOOD_SCOPE, EventType.ERROR])

src/meshcore/events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class EventType(Enum):
5858
SIGN_START = "sign_start"
5959
SIGNATURE = "signature"
6060
ALLOWED_REPEAT_FREQ = "allowed_repeat_freq"
61+
DEFAULT_FLOOD_SCOPE = "default_flood_scope"
6162

6263
# Command response types
6364
OK = "command_ok"

src/meshcore/packets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class CommandType(Enum):
7373
GET_ALLOWED_REPEAT_FREQ = 60
7474
GET_STATS = 56 # R04: CMD_GET_STATS — used by get_stats_core/radio/packets
7575
SET_PATH_HASH_MODE = 61
76+
SET_DEFAULT_FLOOD_SCOPE = 63
77+
GET_DEFAULT_FLOOD_SCOPE = 64
7678

7779
# Packet prefixes for the protocol
7880
class PacketType(Enum):
@@ -103,6 +105,7 @@ class PacketType(Enum):
103105
STATS = 24
104106
AUTOADD_CONFIG = 25
105107
ALLOWED_REPEAT_FREQ = 26
108+
DEFAULT_FLOOD_SCOPE = 28
106109

107110
# Push notifications
108111
ADVERTISEMENT = 0x80

src/meshcore/reader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ async def handle_rx(self, data: bytearray):
182182
self_info["name"] = dbuf.read().decode("utf-8", "ignore")
183183
await self.dispatcher.dispatch(Event(EventType.SELF_INFO, self_info))
184184

185+
elif packet_type_value == PacketType.DEFAULT_FLOOD_SCOPE.value:
186+
res = {}
187+
res["scope_name"] = dbuf.read(31).decode("utf-8", "ignore").replace("\0", "")
188+
res["scope_key"] = dbuf.read(16).hex()
189+
await self.dispatcher.dispatch(Event(EventType.DEFAULT_FLOOD_SCOPE, res))
190+
185191
elif packet_type_value == PacketType.MSG_SENT.value:
186192
res = {}
187193
res["type"] = dbuf.read(1)[0]

0 commit comments

Comments
 (0)