aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_bwmgt.c
AgeCommit message (Collapse)Author
2023-05-24token_bucket_ctr: replace 32-bit wallclock time with monotimeMicah Elizabeth Scott
This started as a response to ticket #40792 where Coverity is complaining about a potential year 2038 bug where we cast time_t from approx_time() to uint32_t for use in token_bucket_ctr. There was a larger can of worms though, since token_bucket really doesn't want to be using wallclock time here. I audited the call sites for approx_time() and changed any that used a 32-bit cast or made inappropriate use of wallclock time. Things like certificate lifetime, consensus intervals, etc. need wallclock time. Measurements of rates over time, however, are better served with a monotonic timer that does not try and sync with wallclock ever. Looking closer at token_bucket, its design is a bit odd because it was initially intended for use with tick units but later forked into token_bucket_rw which uses ticks to count bytes per second, and token_bucket_ctr which uses seconds to count slower events. The rates represented by either token bucket can't be lower than 1 per second, so the slower timer in 'ctr' is necessary to represent the slower rates of things like connections or introduction packets or rendezvous attempts. I considered modifying token_bucket to use 64-bit timestamps overall instead of 32-bit, but that seemed like an unnecessarily invasive change that would grant some peace of mind but probably not help much. I was more interested in removing the dependency on wallclock time. The token_bucket_rw timer already uses monotonic time. This patch converts token_bucket_ctr to use monotonic time as well. It introduces a new monotime_coarse_absolute_sec(), which is currently the same as nsec divided by a billion but could be optimized easily if we ever need to. This patch also might fix a rollover bug.. I haven't tested this extensively but I don't think the previous version of the rollover code on either token bucket was correct, and I would expect it to get stuck after the first rollover. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2021-03-12Update copyrights to 2021, using "make update-copyright"Nick Mathewson
2020-07-14addr: Use tor_addr_t instead of uint32_t for IPv4David Goulet
This changes a LOT of code but in the end, behavior is the same. Unfortunately, many functions had to be changed to accomodate but in majority of cases, to become simpler. Functions are also removed specifically those that were there to convert an IPv4 as a host format to a tor_addr_t. Those are not needed anymore. The IPv4 address field has been standardized to "ipv4_addr", the ORPort to "ipv4_orport" (currently IPv6 uses ipv6_orport) and DirPort to "ipv4_dirport". This is related to Sponsor 55 work that adds IPv6 support for relays and this work is needed in order to have a common interface between IPv4 and IPv6. Closes #40043. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-02-11Merge branch 'ticket33029_042_01' into ticket33029_043_03David Goulet
Conflicts: doc/tor.1.txt src/app/config/config.c src/app/config/or_options_st.h src/core/mainloop/connection.h Between 042 and 043, the dirauth options were modularized so this merge commit address this by moving the AuthDirRejectUncompressedRequests to the module along with a series of accessors. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-02-11test: Add unit test for connection_dir_is_global_write_low()David Goulet
Part of #33029 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-01-08It's 2020. Update the copyright dates with "make update-copyright"Nick Mathewson
2019-01-16Bump copyright date to 2019Nick Mathewson
2018-08-06Merge branch 'maint-0.3.4'Nick Mathewson
2018-08-06Rename SEC identifier to BW_SEC in test_bwmgt.hNick Mathewson
Apparently Solaris 10 defines SEC somewhere in its headers, causing a compilation problem. Fixes bug 26994; bugfix on 0.3.4.1-alpha.
2018-07-05Fix every include path changed in the previous commit (automated)Nick Mathewson
I am very glad to have written this script.
2018-07-05Clean up include paths for libtor-evloop (automated)Nick Mathewson
2018-07-03Replace U64_LITERAL with the standard UINT64_CNick Mathewson
2018-06-20Run rectify_include_paths.pyNick Mathewson
2018-04-16token: Fix uint32_t to uint64_t conversionDavid Goulet
Unfortunately, the units passed to monotime_coarse_stamp_units_to_approx_msec() was always 0 due to a type conversion. Signed-off-by: David Goulet <dgoulet@torproject.org>
2018-04-13Fix "make check-spaces"Nick Mathewson
2018-04-13Refactor "timestamp" not to be its own type coupled to token buffersNick Mathewson
Really, the uint32_t is only an optimization; any kind of unit should work fine. Some users might want to use time_t or monotime_coarse_t or something like that.
2018-04-13Start re-refactoring the token bucket interface.Nick Mathewson
Begin by creating a lowest-level triple of the types needed to implement a token bucket: a configuration, a timestamp, and the raw bucket itself. Note that for low-level buckets, the units of the timestamp and the bucket itself are unspecified: each user can use a different type. (This patch breaks check-spaces; a later patch will fix it)
2018-04-13Rename token_bucket_t to token_bucket_rw_t.Nick Mathewson
This is a simple search-and-replace to rename the token bucket type to indicate that it contains both a read and a write bucket, bundled with their configuration. It's preliminary to refactoring the bucket type.
2018-04-13Increase tolerances for imprecise time.Nick Mathewson
2018-04-13Accept small hops backward in the monotonic timer.Nick Mathewson
2018-04-13Add a new token-bucket backend abstraction, with testsNick Mathewson
This differs from our previous token bucket abstraction in a few ways: 1) It is an abstraction, and not a collection of fields. 2) It is meant to be used with monotonic timestamps, which should produce better results than calling gettimeofday over and over.