Sponge
CS144's user-space TCP library
Public Member Functions | Private Attributes | List of all members
TCPReceiver Class Reference

The "receiver" part of a TCP implementation. More...

#include <tcp_receiver.hh>

Public Member Functions

 TCPReceiver (const size_t capacity)
 Construct a TCP receiver. More...
 
void segment_received (const TCPSegment &seg)
 handle an inbound segment More...
 
size_t unassembled_bytes () const
 number of bytes stored but not yet reassembled More...
 
Accessors to provide feedback to the remote TCPSender
std::optional< WrappingInt32ackno () const
 The ackno that should be sent to the peer. More...
 
size_t window_size () const
 The window size that should be sent to the peer. More...
 
"Output" interface for the reader
ByteStreamstream_out ()
 
const ByteStreamstream_out () const
 

Private Attributes

size_t _capacity
 The maximum number of bytes we'll store. More...
 
StreamReassembler _reassembler
 Our data structure for re-assembling bytes. More...
 

Detailed Description

The "receiver" part of a TCP implementation.

Receives and reassembles segments into a ByteStream, and computes the acknowledgment number and window size to advertise back to the remote TCPSender.

Definition at line 16 of file tcp_receiver.hh.

Constructor & Destructor Documentation

◆ TCPReceiver()

TCPReceiver::TCPReceiver ( const size_t  capacity)
inline

Construct a TCP receiver.

Parameters
capacitythe maximum number of bytes that the receiver will store in its buffers at any give time.

Definition at line 28 of file tcp_receiver.hh.

Member Function Documentation

◆ ackno()

optional< WrappingInt32 > TCPReceiver::ackno ( ) const

The ackno that should be sent to the peer.

Returns
empty if no SYN has been received

This is the beginning of the receiver's window, or in other words, the sequence number of the first byte in the stream that the receiver hasn't received.

Definition at line 17 of file tcp_receiver.cc.

◆ segment_received()

void TCPReceiver::segment_received ( const TCPSegment seg)

handle an inbound segment

Definition at line 13 of file tcp_receiver.cc.

◆ stream_out() [1/2]

ByteStream& TCPReceiver::stream_out ( )
inline

Definition at line 61 of file tcp_receiver.hh.

◆ stream_out() [2/2]

const ByteStream& TCPReceiver::stream_out ( ) const
inline

Definition at line 62 of file tcp_receiver.hh.

◆ unassembled_bytes()

size_t TCPReceiver::unassembled_bytes ( ) const
inline

number of bytes stored but not yet reassembled

Definition at line 54 of file tcp_receiver.hh.

◆ window_size()

size_t TCPReceiver::window_size ( ) const

The window size that should be sent to the peer.

Operationally: the capacity minus the number of bytes that the TCPReceiver is holding in its byte stream (those that have been reassembled, but not consumed).

Formally: the difference between (a) the sequence number of the first byte that falls after the window (and will not be accepted by the receiver) and (b) the sequence number of the beginning of the window (the ackno).

Definition at line 19 of file tcp_receiver.cc.

Member Data Documentation

◆ _capacity

size_t TCPReceiver::_capacity
private

The maximum number of bytes we'll store.

Definition at line 21 of file tcp_receiver.hh.

◆ _reassembler

StreamReassembler TCPReceiver::_reassembler
private

Our data structure for re-assembling bytes.

Definition at line 18 of file tcp_receiver.hh.


The documentation for this class was generated from the following files: