aboutsummaryrefslogtreecommitdiff
path: root/src/rust/protover
AgeCommit message (Collapse)Author
2018-04-02rust: Add macro for `impl ToString for {Unvalidated}ProtoEntry`.Isis Lovecruft
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
2018-04-02rust: Add new protover::UnvalidatedProtoEntry type.Isis Lovecruft
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.
2018-04-02rust: Add new protover::ProtoEntry type which uses new datatypes.Isis Lovecruft
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
2018-04-02rust: Add new protover::UnknownProtocol type.Isis Lovecruft
* 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
2018-04-02rust: Implement more memory-efficient protover datatype.Isis Lovecruft
* 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.
2018-04-02rust: Implement error types for Rust protover implementation.Isis Lovecruft
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.
2018-03-21Merge branch 'maint-0.3.3'Nick Mathewson
2018-03-21maint: Update Rust libc dependency from 0.2.22 to 0.2.39.Isis Lovecruft
Requires the update/libc-0.2.39 branch from https://github.com/isislovecruft/tor-rust-dependencies to be merged first.
2018-03-19Merge remote-tracking branch 'isis/bug23881_r1'Nick Mathewson
2018-02-15Merge remote-tracking branch 'isis/bug25185'Nick Mathewson
2018-02-15rust protover: match the C implementation on empty-str casesNick Mathewson
Empty versions lists are permitted; empty keywords are not.
2018-02-15Forbid u32::MAX as a protover range element in rustNick Mathewson
Part of the 25249 fix to make rust match the C.
2018-02-15Rust protover compat: forbid more than MAX_VERSIONS_TO_EXPAND in a rangeNick Mathewson
Also correct MAX_VERSIONS_TO_EXPAND to match the C. NOTE that this patch leads to incorrect behavior: the C code allows huge ranges; it just doesn't allow votes on them (currently). For full compatibility, we'll need to make the rust code store ranges as ranges natively, possibly using something like the range_map crate. Still, this patch is smaller than a "proper" fix. Fixes TROVE-2018-003.
2018-02-10rust: Remove now unused byte_slice_is_c_like() utility.Isis Lovecruft
2018-02-10rust: Remove empty_static_cstr() in favour of new cstr!() macro.Isis Lovecruft
2018-02-10rust: Use tor_util::strings utils for protover_compute_for_old_tor.Isis Lovecruft
2018-02-10rust: Use tor_util::strings utils for protover_get_supported_protocols.Isis Lovecruft
2018-02-10rust: Replace two `unwrap()`s in FFI code with `unwrap_or()`s.Isis Lovecruft
2018-02-08Merge remote-tracking branch 'frewsxcv/frewsxcv-protover'Nick Mathewson
2018-02-08Stop claiming that compute_for_old_tor() returns pairsNick Mathewson
2018-02-08Remove new unsafe {} use.Nick Mathewson
Rationale: this helps for performance only, but we don't actually have any reason to think that the checks here are performance-critical. Let's not normalize the use of unsafe {}.
2018-02-07protover: Fix memleak in Rust impl of protover_compute_for_old_tor.Isis Lovecruft
* FIXES #25127: https://bugs.torproject.org/25127 * ADDS a new module to the Rust tor_util crate for small utilities for working with static strings between languages. * CHANGES the return type of protover_compute_for_old_tor to point to immutable data. * CHANGES the code from the previous commit to use the new static string utilities.
2018-02-06protover: Fix memleak in Rust implementation.Isis Lovecruft
* FIXES #25127: https://bugs.torproject.org/25127.
2018-01-30Add Link protocol version 5 to the supported protocols list in protover.rsteor
And fix the unsupported protover example so it uses a Link protover much higher than 5. Part of #25070, bugfix on 0.3.3.1-alpha, which introduced the protover crate.
2018-01-29Wrap types in protover.rs.Corey Farwell
https://trac.torproject.org/projects/tor/ticket/24030 Introduce new wrapper types: - `SupportedProtocols` - `Versions` Introduce a type alias: - `Version` (`u32`)
2018-01-22fixups from code reviewChelsea Holland Komlo
2017-12-28[fixup] this might be an improvement?Corey Farwell
2017-12-27Remove unneeded heap allocations in protover.rs.Corey Farwell
2017-12-21allow running protover test with a testing feature flagChelsea Holland Komlo
2017-12-21move macro body to inline rust functionChelsea Holland Komlo
2017-12-21cargo fmt fixesChelsea Holland Komlo
2017-12-21add minimal rust module for logging to tor's loggerChelsea Holland Komlo
Allows an optional no-op for testing purposes
2017-11-11annotate where C and Rust need to stay in syncChelsea Holland Komlo
2017-11-09slight improvement to rust idiomicityNick Mathewson
2017-11-09Rust implementation of protocol_list_supports_protocol_or_later()Nick Mathewson
2017-10-27[rust] Avoid a clone in contract_protocol_list()Nick Mathewson
2017-10-27Add missing copyright/license statements on all .rs filesNick Mathewson
(Yes, I have Chelsea's permission.)
2017-10-27cargo fmt; fix line length warningsChelsea Holland Komlo
2017-10-27remove experimental rust featuresChelsea Holland Komlo
allow unsafe on function that calls C
2017-10-27remove unused include.am for rust modulesChelsea Holland Komlo
2017-10-27add tor allocator for rustChelsea Holland Komlo
2017-10-27remove unneeded dependencies, remove types where unnecessaryChelsea Holland Komlo
2017-10-27use tor allocator for string allocation in rustChelsea Holland Komlo
2017-10-27rust implementation of protoverChelsea Holland Komlo