mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-31 20:58:07 -06:00
Merge pull request #10158 from Piccirello/webui-peers-table
Add ability to add and ban a peer from the Web UI
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include "base/bittorrent/downloadpriority.h"
|
||||
#include "base/bittorrent/peeraddress.h"
|
||||
#include "base/bittorrent/peerinfo.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/torrenthandle.h"
|
||||
@@ -681,6 +682,42 @@ void TorrentsController::removeTrackersAction()
|
||||
torrent->forceReannounce();
|
||||
}
|
||||
|
||||
void TorrentsController::addPeersAction()
|
||||
{
|
||||
checkParams({"hashes", "peers"});
|
||||
|
||||
const QStringList hashes = params()["hashes"].split('|');
|
||||
const QStringList peers = params()["peers"].split('|');
|
||||
|
||||
QVector<BitTorrent::PeerAddress> peerList;
|
||||
peerList.reserve(peers.size());
|
||||
for (const QString &peer : peers) {
|
||||
const BitTorrent::PeerAddress addr = BitTorrent::PeerAddress::parse(peer.trimmed());
|
||||
if (!addr.ip.isNull())
|
||||
peerList.append(addr);
|
||||
}
|
||||
|
||||
if (peerList.isEmpty())
|
||||
throw APIError(APIErrorType::BadParams, "No valid peers were specified");
|
||||
|
||||
QJsonObject results;
|
||||
|
||||
applyToTorrents(hashes, [peers, peerList, &results](BitTorrent::TorrentHandle *const torrent)
|
||||
{
|
||||
const int peersAdded = std::count_if(peerList.cbegin(), peerList.cend(), [torrent](const BitTorrent::PeerAddress &peer)
|
||||
{
|
||||
return torrent->connectPeer(peer);
|
||||
});
|
||||
|
||||
results[torrent->hash()] = QJsonObject {
|
||||
{"added", peersAdded},
|
||||
{"failed", (peers.size() - peersAdded)}
|
||||
};
|
||||
});
|
||||
|
||||
setResult(results);
|
||||
}
|
||||
|
||||
void TorrentsController::pauseAction()
|
||||
{
|
||||
checkParams({"hashes"});
|
||||
|
||||
@@ -66,6 +66,7 @@ private slots:
|
||||
void addTrackersAction();
|
||||
void editTrackerAction();
|
||||
void removeTrackersAction();
|
||||
void addPeersAction();
|
||||
void filePrioAction();
|
||||
void uploadLimitAction();
|
||||
void downloadLimitAction();
|
||||
|
||||
@@ -29,8 +29,13 @@
|
||||
#include "transfercontroller.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QVector>
|
||||
|
||||
#include "base/bittorrent/peeraddress.h"
|
||||
#include "base/bittorrent/peerinfo.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/global.h"
|
||||
#include "apierror.h"
|
||||
|
||||
const char KEY_TRANSFER_DLSPEED[] = "dl_info_speed";
|
||||
const char KEY_TRANSFER_DLDATA[] = "dl_info_data";
|
||||
@@ -111,3 +116,15 @@ void TransferController::speedLimitsModeAction()
|
||||
{
|
||||
setResult(QString::number(BitTorrent::Session::instance()->isAltGlobalSpeedLimitEnabled()));
|
||||
}
|
||||
|
||||
void TransferController::banPeersAction()
|
||||
{
|
||||
checkParams({"peers"});
|
||||
|
||||
const QStringList peers = params()["peers"].split('|');
|
||||
for (const QString &peer : peers) {
|
||||
const BitTorrent::PeerAddress addr = BitTorrent::PeerAddress::parse(peer.trimmed());
|
||||
if (!addr.ip.isNull())
|
||||
BitTorrent::Session::instance()->banIP(addr.ip.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,5 @@ private slots:
|
||||
void downloadLimitAction();
|
||||
void setUploadLimitAction();
|
||||
void setDownloadLimitAction();
|
||||
void banPeersAction();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user