Skip to content

Commit

Permalink
pylibschc.fragmenter: fix non-ACK handling for Fragmenter
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Feb 16, 2023
1 parent 061de8a commit 6cbffa1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pylibschc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
__copyright__ = "Copyright 2023 Freie Universität Berlin"
__license__ = "GPLv3"
__email__ = "[email protected]"
__version__ = "0.0.1b2"
__version__ = "0.0.1b3"
7 changes: 5 additions & 2 deletions pylibschc/fragmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ def input(self, data: typing.Union[bytes, BitArray]) -> ReassemblyStatus:
"""Handle incoming an ACK.
:param data: An ACK.
:raise RuntimeError: if ``data`` was not an ACK.
:raise RuntimeError: if ``data`` was not an ACK or if the fragmenter never sent
a fragment for which the ACK should be handled.
:retval ACK_HANDLED: when the ACK was handled."""
if not self._tx_conn:
raise RuntimeError("Unexpected state, you did not send a fragment yet")
if isinstance(data, BitArray):
bit_array = data
else:
Expand All @@ -115,7 +118,7 @@ def input(self, data: typing.Union[bytes, BitArray]) -> ReassemblyStatus:
self.end_rx(new_conn)
new_conn.reset()
assert RuntimeError(
b"Unexpected state, input {data.hex()} should be an ACK"
f"Unexpected state, input {data.hex()} should be an ACK"
)
return ReassemblyStatus.ACK_HANDLED # pragma: no cover

Expand Down
4 changes: 4 additions & 0 deletions tests/test_fragmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def test_fragmenter_reassembler_threaded( # pylint: disable=too-many-arguments
end_tx=self.end_tx,
remove_timer_entry=self.remove_timer_entry,
)
with pytest.raises(RuntimeError):
self.fragmenter.input(b"\x03\x03")
self.reassembler = pylibschc.fragmenter.Reassembler(
device=device,
post_timer_task=self.post_timer_task,
Expand Down Expand Up @@ -426,6 +428,8 @@ async def output(buffer):
end_tx=self.end_tx,
remove_timer_entry=self.remove_timer_entry,
)
with pytest.raises(RuntimeError):
self.fragmenter.input(b"\x03\x03")
self.reassembler = pylibschc.fragmenter.Reassembler(
device=device,
post_timer_task=self.post_timer_task,
Expand Down

0 comments on commit 6cbffa1

Please sign in to comment.