diff --git a/vnt-jni/src/config.rs b/vnt-jni/src/config.rs index 1bb3a02..a0ce208 100644 --- a/vnt-jni/src/config.rs +++ b/vnt-jni/src/config.rs @@ -2,8 +2,8 @@ use std::net::ToSocketAddrs; use std::str::FromStr; use jni::errors::Error; -use jni::JNIEnv; use jni::objects::JObject; +use jni::JNIEnv; use vnt::channel::punch::PunchModel; use vnt::cipher::CipherModel; @@ -22,7 +22,7 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result { let stun_server = to_string_array_not_null(env, &config, "stunServer")?; let cipher_model = to_string_not_null(env, &config, "cipherModel")?; let punch_model = to_string(env, &config, "punchModel")?; - let mtu = to_integer(env, &config, "mtu")?.map(|v|v as u32); + let mtu = to_integer(env, &config, "mtu")?.map(|v| v as u32); let tcp = env.get_field(&config, "tcp", "Z")?.z()?; let server_encrypt = env.get_field(&config, "serverEncrypt", "Z")?.z()?; let relay = env.get_field(&config, "relay", "Z")?.z()?; @@ -34,12 +34,13 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result { to_i32_array(env, &config, "ports")?.map(|v| v.into_iter().map(|v| v as u16).collect()); let ip = if let Some(ip) = to_string(env, &config, "ip")? { match ip.parse() { - Ok(ip) => { - Some(ip) - } + Ok(ip) => Some(ip), Err(e) => { - env.throw_new("java/lang/RuntimeException", format!("ip {} err: {}", ip, e)) - .expect("throw"); + env.throw_new( + "java/lang/RuntimeException", + format!("ip {} err: {}", ip, e), + ) + .expect("throw"); return Err(Error::JavaException); } } @@ -86,7 +87,7 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result { "java/lang/RuntimeException", format!("server address {}", e), ) - .expect("throw"); + .expect("throw"); return Err(Error::JavaException); } }; @@ -99,12 +100,12 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result { } }; #[cfg(not(target_os = "android"))] - let device_name = to_string(env, &config, "deviceName")?; + let device_name = to_string(env, &config, "deviceName")?; #[cfg(target_os = "android")] - let device_fd = env.get_field(&config, "deviceFd", "I")?.i()? as i32; + let device_fd = env.get_field(&config, "deviceFd", "I")?.i()? as i32; let config = match Config::new( #[cfg(any(target_os = "windows", target_os = "linux"))] - tap, + tap, token, device_id, name, @@ -127,9 +128,9 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result { ports, first_latency, #[cfg(not(target_os = "android"))] - device_name, + device_name, #[cfg(target_os = "android")] - device_fd, + device_fd, ) { Ok(config) => config, Err(e) => { @@ -137,7 +138,7 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result { "java/lang/RuntimeException", format!("vnt start error {}", e), ) - .expect("throw"); + .expect("throw"); return Err(Error::JavaException); } }; diff --git a/vnt-jni/src/lib.rs b/vnt-jni/src/lib.rs index 4ac5839..898137c 100644 --- a/vnt-jni/src/lib.rs +++ b/vnt-jni/src/lib.rs @@ -1,4 +1,4 @@ pub mod callback; pub mod config; +pub mod utils; pub mod vnt; -pub mod utils; \ No newline at end of file diff --git a/vnt-jni/src/utils.rs b/vnt-jni/src/utils.rs index 291faf4..dd204f4 100644 --- a/vnt-jni/src/utils.rs +++ b/vnt-jni/src/utils.rs @@ -1,6 +1,6 @@ use jni::errors::Error; -use jni::JNIEnv; use jni::objects::{JIntArray, JObject, JObjectArray, JString}; +use jni::JNIEnv; pub fn to_string_not_null( env: &mut JNIEnv, @@ -76,7 +76,7 @@ pub fn to_string_array( "java/lang/NullPointerException", format!("{},index={}", name, index), ) - .expect("throw"); + .expect("throw"); return Err(Error::JavaException); } match env.get_string(JString::from(object).as_ref())?.to_str() { @@ -93,7 +93,11 @@ pub fn to_string_array( Ok(Some(rs)) } -pub fn to_i32_array(env: &mut JNIEnv, config: &JObject, name: &str) -> Result>, Error> { +pub fn to_i32_array( + env: &mut JNIEnv, + config: &JObject, + name: &str, +) -> Result>, Error> { let obj = env.get_field(&config, name, "[I")?.l()?; if obj.is_null() { Ok(None) @@ -111,5 +115,7 @@ pub fn to_integer(env: &mut JNIEnv, config: &JObject, name: &str) -> Result