-
-
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
Open
Piccirello
wants to merge
4
commits into
qbittorrent:master
Choose a base branch
from
Piccirello:webui-peer-host-name
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+179
−7
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
|
||||||
| td.textContent = displayValue; | ||||||
| td.title = displayValue; | ||||||
| }; | ||||||
| this.columns["ip"].compareRows = function(row1, row2) { | ||||||
| const ip1 = this.getRowValue(row1); | ||||||
| const ip2 = this.getRowValue(row2); | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.