@@ -39,31 +39,31 @@ int64_t GetAdjustedTime()
39
39
40
40
#define BITCOIN_TIMEDATA_MAX_SAMPLES 200
41
41
42
- static std::set<CNetAddr> setKnown ;
43
- static CMedianFilter<int64_t > vTimeOffsets ( BITCOIN_TIMEDATA_MAX_SAMPLES, 0 ) ;
44
- static bool fDone ;
42
+ static std::set<CNetAddr> g_sources ;
43
+ static CMedianFilter<int64_t > g_time_offsets{ BITCOIN_TIMEDATA_MAX_SAMPLES, 0 } ;
44
+ static bool g_warning_emitted ;
45
45
46
46
void AddTimeData (const CNetAddr& ip, int64_t nOffsetSample)
47
47
{
48
48
LOCK (g_timeoffset_mutex);
49
49
// Ignore duplicates
50
- if (setKnown .size () == BITCOIN_TIMEDATA_MAX_SAMPLES)
50
+ if (g_sources .size () == BITCOIN_TIMEDATA_MAX_SAMPLES)
51
51
return ;
52
- if (!setKnown .insert (ip).second )
52
+ if (!g_sources .insert (ip).second )
53
53
return ;
54
54
55
55
// Add data
56
- vTimeOffsets .input (nOffsetSample);
57
- LogPrint (BCLog::NET, " added time data, samples %d, offset %+d (%+d minutes)\n " , vTimeOffsets .size (), nOffsetSample, nOffsetSample / 60 );
56
+ g_time_offsets .input (nOffsetSample);
57
+ LogPrint (BCLog::NET, " added time data, samples %d, offset %+d (%+d minutes)\n " , g_time_offsets .size (), nOffsetSample, nOffsetSample / 60 );
58
58
59
59
// There is a known issue here (see issue #4521):
60
60
//
61
- // - The structure vTimeOffsets contains up to 200 elements, after which
61
+ // - The structure g_time_offsets contains up to 200 elements, after which
62
62
// any new element added to it will not increase its size, replacing the
63
63
// oldest element.
64
64
//
65
65
// - The condition to update nTimeOffset includes checking whether the
66
- // number of elements in vTimeOffsets is odd, which will never happen after
66
+ // number of elements in g_time_offsets is odd, which will never happen after
67
67
// there are 200 elements.
68
68
//
69
69
// But in this case the 'bug' is protective against some attacks, and may
@@ -73,25 +73,25 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
73
73
// So we should hold off on fixing this and clean it up as part of
74
74
// a timing cleanup that strengthens it in a number of other ways.
75
75
//
76
- if (vTimeOffsets .size () >= 5 && vTimeOffsets .size () % 2 == 1 ) {
77
- int64_t nMedian = vTimeOffsets .median ();
78
- std::vector<int64_t > vSorted = vTimeOffsets .sorted ();
76
+ if (g_time_offsets .size () >= 5 && g_time_offsets .size () % 2 == 1 ) {
77
+ int64_t nMedian = g_time_offsets .median ();
78
+ std::vector<int64_t > vSorted = g_time_offsets .sorted ();
79
79
// Only let other nodes change our time by so much
80
80
int64_t max_adjustment = std::max<int64_t >(0 , gArgs .GetIntArg (" -maxtimeadjustment" , DEFAULT_MAX_TIME_ADJUSTMENT));
81
81
if (nMedian >= -max_adjustment && nMedian <= max_adjustment) {
82
82
nTimeOffset = nMedian;
83
83
} else {
84
84
nTimeOffset = 0 ;
85
85
86
- if (!fDone ) {
86
+ if (!g_warning_emitted ) {
87
87
// If nobody has a time different than ours but within 5 minutes of ours, give a warning
88
88
bool fMatch = false ;
89
89
for (const int64_t nOffset : vSorted) {
90
90
if (nOffset != 0 && nOffset > -5 * 60 && nOffset < 5 * 60 ) fMatch = true ;
91
91
}
92
92
93
93
if (!fMatch ) {
94
- fDone = true ;
94
+ g_warning_emitted = true ;
95
95
bilingual_str strMessage = strprintf (_ (" Please check that your computer's date and time are correct! If your clock is wrong, %s will not work properly." ), PACKAGE_NAME);
96
96
SetMiscWarning (strMessage);
97
97
uiInterface.ThreadSafeMessageBox (strMessage, " " , CClientUIInterface::MSG_WARNING);
@@ -114,7 +114,7 @@ void TestOnlyResetTimeData()
114
114
{
115
115
LOCK (g_timeoffset_mutex);
116
116
nTimeOffset = 0 ;
117
- setKnown .clear ();
118
- vTimeOffsets = CMedianFilter<int64_t >( BITCOIN_TIMEDATA_MAX_SAMPLES, 0 ) ;
119
- fDone = false ;
117
+ g_sources .clear ();
118
+ g_time_offsets = CMedianFilter<int64_t >{ BITCOIN_TIMEDATA_MAX_SAMPLES, 0 } ;
119
+ g_warning_emitted = false ;
120
120
}
0 commit comments