Sponge
CS144's user-space TCP library
|
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< WrappingInt32 > | ackno () 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 | |
ByteStream & | stream_out () |
const ByteStream & | stream_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... | |
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.
|
inline |
Construct a TCP receiver.
capacity | the 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.
optional< WrappingInt32 > TCPReceiver::ackno | ( | ) | const |
The ackno that should be sent to the peer.
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.
void TCPReceiver::segment_received | ( | const TCPSegment & | seg | ) |
handle an inbound segment
Definition at line 13 of file tcp_receiver.cc.
|
inline |
Definition at line 61 of file tcp_receiver.hh.
|
inline |
Definition at line 62 of file tcp_receiver.hh.
|
inline |
number of bytes stored but not yet reassembled
Definition at line 54 of file tcp_receiver.hh.
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.
|
private |
The maximum number of bytes we'll store.
Definition at line 21 of file tcp_receiver.hh.
|
private |
Our data structure for re-assembling bytes.
Definition at line 18 of file tcp_receiver.hh.