From 0e12442a28be1fec6d8721fd11baf2e522da370a Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 27 Oct 2023 18:12:53 +0200 Subject: [PATCH] Local interface bitrate simulation --- RNS/Interfaces/LocalInterface.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/RNS/Interfaces/LocalInterface.py b/RNS/Interfaces/LocalInterface.py index a076831..fbfffdc 100644 --- a/RNS/Interfaces/LocalInterface.py +++ b/RNS/Interfaces/LocalInterface.py @@ -28,6 +28,7 @@ import time import sys import os import RNS +from threading import Lock class HDLC(): FLAG = 0x7E @@ -150,9 +151,6 @@ class LocalClientInterface(Interface): def processIncoming(self, data): - if self._force_bitrate: - time.sleep(len(data) / self.bitrate * 8) - self.rxb += len(data) if hasattr(self, "parent_interface") and self.parent_interface != None: self.parent_interface.rxb += len(data) @@ -170,8 +168,16 @@ class LocalClientInterface(Interface): if self.online: try: self.writing = True + if self._force_bitrate: - time.sleep(len(data) / self.bitrate * 8) + if not hasattr(self, "send_lock"): + self.send_lock = Lock() + + with self.send_lock: + s = len(data) / self.bitrate * 8 + RNS.log(f"Simulating latency of {RNS.prettytime(s)} for {len(data)} bytes") + time.sleep(s) + data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG]) self.socket.sendall(data) self.writing = False