Enable VibeChat UTUN service and package the Wintun driver
Add a settings button to open the current config in an external editor. Wait for core, UTUN and chat startup before reporting readiness; verify startup failures and restarts. Include Wintun DLL and license notices in Windows builds and installers.
This commit is contained in:
1 parent
bdb6bf80a4
commit
ffe563bb9f
13 files changed
+253
-26
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include "utun_node.h"
|
||||
#include "stream_bridge.h"
|
||||
#include <cinttypes>
|
||||
#include <utility>
|
||||
#include <QDir>
|
||||
#include "../../lib/socket_compat.h"
|
||||
|
||||
@@ -47,15 +48,12 @@ bool UtunNode::start(const QString& configPath) {
|
||||
m_configPath = configPath;
|
||||
m_stop = false;
|
||||
m_running = true;
|
||||
m_thread = std::thread(&UtunNode::runLoop, this);
|
||||
|
||||
for (int i = 0; i < 50 && m_running && !m_instance; ++i)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
if (!m_instance) {
|
||||
m_stop = true;
|
||||
std::promise<bool> startup;
|
||||
auto ready = startup.get_future();
|
||||
m_thread = std::thread(&UtunNode::runLoop, this, std::move(startup));
|
||||
if (!ready.get()) {
|
||||
if (m_thread.joinable()) m_thread.join();
|
||||
m_running = false;
|
||||
finalize();
|
||||
return false;
|
||||
}
|
||||
emit started();
|
||||
@@ -125,7 +123,7 @@ bool UtunNode::ntpEnabled() const {
|
||||
return m_instance ? m_instance->ntp.enabled : false;
|
||||
}
|
||||
|
||||
void UtunNode::runLoop() {
|
||||
void UtunNode::runLoop(std::promise<bool> startup) {
|
||||
debug_config_init();
|
||||
debug_enable_function_name(0);
|
||||
|
||||
@@ -180,11 +178,13 @@ void UtunNode::runLoop() {
|
||||
g_debug_config.thread_marker = 2;
|
||||
}
|
||||
|
||||
utun_instance_set_tun_init_enabled(0);
|
||||
utun_instance_set_tun_init_enabled(1);
|
||||
|
||||
struct UASYNC* ua = uasync_create();
|
||||
if (!ua) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_SYS, "desktop startup: uasync_create failed");
|
||||
QMetaObject::invokeMethod(this, [this] { emit error("uasync_create failed"); });
|
||||
startup.set_value(false);
|
||||
return;
|
||||
}
|
||||
m_ua = ua;
|
||||
@@ -194,9 +194,11 @@ void UtunNode::runLoop() {
|
||||
* иначе auto_socket не сможет сохранить/переиспользовать порты (БД ещё не открыта). */
|
||||
struct utun_config* cfg = parse_config(m_configPath.toUtf8().constData());
|
||||
if (!cfg) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "desktop startup: parse_config failed path=%s", qPrintable(m_configPath));
|
||||
QMetaObject::invokeMethod(this, [this] { emit error("parse_config failed"); });
|
||||
uasync_destroy(ua, 0);
|
||||
m_ua = nullptr;
|
||||
startup.set_value(false);
|
||||
return;
|
||||
}
|
||||
cfg->global.db_sync_enabled = 1;
|
||||
@@ -207,25 +209,35 @@ void UtunNode::runLoop() {
|
||||
|
||||
m_instance = utun_instance_create_from_config(ua, cfg);
|
||||
if (!m_instance) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_SYS, "desktop startup: instance creation failed");
|
||||
free_config(cfg);
|
||||
QMetaObject::invokeMethod(this, [this] { emit error("utun_instance_create_from_config failed"); });
|
||||
uasync_destroy(ua, 0);
|
||||
m_ua = nullptr;
|
||||
startup.set_value(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_instance->test_user_ptr = this;
|
||||
|
||||
/* set ua for gui_bridge before init, so GUI can post */
|
||||
gui_bridge_set_uasync(ua);
|
||||
gui_bridge_set_inst(m_instance);
|
||||
|
||||
if (utun_core_start(m_instance) != 0) {
|
||||
QMetaObject::invokeMethod(this, [this] { emit error("utun_instance_init failed"); });
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_SYS, "desktop startup: utun_core_start failed");
|
||||
QMetaObject::invokeMethod(this, [this] { emit error("utun_core_start failed"); });
|
||||
utun_instance_destroy(m_instance);
|
||||
m_instance = nullptr;
|
||||
uasync_destroy(ua, 0);
|
||||
m_ua = nullptr;
|
||||
startup.set_value(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (utun_service_start(m_instance) != 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "desktop startup: UTUN service failed tun_enabled=%d interface=%s",
|
||||
cfg->global.tun_enabled, cfg->global.tun_ifname);
|
||||
QMetaObject::invokeMethod(this, [this] { emit error("utun_service_start failed; check TUN configuration, driver and permissions"); });
|
||||
utun_instance_destroy(m_instance); m_instance = nullptr;
|
||||
uasync_destroy(ua, 0); m_ua = nullptr;
|
||||
startup.set_value(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -242,9 +254,12 @@ void UtunNode::runLoop() {
|
||||
});
|
||||
|
||||
if (chat_service_start(m_instance) != 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "desktop startup: chat_service_start failed");
|
||||
QMetaObject::invokeMethod(this, [this] { emit error("chat_service_start failed"); });
|
||||
utun_instance_destroy(m_instance); m_instance = nullptr;
|
||||
uasync_destroy(ua, 0); m_ua = nullptr; return;
|
||||
uasync_destroy(ua, 0); m_ua = nullptr;
|
||||
startup.set_value(false);
|
||||
return;
|
||||
}
|
||||
call_audio_init(m_instance);
|
||||
call_video_port_attach(m_instance);
|
||||
@@ -257,7 +272,13 @@ void UtunNode::runLoop() {
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "chat_core + chat_sync initialized");
|
||||
uasync_mark_running(ua);
|
||||
gui_bridge_set_uasync(ua);
|
||||
gui_bridge_set_inst(m_instance);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "utun_node: poll started ua=%p running=%d", (void*)ua, uasync_is_running(ua));
|
||||
DEBUG_INFO(DEBUG_CATEGORY_SYS, "desktop services ready: core=%d utun=%d chat=%d tun=%d interface=%s",
|
||||
m_instance->core_started, m_instance->utun_started, m_instance->chat_started,
|
||||
cfg->global.tun_enabled, cfg->global.tun_ifname);
|
||||
startup.set_value(true);
|
||||
|
||||
while (!m_stop) {
|
||||
uasync_poll(ua, 100);
|
||||
|
||||
Reference in new issue
Block a user