2024-04-27 20:34:06 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2025-02-11 19:52:03 +01:00
|
|
|
* Copyright (C) 2024-2025 Tom Zander <tom@flowee.org>
|
2024-04-27 20:34:06 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef INDEXERSERVICES_H
|
|
|
|
|
#define INDEXERSERVICES_H
|
|
|
|
|
|
|
|
|
|
#include <QMutex>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
2025-04-13 12:46:28 +02:00
|
|
|
#include <QDateTime>
|
2024-04-27 20:34:06 +02:00
|
|
|
|
2024-05-03 11:51:16 +02:00
|
|
|
#include <NetworkEndPoint.h>
|
|
|
|
|
#include <boost/asio.hpp>
|
2024-04-27 20:34:06 +02:00
|
|
|
#include <deque>
|
|
|
|
|
|
|
|
|
|
using boost::asio::ip::tcp;
|
|
|
|
|
|
|
|
|
|
class FetchIndexerServicePeers;
|
|
|
|
|
|
|
|
|
|
class IndexerServices : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2025-02-11 19:52:03 +01:00
|
|
|
explicit IndexerServices(const QString &basedir, boost::asio::io_context &ioContext, QObject *parent = nullptr);
|
2024-04-27 20:34:06 +02:00
|
|
|
|
|
|
|
|
void populate();
|
|
|
|
|
|
|
|
|
|
struct Indexer {
|
|
|
|
|
QString hostname;
|
|
|
|
|
QString ip;
|
|
|
|
|
int port = -1;
|
|
|
|
|
int securePort = -1;
|
|
|
|
|
uint32_t protocolVersion = 0;
|
|
|
|
|
|
|
|
|
|
int punishment = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void save();
|
|
|
|
|
|
2024-05-03 11:51:16 +02:00
|
|
|
/// return a single, (semi) random service provider.
|
|
|
|
|
EndPoint service() const;
|
|
|
|
|
|
|
|
|
|
void punish(const EndPoint &ep, int score);
|
|
|
|
|
|
2024-04-27 20:34:06 +02:00
|
|
|
signals:
|
|
|
|
|
void startMaybeFindServices();
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void maybeFindServices();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void load();
|
|
|
|
|
|
2025-02-11 19:52:03 +01:00
|
|
|
void onSeedLookupComplete(const boost::system::error_code &error, boost::asio::ip::tcp::resolver::results_type results);
|
2024-04-27 20:34:06 +02:00
|
|
|
|
|
|
|
|
std::deque<Indexer> m_knownServices;
|
|
|
|
|
tcp::resolver m_resolver;
|
|
|
|
|
mutable QMutex m_mutex;
|
|
|
|
|
QString m_basedir;
|
2025-04-13 12:46:28 +02:00
|
|
|
QDateTime m_lastAdjustDate;
|
|
|
|
|
QDateTime m_lastFetchDate;
|
2024-04-27 20:34:06 +02:00
|
|
|
|
|
|
|
|
FetchIndexerServicePeers *m_fetcher = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|