2014-12-16 17:47:57 -08:00
|
|
|
// Copyright (c) 2014 The Bitcoin Core developers
|
2020-02-19 16:09:38 -08:00
|
|
|
// Copyright (c) 2020 The Zcash developers
|
2014-10-30 17:43:19 -07:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2019-07-18 07:16:09 -07:00
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2014-06-19 06:08:37 -07:00
|
|
|
|
|
|
|
#ifndef BITCOIN_TIMEDATA_H
|
|
|
|
#define BITCOIN_TIMEDATA_H
|
|
|
|
|
2020-02-19 16:09:38 -08:00
|
|
|
#include <set>
|
2014-09-14 03:43:56 -07:00
|
|
|
#include <stdint.h>
|
2014-06-19 06:08:37 -07:00
|
|
|
|
2020-02-19 16:09:38 -08:00
|
|
|
#include "netbase.h"
|
|
|
|
#include "sync.h"
|
2014-06-19 06:08:37 -07:00
|
|
|
|
2014-09-19 10:21:46 -07:00
|
|
|
|
2020-02-19 16:09:38 -08:00
|
|
|
class CTimeWarning
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CCriticalSection cs;
|
|
|
|
std::set<CNetAddr> setKnown;
|
|
|
|
size_t nPeersAhead;
|
|
|
|
size_t nPeersBehind;
|
2014-08-20 04:53:42 -07:00
|
|
|
|
2020-02-19 16:09:38 -08:00
|
|
|
public:
|
|
|
|
static const size_t TIMEDATA_WARNING_SAMPLES = 8;
|
|
|
|
static const size_t TIMEDATA_WARNING_MAJORITY = 6;
|
|
|
|
static const size_t TIMEDATA_MAX_SAMPLES = 20;
|
|
|
|
static const int64_t TIMEDATA_WARNING_THRESHOLD = 10 * 60;
|
|
|
|
static const int64_t TIMEDATA_IGNORE_THRESHOLD = 10 * 24 * 60 * 60;
|
2014-08-20 04:53:42 -07:00
|
|
|
|
2020-02-19 16:09:38 -08:00
|
|
|
CTimeWarning() : nPeersBehind(0), nPeersAhead(0) {}
|
|
|
|
virtual ~CTimeWarning() {}
|
2014-08-20 04:53:42 -07:00
|
|
|
|
2020-02-19 16:09:38 -08:00
|
|
|
int64_t AddTimeData(const CNetAddr& ip, int64_t nTime, int64_t now);
|
|
|
|
virtual void Warn(size_t peersAhead, size_t peersBehind);
|
2014-08-20 04:53:42 -07:00
|
|
|
};
|
|
|
|
|
2020-02-19 16:09:38 -08:00
|
|
|
extern CTimeWarning timeWarning;
|
2014-06-19 06:08:37 -07:00
|
|
|
|
2014-08-28 13:21:03 -07:00
|
|
|
#endif // BITCOIN_TIMEDATA_H
|