diff options
author | Riccardo Spagni <ric@spagni.net> | 2019-11-03 14:52:16 -0800 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2019-11-03 14:52:16 -0800 |
commit | 06b044176201fc4be89439a03d05e7ad840f44e0 (patch) | |
tree | 4641b636fd85cff61b6ce489ff8289328dc587eb /contrib | |
parent | Merge pull request #6077 (diff) | |
parent | simplewallet: plug a timing leak (diff) | |
download | monero-06b044176201fc4be89439a03d05e7ad840f44e0.tar.xz |
Merge pull request #6074
38f691048 simplewallet: plug a timing leak (moneromooo-monero)
dcff02e4c epee: allow a random component in once_a_time timeouts (moneromooo-monero)
e10833024 wallet: reuse cached height when set after refresh (moneromooo-monero)
5956beaa1 wallet2: fix is_synced checking target height, not height (moneromooo-monero)
fd35e2304 wallet: fix another facet of "did I get some monero" information leak (moneromooo-monero)
d5472bd87 wallet2: do not send an unnecessary last getblocks.bin call on refresh (moneromooo-monero)
97ae7bb5c wallet2: do not repeatedly ask for pool txes sent to us (moneromooo-monero)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/epee/include/math_helper.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h index 604a04680..29acffaea 100644 --- a/contrib/epee/include/math_helper.h +++ b/contrib/epee/include/math_helper.h @@ -32,6 +32,7 @@ #include <list> #include <numeric> +#include <random> #include <boost/timer/timer.hpp> #include <boost/uuid/uuid.hpp> #include <boost/uuid/random_generator.hpp> @@ -230,7 +231,7 @@ namespace math_helper } } - template<uint64_t scale, int default_interval, bool start_immediate = true> + template<typename get_interval, bool start_immediate = true> class once_a_time { uint64_t get_time() const @@ -251,12 +252,18 @@ namespace math_helper #endif } + void set_next_interval() + { + m_interval = get_interval()(); + } + public: - once_a_time():m_interval(default_interval * scale) + once_a_time() { m_last_worked_time = 0; if(!start_immediate) m_last_worked_time = get_time(); + set_next_interval(); } void trigger() @@ -273,6 +280,7 @@ namespace math_helper { bool res = functr(); m_last_worked_time = get_time(); + set_next_interval(); return res; } return true; @@ -283,9 +291,13 @@ namespace math_helper uint64_t m_interval; }; + template<uint64_t N> struct get_constant_interval { public: uint64_t operator()() const { return N; } }; + template<int default_interval, bool start_immediate = true> - class once_a_time_seconds: public once_a_time<1000000, default_interval, start_immediate> {}; + class once_a_time_seconds: public once_a_time<get_constant_interval<default_interval * (uint64_t)1000000>, start_immediate> {}; template<int default_interval, bool start_immediate = true> - class once_a_time_milliseconds: public once_a_time<1000, default_interval, start_immediate> {}; + class once_a_time_milliseconds: public once_a_time<get_constant_interval<default_interval * (uint64_t)1000>, start_immediate> {}; + template<typename get_interval, bool start_immediate = true> + class once_a_time_seconds_range: public once_a_time<get_interval, start_immediate> {}; } } |