From 8bf7a8319b057989ced97c189693fced37e7de8a Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 28 Oct 2026 17:20:46 +0100 Subject: [PATCH] Show actual member routes and both endpoints' NAT types in desktop details --- tools/chatgui/src/accountlist.cpp | 13 ++++---- tools/chatgui/src/memberlistmodel.cpp | 43 ++++++++++++++++++++------- tools/chatgui/src/memberlistmodel.h | 3 ++ 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/tools/chatgui/src/accountlist.cpp b/tools/chatgui/src/accountlist.cpp index 9efb4e559..025d82d8f 100644 --- a/tools/chatgui/src/accountlist.cpp +++ b/tools/chatgui/src/accountlist.cpp @@ -243,7 +243,12 @@ void AccountList::hideEvent(QHideEvent* event) { } void AccountList::onSnapshotChanged(quint64 nodeId) { - if (!m_detailNodeId || (nodeId && nodeId != m_detailNodeId)) return; + if (!m_detailNodeId) return; + if (nodeId && nodeId != m_detailNodeId) { + const auto changed = m_model->member(nodeId); + if (changed && changed->is_self) updateDetailDisplay(); + return; + } if (!m_model->member(m_detailNodeId)) { clearMemberDetail(); return; } m_detailDirty = true; m_detailHops.clear(); for (int row = 0; row < m_model->rowCount(); row++) if (m_model->nodeIdAt(row) == m_detailNodeId) { @@ -463,11 +468,7 @@ void AccountList::updateDetailDisplay() { lines.append(QString(" %1").arg(QString::fromUtf8(lk.sockName).toHtmlEscaped())); } } - QString route = !member->online ? QCoreApplication::translate("ChatGui", "offline") : - member->conn_up & NCONN_DIRECT ? "D" : member->conn_up & NCONN_INDIRECT ? "I" : "B"; - if (member->online && member->rtt != 0xffff) route += QString(" · rtt=%1ms").arg(member->rtt / 10.0, 0, 'f', 1); - if (member->online && member->intermediaries) route += QString(" · hop:%1").arg(member->intermediaries); - lines.prepend(route); + lines.prepend(m_model->routeText(*member, true)); if (!m_detailHops.isEmpty() && member->online) { QStringList hops; for (auto it = m_detailHops.crbegin(); it != m_detailHops.crend(); ++it) { diff --git a/tools/chatgui/src/memberlistmodel.cpp b/tools/chatgui/src/memberlistmodel.cpp index ea7dfb6a7..55920b498 100644 --- a/tools/chatgui/src/memberlistmodel.cpp +++ b/tools/chatgui/src/memberlistmodel.cpp @@ -15,6 +15,7 @@ extern "C" { #include "../../../src/chat/chat_core.h" #include "../../../src/chat/chat_member.h" +#include "../../../src/routing_layer/topo_node.h" #include "../../../lib/mem.h" } @@ -59,17 +60,7 @@ QVariant MemberListModel::data(const QModelIndex& index, int role) const { const auto& item = m_members.at(index.row()); if (role == Qt::DisplayRole) return item.name; if (role == Qt::DecorationRole) return QVariant::fromValue(QIcon(item.avatar)); - if (role == Qt::UserRole + 1) { - QString sub; - if (item.snapshot.rtt != 0xffff) sub += QString("rtt=%1ms").arg(item.snapshot.rtt / 10); - if (item.snapshot.nat_type != 0xff) { - static const char* nat[] = {"NET","DIR","EIM","DEP","NAT?","CONTACT","EIM?"}; - const char* nt = (item.snapshot.nat_type <= 6) ? nat[item.snapshot.nat_type] : "?"; - if (!sub.isEmpty()) sub += " "; - sub += nt; - } - return sub; - } + if (role == Qt::UserRole + 1) return routeText(item.snapshot, false); if (role == Qt::ToolTipRole) return QCoreApplication::translate("ChatGui", item.snapshot.online ? "online" : "offline") + " | 0x" + QString("%1").arg(item.snapshot.node_id, 16, 16, QChar('0')) + @@ -82,6 +73,30 @@ QVariant MemberListModel::data(const QModelIndex& index, int role) const { return {}; } +QString MemberListModel::routeText(const chat_member_display& peer, bool detailed) const { + if (!peer.online) return QCoreApplication::translate("ChatGui", "offline"); + if (peer.is_self) return QStringLiteral("SELF"); + QString route; + if (peer.conn_up & NCONN_DIRECT) { + route = QStringLiteral("DIR"); + if (detailed) { + uint8_t localNat = 255; + for (const auto& item : m_members) if (item.snapshot.is_self) { localNat = item.snapshot.nat_type; break; } + auto nat = [](uint8_t type) { + static const char* names[] = {"NET", "NONE", "EIM", "STRICT", "NAT?", "CONTACT", "EIM?"}; + return QString::fromLatin1(type < sizeof(names) / sizeof(names[0]) ? names[type] : "?"); + }; + route += QStringLiteral("(%1-%2)").arg(nat(localNat), nat(peer.nat_type)); + } + } else if (peer.conn_up & NCONN_INDIRECT) route = QStringLiteral("IND"); + else route = detailed ? QStringLiteral("BGP(%1 hop)").arg(peer.intermediaries) : QStringLiteral("B%1").arg(peer.intermediaries); + if (peer.rtt != UINT16_MAX) { + QString rtt = QString::number(peer.rtt / 10.0, 'f', peer.rtt % 10 ? 1 : 0); + route += (detailed ? QStringLiteral(" RTT=%1ms") : QStringLiteral(", RTT=%1ms")).arg(rtt); + } + return route; +} + void MemberListModel::setChannel(const QString& channelId, bool isOwner) { const QByteArray channel = channelId.toUtf8(); if (channel.size() >= int(sizeof(chat_member_list_req::ch_id)) || channel.contains('\0')) { @@ -212,6 +227,12 @@ void MemberListModel::onMemberUpdated(const QString& chId, const uint8_t* data) } if (row >= 0) { + const auto& previous = m_members[row].snapshot; + if (previous.online != item.snapshot.online || previous.conn_up != item.snapshot.conn_up + || previous.intermediaries != item.snapshot.intermediaries || previous.nat_type != item.snapshot.nat_type) + DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "member route updated ch=%s node=%016llx online=%u up=%u intermediaries=%u nat=%u display=%s", + qPrintable(chId), (unsigned long long)item.snapshot.node_id, item.snapshot.online, item.snapshot.conn_up, + item.snapshot.intermediaries, item.snapshot.nat_type, qPrintable(routeText(item.snapshot, false))); m_members[row] = item; emit dataChanged(index(row), index(row)); } else { diff --git a/tools/chatgui/src/memberlistmodel.h b/tools/chatgui/src/memberlistmodel.h index 552b92776..ed7c6a703 100644 --- a/tools/chatgui/src/memberlistmodel.h +++ b/tools/chatgui/src/memberlistmodel.h @@ -46,6 +46,9 @@ public: bool isOnlineAt(int row) const; // false вне диапазона; online из последнего снимка, не из БД /* Копия записи: указатели в row-cache нельзя сохранять через reset/обновления. */ std::optional member(quint64 nodeId) const; + /* Единый формат фактического подключения для строки и деталей. Bn/BGP(n hop) считает посредников. + * detailed добавляет пару NAT «наш узел — участник» для DIR; неизвестный тип обозначен ?, RTT не округляется до целых. */ + QString routeText(const chat_member_display& member, bool detailed) const; /* GUI callbacks, data заимствован на время вызова. Другой chId игнорируется. * List требует ровно count*CHAT_MEMBER_DISPLAY_SIZE байтов; (0,NULL,0) очищает список.