Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

netfulfilledman.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2019 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <chainparams.h>
6 #include <init.h>
7 #include <netfulfilledman.h>
8 #include <util.h>
9 
11 
12 void CNetFulfilledRequestManager::AddFulfilledRequest(const CService& addr, const std::string& strRequest)
13 {
15  CService addrSquashed = Params().AllowMultiplePorts() ? addr : CService(addr, 0);
16  mapFulfilledRequests[addrSquashed][strRequest] = GetTime() + Params().FulfilledRequestExpireTime();
17 }
18 
19 bool CNetFulfilledRequestManager::HasFulfilledRequest(const CService& addr, const std::string& strRequest)
20 {
22  CService addrSquashed = Params().AllowMultiplePorts() ? addr : CService(addr, 0);
23  fulfilledreqmap_t::iterator it = mapFulfilledRequests.find(addrSquashed);
24 
25  return it != mapFulfilledRequests.end() &&
26  it->second.find(strRequest) != it->second.end() &&
27  it->second[strRequest] > GetTime();
28 }
29 
30 void CNetFulfilledRequestManager::RemoveFulfilledRequest(const CService& addr, const std::string& strRequest)
31 {
33  CService addrSquashed = Params().AllowMultiplePorts() ? addr : CService(addr, 0);
34  fulfilledreqmap_t::iterator it = mapFulfilledRequests.find(addrSquashed);
35 
36  if (it != mapFulfilledRequests.end()) {
37  it->second.erase(strRequest);
38  }
39 }
40 
42 {
44  CService addrSquashed = Params().AllowMultiplePorts() ? addr : CService(addr, 0);
45  fulfilledreqmap_t::iterator it = mapFulfilledRequests.find(addrSquashed);
46 
47  if (it != mapFulfilledRequests.end()) {
48  mapFulfilledRequests.erase(it++);
49  }
50 }
51 
53 {
55 
56  int64_t now = GetTime();
57  fulfilledreqmap_t::iterator it = mapFulfilledRequests.begin();
58 
59  while(it != mapFulfilledRequests.end()) {
60  fulfilledreqmapentry_t::iterator it_entry = it->second.begin();
61  while(it_entry != it->second.end()) {
62  if(now > it_entry->second) {
63  it->second.erase(it_entry++);
64  } else {
65  ++it_entry;
66  }
67  }
68  if(it->second.size() == 0) {
69  mapFulfilledRequests.erase(it++);
70  } else {
71  ++it;
72  }
73  }
74 }
75 
77 {
79  mapFulfilledRequests.clear();
80 }
81 
83 {
84  std::ostringstream info;
85  info << "Nodes with fulfilled requests: " << (int)mapFulfilledRequests.size();
86  return info.str();
87 }
88 
90 {
91  if (ShutdownRequested()) return;
92 
94 }
bool HasFulfilledRequest(const CService &addr, const std::string &strRequest)
void RemoveFulfilledRequest(const CService &addr, const std::string &strRequest)
bool ShutdownRequested()
Definition: init.cpp:179
int64_t GetTime()
Return system time (or mocked time, if set)
Definition: utiltime.cpp:22
#define LOCK(cs)
Definition: sync.h:178
CCriticalSection cs_mapFulfilledRequests
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:143
bool AllowMultiplePorts() const
Allow nodes with the same address and multiple ports.
Definition: chainparams.h:72
const CChainParams & Params()
Return the currently selected parameters.
int FulfilledRequestExpireTime() const
Definition: chainparams.h:95
CNetFulfilledRequestManager netfulfilledman
std::string ToString() const
fulfilledreqmap_t mapFulfilledRequests
void AddFulfilledRequest(const CService &addr, const std::string &strRequest)
void RemoveAllFulfilledRequests(const CService &addr)
Released under the MIT license