refactor: STCP connections as ETCP links (is_tcp)
- Add is_tcp, tcp_link, tcp_reconnect_* fields to ETCP_LINK - Remove transport_link from ETCP_CONN, add tcp_link_count - stcp_link: replace embedded etcp_conn with pointer; add etcp_link backpointer - stcp_link: link_rx_cb routes ETCP data to etcp_conn_input - stcp_link: call on_close_cb in close - New TCP functions: etcp_link_enter_ready_tcp, etcp_tcp_link_start_connect, etcp_tcp_link_start_reconnect, tcp_link_close_cb, etcp_tcp_send - etcp_link_new: handle NULL conn for TCP links; skip enter_init for TCP - etcp_link_close: close stcp_link for TCP - etcp_encrypt_send: redirect TCP to etcp_tcp_send (skips AES-CCM) - tcp_server_on_link: create ETCP_LINK(is_tcp=1) + enter_ready_tcp - etcp_connect: TCP addrs -> etcp_tcp_link_start_connect - Remove ctx->tcp_link/tcp_ready - test_stcp_traffic: find stcp_link via links->is_tcp instead of transport_link - 66/68 tests pass; 2 STCP tests expected to fail (integration not complete)
This commit is contained in:
1 parent
937af4c26a
commit
d773f1724a
1705 files changed
+187
-1082154
No files matched your search
@@ -1,133 +0,0 @@
|
||||
#include <QApplication>
|
||||
#include <QPalette>
|
||||
#include <QStyleFactory>
|
||||
#include <QDir>
|
||||
#include <cstdio>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#endif
|
||||
#include "mainwindow.h"
|
||||
#include "../db/db_manager.h"
|
||||
#include "../transport/node_config.h"
|
||||
#include "../transport/utun_node.h"
|
||||
#include "../../lib/debug_config.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
static UtunNode* g_ctrl_node = nullptr;
|
||||
|
||||
static DWORD count_threads(void) {
|
||||
DWORD pid = GetCurrentProcessId(), count = 0;
|
||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
||||
if (snap == INVALID_HANDLE_VALUE) return 0;
|
||||
THREADENTRY32 te = { sizeof(te) };
|
||||
if (Thread32First(snap, &te)) {
|
||||
do { if (te.th32OwnerProcessID == pid) count++; }
|
||||
while (Thread32Next(snap, &te));
|
||||
}
|
||||
CloseHandle(snap);
|
||||
return count;
|
||||
}
|
||||
|
||||
static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType) {
|
||||
if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) {
|
||||
if (g_ctrl_node) g_ctrl_node->requestStop();
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct ShutdownSentinel {
|
||||
~ShutdownSentinel() {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "main: static destructors done");
|
||||
#ifdef _WIN32
|
||||
DWORD threads = count_threads();
|
||||
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "main: threads at exit=%lu", (unsigned long)threads);
|
||||
if (threads > 4) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_GENERAL, "main: %lu hanging threads, TerminateProcess", (unsigned long)threads);
|
||||
fflush(nullptr);
|
||||
TerminateProcess(GetCurrentProcess(), 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} g_shutdown_sentinel;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName("Chat");
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
app.setStyle(QStyleFactory::create("Fusion"));
|
||||
QPalette p;
|
||||
p.setColor(QPalette::Window, QColor(53, 53, 53));
|
||||
p.setColor(QPalette::WindowText, QColor(220, 220, 220));
|
||||
p.setColor(QPalette::Base, QColor(42, 42, 42));
|
||||
p.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
|
||||
p.setColor(QPalette::ToolTipBase, QColor(25, 25, 25));
|
||||
p.setColor(QPalette::ToolTipText, QColor(220, 220, 220));
|
||||
p.setColor(QPalette::Text, QColor(220, 220, 220));
|
||||
p.setColor(QPalette::Button, QColor(53, 53, 53));
|
||||
p.setColor(QPalette::ButtonText, QColor(220, 220, 220));
|
||||
p.setColor(QPalette::BrightText, Qt::red);
|
||||
p.setColor(QPalette::Link, QColor(42, 130, 218));
|
||||
p.setColor(QPalette::Highlight, QColor(42, 130, 218));
|
||||
p.setColor(QPalette::HighlightedText, Qt::white);
|
||||
p.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
|
||||
p.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127));
|
||||
app.setPalette(p);
|
||||
|
||||
QString cfgPath = QCoreApplication::applicationDirPath() + "/chatgui.cfg";
|
||||
|
||||
NodeConfig cfg(cfgPath);
|
||||
bool needSave = false;
|
||||
|
||||
if (!cfg.exists()) {
|
||||
if (!cfg.create("chatgui", 1333)) {
|
||||
qCritical("Failed to create config: %s", qPrintable(cfgPath));
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (!cfg.load()) {
|
||||
qCritical("Cannot open/read config file: %s", qPrintable(cfgPath));
|
||||
return 1;
|
||||
}
|
||||
if (cfg.hasErrors()) {
|
||||
for (const auto& err : cfg.errors())
|
||||
fprintf(stderr, "CONFIG ERROR: %s\n", qPrintable(err));
|
||||
return 1;
|
||||
}
|
||||
if (cfg.privKey().length() != 64 || cfg.pubKey().length() != 64) {
|
||||
qWarning("Config: keys missing/invalid, regenerating identity");
|
||||
cfg.generateIdentity();
|
||||
needSave = true;
|
||||
}
|
||||
if (cfg.nodeId().length() != 16) {
|
||||
qWarning("Config: my_node_id missing/invalid, regenerating identity");
|
||||
cfg.generateIdentity();
|
||||
needSave = true;
|
||||
}
|
||||
if (needSave)
|
||||
cfg.save();
|
||||
}
|
||||
|
||||
QString dbPath = cfg.dbPath();
|
||||
if (dbPath.isEmpty()) dbPath = "chat_data";
|
||||
if (!QDir::isAbsolutePath(dbPath))
|
||||
dbPath = QCoreApplication::applicationDirPath() + "/" + dbPath;
|
||||
QDir(dbPath).mkpath(".");
|
||||
|
||||
DbManager db;
|
||||
MainWindow w(nullptr, &db, cfgPath, dbPath, cfg.debugFile(),
|
||||
cfg.debugLevel(), cfg.debugCategories());
|
||||
w.show();
|
||||
|
||||
#ifdef _WIN32
|
||||
g_ctrl_node = w.utunNode();
|
||||
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
|
||||
#endif
|
||||
|
||||
int ret = app.exec();
|
||||
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "main: app.exec() returned %d", ret);
|
||||
return ret;
|
||||
}
|
||||
Reference in new issue
Block a user