Let's say the sender and the receiver got a 16 size buffer with a 7 size window.
In other words, each side has a buffer, an array, where they can store 16 frames. Each frame has an id that fits in the 16 frames buffer (index in the array). The receiver got a window that only allow 7 frames in any order to be accepted at any given time. The window will slide by one when it got the oldest frame in the buffer filled.
My problem now is, let's say if a frame get lost on the way, but somehow make it back way too late. The receiver got it so late it actually fills the next circle of the frame's buffer.
- The sender send the frames: 0, 1, 2, 3, 4, 5, 6, 7.
- The receiver gets the frames and sends an ACK back for having got all up to 7 (or for each one).
- The sender gets a timeout on frame 0, and re-sends it.
- The sender gets ACK on all up to 7, so it sends the next frames: 8, 9, 10, 11, 12, 13, 14
- The receiver gets the following packets: 8, 9, 10, 11, 12, 13, 14. It sends an ACK for having got them and open ups the buffer for: 15, 0, 1, 2, 3, 4, 5, 6.
- The receiver gets the old frame 0 that was sent by the sender due to a timeout. The receiver think the packet is legit and stores it.
How to avoid what happened at step 6? Should I send a CRC of the entire window? CRC is not perfect, so there may still be issues.
I'm currently doing this over an UDP socket in C, hence the C tag.