1. Overview
Little-Snitch-style GTK connection monitor with an application summary view, per-application connection details, verdict editing, grouped connection counts, estimated traffic, a live activity sparkline, and retained JSON-line history.
File role: Header Interface. The file contains 301 lines and belongs to the pages/ConnectionsPage.hpp path.
The companion file is pages/ConnectionsPage.cpp.
2. Component Responsibilities
- Declare the component API, owned state, callbacks, and data structures.
- Build application and detailed tree views
- Aggregate new connections by application
- Group repeated destination tuples
- Maintain a bounded per-application detail ring
- Switch between application overview and detail views
- Allow verdict changes through a combo renderer
- Send selected replies to UIServer
- Persist, load, prune, and clear connection history
- Update the live sparkline from recent event buckets
3. Dependencies and Integration
Project-level dependencies:
gtkmm.h../ipc/UIServer.hpp
System and library dependencies:
stringcstdintvectordequeunordered_mapchrono
4. Declared Types
ConnectionsPage
Declares a class derived from or associated with public Gtk::Box.
DetailColumns
Declares a struct derived from or associated with public Gtk::TreeModel::ColumnRecord.
AppColumns
Declares a struct derived from or associated with public Gtk::TreeModel::ColumnRecord.
ComboCol
Declares a struct derived from or associated with public Gtk::TreeModel::ColumnRecord.
AppStats
Declares a struct.
DetailEvent
Declares a struct.
5. Constants and Fixed Configuration
The file declares or uses the following fixed values:
static constexpr uint64_t kEstimatedBytesPerConn = 4096;
static constexpr size_t kDetailRingMax = 500;
static constexpr int64_t kRetentionSeconds = 7 * 24 * 3600;
static constexpr int kSparkBucketMs = 500;
static constexpr int kSparkBucketsMax = 120;
6. Owned State and UI Members
User-interface members
Gtk::TreeModelColumn<Glib::ustring> col_time;Gtk::TreeModelColumn<Glib::ustring> col_app;Gtk::TreeModelColumn<Glib::ustring> col_verdict;Gtk::TreeModelColumn<uint32_t> col_count;Gtk::TreeModelColumn<uint32_t> col_pid;Gtk::TreeModelColumn<Glib::ustring> col_protocol;Gtk::TreeModelColumn<Glib::ustring> col_src_ip;Gtk::TreeModelColumn<Glib::ustring> col_host;Gtk::TreeModelColumn<Glib::ustring> col_ip;Gtk::TreeModelColumn<uint32_t> col_port;Gtk::TreeModelColumn<Glib::ustring> col_args;Gtk::TreeModelColumn<bool> col_pending;Gtk::TreeModelColumn<Glib::ustring> col_group_key;Gtk::TreeModelColumn<Glib::ustring> col_icon_name;Gtk::TreeModelColumn<uint32_t> col_conn_count;Gtk::TreeModelColumn<Glib::ustring> col_bytes_str;Gtk::TreeModelColumn<uint64_t> col_bytes_raw;Gtk::TreeModelColumn<Glib::ustring> col_last_seen;Gtk::TreeModelColumn<int64_t> col_last_ts;Gtk::TreeModelColumn<Glib::ustring> val;Glib::RefPtr<Gtk::ListStore> m_verdictModel;Glib::RefPtr<Gtk::ListStore> m_store;Glib::RefPtr<Gtk::ListStore> m_appStore;Gtk::TreeView m_treeView;Gtk::TreeView m_appTreeView;Gtk::ScrolledWindow m_scroll;Gtk::ScrolledWindow m_appScroll;Gtk::Stack m_stack;Gtk::Box m_toolbar { Gtk::Orientation::HORIZONTAL, 6 };Gtk::Button m_clearBtn;Gtk::Button m_backBtn;Gtk::Label m_detailTitle;Gtk::SearchEntry m_search;Gtk::Frame m_sparkFrame;Gtk::Box m_sparkBox { Gtk::Orientation::VERTICAL, 4 };Gtk::Label m_sparkLabel;Gtk::DrawingArea m_sparkArea;std::unordered_map<std::string, Gtk::TreeModel::iterator> m_groupIndex;std::unordered_map<std::string, Gtk::TreeModel::iterator> m_appIndex;
Threading, dispatch, and callback state
sigc::connection m_sparkTick;
Data and configuration state
static constexpr uint64_t kEstimatedBytesPerConn = 4096;uint32_t conn_count = 0;uint64_t estimated_bytes = 0;int64_t last_seen_epoch = 0;std::string time;int64_t ts_epoch{0};uint32_t pid{0};std::string protocol;std::string src_ip;std::string host;std::string ip;uint32_t port{0};std::string args;std::string verdict;bool pending{false};uint32_t count{1};static constexpr size_t kDetailRingMax = 500;std::unordered_map<std::string, std::deque<DetailEvent>> m_detailRings;static constexpr int64_t kRetentionSeconds = 7 * 24 * 3600;static constexpr int kSparkBucketMs = 500;static constexpr int kSparkBucketsMax = 120;std::deque<uint64_t> m_sparkBuckets;uint64_t m_currentBucket = 0;DetailColumns m_columns;AppColumns m_appColumns;ComboCol m_comboCol;std::unordered_map<std::string, AppStats> m_appStats;std::string m_currentAppFilter;std::unordered_map<std::string, std::string> m_iconCache;std::unordered_map<std::string, std::string> m_desktopIndex;bool m_desktopIndexBuilt = false;UIServer& m_uiServer;
7. Functions and Methods
The file exposes or implements 36 detected function or method signatures.
1. ConnectionsPage
explicit ConnectionsPage(UIServer& uiServer)
Implements the connections page operation declared by this component.
2. ~ConnectionsPage
~ConnectionsPage() override
Releases resources owned by the object and stops any active background integration.
3. onNewConnection
void onNewConnection(const ConnectionInfo& info, bool pending = true)
Handles the new connection callback or user event.
4. setLastVerdict
void setLastVerdict(const std::string& verdict)
Updates last verdict and synchronizes dependent state.
5. saveLog
void saveLog() const
Serializes or persists log.
6. loadLog
void loadLog()
Loads log from its persistent or runtime source.
7. clearLog
void clearLog()
Clears log and resets related state.
8. logPath
static std::string logPath()
Implements the log path operation declared by this component.
9. buildVerdictModel
void buildVerdictModel()
Builds and configures the verdict model user-interface or internal structure.
10. buildToolbar
void buildToolbar()
Builds and configures the toolbar user-interface or internal structure.
11. buildAppTreeView
void buildAppTreeView()
Builds and configures the app tree view user-interface or internal structure.
12. buildDetailTreeView
void buildDetailTreeView()
Builds and configures the detail tree view user-interface or internal structure.
13. buildSparkline
void buildSparkline()
Builds and configures the sparkline user-interface or internal structure.
14. showAppsView
void showAppsView()
Displays apps view.
15. showDetailView
void showDetailView(const std::string& app)
Displays detail view.
16. onAppActivated
void onAppActivated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column)
Handles the app activated callback or user event.
17. onBackClicked
void onBackClicked()
Handles the back clicked callback or user event.
18. onVerdictEdited
void onVerdictEdited(const Glib::ustring& pathStr, const Glib::ustring& newText)
Handles the verdict edited callback or user event.
19. onClear
void onClear()
Handles the clear callback or user event.
20. addOrUpdateDetailRow
void addOrUpdateDetailRow(const ConnectionInfo& info, const std::string& app_display, const std::string& argsStr, bool pending)
Adds or update detail row to the relevant model or index.
21. updateAppAggregate
void updateAppAggregate(const std::string& app_display)
Updates app aggregate using the latest runtime data.
22. pushDetailEvent
void pushDetailEvent(const std::string& app_display, const DetailEvent& ev)
Implements the push detail event operation declared by this component.
23. populateDetailFromRing
void populateDetailFromRing(const std::string& app_display)
Implements the populate detail from ring operation declared by this component.
24. onSparkTick
bool onSparkTick()
Handles the spark tick callback or user event.
25. onSparkDraw
void onSparkDraw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
Handles the spark draw callback or user event.
26. resolveIconName
std::string resolveIconName(const std::string& app_display)
Resolves icon name into normalized metadata or runtime data.
27. buildDesktopIndex
void buildDesktopIndex()
Builds and configures the desktop index user-interface or internal structure.
28. currentTime
std::string currentTime()
Implements the current time operation declared by this component.
29. parseReplyAction
ReplyAction parseReplyAction(const Glib::ustring& text) const
Parses reply action into a structured representation.
30. groupKeyFor
static std::string groupKeyFor(const std::string& app, const std::string& protocol, const std::string& host, const std::string& ip, uint32_t port)
Implements the group key for operation declared by this component.
31. formatBytes
static std::string formatBytes(uint64_t n)
Formats bytes for display or persistence.
32. formatEpochTime
static std::string formatEpochTime(int64_t epoch)
Formats epoch time for display or persistence.
33. jsonEscapeStr
static std::string jsonEscapeStr(const std::string& s)
Implements the json escape str operation declared by this component.
34. jsonFieldStr
static std::string jsonFieldStr(const std::string& json, const std::string& key)
Implements the json field str operation declared by this component.
35. jsonFieldUint
static uint32_t jsonFieldUint(const std::string& json, const std::string& key)
Implements the json field uint operation declared by this component.
36. jsonFieldBool
static bool jsonFieldBool(const std::string& json, const std::string& key)
Implements the json field bool operation declared by this component.
8. Runtime Flow
- Build application and detailed tree views
- Aggregate new connections by application
- Group repeated destination tuples
- Maintain a bounded per-application detail ring
- Switch between application overview and detail views
- Allow verdict changes through a combo renderer
- Send selected replies to UIServer
- Persist, load, prune, and clear connection history
- Update the live sparkline from recent event buckets
9. Runtime and Security Considerations
- Limits in-memory detail history.
- Escapes JSON strings before persistence.
- Uses typed ReplyAction values for edited verdicts.
- Retains only events inside the configured seven-day window.
10. Error Handling and Operational Notes
- Errors are propagated through the return type, callbacks, or the owning controller.
11. Source Integrity
Relative source path: pages/ConnectionsPage.hpp
SHA-256:
eb439390eaa581301f0fedf13f7468dc1bb1578d14f4303816ece48031fb3dc0
12. Licensing
The source header identifies this component as distributed under the GNU General Public License version 3. BastionGuard branding and trademarks remain subject to the notices stated in the source file.
