mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
Merge pull request #66 from jkingsman/fix-three-byte-path-packets
Fix bad bitmask on three byte PATH packets
This commit is contained in:
commit
cfafaccb5b
2 changed files with 47 additions and 2 deletions
|
|
@ -827,13 +827,13 @@ class MessageReader:
|
|||
res["pubkey_pre"] = dbuf.read(6).hex()
|
||||
opl = dbuf.read(1)[0]
|
||||
opl_hlen = ((opl & 0xc0) >> 6) + 1
|
||||
opl = opl & 0xbf
|
||||
opl = opl & 0x3f
|
||||
res["out_path_len"] = opl
|
||||
res["out_path_hash_len"] = opl_hlen
|
||||
res["out_path"] = dbuf.read(opl*opl_hlen).hex()
|
||||
ipl = dbuf.read(1)[0]
|
||||
ipl_hlen = ((ipl & 0xc0) >> 6) + 1
|
||||
ipl = ipl & 0xbf
|
||||
ipl = ipl & 0x3f
|
||||
res["in_path_len"] = ipl
|
||||
res["in_path_hash_len"] = ipl_hlen
|
||||
res["in_path"] = dbuf.read(ipl*ipl_hlen).hex()
|
||||
|
|
|
|||
45
tests/unit/test_path_discovery_response.py
Normal file
45
tests/unit/test_path_discovery_response.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import pytest
|
||||
|
||||
from meshcore.events import EventType
|
||||
from meshcore.reader import MessageReader
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class MockDispatcher:
|
||||
def __init__(self):
|
||||
self.dispatched_events = []
|
||||
|
||||
async def dispatch(self, event):
|
||||
self.dispatched_events.append(event)
|
||||
|
||||
|
||||
async def test_path_discovery_response_decodes_3byte_paths():
|
||||
dispatcher = MockDispatcher()
|
||||
reader = MessageReader(dispatcher)
|
||||
|
||||
packet = bytearray.fromhex(
|
||||
"8d" # PacketType.PATH_DISCOVERY_RESPONSE
|
||||
"00" # Reserved byte
|
||||
"112233445566" # 6-byte contact public-key prefix
|
||||
"82" # Outbound path descriptor: mode=2 (3-byte hops), hop_count=2
|
||||
"a1a2a3b1b2b3" # Outbound path bytes: 2 hops * 3 bytes each
|
||||
"81" # Inbound path descriptor: mode=2 (3-byte hops), hop_count=1
|
||||
"c1c2c3" # Inbound path bytes: 1 hop * 3 bytes
|
||||
)
|
||||
|
||||
await reader.handle_rx(packet)
|
||||
|
||||
matching = [e for e in dispatcher.dispatched_events if e.type == EventType.PATH_RESPONSE]
|
||||
assert len(matching) == 1
|
||||
|
||||
payload = matching[0].payload
|
||||
assert payload["pubkey_pre"] == "112233445566"
|
||||
|
||||
assert payload["out_path_hash_len"] == 3
|
||||
assert payload["out_path_len"] == 2
|
||||
assert payload["out_path"] == "a1a2a3b1b2b3"
|
||||
|
||||
assert payload["in_path_hash_len"] == 3
|
||||
assert payload["in_path_len"] == 1
|
||||
assert payload["in_path"] == "c1c2c3"
|
||||
Loading…
Add table
Add a link
Reference in a new issue