Browse Source

chatgui: clean up log — remove spam, move messages to proper categories

A-B: Remove gui_bridge_post_uasync_fn log, MainWindow::onMessageReceived, InputBar send text
B1: Move lifecycle messages to GENERAL (utun_node, main, mainwindow, animtimer, sound_manager, messagelist, db_manager)
B2: Move chat events to CHAT_SYNC (MSG_RECEIVED, CHANNEL_UPDATED, CHANNEL_PEERS_ONLINE, DB_READY)
B3: Move peer/connect events to MEMBER_SYNC (CONNECT_RESULT, NEW_PEER, AUTO_CONNECT, NODE_CHANGED)
C: Lower level of C-side spam (recalc, send OK, PUSH ACK, connect_channel) INFO->DEBUG
D: Fix duplicate PUSH log line in db_sync.c
E: Add debounce to CHANNEL_PEERS_ONLINE — log only on change
Misc: Remove sort=0 from ChannelList::loadChannels, improve DB_READY message
topo_upd
evgeny 2 months ago
parent
commit
5feeb2c169
  1. 2
      src/chat/chat_channel.c
  2. 13
      src/chat/db_sync.c
  3. 2
      tools/chatgui/db/db_manager.cpp
  4. 2
      tools/chatgui/src/animtimer.cpp
  5. 8
      tools/chatgui/src/channellist.cpp
  6. 2
      tools/chatgui/src/inputbar.cpp
  7. 8
      tools/chatgui/src/main.cpp
  8. 16
      tools/chatgui/src/mainwindow.cpp
  9. 4
      tools/chatgui/src/messagelist.cpp
  10. 6
      tools/chatgui/src/sound_manager.cpp
  11. 23
      tools/chatgui/transport/gui_bridge_impl.cpp
  12. 21
      tools/chatgui/transport/utun_node.cpp

2
src/chat/chat_channel.c

@ -283,7 +283,7 @@ void chat_core_connect_channel(const char* ch_id) {
if (!group) { DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "%s: connect_channel — group not found ch=%s gid=%016llx total_groups=%d", CC_ID, ch_id, (unsigned long long)gid, queue_entry_count(g_cc.inst->topo_groups->group_list)); return; } if (!group) { DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "%s: connect_channel — group not found ch=%s gid=%016llx total_groups=%d", CC_ID, ch_id, (unsigned long long)gid, queue_entry_count(g_cc.inst->topo_groups->group_list)); return; }
if (group->connect) { if (group->connect) {
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "%s: connect_channel — already in progress ch=%s active=%d", DEBUG_DEBUG(DEBUG_CATEGORY_CHAT_SYNC, "%s: connect_channel — already in progress ch=%s active=%d",
CC_ID, ch_id, topo_group_connect_active_count(group)); CC_ID, ch_id, topo_group_connect_active_count(group));
return; return;
} }

13
src/chat/db_sync.c

@ -460,7 +460,7 @@ static void db_recalc_tick(void* arg)
if (si->recalc.pos >= total) { if (si->recalc.pos >= total) {
si->recalc.timer = NULL; si->recalc.timer = NULL;
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "recalc complete tbl=%s pos=%u(total)", SI_TBL(si), si->recalc.pos); DEBUG_DEBUG(DEBUG_CATEGORY_CHAT_SYNC, "recalc complete tbl=%s pos=%u(total)", SI_TBL(si), si->recalc.pos);
} else { } else {
si->recalc.timer = uasync_set_timeout(si->db_sync->inst->ua, 100, si, db_recalc_tick, "db_recalc"); si->recalc.timer = uasync_set_timeout(si->db_sync->inst->ua, 100, si, db_recalc_tick, "db_recalc");
} }
@ -675,14 +675,14 @@ static int db_sync_send_hash(struct DB_SYNC* db, uint64_t node_id, uint64_t hash
struct ETCP_CONN* conn = instance_find_conn(db->inst, node_id); struct ETCP_CONN* conn = instance_find_conn(db->inst, node_id);
if (!conn || !conn->links_up) { if (!conn || !conn->links_up) {
DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, "sync: send DROP — no direct conn to %04llX (hash=%016llx, type=%02x, conn=%p lu=%d)", DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "sync: send DROP — no conn to %04llX (hash=%016llx, type=%02x)",
(unsigned long long)(node_id >> 16), hash, plen > 0 ? payload[0] : 0, (unsigned long long)(node_id >> 16), hash, plen > 0 ? payload[0] : 0,
(void*)conn, conn ? conn->links_up : -1); (void*)conn, conn ? conn->links_up : -1);
queue_entry_free(entry); queue_entry_free(entry);
return -1; return -1;
} }
int ret = etcp_send(conn, entry); int ret = etcp_send(conn, entry);
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "sync: send OK → etcp_send ret=%d conn=%s l_up=%d init=%d q=%p", DEBUG_DEBUG(DEBUG_CATEGORY_CHAT_SYNC, "sync: send OK → etcp_send ret=%d conn=%s l_up=%d init=%d q=%p",
ret, conn->log_name, conn->links_up, conn->initialized, (void*)conn->send_input_q); ret, conn->log_name, conn->links_up, conn->initialized, (void*)conn->send_input_q);
return ret; return ret;
} }
@ -1134,7 +1134,7 @@ static void db_handle_ack_push(struct DB_SYNC_INSTANCE* si, uint64_t src, const
int changed = sqlite3_changes(SI_DB(si)); int changed = sqlite3_changes(SI_DB(si));
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
if (changed > 0) if (changed > 0)
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "sync [%s:%04llX] ← PUSH ACK: ts=%llu — delivery confirmed by peer", DEBUG_DEBUG(DEBUG_CATEGORY_CHAT_SYNC, "sync [%s:%04llX] ← PUSH ACK: ts=%llu — delivery confirmed by peer",
SI_SHRT(si), (unsigned long long)(src >> 16), (unsigned long long)ts); SI_SHRT(si), (unsigned long long)(src >> 16), (unsigned long long)ts);
} }
si_delivery_update(si, ts, author, src); si_delivery_update(si, ts, author, src);
@ -1166,9 +1166,6 @@ static void db_handle_push(struct DB_SYNC_INSTANCE* si, uint64_t src, const uint
memcpy(ack + 1, &rts, 8); memcpy(ack + 1, &rts, 8);
memcpy(ack + 9, &rauthor, 8); memcpy(ack + 9, &rauthor, 8);
db_sync_send(si, src, ack, 17); db_sync_send(si, src, ack, 17);
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "sync [%s:%04llX] ← PUSH: msg id=%llu author=%016llX ts=%llu → inserted at pos=%u (of %u total)",
SI_SHRT(si), (unsigned long long)(src >> 16),
(unsigned long long)rid, (unsigned long long)rauthor, (unsigned long long)rts, ins_pos, total);
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "sync [%s:%04llX] ← PUSH: msg id=%llu author=%016llX ts=%llu → inserted at pos=%u (of %u total)", DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "sync [%s:%04llX] ← PUSH: msg id=%llu author=%016llX ts=%llu → inserted at pos=%u (of %u total)",
SI_SHRT(si), (unsigned long long)(src >> 16), SI_SHRT(si), (unsigned long long)(src >> 16),
(unsigned long long)rid, (unsigned long long)rauthor, (unsigned long long)rts, ins_pos, total); (unsigned long long)rid, (unsigned long long)rauthor, (unsigned long long)rts, ins_pos, total);
@ -1525,7 +1522,7 @@ static void db_sync_peer_check_cb(void* arg)
for (int j = 0; j < si->peer_count; j++) { for (int j = 0; j < si->peer_count; j++) {
struct SI_PEER* p = &si->peers[j]; struct SI_PEER* p = &si->peers[j];
if (p->sync_state == 1 && p->sync_start_tb > 0 && now - p->sync_start_tb > to_tb) { if (p->sync_state == 1 && p->sync_start_tb > 0 && now - p->sync_start_tb > to_tb) {
DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC,
"sync [%s:%04llX] TIMEOUT: no response for %llu ms, sync_state 1→0 (synced_pos was %u)", "sync [%s:%04llX] TIMEOUT: no response for %llu ms, sync_state 1→0 (synced_pos was %u)",
SI_SHRT(si), (unsigned long long)(p->node_id >> 16), SI_SHRT(si), (unsigned long long)(p->node_id >> 16),
(unsigned long long)((now - p->sync_start_tb) / 10), p->synced_pos); (unsigned long long)((now - p->sync_start_tb) / 10), p->synced_pos);

2
tools/chatgui/db/db_manager.cpp

@ -79,7 +79,7 @@ DbManager::~DbManager() {
for (auto it = m_cursors.begin(); it != m_cursors.end(); ++it) for (auto it = m_cursors.begin(); it != m_cursors.end(); ++it)
sqlite3_finalize(it.value()); sqlite3_finalize(it.value());
m_cursors.clear(); m_cursors.clear();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "DbManager: destroyed"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "DbManager: destroyed");
} }
sqlite3_stmt* DbManager::prepareOrNull(const char* sql) const { sqlite3_stmt* DbManager::prepareOrNull(const char* sql) const {

2
tools/chatgui/src/animtimer.cpp

@ -16,7 +16,7 @@ AnimTimer *AnimTimer::instance() {
void AnimTimer::shutdown() { void AnimTimer::shutdown() {
instance()->m_timer.stop(); instance()->m_timer.stop();
instance()->m_icons.clear(); instance()->m_icons.clear();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "AnimTimer: shutdown"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "AnimTimer: shutdown");
} }
void AnimTimer::registerIcon(const QString &key, LottieIcon *icon) { void AnimTimer::registerIcon(const QString &key, LottieIcon *icon) {

8
tools/chatgui/src/channellist.cpp

@ -203,9 +203,9 @@ void ChannelList::loadChannels() {
item->setData(ch.lastMsgAt, ChannelLastMsgAtRole); item->setData(ch.lastMsgAt, ChannelLastMsgAtRole);
item->setData(makeChannelIcon(colors[ci % 6], letter), ChannelIconRole); item->setData(makeChannelIcon(colors[ci % 6], letter), ChannelIconRole);
m_model->appendRow(item); m_model->appendRow(item);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "ChannelList::loadChannels row=%d cid='%s' name='%s' unread=%d lastMsgAt=%lld sort=%d", DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "ChannelList::loadChannels row=%d cid='%s' name='%s' unread=%d lastMsgAt=%lld",
m_model->rowCount()-1, qPrintable(ch.channelId), qPrintable(ch.name), ch.unreadCount, m_model->rowCount()-1, qPrintable(ch.channelId), qPrintable(ch.name), ch.unreadCount,
(long long)ch.lastMsgAt, sortMode); (long long)ch.lastMsgAt);
ci++; ci++;
} }
} }
@ -233,18 +233,14 @@ void ChannelList::selectChannel(const QString& channelId) {
void ChannelList::setChannelPeersOnline(const QString& channelId, int count) { void ChannelList::setChannelPeersOnline(const QString& channelId, int count) {
int found = 0; int found = 0;
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "ChannelList::setChannelPeersOnline search='%s' online=%d rows=%d",
qPrintable(channelId), count, m_model->rowCount());
for (int row = 0; row < m_model->rowCount(); row++) { for (int row = 0; row < m_model->rowCount(); row++) {
QStandardItem* item = m_model->item(row); QStandardItem* item = m_model->item(row);
if (item) { if (item) {
QString itemCid = item->data(ChannelChannelIdRole).toString(); QString itemCid = item->data(ChannelChannelIdRole).toString();
int match = (itemCid == channelId) ? 1 : 0; int match = (itemCid == channelId) ? 1 : 0;
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, " row=%d cid='%s' match=%d", row, qPrintable(itemCid), match);
if (match) { if (match) {
item->setData(count, ChannelPeersOnlineRole); item->setData(count, ChannelPeersOnlineRole);
item->setData(m_autoConnectActive ? 1 : 0, ChannelAutoConnectActiveRole); item->setData(m_autoConnectActive ? 1 : 0, ChannelAutoConnectActiveRole);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, " SET online=%d", count);
found = 1; found = 1;
break; break;
} }

2
tools/chatgui/src/inputbar.cpp

@ -234,8 +234,6 @@ void InputBar::onSendClicked() {
m_attachPreview->hide(); m_attachPreview->hide();
} }
if (!text.isEmpty()) { if (!text.isEmpty()) {
GUI_INFO("send: len=%d hasLF=%d text='%s'",
text.length(), text.contains('\n'), qPrintable(text));
emit sendMessage(text); emit sendMessage(text);
m_input->clear(); m_input->clear();
if (m_emojiPanel) m_emojiPanel->hide(); if (m_emojiPanel) m_emojiPanel->hide();

8
tools/chatgui/src/main.cpp

@ -40,12 +40,12 @@ static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType) {
static struct ShutdownSentinel { static struct ShutdownSentinel {
~ShutdownSentinel() { ~ShutdownSentinel() {
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "main: static destructors done"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "main: static destructors done");
#ifdef _WIN32 #ifdef _WIN32
DWORD threads = count_threads(); DWORD threads = count_threads();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "main: threads at exit=%lu", (unsigned long)threads); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "main: threads at exit=%lu", (unsigned long)threads);
if (threads > 4) { if (threads > 4) {
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "main: %lu hanging threads, TerminateProcess", (unsigned long)threads); DEBUG_WARN(DEBUG_CATEGORY_GENERAL, "main: %lu hanging threads, TerminateProcess", (unsigned long)threads);
fflush(nullptr); fflush(nullptr);
TerminateProcess(GetCurrentProcess(), 0); TerminateProcess(GetCurrentProcess(), 0);
} }
@ -128,6 +128,6 @@ int main(int argc, char *argv[]) {
#endif #endif
int ret = app.exec(); int ret = app.exec();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "main: app.exec() returned %d", ret); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "main: app.exec() returned %d", ret);
return ret; return ret;
} }

16
tools/chatgui/src/mainwindow.cpp

@ -97,15 +97,15 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
if (m_recorder) { m_recorder->shutdown(); m_recorder = nullptr; } if (m_recorder) { m_recorder->shutdown(); m_recorder = nullptr; }
SoundManager::instance()->shutdown(); SoundManager::instance()->shutdown();
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow — saving channel state"); DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: ~MainWindow — saving channel state");
if (m_messageList) m_messageList->saveChannelState(); if (m_messageList) m_messageList->saveChannelState();
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow — stopping utun node"); DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: ~MainWindow — stopping utun node");
if (m_node) { m_node->stop(); delete m_node; m_node = nullptr; } if (m_node) { m_node->stop(); delete m_node; m_node = nullptr; }
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow — node stop+delete done"); DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: ~MainWindow — node stop+delete done");
AnimTimer::shutdown(); AnimTimer::shutdown();
MessageList::cleanupAnimations(); MessageList::cleanupAnimations();
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow — animations cleaned"); DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: ~MainWindow — animations cleaned");
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow done"); DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: ~MainWindow done");
} }
void MainWindow::setupUi() { void MainWindow::setupUi() {
@ -330,7 +330,7 @@ void MainWindow::setupTray() {
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: closeEvent — hiding to tray"); DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: closeEvent — hiding to tray");
hide(); hide();
m_trayIcon->showMessage("Chat", "Application minimized to tray.", m_trayIcon->showMessage("Chat", "Application minimized to tray.",
QSystemTrayIcon::Information, 2000); QSystemTrayIcon::Information, 2000);
@ -408,8 +408,6 @@ void MainWindow::showSettings() {
void MainWindow::onMessageReceived(const char* ch_id, int ch_id_len, uint64_t author) { void MainWindow::onMessageReceived(const char* ch_id, int ch_id_len, uint64_t author) {
QString cid = QString::fromUtf8(ch_id, ch_id_len); QString cid = QString::fromUtf8(ch_id, ch_id_len);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "MainWindow::onMessageReceived ch=%s author=%llu cur=%s",
qPrintable(cid), (unsigned long long)author, qPrintable(m_currentChannelId));
if (m_db && author != m_db->myNodeId()) if (m_db && author != m_db->myNodeId())
SoundManager::instance()->play("msg_incoming"); SoundManager::instance()->play("msg_incoming");
if (m_messageList) { if (m_messageList) {
@ -442,8 +440,6 @@ void MainWindow::onAutoConnectStatus(uint8_t status, uint16_t /*total_tried*/,
void MainWindow::onChannelPeersOnline(const char* ch_id, int ch_id_len, uint16_t online) { void MainWindow::onChannelPeersOnline(const char* ch_id, int ch_id_len, uint16_t online) {
if (m_channelList) { if (m_channelList) {
QString cid = QString::fromUtf8(ch_id, ch_id_len); QString cid = QString::fromUtf8(ch_id, ch_id_len);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "MainWindow::onChannelPeersOnline cid=%s online=%u",
qPrintable(cid), online);
m_channelList->setChannelPeersOnline(cid, (int)online); m_channelList->setChannelPeersOnline(cid, (int)online);
} }
} }

4
tools/chatgui/src/messagelist.cpp

@ -659,9 +659,9 @@ void MessageList::updateReadPosition() {
void MessageList::cleanupAnimations() { void MessageList::cleanupAnimations() {
size_t n = s_icons.size(); size_t n = s_icons.size();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "MessageList: cleanupAnimations clearing %zu icons", n); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "MessageList: cleanupAnimations clearing %zu icons", n);
s_icons.clear(); s_icons.clear();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "MessageList: cleanupAnimations done"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "MessageList: cleanupAnimations done");
} }
void MessageList::updateMessageProgress(const QString& chId, int64_t msgId, void MessageList::updateMessageProgress(const QString& chId, int64_t msgId,

6
tools/chatgui/src/sound_manager.cpp

@ -11,7 +11,7 @@ SoundManager* SoundManager::instance() {
} }
SoundManager::~SoundManager() { SoundManager::~SoundManager() {
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "SoundManager: static destructor entered"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "SoundManager: static destructor entered");
shutdown(); shutdown();
} }
@ -43,14 +43,14 @@ void SoundManager::shutdown() {
} }
m_sounds.clear(); m_sounds.clear();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "SoundManager: before ma_engine_uninit engine=%p", (void*)m_engine); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "SoundManager: before ma_engine_uninit engine=%p", (void*)m_engine);
if (m_engine) { ma_engine_uninit(m_engine); delete m_engine; m_engine = nullptr; } if (m_engine) { ma_engine_uninit(m_engine); delete m_engine; m_engine = nullptr; }
if (m_currentPcmSound) { delete m_currentPcmSound; m_currentPcmSound = nullptr; } if (m_currentPcmSound) { delete m_currentPcmSound; m_currentPcmSound = nullptr; }
if (m_currentPcmBuffer) { if (m_currentPcmBuffer) {
ma_audio_buffer* buf = (ma_audio_buffer*)m_currentPcmBuffer; ma_audio_buffer* buf = (ma_audio_buffer*)m_currentPcmBuffer;
ma_audio_buffer_uninit(buf); delete buf; m_currentPcmBuffer = nullptr; ma_audio_buffer_uninit(buf); delete buf; m_currentPcmBuffer = nullptr;
} }
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "SoundManager: after ma_engine_uninit"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "SoundManager: after ma_engine_uninit");
m_initialized = false; m_initialized = false;
} }

23
tools/chatgui/transport/gui_bridge_impl.cpp

@ -55,7 +55,7 @@ void GuiBridgeReceiver::processPost(int eventType, QByteArray data) {
uint64_t author = 0; uint64_t author = 0;
memcpy(&author, d + 1 + chLen, 8); memcpy(&author, d + 1 + chLen, 8);
QString chId = QString::fromUtf8((const char*)d + 1, chLen); QString chId = QString::fromUtf8((const char*)d + 1, chLen);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: MSG_RECEIVED ch=%s author=%llu", DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "gui_bridge: MSG_RECEIVED ch=%s author=%llu",
qPrintable(chId), (unsigned long long)author); qPrintable(chId), (unsigned long long)author);
if (g_msg_received_cb) g_msg_received_cb((const char*)d + 1, chLen, author); if (g_msg_received_cb) g_msg_received_cb((const char*)d + 1, chLen, author);
} else { } else {
@ -69,7 +69,7 @@ void GuiBridgeReceiver::processPost(int eventType, QByteArray data) {
if (dlen >= 20) { if (dlen >= 20) {
uint64_t nodeId, channelId; int result; uint64_t nodeId, channelId; int result;
memcpy(&nodeId, d, 8); memcpy(&result, d + 8, 4); memcpy(&channelId, d + 12, 8); memcpy(&nodeId, d, 8); memcpy(&result, d + 8, 4); memcpy(&channelId, d + 12, 8);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: CONNECT_RESULT node=0x%016llx ch=%llu result=%d", DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "gui_bridge: CONNECT_RESULT node=0x%016llx ch=%llu result=%d",
(unsigned long long)nodeId, (unsigned long long)channelId, result); (unsigned long long)nodeId, (unsigned long long)channelId, result);
if (g_connect_result_cb) g_connect_result_cb(nodeId, channelId, result); if (g_connect_result_cb) g_connect_result_cb(nodeId, channelId, result);
} else { } else {
@ -79,7 +79,7 @@ void GuiBridgeReceiver::processPost(int eventType, QByteArray data) {
case GUI_EVT_NEW_PEER: case GUI_EVT_NEW_PEER:
if (dlen >= 8) { if (dlen >= 8) {
uint64_t nodeId; memcpy(&nodeId, d, 8); uint64_t nodeId; memcpy(&nodeId, d, 8);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: NEW_PEER node=0x%016llx", (unsigned long long)nodeId); DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "gui_bridge: NEW_PEER node=0x%016llx", (unsigned long long)nodeId);
} else { } else {
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "gui_bridge: NEW_PEER data too short %d", dlen); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "gui_bridge: NEW_PEER data too short %d", dlen);
} }
@ -89,7 +89,7 @@ void GuiBridgeReceiver::processPost(int eventType, QByteArray data) {
uint8_t chLen = d[0]; uint8_t chLen = d[0];
if (dlen >= 1 + chLen) { if (dlen >= 1 + chLen) {
QString chId = QString::fromUtf8((const char*)d + 1, chLen); QString chId = QString::fromUtf8((const char*)d + 1, chLen);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: CHANNEL_UPDATED ch=%s", qPrintable(chId)); DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "gui_bridge: CHANNEL_UPDATED ch=%s", qPrintable(chId));
if (g_channel_updated_cb) g_channel_updated_cb((const char*)d + 1, chLen); if (g_channel_updated_cb) g_channel_updated_cb((const char*)d + 1, chLen);
} }
} else { } else {
@ -118,7 +118,7 @@ void GuiBridgeReceiver::processPost(int eventType, QByteArray data) {
uint16_t node_count; memcpy(&node_count, d + 3, 2); uint16_t node_count; memcpy(&node_count, d + 3, 2);
uint16_t connected; memcpy(&connected, d + 5, 2); uint16_t connected; memcpy(&connected, d + 5, 2);
const char* st_str = status == 0 ? "in_progress" : status == 1 ? "done" : "stopped"; const char* st_str = status == 0 ? "in_progress" : status == 1 ? "done" : "stopped";
if (status != 0) DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: AUTO_CONNECT %s tried=%u/%u connected=%u", st_str, total_tried, node_count, connected); if (status != 0) DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "gui_bridge: AUTO_CONNECT %s tried=%u/%u connected=%u", st_str, total_tried, node_count, connected);
if (g_auto_connect_status_cb) g_auto_connect_status_cb(status, total_tried, node_count, connected); if (g_auto_connect_status_cb) g_auto_connect_status_cb(status, total_tried, node_count, connected);
} }
break; break;
@ -127,13 +127,19 @@ void GuiBridgeReceiver::processPost(int eventType, QByteArray data) {
uint8_t chLen = d[0]; uint8_t chLen = d[0];
if (dlen >= 3 + chLen) { if (dlen >= 3 + chLen) {
uint16_t online; memcpy(&online, d + 1 + chLen, 2); uint16_t online; memcpy(&online, d + 1 + chLen, 2);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: CHANNEL_PEERS_ONLINE ch=%.*s online=%u", chLen, (const char*)d + 1, online); static char lastChId[256] = {0};
static uint16_t lastOnline = 0xFFFF;
if (chLen != (uint8_t)strlen(lastChId) || memcmp(lastChId, d + 1, chLen) != 0 || online != lastOnline) {
memcpy(lastChId, d + 1, chLen); lastChId[chLen] = '\0';
lastOnline = online;
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "gui_bridge: CHANNEL_PEERS_ONLINE ch=%.*s online=%u", chLen, (const char*)d + 1, online);
}
if (g_channel_peers_online_cb) g_channel_peers_online_cb((const char*)d + 1, chLen, online); if (g_channel_peers_online_cb) g_channel_peers_online_cb((const char*)d + 1, chLen, online);
} }
} }
break; break;
case GUI_EVT_DB_READY: case GUI_EVT_DB_READY:
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: DB_READY"); DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "gui_bridge: DB_READY (chat DB tables created)");
if (g_db_ready_cb) g_db_ready_cb(); if (g_db_ready_cb) g_db_ready_cb();
break; break;
case GUI_EVT_STATUS_REFRESH: case GUI_EVT_STATUS_REFRESH:
@ -142,7 +148,7 @@ void GuiBridgeReceiver::processPost(int eventType, QByteArray data) {
case GUI_EVT_NODE_CHANGED: case GUI_EVT_NODE_CHANGED:
if (dlen >= 8) { if (dlen >= 8) {
uint64_t nodeId; memcpy(&nodeId, d, 8); uint64_t nodeId; memcpy(&nodeId, d, 8);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge: NODE_CHANGED node=0x%016llx — pubkey changed, connection closed", (unsigned long long)nodeId); DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "gui_bridge: NODE_CHANGED node=0x%016llx — pubkey changed, connection closed", (unsigned long long)nodeId);
} else { } else {
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "gui_bridge: NODE_CHANGED data too short %d", dlen); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "gui_bridge: NODE_CHANGED data too short %d", dlen);
} }
@ -213,7 +219,6 @@ void gui_bridge_post_uasync_fn(void (*fn)(void*), void* arg) {
} }
if (!fn) return; if (!fn) return;
uasync_post(g_ua, fn, arg); uasync_post(g_ua, fn, arg);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "gui_bridge_post_uasync_fn: posted fn=%p arg=%p", (void*)fn, arg);
} }
int gui_bridge_is_uasync_ready(void) { int gui_bridge_is_uasync_ready(void) {

21
tools/chatgui/transport/utun_node.cpp

@ -102,7 +102,7 @@ void UtunNode::stop() {
void UtunNode::finalize() { void UtunNode::finalize() {
if (!m_instance) return; if (!m_instance) return;
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "finalize: cleanup start"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "finalize: cleanup start");
etcp_router_bind(m_instance, ETCP_RT_ID_CHAT, nullptr); etcp_router_bind(m_instance, ETCP_RT_ID_CHAT, nullptr);
chat_sync_destroy(m_instance); chat_sync_destroy(m_instance);
chat_core_destroy(m_instance); chat_core_destroy(m_instance);
@ -110,7 +110,7 @@ void UtunNode::finalize() {
m_instance = nullptr; m_instance = nullptr;
uasync_destroy(m_ua, 0); uasync_destroy(m_ua, 0);
m_ua = nullptr; m_ua = nullptr;
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "finalize: cleanup done"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "finalize: cleanup done");
} }
void UtunNode::send(uint64_t dstNodeId, const QByteArray& data) { void UtunNode::send(uint64_t dstNodeId, const QByteArray& data) {
@ -283,8 +283,7 @@ void UtunNode::runLoop() {
} }
/* chatgui defaults: suppress spam, verbose for our categories */ /* chatgui defaults: suppress spam, verbose for our categories */
g_debug_config.category_levels[DEBUG_CATEGORY_MEMORY] = DEBUG_LEVEL_DISABLED; g_debug_config.category_levels[DEBUG_CATEGORY_SYS] = DEBUG_LEVEL_DISABLED;
g_debug_config.category_levels[DEBUG_CATEGORY_TIMING] = DEBUG_LEVEL_DISABLED;
g_debug_config.category_levels[DEBUG_CATEGORY_BGP] = DEBUG_LEVEL_INFO; g_debug_config.category_levels[DEBUG_CATEGORY_BGP] = DEBUG_LEVEL_INFO;
/* per-category overrides from config: cat=level,cat=level,... */ /* per-category overrides from config: cat=level,cat=level,... */
@ -360,9 +359,9 @@ void UtunNode::runLoop() {
sqlite3_exec(m_instance->topo_sqlite_db, "PRAGMA synchronous=NORMAL", NULL, NULL, NULL); sqlite3_exec(m_instance->topo_sqlite_db, "PRAGMA synchronous=NORMAL", NULL, NULL, NULL);
sqlite3_exec(m_instance->topo_sqlite_db, "PRAGMA wal_autocheckpoint=10000", NULL, NULL, NULL); sqlite3_exec(m_instance->topo_sqlite_db, "PRAGMA wal_autocheckpoint=10000", NULL, NULL, NULL);
topo_node_sqlite_init(m_instance->topo_sqlite_db); topo_node_sqlite_init(m_instance->topo_sqlite_db);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "SQLite (shared): %s db=%p", db_file, (void*)m_instance->topo_sqlite_db); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "SQLite (shared): %s db=%p", db_file, (void*)m_instance->topo_sqlite_db);
} else { } else {
DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, "SQLite open failed: %s rc=%d", db_file, rc); DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "SQLite open failed: %s rc=%d", db_file, rc);
if (m_instance->topo_sqlite_db) { sqlite3_close(m_instance->topo_sqlite_db); m_instance->topo_sqlite_db = NULL; } if (m_instance->topo_sqlite_db) { sqlite3_close(m_instance->topo_sqlite_db); m_instance->topo_sqlite_db = NULL; }
} }
} }
@ -381,7 +380,7 @@ void UtunNode::runLoop() {
} }
{ int sock_count = 0; for (struct ETCP_SOCKET* s = m_instance->etcp_sockets; s; s = s->next) sock_count++; { int sock_count = 0; for (struct ETCP_SOCKET* s = m_instance->etcp_sockets; s; s = s->next) sock_count++;
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "utun_node: after instance_init, etcp_sockets=%d conns=%d", DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "utun_node: after instance_init, etcp_sockets=%d conns=%d",
sock_count, queue_entry_count(m_instance->connections)); } sock_count, queue_entry_count(m_instance->connections)); }
etcp_router_bind(m_instance, ETCP_RT_ID_CHAT, recvCallback); etcp_router_bind(m_instance, ETCP_RT_ID_CHAT, recvCallback);
@ -398,8 +397,8 @@ void UtunNode::runLoop() {
chat_sync_init(m_instance); chat_sync_init(m_instance);
chat_core_sync_my_addresses(); chat_core_sync_my_addresses();
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "chat_core + chat_sync initialized"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "chat_core + chat_sync initialized");
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "utun_node: entering poll loop"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "utun_node: entering poll loop");
signal(SIGINT, signal_handler); signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler); signal(SIGTERM, signal_handler);
@ -408,11 +407,11 @@ void UtunNode::runLoop() {
uasync_poll(ua, 100); uasync_poll(ua, 100);
} }
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "runLoop: poll exit m_stop=%d", (int)m_stop); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "runLoop: poll exit m_stop=%d", (int)m_stop);
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "runLoop: emitting stopped"); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "runLoop: emitting stopped");
QMetaObject::invokeMethod(this, [this] { emit stopped(); }); QMetaObject::invokeMethod(this, [this] { emit stopped(); });
} }

Loading…
Cancel
Save