chatgui: integrate UtunNode + NodeConfig, replace MsgClient
- Add NodeConfig: simplified INI config manager for embedded uTun node - X25519 key generation via OpenSSL EVP - Random node_id generation - addServer/removeServer, addClient/removeClient API - Auto-creates config with default server on first run - Integrate UtunNode into MainWindow: - Creates NodeConfig in ~/.config/chatgui/node.conf - Starts embedded uTun node (no TUN, no msg_transport) - In separate thread with uasync_poll event loop - Replace MsgClient (TCP IPC) with UtunNode (direct calls): - ChatPropagator now uses UtunNode for send/recv - send(uint64_t, QByteArray) replaces sendTo - messageReceived signal replaces received signal - MainWindow cleanup: remove MsgClient, add UtunNode+NodeConfig
This commit is contained in:
1 parent
118ab04788
commit
7628f77b93
7 files changed
+340
-26
No files matched your search
@@ -5,14 +5,16 @@
|
||||
#include "invitedialog.h"
|
||||
#include "invite_link.h"
|
||||
#include "../db/db_manager.h"
|
||||
#include "../transport/msg_client.h"
|
||||
#include "../transport/utun_node.h"
|
||||
#include "../transport/node_config.h"
|
||||
#include "../transport/chat_propagator.h"
|
||||
#include "../transport/crypto.h"
|
||||
#include <QSplitter>
|
||||
#include <QCloseEvent>
|
||||
#include <QApplication>
|
||||
#include <QStyle>
|
||||
#include <QMessageBox>
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent, DbManager* db)
|
||||
: QMainWindow(parent)
|
||||
@@ -22,8 +24,6 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db)
|
||||
, m_trayIcon(nullptr)
|
||||
, m_trayMenu(nullptr)
|
||||
, m_db(db)
|
||||
, m_client(nullptr)
|
||||
, m_propagator(nullptr)
|
||||
{
|
||||
setWindowTitle("Chat");
|
||||
resize(900, 600);
|
||||
@@ -31,12 +31,8 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db)
|
||||
setupTray();
|
||||
|
||||
if (m_db && m_db->isOpen()) {
|
||||
m_client = new MsgClient(this);
|
||||
m_propagator = new ChatPropagator(m_client, m_db, this);
|
||||
m_messageList->setPropagator(m_propagator);
|
||||
|
||||
connect(m_propagator, &ChatPropagator::messageReceived,
|
||||
m_messageList, &MessageList::addMessage);
|
||||
setupNode();
|
||||
setupMessaging();
|
||||
|
||||
connect(m_channelList, &ChannelList::channelSelected,
|
||||
this, [this](const QString& channelId) {
|
||||
@@ -56,6 +52,11 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db)
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
if (m_node) { m_node->stop(); delete m_node; m_node = nullptr; }
|
||||
delete m_config;
|
||||
}
|
||||
|
||||
void MainWindow::setupUi() {
|
||||
auto *splitter = new QSplitter(Qt::Horizontal, this);
|
||||
|
||||
@@ -76,6 +77,45 @@ void MainWindow::setupUi() {
|
||||
setCentralWidget(splitter);
|
||||
}
|
||||
|
||||
void MainWindow::setupNode() {
|
||||
QString configDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
QDir().mkpath(configDir);
|
||||
QString configPath = configDir + "/node.conf";
|
||||
|
||||
m_config = new NodeConfig(configPath);
|
||||
if (!m_config->exists()) {
|
||||
if (!m_config->create("chatgui", 1333)) {
|
||||
qWarning("Failed to create node config");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
m_config->load();
|
||||
}
|
||||
|
||||
m_node = new UtunNode(this);
|
||||
connect(m_node, &UtunNode::error, this, [](const QString& msg) {
|
||||
qWarning("UtunNode error: %s", qPrintable(msg));
|
||||
});
|
||||
connect(m_node, &UtunNode::started, this, []() {
|
||||
qDebug("UtunNode started");
|
||||
});
|
||||
connect(m_node, &UtunNode::stopped, this, []() {
|
||||
qDebug("UtunNode stopped");
|
||||
});
|
||||
|
||||
if (!m_node->start(configPath))
|
||||
qWarning("Failed to start UtunNode");
|
||||
}
|
||||
|
||||
void MainWindow::setupMessaging() {
|
||||
if (!m_node || !m_node->isRunning()) return;
|
||||
m_propagator = new ChatPropagator(m_node, m_db, this);
|
||||
m_messageList->setPropagator(m_propagator);
|
||||
|
||||
connect(m_propagator, &ChatPropagator::messageReceived,
|
||||
m_messageList, &MessageList::addMessage);
|
||||
}
|
||||
|
||||
void MainWindow::setupTray() {
|
||||
m_trayIcon = new QSystemTrayIcon(this);
|
||||
m_trayIcon->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
|
||||
@@ -119,9 +159,12 @@ void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) {
|
||||
void MainWindow::showInviteDialog(const QString& channelId) {
|
||||
if (!m_db || !m_db->isOpen()) return;
|
||||
|
||||
QByteArray pubkey = m_db->getLocalPubkey();
|
||||
QByteArray pubkey;
|
||||
if (m_config && !m_config->pubKey().isEmpty())
|
||||
pubkey = QByteArray::fromHex(m_config->pubKey().toLatin1());
|
||||
|
||||
if (pubkey.size() != 32) {
|
||||
QMessageBox::warning(this, "Ошибка", "Не удалось получить публичный ключ узла.");
|
||||
QMessageBox::warning(this, "Error", "Failed to get node public key.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -129,7 +172,7 @@ void MainWindow::showInviteDialog(const QString& channelId) {
|
||||
|
||||
QString link = encodeInviteLink(channelId, pubkey, addrs);
|
||||
if (link.isEmpty()) {
|
||||
QMessageBox::warning(this, "Ошибка", "Не удалось сформировать пригласительную ссылку.");
|
||||
QMessageBox::warning(this, "Error", "Failed to create invite link.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user