2021-04-20 21:33:02 +02:00
|
|
|
// Copyright (c) 2014-2020 The Dash Core developers
|
2016-09-27 09:50:04 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#ifndef BITCOIN_NETFULFILLEDMAN_H
|
|
|
|
#define BITCOIN_NETFULFILLEDMAN_H
|
2016-09-27 09:50:04 +02:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <netaddress.h>
|
|
|
|
#include <serialize.h>
|
|
|
|
#include <sync.h>
|
2016-09-27 09:50:04 +02:00
|
|
|
|
|
|
|
class CNetFulfilledRequestManager;
|
|
|
|
extern CNetFulfilledRequestManager netfulfilledman;
|
|
|
|
|
|
|
|
// Fulfilled requests are used to prevent nodes from asking for the same data on sync
|
|
|
|
// and from being banned for doing so too often.
|
|
|
|
class CNetFulfilledRequestManager
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef std::map<std::string, int64_t> fulfilledreqmapentry_t;
|
2018-03-08 13:16:52 +01:00
|
|
|
typedef std::map<CService, fulfilledreqmapentry_t> fulfilledreqmap_t;
|
2016-09-27 09:50:04 +02:00
|
|
|
|
|
|
|
//keep track of what node has/was asked for and when
|
|
|
|
fulfilledreqmap_t mapFulfilledRequests;
|
2021-05-27 17:17:29 +02:00
|
|
|
mutable CCriticalSection cs_mapFulfilledRequests;
|
2016-09-27 09:50:04 +02:00
|
|
|
|
2018-04-18 13:49:25 +02:00
|
|
|
void RemoveFulfilledRequest(const CService& addr, const std::string& strRequest);
|
|
|
|
|
2016-09-27 09:50:04 +02:00
|
|
|
public:
|
|
|
|
CNetFulfilledRequestManager() {}
|
|
|
|
|
2021-05-27 17:17:29 +02:00
|
|
|
SERIALIZE_METHODS(CNetFulfilledRequestManager, obj)
|
|
|
|
{
|
|
|
|
LOCK(obj.cs_mapFulfilledRequests);
|
|
|
|
READWRITE(obj.mapFulfilledRequests);
|
2016-09-27 09:50:04 +02:00
|
|
|
}
|
|
|
|
|
2018-03-08 13:16:52 +01:00
|
|
|
void AddFulfilledRequest(const CService& addr, const std::string& strRequest);
|
|
|
|
bool HasFulfilledRequest(const CService& addr, const std::string& strRequest);
|
2016-09-27 09:50:04 +02:00
|
|
|
|
2019-12-31 11:01:48 +01:00
|
|
|
void RemoveAllFulfilledRequests(const CService& addr);
|
|
|
|
|
2016-09-27 09:50:04 +02:00
|
|
|
void CheckAndRemove();
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
std::string ToString() const;
|
2018-07-16 14:47:37 +02:00
|
|
|
|
2018-11-01 22:58:17 +01:00
|
|
|
void DoMaintenance();
|
2016-09-27 09:50:04 +02:00
|
|
|
};
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#endif // BITCOIN_NETFULFILLEDMAN_H
|