Some more updates
This commit is contained in:
parent
504c842499
commit
25c507c699
@ -1,97 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <protocol/buffers.h>
|
||||
#include <netinet/in.h>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
#include "license.h"
|
||||
|
||||
namespace license::client {
|
||||
class LicenseServerClient {
|
||||
public:
|
||||
enum ConnectionState {
|
||||
CONNECTING,
|
||||
INITIALIZING,
|
||||
CONNECTED,
|
||||
DISCONNECTING,
|
||||
|
||||
UNCONNECTED
|
||||
};
|
||||
typedef std::function<void()> callback_connected_t;
|
||||
typedef std::function<void(protocol::PacketType /* type */, const void* /* payload */, size_t /* length */)> callback_message_t;
|
||||
typedef std::function<void(bool /* expected */, const std::string& /* reason */)> callback_disconnect_t;
|
||||
|
||||
explicit LicenseServerClient(const sockaddr_in&, int /* protocol version */);
|
||||
virtual ~LicenseServerClient();
|
||||
|
||||
bool start_connection(std::string& /* error */);
|
||||
void send_message(protocol::PacketType /* type */, const void* /* buffer */, size_t /* length */);
|
||||
void close_connection();
|
||||
|
||||
void disconnect(const std::string& /* reason */, std::chrono::system_clock::time_point /* timeout */);
|
||||
bool await_disconnect();
|
||||
|
||||
|
||||
/*
|
||||
* Events will be called within the event loop.
|
||||
* All methods are save to call.
|
||||
* When close_connection or await_disconnect has been called these methods will not be called anymore.
|
||||
*/
|
||||
callback_message_t callback_message{nullptr};
|
||||
callback_connected_t callback_connected{nullptr};
|
||||
callback_disconnect_t callback_disconnected{nullptr};
|
||||
|
||||
const int protocol_version;
|
||||
private:
|
||||
std::mutex connection_lock{};
|
||||
ConnectionState connection_state{ConnectionState::UNCONNECTED};
|
||||
std::chrono::system_clock::time_point disconnect_timeout{};
|
||||
|
||||
struct Buffer {
|
||||
static Buffer* allocate(size_t /* capacity */);
|
||||
static void free(Buffer* /* ptr */);
|
||||
|
||||
void* data;
|
||||
size_t capacity;
|
||||
size_t fill;
|
||||
size_t offset;
|
||||
|
||||
TAILQ_ENTRY(Buffer) tail;
|
||||
};
|
||||
|
||||
/* modify everything here only within the event base, or when exited when connection_lock is locked */
|
||||
struct {
|
||||
sockaddr_in address{};
|
||||
int file_descriptor{0};
|
||||
|
||||
std::thread event_dispatch{};
|
||||
struct event_base* event_base{nullptr}; /* will be cleaned up by the event loop! */
|
||||
struct event* event_read{nullptr};
|
||||
struct event* event_write{nullptr};
|
||||
} network;
|
||||
|
||||
struct {
|
||||
std::mutex lock{};
|
||||
std::condition_variable notify_empty{};
|
||||
|
||||
Buffer* read{nullptr}; /* must noch be accessed via lock because only the event loop uses it */
|
||||
TAILQ_HEAD(, Buffer) write;
|
||||
} buffers;
|
||||
|
||||
struct {
|
||||
bool initialized{false};
|
||||
std::string crypt_key{};
|
||||
} communication;
|
||||
|
||||
void callback_read(short /* events */);
|
||||
void callback_write(short /* events */);
|
||||
void callback_socket_connected();
|
||||
|
||||
void cleanup_network_resources();
|
||||
|
||||
void handle_data(void*, size_t);
|
||||
void handle_raw_packet(protocol::PacketType /* type */, void* /* payload */, size_t /* length */);
|
||||
void handle_handshake_packet(void* /* payload */, size_t /* length */);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <protocol/buffers.h>
|
||||
#include <netinet/in.h>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
#include "license.h"
|
||||
|
||||
namespace license::client {
|
||||
class LicenseServerClient {
|
||||
public:
|
||||
enum ConnectionState {
|
||||
CONNECTING,
|
||||
INITIALIZING,
|
||||
CONNECTED,
|
||||
DISCONNECTING,
|
||||
|
||||
UNCONNECTED
|
||||
};
|
||||
typedef std::function<void()> callback_connected_t;
|
||||
typedef std::function<void(protocol::PacketType /* type */, const void* /* payload */, size_t /* length */)> callback_message_t;
|
||||
typedef std::function<void(bool /* expected */, const std::string& /* reason */)> callback_disconnect_t;
|
||||
|
||||
explicit LicenseServerClient(const sockaddr_in&, int /* protocol version */);
|
||||
virtual ~LicenseServerClient();
|
||||
|
||||
bool start_connection(std::string& /* error */);
|
||||
void send_message(protocol::PacketType /* type */, const void* /* buffer */, size_t /* length */);
|
||||
void close_connection();
|
||||
|
||||
void disconnect(const std::string& /* reason */, std::chrono::system_clock::time_point /* timeout */);
|
||||
bool await_disconnect();
|
||||
|
||||
|
||||
/*
|
||||
* Events will be called within the event loop.
|
||||
* All methods are save to call.
|
||||
* When close_connection or await_disconnect has been called these methods will not be called anymore.
|
||||
*/
|
||||
callback_message_t callback_message{nullptr};
|
||||
callback_connected_t callback_connected{nullptr};
|
||||
callback_disconnect_t callback_disconnected{nullptr};
|
||||
|
||||
const int protocol_version;
|
||||
private:
|
||||
std::mutex connection_lock{};
|
||||
ConnectionState connection_state{ConnectionState::UNCONNECTED};
|
||||
std::chrono::system_clock::time_point disconnect_timeout{};
|
||||
|
||||
struct Buffer {
|
||||
static Buffer* allocate(size_t /* capacity */);
|
||||
static void free(Buffer* /* ptr */);
|
||||
|
||||
void* data;
|
||||
size_t capacity;
|
||||
size_t fill;
|
||||
size_t offset;
|
||||
|
||||
TAILQ_ENTRY(Buffer) tail;
|
||||
};
|
||||
|
||||
/* modify everything here only within the event base, or when exited when connection_lock is locked */
|
||||
struct {
|
||||
sockaddr_in address{};
|
||||
int file_descriptor{0};
|
||||
|
||||
std::thread event_dispatch{};
|
||||
struct event_base* event_base{nullptr}; /* will be cleaned up by the event loop! */
|
||||
struct event* event_read{nullptr};
|
||||
struct event* event_write{nullptr};
|
||||
} network;
|
||||
|
||||
struct {
|
||||
std::mutex lock{};
|
||||
std::condition_variable notify_empty{};
|
||||
|
||||
Buffer* read{nullptr}; /* must noch be accessed via lock because only the event loop uses it */
|
||||
TAILQ_HEAD(, Buffer) write;
|
||||
} buffers;
|
||||
|
||||
struct {
|
||||
bool initialized{false};
|
||||
std::string crypt_key{};
|
||||
} communication;
|
||||
|
||||
void callback_read(short /* events */);
|
||||
void callback_write(short /* events */);
|
||||
void callback_socket_connected();
|
||||
|
||||
void cleanup_network_resources();
|
||||
|
||||
void handle_data(void*, size_t);
|
||||
void handle_raw_packet(protocol::PacketType /* type */, void* /* payload */, size_t /* length */);
|
||||
void handle_handshake_packet(void* /* payload */, size_t /* length */);
|
||||
};
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,134 +1,134 @@
|
||||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
namespace license::client {
|
||||
class LicenseServerClient;
|
||||
}
|
||||
|
||||
namespace google::protobuf {
|
||||
class Message;
|
||||
}
|
||||
|
||||
namespace ts::server::license {
|
||||
struct InstanceLicenseInfo {
|
||||
std::shared_ptr<::license::License> license{nullptr};
|
||||
std::string web_certificate_revision{};
|
||||
|
||||
struct metrics_ {
|
||||
size_t servers_online{0};
|
||||
size_t client_online{0};
|
||||
size_t web_clients_online{0};
|
||||
size_t bots_online{0};
|
||||
size_t queries_online{0};
|
||||
|
||||
size_t speech_total{0};
|
||||
size_t speech_varianz{0};
|
||||
size_t speech_online{0};
|
||||
size_t speech_dead{0};
|
||||
} metrics;
|
||||
|
||||
struct info_ {
|
||||
std::chrono::milliseconds timestamp{};
|
||||
std::string version{};
|
||||
std::string uname{};
|
||||
std::string unique_id{};
|
||||
} info;
|
||||
};
|
||||
|
||||
|
||||
class LicenseService {
|
||||
public:
|
||||
LicenseService();
|
||||
~LicenseService();
|
||||
|
||||
[[nodiscard]] bool initialize(std::string& /* error */);
|
||||
void shutdown();
|
||||
|
||||
/* whatever it failed/succeeded */
|
||||
bool execute_request_sync(const std::chrono::milliseconds& /* timeout */);
|
||||
|
||||
[[nodiscard]] inline bool verbose() const { return this->verbose_; }
|
||||
void execute_tick(); /* should not be essential to the core functionality! */
|
||||
private:
|
||||
std::chrono::steady_clock::time_point startup_timepoint_;
|
||||
|
||||
enum struct request_state {
|
||||
empty,
|
||||
|
||||
/* initializing */
|
||||
dns_lookup,
|
||||
connecting,
|
||||
|
||||
/* connected states */
|
||||
license_validate,
|
||||
license_upgrade,
|
||||
property_update,
|
||||
|
||||
/* disconnecting */
|
||||
finishing
|
||||
};
|
||||
bool verbose_{false};
|
||||
|
||||
std::recursive_timed_mutex request_lock{};
|
||||
request_state request_state_{request_state::empty};
|
||||
std::unique_ptr<::license::client::LicenseServerClient> current_client{nullptr};
|
||||
std::shared_ptr<InstanceLicenseInfo> license_request_data{nullptr};
|
||||
|
||||
std::condition_variable sync_request_cv;
|
||||
std::mutex sync_request_lock;
|
||||
|
||||
struct _timings {
|
||||
std::chrono::system_clock::time_point last_request{};
|
||||
std::chrono::system_clock::time_point next_request{};
|
||||
|
||||
std::chrono::system_clock::time_point last_succeeded{};
|
||||
size_t failed_count{0};
|
||||
} timings;
|
||||
|
||||
struct _dns {
|
||||
std::shared_ptr<std::recursive_mutex> lock{nullptr};
|
||||
|
||||
struct _lookup {
|
||||
std::shared_ptr<std::recursive_mutex> lock{nullptr};
|
||||
std::thread thread{};
|
||||
|
||||
LicenseService* handle{nullptr}; /* may be null, locked via lock */
|
||||
}* current_lookup{nullptr};
|
||||
} dns;
|
||||
|
||||
std::optional<std::string> license_invalid_reason{}; /* set if the last license is invalid */
|
||||
|
||||
void schedule_next_request(bool /* last request succeeded */);
|
||||
|
||||
void begin_request();
|
||||
void client_send_message(::license::protocol::PacketType /* type */, ::google::protobuf::Message& /* message */);
|
||||
void handle_check_fail(const std::string& /* error */); /* might be called form the DNS loop */
|
||||
void handle_check_succeeded();
|
||||
|
||||
/* if not disconnect message has been set it will just close the connection */
|
||||
void abort_request(std::lock_guard<std::recursive_timed_mutex>& /* request lock */, const std::string& /* disconnect message */);
|
||||
|
||||
void abort_dns_request();
|
||||
void execute_dns_request();
|
||||
|
||||
/* will be called while dns lock has been locked! */
|
||||
void handle_dns_lookup_result(bool /* success */, const std::variant<std::string, sockaddr_in>& /* data */);
|
||||
|
||||
/* all callbacks bellow are called from the current_client. It will not be null while being within the callback. */
|
||||
void handle_client_connected();
|
||||
void handle_client_disconnected(const std::string& /* error */);
|
||||
|
||||
void handle_message(::license::protocol::PacketType /* type */, const void* /* buffer */, size_t /* length */);
|
||||
void handle_message_license_info(const void* /* buffer */, size_t /* length */);
|
||||
void handle_message_license_update(const void* /* buffer */, size_t /* length */);
|
||||
void handle_message_property_adjustment(const void* /* buffer */, size_t /* length */);
|
||||
|
||||
void send_license_validate_request();
|
||||
bool send_license_update_request();
|
||||
void send_property_update_request();
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
namespace license::client {
|
||||
class LicenseServerClient;
|
||||
}
|
||||
|
||||
namespace google::protobuf {
|
||||
class Message;
|
||||
}
|
||||
|
||||
namespace ts::server::license {
|
||||
struct InstanceLicenseInfo {
|
||||
std::shared_ptr<::license::License> license{nullptr};
|
||||
std::string web_certificate_revision{};
|
||||
|
||||
struct metrics_ {
|
||||
size_t servers_online{0};
|
||||
size_t client_online{0};
|
||||
size_t web_clients_online{0};
|
||||
size_t bots_online{0};
|
||||
size_t queries_online{0};
|
||||
|
||||
size_t speech_total{0};
|
||||
size_t speech_varianz{0};
|
||||
size_t speech_online{0};
|
||||
size_t speech_dead{0};
|
||||
} metrics;
|
||||
|
||||
struct info_ {
|
||||
std::chrono::milliseconds timestamp{};
|
||||
std::string version{};
|
||||
std::string uname{};
|
||||
std::string unique_id{};
|
||||
} info;
|
||||
};
|
||||
|
||||
|
||||
class LicenseService {
|
||||
public:
|
||||
LicenseService();
|
||||
~LicenseService();
|
||||
|
||||
[[nodiscard]] bool initialize(std::string& /* error */);
|
||||
void shutdown();
|
||||
|
||||
/* whatever it failed/succeeded */
|
||||
bool execute_request_sync(const std::chrono::milliseconds& /* timeout */);
|
||||
|
||||
[[nodiscard]] inline bool verbose() const { return this->verbose_; }
|
||||
void execute_tick(); /* should not be essential to the core functionality! */
|
||||
private:
|
||||
std::chrono::steady_clock::time_point startup_timepoint_;
|
||||
|
||||
enum struct request_state {
|
||||
empty,
|
||||
|
||||
/* initializing */
|
||||
dns_lookup,
|
||||
connecting,
|
||||
|
||||
/* connected states */
|
||||
license_validate,
|
||||
license_upgrade,
|
||||
property_update,
|
||||
|
||||
/* disconnecting */
|
||||
finishing
|
||||
};
|
||||
bool verbose_{false};
|
||||
|
||||
std::recursive_timed_mutex request_lock{};
|
||||
request_state request_state_{request_state::empty};
|
||||
std::unique_ptr<::license::client::LicenseServerClient> current_client{nullptr};
|
||||
std::shared_ptr<InstanceLicenseInfo> license_request_data{nullptr};
|
||||
|
||||
std::condition_variable sync_request_cv;
|
||||
std::mutex sync_request_lock;
|
||||
|
||||
struct _timings {
|
||||
std::chrono::system_clock::time_point last_request{};
|
||||
std::chrono::system_clock::time_point next_request{};
|
||||
|
||||
std::chrono::system_clock::time_point last_succeeded{};
|
||||
size_t failed_count{0};
|
||||
} timings;
|
||||
|
||||
struct _dns {
|
||||
std::shared_ptr<std::recursive_mutex> lock{nullptr};
|
||||
|
||||
struct _lookup {
|
||||
std::shared_ptr<std::recursive_mutex> lock{nullptr};
|
||||
std::thread thread{};
|
||||
|
||||
LicenseService* handle{nullptr}; /* may be null, locked via lock */
|
||||
}* current_lookup{nullptr};
|
||||
} dns;
|
||||
|
||||
std::optional<std::string> license_invalid_reason{}; /* set if the last license is invalid */
|
||||
|
||||
void schedule_next_request(bool /* last request succeeded */);
|
||||
|
||||
void begin_request();
|
||||
void client_send_message(::license::protocol::PacketType /* type */, ::google::protobuf::Message& /* message */);
|
||||
void handle_check_fail(const std::string& /* error */); /* might be called form the DNS loop */
|
||||
void handle_check_succeeded();
|
||||
|
||||
/* if not disconnect message has been set it will just close the connection */
|
||||
void abort_request(std::lock_guard<std::recursive_timed_mutex>& /* request lock */, const std::string& /* disconnect message */);
|
||||
|
||||
void abort_dns_request();
|
||||
void execute_dns_request();
|
||||
|
||||
/* will be called while dns lock has been locked! */
|
||||
void handle_dns_lookup_result(bool /* success */, const std::variant<std::string, sockaddr_in>& /* data */);
|
||||
|
||||
/* all callbacks bellow are called from the current_client. It will not be null while being within the callback. */
|
||||
void handle_client_connected();
|
||||
void handle_client_disconnected(const std::string& /* error */);
|
||||
|
||||
void handle_message(::license::protocol::PacketType /* type */, const void* /* buffer */, size_t /* length */);
|
||||
void handle_message_license_info(const void* /* buffer */, size_t /* length */);
|
||||
void handle_message_license_update(const void* /* buffer */, size_t /* length */);
|
||||
void handle_message_property_adjustment(const void* /* buffer */, size_t /* length */);
|
||||
|
||||
void send_license_validate_request();
|
||||
bool send_license_update_request();
|
||||
void send_property_update_request();
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user