61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
/*
|
|
* BastionGuard™ Secure Connection
|
|
* Copyright (C) 2025–2026 Calogero Scarnà
|
|
* GPL-3.0
|
|
*/
|
|
|
|
#pragma once
|
|
#include "bsc/model/Connection.hpp"
|
|
#include "bsc/rule/Rule.hpp"
|
|
#include "bsc/stats/Statistics.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace bsc::ui {
|
|
|
|
struct NotificationEvent {
|
|
std::uint64_t id{0};
|
|
std::string type;
|
|
std::string data;
|
|
std::vector<bsc::rule::Rule> rules;
|
|
};
|
|
|
|
/**
|
|
* Client Unix-socket verso il server della UI. Sostituisce la precedente
|
|
* implementazione gRPC. Gestisce:
|
|
* - thread di lettura frame che smista pong / notification / ask_rule_reply
|
|
* - scrittore serializzato via mutex
|
|
* - reconnector che riprova finche' il socket non e' disponibile
|
|
*/
|
|
class UIClient {
|
|
public:
|
|
explicit UIClient(std::string socket_uri);
|
|
~UIClient();
|
|
|
|
UIClient(const UIClient&) = delete;
|
|
UIClient& operator=(const UIClient&) = delete;
|
|
|
|
void start();
|
|
void stop();
|
|
bool is_connected() const noexcept;
|
|
|
|
std::optional<bsc::rule::Rule> ask_rule(const bsc::model::Connection& conn);
|
|
bool ping(const bsc::stats::Statistics& stats);
|
|
bool post_alert(const std::string& text);
|
|
bool post_connection_alert(const bsc::model::Connection& conn,
|
|
const std::string& action,
|
|
const std::string& rule_name = {});
|
|
|
|
void set_notification_handler(std::function<void(const NotificationEvent&)> cb);
|
|
|
|
private:
|
|
class Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
|
|
} // namespace bsc::ui
|