qt5base-lts/examples/network/torrent/trackerclient.h
Lucie Gérard 05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00

70 lines
1.6 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef TRACKERCLIENT_H
#define TRACKERCLIENT_H
#include <QByteArray>
#include <QList>
#include <QObject>
#include <QHostAddress>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QAuthenticator>
#include "metainfo.h"
#include "torrentclient.h"
class TorrentClient;
class TrackerClient : public QObject
{
Q_OBJECT
public:
explicit TrackerClient(TorrentClient *downloader, QObject *parent = nullptr);
void start(const MetaInfo &info);
void stop();
void startSeeding();
signals:
void connectionError(QNetworkReply::NetworkError error);
void failure(const QString &reason);
void warning(const QString &message);
void peerListUpdated(const QList<TorrentPeer> &peerList);
void uploadCountUpdated(qint64 newUploadCount);
void downloadCountUpdated(qint64 newDownloadCount);
void stopped();
protected:
void timerEvent(QTimerEvent *event) override;
private slots:
void fetchPeerList();
void httpRequestDone(QNetworkReply *reply);
void provideAuthentication(QNetworkReply *reply, QAuthenticator *auth);
private:
TorrentClient *torrentDownloader;
int requestInterval = 5 * 60;
int requestIntervalTimer = -1;
QNetworkAccessManager http;
MetaInfo metaInfo;
QByteArray trackerId;
QList<TorrentPeer> peers;
qint64 length = 0;
QString uname;
QString pwd;
bool firstTrackerRequest = true;
bool lastTrackerRequest = false;
bool firstSeeding = true;
};
#endif