Skip to content

Commit

Permalink
Merge pull request #998 from PBH-BTN/master
Browse files Browse the repository at this point in the history
merge bufix
  • Loading branch information
Gaojianli authored Feb 19, 2025
2 parents 6020b39 + 27b5fde commit d48c4b4
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.bat text eol=crlf
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
12 changes: 10 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
mvn -B clean package --file pom.xml
3 changes: 3 additions & 0 deletions pkg/portable/1. GUI Mode.bat
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions pkg/portable/2. GUI mode (slient).bat
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions pkg/portable/3. Console.bat
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.ghostchu.peerbanhelper</groupId>
<artifactId>peerbanhelper</artifactId>
<version>7.4.0</version>
<version>7.4.3</version>
<packaging>jar</packaging>

<name>PeerBanHelper</name>
Expand Down Expand Up @@ -270,7 +270,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.12.0</version>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -307,7 +307,7 @@
<dependency>
<groupId>com.github.mizosoft.methanol</groupId>
<artifactId>methanol</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
Expand Down Expand Up @@ -363,7 +363,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.2.2</version>
<version>6.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.j256.ormlite/ormlite-core -->
<dependency>
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/ghostchu/lib/jni/EcoMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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);
}
1 change: 0 additions & 1 deletion src/main/resources/profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" # 本地回环地址
Expand Down

0 comments on commit d48c4b4

Please # to comment.