diff options
author | Isis Lovecruft <isis@torproject.org> | 2018-03-21 03:05:56 +0000 |
---|---|---|
committer | Isis Lovecruft <isis@torproject.org> | 2018-04-02 19:36:25 +0000 |
commit | 32638ed4a6c47a03b899cd09582888674ae3bf08 (patch) | |
tree | 7173a82330f5f9f2d5a6753222025823d7df6ec0 | |
parent | 269053a3801ebe925707db5a8e519836ad2242c9 (diff) | |
download | tor-32638ed4a6c47a03b899cd09582888674ae3bf08.tar.gz tor-32638ed4a6c47a03b899cd09582888674ae3bf08.zip |
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.
-rw-r--r-- | src/rust/protover/ffi.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/rust/protover/ffi.rs b/src/rust/protover/ffi.rs index e7c8211161..13d64821f4 100644 --- a/src/rust/protover/ffi.rs +++ b/src/rust/protover/ffi.rs @@ -175,6 +175,8 @@ pub extern "C" fn protover_get_supported_protocols() -> *const c_char { /// Provide an interface for C to translate arguments and return types for /// protover::compute_vote +// +// Why is the threshold a signed integer? —isis #[no_mangle] pub extern "C" fn protover_compute_vote( list: *const Stringlist, @@ -189,10 +191,19 @@ pub extern "C" fn protover_compute_vote( // Dereference of raw pointer requires an unsafe block. The pointer is // checked above to ensure it is not null. let data: Vec<String> = unsafe { (*list).get_list() }; + let hold: usize = threshold as usize; + let mut proto_entries: Vec<UnvalidatedProtoEntry> = Vec::new(); - let vote = compute_vote(data, threshold); + for datum in data { + let entry: UnvalidatedProtoEntry = match datum.parse() { + Ok(x) => x, + Err(_) => continue, + }; + proto_entries.push(entry); + } + let vote: UnvalidatedProtoEntry = ProtoverVote::compute(&proto_entries, &hold); - allocate_and_copy_string(&vote) + allocate_and_copy_string(&vote.to_string()) } /// Provide an interface for C to translate arguments and return types for |