1. Overview
The VpnPage.cpp file is a GTKmm WireGuard page implementation in BastionGuard.
Builds the VPN notebook, imports or generates tunnel configuration, connects/disconnects asynchronously, compares public IP before and after tunneling, manages kill-switch state, and refreshes connection status.
The documentation below is generated from the supplied source and covers its API surface, runtime responsibilities, data flow, filesystem or command interactions, concurrency model, and security considerations.
2. Source Inventory
- Original path:
vpn/VpnPage.cpp - Language: C++
- Source type:
.cpp - Line count: 575
- SHA-256:
04df287096312813e402fd0bc7e7b4cf81a756b67d221c8d084caafbbfd58068
3. Dependencies
The file declares the following compile-time dependencies:
Project
vpn/VpnPage.hpp
GTK/GLib
glibmm/i18n.hglibmm/main.h
C/C++ Runtime
threadutility
4. Types and Public Contract
No standalone class, structure, or enumeration is declared directly in this file.
5. API and Method Inventory
The following functions or methods are implemented in this file:
VpnPage::VpnPage()– Implements the operation represented by this API.sigc::mem_fun(*this, &VpnPage::on_poll_status), 4000); } VpnPage::~VpnPage()– Implements the operation represented by this API.VpnPage::labeled_row(const std::string& label, Gtk::Widget& field)– Implements the operation represented by this API.VpnPage::build_ui()– Constructs the corresponding GTK interface section.VpnPage::build_tab_connection()– Constructs the corresponding VPN notebook tab.sigc::mem_fun(*this, &VpnPage::on_connect_clicked)); btn_disconnect_.signal_clicked().connect( sigc::mem_fun(*this, &VpnPage::on_disconnect_clicked)); btn_refresh_ip_.signal_clicked().connect( sigc::mem_fun(*this, &VpnPage::on_refresh_ip_clicked)); return &tab_conn_; } Gtk::Widget* VpnPage::build_tab_config()– Implements the operation represented by this API.sigc::mem_fun(*this, &VpnPage::on_generate_keys_clicked)); btn_generate_.signal_clicked().connect( sigc::mem_fun(*this, &VpnPage::on_generate_config_clicked)); btn_browse_.signal_clicked().connect( sigc::mem_fun(*this, &VpnPage::on_browse_clicked)); btn_import_.signal_clicked().connect( sigc::mem_fun(*this, &VpnPage::on_import_clicked)); // La scheda config può crescere: avvolgila in uno scroller. auto scroller = Gtk::make_managed<Gtk::ScrolledWindow>(); scroller->set_child(tab_config_); scroller->set_policy(Gtk::PolicyType::NEVER, Gtk::PolicyType::AUTOMATIC); return scroller; } Gtk::Widget* VpnPage::build_tab_killswitch()– Implements the operation represented by this API.sigc::mem_fun(*this, &VpnPage::on_killswitch_toggled)); return &tab_ks_; } // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- void VpnPage::append_log(const std::string& line)– Implements the operation represented by this API.VpnPage::set_busy(bool b)– Enables or disables the VPN page busy state.VpnPage::refresh_state_ui(const WgStatus& st)– Maps backend tunnel state into labels and button sensitivity.VpnPage::run_async(std::function<OpResult()> work, std::function<void(OpResult)> done)– Runs a backend operation on a worker and returns the result to GTK.VpnPage::on_generate_keys_clicked()– Handles the on generate keys clicked user-interface action.VpnPage::on_generate_config_clicked()– Handles the on generate config clicked user-interface action.VpnPage::on_browse_clicked()– Handles the on browse clicked user-interface action.VpnPage::on_import_clicked()– Handles the on import clicked user-interface action.VpnPage::on_connect_clicked()– Handles the on connect clicked user-interface action.VpnPage::on_disconnect_clicked()– Handles the on disconnect clicked user-interface action.VpnPage::on_refresh_ip_clicked()– Handles the on refresh ip clicked user-interface action.VpnPage::refresh_public_ip(IpSlot slot)– Queries and stores the public address in the requested before/after slot.VpnPage::on_killswitch_toggled()– Handles the on killswitch toggled user-interface action.VpnPage::on_poll_status()– Handles the on poll status user-interface action.
6. Functional Architecture
Notebook Layout
- Connection tab: connect/disconnect, endpoint state, spinner, and public-IP comparison.
- Configuration tab: client key generation, server public key, endpoint, address, DNS, AllowedIPs, and
.confimport. - Kill-switch tab: a switch bound to backend nftables operations.
- A shared monospace log records all operations.
Asynchronous UI Model
- Runs backend work on detached worker threads.
- Returns results to GTK with
Glib::signal_idle().connect_once(). - Disables interactive controls while operations are active.
- Uses an alive flag to prevent callbacks from touching a destroyed page.
Connection Verification
- Captures the public IPv4 address before the tunnel.
- After connection, waits approximately 1.5 seconds before querying the tunneled address.
- Warns when the address does not change and points to AllowedIPs/NAT configuration.
7. Operational Flow
- Build the three-tab VPN interface and initialize the backend.
- Import a WireGuard file or populate the configuration form.
- Generate client keys when requested.
- Execute connect, disconnect, IP, or kill-switch work asynchronously.
- Return results to GTK, update labels/buttons, and append operation logs.
- Poll the backend periodically for current tunnel state.
8. Filesystem and External Command Surface
Referenced Absolute Paths
/percorso/al/tuo/wg0.conf
Commands or Security Primitives Referenced
ipshwg
9. Concurrency and Lifecycle
- Uses worker threads for operations that could block the GTK main loop.
- Uses GLib idle callbacks to update GTK from the main thread.
- Uses GLib timers for progress, deferred actions, polling, or cache readiness.
- Uses a lifetime guard so delayed callbacks do not access a destroyed widget.
10. Security Considerations
- Tunnel creation, route changes, DNS replacement, and nftables updates require elevated privileges.
- Private keys are held in memory and may be displayed in the configuration form.
- Imported WireGuard configuration must be treated as sensitive input.
- Failure paths must restore DNS, routes, and kill-switch state to avoid connectivity loss.
11. Implementation Considerations
- The implementation should remain synchronized with the matching header declarations.
- Detached worker threads require careful object-lifetime protection and deterministic shutdown behavior.
12. Licensing and Branding
The source is distributed under the GNU General Public License version 3.
The source header identifies BastionGuard™ as a trademark and states that the name and branding are not licensed under the GPL.
The software is provided without warranty, including implied warranties of merchantability or fitness for a particular purpose.
