1. Overview
Daemon orchestration interface. Declares the central service that coordinates monitoring, rules, firewall, NFQUEUE, process enrichment, UI communication, statistics, task scheduling and verdict caching.
The original source path is:
include/bsc/service/DaemonService.hpp
2. Role in the Daemon
This file participates in the privileged BastionGuard Secure Connection daemon. It uses the shared bsc models and follows the daemon-wide fallback strategy: optional high-fidelity backends are used when available, while portable polling or stub behavior preserves service startup.
3. Namespaces
bsc::service
4. Dependencies and Included Interfaces
bsc/config/Config.hppbsc/fw/Firewall.hppbsc/net/DnsResolver.hppbsc/netlink/ProcEventMonitor.hppbsc/net/SocketSnapshot.hppbsc/netfilter/NFQueue.hppbsc/proc/ProcMon.hppbsc/rule/Rule.hppbsc/stats/Statistics.hppbsc/task/TaskRunner.hppbsc/ui/UIClient.hppatomicchronofilesystemmutexoptionalsetunordered_map
5. Declared Types
class DaemonServicestruct CachedVerdict
6. State and Data Members
The interface declares the following relevant state members:
bool allow_blocking_ask = true)bsc::config::Config config_bsc::fw::Firewall firewall_bsc::net::DnsResolver dns_bsc::netlink::ProcEventMonitor proc_events_bsc::net::SocketSnapshot net_bsc::netfilter::NFQueue nfqueue_bsc::proc::ProcMon proc_bsc::rule::Loader rules_bsc::stats::Statistics stats_bsc::ui::UIClient ui_bsc::task::TaskRunner tasks_std::mutex seen_mutex_std::set<std::string> seen_mutable std::mutex rules_reload_mutex_mutable std::mutex flow_mutex_std::unordered_map<std::string, std::pair<bsc::model::Connection, std::chrono::steady_clock::time_point>> recent_flows_std::string actionstd::string durationstd::chrono::steady_clock::time_point expires_atmutable std::mutex verdict_cache_mutex_std::unordered_map<std::string, CachedVerdict> verdict_cache_
7. API and Functions
The file declares or implements the following callable entry points:
public: explicit DaemonService(bsc::config::Config config)void run()void stop()private: void scan_connections()bool desktop_allows_activity() constvoid set_desktop_active(bool active)void handle_proc_event(const bsc::netlink::ProcEvent& ev)void heartbeat()void reload_rules()void reload_firewall()void handle_notification(const bsc::ui::NotificationEvent& ev)bsc::netfilter::Decision decide_connection(bsc::model::Connection conn, bool realtime, bool allow_blocking_ask = true)void persist_learned_rule(const bsc::model::Connection& conn, const bsc::rule::Rule& decision)void remember_connection(const bsc::model::Connection& conn)void enrich_from_recent_flows(bsc::model::Connection& conn)void enrich_from_recent_processes(bsc::model::Connection& conn, std::chrono::milliseconds max_age = std::chrono::milliseconds(5000))bool rules_changed() conststatic std::chrono::milliseconds parse_interval(const std::string& v, std::chrono::milliseconds def = std::chrono::seconds(5))static std::string verdict_key(const bsc::model::Connection& c)std::optional<CachedVerdict> verdict_lookup(const bsc::model::Connection& c) constvoid verdict_store(const bsc::model::Connection& c, const bsc::rule::Rule& r)explicit DaemonService(bsc::config::Config config)
8. External Resources and Protocol Values
Relevant paths, endpoints, command names or policy values referenced by this file include:
bsc/config/Config.hppbsc/fw/Firewall.hppbsc/net/DnsResolver.hppbsc/netlink/ProcEventMonitor.hppbsc/net/SocketSnapshot.hppbsc/netfilter/NFQueue.hppbsc/proc/ProcMon.hppbsc/rule/Rule.hppbsc/stats/Statistics.hppbsc/task/TaskRunner.hppbsc/ui/UIClient.hppallow
9. Concurrency and Lifecycle
- Protects mutable shared data with std::mutex.
- Uses atomic flags for lifecycle or activity state.
10. Security Considerations
- The component processes privileged operating-system or network data and should run with only the capabilities required by its backend.
11. Implementation Considerations
- Shared state is protected by mutexes; callers should avoid holding external locks while invoking callbacks.
- Atomic flags are used for low-cost lifecycle or activity state coordination.
- Linux /proc data can disappear between reads because processes and sockets are inherently short-lived.
12. Source Metrics
| Metric | Value |
|---|---|
| File size | 4456 bytes |
| Lines | 99 |
| Detected API entries | 22 |
| Detected types | 2 |
