From 6567c3a09d3ca6ba2051017c2f20cb05018c6dc8 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 12 Jan 2025 23:24:27 +0100 Subject: [PATCH 1/2] Added support for dynamic link MTU discovery --- rnsh/initiator.py | 6 ++++-- rnsh/session.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rnsh/initiator.py b/rnsh/initiator.py index ec1c3f5..f58f81b 100644 --- a/rnsh/initiator.py +++ b/rnsh/initiator.py @@ -448,21 +448,23 @@ def compress_adaptive(buf: bytes): chunk_segment = None chunk_segment = None + max_data_len = channel.mdu - protocol.StreamDataMessage.OVERHEAD while chunk_len > 32 and comp_try < comp_tries: chunk_segment_length = int(chunk_len/comp_try) compressed_chunk = bz2.compress(buf[:chunk_segment_length]) compressed_length = len(compressed_chunk) - if compressed_length < protocol.StreamDataMessage.MAX_DATA_LEN and compressed_length < chunk_segment_length: + if compressed_length < max_data_len and compressed_length < chunk_segment_length: comp_success = True break else: comp_try += 1 if comp_success: + diff = max_data_len - len(compressed_chunk) chunk = compressed_chunk processed_length = chunk_segment_length else: - chunk = bytes(buf[:protocol.StreamDataMessage.MAX_DATA_LEN]) + chunk = bytes(buf[:max_data_len]) processed_length = len(chunk) return comp_success, processed_length, chunk diff --git a/rnsh/session.py b/rnsh/session.py index a56d971..f65e741 100644 --- a/rnsh/session.py +++ b/rnsh/session.py @@ -218,21 +218,23 @@ def compress_adaptive(buf: bytes): chunk_segment = None chunk_segment = None + max_data_len = self.channel.mdu - protocol.StreamDataMessage.OVERHEAD while chunk_len > 32 and comp_try < comp_tries: chunk_segment_length = int(chunk_len/comp_try) compressed_chunk = bz2.compress(buf[:chunk_segment_length]) compressed_length = len(compressed_chunk) - if compressed_length < protocol.StreamDataMessage.MAX_DATA_LEN and compressed_length < chunk_segment_length: + if compressed_length < max_data_len and compressed_length < chunk_segment_length: comp_success = True break else: comp_try += 1 if comp_success: + diff = max_data_len - len(compressed_chunk) chunk = compressed_chunk processed_length = chunk_segment_length else: - chunk = bytes(buf[:protocol.StreamDataMessage.MAX_DATA_LEN]) + chunk = bytes(buf[:max_data_len]) processed_length = len(chunk) return comp_success, processed_length, chunk From a9632d24fb2b84b29fcbc43dd8cc1f58e36421c3 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 12 Jan 2025 23:24:43 +0100 Subject: [PATCH 2/2] Updated version and RNS dependency version --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1402ebc..de8c8e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rnsh" -version = "0.1.4" +version = "0.1.5" description = "Shell over Reticulum" authors = ["acehoss "] license = "MIT" @@ -8,7 +8,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.7" -rns = ">=0.7.4" +rns = ">=0.9.0" [tool.poetry.scripts] rnsh = 'rnsh.rnsh:rnsh_cli'