Commit 8dcb1a40 authored by StevenWdV's avatar StevenWdV

Fixed bug in __seq_between: 100 is now not between 42 and 42 anymore. Made...

Fixed bug in __seq_between: 100 is now not between 42 and 42 anymore. Made some more debugs warnings. Lowered default window size.
parent 8f51eb1a
......@@ -7,10 +7,10 @@ import sys
import btcp
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=100)
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=70)
parser.add_argument("-t", "--timeout", help="Define bTCP timeout in milliseconds", type=int, default=100)
parser.add_argument("-i", "--input", help="File to send", default="tmp.file")
args = parser.parse_args()
......
......@@ -7,11 +7,11 @@ import sys
import btcp
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
# Handle arguments
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=100)
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=70)
parser.add_argument("-t", "--timeout", help="Define bTCP timeout in milliseconds", type=int, default=100)
parser.add_argument("-o", "--output", help="Where to store file", default="tmp.file")
args = parser.parse_args()
......
......@@ -17,7 +17,7 @@ header_size = 16
payload_size = 1000
max_seq = 0xffFF
debug_window = True
debug_window = False
class _Flags:
......@@ -191,7 +191,7 @@ class _Stream:
nr %= max_seq
lower_bound %= max_seq
upper_bound %= max_seq
if lower_bound < upper_bound:
if lower_bound <= upper_bound:
return lower_bound <= nr <= upper_bound
else:
return nr >= lower_bound or nr <= upper_bound
......@@ -244,7 +244,7 @@ class _Stream:
continue
elif flags.syn:
if self.first_recv_syn_nr is not None and packet.header.syn_nr == self.first_recv_syn_nr:
logging.debug(self.deb + "Spurious SYN")
logging.warning(self.deb + "Spurious SYN")
continue
else:
logging.warning(self.deb + "Unexpected SYN")
......@@ -253,7 +253,7 @@ class _Stream:
if not self.__seq_between(packet.header.syn_nr, self.recv_ack_nr - self.local_window_size,
self.recv_ack_nr + self.local_window_size - 1):
logging.debug(self.deb + "SYN nr outside of window (spurious retransmission?)")
logging.warning(self.deb + "SYN nr outside of window (spurious retransmission?)")
continue
if self.__seq_between(packet.header.syn_nr, self.recv_ack_nr + 1,
......@@ -309,11 +309,11 @@ class _Stream:
if (insert_index < len(self.receive_ack_buffer)
and self.receive_ack_buffer[insert_index].header.syn_nr == packet.header.syn_nr):
assert self.receive_ack_buffer[insert_index].data == packet.data
logging.debug(self.deb + "Spurious retransmission")
logging.warning(self.deb + "Spurious retransmission of packet in window")
else:
self.receive_ack_buffer.insert(insert_index, packet)
else:
logging.debug(self.deb + "Spurious retransmission of packet before window")
logging.warning(self.deb + "Spurious retransmission of packet before window")
send_ack = True
......@@ -352,7 +352,7 @@ class _Stream:
# print(f"LOST: {', '.join([str(packet.header.syn_nr) for packet in lost])}")
# print(f"NOT LOST: {', '.join([str(packet.header.syn_nr) for packet in self.sent_ack_buffer])}")
if len(lost) > 0:
logging.debug(self.deb + f"{len(lost)} lost messages")
logging.warning(self.deb + f"{len(lost)} lost messages")
for p in lost:
p.timestamp = time.perf_counter()
self.__send_to_be_acked(p.data, p.header.syn_nr, p.header.flags_obj())
......@@ -444,7 +444,6 @@ class _Stream:
logging.debug(self.deb + "Waiting until sent_ack_buffer is empty")
self.all_acked_lock.acquire()
print(self.send_ack_nr, self.send_syn_nr)
self.all_acked.wait_for(lambda: self.send_ack_nr == self.send_syn_nr)
self.all_acked_lock.release()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment