Skip to content

Massively refactor the structure of `onionmasq-mobile`

eta requested to merge eta/onionmasq-mobile-refactor into main
  • This changes the structure of the onionmasq-mobile crate quite significantly by introducing an OnionmasqMobile singleton struct that contains most of the business logic.
    • This avoids the need to have multiple hacky OnceCell global variables, for example; the stuff in those has been moved into the singleton.
  • We use this reorganisation to add a bunch of helper methods that clean up the code and provide opportunities for cleaner error handling.
    • Most Rust->Java JNI calls now use OnionmasqMobile::call_jni_class_method, a new function that has nice "automatic" return type casting with helpful error messages if things go wrong.
    • (This means you can treat its return value as a native Rust type, instead of having to do the result.i() thing.)
  • The C native functions exposed for Java to call are now in ffi.rs, and call methods on the OnionmasqMobile singleton.
    • This means the main Rust business logic can look more like idiomatic Rust, using Rust error handling conventions for example.
    • The FFI code can then wrap this in the necessary conversion functions to get it to work with Java.
  • Panic handling was moved out to a new panic_handling module, and slightly improved.
    • We now log the panic inside the panic hook, instead of waiting for it to propagate out to catch_unwind, meaning we don't miss panics that happen outside such a block.
    • (Also, failing to get a backtrace is now recoverable.)
  • The AndroidScaffolding used by onion-tunnel was moved out to a new scaffolding module, and changed to use the singleton.
  • We also get rid of the interface_name parameter to runProxy, since it wasn't being used any more.

I apologise for the large diff! Let me know if you have any questions, or need me to split this up into smaller patches for review.

Edited by eta

Merge request reports

Loading