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 RATECONTROLLER_H
|
|
|
|
#define RATECONTROLLER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSet>
|
2019-06-12 16:06:23 +00:00
|
|
|
#include <QElapsedTimer>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class PeerWireClient;
|
|
|
|
|
|
|
|
class RateController : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-11-01 12:21:32 +00:00
|
|
|
using QObject::QObject;
|
2011-04-27 10:05:43 +00:00
|
|
|
static RateController *instance();
|
|
|
|
|
|
|
|
void addSocket(PeerWireClient *socket);
|
|
|
|
void removeSocket(PeerWireClient *socket);
|
|
|
|
|
|
|
|
inline int uploadLimit() const { return upLimit; }
|
|
|
|
inline int downloadLimit() const { return downLimit; }
|
|
|
|
inline void setUploadLimit(int bytesPerSecond) { upLimit = bytesPerSecond; }
|
|
|
|
void setDownloadLimit(int bytesPerSecond);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void transfer();
|
|
|
|
void scheduleTransfer();
|
|
|
|
|
|
|
|
private:
|
2019-06-12 16:06:23 +00:00
|
|
|
QElapsedTimer stopWatch;
|
2011-04-27 10:05:43 +00:00
|
|
|
QSet<PeerWireClient *> sockets;
|
2019-11-01 12:21:32 +00:00
|
|
|
int upLimit = 0;
|
|
|
|
int downLimit = 0;
|
|
|
|
bool transferScheduled = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|