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
Pick-to: 6.5
Change-Id: Ica40fb9205f09d135407a160a28a45d06a418176
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Mårten Nordheim 2023-01-25 12:31:12 +01:00
parent 6c90c04fb9
commit 39daa368d4

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);