Skip to content
Snippets Groups Projects
Commit c3e91066 authored by Josep Marcello's avatar Josep Marcello :disappointed_relieved:
Browse files

fix: benerin go_back_n

parent a44573f2
No related merge requests found
......@@ -6,7 +6,8 @@ class FLAGS:
ACK = 0b0001_0000
WINDOWS_SIZE = 16
SERVER_TIMEOUT = CLIENT_TIMEOUT = 5
CLIENT_TIMEOUT = 5
SERVER_TIMEOUT = CLIENT_TIMEOUT / 2
HEADER_SIZE = 12 # bytes
MAX_PAYLOAD_SIZE = 32768 # bytes
......
......@@ -21,6 +21,7 @@ def send_handler(
sequence_base = 0
sequence_max = WINDOWS_SIZE + 1
ack_number = -1
go_back = False
def update_ack():
nonlocal ack_number
......@@ -41,10 +42,8 @@ def send_handler(
# terima ACK
update_ack()
can_send = sequence_base <= sequence_current <= sequence_max
can_send = sequence_base <= sequence_current < sequence_max
init_time = perf_counter()
i = 0
max_try = 3
while not can_send:
# Nunggu dapet ACK sampe timeout
# Kalo timeout belom go_back_n
......@@ -54,16 +53,17 @@ def send_handler(
update_ack()
# Tandai request udah di-consume
event.clear()
can_send = sequence_base <= sequence_current <= sequence_max
can_send = sequence_base <= sequence_current < sequence_max
# masih ga bisa ngirim dan waktu habis
if not can_send and perf_counter() - init_time >= SERVER_TIMEOUT:
if i >= max_try:
print(f'Connection with client {client[0]}:{client[1]} has timed out after {max_try} tries. Giving up.')
return
packets.go_back_n(WINDOWS_SIZE + 1)
go_back = True
break
packets.go_back_n(WINDOWS_SIZE)
i += 1
if go_back:
go_back = False
continue
print(f'Sending packet {sequence_current} to {client[0]}:{client[1]}')
sock.sendto(packet, client)
......
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