dash/src/netfulfilledman.h
PastaPastaPasta f503a7edc1
refactor: Fix warnings from cppcheck (#4625)
* src/evo/evodb.cpp:57:29: warning: Assert statement calls a function which may have desired side effects: 'IsClean'. [assertWithSideEffect]

* src/llmq/quorums.cpp:635:37: note: Null pointer dereference

src/llmq/quorums.cpp:635:37: warning: Either the condition 'pFrom==nullptr' is redundant or there is possible null pointer dereference: pFrom. [nullPointerRedundantCheck]
src/llmq/quorums.cpp:636:81: note: Assuming that condition 'pFrom==nullptr' is not redundant

* fix a bunch of cppcheck warnings

* cppcheck: run on many more files. Enable all checks except a few ignored ones.

ignored
```
    "Consider using std::transform algorithm instead of a raw loop."
    "Consider using std::accumulate algorithm instead of a raw loop."
```

* ci: build specific version of cppcheck instead of install from apt

* ci: use cppcheck 2.4, remove commented out line, fix symlink

cppcheck 2.6 is latest, however causes issues
```
src/spork.cpp:135:51: warning: Analysis failed. If the code is valid then please report this failure. [cppcheckError]
```
cppcheck 2.5 appears to get into an infinite loop

* no need to check presence before insertion

* use if-init, remove redundant check

* remove redundant check

* don't remove cmake? fix macOs depends build?

* cppcheck: one per line, alphabetize

* remove duplicate cmake install
2021-12-29 00:54:50 +03:00

50 lines
1.4 KiB
C++

// Copyright (c) 2014-2020 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.
#ifndef BITCOIN_NETFULFILLEDMAN_H
#define BITCOIN_NETFULFILLEDMAN_H
#include <netaddress.h>
#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;
typedef std::map<CService, fulfilledreqmapentry_t> fulfilledreqmap_t;
//keep track of what node has/was asked for and when
fulfilledreqmap_t mapFulfilledRequests;
mutable CCriticalSection cs_mapFulfilledRequests;
public:
CNetFulfilledRequestManager() {}
SERIALIZE_METHODS(CNetFulfilledRequestManager, obj)
{
LOCK(obj.cs_mapFulfilledRequests);
READWRITE(obj.mapFulfilledRequests);
}
void AddFulfilledRequest(const CService& addr, const std::string& strRequest);
bool HasFulfilledRequest(const CService& addr, const std::string& strRequest);
void RemoveAllFulfilledRequests(const CService& addr);
void CheckAndRemove();
void Clear();
std::string ToString() const;
void DoMaintenance();
};
#endif // BITCOIN_NETFULFILLEDMAN_H