WebAPI: Add I2P peers to peer list

Fixes the second part of #19794.

PR #23061.
This commit is contained in:
anikey 2025-08-29 12:51:31 +00:00 committed by GitHub
parent 6ac0c5a8b8
commit 5e11f4dc5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 5 deletions

View File

@ -10,6 +10,9 @@
* `torrents/editTracker` endpoint now supports setting a tracker's tier via `tier` parameter
* `torrents/editTracker` endpoint always responds with a 204 when successful
* `torrents/editTracker` endpoint `origUrl` parameter renamed to `url`
* [#23061](https://github.com/qbittorrent/qBittorrent/pull/23061)
* `sync/torrentPeers` returns one new field: `i2p_dest`, only when the peer is from I2P
* In this case, the fields `ip` and `port` are not returned
* [#23085](https://github.com/qbittorrent/qBittorrent/pull/23085)
* `torrents/parseMetadata` now responds with an array of metadata in the same order as the files in the request. It previously responded with an object keyed off of the submitted file name.

View File

@ -72,6 +72,7 @@ namespace
const QString KEY_PEER_FLAGS = u"flags"_s;
const QString KEY_PEER_FLAGS_DESCRIPTION = u"flags_desc"_s;
const QString KEY_PEER_IP = u"ip"_s;
const QString KEY_PEER_I2P_DEST = u"i2p_dest"_s;
const QString KEY_PEER_PORT = u"port"_s;
const QString KEY_PEER_PROGRESS = u"progress"_s;
const QString KEY_PEER_RELEVANCE = u"relevance"_s;
@ -847,12 +848,11 @@ void SyncController::torrentPeersAction()
for (const BitTorrent::PeerInfo &pi : peersList)
{
if (pi.address().ip.isNull()) continue;
const bool useI2PSocket = pi.useI2PSocket();
if (pi.address().ip.isNull() && !useI2PSocket) continue;
QVariantMap peer =
{
{KEY_PEER_IP, pi.address().ip.toString()},
{KEY_PEER_PORT, pi.address().port},
{KEY_PEER_CLIENT, pi.client()},
{KEY_PEER_ID_CLIENT, pi.peerIdClient()},
{KEY_PEER_PROGRESS, pi.progress()},
@ -876,13 +876,23 @@ void SyncController::torrentPeersAction()
peer.insert(KEY_PEER_FILES, filesForPiece.join(u'\n'));
}
if (resolvePeerCountries)
if (resolvePeerCountries && !useI2PSocket)
{
peer[KEY_PEER_COUNTRY_CODE] = pi.country().toLower();
peer[KEY_PEER_COUNTRY] = Net::GeoIPManager::CountryName(pi.country());
}
peers[pi.address().toString()] = peer;
if (useI2PSocket)
{
peer[KEY_PEER_I2P_DEST] = pi.I2PAddress();
peers[pi.I2PAddress()] = peer;
}
else
{
peer[KEY_PEER_IP] = pi.address().ip.toString();
peer[KEY_PEER_PORT] = pi.address().port;
peers[pi.address().toString()] = peer;
}
}
data[u"peers"_s] = peers;