Fixed missing check for zero-length packets on IFAC-enabled interfaces. Fixes #65.

This commit is contained in:
Mark Qvist 2022-06-11 18:52:26 +02:00
parent 214ee9d771
commit 2685e043ea
2 changed files with 27 additions and 38 deletions

View File

@ -376,7 +376,7 @@ class RNodeInterface(Interface):
self.bitrate = 0 self.bitrate = 0
def processIncoming(self, data): def processIncoming(self, data):
self.rxb += len(data) self.rxb += len(data)
self.owner.inbound(data, self) self.owner.inbound(data, self)
self.r_stat_rssi = None self.r_stat_rssi = None
self.r_stat_snr = None self.r_stat_snr = None

View File

@ -26,7 +26,6 @@ import time
import math import math
import struct import struct
import threading import threading
import traceback
from time import sleep from time import sleep
from .vendor import umsgpack as umsgpack from .vendor import umsgpack as umsgpack
@ -284,9 +283,6 @@ class Transport:
def jobs(): def jobs():
outgoing = [] outgoing = []
Transport.jobs_running = True Transport.jobs_running = True
# TODO: Remove at some point
# start_time = time.time()
try: try:
if not Transport.jobs_locked: if not Transport.jobs_locked:
@ -508,17 +504,9 @@ class Transport:
except Exception as e: except Exception as e:
RNS.log("An exception occurred while running Transport jobs.", RNS.LOG_ERROR) RNS.log("An exception occurred while running Transport jobs.", RNS.LOG_ERROR)
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR) RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
traceback.print_exc()
Transport.jobs_running = False Transport.jobs_running = False
# TODO: Remove at some point
# end_time = time.time()
# if RNS.loglevel >= RNS.LOG_EXTREME:
# duration = round((end_time - start_time) * 1000, 2)
# if duration > 1:
# RNS.log("Transport jobs took "+str(duration)+"ms", RNS.LOG_EXTREME)
for packet in outgoing: for packet in outgoing:
packet.send() packet.send()
@ -822,42 +810,43 @@ class Transport:
def inbound(raw, interface=None): def inbound(raw, interface=None):
# If interface access codes are enabled, # If interface access codes are enabled,
# we must authenticate each packet. # we must authenticate each packet.
if interface != None and hasattr(interface, "ifac_identity") and interface.ifac_identity != None: if len(raw) > 1:
# Check that IFAC flag is set if interface != None and hasattr(interface, "ifac_identity") and interface.ifac_identity != None:
if raw[0] & 0x80 == 0x80: # Check that IFAC flag is set
if len(raw) > 2+interface.ifac_size: if raw[0] & 0x80 == 0x80:
# Extract IFAC if len(raw) > 2+interface.ifac_size:
ifac = raw[2:2+interface.ifac_size] # Extract IFAC
ifac = raw[2:2+interface.ifac_size]
# Unset IFAC flag # Unset IFAC flag
new_header = bytes([raw[0] & 0x7f, raw[1]]) new_header = bytes([raw[0] & 0x7f, raw[1]])
# Re-assemble packet # Re-assemble packet
new_raw = new_header+raw[2+interface.ifac_size:] new_raw = new_header+raw[2+interface.ifac_size:]
# Calculate expected IFAC # Calculate expected IFAC
expected_ifac = interface.ifac_identity.sign(new_raw)[-interface.ifac_size:] expected_ifac = interface.ifac_identity.sign(new_raw)[-interface.ifac_size:]
# Check it
if ifac == expected_ifac:
raw = new_raw
else:
return
# Check it
if ifac == expected_ifac:
raw = new_raw
else: else:
return return
else: else:
# If the IFAC flag is not set, but should be,
# drop the packet.
return return
else: else:
# If the IFAC flag is not set, but should be, # If the interface does not have IFAC enabled,
# drop the packet. # check the received packet IFAC flag.
return if raw[0] & 0x80 == 0x80:
# If the flag is set, drop the packet
else: return
# If the interface does not have IFAC enabled,
# check the received packet IFAC flag.
if raw[0] & 0x80 == 0x80:
# If the flag is set, drop the packet
return
while (Transport.jobs_running): while (Transport.jobs_running):
sleep(0.0005) sleep(0.0005)