Flow 1.0.1
Flow project: Full implementation reference.
|
Internal net_flow
struct
that encapsulates the Flow-protocol low-level DATA packet.
More...
#include <low_lvl_packet.hpp>
Public Types | |
using | rexmit_id_t = uint8_t |
Type used to store the retransmission count in DATA and ACK packets. More... | |
Public Types inherited from flow::net_flow::Low_lvl_packet | |
using | Const_buffer = boost::asio::const_buffer |
Short-hand for boost.asio immutable buffer, which essentially is a pointer to and length of a memory area. More... | |
using | Const_buffer_sequence = std::vector< Const_buffer > |
Short-hand for sequence of immutable buffers; i.e., a sequence of 1 or more scattered areas in memory. More... | |
using | security_token_t = uint64_t |
Type used for m_security_token member of a couple different packet types. More... | |
using | rexmit_id_t = uint8_t |
Type used to store the retransmission count in DATA and ACK packets. More... | |
using | rcv_wnd_t = uint32_t |
Type used to store the size of m_rcv_wnd member in a couple of different packet types. More... | |
Public Types inherited from flow::util::Shared_ptr_alias_holder< boost::shared_ptr< Low_lvl_packet > > | |
using | Ptr = boost::shared_ptr< Low_lvl_packet > |
Short-hand for ref-counted pointer to mutable values of type Target_type::element_type (a-la T* ). More... | |
using | Const_ptr = Const_target_ptr |
Short-hand for ref-counted pointer to immutable values of type Target_type::element_type (a-la T const * ). More... | |
Public Member Functions | |
size_t | serialize_to_raw_data (Const_buffer_sequence *raw_bufs) const override |
Implements Low_lvl_packet API. More... | |
Public Member Functions inherited from flow::net_flow::Low_lvl_packet | |
virtual size_t | serialize_to_raw_data (Const_buffer_sequence *raw_bufs) const =0 |
Serializes the current logical packet data from *this into the given Const_buffer_sequence , which is a sequence of pointers and lengths of existing scattered areas in memory, presumably for transmission over the wire to a compatible serializing Node. More... | |
size_t | serialize_to_raw_data_and_log (Const_buffer_sequence *raw_bufs) const |
Identical to serialize_to_raw_data() but adds log-level-appropriate logging after the operation. More... | |
Public Member Functions inherited from flow::util::Null_interface | |
virtual | ~Null_interface ()=0 |
Boring virtual destructor. More... | |
Public Member Functions inherited from flow::log::Log_context | |
Log_context (Logger *logger=0) | |
Constructs Log_context by storing the given pointer to a Logger and a null Component. More... | |
template<typename Component_payload > | |
Log_context (Logger *logger, Component_payload component_payload) | |
Constructs Log_context by storing the given pointer to a Logger and a new Component storing the specified generically typed payload (an enum value). More... | |
Log_context (const Log_context &src) | |
Copy constructor that stores equal Logger* and Component values as the source. More... | |
Log_context (Log_context &&src) | |
Move constructor that makes this equal to src , while the latter becomes as-if default-constructed. More... | |
Log_context & | operator= (const Log_context &src) |
Assignment operator that behaves similarly to the copy constructor. More... | |
Log_context & | operator= (Log_context &&src) |
Move assignment operator that behaves similarly to the move constructor. More... | |
void | swap (Log_context &other) |
Swaps Logger pointers and Component objects held by *this and other . More... | |
Logger * | get_logger () const |
Returns the stored Logger pointer, particularly as many FLOW_LOG_*() macros expect. More... | |
const Component & | get_log_component () const |
Returns reference to the stored Component object, particularly as many FLOW_LOG_*() macros expect. More... | |
Public Attributes | |
Sequence_number | m_seq_num |
The sequence number of the first byte in the payload; i.e., of m_data.front() , a/k/a m_data[0] . More... | |
rexmit_id_t | m_rexmit_id |
Retransmit counter of the DATA packet being sent. More... | |
uint16_t | m_data_size_raw |
This is the serialized version of m_data.size() (see m_data). More... | |
util::Blob | m_data |
The payload. More... | |
Public Attributes inherited from flow::net_flow::Low_lvl_packet | |
bool | m_opt_rexmit_on |
Option indicating whether this connection is using retransmission or not. More... | |
struct { | |
flow_port_t m_src_port | |
Flow-protocol port # of socket in sending Node. More... | |
flow_port_t m_dst_port | |
Flow-protocol port # of socket in receiving Node. More... | |
} | m_packed |
Packed group affected by #pragma pack . | |
const Function< std::ostream &(std::ostream &)> | m_type_ostream_manip |
ostream manipulator (argument to ostream << ) that will output packet's type ("ACK", "RST", etc.). More... | |
const Function< std::ostream &(std::ostream &)> | m_verbose_ostream_manip |
ostream manipulator (argument to ostream << ) that will output packet info suitable for DATA log level. More... | |
const Function< std::ostream &(std::ostream &)> | m_concise_ostream_manip |
ostream manipulator (argument to ostream << ) that will output packet info suitable for TRACE log level. More... | |
Static Public Attributes | |
static const uint8_t | S_RAW_TYPE_ID |
In serialized packet, the type ID byte identifying this as a DATA packet. Must not equal any other packet type's. More... | |
Private Member Functions | |
Data_packet (log::Logger *logger_ptr) | |
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet. More... | |
std::ostream & | to_ostream (std::ostream &os, bool verbose) const override |
Implements Low_lvl_packet API. More... | |
bool | deserialize_type_specific_data_from_raw_data_packet (Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet) override |
Implements Low_lvl_packet API. More... | |
Friends | |
boost::shared_ptr< Data_packet > | Low_lvl_packet::create_uninit_packet (log::Logger *) |
Friend of Data_packet: For access to private constructor Data_packet(Logger*) . | |
Additional Inherited Members | |
Static Public Member Functions inherited from flow::net_flow::Low_lvl_packet | |
template<typename Low_lvl_packet_sub > | |
static boost::shared_ptr< Low_lvl_packet_sub > | create_uninit_packet (log::Logger *logger_ptr) |
Constructs packet with uninitialized (essentially random) values, of the Low_lvl_packet sub-type specified as the template parameter (Ack_packet, Rst_packet, etc.). More... | |
template<typename Low_lvl_packet_sub > | |
static Ptr | create_uninit_packet_base (log::Logger *logger_ptr) |
A simple convenience method that casts the result of create_uninit_packet() from shared_ptr<T> , where T is a sub-type of Low_lvl_packet, to shared_ptr<Low_lvl_packet> a/k/a Ptr. More... | |
static Ptr | create_from_raw_data_packet (log::Logger *logger_ptr, util::Blob *raw_packet, bool prefer_no_move) |
Constructs packet on the heap with values determined by the given raw binary data as presumably received from the wire and originally serialized by a compatible serializing Node. More... | |
static const std::string & | type_id_to_str (const std::type_index &type_id) |
Returns a brief (a few characters) string description of the given packet type given as type_index(typeid(p)) , where p is a reference to an instance of a concrete Low_lvl_packet sub-type. More... | |
Static Public Member Functions inherited from flow::util::Shared_ptr_alias_holder< boost::shared_ptr< Low_lvl_packet > > | |
static Ptr | ptr_cast (const From_ptr &ptr_to_cast) |
Provides syntactic-sugary way to perform a static_pointer_cast<> from a compatible smart pointer type From_ptr , typically From_ptr::element_type being in the same class hierarchy as Target_ptr::element_type . More... | |
static Const_ptr | const_ptr_cast (const From_ptr &ptr_to_cast) |
Identical to ptr_cast() but adds const -ness (immutability) to the pointed-to type. More... | |
static Ptr | dynamic_ptr_cast (const From_ptr &ptr_to_cast) |
Equivalent to ptr_cast() but a dynamic_pointer_cast instead of static. More... | |
static Const_ptr | dynamic_const_ptr_cast (const From_ptr &ptr_to_cast) |
Identical to const_ptr_cast() but a dynamic_pointer_cast instead of static. More... | |
Protected Member Functions inherited from flow::net_flow::Low_lvl_packet | |
Low_lvl_packet (log::Logger *logger_ptr) | |
Constructs packet with uninitialized (essentially random) values. More... | |
size_t | serialize_common_header_to_raw_data (Const_buffer_sequence *raw_bufs) const |
Helper for serialize_to_raw_data() implementations in sub-types that encodes the header common to all packet types, starting with the packet type ID leading that header. More... | |
virtual std::ostream & | to_ostream (std::ostream &os, bool verbose=false) const |
Writes a multi-line representation of *this to an output stream. More... | |
Static Protected Member Functions inherited from flow::net_flow::Low_lvl_packet | |
static constexpr bool | native_is_big_endian () |
Returns true , at compile time, if and only if the native memory representation is big-endian, meaning, for example, the value uint32_t(1) is stored as the bytes, in order, 0x00 0x00 0x00 0x01, and not the reverse. More... | |
Internal net_flow
struct
that encapsulates the Flow-protocol low-level DATA packet.
See Low_lvl_packet doc header for information common to all low-level packets including this one.
Each DATA packet contains actual data payload packetized from the application-provided stream of bytes. It is identified by the sequence number (encoded in this object) of the first byte of that payload. An individual acknowledgment inside an Ack_packet refers to the Data_packet by that first sequence number. If Low_lvl_packet::m_opt_rexmit_on is true
, then m_rexmit_id identifies which attempt at sending the payload with this sequence number and payload this packet represents: 0 is 1st attempt, 1 is 1st retry, 2 is 2nd retry, etc. If that option is off, then a lost packet is never retransmitted; and therefore m_rexmit_id is always 0.
Definition at line 892 of file low_lvl_packet.hpp.
Type used to store the retransmission count in DATA and ACK packets.
Why 8 bits? This handles up 255 retransmissions, which is long after we'd kill the connection anyway.
Definition at line 902 of file low_lvl_packet.hpp.
|
explicitprivate |
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet.
logger_ptr | Logger to use subsequently. |
Definition at line 88 of file low_lvl_packet.cpp.
|
overrideprivatevirtual |
Implements Low_lvl_packet API.
See that super-method's doc header.
Implements flow::net_flow::Low_lvl_packet.
Definition at line 655 of file low_lvl_packet.cpp.
References FLOW_LOG_TRACE, FLOW_LOG_WARNING, m_data, m_data_size_raw, flow::net_flow::Low_lvl_packet::m_opt_rexmit_on, m_rexmit_id, m_seq_num, flow::net_flow::Low_lvl_packet::m_type_ostream_manip, flow::net_flow::Sequence_number::set_metadata(), and flow::net_flow::Sequence_number::set_raw_num().
|
overridevirtual |
Implements Low_lvl_packet API.
See that super-method's doc header.
raw_bufs | See Low_lvl_packet::serialize_to_raw_data(). |
Implements flow::net_flow::Low_lvl_packet.
Definition at line 279 of file low_lvl_packet.cpp.
|
overrideprivatevirtual |
Implements Low_lvl_packet API.
See that super-method's doc header.
os | See Low_lvl_packet::to_ostream(). |
verbose | See Low_lvl_packet::to_ostream(). |
os
. Reimplemented from flow::net_flow::Low_lvl_packet.
Definition at line 968 of file low_lvl_packet.cpp.
References flow::util::buffers_to_ostream(), and flow::net_flow::Low_lvl_packet::to_ostream().
util::Blob flow::net_flow::Data_packet::m_data |
The payload.
Cannot be empty()
.
As of this writing there is an important (for performance) subtlety about how this is originally filled in when deserializing a wire-arrived packet. See Data_packet::deserialize_type_specific_data_from_raw_data_packet().
Definition at line 933 of file low_lvl_packet.hpp.
Referenced by deserialize_type_specific_data_from_raw_data_packet().
|
mutable |
This is the serialized version of m_data.size()
(see m_data).
We send this value, even though it could be figured out from the overall serialized size, to ensure integrity (see the deserialization logic for details). This here is set to m_data.size()
, when Low_lvl_packet::serialize_to_raw_data() needs to serialize that value. Outside serialization m_data.size()
is used directly, and this value is meaningless.
Definition at line 925 of file low_lvl_packet.hpp.
Referenced by deserialize_type_specific_data_from_raw_data_packet().
rexmit_id_t flow::net_flow::Data_packet::m_rexmit_id |
Retransmit counter of the DATA packet being sent.
Identifies which attempt we are acknowledging (0 = initial, 1 = first retransmit, 2 = second retransmit, ...). Always 0 if !m_opt_rexmit_on
.
Definition at line 916 of file low_lvl_packet.hpp.
Referenced by deserialize_type_specific_data_from_raw_data_packet().
Sequence_number flow::net_flow::Data_packet::m_seq_num |
The sequence number of the first byte in the payload; i.e., of m_data.front()
, a/k/a m_data[0]
.
Note that m_data cannot be empty, so m_seq_num is always meaningful.
Definition at line 910 of file low_lvl_packet.hpp.
Referenced by deserialize_type_specific_data_from_raw_data_packet().
|
static |
In serialized packet, the type ID byte identifying this as a DATA packet. Must not equal any other packet type's.
Definition at line 944 of file low_lvl_packet.hpp.