hans-3.0.2: Network Stack

Safe HaskellNone
LanguageHaskell2010

Hans.Tcp.RecvWindow

Contents

Synopsis

Receive Window

data Window Source #

The receive window.

INVARIANTS:

  1. All segments in rwSegments are within the window defined by rwRcvNxt and rwRcvWnd
  2. 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).

rcvWnd :: Lens' Window Word16 Source #

The value of RCV.WND.

rcvNxt :: Getting r Window TcpSeqNum Source #

The left edge of the receive window.

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

sequenceNumberValid Source #

Arguments

:: 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:

  1. The sequence number is within the window
  2. The segment body falls within the window
  3. 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.