diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 675841f..e769116 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,7 +11,7 @@ on: image_tag: description: 'Tag for this image build' type: string - default: 'v2.3.0' + default: 'v2.3.1' required: true mark_latest: description: 'Mark this image as latest' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0aac7b9..af3cbe4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ on: version: description: 'Version for this release' type: string - default: 'v2.3.0' + default: 'v2.3.1' required: true make_latest: description: 'Mark this release as latest' @@ -57,7 +57,7 @@ jobs: repo: EasyTier/EasyTier path: release_assets_nozip - - name: Download GUI Artifact + - name: Download Mobile Artifact uses: dawidd6/action-download-artifact@v6 with: github_token: ${{secrets.GITHUB_TOKEN}} @@ -78,7 +78,14 @@ jobs: ls -l -R ./ chmod -R 755 . for x in `ls`; do - zip ../zipped_assets/$x-${VERSION}.zip $x/*; + if [ "$x" = "Easytier-Magisk" ]; then + # for Easytier-Magisk, make sure files are in the root of the zip + cd $x; + zip -r ../../zipped_assets/$x-${VERSION}.zip .; + cd ..; + else + zip -r ../zipped_assets/$x-${VERSION}.zip $x; + fi done - name: Release diff --git a/Cargo.lock b/Cargo.lock index 299fd39..4e60f75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1918,7 +1918,7 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "easytier" -version = "2.3.0" +version = "2.3.1" dependencies = [ "aes-gcm", "anyhow", @@ -2045,7 +2045,7 @@ dependencies = [ [[package]] name = "easytier-gui" -version = "2.3.0" +version = "2.3.1" dependencies = [ "anyhow", "chrono", @@ -2091,7 +2091,7 @@ dependencies = [ [[package]] name = "easytier-web" -version = "2.3.0" +version = "2.3.1" dependencies = [ "anyhow", "async-trait", diff --git a/easytier-contrib/easytier-magisk/README.md b/easytier-contrib/easytier-magisk/README.md index 55e8ac2..a9edd7e 100644 --- a/easytier-contrib/easytier-magisk/README.md +++ b/easytier-contrib/easytier-magisk/README.md @@ -2,5 +2,5 @@ magisk安装后重启 目录位置:/data/adb/modules/easytier_magisk -配置文件位置://data/adb/modules/easytier_magisk/config/config.conf +配置文件位置://data/adb/modules/easytier_magisk/config/config.toml 修改config.conf即可,修改后配置文件后去magisk app重新开关模块即可生效 diff --git a/easytier-contrib/easytier-magisk/action.sh b/easytier-contrib/easytier-magisk/action.sh deleted file mode 100644 index 1294dc8..0000000 --- a/easytier-contrib/easytier-magisk/action.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/data/adb/magisk/busybox sh -MODDIR=${0%/*} -echo 'Easytier 服务停止中....' - -PIDS=$(pgrep -f "^${MODDIR}/easytier-core -c ${MODDIR}/config/config.conf") - -if [ -n "$PIDS" ]; then - kill $PIDS # 杀死所有匹配的进程 - echo "已停止所有 Easytier 进程 (PIDs: $PIDS)" -else - echo "Easytier 服务未运行" -fi -echo '重启服务中...' -nohup sh ${MODDIR}/service.sh >> ${MODDIR}/log/start.log 2>&1 & -echo '服务已重启' -exit \ No newline at end of file diff --git a/easytier-contrib/easytier-magisk/config/config.conf b/easytier-contrib/easytier-magisk/config/config.toml similarity index 100% rename from easytier-contrib/easytier-magisk/config/config.conf rename to easytier-contrib/easytier-magisk/config/config.toml diff --git a/easytier-contrib/easytier-magisk/customize.sh b/easytier-contrib/easytier-magisk/customize.sh index 2331919..6c7393a 100644 --- a/easytier-contrib/easytier-magisk/customize.sh +++ b/easytier-contrib/easytier-magisk/customize.sh @@ -2,6 +2,6 @@ ui_print '安装完成' ui_print '当前架构为' + $ARCH ui_print '当前系统版本为' + $API ui_print '安装目录为: /data/adb/modules/easytier_magisk' -ui_print '配置文件位置: /data/adb/modules/easytier_magisk/config/config.conf' +ui_print '配置文件位置: /data/adb/modules/easytier_magisk/config/config.toml' ui_print '修改后配置文件后在magisk app点击操作按钮即可生效' ui_print '记得重启' \ No newline at end of file diff --git a/easytier-contrib/easytier-magisk/easytier_core.sh b/easytier-contrib/easytier-magisk/easytier_core.sh new file mode 100644 index 0000000..7ff8de2 --- /dev/null +++ b/easytier-contrib/easytier-magisk/easytier_core.sh @@ -0,0 +1,48 @@ +#!/system/bin/sh + +MODDIR=${0%/*} +CONFIG_FILE="${MODDIR}/config/config.toml" +LOG_FILE="${MODDIR}/log.log" +MODULE_PROP="${MODDIR}/module.prop" +EASYTIER="${MODDIR}/easytier-core" + +# 更新module.prop文件中的description +update_module_description() { + local status_message=$1 + sed -i "/^description=/c\description=[状态]${status_message}" ${MODULE_PROP} +} + +if [ ! -e /dev/net/tun ]; then + if [ ! -d /dev/net ]; then + mkdir -p /dev/net + fi + + ln -s /dev/tun /dev/net/tun +fi + +while true; do + if ls $MODDIR | grep -q "disable"; then + update_module_description "关闭中" + if pgrep -f 'easytier-core' >/dev/null; then + echo "开关控制$(date "+%Y-%m-%d %H:%M:%S") 进程已存在,正在关闭 ..." + pkill easytier-core # 关闭进程 + fi + else + if ! pgrep -f 'easytier-core' >/dev/null; then + if [ ! -f "$CONFIG_FILE" ]; then + update_module_description "config.toml不存在" + sleep 3s + continue + fi + + TZ=Asia/Shanghai ${EASYTIER} -c ${CONFIG_FILE} > ${LOG_FILE} & + sleep 5s # 等待easytier-core启动完成 + update_module_description "已开启(不一定运行成功)" + ip rule add from all lookup main + else + echo "开关控制$(date "+%Y-%m-%d %H:%M:%S") 进程已存在" + fi + fi + + sleep 3s # 暂停3秒后再次执行循环 +done diff --git a/easytier-contrib/easytier-magisk/kill.sh b/easytier-contrib/easytier-magisk/kill.sh new file mode 100644 index 0000000..7ab70f3 --- /dev/null +++ b/easytier-contrib/easytier-magisk/kill.sh @@ -0,0 +1,14 @@ +#!/data/adb/magisk/busybox sh +MODDIR=${0%/*} + +# 查找 easytier-core 进程的 PID +PID=$(pgrep easytier-core) + +# 检查是否找到了进程 +if [ -z "$PID" ]; then + echo "easytier-core 进程未找到" +else + # 结束进程 + kill $PID + echo "已结束 easytier-core 进程 (PID: $PID)" +fi diff --git a/easytier-contrib/easytier-magisk/module.prop b/easytier-contrib/easytier-magisk/module.prop index 223a10c..8df373b 100644 --- a/easytier-contrib/easytier-magisk/module.prop +++ b/easytier-contrib/easytier-magisk/module.prop @@ -1,7 +1,7 @@ id=easytier_magisk -name=easytier_magisk版 -version=v2.2.4 +name=EasyTier_Magisk +version=v2.3.1 versionCode=1 author=EasyTier -description=easytier_magisk版模块 作者:EasyTier https://github.com/EasyTier/EasyTier +description=easytier magisk module @EasyTier(https://github.com/EasyTier/EasyTier) updateJson=https://raw.githubusercontent.com/EasyTier/EasyTier/refs/heads/main/easytier-contrib/easytier-magisk/magisk_update.json diff --git a/easytier-contrib/easytier-magisk/service.sh b/easytier-contrib/easytier-magisk/service.sh index 8e95b24..c443017 100644 --- a/easytier-contrib/easytier-magisk/service.sh +++ b/easytier-contrib/easytier-magisk/service.sh @@ -1,20 +1,27 @@ #!/data/adb/magisk/busybox sh MODDIR=${0%/*} # MODDIR="$(dirname $(readlink -f "$0"))" -mkdir -p ${MODDIR}/log chmod 755 ${MODDIR}/* -echo $MODDIR >> ${MODDIR}/log/start.log +# 等待系统启动成功 +while [ "$(getprop sys.boot_completed)" != "1" ]; do + sleep 5s +done -echo "Easytier 服务启动" >> ${MODDIR}/log/start.log +# 防止系统挂起 +echo "PowerManagerService.noSuspend" > /sys/power/wake_lock -# 启动 -nohup ${MODDIR}/easytier-core -c ${MODDIR}/config/config.conf >> ${MODDIR}/log/start.log 2>&1 & +# 修改模块描述 +sed -i 's/$(description=)$[^"]*/\1[状态]关闭中/' "$MODDIR/module.prop" + +# 等待 3 秒 +sleep 3s + +"${MODDIR}/easytier_core.sh" & # 检查是否启用模块 while [ ! -f ${MODDIR}/disable ]; do sleep 2 done -PID=$(ps -ef|grep "${MODDIR}/easytier-core -c ${MODDIR}/config/config.conf" | awk '{print $2}') -kill $PID -echo "Easytier 服务停止" >> ${MODDIR}/log/start.log + +pkill easytier-core diff --git a/easytier-contrib/easytier-magisk/system/etc/resolv.conf b/easytier-contrib/easytier-magisk/system/etc/resolv.conf new file mode 100644 index 0000000..38e2618 --- /dev/null +++ b/easytier-contrib/easytier-magisk/system/etc/resolv.conf @@ -0,0 +1,2 @@ +nameserver 114.114.114.114 +nameserver 223.5.5.5 diff --git a/easytier-contrib/easytier-magisk/uninstall.sh b/easytier-contrib/easytier-magisk/uninstall.sh index d50d747..c7d7cb2 100644 --- a/easytier-contrib/easytier-magisk/uninstall.sh +++ b/easytier-contrib/easytier-magisk/uninstall.sh @@ -1,2 +1,3 @@ MODDIR=${0%/*} +pkill easytier-core # 结束 easytier-core 进程 rm -rf $MODDIR/* \ No newline at end of file diff --git a/easytier-gui/package.json b/easytier-gui/package.json index 4987331..5dc10bb 100644 --- a/easytier-gui/package.json +++ b/easytier-gui/package.json @@ -1,7 +1,7 @@ { "name": "easytier-gui", "type": "module", - "version": "2.2.4", + "version": "2.3.1", "private": true, "packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4", "scripts": { diff --git a/easytier-gui/src-tauri/Cargo.toml b/easytier-gui/src-tauri/Cargo.toml index 899f83a..ef5c419 100644 --- a/easytier-gui/src-tauri/Cargo.toml +++ b/easytier-gui/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "easytier-gui" -version = "2.3.0" +version = "2.3.1" description = "EasyTier GUI" authors = ["you"] edition = "2021" diff --git a/easytier-gui/src-tauri/tauri.conf.json b/easytier-gui/src-tauri/tauri.conf.json index 18d36f5..f2a947a 100644 --- a/easytier-gui/src-tauri/tauri.conf.json +++ b/easytier-gui/src-tauri/tauri.conf.json @@ -17,7 +17,7 @@ "createUpdaterArtifacts": false }, "productName": "easytier-gui", - "version": "2.3.0", + "version": "2.3.1", "identifier": "com.kkrainbow.easytier", "plugins": {}, "app": { diff --git a/easytier-web/Cargo.toml b/easytier-web/Cargo.toml index 12bbcee..90de5c8 100644 --- a/easytier-web/Cargo.toml +++ b/easytier-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "easytier-web" -version = "2.3.0" +version = "2.3.1" edition = "2021" description = "Config server for easytier. easytier-core gets config from this and web frontend use it as restful api server." diff --git a/easytier/Cargo.toml b/easytier/Cargo.toml index 4f0e11f..1df24c4 100644 --- a/easytier/Cargo.toml +++ b/easytier/Cargo.toml @@ -3,7 +3,7 @@ name = "easytier" description = "A full meshed p2p VPN, connecting all your devices in one network with one command." homepage = "https://github.com/EasyTier/EasyTier" repository = "https://github.com/EasyTier/EasyTier" -version = "2.3.0" +version = "2.3.1" edition = "2021" authors = ["kkrainbow"] keywords = ["vpn", "p2p", "network", "easytier"] diff --git a/easytier/src/common/mod.rs b/easytier/src/common/mod.rs index ad8ac3a..8b9e859 100644 --- a/easytier/src/common/mod.rs +++ b/easytier/src/common/mod.rs @@ -109,6 +109,9 @@ pub fn get_machine_id() -> uuid::Uuid { ))] let gen_mid = machine_uid::get() .map(|x| { + if x.is_empty() { + return uuid::Uuid::new_v4(); + } let mut b = [0u8; 16]; crate::tunnel::generate_digest_from_str("", x.as_str(), &mut b); uuid::Uuid::from_bytes(b) diff --git a/easytier/src/peers/peer_conn_ping.rs b/easytier/src/peers/peer_conn_ping.rs index 93e0afb..0cfc7d9 100644 --- a/easytier/src/peers/peer_conn_ping.rs +++ b/easytier/src/peers/peer_conn_ping.rs @@ -55,7 +55,7 @@ impl std::fmt::Debug for PingIntervalController { impl PingIntervalController { fn new(throughput: Arc, loss_counter: Arc) -> Self { - let last_throughput = *throughput; + let last_throughput = (*throughput).clone(); Self { throughput, @@ -92,7 +92,7 @@ impl PingIntervalController { self.backoff_idx = 0; } - self.last_throughput = *self.throughput; + self.last_throughput = (*self.throughput).clone(); if (self.logic_time - self.last_send_logic_time) < (1 << self.backoff_idx) { return false; diff --git a/easytier/src/tunnel/stats.rs b/easytier/src/tunnel/stats.rs index 1446def..f3b707a 100644 --- a/easytier/src/tunnel/stats.rs +++ b/easytier/src/tunnel/stats.rs @@ -1,4 +1,7 @@ -use std::sync::atomic::{AtomicU32, Ordering::Relaxed}; +use std::{ + cell::UnsafeCell, + sync::atomic::{AtomicU32, Ordering::Relaxed}, +}; pub struct WindowLatency { latency_us_window: Vec, @@ -58,13 +61,38 @@ impl WindowLatency { } } -#[derive(Default, Copy, Clone, Debug)] +#[derive(Debug)] pub struct Throughput { - tx_bytes: u64, - rx_bytes: u64, + tx_bytes: UnsafeCell, + rx_bytes: UnsafeCell, + tx_packets: UnsafeCell, + rx_packets: UnsafeCell, +} - tx_packets: u64, - rx_packets: u64, +impl Clone for Throughput { + fn clone(&self) -> Self { + Self { + tx_bytes: UnsafeCell::new(unsafe { *self.tx_bytes.get() }), + rx_bytes: UnsafeCell::new(unsafe { *self.rx_bytes.get() }), + tx_packets: UnsafeCell::new(unsafe { *self.tx_packets.get() }), + rx_packets: UnsafeCell::new(unsafe { *self.rx_packets.get() }), + } + } +} + +// add sync::Send and sync::Sync traits to Throughput +unsafe impl Send for Throughput {} +unsafe impl Sync for Throughput {} + +impl Default for Throughput { + fn default() -> Self { + Self { + tx_bytes: UnsafeCell::new(0), + rx_bytes: UnsafeCell::new(0), + tx_packets: UnsafeCell::new(0), + rx_packets: UnsafeCell::new(0), + } + } } impl Throughput { @@ -73,34 +101,32 @@ impl Throughput { } pub fn tx_bytes(&self) -> u64 { - self.tx_bytes + unsafe { *self.tx_bytes.get() } } pub fn rx_bytes(&self) -> u64 { - self.rx_bytes + unsafe { *self.rx_bytes.get() } } pub fn tx_packets(&self) -> u64 { - self.tx_packets + unsafe { *self.tx_packets.get() } } pub fn rx_packets(&self) -> u64 { - self.rx_packets + unsafe { *self.rx_packets.get() } } pub fn record_tx_bytes(&self, bytes: u64) { - #[allow(invalid_reference_casting)] unsafe { - *(&self.tx_bytes as *const u64 as *mut u64) += bytes; - *(&self.tx_packets as *const u64 as *mut u64) += 1; + *self.tx_bytes.get() += bytes; + *self.tx_packets.get() += 1; } } pub fn record_rx_bytes(&self, bytes: u64) { - #[allow(invalid_reference_casting)] unsafe { - *(&self.rx_bytes as *const u64 as *mut u64) += bytes; - *(&self.rx_packets as *const u64 as *mut u64) += 1; + *self.rx_bytes.get() += bytes; + *self.rx_packets.get() += 1; } } }