]> git.ipfire.org Git - thirdparty/tor.git/log
thirdparty/tor.git
7 years agoEnsure that global buckets are updated on configuration change
Nick Mathewson [Tue, 10 Apr 2018 17:40:34 +0000 (13:40 -0400)] 
Ensure that global buckets are updated on configuration change

7 years agoReplace the global buckets with token_bucket_t
Nick Mathewson [Tue, 10 Apr 2018 17:19:25 +0000 (13:19 -0400)] 
Replace the global buckets with token_bucket_t

7 years agoRefactor or_connection token buckets to use token_bucket_t
Nick Mathewson [Tue, 10 Apr 2018 16:34:28 +0000 (12:34 -0400)] 
Refactor or_connection token buckets to use token_bucket_t

7 years agoAdd a helper function to decrement read and write at the same time
Nick Mathewson [Tue, 10 Apr 2018 16:33:30 +0000 (12:33 -0400)] 
Add a helper function to decrement read and write at the same time

7 years agoAdd a new token-bucket backend abstraction, with tests
Nick Mathewson [Tue, 10 Apr 2018 15:23:14 +0000 (11:23 -0400)] 
Add a new token-bucket backend abstraction, with tests

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.

7 years agoExpose a function that computes stamp units from msec.
Nick Mathewson [Tue, 10 Apr 2018 14:47:11 +0000 (10:47 -0400)] 
Expose a function that computes stamp units from msec.

(It turns out we can't just expose STAMP_TICKS_PER_SECOND, since
Apple doesn't have that.)

7 years agoRemove TestingEnableTbEmptyEvent
Nick Mathewson [Tue, 10 Apr 2018 16:16:21 +0000 (12:16 -0400)] 
Remove TestingEnableTbEmptyEvent

This option was used for shadow testing previously, but is no longer
used for anything.  It interferes with refactoring our token buckets.

7 years agocompat: Fix unchecked return value from event_del()
David Goulet [Mon, 9 Apr 2018 18:09:40 +0000 (14:09 -0400)] 
compat: Fix unchecked return value from event_del()

Explicitly tell the compiler we don't care about it.

Coverity CID 1434156

Signed-off-by: David Goulet <dgoulet@torproject.org>
7 years agoAdd a comment explaining why we do a certain redundant check
Nick Mathewson [Mon, 9 Apr 2018 16:58:17 +0000 (12:58 -0400)] 
Add a comment explaining why we do a certain redundant check

Closes ticket 25291.

7 years agoInclude tor_log rust files in source distribution.
Nick Mathewson [Fri, 6 Apr 2018 20:19:14 +0000 (16:19 -0400)] 
Include tor_log rust files in source distribution.

Fixes another case of #25732; bug not in any released Tor.

7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Fri, 6 Apr 2018 20:18:47 +0000 (16:18 -0400)] 
Merge branch 'maint-0.3.3'

7 years agoShip all files needed to build Tor with rust
Nick Mathewson [Fri, 6 Apr 2018 20:18:11 +0000 (16:18 -0400)] 
Ship all files needed to build Tor with rust

Fixes bug 25732; bugfix on 0.3.3.2-alpha when strings.rs was
introduced.

7 years agoMerge branch 'isolate_libevent_2_squashed'
Nick Mathewson [Fri, 6 Apr 2018 12:50:35 +0000 (08:50 -0400)] 
Merge branch 'isolate_libevent_2_squashed'

7 years agofix confusing comment
Roger Dingledine [Thu, 5 Apr 2018 19:59:37 +0000 (15:59 -0400)] 
fix confusing comment

presumably introduced by copy-and-paste mistake

7 years agochanges file for libevent isolation work
Nick Mathewson [Tue, 3 Oct 2017 17:02:59 +0000 (13:02 -0400)] 
changes file for libevent isolation work

7 years agoRemove needless event2/thread.h include from test_compat_libevent.c
Nick Mathewson [Tue, 3 Oct 2017 17:01:31 +0000 (13:01 -0400)] 
Remove needless event2/thread.h include from test_compat_libevent.c

7 years agoRemove redundant event2/event.h usage from test_scheduler.c
Nick Mathewson [Tue, 3 Oct 2017 16:58:19 +0000 (12:58 -0400)] 
Remove redundant event2/event.h usage from test_scheduler.c

This module doesn't actually need to mock the libevent mainloop at
all: it can just use the regular mainloop that the test environment
sets up.

Part of ticket 23750.

7 years agoMove responsibility for threadpool reply-handler events to workqueue
Nick Mathewson [Tue, 3 Oct 2017 16:49:34 +0000 (12:49 -0400)] 
Move responsibility for threadpool reply-handler events to workqueue

This change makes cpuworker and test_workqueue no longer need to
include event2/event.h.  Now workqueue.c needs to include it, but
that is at least somewhat logical here.

7 years agoWrap the function we use to run the event loop.
Nick Mathewson [Tue, 3 Oct 2017 15:20:59 +0000 (11:20 -0400)] 
Wrap the function we use to run the event loop.

Doing this lets us remove the event2/event.h header from a few more
modules, particularly in the tests.

Part of work on 23750.

7 years agoAdd wrappers for event_base_loopexit and event_base_loopbreak.
Nick Mathewson [Tue, 3 Oct 2017 15:09:44 +0000 (11:09 -0400)] 
Add wrappers for event_base_loopexit and event_base_loopbreak.

7 years agoRevise procmon.c to use periodic_timer_t
Nick Mathewson [Tue, 3 Oct 2017 14:52:34 +0000 (10:52 -0400)] 
Revise procmon.c to use periodic_timer_t

This removes its need to use event2/event.h, and thereby fixes
another instance of 23750.

7 years agoAdd an API for a scheduled/manually activated event in the mainloop
Nick Mathewson [Tue, 3 Oct 2017 14:44:45 +0000 (10:44 -0400)] 
Add an API for a scheduled/manually activated event in the mainloop

Using this API lets us remove event2/event.h usage from half a dozen
modules, to better isolate libevent.  Implements part of ticket
23750.

7 years agoMerge remote-tracking branch 'public/split_relay_crypto'
Nick Mathewson [Thu, 5 Apr 2018 16:12:18 +0000 (12:12 -0400)] 
Merge remote-tracking branch 'public/split_relay_crypto'

7 years agoMerge branch 'maint-0.3.2' into maint-0.3.3
Nick Mathewson [Thu, 5 Apr 2018 16:09:00 +0000 (12:09 -0400)] 
Merge branch 'maint-0.3.2' into maint-0.3.3

7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Thu, 5 Apr 2018 16:09:00 +0000 (12:09 -0400)] 
Merge branch 'maint-0.3.3'

7 years agoMerge branch 'ticket25296_032_squashed' into maint-0.3.2
Nick Mathewson [Thu, 5 Apr 2018 16:08:53 +0000 (12:08 -0400)] 
Merge branch 'ticket25296_032_squashed' into maint-0.3.2

7 years agoPerConnBW{Rate,Burst} docs: do not say consensus param is always set
Nick Mathewson [Mon, 19 Mar 2018 10:14:57 +0000 (06:14 -0400)] 
PerConnBW{Rate,Burst} docs: do not say consensus param is always set

Closes ticket 25296; bugfix on 0.2.2.7-alpha when these manpage
entries were introduced.

7 years agoman: Move RephistTrackTime to the server section
David Goulet [Thu, 5 Apr 2018 13:42:45 +0000 (09:42 -0400)] 
man: Move RephistTrackTime to the server section

Every node in the network uses that value, it is a general server options, not
a dirauth specific one.

Fixes #25720

Signed-off-by: David Goulet <dgoulet@torproject.org>
7 years agoSwitch to use should_record_bridge_info()
Neel Chauhan [Thu, 5 Apr 2018 12:35:21 +0000 (08:35 -0400)] 
Switch to use should_record_bridge_info()

Both in geoip_note_client_seen() and options_need_geoip_info(), switch from
accessing the options directly to using the should_record_bridge_info() helper
function.

Fixes #25290

Signed-off-by: David Goulet <dgoulet@torproject.org>
7 years agoMerge branch 'maint-0.3.2' into maint-0.3.3
Nick Mathewson [Thu, 5 Apr 2018 12:36:13 +0000 (08:36 -0400)] 
Merge branch 'maint-0.3.2' into maint-0.3.3

7 years agoMerge branch 'maint-0.3.1' into maint-0.3.2
Nick Mathewson [Thu, 5 Apr 2018 12:36:13 +0000 (08:36 -0400)] 
Merge branch 'maint-0.3.1' into maint-0.3.2

7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Thu, 5 Apr 2018 12:36:13 +0000 (08:36 -0400)] 
Merge branch 'maint-0.3.3'

7 years agoSwitch Travis to stable rust
Taylor Yu [Wed, 4 Apr 2018 22:07:39 +0000 (17:07 -0500)] 
Switch Travis to stable rust

7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Thu, 5 Apr 2018 12:22:35 +0000 (08:22 -0400)] 
Merge branch 'maint-0.3.3'

7 years agoMerge branch 'maint-0.3.2' into maint-0.3.3
Nick Mathewson [Thu, 5 Apr 2018 12:22:34 +0000 (08:22 -0400)] 
Merge branch 'maint-0.3.2' into maint-0.3.3

7 years agoMerge branch 'maint-0.3.1' into maint-0.3.2
Nick Mathewson [Thu, 5 Apr 2018 12:22:34 +0000 (08:22 -0400)] 
Merge branch 'maint-0.3.1' into maint-0.3.2

7 years agoMerge branch 'maint-0.2.9' into maint-0.3.1
Nick Mathewson [Thu, 5 Apr 2018 12:22:34 +0000 (08:22 -0400)] 
Merge branch 'maint-0.2.9' into maint-0.3.1

7 years agoMerge branch 'maint-0.2.5' into maint-0.2.9
Nick Mathewson [Thu, 5 Apr 2018 12:22:33 +0000 (08:22 -0400)] 
Merge branch 'maint-0.2.5' into maint-0.2.9

7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Thu, 5 Apr 2018 12:21:43 +0000 (08:21 -0400)] 
Merge branch 'maint-0.3.3'

7 years agoMerge remote-tracking branch 'dgoulet/bug25582_033' into maint-0.3.3
Nick Mathewson [Thu, 5 Apr 2018 12:21:38 +0000 (08:21 -0400)] 
Merge remote-tracking branch 'dgoulet/bug25582_033' into maint-0.3.3

7 years agoMerge branch 'bug25679_033_squashed' into maint-0.3.3
Nick Mathewson [Thu, 5 Apr 2018 12:20:15 +0000 (08:20 -0400)] 
Merge branch 'bug25679_033_squashed' into maint-0.3.3

7 years agoFix the default for TOR_RUST_DEPENDENCIES
Nick Mathewson [Fri, 30 Mar 2018 12:53:58 +0000 (08:53 -0400)] 
Fix the default for TOR_RUST_DEPENDENCIES

By default, we want to look at the crates directory of the
submodule, not the toplevel of the submodule.  Fixes bug 25679;
bugfix on 0.3.3.1-alpha.

7 years agoUpdate geoip and geoip6 to the April 3 2018 database. maint-0.2.5
Karsten Loesing [Thu, 5 Apr 2018 08:42:25 +0000 (10:42 +0200)] 
Update geoip and geoip6 to the April 3 2018 database.

7 years agoman: Add a comment to anchor only option
David Goulet [Wed, 4 Apr 2018 15:38:42 +0000 (11:38 -0400)] 
man: Add a comment to anchor only option

Some anchor don't appear in the final man page so document those so we
understand why we do that in the future.

Part of #25582

Signed-off-by: David Goulet <dgoulet@torproject.org>
7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Wed, 4 Apr 2018 12:57:24 +0000 (08:57 -0400)] 
Merge branch 'maint-0.3.3'

7 years agoMerge branch 'bug21394_029_redux' into maint-0.3.3
Nick Mathewson [Wed, 4 Apr 2018 12:55:37 +0000 (08:55 -0400)] 
Merge branch 'bug21394_029_redux' into maint-0.3.3

7 years agoBug 21394 touchup: Increase DNS attempts to 3
Dhalgren [Sun, 1 Apr 2018 05:01:51 +0000 (05:01 +0000)] 
Bug 21394 touchup: Increase DNS attempts to 3

Also don't give up on a resolver as quickly if multiple are configured.

7 years agoMerge remote-tracking branch 'fristonio/ticket-25645'
Nick Mathewson [Tue, 3 Apr 2018 23:19:02 +0000 (19:19 -0400)] 
Merge remote-tracking branch 'fristonio/ticket-25645'

7 years agoFix bug24031 changes file
Nick Mathewson [Tue, 3 Apr 2018 23:03:33 +0000 (19:03 -0400)] 
Fix bug24031 changes file

7 years agoMerge remote-tracking branch 'isis-github/bug24031_r5_squashed'
Nick Mathewson [Tue, 3 Apr 2018 19:33:50 +0000 (15:33 -0400)] 
Merge remote-tracking branch 'isis-github/bug24031_r5_squashed'

7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Tue, 3 Apr 2018 19:33:29 +0000 (15:33 -0400)] 
Merge branch 'maint-0.3.3'

7 years agoadd a missing word
Nick Mathewson [Tue, 3 Apr 2018 19:31:30 +0000 (15:31 -0400)] 
add a missing word

7 years agoMerge remote-tracking branch 'isis-github/bug24031_r5_squashed_033' into maint-0.3.3
Nick Mathewson [Tue, 3 Apr 2018 19:29:29 +0000 (15:29 -0400)] 
Merge remote-tracking branch 'isis-github/bug24031_r5_squashed_033' into maint-0.3.3

7 years agochanges: Add changes file for #24031.
Isis Lovecruft [Tue, 3 Apr 2018 19:19:40 +0000 (19:19 +0000)] 
changes: Add changes file for #24031.

(cherry picked from commit 5a8cdec3f8617920f19e3ab7707233ad3f02424f)

7 years agochanges: Add changes file for #24031.
Isis Lovecruft [Tue, 3 Apr 2018 19:19:40 +0000 (19:19 +0000)] 
changes: Add changes file for #24031.

7 years agoticket(25645): remove unused variable n_possible from channel_get_for_extend()
Deepesh Pathak [Tue, 3 Apr 2018 03:47:23 +0000 (09:17 +0530)] 
ticket(25645): remove unused variable n_possible from channel_get_for_extend()

7 years agorust: Fix ProtoSet and ProtoEntry to use the same DoS limits as C.
Isis Lovecruft [Tue, 27 Mar 2018 22:46:14 +0000 (22:46 +0000)] 
rust: Fix ProtoSet and ProtoEntry to use the same DoS limits as C.

Previously, the limit for MAX_PROTOCOLS_TO_EXPAND was actually being applied
in Rust to the maximum number of version (total, for all subprotocols).
Whereas in C, it was being applied to the number of subprotocols that were
allowed.  This changes the Rust to match C's behaviour.

7 years agorust: Port all C protover_all_supported tests to Rust.
Isis Lovecruft [Tue, 27 Mar 2018 21:38:29 +0000 (21:38 +0000)] 
rust: Port all C protover_all_supported tests to Rust.

The behaviours still do not match, unsurprisingly, but now we know where a
primary difference is: the Rust is validating version ranges more than the C,
so in the C it's possible to call protover_all_supported on a ridiculous
version range like "Sleen=0-4294967294" because the C uses
MAX_PROTOCOLS_TO_EXPAND to count the number of *subprotocols* whereas the Rust
uses it to count the total number of *versions* of all subprotocols.

7 years agotests: Run all existing protover tests in both languages.
Isis Lovecruft [Tue, 27 Mar 2018 21:36:10 +0000 (21:36 +0000)] 
tests: Run all existing protover tests in both languages.

There's now no difference in these tests w.r.t. the C or Rust: both
fail miserably (well, Rust fails with nice descriptive errors, and C
gives you a traceback, because, well, C).

7 years agotests: Make inline comments in test_protover.c more accurate.
Isis Lovecruft [Tue, 27 Mar 2018 21:34:00 +0000 (21:34 +0000)] 
tests: Make inline comments in test_protover.c more accurate.

The DoS potential is slightly higher in C now due to some differences to the
Rust code, see the C_RUST_DIFFERS tags in src/rust/protover/tests/protover.rs.

Also, the comment about "failing at the splitting stage" in Rust wasn't true,
since when we split, we ignore empty chunks (e.g. "1--1" parses into
"(1,None),(None,1)" and "None" can't be parsed into an integer).

Finally, the comment about "Rust seems to experience an internal error" is only
true in debug mode, where u32s are bounds-checked at runtime.  In release mode,
code expressing the equivalent of this test will error with
`Err(ProtoverError::Unparseable)` because 4294967295 is too large.

7 years agoprotover: Change protover_all_supported() to return only unsupported.
Isis Lovecruft [Tue, 27 Mar 2018 16:59:49 +0000 (16:59 +0000)] 
protover: Change protover_all_supported() to return only unsupported.

Previously, if "Link=1-5" was supported, and you asked protover_all_supported()
(or protover::all_supported() in Rust) if it supported "Link=3-999", the C
version would return "Link=3-999" and the Rust would return "Link=6-999".  These
both behave the same now, i.e. both return "Link=6-999".

7 years agorust: Refactor protover::compute_for_old_tor().
Isis Lovecruft [Tue, 27 Mar 2018 02:41:25 +0000 (02:41 +0000)] 
rust: Refactor protover::compute_for_old_tor().

During code review and discussion with Chelsea Komlo, she pointed out
that protover::compute_for_old_tor() was a public function whose
return type was `&'static CStr`.  We both agree that C-like parts of
APIs should:

1. not be exposed publicly (to other Rust crates),
2. only be called in the appropriate FFI code,
3. not expose types which are meant for FFI code (e.g. `*mut char`,
   `CString`, `*const c_int`, etc.) to the pure-Rust code of other
   crates.
4. FFI code (e.g. things in `ffi.rs` modules) should _never_ be called
   from pure-Rust, not even from other modules in its own crate
   (i.e. do not call `protover::ffi::*` from anywhere in
   `protover::protoset::*`, etc).

With that in mind, this commit makes the following changes:

 * CHANGE `protover::compute_for_old_tor()` to be
   visible only at the `pub(crate)` level.
 * RENAME `protover::compute_for_old_tor()` to
   `protover::compute_for_old_tor_cstr()` to reflect the last change.
 * ADD a new `protover::compute_for_old_tor()` function wrapper which
   is public and intended for other Rust code to use, which returns a
   `&str`.

7 years agorust: Refactor Rust implementation of protover_is_supported_here().
Isis Lovecruft [Wed, 21 Mar 2018 03:08:35 +0000 (03:08 +0000)] 
rust: Refactor Rust implementation of protover_is_supported_here().

It was changed to take borrows instead of taking ownership.

 * REFACTOR `protover::ffi::protover_is_supported_here()` to use changed method
   signature on `protover::is_supported_here()`.

7 years agorust: Refactor Rust impl of protover_compute_vote().
Isis Lovecruft [Wed, 21 Mar 2018 03:05:56 +0000 (03:05 +0000)] 
rust: Refactor Rust impl of protover_compute_vote().

This includes a subtle difference in behaviour to the previous Rust
implementation, where, for each vote that we're computing over, if a single one
fails to parse, we skip it.  This now matches the current behaviour in the C
implementation.

 * REFACTOR `protover::ffi::protover_compute_vote()` to use
   new types and methods.

7 years agorust: Refactor Rust impl of protover_list_supports_protocol_or_later().
Isis Lovecruft [Wed, 21 Mar 2018 02:59:25 +0000 (02:59 +0000)] 
rust: Refactor Rust impl of protover_list_supports_protocol_or_later().

This includes a subtle difference in behaviour, as in 4258f1e18, where we return
(matching the C impl's return behaviour) earlier than before if parsing failed,
saving us computation in parsing the versions into a
protover::protoset::ProtoSet.

 * REFACTOR `protover::ffi::protover_list_supports_protocol_or_later()` to use
   new types and methods.

7 years agorust: Refactor Rust impl of protover_list_supports_protocol().
Isis Lovecruft [Wed, 21 Mar 2018 02:52:04 +0000 (02:52 +0000)] 
rust: Refactor Rust impl of protover_list_supports_protocol().

This includes a subtle difference in behaviour, as in 4258f1e18, where we return
(matching the C impl's return behaviour) earlier than before if parsing failed,
saving us computation in parsing the versions into a
protover::protoset::ProtoSet.

 * REFACTOR `protover::ffi::protover_list_supports_protocol()` to use new types
   and methods.

7 years agorust: Refactor Rust impl of protover_all_supported().
Isis Lovecruft [Wed, 21 Mar 2018 02:45:41 +0000 (02:45 +0000)] 
rust: Refactor Rust impl of protover_all_supported().

This includes differences in behaviour to before, which should now more closely
match the C version:

 - If parsing a protover `char*` from C, and the string is not parseable, this
   function will return 1 early, which matches the C behaviour when protocols
   are unparseable.  Previously, we would parse it and its version numbers
   simultaneously, i.e. there was no fail early option, causing us to spend more
   time unnecessarily parsing versions.

 * REFACTOR `protover::ffi::protover_all_supported()` to use new types and
   methods.

7 years agorust: Refactor protover tests with new methods; note altered behaviours.
Isis Lovecruft [Wed, 21 Mar 2018 02:13:40 +0000 (02:13 +0000)] 
rust: Refactor protover tests with new methods; note altered behaviours.

Previously, the rust implementation of protover considered an empty string to be
a valid ProtoEntry, while the C version did not (it must have a "=" character).
Other differences include that unknown protocols must now be parsed as
`protover::UnknownProtocol`s, and hence their entries as
`protover::UnvalidatedProtoEntry`s, whereas before (nearly) all protoentries
could be parsed regardless of how erroneous they might be considered by the C
version.

My apologies for this somewhat messy and difficult to read commit, if any part
is frustrating to the reviewer, please feel free to ask me to split this into
smaller changes (possibly hard to do, since so much changed), or ask me to
comment on a specific line/change and clarify how/when the behaviours differ.

The tests here should more closely match the behaviours exhibited by the C
implementation, but I do not yet personally guarantee they match precisely.

 * REFACTOR unittests in protover::protover.
 * ADD new integration tests for previously untested behaviour.
 * FIXES part of #24031: https://bugs.torproject.org/24031.

7 years agorust: Refactor protover::is_supported_here().
Isis Lovecruft [Wed, 21 Mar 2018 02:09:04 +0000 (02:09 +0000)] 
rust: Refactor protover::is_supported_here().

This changes `protover::is_supported_here()` to be aware of new datatypes
(e.g. don't call `.0` on things which are no longer tuple structs) and also
changes the method signature to take borrows, making it faster, threadable, and
easier to read (i.e. the caller can know from reading the function signature
that the function won't mutate values passed into it).

 * CHANGE the `protover::is_supported_here()` function to take borrows.
 * REFACTOR the `protover::is_supported_here()` function to be aware of new
   datatypes.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Add new ProtoverVote type and refactor functions to methods.
Isis Lovecruft [Wed, 21 Mar 2018 01:52:41 +0000 (01:52 +0000)] 
rust: Add new ProtoverVote type and refactor functions to methods.

This adds a new type for votes upon `protover::ProtoEntry`s (technically, on
`protover::UnvalidatedProtoEntry`s, because the C code does not validate based
upon currently known protocols when voting, in order to maintain
future-compatibility), and converts several functions which would have operated
on this datatype into methods for ease-of-use and readability.

This also fixes a behavioural differentce to the C version of
protover_compute_vote().  The C version of protover_compute_vote() calls
expand_protocol_list() which checks if there would be too many subprotocols *or*
expanded individual version numbers, i.e. more than MAX_PROTOCOLS_TO_EXPAND, and
does this *per vote* (but only in compute_vote(), everywhere else in the C seems
to only care about the number of subprotocols, not the number of individual
versions).  We need to match its behaviour in Rust and ensure we're not allowing
more than it would to get the votes to match.

 * ADD new `protover::ProtoverVote` datatype.
 * REMOVE the `protover::compute_vote()` function and refactor it into an
   equivalent-in-behaviour albeit more memory-efficient voting algorithm based
   on the new underlying `protover::protoset::ProtoSet` datatype, as
   `ProtoverVote::compute()`.
 * REMOVE the `protover::write_vote_to_string()` function, since this
   functionality is now generated by the impl_to_string_for_proto_entry!() macro
   for both `ProtoEntry` and `UnvalidatedProtoEntry` (the latter of which is the
   correct type to return from a voting protocol instance, since the entity
   voting may not know of all protocols being voted upon or known about by other
   voting parties).
 * FIXES part of #24031: https://bugs.torproject.org/24031

rust: Fix a difference in compute_vote() behaviour to C version.

7 years agorust: Add macro for `impl ToString for {Unvalidated}ProtoEntry`.
Isis Lovecruft [Wed, 21 Mar 2018 01:44:59 +0000 (01:44 +0000)] 
rust: Add macro for `impl ToString for {Unvalidated}ProtoEntry`.

This implements conversions from either a ProtoEntry or an UnvalidatedProtoEntry
into a String, for use in replacing such functions as
`protover::write_vote_to_string()`.

 * ADD macro for implementing ToString trait for ProtoEntry and
   UnvalidatedProtoEntry.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Add new protover::UnvalidatedProtoEntry type.
Isis Lovecruft [Wed, 21 Mar 2018 01:29:36 +0000 (01:29 +0000)] 
rust: Add new protover::UnvalidatedProtoEntry type.

This adds a new protover::UnvalidatedProtoEntry type, which is the
UnknownProtocol variant of a ProtoEntry, and refactors several functions which
should operate on this type into methods.

This also fixes what was previously another difference to the C implementation:
if you asked the C version of protovet_compute_vote() to compute a single vote
containing "Fribble=", it would return NULL.  However, the Rust version would
return "Fribble=" since it didn't check if the versions were empty before
constructing the string of differences.  ("Fribble=" is technically a valid
protover string.)  This is now fixed, and the Rust version in that case will,
analogous to (although safer than) C returning a NULL, return None.

 * REMOVE internal `contains_only_supported_protocols()` function.
 * REMOVE `all_supported()` function and refactor it into
   `UnvalidatedProtoEntry::all_supported()`.
 * REMOVE `parse_protocols_from_string_with_no_validation()` and
   refactor it into the more rusty implementation of
   `impl FromStr for UnvalidatedProtoEntry`.
 * REMOVE `protover_string_supports_protocol()` and refactor it into
   `UnvalidatedProtoEntry::supports_protocol()`.
 * REMOVE `protover_string_supports_protocol_or_later()` and refactor
   it into `UnvalidatedProtoEntry::supports_protocol_or_later()`.
 * FIXES part of #24031: https://bugs.torproject.org/24031

rust: Fix another C/Rust different in compute_vote().

This fixes the unittest from the prior commit by checking if the versions are
empty before adding a protocol to a vote.

7 years agorust: Add new protover::ProtoEntry type which uses new datatypes.
Isis Lovecruft [Wed, 21 Mar 2018 01:18:02 +0000 (01:18 +0000)] 
rust: Add new protover::ProtoEntry type which uses new datatypes.

This replaces the `protover::SupportedProtocols` (why would you have a type just
for things which are supported?) with a new, more generic type,
`protover::ProtoEntry`, which utilises the new, more memory-efficient datatype
in protover::protoset.

 * REMOVE `get_supported_protocols()` and `SupportedProtocols::tor_supported()`
   (since they were never used separately) and collapse their functionality into
   a single `ProtoEntry::supported()` method.
 * REMOVE `SupportedProtocols::from_proto_entries()` and reimplement its
   functionality as the more rusty `impl FromStr for ProtoEntry`.
 * REMOVE `get_proto_and_vers()` function and refactor it into the more rusty
   `impl FromStr for ProtoEntry`.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Add new protover::UnknownProtocol type.
Isis Lovecruft [Wed, 21 Mar 2018 01:07:18 +0000 (01:07 +0000)] 
rust: Add new protover::UnknownProtocol type.

 * ADD new type, protover::UnknownProtocol, so that we have greater type safety
   and our protover functionality which works with unsanitised protocol names is
   more clearly demarcated.
 * REFACTOR protover::Proto, renaming it protover::Protocol to mirror the new
   protover::UnknownProtocol type name.
 * ADD a utility conversion of `impl From<Protocol> for UnknownProtocol` so that
   we can easily with known protocols and unknown protocols simultaneously
   (e.g. doing comparisons, checking their version numbers), while not allowing
   UnknownProtocols to be accidentally used in functions which should only take
   Protocols.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Implement more memory-efficient protover datatype.
Isis Lovecruft [Wed, 21 Mar 2018 00:43:55 +0000 (00:43 +0000)] 
rust: Implement more memory-efficient protover datatype.

 * ADD new protover::protoset module.
 * ADD new protover::protoset::ProtoSet class for holding protover versions.
 * REMOVE protover::Versions type implementation and its method
   `from_version_string()`, and instead implement this behaviour in a more
   rust-like manner as `impl FromStr for ProtoSet`.
 * MOVE the `find_range()` utility function from protover::protover to
   protover::protoset since it's only used internally in the
   implementation of ProtoSet.
 * REMOVE the `contract_protocol_list()` function from protover::protover and
   instead refactor it (reusing nearly the entire thing, with minor superficial,
   i.e. non-behavioural, changes) into a more rusty
   `impl ToString for ProtoSet`.
 * REMOVE the `expand_version_range()` function from protover::protover and
   instead refactor it into a more rusty implementation of
   `impl Into<Vec<Version>> for ProtoSet` using the new error types in
   protover::errors.
 * FIXES part of #24031: https://bugs.torproject.org/24031.

7 years agorust: Implement error types for Rust protover implementation.
Isis Lovecruft [Wed, 21 Mar 2018 00:24:46 +0000 (00:24 +0000)] 
rust: Implement error types for Rust protover implementation.

This will allow us to do actual error handling intra-crate in a more
rusty manner, e.g. propogating errors in match statements, conversion
between error types, logging messages, etc.

 * FIXES part of #24031: https://bugs.torproject.org/24031.

7 years agorust: Fix ProtoSet and ProtoEntry to use the same DoS limits as C.
Isis Lovecruft [Tue, 27 Mar 2018 22:46:14 +0000 (22:46 +0000)] 
rust: Fix ProtoSet and ProtoEntry to use the same DoS limits as C.

Previously, the limit for MAX_PROTOCOLS_TO_EXPAND was actually being applied
in Rust to the maximum number of version (total, for all subprotocols).
Whereas in C, it was being applied to the number of subprotocols that were
allowed.  This changes the Rust to match C's behaviour.

7 years agorust: Port all C protover_all_supported tests to Rust.
Isis Lovecruft [Tue, 27 Mar 2018 21:38:29 +0000 (21:38 +0000)] 
rust: Port all C protover_all_supported tests to Rust.

The behaviours still do not match, unsurprisingly, but now we know where a
primary difference is: the Rust is validating version ranges more than the C,
so in the C it's possible to call protover_all_supported on a ridiculous
version range like "Sleen=0-4294967294" because the C uses
MAX_PROTOCOLS_TO_EXPAND to count the number of *subprotocols* whereas the Rust
uses it to count the total number of *versions* of all subprotocols.

7 years agotests: Run all existing protover tests in both languages.
Isis Lovecruft [Tue, 27 Mar 2018 21:36:10 +0000 (21:36 +0000)] 
tests: Run all existing protover tests in both languages.

There's now no difference in these tests w.r.t. the C or Rust: both
fail miserably (well, Rust fails with nice descriptive errors, and C
gives you a traceback, because, well, C).

7 years agotests: Make inline comments in test_protover.c more accurate.
Isis Lovecruft [Tue, 27 Mar 2018 21:34:00 +0000 (21:34 +0000)] 
tests: Make inline comments in test_protover.c more accurate.

The DoS potential is slightly higher in C now due to some differences to the
Rust code, see the C_RUST_DIFFERS tags in src/rust/protover/tests/protover.rs.

Also, the comment about "failing at the splitting stage" in Rust wasn't true,
since when we split, we ignore empty chunks (e.g. "1--1" parses into
"(1,None),(None,1)" and "None" can't be parsed into an integer).

Finally, the comment about "Rust seems to experience an internal error" is only
true in debug mode, where u32s are bounds-checked at runtime.  In release mode,
code expressing the equivalent of this test will error with
`Err(ProtoverError::Unparseable)` because 4294967295 is too large.

7 years agoprotover: Change protover_all_supported() to return only unsupported.
Isis Lovecruft [Tue, 27 Mar 2018 16:59:49 +0000 (16:59 +0000)] 
protover: Change protover_all_supported() to return only unsupported.

Previously, if "Link=1-5" was supported, and you asked protover_all_supported()
(or protover::all_supported() in Rust) if it supported "Link=3-999", the C
version would return "Link=3-999" and the Rust would return "Link=6-999".  These
both behave the same now, i.e. both return "Link=6-999".

7 years agorust: Refactor protover::compute_for_old_tor().
Isis Lovecruft [Tue, 27 Mar 2018 02:41:25 +0000 (02:41 +0000)] 
rust: Refactor protover::compute_for_old_tor().

During code review and discussion with Chelsea Komlo, she pointed out
that protover::compute_for_old_tor() was a public function whose
return type was `&'static CStr`.  We both agree that C-like parts of
APIs should:

1. not be exposed publicly (to other Rust crates),
2. only be called in the appropriate FFI code,
3. not expose types which are meant for FFI code (e.g. `*mut char`,
   `CString`, `*const c_int`, etc.) to the pure-Rust code of other
   crates.
4. FFI code (e.g. things in `ffi.rs` modules) should _never_ be called
   from pure-Rust, not even from other modules in its own crate
   (i.e. do not call `protover::ffi::*` from anywhere in
   `protover::protoset::*`, etc).

With that in mind, this commit makes the following changes:

 * CHANGE `protover::compute_for_old_tor()` to be
   visible only at the `pub(crate)` level.
 * RENAME `protover::compute_for_old_tor()` to
   `protover::compute_for_old_tor_cstr()` to reflect the last change.
 * ADD a new `protover::compute_for_old_tor()` function wrapper which
   is public and intended for other Rust code to use, which returns a
   `&str`.

7 years agorust: Refactor Rust implementation of protover_is_supported_here().
Isis Lovecruft [Wed, 21 Mar 2018 03:08:35 +0000 (03:08 +0000)] 
rust: Refactor Rust implementation of protover_is_supported_here().

It was changed to take borrows instead of taking ownership.

 * REFACTOR `protover::ffi::protover_is_supported_here()` to use changed method
   signature on `protover::is_supported_here()`.

7 years agorust: Refactor Rust impl of protover_compute_vote().
Isis Lovecruft [Wed, 21 Mar 2018 03:05:56 +0000 (03:05 +0000)] 
rust: Refactor Rust impl of protover_compute_vote().

This includes a subtle difference in behaviour to the previous Rust
implementation, where, for each vote that we're computing over, if a single one
fails to parse, we skip it.  This now matches the current behaviour in the C
implementation.

 * REFACTOR `protover::ffi::protover_compute_vote()` to use
   new types and methods.

7 years agorust: Refactor Rust impl of protover_list_supports_protocol_or_later().
Isis Lovecruft [Wed, 21 Mar 2018 02:59:25 +0000 (02:59 +0000)] 
rust: Refactor Rust impl of protover_list_supports_protocol_or_later().

This includes a subtle difference in behaviour, as in 4258f1e18, where we return
(matching the C impl's return behaviour) earlier than before if parsing failed,
saving us computation in parsing the versions into a
protover::protoset::ProtoSet.

 * REFACTOR `protover::ffi::protover_list_supports_protocol_or_later()` to use
   new types and methods.

7 years agorust: Refactor Rust impl of protover_list_supports_protocol().
Isis Lovecruft [Wed, 21 Mar 2018 02:52:04 +0000 (02:52 +0000)] 
rust: Refactor Rust impl of protover_list_supports_protocol().

This includes a subtle difference in behaviour, as in 4258f1e18, where we return
(matching the C impl's return behaviour) earlier than before if parsing failed,
saving us computation in parsing the versions into a
protover::protoset::ProtoSet.

 * REFACTOR `protover::ffi::protover_list_supports_protocol()` to use new types
   and methods.

7 years agorust: Refactor Rust impl of protover_all_supported().
Isis Lovecruft [Wed, 21 Mar 2018 02:45:41 +0000 (02:45 +0000)] 
rust: Refactor Rust impl of protover_all_supported().

This includes differences in behaviour to before, which should now more closely
match the C version:

 - If parsing a protover `char*` from C, and the string is not parseable, this
   function will return 1 early, which matches the C behaviour when protocols
   are unparseable.  Previously, we would parse it and its version numbers
   simultaneously, i.e. there was no fail early option, causing us to spend more
   time unnecessarily parsing versions.

 * REFACTOR `protover::ffi::protover_all_supported()` to use new types and
   methods.

7 years agorust: Refactor protover tests with new methods; note altered behaviours.
Isis Lovecruft [Wed, 21 Mar 2018 02:13:40 +0000 (02:13 +0000)] 
rust: Refactor protover tests with new methods; note altered behaviours.

Previously, the rust implementation of protover considered an empty string to be
a valid ProtoEntry, while the C version did not (it must have a "=" character).
Other differences include that unknown protocols must now be parsed as
`protover::UnknownProtocol`s, and hence their entries as
`protover::UnvalidatedProtoEntry`s, whereas before (nearly) all protoentries
could be parsed regardless of how erroneous they might be considered by the C
version.

My apologies for this somewhat messy and difficult to read commit, if any part
is frustrating to the reviewer, please feel free to ask me to split this into
smaller changes (possibly hard to do, since so much changed), or ask me to
comment on a specific line/change and clarify how/when the behaviours differ.

The tests here should more closely match the behaviours exhibited by the C
implementation, but I do not yet personally guarantee they match precisely.

 * REFACTOR unittests in protover::protover.
 * ADD new integration tests for previously untested behaviour.
 * FIXES part of #24031: https://bugs.torproject.org/24031.

7 years agorust: Refactor protover::is_supported_here().
Isis Lovecruft [Wed, 21 Mar 2018 02:09:04 +0000 (02:09 +0000)] 
rust: Refactor protover::is_supported_here().

This changes `protover::is_supported_here()` to be aware of new datatypes
(e.g. don't call `.0` on things which are no longer tuple structs) and also
changes the method signature to take borrows, making it faster, threadable, and
easier to read (i.e. the caller can know from reading the function signature
that the function won't mutate values passed into it).

 * CHANGE the `protover::is_supported_here()` function to take borrows.
 * REFACTOR the `protover::is_supported_here()` function to be aware of new
   datatypes.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Add new ProtoverVote type and refactor functions to methods.
Isis Lovecruft [Wed, 21 Mar 2018 01:52:41 +0000 (01:52 +0000)] 
rust: Add new ProtoverVote type and refactor functions to methods.

This adds a new type for votes upon `protover::ProtoEntry`s (technically, on
`protover::UnvalidatedProtoEntry`s, because the C code does not validate based
upon currently known protocols when voting, in order to maintain
future-compatibility), and converts several functions which would have operated
on this datatype into methods for ease-of-use and readability.

This also fixes a behavioural differentce to the C version of
protover_compute_vote().  The C version of protover_compute_vote() calls
expand_protocol_list() which checks if there would be too many subprotocols *or*
expanded individual version numbers, i.e. more than MAX_PROTOCOLS_TO_EXPAND, and
does this *per vote* (but only in compute_vote(), everywhere else in the C seems
to only care about the number of subprotocols, not the number of individual
versions).  We need to match its behaviour in Rust and ensure we're not allowing
more than it would to get the votes to match.

 * ADD new `protover::ProtoverVote` datatype.
 * REMOVE the `protover::compute_vote()` function and refactor it into an
   equivalent-in-behaviour albeit more memory-efficient voting algorithm based
   on the new underlying `protover::protoset::ProtoSet` datatype, as
   `ProtoverVote::compute()`.
 * REMOVE the `protover::write_vote_to_string()` function, since this
   functionality is now generated by the impl_to_string_for_proto_entry!() macro
   for both `ProtoEntry` and `UnvalidatedProtoEntry` (the latter of which is the
   correct type to return from a voting protocol instance, since the entity
   voting may not know of all protocols being voted upon or known about by other
   voting parties).
 * FIXES part of #24031: https://bugs.torproject.org/24031

rust: Fix a difference in compute_vote() behaviour to C version.

7 years agorust: Add macro for `impl ToString for {Unvalidated}ProtoEntry`.
Isis Lovecruft [Wed, 21 Mar 2018 01:44:59 +0000 (01:44 +0000)] 
rust: Add macro for `impl ToString for {Unvalidated}ProtoEntry`.

This implements conversions from either a ProtoEntry or an UnvalidatedProtoEntry
into a String, for use in replacing such functions as
`protover::write_vote_to_string()`.

 * ADD macro for implementing ToString trait for ProtoEntry and
   UnvalidatedProtoEntry.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Add new protover::UnvalidatedProtoEntry type.
Isis Lovecruft [Wed, 21 Mar 2018 01:29:36 +0000 (01:29 +0000)] 
rust: Add new protover::UnvalidatedProtoEntry type.

This adds a new protover::UnvalidatedProtoEntry type, which is the
UnknownProtocol variant of a ProtoEntry, and refactors several functions which
should operate on this type into methods.

This also fixes what was previously another difference to the C implementation:
if you asked the C version of protovet_compute_vote() to compute a single vote
containing "Fribble=", it would return NULL.  However, the Rust version would
return "Fribble=" since it didn't check if the versions were empty before
constructing the string of differences.  ("Fribble=" is technically a valid
protover string.)  This is now fixed, and the Rust version in that case will,
analogous to (although safer than) C returning a NULL, return None.

 * REMOVE internal `contains_only_supported_protocols()` function.
 * REMOVE `all_supported()` function and refactor it into
   `UnvalidatedProtoEntry::all_supported()`.
 * REMOVE `parse_protocols_from_string_with_no_validation()` and
   refactor it into the more rusty implementation of
   `impl FromStr for UnvalidatedProtoEntry`.
 * REMOVE `protover_string_supports_protocol()` and refactor it into
   `UnvalidatedProtoEntry::supports_protocol()`.
 * REMOVE `protover_string_supports_protocol_or_later()` and refactor
   it into `UnvalidatedProtoEntry::supports_protocol_or_later()`.
 * FIXES part of #24031: https://bugs.torproject.org/24031

rust: Fix another C/Rust different in compute_vote().

This fixes the unittest from the prior commit by checking if the versions are
empty before adding a protocol to a vote.

7 years agorust: Add new protover::ProtoEntry type which uses new datatypes.
Isis Lovecruft [Wed, 21 Mar 2018 01:18:02 +0000 (01:18 +0000)] 
rust: Add new protover::ProtoEntry type which uses new datatypes.

This replaces the `protover::SupportedProtocols` (why would you have a type just
for things which are supported?) with a new, more generic type,
`protover::ProtoEntry`, which utilises the new, more memory-efficient datatype
in protover::protoset.

 * REMOVE `get_supported_protocols()` and `SupportedProtocols::tor_supported()`
   (since they were never used separately) and collapse their functionality into
   a single `ProtoEntry::supported()` method.
 * REMOVE `SupportedProtocols::from_proto_entries()` and reimplement its
   functionality as the more rusty `impl FromStr for ProtoEntry`.
 * REMOVE `get_proto_and_vers()` function and refactor it into the more rusty
   `impl FromStr for ProtoEntry`.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Add new protover::UnknownProtocol type.
Isis Lovecruft [Wed, 21 Mar 2018 01:07:18 +0000 (01:07 +0000)] 
rust: Add new protover::UnknownProtocol type.

 * ADD new type, protover::UnknownProtocol, so that we have greater type safety
   and our protover functionality which works with unsanitised protocol names is
   more clearly demarcated.
 * REFACTOR protover::Proto, renaming it protover::Protocol to mirror the new
   protover::UnknownProtocol type name.
 * ADD a utility conversion of `impl From<Protocol> for UnknownProtocol` so that
   we can easily with known protocols and unknown protocols simultaneously
   (e.g. doing comparisons, checking their version numbers), while not allowing
   UnknownProtocols to be accidentally used in functions which should only take
   Protocols.
 * FIXES part of #24031: https://bugs.torproject.org/24031

7 years agorust: Implement more memory-efficient protover datatype.
Isis Lovecruft [Wed, 21 Mar 2018 00:43:55 +0000 (00:43 +0000)] 
rust: Implement more memory-efficient protover datatype.

 * ADD new protover::protoset module.
 * ADD new protover::protoset::ProtoSet class for holding protover versions.
 * REMOVE protover::Versions type implementation and its method
   `from_version_string()`, and instead implement this behaviour in a more
   rust-like manner as `impl FromStr for ProtoSet`.
 * MOVE the `find_range()` utility function from protover::protover to
   protover::protoset since it's only used internally in the
   implementation of ProtoSet.
 * REMOVE the `contract_protocol_list()` function from protover::protover and
   instead refactor it (reusing nearly the entire thing, with minor superficial,
   i.e. non-behavioural, changes) into a more rusty
   `impl ToString for ProtoSet`.
 * REMOVE the `expand_version_range()` function from protover::protover and
   instead refactor it into a more rusty implementation of
   `impl Into<Vec<Version>> for ProtoSet` using the new error types in
   protover::errors.
 * FIXES part of #24031: https://bugs.torproject.org/24031.

7 years agorust: Implement error types for Rust protover implementation.
Isis Lovecruft [Wed, 21 Mar 2018 00:24:46 +0000 (00:24 +0000)] 
rust: Implement error types for Rust protover implementation.

This will allow us to do actual error handling intra-crate in a more
rusty manner, e.g. propogating errors in match statements, conversion
between error types, logging messages, etc.

 * FIXES part of #24031: https://bugs.torproject.org/24031.

7 years agoRemove an unnecessary event2 include.
Nick Mathewson [Tue, 3 Oct 2017 13:59:37 +0000 (09:59 -0400)] 
Remove an unnecessary event2 include.

The rest, are, unfortunately, necessary for now.

7 years agoRemove event2/event.h include from compat_libevent.h
Nick Mathewson [Tue, 3 Oct 2017 13:51:38 +0000 (09:51 -0400)] 
Remove event2/event.h include from compat_libevent.h

Only one module was depending on this include (test_helpers.c), and
it was doing so incorrectly.

7 years agoMerge branch 'maint-0.3.3'
Nick Mathewson [Mon, 2 Apr 2018 12:51:47 +0000 (08:51 -0400)] 
Merge branch 'maint-0.3.3'

7 years agouse channel_is_client for create cell counts
Roger Dingledine [Mon, 2 Apr 2018 05:00:31 +0000 (01:00 -0400)] 
use channel_is_client for create cell counts

When a relay is collecting internal statistics about how many
create cell requests it has seen of each type, accurately count the
requests from relays that temporarily fall out of the consensus.

(To be extra conservative, we were already ignoring requests from clients
in our counts, and we continue ignoring them here.)

Fixes bug 24910; bugfix on 0.2.4.17-rc.