Sponge
CS144's user-space TCP library
tcp_connection.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_TCP_FACTORED_HH
2 #define SPONGE_LIBSPONGE_TCP_FACTORED_HH
3 
4 #include "tcp_config.hh"
5 #include "tcp_receiver.hh"
6 #include "tcp_sender.hh"
7 #include "tcp_state.hh"
8 
11  private:
15 
18 
23 
24  public:
27 
29  void connect();
30 
33  size_t write(const std::string &data);
34 
36  size_t remaining_outbound_capacity() const;
37 
39  void end_input_stream();
41 
44 
48 
50 
53  size_t bytes_in_flight() const;
55  size_t unassembled_bytes() const;
57  size_t time_since_last_segment_received() const;
61 
64 
66  void segment_received(const TCPSegment &seg);
67 
69  void tick(const size_t ms_since_last_tick);
70 
76 
80  bool active() const;
82 
84  explicit TCPConnection(const TCPConfig &cfg) : _cfg{cfg} {}
85 
88 
90  ~TCPConnection();
91  TCPConnection() = delete;
92  TCPConnection(TCPConnection &&other) = default;
93  TCPConnection &operator=(TCPConnection &&other) = default;
94  TCPConnection(const TCPConnection &other) = delete;
95  TCPConnection &operator=(const TCPConnection &other) = delete;
97 };
98 
99 #endif // SPONGE_LIBSPONGE_TCP_FACTORED_HH
TCPConnection::connect
void connect()
Initiate a connection by sending a SYN segment.
Definition: tcp_connection.cc:37
tcp_state.hh
TCPConnection::unassembled_bytes
size_t unassembled_bytes() const
number of bytes not yet reassembled
Definition: tcp_connection.cc:19
TCPConnection::time_since_last_segment_received
size_t time_since_last_segment_received() const
Number of milliseconds since the last segment was received.
Definition: tcp_connection.cc:21
std::string
tcp_receiver.hh
TCPConnection::segments_out
std::queue< TCPSegment > & segments_out()
TCPSegments that the TCPConnection has enqueued for transmission.
Definition: tcp_connection.hh:75
TCPConnection::TCPConnection
TCPConnection()=delete
TCPConnection
A complete endpoint of a TCP connection.
Definition: tcp_connection.hh:10
TCPConnection::inbound_stream
ByteStream & inbound_stream()
The inbound byte stream received from the peer.
Definition: tcp_connection.hh:46
TCPSender
The "sender" part of a TCP implementation.
Definition: tcp_sender.hh:18
std::queue< TCPSegment >
tcp_sender.hh
TCPConnection::end_input_stream
void end_input_stream()
Shut down the outbound byte stream (still allows reading incoming data)
Definition: tcp_connection.cc:35
TCPConnection::remaining_outbound_capacity
size_t remaining_outbound_capacity() const
Definition: tcp_connection.cc:15
TCPConnection::bytes_in_flight
size_t bytes_in_flight() const
number of bytes sent and not yet acknowledged, counting SYN/FIN each as one byte
Definition: tcp_connection.cc:17
TCPConnection::active
bool active() const
Is the connection still alive in any way?
Definition: tcp_connection.cc:25
ByteStream
An in-order byte stream.
Definition: byte_stream.hh:11
tcp_config.hh
TCPConnection::segment_received
void segment_received(const TCPSegment &seg)
Called when a new segment has been received from the network.
Definition: tcp_connection.cc:23
TCPConfig::send_capacity
size_t send_capacity
Sender capacity, in bytes.
Definition: tcp_config.hh:21
TCPReceiver
The "receiver" part of a TCP implementation.
Definition: tcp_receiver.hh:16
TCPConnection::_sender
TCPSender _sender
Definition: tcp_connection.hh:14
TCPState
Summary of a TCPConnection's internal state.
Definition: tcp_state.hh:23
TCPConfig::rt_timeout
uint16_t rt_timeout
Initial value of the retransmission timeout, in milliseconds.
Definition: tcp_config.hh:19
TCPConnection::operator=
TCPConnection & operator=(TCPConnection &&other)=default
TCPConnection::~TCPConnection
~TCPConnection()
destructor sends a RST if the connection is still open
Definition: tcp_connection.cc:39
TCPConfig
Config for TCP sender and receiver.
Definition: tcp_config.hh:12
TCPConnection::_receiver
TCPReceiver _receiver
Definition: tcp_connection.hh:13
TCPConfig::recv_capacity
size_t recv_capacity
Receive capacity, in bytes.
Definition: tcp_config.hh:20
TCPConnection::TCPConnection
TCPConnection(const TCPConfig &cfg)
Construct a new connection from a configuration.
Definition: tcp_connection.hh:84
TCPConnection::state
TCPState state() const
Definition: tcp_connection.hh:59
TCPConnection::write
size_t write(const std::string &data)
Write data to the outbound byte stream, and send it over TCP if possible.
Definition: tcp_connection.cc:27
TCPConnection::tick
void tick(const size_t ms_since_last_tick)
Called periodically when time elapses.
Definition: tcp_connection.cc:33
TCPConnection::_linger_after_streams_finish
bool _linger_after_streams_finish
Definition: tcp_connection.hh:22
TCPReceiver::stream_out
ByteStream & stream_out()
Definition: tcp_receiver.hh:61
TCPConfig::fixed_isn
std::optional< WrappingInt32 > fixed_isn
Definition: tcp_config.hh:22
TCPConnection::_cfg
TCPConfig _cfg
Definition: tcp_connection.hh:12
TCPSegment
TCP segment
Definition: tcp_segment.hh:10
TCPConnection::_segments_out
std::queue< TCPSegment > _segments_out
outbound queue of segments that the TCPConnection wants sent
Definition: tcp_connection.hh:17