diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..69b47b5ad --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.bat text eol=crlf diff --git a/Dockerfile b/Dockerfile index 3c742203f..00df13436 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM --platform=$BUILDPLATFORM docker.io/maven:3.9.9-eclipse-temurin-21-alpine A COPY . /build WORKDIR /build -RUN apk add --update npm curl git && \ +RUN apk --update upgrade && apk add --update npm curl git && \ curl -L https://unpkg.com/@pnpm/self-installer | node && \ cd webui && \ pnpm i && \ diff --git a/build.sh b/build.sh index f4433e72c..1424789f7 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,14 @@ #!/bin/sh echo "Setup webui files.." -sh setup-webui.sh +current_wd=$(pwd) +static_dir="$(dirname $0)/src/main/resources/static" + +rm -rf ${static_dir} || echo "" +cd ${current_wd}/webui +pnpm install +pnpm run build +cd ${current_wd} +cp -r webui/dist ${static_dir} echo "Prepare to build jar.." -mvn -B clean package --file pom.xml \ No newline at end of file +mvn -B clean package --file pom.xml diff --git a/pkg/portable/1. GUI Mode.bat b/pkg/portable/1. GUI Mode.bat new file mode 100644 index 000000000..eaa9fdaa6 --- /dev/null +++ b/pkg/portable/1. GUI Mode.bat @@ -0,0 +1,3 @@ +@echo off +title PeerBanHelper (GUI Mode) +start ./jre/bin/javaw.exe -Xmx512M -Xss512k -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+ShrinkHeapInSteps -Dpbh.release=portable -Dfile.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -Dconsole.encoding=UTF-8 -jar PeerBanHelper.jar diff --git a/pkg/portable/2. GUI mode (slient).bat b/pkg/portable/2. GUI mode (slient).bat new file mode 100644 index 000000000..3bc908243 --- /dev/null +++ b/pkg/portable/2. GUI mode (slient).bat @@ -0,0 +1,3 @@ +@echo off +title PeerBanHelper (GUI mode, slient) +start ./jre/bin/javaw.exe -Xmx512M -Xss512k -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+ShrinkHeapInSteps -Dpbh.release=portable -Dfile.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -Dconsole.encoding=UTF-8 -jar PeerBanHelper.jar silent diff --git a/pkg/portable/3. Console.bat b/pkg/portable/3. Console.bat new file mode 100644 index 000000000..68f1b1db5 --- /dev/null +++ b/pkg/portable/3. Console.bat @@ -0,0 +1,4 @@ +@echo off +title PeerBanHelper (Console) +start ./jre/bin/java.exe -Xmx512M -Xss512k -XX:+UseG1GC -XX:+UseStringDeduplication -Djava.awt.headless=true -XX:+ShrinkHeapInSteps -Dpbh.release=portable -Dfile.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -Dconsole.encoding=UTF-8 -jar PeerBanHelper.jar nogui +pause \ No newline at end of file diff --git "a/pkg/portable/4) \344\273\245\346\216\247\345\210\266\345\217\260\346\250\241\345\274\217\345\220\257\345\212\250 (\344\275\216\345\206\205\345\255\230\346\250\241\345\274\217\357\274\214\345\217\257\350\203\275\344\275\277\347\224\250\346\233\264\345\244\232 CPU \345\222\214\347\243\201\347\233\230 IO).bat" "b/pkg/portable/4) \344\273\245\346\216\247\345\210\266\345\217\260\346\250\241\345\274\217\345\220\257\345\212\250 (\344\275\216\345\206\205\345\255\230\346\250\241\345\274\217\357\274\214\345\217\257\350\203\275\344\275\277\347\224\250\346\233\264\345\244\232 CPU \345\222\214\347\243\201\347\233\230 IO).bat" index f9f23a8ca..80b3033ab 100644 --- "a/pkg/portable/4) \344\273\245\346\216\247\345\210\266\345\217\260\346\250\241\345\274\217\345\220\257\345\212\250 (\344\275\216\345\206\205\345\255\230\346\250\241\345\274\217\357\274\214\345\217\257\350\203\275\344\275\277\347\224\250\346\233\264\345\244\232 CPU \345\222\214\347\243\201\347\233\230 IO).bat" +++ "b/pkg/portable/4) \344\273\245\346\216\247\345\210\266\345\217\260\346\250\241\345\274\217\345\220\257\345\212\250 (\344\275\216\345\206\205\345\255\230\346\250\241\345\274\217\357\274\214\345\217\257\350\203\275\344\275\277\347\224\250\346\233\264\345\244\232 CPU \345\222\214\347\243\201\347\233\230 IO).bat" @@ -1,5 +1,5 @@ @echo off chcp 65001 -title PeerBanHelper (低内存模式,控制台,将使用更多 CPU 和磁盘 I/O) +title PeerBanHelper (低内存模式) start ./jre/bin/java.exe -Xmx168M -Xms16M -Xss512k -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+ShrinkHeapInSteps -Dfile.encoding=UTF-8 -Dpbh.usePlatformConfigLocation=true -Dpbh.release=install4j -Djava.awt.headless=true -Dpbh.geoIpCache.timeout=30000 -Dpbh.geoIpCache.size=100 -Dpbh.moduleMatchCache.weight=25000 -Dpbh.modulematchcache.timeout=30000 -Dpbh.gui.logs.maxSize=50 -Dpbh.logger.logEntryDeque.size=100 -Dpbh.logger.ringDeque.size=50 -Dpbh.module.activeMonitorModule.diskWriteCache.timeout=30000 -Dpbh.module.activeMonitorModule.diskWriteCache.size=1500 -Dpbh.module.progressCheatBlocker.recorder.timeout=30000 -Dpbh.module.progressCheatBlocker.recorder.weight=6000000 -jar PeerBanHelper.jar nogui nojcef pause \ No newline at end of file diff --git a/pkg/portable/4. Low-memory Mode (May cost more CPU and disk) .bat b/pkg/portable/4. Low-memory Mode (May cost more CPU and disk) .bat new file mode 100644 index 000000000..f15ed894c --- /dev/null +++ b/pkg/portable/4. Low-memory Mode (May cost more CPU and disk) .bat @@ -0,0 +1,4 @@ +@echo off +title PeerBanHelper (Console, Low-Memeory Mode) +start ./jre/bin/java.exe -Xmx168M -Xms16M -Xss512k -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+ShrinkHeapInSteps -Dfile.encoding=UTF-8 -Dpbh.usePlatformConfigLocation=true -Dpbh.release=install4j -Djava.awt.headless=true -Dpbh.geoIpCache.timeout=30000 -Dpbh.geoIpCache.size=100 -Dpbh.moduleMatchCache.weight=25000 -Dpbh.modulematchcache.timeout=30000 -Dpbh.gui.logs.maxSize=50 -Dpbh.logger.logEntryDeque.size=100 -Dpbh.logger.ringDeque.size=50 -Dpbh.module.activeMonitorModule.diskWriteCache.timeout=30000 -Dpbh.module.activeMonitorModule.diskWriteCache.size=1500 -Dpbh.module.progressCheatBlocker.recorder.timeout=30000 -Dpbh.module.progressCheatBlocker.recorder.weight=6000000 -jar PeerBanHelper.jar nogui nojcef +pause \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2555e9d95..29d56e5ea 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.ghostchu.peerbanhelper peerbanhelper - 7.4.0 + 7.4.3 jar PeerBanHelper @@ -270,7 +270,7 @@ com.google.code.gson gson - 2.12.0 + 2.12.1 com.google.guava @@ -307,7 +307,7 @@ com.github.mizosoft.methanol methanol - 1.8.0 + 1.8.1 @@ -363,7 +363,7 @@ org.springframework spring-context - 6.2.2 + 6.2.3 diff --git a/src/main/java/com/ghostchu/lib/jni/EcoMode.java b/src/main/java/com/ghostchu/lib/jni/EcoMode.java index 5c0877fc4..fc4755cdb 100644 --- a/src/main/java/com/ghostchu/lib/jni/EcoMode.java +++ b/src/main/java/com/ghostchu/lib/jni/EcoMode.java @@ -18,6 +18,10 @@ public boolean ecoMode(boolean enable) { if (!os.startsWith("win")) { throw new IllegalStateException("Only Windows OS support EcoMode API"); } + String osVersion = System.getProperty("os.version"); + if (!isSupportedVersion(osVersion)) { // 检查是否为版本号大于22621 + throw new IllegalStateException("EcoQoS is only supported on Windows version 22621 or higher"); + } String arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT); try { File tmpFile = Files.createTempFile("pbh-jni-lib", ".dll").toFile(); @@ -28,7 +32,7 @@ public boolean ecoMode(boolean enable) { Files.copy(Main.class.getResourceAsStream("/native/windows/ghost-common-jni_vc2015_amd64.dll"), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } System.load(tmpFile.getAbsolutePath()); - } catch (Exception e) { + } catch (Throwable e) { log.error("Unable load JNI native libraries", e); } try { @@ -39,5 +43,15 @@ public boolean ecoMode(boolean enable) { } } + // 判断是否为受支持的版本 + private boolean isSupportedVersion(String osVersion) { + try { + int versionNumber = Integer.parseInt(osVersion.replaceAll("\\.", "")); + return versionNumber >= 10022621; // 10.0.22621 开始支持 + } catch (NumberFormatException e) { + return false; + } + } + private native static String setEcoMode(boolean enable); } diff --git a/src/main/resources/profile.yml b/src/main/resources/profile.yml index 8a72696fc..1f2f2769f 100644 --- a/src/main/resources/profile.yml +++ b/src/main/resources/profile.yml @@ -19,7 +19,6 @@ ignore-peers-from-addresses: - "172.16.0.0/12" # 中型企业内部网络 - "192.168.0.0/16" # 小型企业和家庭内部网络 - "fc00::/7" # 唯一本地地址 (ULA),用于站点内部通信 - - "fd00::/8" # 本地分配的ULA - "100.64.0.0/10" # 用于大规模NAT (CGNAT, Carrier-Grade NAT),也常被 Tailscale 使用 - "169.254.0.0/16" # 链路本地地址 (Link-Local Address) - "127.0.0.0/8" # 本地回环地址