25#include "flow/error/error.hpp"
35#include <boost/utility.hpp>
36#include <boost/shared_ptr.hpp>
37#include <boost/enable_shared_from_this.hpp>
38#include <boost/move/unique_ptr.hpp>
220 public boost::enable_shared_from_this<Peer_socket>,
222 private boost::noncopyable
406 template<
typename Const_buffer_sequence>
407 size_t send(
const Const_buffer_sequence& data,
Error_code* err_code = 0);
456 template<
typename Rep,
typename Period,
typename Const_buffer_sequence>
457 size_t sync_send(
const Const_buffer_sequence& data,
458 const boost::chrono::duration<Rep, Period>& max_wait,
Error_code* err_code = 0);
495 template<
typename Rep,
typename Period>
496 bool sync_send(
const boost::asio::null_buffers&,
497 const boost::chrono::duration<Rep, Period>& max_wait,
Error_code* err_code = 0);
510 template<
typename Const_buffer_sequence>
576 template<
typename Mutable_buffer_sequence>
625 template<
typename Rep,
typename Period,
typename Mutable_buffer_sequence>
626 size_t sync_receive(
const Mutable_buffer_sequence& target,
627 const boost::chrono::duration<Rep, Period>& max_wait,
Error_code* err_code = 0);
664 template<
typename Rep,
typename Period>
666 const boost::chrono::duration<Rep, Period>& max_wait,
Error_code* err_code = 0);
680 template<
typename Mutable_buffer_sequence>
965 using Recvd_pkt_map = std::map<Sequence_number, boost::shared_ptr<Received_packet>>;
998 size_t node_send(
const Function<
size_t (
size_t max_data_size)>& snd_buf_feed_func,
1016 template<
typename Const_buffer_sequence>
1076 template<
typename Mutable_buffer_sequence>
1119 template<
typename Opt_type>
1120 Opt_type
opt(
const Opt_type& opt_val_ref)
const;
1139 const unsigned int* inflate_pct_val_ptr = 0)
const;
2180 private boost::noncopyable
2340 private boost::noncopyable
2388 using Ptr = boost::shared_ptr<Individual_ack>;
2447template<
typename Const_buffer_sequence>
2450 namespace bind_ns = util::bind_ns;
2451 using bind_ns::bind;
2478 const auto snd_buf_feed_func = [
this, &data](
size_t max_data_size)
2487 return node_send(snd_buf_feed_func, err_code);
2490template<
typename Const_buffer_sequence>
2496template<
typename Rep,
typename Period,
typename Const_buffer_sequence>
2498 const boost::chrono::duration<Rep, Period>& max_wait,
2501 assert(max_wait.count() > 0);
2507template<
typename Rep,
typename Period>
2509 const boost::chrono::duration<Rep, Period>& max_wait,
2512 assert(max_wait.count() > 0);
2517template<
typename Const_buffer_sequence>
2521 namespace bind_ns = util::bind_ns;
2522 using bind_ns::bind;
2525 bind_ns::cref(data), bind_ns::cref(wait_until), _1);
2538 const auto snd_buf_feed_func = [
this, &data](
size_t max_data_size)
2551template<
typename Mutable_buffer_sequence>
2554 namespace bind_ns = util::bind_ns;
2555 using bind_ns::bind;
2570 const auto rcv_buf_consume_func = [
this, &target]()
2584template<
typename Mutable_buffer_sequence>
2590template<
typename Rep,
typename Period,
typename Mutable_buffer_sequence>
2592 const boost::chrono::duration<Rep, Period>& max_wait,
Error_code* err_code)
2594 assert(max_wait.count() > 0);
2600template<
typename Rep,
typename Period>
2602 const boost::chrono::duration<Rep, Period>& max_wait,
2605 assert(max_wait.count() > 0);
2609template<
typename Mutable_buffer_sequence>
2613 namespace bind_ns = util::bind_ns;
2614 using bind_ns::bind;
2617 bind_ns::cref(target), bind_ns::cref(wait_until), _1);
2630 const auto rcv_buf_consume_func = [
this, &target]()
2643template<
typename Opt_type>
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns...
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
Utility class for use by Congestion_control_strategy implementations that implements congestion windo...
Classic congestion control but with backoff to bandwidth estimate-based pipe size.
Classic congestion control, based on Reno (TCP RFC 5681), with congestion avoidance,...
Internal net_flow class that maintains the Drop Timer for DATA packet(s) to have been sent out over a...
An object of this class is a single Flow-protocol networking node, in the sense that: (1) it has a di...
A class that keeps a Peer_socket_receive_stats data store, includes methods to conveniently accumulat...
A class that keeps a Peer_socket_send_stats data store, includes methods to conveniently accumulate d...
A peer (non-server) socket operating over the Flow network protocol, with optional stream-of-bytes an...
Drop_timer_ptr m_snd_drop_timer
The Drop Timer engine, which controls how In-flight (m_snd_flying_pkts_by_sent_when) packets are cons...
friend std::ostream & operator<<(std::ostream &os, Int_state state)
State m_state
See state().
size_t m_snd_pending_rcv_wnd
While Node::low_lvl_recv_and_handle() or async part of Node::async_wait_latency_then_handle_incoming(...
size_t get_connect_metadata(const boost::asio::mutable_buffer &buffer, Error_code *err_code=0) const
Obtains the serialized connect metadata, as supplied by the user during the connection handshake.
unsigned int m_init_rexmit_count
If currently using m_init_rexmit_scheduled_task, this is the number of times the timer has already fi...
size_t max_block_size_multiple(const size_t &opt_val_ref, const unsigned int *inflate_pct_val_ptr=0) const
Returns the smallest multiple of max_block_size() that is >= the given option value,...
size_t m_snd_remote_rcv_wnd
The receive window: the maximum number of bytes the other side has advertised it would be willing to ...
Sequence_number m_rcv_next_seq_num
The maximal sequence number R from the remote side such that all data with sequence numbers strictly ...
size_t m_rcv_syn_rcvd_data_cumulative_size
The running total count of bytes in the m_data fields of m_rcv_syn_rcvd_data_q.
bool sync_send_reactor_pattern_impl(const Fine_time_pt &wait_until, Error_code *err_code)
Helper similar to sync_send_impl() but for the null_buffers versions of sync_send().
std::vector< boost::shared_ptr< Data_packet > > Rcv_syn_rcvd_data_q
Type used for m_rcv_syn_rcvd_data_q.
std::map< Sequence_number, Sent_pkt_ordered_by_when_iter > Sent_pkt_by_seq_num_map
Short-hand for m_snd_flying_pkts_by_seq_num type; see that data member.
bool sync_receive_reactor_pattern_impl(const Fine_time_pt &wait_until, Error_code *err_code)
Helper similar to sync_receive_impl() but for the null_buffers versions of sync_receive().
util::Mutex_non_recursive Options_mutex
Short-hand for high-performance, non-reentrant, exclusive mutex used to lock m_opts.
order_num_t m_snd_last_order_num
For the Sent_packet representing the next packet to be sent, this is the value to assign to m_sent_wh...
Sequence_number m_snd_next_seq_num
The sequence number for the start of the data in the next new DATA packet to be sent out.
Remote_endpoint m_remote_endpoint
See remote_endpoint(). Should be set before user gets access to *this and not changed afterwards.
size_t sync_receive(const Mutable_buffer_sequence &target, const boost::chrono::duration< Rep, Period > &max_wait, Error_code *err_code=0)
Blocking (synchronous) version of receive().
Fine_duration m_round_trip_time_variance
RTTVAR used for m_snd_smoothed_round_trip_time calculation.
bool m_active_connect
true if we connect() to server; false if we are to be/are accept()ed. Should be set once and not modi...
Int_state m_int_state
Current internal state of the socket.
Fine_duration m_snd_drop_timeout
The Drop Timeout: Time period between the next time m_snd_drop_timer schedules a Drop Timer and that ...
Sent_pkt_by_seq_num_map m_snd_flying_pkts_by_seq_num
The collection of all In-flight packets (including those queued up to send in pacing module),...
boost::movelib::unique_ptr< Send_bandwidth_estimator > m_snd_bandwidth_estimator
The outgoing available bandwidth estimator for this connection on this side.
util::Blob m_serialized_metadata
If !m_active_connect, this contains the serialized metadata that the user supplied on the other side ...
security_token_t m_security_token
Random security token used during SYN_ACK-SYN_ACK_ACK.
size_t node_sync_send(const Function< size_t(size_t max_data_size)> &snd_buf_feed_func_or_empty, const Fine_time_pt &wait_until, Error_code *err_code)
This is to sync_send() as node_send() is to send().
boost::movelib::unique_ptr< Congestion_control_strategy > m_snd_cong_ctl
The congestion control strategy in use for this connection on this side.
size_t sync_send_impl(const Const_buffer_sequence &data, const Fine_time_pt &wait_until, Error_code *err_code)
Same as sync_send() but uses a Fine_clock-based Fine_duration non-template type for implementation co...
Rcv_syn_rcvd_data_q m_rcv_syn_rcvd_data_q
The queue of DATA packets received while in Int_state::S_SYN_RCVD state before the Syn_ack_ack_packet...
Error_code m_disconnect_cause
The Error_code causing disconnection (if one has occurred or is occurring) on this socket; otherwise ...
Peer_socket(log::Logger *logger_ptr, util::Task_engine *task_engine, const Peer_socket_options &opts)
Constructs object; initializes most values to well-defined (0, empty, etc.) but not necessarily meani...
Fine_time_pt m_rcv_wnd_recovery_start_time
Time point at which m_rcv_in_rcv_wnd_recovery was last set to true.
Send_pacing_data m_snd_pacing_data
The state of outgoing packet pacing for this socket; segregated into a simple struct to keep Peer_soc...
Server_socket::Ptr m_originating_serv
For sockets that come a Server_socket, this is the inverse of Server_socket::m_connecting_socks: it i...
uint64_t security_token_t
Type used for m_security_token.
Sequence_number m_rcv_init_seq_num
The Initial Sequence Number (ISN) contained in the original Syn_packet or Syn_ack_packet we received.
const Remote_endpoint & remote_endpoint() const
Intended other side of the connection (regardless of success, failure, or current State).
Sent_pkt_by_sent_when_map m_snd_flying_pkts_by_sent_when
The collection of all In-flight packets, indexed by sequence number and ordered from most to least re...
State
State of a Peer_socket.
Open_sub_state
The sub-state of a Peer_socket when state is State::S_OPEN.
size_t sync_send(const Const_buffer_sequence &data, const boost::chrono::duration< Rep, Period > &max_wait, Error_code *err_code=0)
Blocking (synchronous) version of send().
~Peer_socket() override
Boring virtual destructor. Note that deletion is to be handled exclusively via shared_ptr,...
Error_code disconnect_cause() const
The error code that perviously caused state() to become State::S_CLOSED, or success code if state is ...
size_t m_rcv_pending_acks_size_at_recv_handler_start
Helper state, to be used while inside either Node::low_lvl_recv_and_handle() or async part of Node::a...
Sequence_number::seq_num_t order_num_t
Short-hand for order number type. 0 is reserved. Caution: Keep in sync with Drop_timer::packet_id_t.
flow_port_t local_port() const
The local Flow-protocol port chosen by the Node (if active or passive open) or user (if passive open)...
flow_port_t m_local_port
See local_port(). Should be set before user gets access to *this and not changed afterwards.
Peer_socket_receive_stats_accumulator m_rcv_stats
Stats regarding incoming traffic (and resulting outgoing ACKs) for this connection so far.
bool set_options(const Peer_socket_options &opts, Error_code *err_code=0)
Dynamically replaces the current options set (options()) with the given options set.
size_t m_rcv_last_sent_rcv_wnd
The last rcv_wnd value sent to the other side (in an ACK).
std::vector< Ack_packet::Individual_ack::Ptr > m_rcv_acked_packets
While Node::low_lvl_recv_and_handle() or async part of Node::async_wait_latency_then_handle_incoming(...
size_t node_send(const Function< size_t(size_t max_data_size)> &snd_buf_feed_func, Error_code *err_code)
Non-template helper for template send() that forwards the send() logic to Node::send().
std::list< boost::shared_ptr< Sent_packet > > m_snd_rexmit_q
If retransmission is on, this is the retransmission queue.
util::Scheduled_task_handle m_init_rexmit_scheduled_task
Connection attempt scheduled task; fires if an individual connection request packet is not answered w...
util::Timer m_rcv_delayed_ack_timer
Timer started, assuming delayed ACKs are enabled, when the first Individual_ack is placed onto an emp...
bool rexmit_on() const
Whether retransmission is enabled on this connection.
size_t node_sync_receive(const Function< size_t()> &rcv_buf_consume_func_or_empty, const Fine_time_pt &wait_until, Error_code *err_code)
This is to sync_receive() as node_receive() is to receive().
util::Lock_guard< Mutex > Lock_guard
Short-hand for RAII lock guard of Mutex.
Sent_pkt_by_seq_num_map::iterator Sent_pkt_ordered_by_seq_iter
Short-hand for m_snd_flying_pkts_by_seq_num iterator type.
Int_state
The state of the socket (and the connection from this end's point of view) for the internal state mac...
util::Lock_guard< Options_mutex > Options_lock
Short-hand for lock that acquires exclusive access to an Options_mutex.
Socket_buffer m_snd_buf
The Send buffer; user feeds data at the back; Node consumes data at the front.
void close_abruptly(Error_code *err_code=0)
Acts as if fatal error error::Code::S_USER_CLOSED_ABRUPTLY has been discovered on the connection.
size_t m_snd_rexmit_q_size
Equals m_snd_rexmit_q.size(). Kept since m_snd_rexmit_q.size() may be O(n) depending on implementatio...
size_t max_block_size() const
The maximum number of bytes of user data per received or sent packet on this connection.
size_t m_rcv_reassembly_q_data_size
With retransmission enabled, the sum of Received_packet::m_size over all packets stored in the reasse...
Node * node() const
Node that produced this Peer_socket.
Fine_time_pt m_snd_last_loss_event_when
The last time that Node has detected a packet loss event and so informed m_snd_cong_ctl by calling th...
Peer_socket_info info() const
Returns a structure containing the most up-to-date stats about this connection.
Socket_buffer m_rcv_buf
The Receive buffer; Node feeds data at the back; user consumes data at the front.
Recvd_pkt_map::iterator Recvd_pkt_iter
Short-hand for m_rcv_packets_with_gaps iterator type.
Mutex m_mutex
This object's mutex.
Peer_socket_send_stats_accumulator m_snd_stats
Stats regarding outgoing traffic (and resulting incoming ACKs) for this connection so far.
Sent_pkt_by_sent_when_map::iterator Sent_pkt_ordered_by_when_iter
Short-hand for m_snd_flying_pkts_by_sent_when iterator type.
Sent_pkt_by_seq_num_map::const_iterator Sent_pkt_ordered_by_seq_const_iter
Short-hand for m_snd_flying_pkts_by_seq_num const iterator type.
Peer_socket_info m_info_on_close
This is the final set of stats collected at the time the socket was moved to S_CLOSED m_state.
bool ensure_open(Error_code *err_code) const
Helper that is equivalent to Node::ensure_sock_open(this, err_code).
Sent_pkt_by_sent_when_map::const_iterator Sent_pkt_ordered_by_when_const_iter
Short-hand for m_snd_flying_pkts_by_sent_when const iterator type.
Sequence_number m_snd_init_seq_num
The Initial Sequence Number (ISN) used in our original SYN or SYN_ACK.
Opt_type opt(const Opt_type &opt_val_ref) const
Analogous to Node::opt() but for per-socket options.
std::string bytes_blocks_str(size_t bytes) const
Helper that, given a byte count, returns a string with that byte count and the number of max_block_si...
Fine_duration m_snd_smoothed_round_trip_time
Estimated current round trip time of packets, computed as a smooth value over the past individual RTT...
util::Mutex_recursive Mutex
Short-hand for reentrant mutex type.
size_t sync_receive_impl(const Mutable_buffer_sequence &target, const Fine_time_pt &wait_until, Error_code *err_code)
Same as sync_receive() but uses a Fine_clock-based Fine_duration non-template type for implementation...
std::vector< boost::shared_ptr< Individual_ack > > m_rcv_pending_acks
The received packets to be acknowledged in the next low-level ACK packet to be sent to the other side...
Peer_socket_options m_opts
This socket's per-socket set of options.
bool m_rcv_in_rcv_wnd_recovery
true indicates we are in a state where we've decided other side needs to be informed that our receive...
util::Scheduled_task_handle m_connection_timeout_scheduled_task
Connection timeout scheduled task; fires if the entire initial connection process does not complete w...
Peer_socket_options options() const
Copies this socket's option set and returns that copy.
Options_mutex m_opts_mutex
The mutex protecting m_opts.
std::map< Sequence_number, boost::shared_ptr< Received_packet > > Recvd_pkt_map
Short-hand for m_rcv_packets_with_gaps type; see that data member.
Recvd_pkt_map::const_iterator Recvd_pkt_const_iter
Short-hand for m_rcv_packets_with_gaps const iterator type.
Open_sub_state m_open_sub_state
See state().
boost::shared_ptr< Drop_timer > Drop_timer_ptr
Short-hand for shared_ptr to immutable Drop_timer (can't use Drop_timer::Ptr due to C++ and circular ...
Recvd_pkt_map m_rcv_packets_with_gaps
The sequence-number-ordered collection of all received-and-not-dropped-due-to-buffer-overflow packets...
size_t m_snd_flying_bytes
The number of bytes contained in all In-flight packets, used at least for comparison against the cong...
std::vector< order_num_t > m_snd_temp_pkts_marked_to_drop
Helper data structure to store the packet IDs of packets that are marked Dropped during a single run ...
size_t receive(const Mutable_buffer_sequence &target, Error_code *err_code=0)
Receives (consumes from the Receive buffer) bytes of data, up to a given maximum cumulative number of...
Fine_time_pt m_snd_last_data_sent_when
Time at which the last Data_packet low-level packet for this connection was sent.
size_t node_receive(const Function< size_t()> &rcv_buf_consume_func, Error_code *err_code)
Non-template helper for template receive() that forwards the receive() logic to Node::receive().
size_t send(const Const_buffer_sequence &data, Error_code *err_code=0)
Sends (adds to the Send buffer) the given bytes of data up to a maximum internal buffer size; and asy...
State state(Open_sub_state *open_sub_state=0) const
Current State of the socket.
util::Scheduled_task_handle m_rcv_wnd_recovery_scheduled_task
When m_rcv_in_rcv_wnd_recovery is true, this is the scheduled task to possibly send another unsolicit...
A per-Peer_socket module that tries to estimate the bandwidth available to the outgoing flow.
An internal net_flow sequence number identifying a piece of data.
uint64_t seq_num_t
Raw sequence number type.
A server socket able to listen on a single Flow port for incoming connections and return peer sockets...
Internal net_flow class that implements a socket buffer, as used by Peer_socket for Send and Receive ...
size_t feed_bufs_copy(const Const_buffer_sequence &data, size_t max_data_size)
Feeds (adds to the back of the byte buffer) the contents of the byte stream composed of the bytes in ...
size_t consume_bufs_copy(const Mutable_buffer_sequence &target_bufs)
Consumes (removes from the front of the internal byte buffer and returns them to the caller) a byte s...
Iterator iterator
For container compliance (hence the irregular capitalization): Iterator type.
Const_iterator const_iterator
For container compliance (hence the irregular capitalization): Const_iterator type.
An empty interface, consisting of nothing but a default virtual destructor, intended as a boiler-plat...
Convenience class template that endows the given subclass T with nested aliases Ptr and Const_ptr ali...
boost::shared_ptr< Server_socket > Ptr
Short-hand for ref-counted pointer to mutable values of type Target_type::element_type (a-la T*).
#define FLOW_ERROR_EXEC_AND_THROW_ON_ERROR(ARG_ret_type, ARG_method_name,...)
Narrow-use macro that implements the error code/exception semantics expected of most public-facing Fl...
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
uint16_t flow_port_t
Logical Flow port type (analogous to a UDP/TCP port in spirit but in no way relevant to UDP/TCP).
std::ostream & operator<<(std::ostream &os, const Congestion_control_selector::Strategy_choice &strategy_choice)
Serializes a Peer_socket_options::Congestion_control_strategy_choice enum to a standard ostream – the...
Fine_time_pt chrono_duration_from_now_to_fine_time_pt(const boost::chrono::duration< Rep, Period > &dur)
Helper that takes a non-negative duration of arbitrary precision/period and converts it to Fine_durat...
boost::unique_lock< Mutex > Lock_guard
Short-hand for advanced-capability RAII lock guard for any mutex, ensuring exclusive ownership of tha...
boost::recursive_mutex Mutex_recursive
Short-hand for reentrant, exclusive mutex.
boost::shared_ptr< Scheduled_task_handle_state > Scheduled_task_handle
Black-box type that represents a handle to a scheduled task as scheduled by schedule_task_at() or sch...
boost::mutex Mutex_non_recursive
Short-hand for non-reentrant, exclusive mutex. ("Reentrant" = one can lock an already-locked-in-that-...
boost::asio::io_service Task_engine
Short-hand for boost.asio event service, the central class of boost.asio.
boost::asio::basic_waitable_timer< Fine_clock > Timer
boost.asio timer.
Blob_with_log_context<> Blob
A concrete Blob_with_log_context that compile-time-disables Basic_blob::share() and the sharing API d...
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...
Fine_clock::duration Fine_duration
A high-res time duration as computed from two Fine_time_pts.
Fine_clock::time_point Fine_time_pt
A high-res time point as returned by Fine_clock::now() and suitable for precise time math in general.
Metadata describing the data sent in the acknowledgment of an individual received packet.
const size_t m_data_size
Number of bytes in the packet's user data.
boost::shared_ptr< const Individual_ack > Const_ptr
Short-hand for ref-counted pointer to immutable objects of this class.
const unsigned int m_rexmit_id
Retransmit counter of the packet (as reported by sender).
const Sequence_number m_seq_num
Sequence number of first datum in packet.
Individual_ack(const Individual_ack &)=delete
Force direct member initialization even if no member is const.
Individual_ack & operator=(const Individual_ack &)=delete
Forbid copy assignment.
boost::shared_ptr< Individual_ack > Ptr
Short-hand for ref-counted pointer to mutable objects of this class.
const Fine_time_pt m_received_when
When was it received? Used for supplying delay before acknowledging (for other side's RTT calculation...
Metadata (and data, if retransmission is on) for a packet that has been received (and,...
const size_t m_size
Number of bytes in the Data_packet::m_data field of that packet.
Received_packet(log::Logger *logger_ptr, size_t size, util::Blob *src_data)
Constructs object by storing size of data and, if so instructed, the data themselves.
util::Blob m_data
Byte sequence equal to that of Data_packet::m_data of the packet.
Data store to keep timing related info when a packet is sent out.
const order_num_t m_order_num
Order number of the packet.
size_t m_sent_cwnd_bytes
The congestion window size (in bytes) that is used when the packet is sent out.
Fine_time_pt m_sent_time
The timestamp when the packet is sent out.
Metadata (and data, if retransmission is on) for a packet that has been sent one (if retransmission i...
Sent_packet(bool rexmit_on, boost::shared_ptr< Data_packet > packet, const Sent_when &sent_when)
Constructs object with the given values and m_acks_after_me at zero.
std::vector< Sent_when > m_sent_when
Time stamps, order numbers, and other info at the times when the different attempts (including origin...
const size_t m_size
Number of bytes in the Data_packet::m_data field of the sent packet.
const boost::shared_ptr< Data_packet > m_packet
If retransmission is on, this is the DATA packet itself that was sent; otherwise null.
uint16_t ack_count_t
Type used for m_acks_after_me.
ack_count_t m_acks_after_me
The number of times any packet with m_sent_when.back().m_order_num > this->m_sent_when....
A data store that keeps stats about the a Peer_socket connection.
A set of low-level options affecting a single Peer_socket.
Represents the remote endpoint of a Flow-protocol connection; identifies the UDP endpoint of the remo...
The current outgoing packet pacing state, including queue of low-level packets to be sent,...