switch to coroutine execution model

This commit is contained in:
Martin Michelsen
2025-04-30 21:43:06 -07:00
parent f65b1f1c14
commit cc99050964
160 changed files with 269127 additions and 227736 deletions
+14 -27
View File
@@ -1,6 +1,5 @@
#pragma once
#include <event2/event.h>
#include <stdint.h>
#include <stdio.h>
@@ -14,18 +13,17 @@
class ReplaySession {
public:
ReplaySession(
std::shared_ptr<struct event_base> base,
FILE* input_log,
std::shared_ptr<ServerState> state,
bool require_basic_credentials);
ReplaySession(std::shared_ptr<ServerState> state, FILE* input_log, bool is_interactive);
ReplaySession(const ReplaySession&) = delete;
ReplaySession(ReplaySession&&) = delete;
ReplaySession& operator=(const ReplaySession&) = delete;
ReplaySession& operator=(ReplaySession&&) = delete;
~ReplaySession() = default;
void start();
asio::awaitable<void> run();
inline bool failed() const {
return this->run_failed;
}
private:
struct Event {
@@ -54,46 +52,35 @@ private:
uint64_t id;
uint16_t port;
Version version;
Channel channel;
std::shared_ptr<PeerChannel> channel;
std::deque<std::shared_ptr<Event>> receive_events;
std::shared_ptr<Event> disconnect_event;
Client(ReplaySession* session, uint64_t id, uint16_t port, Version version);
Client(std::shared_ptr<asio::io_context> io_context, uint64_t id, uint16_t port, Version version);
std::string str() const;
};
std::shared_ptr<ServerState> state;
bool require_basic_credentials;
bool is_interactive;
bool prev_psov2_crypt_enabled;
std::unordered_map<uint64_t, std::shared_ptr<Client>> clients;
std::unordered_map<Channel*, std::shared_ptr<Client>> channel_to_client;
std::shared_ptr<Event> first_event;
std::shared_ptr<Event> last_event;
std::shared_ptr<struct event_base> base;
std::shared_ptr<struct event> timeout_ev;
size_t commands_sent;
size_t bytes_sent;
size_t commands_received;
size_t bytes_received;
std::shared_ptr<ReplaySession::Event> create_event(
Event::Type type, std::shared_ptr<Client> c, size_t line_num);
void update_timeout_event();
asio::steady_timer idle_timeout_timer;
bool run_failed;
std::shared_ptr<ReplaySession::Event> create_event(Event::Type type, std::shared_ptr<Client> c, size_t line_num);
void apply_default_mask(std::shared_ptr<Event> ev);
void check_for_password(std::shared_ptr<const Event> ev) const;
static void dispatch_on_timeout(evutil_socket_t fd, short events, void* ctx);
static void dispatch_on_command_received(
Channel& ch, uint16_t command, uint32_t flag, std::string& data);
static void dispatch_on_error(Channel& ch, short events);
void on_command_received(
std::shared_ptr<Client> c, uint16_t command, uint32_t flag, std::string& data);
void on_error(std::shared_ptr<Client> c, short events);
void execute_pending_events();
void reschedule_idle_timeout();
};