[mio] fmt
This commit is contained in:
+15
-14
@@ -2,8 +2,8 @@ use std::net::ToSocketAddrs;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use jni::errors::Error;
|
use jni::errors::Error;
|
||||||
use jni::JNIEnv;
|
|
||||||
use jni::objects::JObject;
|
use jni::objects::JObject;
|
||||||
|
use jni::JNIEnv;
|
||||||
|
|
||||||
use vnt::channel::punch::PunchModel;
|
use vnt::channel::punch::PunchModel;
|
||||||
use vnt::cipher::CipherModel;
|
use vnt::cipher::CipherModel;
|
||||||
@@ -22,7 +22,7 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result<Config, Error> {
|
|||||||
let stun_server = to_string_array_not_null(env, &config, "stunServer")?;
|
let stun_server = to_string_array_not_null(env, &config, "stunServer")?;
|
||||||
let cipher_model = to_string_not_null(env, &config, "cipherModel")?;
|
let cipher_model = to_string_not_null(env, &config, "cipherModel")?;
|
||||||
let punch_model = to_string(env, &config, "punchModel")?;
|
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 tcp = env.get_field(&config, "tcp", "Z")?.z()?;
|
||||||
let server_encrypt = env.get_field(&config, "serverEncrypt", "Z")?.z()?;
|
let server_encrypt = env.get_field(&config, "serverEncrypt", "Z")?.z()?;
|
||||||
let relay = env.get_field(&config, "relay", "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<Config, Error> {
|
|||||||
to_i32_array(env, &config, "ports")?.map(|v| v.into_iter().map(|v| v as u16).collect());
|
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")? {
|
let ip = if let Some(ip) = to_string(env, &config, "ip")? {
|
||||||
match ip.parse() {
|
match ip.parse() {
|
||||||
Ok(ip) => {
|
Ok(ip) => Some(ip),
|
||||||
Some(ip)
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
env.throw_new("java/lang/RuntimeException", format!("ip {} err: {}", ip, e))
|
env.throw_new(
|
||||||
.expect("throw");
|
"java/lang/RuntimeException",
|
||||||
|
format!("ip {} err: {}", ip, e),
|
||||||
|
)
|
||||||
|
.expect("throw");
|
||||||
return Err(Error::JavaException);
|
return Err(Error::JavaException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +87,7 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result<Config, Error> {
|
|||||||
"java/lang/RuntimeException",
|
"java/lang/RuntimeException",
|
||||||
format!("server address {}", e),
|
format!("server address {}", e),
|
||||||
)
|
)
|
||||||
.expect("throw");
|
.expect("throw");
|
||||||
return Err(Error::JavaException);
|
return Err(Error::JavaException);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -99,12 +100,12 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result<Config, Error> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
#[cfg(not(target_os = "android"))]
|
#[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")]
|
#[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(
|
let config = match Config::new(
|
||||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||||
tap,
|
tap,
|
||||||
token,
|
token,
|
||||||
device_id,
|
device_id,
|
||||||
name,
|
name,
|
||||||
@@ -127,9 +128,9 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result<Config, Error> {
|
|||||||
ports,
|
ports,
|
||||||
first_latency,
|
first_latency,
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
device_name,
|
device_name,
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
device_fd,
|
device_fd,
|
||||||
) {
|
) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -137,7 +138,7 @@ pub fn new_config(env: &mut JNIEnv, config: JObject) -> Result<Config, Error> {
|
|||||||
"java/lang/RuntimeException",
|
"java/lang/RuntimeException",
|
||||||
format!("vnt start error {}", e),
|
format!("vnt start error {}", e),
|
||||||
)
|
)
|
||||||
.expect("throw");
|
.expect("throw");
|
||||||
return Err(Error::JavaException);
|
return Err(Error::JavaException);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
pub mod callback;
|
pub mod callback;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod utils;
|
||||||
pub mod vnt;
|
pub mod vnt;
|
||||||
pub mod utils;
|
|
||||||
+10
-4
@@ -1,6 +1,6 @@
|
|||||||
use jni::errors::Error;
|
use jni::errors::Error;
|
||||||
use jni::JNIEnv;
|
|
||||||
use jni::objects::{JIntArray, JObject, JObjectArray, JString};
|
use jni::objects::{JIntArray, JObject, JObjectArray, JString};
|
||||||
|
use jni::JNIEnv;
|
||||||
|
|
||||||
pub fn to_string_not_null(
|
pub fn to_string_not_null(
|
||||||
env: &mut JNIEnv,
|
env: &mut JNIEnv,
|
||||||
@@ -76,7 +76,7 @@ pub fn to_string_array(
|
|||||||
"java/lang/NullPointerException",
|
"java/lang/NullPointerException",
|
||||||
format!("{},index={}", name, index),
|
format!("{},index={}", name, index),
|
||||||
)
|
)
|
||||||
.expect("throw");
|
.expect("throw");
|
||||||
return Err(Error::JavaException);
|
return Err(Error::JavaException);
|
||||||
}
|
}
|
||||||
match env.get_string(JString::from(object).as_ref())?.to_str() {
|
match env.get_string(JString::from(object).as_ref())?.to_str() {
|
||||||
@@ -93,7 +93,11 @@ pub fn to_string_array(
|
|||||||
Ok(Some(rs))
|
Ok(Some(rs))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_i32_array(env: &mut JNIEnv, config: &JObject, name: &str) -> Result<Option<Vec<i32>>, Error> {
|
pub fn to_i32_array(
|
||||||
|
env: &mut JNIEnv,
|
||||||
|
config: &JObject,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<Option<Vec<i32>>, Error> {
|
||||||
let obj = env.get_field(&config, name, "[I")?.l()?;
|
let obj = env.get_field(&config, name, "[I")?.l()?;
|
||||||
if obj.is_null() {
|
if obj.is_null() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -111,5 +115,7 @@ pub fn to_integer(env: &mut JNIEnv, config: &JObject, name: &str) -> Result<Opti
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
// 调用 intValue
|
// 调用 intValue
|
||||||
return Ok(Some(env.call_method(value,"intValue","()I",&[])?.i()? as _))
|
return Ok(Some(
|
||||||
|
env.call_method(value, "intValue", "()I", &[])?.i()? as _
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user