Torrent example: Use QByteArray toPercentEncoding

The hand-rolled loop produced incorrect output and was subsequently
rejected by trackers.

The torrent example doesn't support modern features though, so it's
still a bit hit-or-miss whether a torrent will work. E.g. downloading an
Arch iso does not work since it relies on DHT, PeX and HTTP seeds.

Fixes: QTBUG-109798
Task-number: QTBUG-110622
Change-Id: Ica40fb9205f09d135407a160a28a45d06a418176
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 39daa368d47bc676efb19a8e7478ef1c270ae959)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2023-01-25 12:31:12 +01:00 committed by Qt Cherry-pick Bot
parent 07f2ca775c
commit dbe7f136aa

View File

@ -62,12 +62,8 @@ void TrackerClient::fetchPeerList()
QUrlQuery query(url);
// Percent encode the hash
QByteArray infoHash = torrentDownloader->infoHash();
QByteArray encodedSum;
for (int i = 0; i < infoHash.size(); ++i) {
encodedSum += '%';
encodedSum += QByteArray::number(infoHash[i], 16).right(2).rightJustified(2, '0');
}
const QByteArray infoHash = torrentDownloader->infoHash();
const QByteArray encodedSum = infoHash.toPercentEncoding();
bool seeding = (torrentDownloader->state() == TorrentClient::Seeding);