Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make send() more robust by handling previous ACK #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/tftp/tftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ def send(tag, sock, io)
log :warn, "#{tag} Timeout at block ##{seq}"
return
end
msg, _ = sock.recvfrom(4, 0)
pkt = Packet.parse(msg)
if pkt.class != Packet::ACK
log :warn, "#{tag} Expected ACK but got: #{pkt.class}"
return
end
if pkt.seq != seq
log :warn, "#{tag} Seq mismatch: #{seq} != #{pkt.seq}"
return
loop do
msg, _ = sock.recvfrom(4, 0)
pkt = Packet.parse(msg)
if pkt.class != Packet::ACK
log :warn, "#{tag} Expected ACK but got: #{pkt.class}"
return
end
break if pkt.seq == seq
if pkt.seq > seq
log :warn, "#{tag} Seq mismatch: #{seq} != #{pkt.seq}"
return
end
end
# Increment with wrap around at 16 bit boundary,
# because of tftp block number field size limit.
Expand Down