2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef TRACKERCLIENT_H
|
|
|
|
#define TRACKERCLIENT_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QList>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QHostAddress>
|
2011-12-22 19:42:49 +00:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QAuthenticator>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "metainfo.h"
|
|
|
|
#include "torrentclient.h"
|
|
|
|
|
|
|
|
class TorrentClient;
|
|
|
|
|
|
|
|
class TrackerClient : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-11-01 12:21:32 +00:00
|
|
|
explicit TrackerClient(TorrentClient *downloader, QObject *parent = nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void start(const MetaInfo &info);
|
|
|
|
void stop();
|
|
|
|
void startSeeding();
|
|
|
|
|
|
|
|
signals:
|
2011-12-22 19:42:49 +00:00
|
|
|
void connectionError(QNetworkReply::NetworkError error);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void failure(const QString &reason);
|
|
|
|
void warning(const QString &message);
|
|
|
|
void peerListUpdated(const QList<TorrentPeer> &peerList);
|
|
|
|
|
|
|
|
void uploadCountUpdated(qint64 newUploadCount);
|
|
|
|
void downloadCountUpdated(qint64 newDownloadCount);
|
2013-03-14 23:42:15 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void stopped();
|
|
|
|
|
|
|
|
protected:
|
2016-06-15 08:12:35 +00:00
|
|
|
void timerEvent(QTimerEvent *event) override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void fetchPeerList();
|
2011-12-22 19:42:49 +00:00
|
|
|
void httpRequestDone(QNetworkReply *reply);
|
|
|
|
void provideAuthentication(QNetworkReply *reply, QAuthenticator *auth);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
TorrentClient *torrentDownloader;
|
|
|
|
|
2019-11-01 12:21:32 +00:00
|
|
|
int requestIntervalTimer = -1;
|
2011-12-22 19:42:49 +00:00
|
|
|
QNetworkAccessManager http;
|
2011-04-27 10:05:43 +00:00
|
|
|
MetaInfo metaInfo;
|
|
|
|
QByteArray trackerId;
|
|
|
|
QList<TorrentPeer> peers;
|
2019-11-01 12:21:32 +00:00
|
|
|
qint64 length = 0;
|
2011-12-22 19:42:49 +00:00
|
|
|
QString uname;
|
|
|
|
QString pwd;
|
2013-03-14 23:42:15 +00:00
|
|
|
|
2019-11-01 12:21:32 +00:00
|
|
|
bool firstTrackerRequest = true;
|
|
|
|
bool lastTrackerRequest = false;
|
|
|
|
bool firstSeeding = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|