diff --git a/Makefile b/Makefile index 784cefc7e..a19123916 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ .PHONY: clean const date dist release pipenv pypi update +export PIPENV_VENV_IN_PROJECT=1 + SHELL := /usr/local/bin/bash DIR ?= . diff --git a/docker/Dockerfile b/docker/Dockerfile index 4ddcef0d7..cbfda7dfd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ # basic info FROM library/ubuntu -LABEL version 2019.03.07 +LABEL version 2019.03.28 LABEL description "Ubuntu Environment" # prepare environment diff --git a/setup.py b/setup.py index 08db0db17..4ec732c72 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from distutils.core import setup # version string -__version__ = '0.14.1' +__version__ = '0.14.2' # README with open('README.md', encoding='utf-8') as file: diff --git a/src/reassembly/tcp.py b/src/reassembly/tcp.py index 7516b8881..f9ea4fa64 100644 --- a/src/reassembly/tcp.py +++ b/src/reassembly/tcp.py @@ -95,7 +95,6 @@ for further handling. Otherwise, return. """ -import copy import io import sys @@ -250,68 +249,69 @@ def reassembly(self, info): self._buffer[BUFID] = { 'hdl': [Info(first=info.len, last=sys.maxsize)], ACK: dict( - ind=list(), + ind=[info.num], isn=info.dsn, len=info.len, raw=info.payload, ), } - - # initialise buffer with ACK - if ACK not in self._buffer[BUFID]: - self._buffer[BUFID][ACK] = dict( - ind=list(), - isn=info.dsn, - len=info.len, - raw=info.payload, - ) - - # append packet index - self._buffer[BUFID][ACK]['ind'].append(info.num) - - # record fragment payload - ISN = self._buffer[BUFID][ACK]['isn'] # Initial Sequence Number - RAW = self._buffer[BUFID][ACK]['raw'] # Raw Payload Data - if DSN >= ISN: # if fragment goes after existing payload - LEN = self._buffer[BUFID][ACK]['len'] - GAP = DSN - (ISN + LEN) # gap length between payloads - if GAP >= 0: # if fragment goes after existing payload - RAW += bytearray(GAP) + info.payload - else: # if fragment partially overlaps existing payload - RAW[DSN-ISN:] = info.payload - else: # if fragment exceeds existing payload - LEN = info.len - GAP = ISN - (DSN + LEN) # gap length between payloads - self._buffer[BUFID][ACK]['isn'] = DSN - if GAP >= 0: # if fragment exceeds existing payload - RAW = info.payload + bytearray(GAP) + RAW - else: # if fragment partially overlaps existing payload - RAW = info.payload + RAW[ISN-GAP:] - self._buffer[BUFID][ACK]['raw'] = RAW # update payload datagram - self._buffer[BUFID][ACK]['len'] = len(RAW) # update payload length - - # update hole descriptor list - HDL = copy.deepcopy(self._buffer[BUFID]['hdl']) - for (index, hole) in enumerate(self._buffer[BUFID]['hdl']): # step one - if info.first > hole.last: # step two - continue - if info.last < hole.first: # step three - continue - del HDL[index] # step four - if info.first > hole.first: # step five - new_hole = Info( - first=hole.first, - last=info.first - 1, - ) - HDL.insert(index, new_hole) - if info.last < hole.last and not FIN and not RST: # step six - new_hole = Info( - first=info.last + 1, - last=hole.last + else: + # initialise buffer with ACK + if ACK not in self._buffer[BUFID]: + self._buffer[BUFID][ACK] = dict( + ind=[info.num], + isn=info.dsn, + len=info.len, + raw=info.payload, ) - HDL.insert(index+1, new_hole) - break # step seven - self._buffer[BUFID]['hdl'] = HDL # update HDL + else: + # append packet index + self._buffer[BUFID][ACK]['ind'].append(info.num) + + # record fragment payload + ISN = self._buffer[BUFID][ACK]['isn'] # Initial Sequence Number + RAW = self._buffer[BUFID][ACK]['raw'] # Raw Payload Data + if DSN >= ISN: # if fragment goes after existing payload + LEN = self._buffer[BUFID][ACK]['len'] + GAP = DSN - (ISN + LEN) # gap length between payloads + if GAP >= 0: # if fragment goes after existing payload + RAW += bytearray(GAP) + info.payload + else: # if fragment partially overlaps existing payload + RAW[DSN-ISN:] = info.payload + else: # if fragment exceeds existing payload + LEN = info.len + GAP = ISN - (DSN + LEN) # gap length between payloads + self._buffer[BUFID][ACK]['isn'] = DSN + if GAP >= 0: # if fragment exceeds existing payload + RAW = info.payload + bytearray(GAP) + RAW + else: # if fragment partially overlaps existing payload + RAW = info.payload + RAW[ISN-GAP:] + self._buffer[BUFID][ACK]['raw'] = RAW # update payload datagram + self._buffer[BUFID][ACK]['len'] = len(RAW) # update payload length + + # update hole descriptor list + HDL = self._buffer[BUFID]['hdl'] + for (index, hole) in enumerate(HDL): # step one + if info.first > hole.last: # step two + continue + if info.last < hole.first: # step three + continue + del HDL[index] # step four + if info.first > hole.first: # step five + new_hole = Info( + first=hole.first, + last=info.first - 1, + ) + HDL.insert(index, new_hole) + index += 1 + if info.last < hole.last and not FIN and not RST: # step six + new_hole = Info( + first=info.last + 1, + last=hole.last + ) + HDL.insert(index, new_hole) + break # step seven + self._buffer[BUFID]['hdl'] = HDL # update HDL # when FIN/RST is set, submit buffer of this session if FIN or RST: diff --git a/src/utilities/exceptions.py b/src/utilities/exceptions.py index 6b4971812..4ce1b9c56 100644 --- a/src/utilities/exceptions.py +++ b/src/utilities/exceptions.py @@ -70,10 +70,9 @@ class BaseError(Exception): * In Python 2.7, `trace.print_stack(limit=None)` dose not support negative limit. """ - def __init__(self, *args, **kwargs): + def __init__(self, *args, quiet=False, **kwargs): if DEVMODE: index = stacklevel() - quiet = kwargs.pop('quiet', False) if not quiet and index: fmt_exc = traceback.format_exc(limit=-index) if len(fmt_exc.splitlines(True)) > 1: