bc47a700a4
As we moved most of the creation of a BufferPool to be via the Streaming::pool() method, which uses a thread-local, it makes sense to start cleaning up the design and make it more modern C++. The above mentioned method would return a reference and you'd see loads of places use `auto &pool =` which is less than ideal. As the number of places where we actually instantiate a BufferPool goes down, the usage of some sort of smart pointer makes more sense. This now makes all APIs use BufferPool be wrapped in a shared_ptr.
105 lines
3.1 KiB
C++
105 lines
3.1 KiB
C++
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2019 Tom Zander <tom@flowee.org>
|
|
*
|
|
* 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 INDEXER_H
|
|
#define INDEXER_H
|
|
|
|
#include <QString>
|
|
|
|
#include <Message.h>
|
|
#include <NetworkManager.h>
|
|
#include <NetworkService.h>
|
|
#include <QMutex>
|
|
#include <QWaitCondition>
|
|
#include <WorkerThreads.h>
|
|
#include <qtimer.h>
|
|
#include <memory>
|
|
|
|
class AddressIndexer;
|
|
class TxIndexer;
|
|
class SpentOutputIndexer;
|
|
|
|
class Indexer : public QObject, public NetworkService
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
Indexer(const boost::filesystem::path &basedir);
|
|
~Indexer() override;
|
|
|
|
/// connect to server
|
|
void tryConnectHub(const EndPoint &ep);
|
|
|
|
/// listen to incoming requests
|
|
void bind(const boost::asio::ip::tcp::endpoint &endpoint);
|
|
|
|
/// load config, if prioHubLocation is valid prefer that one.
|
|
void loadConfig(const QString &filename, const EndPoint &prioHubLocation);
|
|
|
|
// network service API
|
|
void onIncomingMessage(Remote *con, const Message &message, const EndPoint &ep) override;
|
|
|
|
/// called by the workerthreads to get a block-message. Blocking.
|
|
/// \param height is the requested blockheight of the next block to process
|
|
Message nextBlock(int height, int *knownTip, unsigned long timeout = ULONG_MAX);
|
|
|
|
private slots:
|
|
void requestBlock(int newBlockHeight = -1);
|
|
void checkBlockArrived();
|
|
|
|
void onFindAddressRequest(const Message &message);
|
|
|
|
signals:
|
|
void requestFindAddress(const Message &message);
|
|
|
|
private:
|
|
void hubConnected(const EndPoint &ep);
|
|
void hubDisconnected();
|
|
void hubSentMessage(const Message &message);
|
|
|
|
void clientConnected(NetworkConnection &con);
|
|
|
|
private:
|
|
QTimer m_pollingTimer;
|
|
std::shared_ptr<Streaming::BufferPool> m_pool;
|
|
std::shared_ptr<Streaming::BufferPool> m_poolAddressAnswers; // FIXME use thread local instead
|
|
|
|
boost::filesystem::path m_basedir;
|
|
TxIndexer *m_txdb = nullptr;
|
|
SpentOutputIndexer *m_spentOutputDb = nullptr;
|
|
AddressIndexer *m_addressdb = nullptr;
|
|
|
|
WorkerThreads m_workers;
|
|
NetworkManager m_network;
|
|
NetworkConnection m_serverConnection;
|
|
|
|
bool m_isServer = false; /// remembers if we (successfully) called m_network::bind() once.
|
|
|
|
int m_lastRequestedBlock = 0;
|
|
qint64 m_timeLastRequest = 0;
|
|
qint64 m_timeLastLogLine = 0;
|
|
|
|
|
|
|
|
// data to process blocks in different workers.
|
|
Message m_nextBlock;
|
|
mutable std::atomic_int m_bestBlockHeight;
|
|
mutable QMutex m_nextBlockLock;
|
|
mutable QWaitCondition m_waitForBlock;
|
|
};
|
|
|
|
#endif
|