2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2018-2023 Vladimir Golovnev <glassez@yandex.ru>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
32 #include <QVariantMap>
34 #include "base/bittorrent/infohash.h"
36 #include "apicontroller.h"
43 class SyncController
: public APIController
46 Q_DISABLE_COPY_MOVE(SyncController
)
49 using APIController::APIController
;
51 explicit SyncController(IApplication
*app
, QObject
*parent
= nullptr);
54 void updateFreeDiskSpace(qint64 freeDiskSpace
);
57 void maindataAction();
58 void torrentPeersAction();
61 void makeMaindataSnapshot();
62 QJsonObject
generateMaindataSyncData(int id
, bool fullUpdate
);
64 void onCategoryAdded(const QString
&categoryName
);
65 void onCategoryRemoved(const QString
&categoryName
);
66 void onCategoryOptionsChanged(const QString
&categoryName
);
67 void onSubcategoriesSupportChanged();
68 void onTagAdded(const Tag
&tag
);
69 void onTagRemoved(const Tag
&tag
);
70 void onTorrentAdded(BitTorrent::Torrent
*torrent
);
71 void onTorrentAboutToBeRemoved(BitTorrent::Torrent
*torrent
);
72 void onTorrentCategoryChanged(BitTorrent::Torrent
*torrent
, const QString
&oldCategory
);
73 void onTorrentMetadataReceived(BitTorrent::Torrent
*torrent
);
74 void onTorrentStopped(BitTorrent::Torrent
*torrent
);
75 void onTorrentStarted(BitTorrent::Torrent
*torrent
);
76 void onTorrentSavePathChanged(BitTorrent::Torrent
*torrent
);
77 void onTorrentSavingModeChanged(BitTorrent::Torrent
*torrent
);
78 void onTorrentTagAdded(BitTorrent::Torrent
*torrent
, const Tag
&tag
);
79 void onTorrentTagRemoved(BitTorrent::Torrent
*torrent
, const Tag
&tag
);
80 void onTorrentsUpdated(const QList
<BitTorrent::Torrent
*> &torrents
);
81 void onTorrentTrackersChanged(BitTorrent::Torrent
*torrent
);
83 qint64 m_freeDiskSpace
= 0;
85 QVariantMap m_lastPeersResponse
;
86 QVariantMap m_lastAcceptedPeersResponse
;
88 QHash
<QString
, QSet
<BitTorrent::TorrentID
>> m_knownTrackers
;
90 QSet
<QString
> m_updatedCategories
;
91 QSet
<QString
> m_removedCategories
;
92 QSet
<QString
> m_addedTags
;
93 QSet
<QString
> m_removedTags
;
94 QSet
<QString
> m_updatedTrackers
;
95 QSet
<QString
> m_removedTrackers
;
96 QSet
<BitTorrent::TorrentID
> m_updatedTorrents
;
97 QSet
<BitTorrent::TorrentID
> m_removedTorrents
;
99 struct MaindataSyncBuf
101 QHash
<QString
, QVariantMap
> categories
;
103 QHash
<QString
, QVariantMap
> torrents
;
104 QHash
<QString
, QStringList
> trackers
;
105 QVariantMap serverState
;
107 QStringList removedCategories
;
108 QStringList removedTags
;
109 QStringList removedTorrents
;
110 QStringList removedTrackers
;
113 MaindataSyncBuf m_maindataSnapshot
;
114 MaindataSyncBuf m_maindataSyncBuf
;
115 int m_maindataLastSentID
= 0;
116 int m_maindataAcceptedID
= -1;