mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
using BytesIO to decode packets
This commit is contained in:
parent
2599b970c1
commit
d95b7bf90d
1 changed files with 14 additions and 15 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import os, sys
|
import os, sys, io
|
||||||
import time, datetime
|
import time, datetime
|
||||||
import getopt, json, shlex, re
|
import getopt, json, shlex, re
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -208,22 +208,19 @@ async def handle_log_rx(event):
|
||||||
return
|
return
|
||||||
|
|
||||||
pkt = bytes().fromhex(event.payload["payload"])
|
pkt = bytes().fromhex(event.payload["payload"])
|
||||||
|
pbuf = io.BytesIO(pkt)
|
||||||
|
header = pbuf.read(1)[0]
|
||||||
|
|
||||||
if handle_log_rx.channel_echoes:
|
if header & ~1 == 0x14: # flood msg / channel
|
||||||
if pkt[0] & ~1 == 0x14:
|
if handle_log_rx.channel_echoes:
|
||||||
chan_name = ""
|
if header & 1 == 0: # has transport code
|
||||||
if pkt[0] & 1: #no transport code
|
pbuf.read(4) # discard transport code
|
||||||
path_len = pkt[1]
|
path_len = pbuf.read(1)[0]
|
||||||
path = pkt[2:path_len+2].hex()
|
path = pbuf.read(path_len).hex()
|
||||||
path_end = path_len+2
|
chan_hash = pbuf.read(1).hex()
|
||||||
else:
|
cipher_mac = pbuf.read(2)
|
||||||
path_len = pkt[5]
|
msg = pbuf.read() # until the end of buffer
|
||||||
path = pkt[6:path_len+6].hex()
|
|
||||||
path_end = path_len+6
|
|
||||||
|
|
||||||
chan_hash = pkt[path_end:path_end+1].hex()
|
|
||||||
cipher_mac = pkt[path_end+1:path_end+3]
|
|
||||||
msg = pkt[path_end+3:]
|
|
||||||
channel = None
|
channel = None
|
||||||
for c in await get_channels(mc):
|
for c in await get_channels(mc):
|
||||||
if c["channel_hash"] == chan_hash : # validate against MAC
|
if c["channel_hash"] == chan_hash : # validate against MAC
|
||||||
|
|
@ -233,6 +230,8 @@ async def handle_log_rx(event):
|
||||||
channel = c
|
channel = c
|
||||||
break
|
break
|
||||||
|
|
||||||
|
chan_name = ""
|
||||||
|
|
||||||
if channel is None :
|
if channel is None :
|
||||||
if handle_log_rx.echo_unk_chans:
|
if handle_log_rx.echo_unk_chans:
|
||||||
chan_name = chan_hash
|
chan_name = chan_hash
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue