[tor-bugs] #22840 [Core Tor/Tor]: Implement protover in Rust

Tor Bug Tracker & Wiki blackhole at torproject.org
Thu Sep 28 00:24:19 UTC 2017

#22840: Implement protover in Rust
 Reporter:  chelseakomlo              |          Owner:  chelseakomlo
     Type:  enhancement               |         Status:  assigned
 Priority:  Medium                    |      Milestone:  Tor: unspecified
Component:  Core Tor/Tor              |        Version:
 Severity:  Normal                    |     Resolution:
 Keywords:  rust protover rust-pilot  |  Actual Points:
Parent ID:                            |         Points:  3
 Reviewer:                            |        Sponsor:  SponsorZ

Comment (by chelseakomlo):

 See `git at github.com:chelseakomlo/tor_patches.git`, branch `protover-rust-

 Some considerations:

 1. Changes to protover.c

 src/or/protover.c was rearranged in order to have functionality defined
 based on conditional definitions. These fall into two categories: 1)
 functions that should only be defined when Rust is not enabled are guarded
 by HAVE_RUST, and 2) functions that are used in src/test/test_protover.c
 are guarded by HAVE_RUST or TOR_UNIT_TESTS (so they are defined only for
 testing or when Rust is not enabled)

 Other than rearranging for ifdef guards, logic in protover.c was not

 2. Why src/or/protover_rust.c is needed

 Currently, it is important to keep the C code stable as we test
 feasibility of introducing Rust. In the future, we can change C code to
 better enable adding Rust functionality, but in the short term, changing C
 as little as possible will both allow us to merge Rust code, and worry
 less about introducing bugs in the meantime. Adding wrappers for
 translation in src/or/protover_rust.c is a temporary measure and is not
 meant as a long-term solution.

 3. Naming/similar functionality between src/common/compat_rust and

 As we are currently experimenting with Rust, I introduced another method
 of handling strings between the Rust/C ABI, which made implementing
 protover in Rust simpler. I propose that we discuss in another ticket how
 to move forward with only one method, and merge this patch with both

 This patch introduces a less heavyweight manner to handle strings passed
 from Rust to C, to better allow Rust to assign string values to pointers
 passed as function arguments.

 4. String handling/copying

 In this patch, strings are passed to C and then immediately copied. The
 string allocated in Rust is immediately freed. In the future, we can
 discuss implementations that avoid this extra copy, but I propose merging
 this patch without that enhancement.

 5. Extending src/rust/smartlist

 In the future, we should talk about how to better handle smartlists that
 are passed between C and Rust, as currently only smartlists of strings is

 6. Documentation and tests in src/rust

 Please let me know if more/less documentation would be helpful, or if
 certain things can be better documented and/or tested.

 7. Logging

 This patch does not implement logging to tor's logger from Rust. Maybe
 this functionality can be added separately, and then logging can be added
 here afterward?

Ticket URL: <https://trac.torproject.org/projects/tor/ticket/22840#comment:4>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online

More information about the tor-bugs mailing list