|
|
@@ -22,9 +22,11 @@ CMD_RUNFOR = 3 # arg: (chan, length): turns on chan for length seconds |
|
|
|
class LORANode(object): |
|
|
|
'''Implement a LORANode initiator.''' |
|
|
|
|
|
|
|
def __init__(self, syncdatagram): |
|
|
|
def __init__(self, syncdatagram, shared=None): |
|
|
|
self.sd = syncdatagram |
|
|
|
self.st = Strobe(domain, F=KeccakF(800)) |
|
|
|
if shared is not None: |
|
|
|
self.st.key(shared) |
|
|
|
|
|
|
|
async def start(self): |
|
|
|
msg = self.st.send_enc(os.urandom(16) + b'reqreset') + \ |
|
|
@@ -177,10 +179,14 @@ def timeout(timeout): |
|
|
|
class TestLORANode(unittest.IsolatedAsyncioTestCase): |
|
|
|
@timeout(2) |
|
|
|
async def test_lora(self): |
|
|
|
shared_key = os.urandom(32) |
|
|
|
|
|
|
|
class TestSD(MockSyncDatagram): |
|
|
|
async def runner(self): |
|
|
|
l = Strobe(domain, F=KeccakF(800)) |
|
|
|
|
|
|
|
l.key(shared_key) |
|
|
|
|
|
|
|
# start handshake |
|
|
|
r = await self.get() |
|
|
|
|
|
|
@@ -234,7 +240,7 @@ class TestLORANode(unittest.IsolatedAsyncioTestCase): |
|
|
|
l.send_mac(8)) |
|
|
|
|
|
|
|
tsd = TestSD() |
|
|
|
l = LORANode(tsd) |
|
|
|
l = LORANode(tsd, shared=shared_key) |
|
|
|
|
|
|
|
await l.start() |
|
|
|
|
|
|
@@ -308,12 +314,15 @@ class TestLORANode(unittest.IsolatedAsyncioTestCase): |
|
|
|
# pass the reply back |
|
|
|
await self.put(outbytes[:outbuf.pktlen]) |
|
|
|
|
|
|
|
# Generate shared key |
|
|
|
shared_key = os.urandom(32) |
|
|
|
|
|
|
|
# Initialize everything |
|
|
|
lora_comms.comms_init(commstate, cb) |
|
|
|
lora_comms.comms_init(commstate, cb, make_pktbuf(shared_key)) |
|
|
|
|
|
|
|
# Create test fixture |
|
|
|
tsd = CCodeSD() |
|
|
|
l = LORANode(tsd) |
|
|
|
l = LORANode(tsd, shared=shared_key) |
|
|
|
|
|
|
|
# Send various messages |
|
|
|
await l.start() |
|
|
|