dash/src/netfulfilledman.cpp
UdjinM6 7e8f07bb92
A couple of fixes for shutdown sequence (#2406)
* Do not run scheduled DoMaintenance if shutdown was requested

* Don't dump cache files if the load sequence was interrupted

* Stop privatesend and release keys before wallet flush

* fix typo
2018-11-02 00:58:17 +03:00

84 lines
2.6 KiB
C++

// Copyright (c) 2014-2017 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparams.h"
#include "init.h"
#include "netfulfilledman.h"
#include "util.h"
CNetFulfilledRequestManager netfulfilledman;
void CNetFulfilledRequestManager::AddFulfilledRequest(const CService& addr, const std::string& strRequest)
{
LOCK(cs_mapFulfilledRequests);
CService addrSquashed = Params().AllowMultiplePorts() ? addr : CService(addr, 0);
mapFulfilledRequests[addrSquashed][strRequest] = GetTime() + Params().FulfilledRequestExpireTime();
}
bool CNetFulfilledRequestManager::HasFulfilledRequest(const CService& addr, const std::string& strRequest)
{
LOCK(cs_mapFulfilledRequests);
CService addrSquashed = Params().AllowMultiplePorts() ? addr : CService(addr, 0);
fulfilledreqmap_t::iterator it = mapFulfilledRequests.find(addrSquashed);
return it != mapFulfilledRequests.end() &&
it->second.find(strRequest) != it->second.end() &&
it->second[strRequest] > GetTime();
}
void CNetFulfilledRequestManager::RemoveFulfilledRequest(const CService& addr, const std::string& strRequest)
{
LOCK(cs_mapFulfilledRequests);
CService addrSquashed = Params().AllowMultiplePorts() ? addr : CService(addr, 0);
fulfilledreqmap_t::iterator it = mapFulfilledRequests.find(addrSquashed);
if (it != mapFulfilledRequests.end()) {
it->second.erase(strRequest);
}
}
void CNetFulfilledRequestManager::CheckAndRemove()
{
LOCK(cs_mapFulfilledRequests);
int64_t now = GetTime();
fulfilledreqmap_t::iterator it = mapFulfilledRequests.begin();
while(it != mapFulfilledRequests.end()) {
fulfilledreqmapentry_t::iterator it_entry = it->second.begin();
while(it_entry != it->second.end()) {
if(now > it_entry->second) {
it->second.erase(it_entry++);
} else {
++it_entry;
}
}
if(it->second.size() == 0) {
mapFulfilledRequests.erase(it++);
} else {
++it;
}
}
}
void CNetFulfilledRequestManager::Clear()
{
LOCK(cs_mapFulfilledRequests);
mapFulfilledRequests.clear();
}
std::string CNetFulfilledRequestManager::ToString() const
{
std::ostringstream info;
info << "Nodes with fulfilled requests: " << (int)mapFulfilledRequests.size();
return info.str();
}
void CNetFulfilledRequestManager::DoMaintenance()
{
if (ShutdownRequested()) return;
CheckAndRemove();
}