aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorMichael Hendricks <michael@ndrix.org>2011-11-29 20:15:59 -0700
committerMichael Hendricks <michael@ndrix.org>2011-12-01 17:28:14 -0700
commit1c4aab926e0b25e0c896d4703d858eda1eb14ea5 (patch)
tree240889e74db6e8ebdbdbad818c7056d964eadde8 /src/util.h
parent5e1ddc421060e24bdcda75a863d9a5e03e633423 (diff)
Retain only the most recent time samples
Remembering all time samples makes nTimeOffset slow to respond to system clock corrections. For instance, I start my node with a system clock that's 30 minutes slow and run it for a few days. During that time, I accumulate 10,000 offset samples with a median of 1800 seconds. Now I correct my system clock. Without this change, my node must collect another 10,000 samples before nTimeOffset is correct again. With this change, I must only accumulate 100 samples to correct the offset. Storing unlimited time samples also allows an attacker with many IP addresses (ex, a large botnet) to perform a memory exhaustion attack against Bitcoin nodes. The attacker sends a version message from each IP to his target, consuming more of the target's memory each time. Time samples are small, so this attack might be impractical under the old code, but it's impossible with the new code.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index 1ef0e6f15c..0dcd01100e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -623,6 +623,16 @@ public:
return (vSorted[size/2-1] + vSorted[size/2]) / 2;
}
}
+
+ int size() const
+ {
+ return vValues.size();
+ }
+
+ std::vector<T> sorted () const
+ {
+ return vSorted;
+ }
};