Browse Source

Include trackers in /sync/maindata API endpoint

adaptive-webui-19844
Thomas Piccirello 5 years ago
parent
commit
84a40c1665
  1. 2
      src/webui/api/serialize/serialize_torrent.cpp
  2. 1
      src/webui/api/serialize/serialize_torrent.h
  3. 30
      src/webui/api/synccontroller.cpp

2
src/webui/api/serialize/serialize_torrent.cpp

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/trackerentry.h"
#include "base/utils/fs.h"
namespace
@ -110,6 +111,7 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent) @@ -110,6 +111,7 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent)
{KEY_TORRENT_ADDED_ON, torrent.addedTime().toSecsSinceEpoch()},
{KEY_TORRENT_COMPLETION_ON, torrent.completedTime().toSecsSinceEpoch()},
{KEY_TORRENT_TRACKER, torrent.currentTracker()},
{KEY_TORRENT_TRACKERS_COUNT, torrent.trackers().size()},
{KEY_TORRENT_DL_LIMIT, torrent.downloadLimit()},
{KEY_TORRENT_UP_LIMIT, torrent.uploadLimit()},
{KEY_TORRENT_AMOUNT_DOWNLOADED, torrent.totalDownload()},

1
src/webui/api/serialize/serialize_torrent.h

@ -61,6 +61,7 @@ const char KEY_TORRENT_SAVE_PATH[] = "save_path"; @@ -61,6 +61,7 @@ const char KEY_TORRENT_SAVE_PATH[] = "save_path";
const char KEY_TORRENT_ADDED_ON[] = "added_on";
const char KEY_TORRENT_COMPLETION_ON[] = "completion_on";
const char KEY_TORRENT_TRACKER[] = "tracker";
const char KEY_TORRENT_TRACKERS_COUNT[] = "trackers_count";
const char KEY_TORRENT_DL_LIMIT[] = "dl_limit";
const char KEY_TORRENT_UP_LIMIT[] = "up_limit";
const char KEY_TORRENT_AMOUNT_DOWNLOADED[] = "downloaded";

30
src/webui/api/synccontroller.cpp

@ -39,6 +39,7 @@ @@ -39,6 +39,7 @@
#include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/trackerentry.h"
#include "base/global.h"
#include "base/net/geoipmanager.h"
#include "base/preferences.h"
@ -247,6 +248,22 @@ namespace @@ -247,6 +248,22 @@ namespace
syncData[i.key()] = map;
}
break;
case QVariant::StringList:
if (!prevData.contains(i.key())) {
// new list item found - append it to syncData
syncData[i.key()] = i.value();
}
else {
QVariantList list;
QVariantList removedList;
processList(prevData[i.key()].toList(), i.value().toList(), list, removedList);
// existing list item found - remove it from prevData
prevData.remove(i.key());
if (!list.isEmpty() || !removedList.isEmpty())
// changed list item found - append entire list to syncData
syncData[i.key()] = i.value();
}
break;
default:
Q_ASSERT(0);
}
@ -354,6 +371,8 @@ SyncController::~SyncController() @@ -354,6 +371,8 @@ SyncController::~SyncController()
// - "torrents_removed": a list of hashes of removed torrents
// - "categories": map of categories info
// - "categories_removed": list of removed categories
// - "trackers": dictionary contains information about trackers
// - "trackers_removed": a list of removed trackers
// - "server_state": map contains information about the state of the server
// The keys of the 'torrents' dictionary are hashes of torrents.
// Each value of the 'torrents' dictionary contains map. The map can contain following keys:
@ -414,6 +433,7 @@ void SyncController::maindataAction() @@ -414,6 +433,7 @@ void SyncController::maindataAction()
QVariantMap lastAcceptedResponse = sessionManager()->session()->getData(QLatin1String("syncMainDataLastAcceptedResponse")).toMap();
QVariantHash torrents;
QHash<QString, QStringList> trackers;
for (const BitTorrent::TorrentHandle *torrent : asConst(session->torrents())) {
const BitTorrent::InfoHash torrentHash = torrent->hash();
@ -439,6 +459,10 @@ void SyncController::maindataAction() @@ -439,6 +459,10 @@ void SyncController::maindataAction()
}
}
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers())) {
trackers[tracker.url()] << torrentHash;
}
torrents[torrentHash] = map;
}
data["torrents"] = torrents;
@ -459,6 +483,12 @@ void SyncController::maindataAction() @@ -459,6 +483,12 @@ void SyncController::maindataAction()
tags << tag;
data["tags"] = tags;
QVariantHash trackersHash;
for (auto i = trackers.constBegin(); i != trackers.constEnd(); ++i) {
trackersHash[i.key()] = i.value();
}
data["trackers"] = trackersHash;
QVariantMap serverState = getTransferInfo();
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();

Loading…
Cancel
Save