2016-12-20 14:26:45 +01:00
|
|
|
// Copyright (c) 2014-2017 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.
|
|
|
|
|
|
|
|
#ifndef NETFULFILLEDMAN_H
|
|
|
|
#define NETFULFILLEDMAN_H
|
|
|
|
|
2018-03-08 13:16:52 +01:00
|
|
|
#include "netaddress.h"
|
2016-09-27 09:50:04 +02:00
|
|
|
#include "serialize.h"
|
|
|
|
#include "sync.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
CCriticalSection cs_mapFulfilledRequests;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CNetFulfilledRequestManager() {}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2016-09-27 09:50:04 +02:00
|
|
|
LOCK(cs_mapFulfilledRequests);
|
|
|
|
READWRITE(mapFulfilledRequests);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
void RemoveFulfilledRequest(const CService& addr, const std::string& strRequest);
|
2016-09-27 09:50:04 +02:00
|
|
|
|
|
|
|
void CheckAndRemove();
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
std::string ToString() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|