Massively refactor the structure of `onionmasq-mobile`
- This changes the structure of the
onionmasq-mobile
crate quite significantly by introducing anOnionmasqMobile
singletonstruct
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.
- This avoids the need to have multiple hacky
- 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.)
- Most Rust->Java JNI calls now use
- The C native functions exposed for Java to call are now in
ffi.rs
, and call methods on theOnionmasqMobile
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.)
- We now log the panic inside the panic hook, instead of waiting for
it to propagate out to
- The
AndroidScaffolding
used byonion-tunnel
was moved out to a newscaffolding
module, and changed to use the singleton. - We also get rid of the
interface_name
parameter torunProxy
, 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