DaemonService.hpp

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.hpp
  • bsc/fw/Firewall.hpp
  • bsc/net/DnsResolver.hpp
  • bsc/netlink/ProcEventMonitor.hpp
  • bsc/net/SocketSnapshot.hpp
  • bsc/netfilter/NFQueue.hpp
  • bsc/proc/ProcMon.hpp
  • bsc/rule/Rule.hpp
  • bsc/stats/Statistics.hpp
  • bsc/task/TaskRunner.hpp
  • bsc/ui/UIClient.hpp
  • atomic
  • chrono
  • filesystem
  • mutex
  • optional
  • set
  • unordered_map

5. Declared Types

  • class DaemonService
  • struct 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 action
  • std::string duration
  • std::chrono::steady_clock::time_point expires_at
  • mutable 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() const
  • void 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() const
  • static 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) const
  • void 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.hpp
  • bsc/fw/Firewall.hpp
  • bsc/net/DnsResolver.hpp
  • bsc/netlink/ProcEventMonitor.hpp
  • bsc/net/SocketSnapshot.hpp
  • bsc/netfilter/NFQueue.hpp
  • bsc/proc/ProcMon.hpp
  • bsc/rule/Rule.hpp
  • bsc/stats/Statistics.hpp
  • bsc/task/TaskRunner.hpp
  • bsc/ui/UIClient.hpp
  • allow

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

MetricValue
File size4456 bytes
Lines99
Detected API entries22
Detected types2