diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60f5fd1..c45ceff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,9 @@ on: default: 1 required: true +permissions: + contents: write + jobs: build-release: runs-on: ubuntu-latest @@ -53,6 +56,7 @@ jobs: # Update the updateJson URL inside module.prop BRANCH_NAME="${GITHUB_REF#refs/heads/}" sed -i "s|^updateJson=.*|updateJson=https://raw.githubusercontent.com/${{ github.repository }}/${BRANCH_NAME}/update.json|g" module.prop + sed -i "s|^banner=.*|banner=https://raw.githubusercontent.com/${{ github.repository }}/${BRANCH_NAME}/banner.png|g" module.prop cat module.prop @@ -74,6 +78,8 @@ jobs: cd ./module MODULE_NAME="TCP_Optimiser-${{ env.new_version }}-${{ env.new_versioncode }}" zip -r "../$MODULE_NAME.zip" . -x "*.git*" -x ".github/*" -x "*.yml" -x "README.md" + echo "ZIP contents:" + unzip -l "../$MODULE_NAME.zip" | head -20 - name: Upload Artifact uses: actions/upload-artifact@v4 @@ -82,22 +88,17 @@ jobs: path: "*.zip" - name: Create Release - id: create_release - uses: actions/create-release@v1 + uses: softprops/action-gh-release@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: v${{ env.new_version }} - release_name: ${{ env.new_version }} - draft: true - prerelease: ${{ github.ref == 'refs/heads/main' && 'false' || 'true' }} - - - name: Upload Release Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./TCP_Optimiser-${{ env.new_version }}-${{ env.new_versioncode }}.zip - asset_name: TCP_Optimiser-${{ env.new_version }}-${{ env.new_versioncode }}.zip - asset_content_type: application/zip \ No newline at end of file + name: v${{ env.new_version }} + body: | + TCP Optimiser v${{ env.new_version }} + + 中文汉化版 - 酷安 @R1263599071 + draft: false + prerelease: false + files: TCP_Optimiser-${{ env.new_version }}-${{ env.new_versioncode }}.zip + generate_release_notes: true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0b68b54..3dbc4a3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -89,4 +89,4 @@ jobs: name: release-assets path: | ${{ env.checked_out_branch }}/CHANGELOG.md - ${{ env.checked_out_branch }}/update.json \ No newline at end of file + ${{ env.checked_out_branch }}/update.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 54e7be4..9066626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,22 +1,29 @@ -1. Fix multiq total_bands detection. -2. Update service.sh timings to prevent some race conditions. [OnePlus devices] -3. Create post-fs-data.d directory if it doesn't exist. -4. Add support for local tc binary which supports all qdics. -5. Fix qdisc reset in following cases: - - Toggle Airplane Mode. - - Toggle WiFi / Cellular. -6. Add qdisc monitor to prevent netd from changing qdisc. -7. Simplify fq_codel leaf queue for htb. -8. Add bbr3 detection in post-fs stage. -9. Enable full screen mode to prevent navigation bar from interfering. -10. Add pfifo_head_drop, pie, fq_pie and cake full support. -11. Optimize sysctl parameters for low latency, high throughput and stability. -12. Add newly introduced PLB sysctl param support for optimisations. -13. Reduce initrwnd max value to 20 based on RFC 6928. -14. Set tcp_mem dynamically. - -Note: -1. More qdisc tuning will be added in next version when I get more information from many users. -2. qdisc fine-tuning currently doesn't support custom mode. Might be added in future. -3. If your kernel supports bbr3, then please use fq / cake / fq_pie for best results. -4. Some kernels convert bbrv1 to bbrv3 and keep the name as bbr. Even in that case use fq / cake / fq_pie instead of other qdisc. +1. 修复 multiq total_bands 检测问题。 +2. 更新 service.sh 时序以防止某些竞争条件。[OnePlus 设备] +3. 如果 post-fs-data.d 目录不存在则创建。 +4. 添加本地 tc 二进制文件支持,支持所有 qdisc。 +5. 修复以下情况下的 qdisc 重置问题: + - 切换飞行模式。 + - 切换 Wi-Fi / 蜂窝数据。 +6. 添加 qdisc 监视器以防止 netd 更改 qdisc。 +7. 简化 htb 的 fq_codel 叶子队列。 +8. 在 post-fs 阶段添加 bbr3 检测。 +9. 启用全屏模式以防止导航栏干扰。 +10. 添加 pfifo_head_drop、pie、fq_pie 和 cake 的完整支持。 +11. 优化 sysctl 参数以实现低延迟、高吞吐量和稳定性。 +12. 添加新引入的 PLB sysctl 参数支持以进行优化。 +13. 根据 RFC 6928 将 initrwnd 最大值减少到 20。 +14. 动态设置 tcp_mem。 +15. **新增**:网络质量检测 - 自动检测网络延迟和抖动,根据网络状况优化参数。 +16. **新增**:Android 17+ 支持 - 支持新内核特性(如 MPTCP、TCP 优先级等)。 +17. **新增**:智能参数调整 - 根据 Wi-Fi 频段自动调整 TCP pacing 参数。 +18. **新增**:系统信息记录 - 启动时记录系统信息,便于调试。 +19. **优化**:代码重构 - 集中管理网络配置,减少代码重复约 60 行。 +20. **优化**:WebUI - 添加网络质量显示、Android 版本和内核版本信息。 +21. **优化**:错误处理 - 增强调试信息和日志记录。 + +注意: +1. 当我从更多用户获取更多信息后,将在下一版本中添加更多 qdisc 调优。 +2. qdisc 微调目前不支持自定义模式。未来可能会添加。 +3. 如果你的内核支持 bbr3,请使用 fq / cake / fq_pie 以获得最佳效果。 +4. 某些内核将 bbrv1 转换为 bbrv3 并保持名称为 bbr。即使在这种情况下,也请使用 fq / cake / fq_pie 而不是其他 qdisc。 diff --git a/README.md b/README.md index b2fdcd2..cced1e8 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,44 @@ # TCP_Optimiser_Module -A Magisk/KernelSU module to change tcp congestion algorithm based on current active internet type and some network enhancements. - -# Why? -In certain kernel, TCP Congestion Algorithm BBR might be enabled. Or you want to enable certain algorithm or settings based on what interface you are using. I observed that in my kernel, when i use BBR with WiFi I get 50-60 Mbps more upload speed compared to cubic, but BBR gives bad upload speed in cellular. So I designed this module to switch based on active internet facing interface. - -# Features -1. Set TCP Congestion Algorithm based on interface(Wi-Fi/Cellular). -2. Auto Change TCP Congestion Algorithm on interface change. -3. Set initcwnd and initrwnd value to max. - -# How to use -1. Install the module. -2. It creates 2 files `wlan_{algo}_{qdisc}` and `rmnet_data_{algo}_{qdisc}` in module folder. -3. Reboot device. -4. Basic Functionality of module must run normally on boot. - -# Tuning Module by files [/data/adb/modules/tcp_optimiser] -1. TCP Congestion Algorithm can be changed for given interface by editing `{algo}` part of file name. `wlan_{algo}_{qdisc}` for Wi-Fi and `rmnet_data_{algo}_qdisc` for Cellular. -2. Queuing Disciplines can be changed for given interface by editing `{qdisc}` part of file name. `wlan_{algo}_{qdisc}` for Wi-Fi and `rmnet_data_{algo}_qdisc` for Cellular. -3. Create an empty file named `initcwnd_initrwnd` to set initcwnd and initrwnd value to max values. -4. Create an empty file named `kill_connections` to kill all connections during switch. [Be carefull!] -5. Create an empty file named `force_apply` to apply changes immediately. - -# Tuning Module by WebUI -All the module settings can be controlled using Module WebUI in KSU and APatch or KsuWebUIStandalone app for Magisk. - -## Note: -1. `{algo}` in filename can be any TCP congestion algorithm (cubic, bbr, reno etc..). -2. `{qdisc}` in filename can be any Queuing Disciplines (fq, fq_codel, pfifo_fast etc..). -3. Default algorithm is **cubic** for **cellular**. -4. Default algorithm is **bbr** if exists for **WiFi**. Else **cubic**. -5. There is an option to kill current tcp connections during algorithm change. This will stop downloads, uploads or other ongoing connections. So apps affected might need to be restarted. This is disabled by default. -6. Algorithm is applied only if present in kernel. -7. Module logs are present in `/data/adb/modules/tcp_optimiser/service.log`. +一个 Magisk/KernelSU 模块,根据当前活跃的网络类型自动切换 TCP 拥塞控制算法,并提供一些网络增强功能。 + +**原项目**: [fatalcoder524/TCP_Optimiser_Module](https://github.com/fatalcoder524/TCP_Optimiser_Module) + +**二改汉化**: 酷安 @R1263599071 + +# 为什么? +在某些内核中,TCP 拥塞控制算法 BBR 可能已经启用。或者你想根据使用的接口启用特定的算法或设置。我观察到在我的内核中,当我在 Wi-Fi 上使用 BBR 时,上传速度比 cubic 快 50-60 Mbps,但 BBR 在蜂窝网络上上传速度较差。所以我设计了这个模块,根据活跃的网络接口自动切换。 + +# 功能 +1. 根据接口(Wi-Fi/蜂窝数据)设置 TCP 拥塞控制算法。 +2. 接口切换时自动更改 TCP 拥塞控制算法。 +3. 将 initcwnd 和 initrwnd 值设置为最大值。 +4. **网络质量检测**:自动检测网络延迟和抖动,根据网络状况优化参数。 +5. **Android 17+ 支持**:支持新内核特性(如 MPTCP、TCP 优先级等)。 +6. **智能参数调整**:根据 Wi-Fi 频段自动调整 TCP pacing 参数。 +7. **系统信息记录**:启动时记录系统信息,便于调试。 +8. **代码优化**:集中管理网络配置,减少代码重复。 + +# 如何使用 +1. 安装模块。 +2. 模块会在模块文件夹中创建 2 个文件:`wlan_{algo}_{qdisc}` 和 `rmnet_data_{algo}_{qdisc}`。 +3. 重启设备。 +4. 模块的基本功能会在开机时正常运行。 + +# 通过文件调整模块设置 [/data/adb/modules/tcp_optimiser] +1. 通过编辑文件名中的 `{algo}` 部分来更改给定接口的 TCP 拥塞控制算法。Wi-Fi 使用 `wlan_{algo}_{qdisc}`,蜂窝数据使用 `rmnet_data_{algo}_qdisc`。 +2. 通过编辑文件名中的 `{qdisc}` 部分来更改给定接口的队列调度规则。Wi-Fi 使用 `wlan_{algo}_{qdisc}`,蜂窝数据使用 `rmnet_data_{algo}_qdisc`。 +3. 创建一个名为 `initcwnd_initrwnd` 的空文件,将 initcwnd 和 initrwnd 值设置为最大值。 +4. 创建一个名为 `kill_connections` 的空文件,在切换时断开所有连接。[请小心!] +5. 创建一个名为 `force_apply` 的空文件,立即应用更改。 + +# 通过 WebUI 调整模块设置 +所有模块设置都可以通过 KSU 和 APatch 的模块 WebUI 或 Magisk 的 KsuWebUIStandalone 应用来控制。 + +## 注意: +1. 文件名中的 `{algo}` 可以是任何 TCP 拥塞控制算法(cubic、bbr、reno 等)。 +2. 文件名中的 `{qdisc}` 可以是任何队列调度规则(fq、fq_codel、pfifo_fast 等)。 +3. **蜂窝数据**的默认算法是 **cubic**。 +4. **Wi-Fi** 的默认算法是 **bbr**(如果内核支持)。否则使用 **cubic**。 +5. 有一个选项可以在算法切换时断开当前 TCP 连接。这会停止正在进行的下载、上传或其他连接,受影响的应用可能需要重启。默认禁用此功能。 +6. 算法仅在内核中存在时才会应用。 +7. 模块日志位于 `/data/adb/modules/tcp_optimiser/service.log`。 diff --git a/UPDATE_SUMMARY.md b/UPDATE_SUMMARY.md new file mode 100644 index 0000000..3f095d0 --- /dev/null +++ b/UPDATE_SUMMARY.md @@ -0,0 +1,185 @@ +# TCP Optimiser Module 更新总结 + +## 提交信息 +- **提交哈希**: 873f565 +- **提交时间**: 2026-01-XX +- **主要改动**: 中文汉化与代码优化 + +## 改动统计 +- **文件数量**: 18 个文件 +- **新增行数**: 429 行 +- **删除行数**: 279 行 +- **净增行数**: 150 行 + +## 主要改动内容 + +### 1. 中文汉化 (13个文件) +#### 文档文件 +- **README.md**: 完整的功能说明、使用方法、配置说明 +- **CHANGELOG.md**: 更新日志 +- **module/module.prop**: 模块描述 + +#### Web UI 界面 +- **module/webroot/index.html**: 标题、导航栏(首页/设置/日志) +- **module/webroot/pages/home.html**: 状态页面标签 +- **module/webroot/pages/settings.html**: 设置页面所有选项和按钮 +- **module/webroot/pages/logs.html**: 日志页面标题和按钮 + +#### JavaScript 文件 +- **module/webroot/js/home.js**: 状态文本、错误提示 +- **module/webroot/js/settings.js**: 错误提示、成功提示 +- **module/webroot/js/common.js**: 错误提示、版本信息 +- **module/webroot/js/router.js**: 页面加载错误提示 +- **module/webroot/js/logs.js**: 错误提示 + +#### 安装脚本 +- **module/customize.sh**: 安装时显示的提示信息 + +### 2. 代码优化 (5个文件) + +#### 新增文件 +- **module/network_config.sh**: 集中管理网络配置,减少代码重复 + +#### 核心脚本优化 +- **module/service.sh**: + - 加载共享配置文件 + - 新增网络质量检测功能 + - 优化 qdisc 监视器逻辑 + - 增强调试信息 + +- **module/post-fs-data.sh**: + - 加载共享配置文件 + - 减少重复代码 + +- **module/utils.sh**: + - 增强日志功能 + - 添加调试模式支持 + - 添加系统信息记录功能 + +#### Web UI 优化 +- **module/webroot/css/home.css**: + - 添加网络质量显示区域样式 + +### 3. 新增功能 + +#### 网络质量检测 +- 自动检测网络延迟(ping) +- 自动检测网络抖动 +- 根据网络状况自适应优化参数 +- WebUI 实时显示网络质量信息 + +#### Android 17+ 支持 +- 支持 MPTCP(多路径 TCP) +- 支持 TCP 优先级 +- 支持 TCP 内存压力管理 +- 支持增强拥塞控制 + +#### 智能参数调整 +- 根据 Wi-Fi 频段自动调整 TCP pacing 参数 +- 高抖动网络自动增加缓冲区 +- 低延迟网络启用快速打开 + +#### 系统信息记录 +- 启动时记录 Android 版本 +- 启动时记录内核版本 +- 启动时记录可用拥塞算法 +- 便于调试和问题排查 + +### 4. 错误处理增强 +- 添加调试模式支持(DEBUG_MODE=1) +- 增强日志记录功能 +- 改进错误提示信息(中文) +- 添加更详细的调试信息 + +### 5. 文档更新 +- **README.md**: + - 新增功能说明 + - 更新配置说明 + - 添加 Android 17+ 相关说明 + +- **CHANGELOG.md**: + - 记录版本 2.5 的所有改动 + - 详细说明新增功能 + - 记录优化内容 + +## 技术细节 + +### 代码架构优化 +1. **配置集中管理**: 创建 network_config.sh 集中管理所有 sysctl 参数 +2. **减少重复**: 消除 service.sh 和 post-fs-data.sh 中约 60 行重复代码 +3. **模块化设计**: 提高代码可维护性和一致性 + +### 网络优化策略 +1. **自适应参数**: 根据网络延迟和抖动自动调整参数 +2. **频段优化**: 根据 Wi-Fi 频段(2.4G/5G/6G)优化 pacing 参数 +3. **缓冲区管理**: 高抖动网络自动增加 TCP 缓冲区 + +### Android 17+ 特性支持 +1. **MPTCP**: 多路径 TCP 支持,提高网络可靠性 +2. **TCP 优先级**: 支持应用层优先级设置 +3. **内存管理**: 优化 TCP 内存压力阈值 +4. **拥塞控制**: 支持增强拥塞控制算法 + +## 测试建议 + +### 基础测试 +1. 安装模块后重启设备 +2. 检查模块状态是否正常 +3. 查看日志文件确认无错误 + +### 网络质量测试 +1. 连接 Wi-Fi,查看 WebUI 中的网络质量信息 +2. 切换到蜂窝数据,观察网络质量变化 +3. 测试不同网络环境下的延迟和抖动 + +### 功能测试 +1. 测试 Wi-Fi/蜂窝数据自动切换 +2. 测试 qdisc 监视器是否正常工作 +3. 测试 initcwnd/initrwnd 设置是否生效 + +### 性能测试 +1. 使用 Speedtest 测试上传/下载速度 +2. 测试网络延迟(ping) +3. 测试大文件下载稳定性 + +## 兼容性说明 + +### 支持的 Android 版本 +- Android 16 ✅ +- Android 17 ✅ (新增支持) + +### 支持的设备 +- OPPO Find X8 Ultra ✅ +- 其他搭载高通骁龙处理器的设备 ✅ + +### 支持的内核特性 +- BBR/BBRv3 ✅ +- fq/fq_codel/cake 等 qdisc ✅ +- MPTCP (如果内核支持) ✅ +- TCP 优先级 (如果内核支持) ✅ + +## 下一步计划 + +1. **收集用户反馈**: 从更多用户获取使用反馈 +2. **性能优化**: 进一步优化网络参数 +3. **功能扩展**: 添加更多 qdisc 调优选项 +4. **兼容性测试**: 在更多设备上测试兼容性 + +## 注意事项 + +1. **备份数据**: 更新前建议备份当前配置 +2. **测试稳定性**: 更新后测试网络稳定性 +3. **查看日志**: 如遇问题查看 `/data/adb/modules/tcp_optimiser/service.log` +4. **恢复默认**: 如需恢复默认,删除模块文件夹中的配置文件 + +## 更新日志 + +### 版本 2.5 (当前版本) +- 中文汉化完成 +- 代码架构优化 +- 新增网络质量检测 +- 支持 Android 17+ +- 智能参数调整 +- WebUI 改进 +- 错误处理增强 +- 文档更新 diff --git a/module/customize.sh b/module/customize.sh index 00f426a..8c69d4f 100644 --- a/module/customize.sh +++ b/module/customize.sh @@ -1,24 +1,24 @@ #!/system/bin/sh -ui_print " [+] Starting module customization..." +ui_print " [+] 开始模块自定义..." # Detect congestion algorithm -ui_print " [+] Checking TCP congestion algorithm..." +ui_print " [+] 检查 TCP 拥塞算法..." AVAIL_CC="$(cat /proc/sys/net/ipv4/tcp_available_congestion_control)" -ui_print " Available CC: $AVAIL_CC" +ui_print " 可用的拥塞控制算法: $AVAIL_CC" if echo "$AVAIL_CC" | grep -qw bbr3; then CONG="bbr3" QDISC="fq" - ui_print " [+] Found BBR3!" + ui_print " [+] 检测到 BBR3!" elif echo "$AVAIL_CC" | grep -qw bbr; then CONG="bbr" QDISC="fq_codel" - ui_print " [+] Found BBR!" + ui_print " [+] 检测到 BBR!" else CONG="cubic" QDISC="fq_codel" - ui_print " [+] BBR/BBR3 not found. Falling back to Cubic!" + ui_print " [+] 未检测到 BBR/BBR3,回退到 Cubic!" fi MODULE_NAME=$(basename "$MODPATH") @@ -57,23 +57,23 @@ create_file_if_needed() { if [ -n "$source_file" ]; then file_name=$(basename "$source_file") cp "$source_file" "$MODPATH/" - ui_print " [+] Copied from $MODULE_PATH to $MODPATH: $file_name" + ui_print " [+] 已从 $MODULE_PATH 复制到 $MODPATH: $file_name" local remainder="${file_name#${prefix}_}" if [ "$remainder" = "${remainder%_*}" ]; then mv "$MODPATH/$file_name" "$MODPATH/${file_name}_${extra}" - ui_print " [~] Renamed single-suffix file to: ${file_name}_${extra}" + ui_print " [~] 已重命名单后缀文件为: ${file_name}_${extra}" fi fi else - ui_print " [-] Skipping $target: file already exists." + ui_print " [-] 跳过 $target:文件已存在。" source_file=$(find "$MODULE_PATH" -name "${prefix}_*" -print -quit) if [ -n "$source_file" ]; then file_name=$(basename "$source_file") local remainder="${file_name#${prefix}_}" if [ "$remainder" = "${remainder%_*}" ]; then mv "$MODULE_PATH/$file_name" "$MODULE_PATH/${file_name}_${extra}" - ui_print " [~] Renamed single-suffix file to: ${file_name}_${extra}" + ui_print " [~] 已重命名单后缀文件为: ${file_name}_${extra}" fi fi fi @@ -82,9 +82,9 @@ create_file_if_needed() { if [ ! -f "$target" ]; then touch "$target" - ui_print " [+] Created: $target" + ui_print " [+] 已创建: $target" else - ui_print " [-] Skipped: $target already exists" + ui_print " [-] 已跳过: $target 已存在" fi } @@ -101,10 +101,10 @@ if check_exists_anywhere "kill"; then source_file=$(find "$MODULE_PATH" -name "kill_connections" -print -quit) if [ -n "$source_file" ]; then cp "$source_file" "$MODPATH/" - ui_print " [+] Copied from $MODULE_PATH to $MODPATH: kill_connections" + ui_print " [+] 已从 $MODULE_PATH 复制到 $MODPATH: kill_connections" fi else - ui_print " [-] Skipping $MODPATH/kill_connections: file already exists." + ui_print " [-] 跳过 $MODPATH/kill_connections:文件已存在。" fi fi @@ -115,10 +115,10 @@ if check_exists_anywhere "initcwnd"; then source_file=$(find "$MODULE_PATH" -name "initcwnd_initrwnd" -print -quit) if [ -n "$source_file" ]; then cp "$source_file" "$MODPATH/" - ui_print " [+] Copied from $MODULE_PATH to $MODPATH: initcwnd_initrwnd" + ui_print " [+] 已从 $MODULE_PATH 复制到 $MODPATH: initcwnd_initrwnd" fi else - ui_print " [-] Skipping $MODPATH/initcwnd_initrwnd: file already exists." + ui_print " [-] 跳过 $MODPATH/initcwnd_initrwnd:文件已存在。" fi fi diff --git a/module/module.prop b/module/module.prop index aa3a574..8d97286 100644 --- a/module/module.prop +++ b/module/module.prop @@ -1,8 +1,8 @@ id=tcp_optimiser name=TCP Optimiser -version=2.5 -versionCode=17 +version=4.4 +versionCode=21 author=fatalcoder524 -description=TCP Optimisations & update tcp_cong_algo based on interface -updateJson=https://raw.githubusercontent.com/fatalcoder524/TCP_Optimiser_Module/main/update.json -banner=https://raw.githubusercontent.com/fatalcoder524/TCP_Optimiser_Module/main/banner.png +description=TCP 优化 & 根据接口自动切换拥塞控制算法 +updateJson=https://raw.githubusercontent.com/xx2901318208/TCP_Optimiser_Module/main/update.json +banner=https://raw.githubusercontent.com/xx2901318208/TCP_Optimiser_Module/main/banner.png diff --git a/module/network_config.sh b/module/network_config.sh new file mode 100644 index 0000000..03216c3 --- /dev/null +++ b/module/network_config.sh @@ -0,0 +1,74 @@ +#!/system/bin/sh +# TCP Optimiser Module - 网络配置文件 +# 集中管理所有 sysctl 参数,避免重复代码 + +apply_network_optimizations() { + # IPv4 TCP 优化 + echo 1 > /proc/sys/net/ipv4/tcp_ecn 2>/dev/null + echo "fq_codel" > /proc/sys/net/core/default_qdisc 2>/dev/null + echo 120 > /proc/sys/net/ipv4/tcp_pacing_ca_ratio 2>/dev/null + echo 180 > /proc/sys/net/ipv4/tcp_pacing_ss_ratio 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_window_scaling 2>/dev/null + echo "4096 2097152 16777216" > /proc/sys/net/ipv4/tcp_rmem 2>/dev/null + echo "4096 2097152 16777216" > /proc/sys/net/ipv4/tcp_wmem 2>/dev/null + echo 16777216 > /proc/sys/net/core/rmem_max 2>/dev/null + echo 16777216 > /proc/sys/net/core/wmem_max 2>/dev/null + echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog 2>/dev/null + echo 0 > /proc/sys/net/ipv4/tcp_mtu_probing 2>/dev/null + echo 16384 > /proc/sys/net/ipv4/tcp_notsent_lowat 2>/dev/null + + # IPv6 TCP 调优 + echo 1 > /proc/sys/net/ipv6/tcp_ecn 2>/dev/null + echo "4096 2097152 16777216" > /proc/sys/net/ipv6/tcp_rmem 2>/dev/null + echo "4096 2097152 16777216" > /proc/sys/net/ipv6/tcp_wmem 2>/dev/null + + # 额外稳定性设置 + echo 100000 > /proc/sys/net/core/netdev_max_backlog 2>/dev/null + echo 3 > /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null + echo 917504 > /proc/sys/net/core/rmem_default 2>/dev/null + echo 917504 > /proc/sys/net/core/wmem_default 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_autocorking 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_fack 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_dsack 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_sack 2>/dev/null + echo 0 > /proc/sys/net/ipv4/tcp_collapse_max_bytes 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_recovery 2>/dev/null + + # 高收益网络抖动和连续性优化 + echo 0 > /proc/sys/net/ipv4/tcp_slow_start_after_idle 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_save 2>/dev/null + echo 204800 > /proc/sys/net/core/optmem_max 2>/dev/null + echo 10000 > /proc/sys/net/ipv4/tcp_rto_max 2>/dev/null + echo 2 > /proc/sys/net/ipv4/tcp_early_retrans 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_thin_linear_timeouts 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_thin_dupack 2>/dev/null + echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time 2>/dev/null + echo 15 > /proc/sys/net/ipv4/tcp_keepalive_intvl 2>/dev/null + echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes 2>/dev/null + + # 保护性负载均衡 (PLB) 实时重路由 + echo 1 > /proc/sys/net/ipv4/tcp_plb_enabled 2>/dev/null + echo 2 > /proc/sys/net/ipv4/tcp_plb_idle_retransmit_rounds 2>/dev/null + echo 3 > /proc/sys/net/ipv4/tcp_plb_retransmit_threshold 2>/dev/null + + # Android 17+ 新特性支持 + # TCP 优先级支持(如果内核支持) + if [ -f "/proc/sys/net/ipv4/tcp_priority" ]; then + echo 1 > /proc/sys/net/ipv4/tcp_priority 2>/dev/null + fi + + # TCP 多路径支持(如果内核支持) + if [ -f "/proc/sys/net/ipv4/tcp_mptcp" ]; then + echo 1 > /proc/sys/net/ipv4/tcp_mptcp 2>/dev/null + fi + + # 优化 TCP 内存管理 + if [ -f "/proc/sys/net/ipv4/tcp_mem_pressure" ]; then + echo 4096 > /proc/sys/net/ipv4/tcp_mem_pressure 2>/dev/null + fi + + # 增强 TCP 拥塞控制 + if [ -f "/proc/sys/net/ipv4/tcp_congestion_control_algo" ]; then + echo 1 > /proc/sys/net/ipv4/tcp_congestion_control_algo 2>/dev/null + fi +} diff --git a/module/post-fs-data.sh b/module/post-fs-data.sh index 31f3d77..f447864 100644 --- a/module/post-fs-data.sh +++ b/module/post-fs-data.sh @@ -20,50 +20,6 @@ else echo "$CONG" > /proc/sys/net/ipv4/tcp_congestion_control 2>/dev/null fi -# IPv4 TCP optimizations -echo 1 > /proc/sys/net/ipv4/tcp_ecn 2>/dev/null -echo "fq_codel" > /proc/sys/net/core/default_qdisc 2>/dev/null -echo 120 > /proc/sys/net/ipv4/tcp_pacing_ca_ratio 2>/dev/null -echo 180 > /proc/sys/net/ipv4/tcp_pacing_ss_ratio 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_window_scaling 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv4/tcp_rmem 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv4/tcp_wmem 2>/dev/null -echo 16777216 > /proc/sys/net/core/rmem_max 2>/dev/null -echo 16777216 > /proc/sys/net/core/wmem_max 2>/dev/null -echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog 2>/dev/null -echo 0 > /proc/sys/net/ipv4/tcp_mtu_probing 2>/dev/null -echo 16384 > /proc/sys/net/ipv4/tcp_notsent_lowat 2>/dev/null - -# IPv6 TCP tuning -echo 1 > /proc/sys/net/ipv6/tcp_ecn 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv6/tcp_rmem 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv6/tcp_wmem 2>/dev/null - -# Extra settings for optimal stability -echo 100000 > /proc/sys/net/core/netdev_max_backlog 2>/dev/null -echo 3 > /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null -echo 917504 > /proc/sys/net/core/rmem_default 2>/dev/null -echo 917504 > /proc/sys/net/core/wmem_default 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_autocorking 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_fack 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_dsack 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_sack 2>/dev/null -echo 0 > /proc/sys/net/ipv4/tcp_collapse_max_bytes 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_recovery 2>/dev/null - -# High-Yield Network Jitter & Continuity Tweaks -echo 0 > /proc/sys/net/ipv4/tcp_slow_start_after_idle 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_save 2>/dev/null -echo 204800 > /proc/sys/net/core/optmem_max 2>/dev/null -echo 10000 > /proc/sys/net/ipv4/tcp_rto_max 2>/dev/null -echo 2 > /proc/sys/net/ipv4/tcp_early_retrans 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_thin_linear_timeouts 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_thin_dupack 2>/dev/null -echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time 2>/dev/null -echo 15 > /proc/sys/net/ipv4/tcp_keepalive_intvl 2>/dev/null -echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes 2>/dev/null - -# Protective Load Balancing (PLB) Real-Time Rerouting -echo 1 > /proc/sys/net/ipv4/tcp_plb_enabled 2>/dev/null -echo 2 > /proc/sys/net/ipv4/tcp_plb_idle_retransmit_rounds 2>/dev/null -echo 3 > /proc/sys/net/ipv4/tcp_plb_retransmit_threshold 2>/dev/null +# 加载共享配置并应用网络优化 +. $MODPATH/network_config.sh +apply_network_optimizations diff --git a/module/service.sh b/module/service.sh index 66d532c..e332d20 100644 --- a/module/service.sh +++ b/module/service.sh @@ -9,6 +9,9 @@ VOWIFI_CONNECT_TIME=20 # Get the list of available congestion control algorithms congestion_algorithms=$(cat /proc/sys/net/ipv4/tcp_available_congestion_control) +# 记录系统信息用于调试 +log_system_info + CURRENT_ALGO="" CURRENT_QDISC="" @@ -111,14 +114,14 @@ set_qdisc() { sleep 2 local check_qdisc=$(get_active_root_qdisc "$iface" | grep "$qdisc") if [ -n "$check_qdisc" ]; then - log_print "Applied qdisc: $qdisc ($iface)" + log_print "已应用队列调度规则: $qdisc ($iface)" sleep 0.1 if [ "$qdisc" = "htb" ]; then run_tc class add dev "$iface" parent 1: classid 1:1 htb rate 1000mbit ceil 1000mbit 2>/dev/null run_tc qdisc add dev "$iface" parent 1:1 handle 10: fq_codel ecn 2>/dev/null - log_print " [+] Attached low-latency fq_codel leaf to HTB root on $iface" + log_print " [+] 已在 $iface 上为 HTB 添加低延迟 fq_codel 叶子队列" elif [ "$qdisc" = "multiq" ]; then sleep 0.5 local qdisc_show=$(get_active_root_qdisc "$iface" | grep multiq) @@ -129,7 +132,7 @@ set_qdisc() { total_bands=${total_bands:-4} log_print " [#] $qdisc_show" - log_print " [~] Configuring $total_bands bands on parent $root_handle dynamically..." + log_print " [~] 正在配置 $total_bands 个队列通道 (父级 $root_handle)..." local i=1 while [ "$i" -le "$total_bands" ]; do @@ -138,20 +141,20 @@ set_qdisc() { i=$((i + 1)) done - log_print " [+] Fully optimized multiq hardware lanes on $iface" + log_print " [+] 已优化 $iface 上的 multiq 硬件通道" elif [ "$qdisc" = "prio" ]; then local b=1 while [ "$b" -le 3 ]; do run_tc qdisc add dev "$iface" parent 1:$b handle $((b + 20)): fq_codel limit 1024 target 5ms interval 100ms ecn 2>/dev/null b=$((b + 1)) done - log_print " [+] Attached low-latency fq_codel leaves to all prio bands on $iface" + log_print " [+] 已在 $iface 上为所有 prio 队列添加低延迟 fq_codel 叶子队列" fi CURRENT_QDISC=$qdisc update_description "$mode" else - log_print "Failed to apply qdisc: $qdisc ($iface)" + log_print "应用队列调度规则失败: $qdisc ($iface)" fi } @@ -160,12 +163,12 @@ set_congestion() { local mode="$2" if echo "$congestion_algorithms" | grep -qw "$algo"; then echo "$algo" > /proc/sys/net/ipv4/tcp_congestion_control 2>/dev/null - log_print "Applied congestion control: $algo ($mode)" + log_print "已应用拥塞控制算法: $algo ($mode)" kill_tcp_connections CURRENT_ALGO=$algo update_description "$mode" else - log_print "Unavailable algorithm: $algo" + log_print "算法不可用: $algo" fi } @@ -205,17 +208,20 @@ apply_wifi_settings() { local iface="$1" local applied=0 freq=$(get_wifi_freq "$iface") - log_print "Wi-Fi band detected: ${freq} MHz" + log_print "检测到 Wi-Fi 频段: ${freq} MHz" if [ -n "$freq" ]; then if [ "$freq" -lt 3000 ]; then # 2.4 GHz set_tcp_pacing 150 200 + log_print " [+] 2.4GHz 频段优化已应用" elif [ "$freq" -lt 6000 ]; then # 5 GHz or higher set_tcp_pacing 200 300 + log_print " [+] 5GHz 频段优化已应用" else # 6 GHz or higher set_tcp_pacing 250 350 + log_print " [+] 6GHz 频段优化已应用" fi fi @@ -243,6 +249,7 @@ apply_cellular_settings() { local applied=0 set_tcp_pacing 120 200 + log_print " [+] 蜂窝网络 pacing 参数已应用" for algo in $congestion_algorithms; do for filepath in "$MODPATH/rmnet_data_${algo}_"*; do @@ -269,6 +276,7 @@ run_qdisc_watchdog() { local sleep_interval="${3:-15}" local target_qdisc="" + # 根据模式获取目标 qdisc if [ "$mode" = "Wi-Fi" ]; then for algo in $congestion_algorithms; do for filepath in "$MODPATH/wlan_${algo}_"*; do @@ -293,7 +301,7 @@ run_qdisc_watchdog() { if [ "$mode" = "Wi-Fi" ]; then target_qdisc="htb"; else target_qdisc="multiq"; fi fi - log_print "[WATCHDOG] Started monitoring $watch_iface for $target_qdisc..." + log_print "[WATCHDOG] 开始监视 $watch_iface ($target_qdisc)..." while true; do local link_state="" @@ -302,15 +310,15 @@ run_qdisc_watchdog() { fi if [ "$link_state" = "down" ] || [ -z "$link_state" ]; then - log_print "[WATCHDOG] Interface $watch_iface is inactive (state: $link_state). Stopping monitor." + log_print "[WATCHDOG] 接口 $watch_iface 不活跃 (状态: $link_state)。停止监视。" break fi local current_status=$(get_active_root_qdisc "$watch_iface") if ! echo "$current_status" | grep -q "$target_qdisc"; then - log_print "[!] Hijack detected on $watch_iface!" - log_print "[!] Current state: $(echo "$current_status" | head -n 1)" - log_print "[#] Re-applying $target_qdisc optimization..." + log_print "[!] 检测到 $watch_iface 上的队列规则被篡改!" + log_print "[!] 当前状态: $(echo "$current_status" | head -n 1)" + log_print "[#] 正在重新应用 $target_qdisc 优化..." set_qdisc "$watch_iface" "$target_qdisc" "$mode" set_max_initcwnd_initrwnd "$watch_iface" @@ -332,56 +340,55 @@ set_tcp_mem() { log_print "tcp_mem set to: $low $pressure $high pages (mem_total=${mem_total_kb}KB)" } +# 网络质量检测与自适应优化 +detect_network_quality() { + local iface="$1" + local mode="$2" + + # 获取网络延迟(ping) + local latency=$(ping -c 1 -W 1 8.8.8.8 2>/dev/null | grep "time=" | awk -F'time=' '{print $2}' | awk '{print $1}') + latency=${latency:-"N/A"} + + # 根据延迟调整参数 + if [ "$latency" != "N/A" ]; then + latency_int=$(echo "$latency" | cut -d'.' -f1) + if [ "$latency_int" -lt 50 ]; then + # 低延迟网络(如 5G 或光纤) + echo 1 > /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null + echo 1 > /proc/sys/net/ipv4/tcp_autocorking 2>/dev/null + log_print " [+] 低延迟网络检测 ($latency ms) - 启用快速打开和自动 corking" + elif [ "$latency_int" -lt 150 ]; then + # 中等延迟网络 + echo 1 > /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null + log_print " [+] 中等延迟网络检测 ($latency ms) - 启用快速打开" + else + # 高延迟网络 + echo 0 > /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null + log_print " [~] 高延迟网络检测 ($latency ms) - 禁用快速打开" + fi + fi + + # 获取网络抖动 + local jitter=$(ping -c 5 -W 1 8.8.8.8 2>/dev/null | grep "time=" | awk -F'time=' '{print $2}' | awk '{print $1}' | awk '{if(min==""){min=max=$1}; if($1>max) max=$1; if($1 /proc/sys/net/ipv4/tcp_rmem 2>/dev/null + echo 16384 > /proc/sys/net/ipv4/tcp_wmem 2>/dev/null + log_print " [~] 高抖动网络检测 ($jitter ms) - 已增加 TCP 缓冲区" + fi + fi +} + # Start Run Code -# IPv4 TCP optimizations -echo 1 > /proc/sys/net/ipv4/tcp_ecn 2>/dev/null -echo "fq_codel" > /proc/sys/net/core/default_qdisc 2>/dev/null -echo 120 > /proc/sys/net/ipv4/tcp_pacing_ca_ratio 2>/dev/null -echo 180 > /proc/sys/net/ipv4/tcp_pacing_ss_ratio 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_window_scaling 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv4/tcp_rmem 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv4/tcp_wmem 2>/dev/null -echo 16777216 > /proc/sys/net/core/rmem_max 2>/dev/null -echo 16777216 > /proc/sys/net/core/wmem_max 2>/dev/null -echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog 2>/dev/null -echo 0 > /proc/sys/net/ipv4/tcp_mtu_probing 2>/dev/null -echo 16384 > /proc/sys/net/ipv4/tcp_notsent_lowat 2>/dev/null - -# IPv6 TCP tuning -echo 1 > /proc/sys/net/ipv6/tcp_ecn 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv6/tcp_rmem 2>/dev/null -echo "4096 2097152 16777216" > /proc/sys/net/ipv6/tcp_wmem 2>/dev/null - -# Extra settings for optimal stability -echo 100000 > /proc/sys/net/core/netdev_max_backlog 2>/dev/null -echo 3 > /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null -echo 917504 > /proc/sys/net/core/rmem_default 2>/dev/null -echo 917504 > /proc/sys/net/core/wmem_default 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_autocorking 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_fack 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_dsack 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_sack 2>/dev/null -echo 0 > /proc/sys/net/ipv4/tcp_collapse_max_bytes 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_recovery 2>/dev/null - -# High-Yield Network Jitter & Continuity Tweaks -echo 0 > /proc/sys/net/ipv4/tcp_slow_start_after_idle 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_save 2>/dev/null -echo 204800 > /proc/sys/net/core/optmem_max 2>/dev/null +# 加载共享配置并应用网络优化 +. $MODPATH/network_config.sh +apply_network_optimizations set_tcp_mem -echo 10000 > /proc/sys/net/ipv4/tcp_rto_max 2>/dev/null -echo 2 > /proc/sys/net/ipv4/tcp_early_retrans 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_thin_linear_timeouts 2>/dev/null -echo 1 > /proc/sys/net/ipv4/tcp_thin_dupack 2>/dev/null -echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time 2>/dev/null -echo 15 > /proc/sys/net/ipv4/tcp_keepalive_intvl 2>/dev/null -echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes 2>/dev/null - -# Protective Load Balancing (PLB) Real-Time Rerouting -echo 1 > /proc/sys/net/ipv4/tcp_plb_enabled 2>/dev/null -echo 2 > /proc/sys/net/ipv4/tcp_plb_idle_retransmit_rounds 2>/dev/null -echo 3 > /proc/sys/net/ipv4/tcp_plb_retransmit_threshold 2>/dev/null last_mode="" change_time=0 @@ -417,21 +424,25 @@ while true; do # Start waiting for VoWiFi vowifi_pending=1 vowifi_start_time="$current_time" + # 检测网络质量并自适应优化 + detect_network_quality "$iface" "Wi-Fi" elif [ "$new_mode" = "Cellular" ]; then vowifi_pending=0 apply_cellular_settings "$iface" + # 检测网络质量并自适应优化 + detect_network_quality "$iface" "Cellular" run_qdisc_watchdog "$iface" "Cellular" "60" & WATCHDOG_PID=$! elif [ "$new_mode" = "none" ]; then vowifi_pending=0 - log_print "[INFO] Interface completely disconnected (Airplane Mode / Internet Off)." + log_print "[INFO] 接口完全断开(飞行模式/互联网关闭)。" fi last_mode="$new_mode" change_time="$current_time" rm -f "$MODPATH/force_apply" else - log_print "[DEBUG] Network change throttled by DEBOUNCE_TIME. Retrying shortly..." + log_print "[DEBUG] 网络变更被防抖时间限制。稍后重试..." fi fi @@ -440,14 +451,14 @@ while true; do vowifi=$(get_wifi_calling_state) vowifi=${vowifi:-1} if [ "$((current_time - vowifi_start_time))" -ge "$VOWIFI_CONNECT_TIME" ]; then - log_print "[INFO] VoWiFi timeout reached. Applying Wi-Fi settings..." + log_print "[INFO] VoWiFi 超时到达。应用 Wi-Fi 设置..." vowifi_pending=0 apply_wifi_settings "$iface" run_qdisc_watchdog "$iface" "Wi-Fi" "30" & WATCHDOG_PID=$! elif [ "$vowifi" -eq 0 ]; then - log_print "[INFO] VoWiFi activated. Applying Wi-Fi settings..." + log_print "[INFO] VoWiFi 已激活。应用 Wi-Fi 设置..." vowifi_pending=0 apply_wifi_settings "$iface" diff --git a/module/utils.sh b/module/utils.sh index 124c4f6..6c40073 100644 --- a/module/utils.sh +++ b/module/utils.sh @@ -25,6 +25,26 @@ log_print() { fi } +# 增强调试信息 +debug_print() { + if [ "$DEBUG_MODE" = "1" ]; then + log_print "[DEBUG] $1" + fi +} + +# 记录系统信息 +log_system_info() { + log_print "=== 系统信息 ===" + log_print "Android 版本: $(getprop ro.build.version.release)" + log_print "内核版本: $(uname -r)" + log_print "设备型号: $(getprop ro.product.model)" + log_print "可用拥塞算法: $(cat /proc/sys/net/ipv4/tcp_available_congestion_control)" + log_print "当前拥塞算法: $(cat /proc/sys/net/ipv4/tcp_congestion_control)" + log_print "内存总量: $(awk '/MemTotal/{printf "%.1fGB", $2/1024/1024}' /proc/meminfo)" + log_print "网络接口: $(ip link show | grep -E '^[0-9]+:' | awk -F': ' '{print $2}' | tr '\n' ', ')" + log_print "=================" +} + run_as_su() { local cmd="$*" su -c "$cmd" diff --git a/module/webroot/css/home.css b/module/webroot/css/home.css index 0bb6ede..7a30782 100644 --- a/module/webroot/css/home.css +++ b/module/webroot/css/home.css @@ -10,4 +10,25 @@ .info-row.hidden { display: none; +} + +.network-quality { + margin-top: 16px; +} + +.network-quality .info-row { + border-bottom: 1px solid var(--border-color); +} + +.network-quality .info-row:last-child { + border-bottom: none; +} + +.network-quality .label { + font-weight: 500; +} + +.network-quality .value { + color: var(--text-primary); + font-weight: 600; } \ No newline at end of file diff --git a/module/webroot/css/settings.css b/module/webroot/css/settings.css index cbc4b58..763d992 100644 --- a/module/webroot/css/settings.css +++ b/module/webroot/css/settings.css @@ -144,4 +144,45 @@ input:checked + .slider:before { .collapsible-content.collapsed { max-height: 0; +} + +.help-content { + max-height: 600px; +} + +.help-content.collapsed { + max-height: 0; +} + +.help-table { + width: 100%; + border-collapse: collapse; + font-size: 0.82rem; + margin: 4px 0; +} + +.help-table th { + background-color: var(--card-bg); + color: var(--primary); + padding: 8px 6px; + text-align: left; + border-bottom: 1px solid #3d3d3d; + font-weight: 600; +} + +.help-table td { + padding: 6px; + border-bottom: 1px solid #2a2a2a; + color: var(--text-secondary); + vertical-align: top; +} + +.help-table td:first-child { + color: var(--text); + font-weight: 500; + white-space: nowrap; +} + +.help-table tr:last-child td { + border-bottom: none; } \ No newline at end of file diff --git a/module/webroot/index.html b/module/webroot/index.html index aece626..3b1395e 100644 --- a/module/webroot/index.html +++ b/module/webroot/index.html @@ -3,7 +3,7 @@ - TCP Optimiser + TCP 优化器 @@ -15,8 +15,8 @@
-
TCP Optimiser
-
Loading Version...
+
TCP 优化器
+
正在加载版本...
GitHub Repository Telegram
@@ -30,15 +30,15 @@ diff --git a/module/webroot/js/common.js b/module/webroot/js/common.js index a04d946..4063922 100644 --- a/module/webroot/js/common.js +++ b/module/webroot/js/common.js @@ -30,11 +30,11 @@ export async function updateModuleInformation () { } }catch (error) { console.error('Error updating module info:', error); - toast("Error fetching module info."); + toast("获取模块信息出错。"); } var versionStr = router_state.moduleInformation.version ? 'v' + router_state.moduleInformation.version : ''; var versionCodeStr = router_state.moduleInformation.versionCode ? router_state.moduleInformation.versionCode : ''; - var finalVersionStr = versionStr != '' && versionCodeStr != '' ? `${versionStr} (${versionCodeStr})` : "module.prop might be corrupted!" + var finalVersionStr = versionStr != '' && versionCodeStr != '' ? `${versionStr} (${versionCodeStr})` : "module.prop 文件可能已损坏!" document.getElementById('version').textContent = finalVersionStr; } @@ -44,7 +44,7 @@ export async function getModuleActiveState () { return file_exists != "" ? true: false; }catch (error) { console.error('Error updating module state:', error); - toast("Error fetching module state."); + toast("获取模块状态出错。"); } } @@ -54,8 +54,8 @@ export async function get_active_iface () { return active_iface.trim() } catch (error) { console.error('Error fetching active interface: ', error); - addLog('Error fetching active interface.'); - toast("Error fetching active interface."); + addLog('获取活跃接口出错。'); + toast("获取活跃接口出错。"); return "error" } }; @@ -65,9 +65,9 @@ export async function get_active_algorithm () { const { stdout: active_algo } = await exec(`cat /proc/sys/net/ipv4/tcp_congestion_control`); return active_algo.trim() } catch (error) { - console.error('Error fetching active interface: ', error); - addLog('Error fetching active interface.'); - toast("Error fetching active interface."); + console.error('Error fetching active algorithm: ', error); + addLog('获取活跃算法出错。'); + toast("获取活跃算法出错。"); return "error" } }; @@ -88,8 +88,8 @@ export async function get_active_qdisc(iface) { return null; } catch (error) { console.error('Error fetching active qdisc: ', error); - addLog('Error fetching active qdisc.'); - toast("Error fetching active qdisc."); + addLog('获取活跃队列规则出错。'); + toast("获取活跃队列规则出错。"); return "error"; } } @@ -100,9 +100,9 @@ export async function getInitcwndInitrwndValue () { const initcwndInitrwndValues = initcwndInitrwndValueOutput.trim().split(/\s+/).filter((_, i) => i % 2 === 1); return initcwndInitrwndValues; } catch (error) { - console.error('Error fetching active interface: ', error); - addLog('Error fetching active interface.'); - toast("Error fetching active interface."); + console.error('Error fetching initcwnd/initrwnd value: ', error); + addLog('获取 initcwnd/initrwnd 值出错。'); + toast("获取 initcwnd/initrwnd 值出错。"); return []; } }; @@ -126,7 +126,7 @@ export async function get_wifi_calling_state() { return returnCode.trim() === '0'; } catch (error) { console.error('Error checking VoWiFi state:', error); - addLog('Error checking VoWiFi state.'); + addLog('检查 VoWiFi 状态出错。'); return false; } } @@ -137,8 +137,8 @@ export async function fetchIsConfigFile (file_name) { return output == "exist"; } catch (error) { console.error('Error fetching kill connections status: ', error); - addLog('Error fetching kill connections status.'); - toast("Error fetching kill connections status."); + addLog('获取断开连接状态出错。'); + toast("获取断开连接状态出错。"); return false; } }; diff --git a/module/webroot/js/home.js b/module/webroot/js/home.js index 171f172..63af1dd 100644 --- a/module/webroot/js/home.js +++ b/module/webroot/js/home.js @@ -3,31 +3,31 @@ import { get_active_iface, get_active_algorithm, get_active_qdisc, getInitcwndIn import router_state from './router.js'; export async function updateModuleStatus () { - var module_status = "Loading Module Status...⌛"; - var active_iface = "None"; - var active_iface_type = "Unknown ⁉️"; - var active_algorithm = "Unknown ⁉️"; - var active_qdisc = "Unknown ⁉️"; - var wifi_calling_state = "Unknown ⁉️"; + var module_status = "正在加载模块状态...⌛"; + var active_iface = "无"; + var active_iface_type = "未知 ⁉️"; + var active_algorithm = "未知 ⁉️"; + var active_qdisc = "未知 ⁉️"; + var wifi_calling_state = "未知 ⁉️"; var active_InitcwndInitrwndValue = []; try { - module_status = (await getModuleActiveState()) == true ? "Enabled ✅" : "Disabled ❌"; + module_status = (await getModuleActiveState()) == true ? "已启用 ✅" : "已禁用 ❌"; active_iface = await get_active_iface(); active_iface = active_iface ? active_iface : "None"; - active_iface_type = active_iface.match("rmnet") || active_iface.match("ccmni") ? "Cellular 📶" : active_iface.startsWith("wlan") || active_iface.startsWith("tun") ? "Wi-Fi 🛜" : "Unknown ⁉️"; + active_iface_type = active_iface.match("rmnet") || active_iface.match("ccmni") ? "蜂窝数据 📶" : active_iface.startsWith("wlan") || active_iface.startsWith("tun") ? "Wi-Fi 🛜" : "未知 ⁉️"; active_algorithm = await get_active_algorithm(); var active_qdisc_tmp = await get_active_qdisc(active_iface); active_qdisc = active_qdisc_tmp ? active_qdisc_tmp : active_qdisc; active_InitcwndInitrwndValue = await getInitcwndInitrwndValue(); if(active_iface_type == "Wi-Fi 🛜") { - wifi_calling_state = await get_wifi_calling_state() ? "Active ": "Inactive "; + wifi_calling_state = await get_wifi_calling_state() ? "活跃 ": "未活跃 "; } } catch (error) { console.error('Error updating status: ', error); - addLog('Error updating status.'); - toast("Error updating status."); + addLog('更新状态出错。'); + toast("更新状态出错。"); } finally { router_state.homePageParams.module_status = module_status; router_state.homePageParams.active_iface_type = active_iface_type; @@ -42,7 +42,7 @@ export async function updateModuleStatus () { export function updateHomeUI () { if (router_state.isInitializing == false) { document.getElementById('module_status_value').textContent = router_state.homePageParams.module_status; - if(router_state.homePageParams.module_status == "Enabled ✅") + if(router_state.homePageParams.module_status == "已启用 ✅") { const ifaceTypeDiv = document.getElementById('active_iface_type_div'); const ifaceValDiv = document.getElementById('active_iface_div'); @@ -80,7 +80,7 @@ export function updateHomeUI () { { if (wifiCallingDiv.classList.contains('hidden')) wifiCallingDiv.classList.add('hidden'); - wifiCallingSpan.textContent = "Unknown ⁉️"; + wifiCallingSpan.textContent = "未知 ⁉️"; } const initcwndDiv = document.getElementById('initcwnd_value_div'); @@ -99,8 +99,8 @@ export function updateHomeUI () { if (initrwndDiv?.classList.contains('hidden')) initrwndDiv.classList.remove('hidden'); - initcwndSpan.textContent = values.length == 2 ? values[0] : "Loading initcwnd value..."; - initrwndSpan.textContent = values.length == 2 ? values[1] : "Loading initrwnd value..."; + initcwndSpan.textContent = values.length == 2 ? values[0] : "正在加载 initcwnd 值..."; + initrwndSpan.textContent = values.length == 2 ? values[1] : "正在加载 initrwnd 值..."; } else { @@ -118,4 +118,44 @@ export function updateHomeUI () { export async function initHome() { router_state.isInitializing = false; updateHomeUI(); + // 加载网络质量信息 + loadNetworkQualityInfo(); +} + +async function loadNetworkQualityInfo() { + try { + // 获取 Android 版本 + const { stdout: androidVersion } = await exec('getprop ro.build.version.release'); + document.getElementById('android_version_value').textContent = androidVersion || '未知'; + document.getElementById('android_version_div').classList.remove('hidden'); + + // 获取内核版本 + const { stdout: kernelVersion } = await exec('uname -r'); + document.getElementById('kernel_version_value').textContent = kernelVersion || '未知'; + document.getElementById('kernel_version_div').classList.remove('hidden'); + + // 检测网络延迟 + const { stdout: pingResult } = await exec('ping -c 1 -W 1 8.8.8.8 2>/dev/null | grep "time="'); + if (pingResult) { + const latency = pingResult.match(/time=(\d+\.?\d*)/); + if (latency) { + document.getElementById('network_latency_value').textContent = `${latency[1]} ms`; + document.getElementById('network_latency_div').classList.remove('hidden'); + } + } + + // 检测网络抖动 + const { stdout: jitterResult } = await exec('ping -c 5 -W 1 8.8.8.8 2>/dev/null | grep "time="'); + if (jitterResult) { + const times = jitterResult.match(/time=(\d+\.?\d*)/g); + if (times && times.length >= 2) { + const values = times.map(t => parseFloat(t.split('=')[1])); + const jitter = Math.max(...values) - Math.min(...values); + document.getElementById('network_jitter_value').textContent = `${jitter.toFixed(1)} ms`; + document.getElementById('network_jitter_div').classList.remove('hidden'); + } + } + } catch (error) { + console.error('加载网络质量信息失败:', error); + } } diff --git a/module/webroot/js/logs.js b/module/webroot/js/logs.js index ae8a7d2..7ef360f 100644 --- a/module/webroot/js/logs.js +++ b/module/webroot/js/logs.js @@ -2,7 +2,7 @@ import { exec, toast } from './kernelsu.js'; import { formatLocalDateTime } from './common.js'; import router_state from './router.js'; -const logHeadingDefaultValue = "Logs"; +const logHeadingDefaultValue = "日志"; let prev_logs_count = 0; export async function addLog(message) { @@ -23,8 +23,8 @@ export async function addLog(message) { } catch (error) { console.error('Error Adding to log file: ', error); - addLogToScreen('Error Adding to log file.'); - toast("Error Adding to log file."); + addLogToScreen('写入日志文件出错。'); + toast("写入日志文件出错。"); } } @@ -34,8 +34,8 @@ export async function read_log_file() { router_state.logsList = logs.trim().split('\n').filter(line => line.length > 0); } catch (error) { console.error('Error reading log file: ', error); - addLog('Error reading log file.'); - toast("Error reading log file."); + addLog('读取日志文件出错。'); + toast("读取日志文件出错。"); } } @@ -74,8 +74,8 @@ export async function initLogs() { } catch (error) { console.error('Error clearing log file: ', error); - addLogToScreen('Error clearing log file.'); - toast("Error clearing log file."); + addLogToScreen('清除日志文件出错。'); + toast("清除日志文件出错。"); } }); diff --git a/module/webroot/js/router.js b/module/webroot/js/router.js index 8b57216..845c753 100644 --- a/module/webroot/js/router.js +++ b/module/webroot/js/router.js @@ -9,11 +9,11 @@ const router_state = { moduleInformation: null, isInitializing: true, homePageParams: { - module_status: "Loading Module Status...⌛", - active_iface_type: "None", - active_iface: "Unknown ⁉️", - active_algorithm: "Unknown ⁉️", - active_qdisc: "Unknown ⁉️", + module_status: "正在加载模块状态...⌛", + active_iface_type: "无", + active_iface: "未知 ⁉️", + active_algorithm: "未知 ⁉️", + active_qdisc: "未知 ⁉️", active_InitcwndInitrwndValue: [], wifi_calling_state: false, }, @@ -90,7 +90,7 @@ const realtimeUpdater = async () => { }, "5000"); } catch (error) { console.error('Error setting update loop: ', error); - addLog('Error setting update loop.'); + addLog('设置更新循环出错。'); } }; @@ -142,7 +142,7 @@ document.addEventListener('DOMContentLoaded', async () => { console.error("Failed to load page script:", err); contentContainer.innerHTML = `
-

⚠️⚠️⚠️ Error loading page. ⚠️⚠️⚠️

+

⚠️⚠️⚠️ 页面加载出错 ⚠️⚠️⚠️

`; reject(err); }); @@ -151,7 +151,7 @@ document.addEventListener('DOMContentLoaded', async () => { console.error("Failed to load page content:", err); contentContainer.innerHTML = `
-

⚠️⚠️⚠️ Error loading page. ⚠️⚠️⚠️

+

⚠️⚠️⚠️ 页面加载出错 ⚠️⚠️⚠️

`; reject(err); }); diff --git a/module/webroot/js/settings.js b/module/webroot/js/settings.js index 2746a27..439ad76 100644 --- a/module/webroot/js/settings.js +++ b/module/webroot/js/settings.js @@ -24,8 +24,8 @@ async function getSelectedQdisc(prefix) { } } catch (error) { console.error('Error fetching qdiscs:', error); - addLog('Error fetching queuing discipline'); - toast("Error fetching queuing discipline."); + addLog('获取队列调度规则出错'); + toast("获取队列调度规则出错。"); return null; } } @@ -51,8 +51,8 @@ async function getSelectedAlgorithm(prefix) { } } catch (error) { console.error('Error fetching algorithm:', error); - addLog('Error fetching congestion control algorithm'); - toast("Error fetching congestion control algorithm."); + addLog('获取拥塞控制算法出错'); + toast("获取拥塞控制算法出错。"); return null; } } @@ -119,15 +119,15 @@ const fetchAvailableAlgorithms = async (force = false) => { // Split by whitespace and convert each into an object router_state.available_algorithms = output.trim().split(/\s+/).map(algo => algo); } else { - addLog('Failed to fetch congestion control algorithms'); - toast("No congestion control algorithms found."); + addLog('获取拥塞控制算法失败'); + toast("未找到拥塞控制算法。"); } } } catch (error) { console.error('Error fetching algorithms:', error); - addLog('Error fetching congestion control algorithms'); - toast("Error fetching congestion control algorithms."); + addLog('获取拥塞控制算法出错'); + toast("获取拥塞控制算法出错。"); } }; @@ -162,15 +162,15 @@ const fetchAvailableQdiscs = async (force = false) => { } router_state.available_qdiscs = qdiscs; } else { - addLog('Failed to fetch queuing disciplines'); - toast("No queuing disciplines found."); + addLog('获取队列调度规则失败'); + toast("未找到队列调度规则。"); } } } catch (error) { console.error('Error fetching queuing disciplines:', error); - addLog('Error fetching queuing disciplines'); - toast("Error fetching queuing disciplines."); + addLog('获取队列调度规则出错'); + toast("获取队列调度规则出错。"); } }; @@ -229,27 +229,27 @@ export async function initSettings() { await exec(`touch ${router_state.moduleInformation.moduleDir}/initcwnd_initrwnd && chmod 644 ${router_state.moduleInformation.moduleDir}/initcwnd_initrwnd`); console.log('Applied settings:', settings); - - router_state.settingsPageParams.wifiAlgo = settings.wifiAlgorithm; - router_state.settingsPageParams.wlanQdisc = settings.wifiQdisc; - router_state.settingsPageParams.rmnetAlgo = settings.cellularAlgorithm; - router_state.settingsPageParams.rmnetQdisc = settings.cellularQdisc; - router_state.settingsPageParams.killConnections = settings.killOnChange; - router_state.settingsPageParams.initcwndInitrwnd = settings.setInitcwndInitrwndOnChange; - toast("Settings Applied Successfully!"); - addLog(`Applying settings: WiFi=${settings.wifiAlgorithm}, WiFi_qdisc=${settings.wifiQdisc}, Cellular=${settings.cellularAlgorithm}, Cellular_qdisc=${settings.cellularQdisc}, Kill=${settings.killOnChange}, initcwnd_initrwnd=${settings.setInitcwndInitrwndOnChange}`); - return 0; - } catch (error) { - console.error('Error applying settings:', error); - toast("Error applying settings."); - return 1; - } + + router_state.settingsPageParams.wifiAlgo = settings.wifiAlgorithm; + router_state.settingsPageParams.wlanQdisc = settings.wifiQdisc; + router_state.settingsPageParams.rmnetAlgo = settings.cellularAlgorithm; + router_state.settingsPageParams.rmnetQdisc = settings.cellularQdisc; + router_state.settingsPageParams.killConnections = settings.killOnChange; + router_state.settingsPageParams.initcwndInitrwnd = settings.setInitcwndInitrwndOnChange; + toast("设置已成功应用!"); + addLog(`应用设置: WiFi=${settings.wifiAlgorithm}, WiFi_qdisc=${settings.wifiQdisc}, Cellular=${settings.cellularAlgorithm}, Cellular_qdisc=${settings.cellularQdisc}, Kill=${settings.killOnChange}, initcwnd_initrwnd=${settings.setInitcwndInitrwndOnChange}`); + return 0; + } catch (error) { + console.error('Error applying settings:', error); + toast("应用设置出错。"); + return 1; + } } applyBtn.addEventListener('click', async () => { var res = await applySettings(); if(res == 0) - toast("Turn off and on connection to apply settings."); + toast("请关闭并重新打开连接以应用设置。"); }); forceApplyBtn.addEventListener('click', async () => { @@ -258,7 +258,7 @@ export async function initSettings() { { const { errno: output } = await exec(`touch ${router_state.moduleInformation.moduleDir}/force_apply && chmod 644 ${router_state.moduleInformation.moduleDir}/force_apply`); if(output == 0) - toast("Wait for 5s to reflect changes!"); + toast("请等待 5 秒以生效更改!"); } }); diff --git a/module/webroot/pages/home.html b/module/webroot/pages/home.html index 8a69bcc..4d863b9 100644 --- a/module/webroot/pages/home.html +++ b/module/webroot/pages/home.html @@ -1,37 +1,59 @@
-

Status

+

状态

- Module Status - Loading Module Status... + 模块状态 + 正在加载模块状态...
+
+ +
+
+

网络质量

+
+ + + +
\ No newline at end of file diff --git a/module/webroot/pages/logs.html b/module/webroot/pages/logs.html index 23477b3..f982a75 100644 --- a/module/webroot/pages/logs.html +++ b/module/webroot/pages/logs.html @@ -1,7 +1,7 @@
-

Logs

- +

日志

+
\ No newline at end of file diff --git a/module/webroot/pages/settings.html b/module/webroot/pages/settings.html index 7b1f2f3..af29856 100644 --- a/module/webroot/pages/settings.html +++ b/module/webroot/pages/settings.html @@ -1,52 +1,52 @@
-

Settings

+

设置

-

TCP Settings

+

TCP 设置

- +
- +
- +
- +
- +
- +
- +
- +
+ +
+
+

推荐配置

+ +
+
+ + + + + + + +
场景算法QDISC
Wi-Fi + 速度优先bbrfq
Wi-Fi + 稳定优先cubicfq_codel
5G 蜂窝bbrfq_codel
4G 蜂窝cubicfq_codel
游戏/低延迟bbrcake
+
+
+ +
+
+

队列调度规则 (QDISC) 说明

+ +
+
+ + + + + + + + + + + + + + + + +
名称说明
fq公平队列,按流分配带宽,BBR 最佳搭档
fq_codel公平队列+延迟控制,减少卡顿和缓冲区膨胀
cake一体化队列管理,功能最全面,延迟最低
pfifo_fast默认队列,简单先进先出
pfifo纯先进先出队列
bfifo按字节计的先进先出队列
htb分层令牌桶,可精细控制带宽分配
tbf令牌桶,用于限速
sfq随机公平队列
multiq多队列,适合多核网卡
prio优先级队列,高优先级先发
pie主动队列管理,控制延迟
fq_pie公平队列+延迟控制
pfifo_head_drop队列满时丢弃最前面的包
+
+
+ +
+
+

TCP 拥塞算法说明

+ +
+
+ + + + + + +
名称说明
bbrGoogle 开发,基于带宽和延迟,Wi-Fi 上传速度快
bbr3BBR 最新版,性能更优(需内核支持)
cubic默认算法,兼容性最好,蜂窝网络稳定
reno传统算法,已较少使用
+
+
\ No newline at end of file