diff --git a/RNS/Interfaces/BackboneInterface.py b/RNS/Interfaces/BackboneInterface.py index e1cba709..0daa2a04 100644 --- a/RNS/Interfaces/BackboneInterface.py +++ b/RNS/Interfaces/BackboneInterface.py @@ -1031,7 +1031,7 @@ class BackboneClientInterface(Interface): def process_outgoing(self, data): if self.online and not self.detached: try: - frame = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG]) + frame = HDLC.frame(data) if self.tx_stalled or not self.transmit_buffer.append(frame, self.tx_hwm): self.tx_drops += 1 self.tx_dropped_bytes += len(frame) diff --git a/RNS/Interfaces/LocalInterface.py b/RNS/Interfaces/LocalInterface.py index 18957d7d..92bd4086 100644 --- a/RNS/Interfaces/LocalInterface.py +++ b/RNS/Interfaces/LocalInterface.py @@ -218,7 +218,7 @@ class LocalClientInterface(Interface): if self.online: try: if self.epoll_backend: - frame = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG]) + frame = HDLC.frame(data) if self.tx_stalled or not self.transmit_buffer.append(frame, self.tx_hwm): self.tx_drops += 1 self.tx_dropped_bytes += len(frame) @@ -235,7 +235,7 @@ class LocalClientInterface(Interface): s = len(data) / self.bitrate * 8 time.sleep(s) - data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG]) + data = HDLC.frame(data) self.socket.sendall(data) self.writing = False self.txb += len(data) diff --git a/RNS/Interfaces/util/HDLC.py b/RNS/Interfaces/util/HDLC.py index ab0f1735..bd7fd976 100644 --- a/RNS/Interfaces/util/HDLC.py +++ b/RNS/Interfaces/util/HDLC.py @@ -50,6 +50,15 @@ class HDLC(): frame = frame.replace(HDLC.ESCPD_ESC, HDLC.ESC_B) return frame + @staticmethod + def frame(data): + esc = HDLC.escape(data) + frame = bytearray(len(esc)+2) + frame[0] = HDLC.FLAG + frame[1:-1] = esc + frame[-1] = HDLC.FLAG + return frame + class ReceiveBuffer(): def __init__(self, mtu, min_frame_len, max_frame_len=None, on_frame=None, on_invalid=None): self._mtu = mtu