9#include <nlohmann/json.hpp>
53[[nodiscard]] std::vector<PcapLine>
parse_pcap_lines(
const nlohmann::json &config,
54 std::span<
const std::pair<const char *, uint8_t>> keys);
84 std::shared_ptr<ReplayGate> gate);
87 void start()
override;
92 void poll(uint64_t now_ns);
95 [[nodiscard]]
const std::string &
name() const noexcept {
return name_; }
97 [[nodiscard]] std::string
feedName()
const override {
return name_; }
99 [[nodiscard]] uint16_t
control_port() const noexcept {
return control_.listen_port(); }
106 [[nodiscard]] uint64_t
event_time_ns() const noexcept {
return event_time_ns_; }
111 virtual void on_packet(uint8_t line,
const uint8_t *data,
size_t size, uint64_t now_ns) = 0;
115 [[nodiscard]]
virtual bool synchronized()
const = 0;
118 [[nodiscard]]
virtual std::string
describe()
const {
return {}; }
121 static constexpr uint32_t MAX_PACKETS_PER_POLL = 4096;
122 static constexpr uint64_t HEARTBEAT_NS = 1'000'000'000;
124 void serve_control();
125 void enter(
FeedState next, uint64_t now_ns, std::string message = {});
126 void publish_status(uint64_t now_ns);
127 void feed(uint64_t now_ns);
131 PcapFeedConfig config_;
132 std::shared_ptr<ReplayGate> gate_;
133 PcapReplaySource source_;
134 PcapControlServer control_;
137 bool start_requested_ =
false;
140 bool control_down_ =
false;
142 std::string message_;
143 uint64_t current_capture_ns_ = 0;
144 uint64_t event_time_ns_ = 0;
145 uint64_t next_heartbeat_ns_ = 0;
Where the CLI server's commands reach a thread that owns some state (the main thread,...
FeedKind feedKind() const noexcept override
const std::string & name() const noexcept
uint64_t event_time_ns() const noexcept
Wall time to stamp on the events of the packet being handled.
virtual void on_timer(uint64_t now_ns)=0
The handler's timers (gap timeouts), while it is being fed.
FeedState state() const noexcept
void poll(uint64_t now_ns)
Exchange thread: serves control requests, advances the state machine and feeds the handler what is du...
uint16_t control_port() const noexcept
The listening port of the control channel (0 before start()).
cli::CliEndpoint * cliEndpoint() noexcept override
pcap/<venue>/<feed>: replay and status, served on the control channel's thread (by poll() if that nev...
virtual std::string describe() const
What the handler has done so far, for the log at READY and at the end: packets, gaps,...
std::string feedName() const override
Its name, different from the venue's other feeds'. Empty for a feed without one.
virtual void on_packet(uint8_t line, const uint8_t *data, size_t size, uint64_t now_ns)=0
Hands one captured packet to the venue's protocol handler.
PcapFeedBase(std::string name, Venue venue, const PcapFeedConfig &config, std::vector< PcapLine > lines, std::shared_ptr< ReplayGate > gate)
gate is shared with the market-data publisher, which holds market data back until it opens.
uint64_t parse_utc_time_ns(const std::string &text)
Parses a UTC "YYYY-MM-DDTHH:MM:SS[.fraction][Z]" into nanoseconds since the epoch.
std::vector< PcapLine > parse_pcap_lines(const nlohmann::json &config, std::span< const std::pair< const char *, uint8_t > > keys)
The multicast groups of a pcap feed's config: for each {key, line} that the config names,...
FeedKind
Where a feed's market data comes from.
FeedState
Where a pcap replay feed is. The values are on the wire: append, never renumber.
What a pcap feed's config entry says, beyond its venue's multicast groups.
static PcapFeedConfig from_json(const nlohmann::json &config, const std::string &feed)
Throws std::runtime_error naming feed when a key is missing or invalid.
static constexpr int DEFAULT_CONTROL_MAX_CONNECTIONS
int control_max_connections