diff --git a/src/wg/wgclient.h b/src/wg/wgclient.h new file mode 100644 index 0000000..a3b1149 --- /dev/null +++ b/src/wg/wgclient.h @@ -0,0 +1,64 @@ +#pragma once +// src/wg/wgclient.h — Platform-agnostic WireGuard tunnel interface for Artemis. +// +// Artemis (the host / Sunshine fork) uses this to connect to the DragonRelay +// WireGuard server so that remote DragonMoonlight clients can reach it over +// the 10.99.0.0/24 subnet without needing mDNS. +// +// Platform implementations: +// Windows : wgclient_win.cpp — Wintun kernel TUN + boringtun FFI +// Linux : wgclient_linux.cpp — /dev/net/tun + boringtun FFI +// +// Usage: +// wg::Config cfg; +// wg::Client client; +// client.start(cfg); // blocks until the tunnel is up or throws +// // ... Artemis runs, registers with DragonRelay ... +// client.stop(); + +#include "wgconfig.h" + +#include +#include +#include + +namespace wg { + +// Callback types +using LogFn = std::function; +using ErrorFn = std::function; + +class ClientImpl; // forward — platform-specific + +class Client { +public: + Client(); + ~Client(); + + // Set optional logging/error callbacks before calling start(). + void setLogCallback(LogFn fn) { m_log = std::move(fn); } + void setErrorCallback(ErrorFn fn){ m_error = std::move(fn); } + + // Start the WireGuard tunnel. Blocks until the TUN device is configured + // and the initial handshake has been dispatched. Throws std::runtime_error + // on failure. Must not be called while already running. + void start(const Config &cfg); + + // Stop the tunnel and release all resources. Safe to call even if never + // started. Blocks until I/O threads have joined. + void stop(); + + // True if the tunnel is currently active. + bool running() const; + + // The local WireGuard address assigned to this host (e.g. "10.99.0.3"). + // Empty if not running. + std::string localIP() const; + +private: + std::unique_ptr m_impl; + LogFn m_log; + ErrorFn m_error; +}; + +} // namespace wg