Improve peer host name resolution (closes #360)

- Take a QString in argument to avoid converting it twice. The caller already
  has the IP as a QString.
- Fix bug where hostnames coming from the cache would not the displayed.
- Fix bug where the resolved hostnames would not be displayed if the IP we know
  does not match the first one in the QHostInfo::addresses() list. It may come
  later in the list or may be formatted differently (possible with IPv6).
- Avoid requesting again host names for IPs that were already requested recently
  but whose resolution did not return a useful hostname.
This commit is contained in:
Christophe Dumez
2013-03-28 21:47:45 +02:00
parent 04ff48fa0b
commit 43f5f81410
2 changed files with 30 additions and 22 deletions

View File

@@ -325,12 +325,15 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso
updatePeer(peer_ip, peer);
old_peers_set.remove(peer_ip);
if (force_hostname_resolution && m_resolver) {
m_resolver->resolve(peer.ip);
m_resolver->resolve(peer_ip);
}
} else {
// Add new peer
m_peerItems[peer_ip] = addPeer(peer_ip, peer);
m_peerEndpoints[peer_ip] = peer.ip;
// Resolve peer host name is asked
if (m_resolver)
m_resolver->resolve(peer_ip);
}
}
// Delete peers that are gone
@@ -350,9 +353,6 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer)
m_listModel->insertRow(row);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ip);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP_HIDDEN), ip);
// Resolve peer host name is asked
if (m_resolver)
m_resolver->resolve(peer.ip);
if (m_displayFlags) {
const QIcon ico = GeoIPManager::CountryISOCodeToIcon(peer.country);
if (!ico.isNull()) {