Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Window
- emptyWindow :: TcpSeqNum -> Int -> Window
- recvSegment :: TcpHeader -> ByteString -> Window -> (Window, Maybe [(TcpHeader, ByteString)])
- rcvWnd :: Lens' Window Word16
- rcvNxt :: Getting r Window TcpSeqNum
- setRcvNxt :: TcpSeqNum -> Window -> (Window, Bool)
- rcvRight :: Getting r Window TcpSeqNum
- moveRcvRight :: Int -> Window -> (Window, ())
- sequenceNumberValid :: TcpSeqNum -> TcpSeqNum -> TcpHeader -> ByteString -> Maybe Segment
Receive Window
The receive window.
INVARIANTS:
- All segments in rwSegments are within the window defined by rwRcvNxt and rwRcvWnd
- The segments in rwSegments should not overlap
recvSegment :: TcpHeader -> ByteString -> Window -> (Window, Maybe [(TcpHeader, ByteString)]) Source #
Check an incoming segment, and queue it in the receive window. When the
segment received was valid Just
is returned, including segments in the
receive window were unblocked by it.
NOTE: when Just[] is returned, this should be a signal to issue a duplicate ACK, as we've receive something out of sequence (fast retransmit).
setRcvNxt :: TcpSeqNum -> Window -> (Window, Bool) Source #
Only sets RCV.NXT when the segment queue is empty. Returns True
when the
value has been successfully changed.
rcvRight :: Getting r Window TcpSeqNum Source #
The right edge of the receive window, RCV.NXT + RCV.WND.
moveRcvRight :: Int -> Window -> (Window, ()) Source #
Increase the right edge of the window by n, clamping at the maximum window size.
Sequence Numbers
:: TcpSeqNum | RCV.NXT |
-> TcpSeqNum | RCV.NXT + RCV.WND |
-> TcpHeader | |
-> ByteString | |
-> Maybe Segment |
This is the check described on page 68 of RFC793, which checks that data falls within the expected receive window. When the check is successful, the segment returned is one that has been trimmed to fit in the window (if necessary).
When this produces a segment, the segment has these properties:
- The sequence number is within the window
- The segment body falls within the window
- The segment has been copied from the original bytestring
The reason for point 3 is that when frames are allocated by devices, they are likely allocated to the full MTU, and not resized. Copying here frees up some memory.