wg: WireGuard client interface header (platform-agnostic)

This commit is contained in:
Zac Gaetano 2026-05-06 19:18:21 -04:00
parent b72eb3c7f1
commit bf05b78282

64
src/wg/wgclient.h Normal file
View file

@ -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 <functional>
#include <memory>
#include <string>
namespace wg {
// Callback types
using LogFn = std::function<void(const std::string &msg)>;
using ErrorFn = std::function<void(const std::string &msg)>;
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<ClientImpl> m_impl;
LogFn m_log;
ErrorFn m_error;
};
} // namespace wg