Skip to content
API Documentation
BastionGuard™
LeakMonitor Class Reference

#include <LeakMonitor.hpp>

Public Types

using NotifyFn = std::function<void(const std::string&)>

Public Member Functions

 LeakMonitor (const std::string &email, NotifyFn notify)
 ~LeakMonitor ()
void start ()
void stop ()

Private Member Functions

void loop ()

Private Attributes

std::string email
NotifyFn notify
std::thread worker
std::atomic< bool > running {false}

Detailed Description

Definition at line 30 of file LeakMonitor.hpp.

Member Typedef Documentation

◆ NotifyFn

using LeakMonitor::NotifyFn = std::function<void(const std::string&)>

Definition at line 32 of file LeakMonitor.hpp.

Constructor & Destructor Documentation

◆ LeakMonitor()

LeakMonitor::LeakMonitor ( const std::string & email,
NotifyFn notify )
explicit

Definition at line 32 of file LeakMonitor.cpp.

35 : email(e),
36 notify(std::move(n)),
37 running(false)
38{
39}
NotifyFn notify
std::atomic< bool > running
std::string email

References email, notify, and running.

◆ ~LeakMonitor()

LeakMonitor::~LeakMonitor ( )

Definition at line 41 of file LeakMonitor.cpp.

42{
43 stop();
44}

References stop().

Member Function Documentation

◆ loop()

void LeakMonitor::loop ( )
private

Definition at line 63 of file LeakMonitor.cpp.

64{
65 LeakAggregator aggregator;
66
67
68 const std::string hibpApiKey =
70
71 const bool hibpEnabled = !hibpApiKey.empty();
72
73 if (hibpEnabled) {
74 aggregator.addProvider(
75 std::make_unique<HibpProvider>(hibpApiKey));
76 }
77
78 // LeakCheck SEMPRE disponibile (fallback)
79 aggregator.addProvider(
80 std::make_unique<LeakCheckProvider>());
81
82 const std::string emailHash =
84
85 if (hibpEnabled) {
86 notify(_("Monitor Identity Leak attivo (HIBP + LeakCheck)"));
87 } else {
88 notify(_(
89 "⚠ Monitor Identity Leak attivo in modalità LIMITATA "
90 "(solo LeakCheck, API HIBP mancante)"));
91 }
92
93
94 while (running) {
95
96 try {
97 auto leaks = aggregator.queryAll(email);
98
99 if (!leaks.empty()) {
100
101 if (hibpEnabled) {
102 notify(_(
103 "⚠ Nuova violazione rilevata per identità: ") +
104 emailHash);
105 } else {
106 notify(_(
107 "⚠ Possibile esposizione rilevata "
108 "(fonte LeakCheck, verifica manuale consigliata)"));
109 }
110 }
111 }
112 catch (const std::exception& ex) {
113 notify(
114 std::string(_("❌ Errore monitor Identity Leak: ")) +
115 ex.what());
116 }
117
118 for (int i = 0; i < 24 * 60 && running; ++i) {
119 std::this_thread::sleep_for(
120 std::chrono::minutes(1));
121 }
122 }
123
124 notify(_("Monitor Identity Leak fermato"));
125}
#define _(s)
static std::string sha256(const std::string &input)
Definition HashUtil.cpp:27
static std::string hibpApiKey()
void addProvider(std::unique_ptr< ILeakProvider > provider)
std::vector< LeakRecord > queryAll(const std::string &email)

References _, LeakAggregator::addProvider(), email, IdentityLeakConfig::hibpApiKey(), notify, LeakAggregator::queryAll(), running, and HashUtil::sha256().

Referenced by start().

◆ start()

void LeakMonitor::start ( )

Definition at line 46 of file LeakMonitor.cpp.

47{
48 if (running)
49 return;
50
51 running = true;
52 worker = std::thread(&LeakMonitor::loop, this);
53}
std::thread worker

References loop(), running, and worker.

◆ stop()

void LeakMonitor::stop ( )

Definition at line 55 of file LeakMonitor.cpp.

56{
57 running = false;
58
59 if (worker.joinable())
60 worker.join();
61}

References running, and worker.

Referenced by ~LeakMonitor().

Member Data Documentation

◆ email

std::string LeakMonitor::email
private

Definition at line 45 of file LeakMonitor.hpp.

Referenced by LeakMonitor(), and loop().

◆ notify

NotifyFn LeakMonitor::notify
private

Definition at line 46 of file LeakMonitor.hpp.

Referenced by LeakMonitor(), and loop().

◆ running

std::atomic<bool> LeakMonitor::running {false}
private

Definition at line 48 of file LeakMonitor.hpp.

Referenced by LeakMonitor(), loop(), start(), and stop().

◆ worker

std::thread LeakMonitor::worker
private

Definition at line 47 of file LeakMonitor.hpp.

Referenced by start(), and stop().


The documentation for this class was generated from the following files: