Skip to content

Commit

Permalink
增加日志输出内容
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed May 10, 2024
1 parent 9df324f commit 0e42944
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 17 deletions.
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vnt-jni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ jni = { version = "0.21.1", default-features = false }
log = "0.4.20"
spki = { version = "0.7.2", features = ["fingerprint", "alloc","base64","pem"]}

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.13"

[lib]
crate-type = ["staticlib", "cdylib"]
48 changes: 35 additions & 13 deletions vnt-jni/java/top/wherewego/vnt/jni/Config.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package top.wherewego.vnt.jni;

import java.io.Serializable;
import java.util.Arrays;

/**
* 启动配置
*
* @author https://github.com/lbl8603/vnt
*/
public class Config {
public class Config implements Serializable {
/**
* 是否是tap模式,仅支持windows和linux
* 是否是tap模式,仅支持windows
*/
private boolean tap;
/**
Expand Down Expand Up @@ -38,10 +41,6 @@ public class Config {
* 是否开启服务端加密
*/
private boolean serverEncrypt;
/**
* 仅使用中继转发
*/
private boolean relay;
/**
* 设备id,请使用唯一值
*/
Expand Down Expand Up @@ -174,13 +173,6 @@ public void setServerEncrypt(boolean serverEncrypt) {
this.serverEncrypt = serverEncrypt;
}

public boolean isRelay() {
return relay;
}

public void setRelay(boolean relay) {
this.relay = relay;
}

public String getDeviceId() {
return deviceId;
Expand Down Expand Up @@ -308,4 +300,34 @@ public Integer getPacketDelay() {
public void setPacketDelay(Integer packetDelay) {
this.packetDelay = packetDelay;
}

@Override
public String toString() {
return "Config{" +
"tap=" + tap +
", token='" + token + '\'' +
", name='" + name + '\'' +
", password='" + password + '\'' +
", cipherModel='" + cipherModel + '\'' +
", punchModel='" + punchModel + '\'' +
", mtu=" + mtu +
", serverEncrypt=" + serverEncrypt +
", deviceId='" + deviceId + '\'' +
", server='" + server + '\'' +
", dns=" + Arrays.toString(dns) +
", portMapping=" + Arrays.toString(portMapping) +
", stunServer=" + Arrays.toString(stunServer) +
", tcp=" + tcp +
", ip='" + ip + '\'' +
", finger=" + finger +
", firstLatency=" + firstLatency +
", inIps=" + Arrays.toString(inIps) +
", outIps=" + Arrays.toString(outIps) +
", ports=" + Arrays.toString(ports) +
", deviceName='" + deviceName + '\'' +
", useChannel='" + useChannel + '\'' +
", packetLossRate=" + packetLossRate +
", packetDelay=" + packetDelay +
'}';
}
}
1 change: 1 addition & 0 deletions vnt-jni/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod callback;
pub mod config;
pub mod utils;
pub mod vnt;
pub(crate) mod vnt_logger;
2 changes: 1 addition & 1 deletion vnt-jni/src/vnt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use vnt::core::Vnt;
use vnt::handle::PeerDeviceInfo;

use crate::callback::CallBack;

#[no_mangle]
pub unsafe extern "C" fn Java_top_wherewego_vnt_jni_Vnt_new0(
mut env: JNIEnv<'static>,
_class: JClass,
config: JObject,
call_back: JObject<'static>,
) -> jlong {
crate::vnt_logger::init_log();
let jvm = if let Ok(jvm) = env.get_java_vm() {
jvm
} else {
Expand Down
12 changes: 12 additions & 0 deletions vnt-jni/src/vnt_logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[cfg(target_os = "android")]
pub fn init_log() {
use android_logger::Config;
use log::LevelFilter;
android_logger::init_once(
Config::default()
.with_max_level(LevelFilter::Info) // limit log level
.with_tag("vnt_jni"), // logs will show under mytag tag
);
}
#[cfg(not(target_os = "android"))]
pub fn init_log() {}
12 changes: 9 additions & 3 deletions vnt/src/ip_proxy/icmp_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,17 @@ fn recv_handle(
}
}
}
_ => {}
h => {
log::warn!("不支持的icmp代理 {:?},{:?}", peer_ip, h)
}
},
Err(_) => {}
Err(e) => {
log::warn!("icmp {:?}", e)
}
},
Err(_) => {}
Err(e) => {
log::warn!("icmp {:?}", e)
}
}
}

Expand Down

0 comments on commit 0e42944

Please sign in to comment.