Show actual member routes and both endpoints' NAT types in desktop details

This commit is contained in:
evgeny committed 2026-10-28 17:20:46 +01:00
1 parent 21411053d8
commit 8bf7a8319b
3 files changed
+42 -17

No files matched your search

+32 -11
View File
@@ -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 {