Hi Petr,
I was just having a look at TrackerRequestDriver and it occurred to me that QUrl might be extremely helpful for handling the query string parameters - have a look at QUrl::addQueryItem(). It can also handle URL-encoding itself!
Another thing is:
QByteArray temporaryRequestUrl = announceUrl_;
appendInfoHash (temporaryRequestUrl);
appendPeerId (temporaryRequestUrl);
...
I guess a more functional style could be more readable and more unambitious (function calls have no side effects):
temporaryRequestUrl = announceUrl_ + "?";
temporaryRequestUrl += infoHash() + "&";
temporaryRequestUrl += peerId() + "&";
...
Similarly void writeRequestUrl (QByteARray &) could become QByteArray requestUrl(). If QUrl is used instead of a QByteArray, this approach may not work though. Or maybe with QUrl one could:
QList <QPair <QString, QStirng> > parameters;
parameters += pair (ParameterInfoHashName, trackerRequest_.infoHash());
parameters += pair (ParameterPeerIdName, trackerRequest_.peerId());
...
where pair is a helper taking two QStrings and returning a QPair of QStrings. The entries with empty values could be filtered before adding them to the QUrl object using addQueryItem() or setQueryItems().
I guess we could assert on an empty infoHash (and others?) because without it we do not have a valid request. Each valid Torrent object must have a valid info dictionary. Maybe we could have Torrent calculate its infoHash?
Regards,
Peter
