2020-04-17 19:33:06 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2023-02-21 20:29:26 +01:00
|
|
|
* Copyright (C) 2020-2023 Tom Zander <tom@flowee.org>
|
2020-04-17 19:33: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/>.
|
|
|
|
|
*/
|
2024-01-22 19:32:15 +01:00
|
|
|
#ifndef FLOWEE_SYNCSPVACTION_H
|
|
|
|
|
#define FLOWEE_SYNCSPVACTION_H
|
2020-04-17 19:33:06 +02:00
|
|
|
|
|
|
|
|
#include "Action.h"
|
|
|
|
|
|
|
|
|
|
#include <bloom.h>
|
|
|
|
|
#include <map>
|
2024-02-23 22:08:28 +01:00
|
|
|
#include <random>
|
2020-04-17 19:33:06 +02:00
|
|
|
#include <set>
|
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
|
|
|
|
|
|
|
|
class PrivacySegment;
|
|
|
|
|
|
2021-07-30 14:04:58 +02:00
|
|
|
/**
|
|
|
|
|
* The goal of this action is to make sure all SPV wallets are synched to the chain-tip.
|
|
|
|
|
*
|
|
|
|
|
* This action is started every time when the header is moved. We run every couple of seconds
|
|
|
|
|
* and have the responsibility to start connections to peers and make sure the SPV wallets have
|
|
|
|
|
* good enough data to ensure they have all the information they need using merkleblock downloads.
|
|
|
|
|
*/
|
2020-04-17 19:33:06 +02:00
|
|
|
class SyncSPVAction : public Action
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SyncSPVAction(DownloadManager *parent);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void execute(const boost::system::error_code &error) override;
|
|
|
|
|
|
|
|
|
|
private:
|
2024-02-23 22:08:28 +01:00
|
|
|
std::random_device m_randomDevice;
|
|
|
|
|
|
2020-11-13 20:11:06 +01:00
|
|
|
struct PeerDownloadInfo {
|
|
|
|
|
int peerId;
|
|
|
|
|
int fromBlock;
|
|
|
|
|
int toBlock; // to-and-including
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-17 19:33:06 +02:00
|
|
|
struct Info {
|
|
|
|
|
boost::posix_time::ptime lastCheckedTime;
|
|
|
|
|
int lastHeight = 0;
|
|
|
|
|
int slowPunishment = 0; // punishment score for being slow
|
2024-01-28 21:27:54 +01:00
|
|
|
int connectionsTriedForWallet = 0;
|
2020-04-17 19:33:06 +02:00
|
|
|
|
2020-11-13 20:11:06 +01:00
|
|
|
/**
|
|
|
|
|
* Remember which blocks were downloaded by which peer in order to actually
|
|
|
|
|
* get our security that when we ask multiple peers for the same blocks, we
|
|
|
|
|
* don't mess up and ask the same one twice.
|
|
|
|
|
*/
|
|
|
|
|
std::vector<PeerDownloadInfo> previousDownloads;
|
2020-04-17 19:33:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::map<PrivacySegment*, Info> m_segmentInfos;
|
2021-07-30 14:04:58 +02:00
|
|
|
|
|
|
|
|
// if nothing happened several calls, we consider us finished
|
|
|
|
|
int m_quietCount = 0;
|
2021-10-31 15:14:34 +01:00
|
|
|
|
|
|
|
|
const int MinPeersPerWallet;
|
2020-04-17 19:33:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|