From 39daa368d47bc676efb19a8e7478ef1c270ae959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 25 Jan 2023 12:31:12 +0100 Subject: [PATCH] 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 Reviewed-by: Marc Mutz --- examples/network/torrent/trackerclient.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp index 077696ccd82..77a45770748 100644 --- a/examples/network/torrent/trackerclient.cpp +++ b/examples/network/torrent/trackerclient.cpp @@ -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);