JayBeams
0.1
Another project to have fun coding.
|
Send a sequence of raw ITCH-5.x messages as MoldUDP64 packets, trying to match the original time interval between messages. More...
#include <mold_udp_pacer.hpp>
Public Types | |
Type traits | |
typedef clock_type::time_point | time_point |
The time point (specific time with respect to some epoch) type. More... | |
typedef clock_type::duration | duration |
The duration (the difference between two time points) type. More... | |
typedef mold_udp_pacer_config | config |
The configuration file. More... | |
typedef jb::itch5::short_string_field< mold_udp_protocol::session_id_size > | session_id_type |
The type used to represent session ids. More... | |
Public Member Functions | |
mold_udp_pacer (config const &cfg=config(), session_id_type const &session_id=session_id_type()) | |
Initialize a MoldUDP pacer object. More... | |
template<typename message_sink_type , typename sleep_functor_type > | |
void | handle_message (time_point ts, unknown_message const &msg, message_sink_type &sink, sleep_functor_type &sleeper) |
Process a raw ITCH-5.x message. More... | |
template<typename message_sink_type > | |
void | flush (timestamp ts, message_sink_type &sink) |
Flush the current messages, if any. More... | |
template<typename message_sink_type > | |
void | heartbeat (message_sink_type &sink) |
Send a heartbeat packet. More... | |
Private Member Functions | |
template<typename message_sink_type > | |
void | coalesce (time_point recv_ts, unknown_message const &msg, timestamp ts, message_sink_type &sink) |
Add another message to the current queue, flushing first if necessary. More... | |
void | fillup_header_fields () |
Fill up the header for the MoldUDP64 packet. More... | |
template<typename message_sink_type > | |
void | flush_impl (timestamp ts, message_sink_type &sink) |
Implement the flush() and hearbeat() member functions. More... | |
bool | packet_full (std::uint16_t block_size) const |
Return true if the packet is too full to accept a new block of size block_size. More... | |
Private Attributes | |
jb::itch5::timestamp | last_send_ |
duration | max_delay_ |
int | mtu_ |
char | rawbuf [rawbufsize] = {0} |
boost::asio::mutable_buffer | packet_ |
std::size_t | packet_size_ |
std::uint32_t | first_block_ |
timestamp | first_block_ts_ |
std::uint16_t | block_count_ |
Static Private Attributes | |
static constexpr std::size_t | rawbufsize = 65536 |
Send a sequence of raw ITCH-5.x messages as MoldUDP64 packets, trying to match the original time interval between messages.
The MoldUDP64 protocol (see link below) allows transmission of ITCH-5.x messages over UDP. Multiple ITCH-5.x messages are packed into a single MoldUDP64 packet, which includes enough information to request retransmissions if needed.
This class receives a stream of raw ITCH-5.x messages and creates a stream of MoldUDP64 packets. It examines the original timestamps of the raw ITCH-5.x messages to pace the outgoing stream. When the original messages are sufficiently close in time they are assembled into a single large packet. If the messages are separated in time the class blocks until enough wall-clock time has elapsed.
clock_type | a dependency injection point to make this class testable. Normally the class is simply used with a std::chrono::steady_clock. Under test, it is convenient to be able to modify the results of the clock_type::now() function to exercise multiple scenarios. |
References: http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/moldudp64.pdf
Definition at line 43 of file mold_udp_pacer.hpp.
typedef mold_udp_pacer_config jb::itch5::mold_udp_pacer< clock_type >::config |
The configuration file.
Definition at line 56 of file mold_udp_pacer.hpp.
typedef clock_type::duration jb::itch5::mold_udp_pacer< clock_type >::duration |
The duration (the difference between two time points) type.
Definition at line 53 of file mold_udp_pacer.hpp.
typedef jb::itch5::short_string_field<mold_udp_protocol::session_id_size> jb::itch5::mold_udp_pacer< clock_type >::session_id_type |
The type used to represent session ids.
The MoldUDP64 protocol uses a 10-character identifier for the session id, different streams can be distinguished using this field in the protocol.
Definition at line 66 of file mold_udp_pacer.hpp.
typedef clock_type::time_point jb::itch5::mold_udp_pacer< clock_type >::time_point |
The time point (specific time with respect to some epoch) type.
Definition at line 50 of file mold_udp_pacer.hpp.
|
inline |
Initialize a MoldUDP pacer object.
Definition at line 72 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::block_count_, jb::itch5::mold_udp_pacer< clock_type >::first_block_, jb::itch5::mold_udp_pacer< clock_type >::first_block_ts_, jb::itch5::mold_udp_protocol::header_size, jb::itch5::mold_udp_pacer< clock_type >::max_delay_, jb::itch5::mold_udp_pacer< clock_type >::mtu_, jb::itch5::mold_udp_pacer< clock_type >::packet_, jb::itch5::mold_udp_pacer< clock_type >::packet_size_, jb::itch5::mold_udp_pacer< clock_type >::rawbuf, and jb::itch5::mold_udp_pacer< clock_type >::rawbufsize.
|
inlineprivate |
Add another message to the current queue, flushing first if necessary.
recv_ts | the timestamp when the message was received |
msg | the message contents and location |
ts | the timestamp when the last message was sent |
sink | the destination for the MoldUDP64 packets |
Definition at line 173 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::block_count_, jb::itch5::unknown_message::buf(), jb::itch5::unknown_message::count(), jb::itch5::mold_udp_pacer< clock_type >::first_block_, jb::itch5::mold_udp_pacer< clock_type >::first_block_ts_, jb::itch5::mold_udp_pacer< clock_type >::flush(), jb::itch5::mold_udp_protocol::header_size, JB_ASSERT_THROW, jb::itch5::unknown_message::len(), jb::itch5::mold_udp_pacer< clock_type >::mtu_, jb::itch5::mold_udp_pacer< clock_type >::packet_, jb::itch5::mold_udp_pacer< clock_type >::packet_full(), jb::itch5::mold_udp_pacer< clock_type >::packet_size_, and jb::itch5::encoder< validate, T >::w().
Referenced by jb::itch5::mold_udp_pacer< clock_type >::handle_message().
|
inlineprivate |
Fill up the header for the MoldUDP64 packet.
Definition at line 209 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::block_count_, jb::itch5::mold_udp_protocol::block_count_offset, jb::itch5::mold_udp_pacer< clock_type >::first_block_, jb::itch5::mold_udp_pacer< clock_type >::packet_, jb::itch5::mold_udp_protocol::sequence_number_offset, and jb::itch5::encoder< validate, T >::w().
Referenced by jb::itch5::mold_udp_pacer< clock_type >::flush_impl().
|
inline |
Flush the current messages, if any.
ts | the wall clock time when the message was received |
sink | the destination for the MoldUDP64 packets |
message_sink_type | please see handle_message() for details |
Definition at line 140 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::block_count_, and jb::itch5::mold_udp_pacer< clock_type >::flush_impl().
Referenced by BOOST_AUTO_TEST_CASE(), jb::itch5::mold_udp_pacer< clock_type >::coalesce(), and jb::itch5::mold_udp_pacer< clock_type >::handle_message().
|
inlineprivate |
Implement the flush() and hearbeat() member functions.
Definition at line 230 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::block_count_, jb::itch5::mold_udp_pacer< clock_type >::fillup_header_fields(), jb::itch5::mold_udp_pacer< clock_type >::first_block_, jb::itch5::mold_udp_protocol::header_size, jb::itch5::mold_udp_pacer< clock_type >::last_send_, jb::itch5::mold_udp_pacer< clock_type >::packet_, and jb::itch5::mold_udp_pacer< clock_type >::packet_size_.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::flush(), and jb::itch5::mold_udp_pacer< clock_type >::heartbeat().
|
inline |
Process a raw ITCH-5.x message.
ts | the wall-clock when the message was received, as defined by clock_type |
msg | the message received, the timestamp in the message is used to pace the outgoing MoldUDP64 packets |
sink | a functor to send the MoldUDP64 packets |
sleeper | a functor to sleep and effectively pace the messages |
message_sink_type | the type of the sink functor. The signature must be compatible with void(auto buffers) where buffers meets the requirements of a Boost.Asio ConstBufferSequence. |
sleep_functor_type | the type of the sleeper function, the signature must be compatible with void(clock_type::duration const&) |
Definition at line 105 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::coalesce(), jb::itch5::unknown_message::count(), jb::itch5::unknown_message::decode_header(), jb::itch5::mold_udp_pacer< clock_type >::flush(), jb::itch5::mold_udp_pacer< clock_type >::last_send_, jb::itch5::mold_udp_pacer< clock_type >::max_delay_, jb::itch5::message_header::timestamp, and jb::itch5::timestamp::ts.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Send a heartbeat packet.
If there are any pending messages those messages are flushed and the resulting packet constitutes the heartbeat.
sink | the destination for the MoldUDP64 packets |
message_sink_type | please see handle_message() for details |
Definition at line 158 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::first_block_ts_, and jb::itch5::mold_udp_pacer< clock_type >::flush_impl().
Referenced by BOOST_AUTO_TEST_CASE().
|
inlineprivate |
Return true if the packet is too full to accept a new block of size block_size.
block_size | the size of the next block that we intend to add to the packet |
Definition at line 246 of file mold_udp_pacer.hpp.
References jb::itch5::mold_udp_pacer< clock_type >::block_count_, jb::itch5::mold_udp_pacer< clock_type >::mtu_, and jb::itch5::mold_udp_pacer< clock_type >::packet_size_.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::coalesce().
|
private |
Definition at line 269 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::coalesce(), jb::itch5::mold_udp_pacer< clock_type >::fillup_header_fields(), jb::itch5::mold_udp_pacer< clock_type >::flush(), jb::itch5::mold_udp_pacer< clock_type >::flush_impl(), jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer(), and jb::itch5::mold_udp_pacer< clock_type >::packet_full().
|
private |
Definition at line 267 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::coalesce(), jb::itch5::mold_udp_pacer< clock_type >::fillup_header_fields(), jb::itch5::mold_udp_pacer< clock_type >::flush_impl(), and jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer().
|
private |
Definition at line 268 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::coalesce(), jb::itch5::mold_udp_pacer< clock_type >::heartbeat(), and jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer().
|
private |
Definition at line 254 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::flush_impl(), and jb::itch5::mold_udp_pacer< clock_type >::handle_message().
|
private |
Definition at line 255 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::handle_message(), and jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer().
|
private |
Definition at line 256 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::coalesce(), jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer(), and jb::itch5::mold_udp_pacer< clock_type >::packet_full().
|
private |
Definition at line 264 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::coalesce(), jb::itch5::mold_udp_pacer< clock_type >::fillup_header_fields(), jb::itch5::mold_udp_pacer< clock_type >::flush_impl(), and jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer().
|
private |
|
private |
Definition at line 262 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer().
|
staticprivate |
Definition at line 261 of file mold_udp_pacer.hpp.
Referenced by jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer().