Sponge
CS144's user-space TCP library
tcp_receiver.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_TCP_RECEIVER_HH
2 #define SPONGE_LIBSPONGE_TCP_RECEIVER_HH
3 
4 #include "byte_stream.hh"
5 #include "stream_reassembler.hh"
6 #include "tcp_segment.hh"
7 #include "wrapping_integers.hh"
8 
9 #include <optional>
10 
12 
16 class TCPReceiver {
19 
21  size_t _capacity;
22 
23  public:
28  TCPReceiver(const size_t capacity) : _reassembler(capacity), _capacity(capacity) {}
29 
32 
38  std::optional<WrappingInt32> ackno() const;
39 
50  size_t window_size() const;
52 
54  size_t unassembled_bytes() const { return _reassembler.unassembled_bytes(); }
55 
57  void segment_received(const TCPSegment &seg);
58 
62  const ByteStream &stream_out() const { return _reassembler.stream_out(); }
64 };
65 
66 #endif // SPONGE_LIBSPONGE_TCP_RECEIVER_HH
TCPReceiver::unassembled_bytes
size_t unassembled_bytes() const
number of bytes stored but not yet reassembled
Definition: tcp_receiver.hh:54
tcp_segment.hh
TCPReceiver::ackno
std::optional< WrappingInt32 > ackno() const
The ackno that should be sent to the peer.
Definition: tcp_receiver.cc:17
byte_stream.hh
ByteStream
An in-order byte stream.
Definition: byte_stream.hh:11
TCPReceiver
The "receiver" part of a TCP implementation.
Definition: tcp_receiver.hh:16
TCPReceiver::segment_received
void segment_received(const TCPSegment &seg)
handle an inbound segment
Definition: tcp_receiver.cc:13
wrapping_integers.hh
StreamReassembler::stream_out
const ByteStream & stream_out() const
Definition: stream_reassembler.hh:36
TCPReceiver::_reassembler
StreamReassembler _reassembler
Our data structure for re-assembling bytes.
Definition: tcp_receiver.hh:18
StreamReassembler
A class that assembles a series of excerpts from a byte stream (possibly out of order,...
Definition: stream_reassembler.hh:11
StreamReassembler::unassembled_bytes
size_t unassembled_bytes() const
Definition: stream_reassembler.cc:24
stream_reassembler.hh
TCPReceiver::stream_out
const ByteStream & stream_out() const
Definition: tcp_receiver.hh:62
TCPReceiver::TCPReceiver
TCPReceiver(const size_t capacity)
Construct a TCP receiver.
Definition: tcp_receiver.hh:28
TCPReceiver::window_size
size_t window_size() const
The window size that should be sent to the peer.
Definition: tcp_receiver.cc:19
TCPReceiver::stream_out
ByteStream & stream_out()
Definition: tcp_receiver.hh:61
TCPReceiver::_capacity
size_t _capacity
The maximum number of bytes we'll store.
Definition: tcp_receiver.hh:21
TCPSegment
TCP segment
Definition: tcp_segment.hh:10