-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
WebAPI: Resolve peer host names #23708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Bittorrent Client using Qt and libtorrent. | ||
| * Copyright (C) 2026 Thomas Piccirello <[email protected]> | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License | ||
| * as published by the Free Software Foundation; either version 2 | ||
| * of the License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| * | ||
| * In addition, as a special exception, the copyright holders give permission to | ||
| * link this program with the OpenSSL project's "OpenSSL" library (or with | ||
| * modified versions of it that use the same license as the "OpenSSL" library), | ||
| * and distribute the linked executables. You must obey the GNU General Public | ||
| * License in all respects for all of the code used other than "OpenSSL". If you | ||
| * modify file(s), you may extend this exception to your version of the file(s), | ||
| * but you are not obligated to do so. If you do not wish to do so, delete this | ||
| * exception statement from your version. | ||
| */ | ||
|
|
||
| #include "peerhostnameresolver.h" | ||
|
|
||
| #include "base/net/reverseresolution.h" | ||
| #include "base/preferences.h" | ||
|
|
||
| PeerHostNameResolver::PeerHostNameResolver(QObject *parent) | ||
| : QObject(parent) | ||
| { | ||
| connect(Preferences::instance(), &Preferences::changed, this, &PeerHostNameResolver::updateState); | ||
| updateState(); | ||
| } | ||
|
|
||
| QString PeerHostNameResolver::lookupHostName(const QHostAddress &ip) | ||
| { | ||
| const QString hostName = m_resolvedHosts.value(ip); | ||
| if (m_resolver && hostName.isEmpty()) | ||
| m_resolver->resolve(ip); | ||
|
|
||
| return hostName; | ||
| } | ||
|
|
||
| void PeerHostNameResolver::onHostNameResolved(const QHostAddress &ip, const QString &hostname) | ||
| { | ||
| m_resolvedHosts.insert(ip, hostname); | ||
| } | ||
|
|
||
| void PeerHostNameResolver::updateState() | ||
| { | ||
| if (Preferences::instance()->resolvePeerHostNames()) | ||
| { | ||
| if (!m_resolver) | ||
| { | ||
| m_resolver = new Net::ReverseResolution(this); | ||
| connect(m_resolver, &Net::ReverseResolution::ipResolved | ||
| , this, &PeerHostNameResolver::onHostNameResolved); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| delete m_resolver; | ||
| m_resolver = nullptr; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Bittorrent Client using Qt and libtorrent. | ||
| * Copyright (C) 2026 Thomas Piccirello <[email protected]> | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License | ||
| * as published by the Free Software Foundation; either version 2 | ||
| * of the License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| * | ||
| * In addition, as a special exception, the copyright holders give permission to | ||
| * link this program with the OpenSSL project's "OpenSSL" library (or with | ||
| * modified versions of it that use the same license as the "OpenSSL" library), | ||
| * and distribute the linked executables. You must obey the GNU General Public | ||
| * License in all respects for all of the code used other than "OpenSSL". If you | ||
| * modify file(s), you may extend this exception to your version of the file(s), | ||
| * but you are not obligated to do so. If you do not wish to do so, delete this | ||
| * exception statement from your version. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <QHash> | ||
| #include <QHostAddress> | ||
| #include <QObject> | ||
|
|
||
| namespace Net | ||
| { | ||
| class ReverseResolution; | ||
| } | ||
|
|
||
| class PeerHostNameResolver final : public QObject | ||
| { | ||
| Q_OBJECT | ||
| Q_DISABLE_COPY_MOVE(PeerHostNameResolver) | ||
|
|
||
| public: | ||
| explicit PeerHostNameResolver(QObject *parent = nullptr); | ||
|
|
||
| QString lookupHostName(const QHostAddress &ip); | ||
|
|
||
| private slots: | ||
| void onHostNameResolved(const QHostAddress &ip, const QString &hostname); | ||
| void updateState(); | ||
|
|
||
| private: | ||
| Net::ReverseResolution *m_resolver = nullptr; | ||
| QHash<QHostAddress, QString> m_resolvedHosts; | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1835,6 +1835,7 @@ window.qBittorrent.DynamicTable ??= (() => { | |||||
| this.newColumn("files", "", "QBT_TR(Files)QBT_TR[CONTEXT=PeerListWidget]", 100, true); | ||||||
|
|
||||||
| this.columns["country"].dataProperties.push("country_code"); | ||||||
| this.columns["ip"].dataProperties.push("host_name"); | ||||||
| this.columns["flags"].dataProperties.push("flags_desc"); | ||||||
| this.initColumnsFunctions(); | ||||||
| } | ||||||
|
|
@@ -1858,6 +1859,14 @@ window.qBittorrent.DynamicTable ??= (() => { | |||||
| }; | ||||||
|
|
||||||
| // ip | ||||||
| this.columns["ip"].updateTd = function(td, row) { | ||||||
| const ip = this.getRowValue(row, 0); | ||||||
| const hostname = this.getRowValue(row, 1); | ||||||
| // Display hostname if resolved, otherwise display IP | ||||||
| const displayValue = hostname || ip; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would cause I think the original code works fine. Or if we want to be more explicit:
|
||||||
| td.textContent = displayValue; | ||||||
| td.title = displayValue; | ||||||
| }; | ||||||
| this.columns["ip"].compareRows = function(row1, row2) { | ||||||
| const ip1 = this.getRowValue(row1); | ||||||
| const ip2 = this.getRowValue(row2); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be moved to line 65. To group with them.