From b2ab6c1858d14c8845ed69ea79923a830c807f98 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 30 Jan 2020 15:04:46 +0800 Subject: [PATCH] Let ReverseResolution always return/emit a result --- src/base/net/reverseresolution.cpp | 25 +++++++++---------------- src/gui/properties/peerlistwidget.cpp | 3 +++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/base/net/reverseresolution.cpp b/src/base/net/reverseresolution.cpp index 6c8fd34f6..4d63923b0 100644 --- a/src/base/net/reverseresolution.cpp +++ b/src/base/net/reverseresolution.cpp @@ -59,15 +59,9 @@ ReverseResolution::~ReverseResolution() void ReverseResolution::resolve(const QHostAddress &ip) { - if (ip.isNull()) - return; - const QString *hostname = m_cache.object(ip); if (hostname) { - if (hostname->isEmpty()) - ; // resolution didn't get meaningful results, so do nothing - else - emit ipResolved(ip, *hostname); + emit ipResolved(ip, *hostname); return; } @@ -80,15 +74,14 @@ void ReverseResolution::hostResolved(const QHostInfo &host) { const QHostAddress ip = m_lookups.take(host.lookupId()); - if (host.error() != QHostInfo::NoError) + if (host.error() != QHostInfo::NoError) { + emit ipResolved(ip, {}); return; - - const QString hostname = host.hostName(); - if (isUsefulHostName(hostname, ip)) { - m_cache.insert(ip, new QString(hostname)); - emit ipResolved(ip, hostname); - } - else { - m_cache.insert(ip, new QString()); } + + const QString hostname = isUsefulHostName(host.hostName(), ip) + ? host.hostName() + : QString(); + m_cache.insert(ip, new QString(hostname)); + emit ipResolved(ip, hostname); } diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index cc40c39d5..4b3107d66 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -428,6 +428,9 @@ void PeerListWidget::updatePeer(const BitTorrent::TorrentHandle *torrent, const void PeerListWidget::handleResolved(const QHostAddress &ip, const QString &hostname) const { + if (hostname.isEmpty()) + return; + const QSet items = m_itemsByIP.value(ip); for (QStandardItem *item : items) item->setData(hostname, Qt::DisplayRole);