Skip to content

Commit

Permalink
Merge pull request #103 from PBH-BTN/master
Browse files Browse the repository at this point in the history
3.4.0
  • Loading branch information
Ghost-chu authored May 10, 2024
2 parents 849495e + 061f632 commit 4257f8e
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 123 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/jvm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ghostchu/peerbanhelper
images: ghostchu/peerbanhelper-snapshot
tags: |
type=ref,event=branch
type=ref,event=tag
Expand All @@ -68,7 +68,7 @@ jobs:
with:
context: .
file: ./Dockerfile
push: false
push: true
platforms: |
linux/amd64
linux/arm64/v8
Expand Down
30 changes: 12 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
FROM eclipse-temurin:17.0.10_7-jre

LABEL MAINTAINER="https://github.com/PBH-BTN/PeerBanHelper"
FROM --platform=$BUILDPLATFORM maven:3.9.6-eclipse-temurin-17 as build

ENV TZ=UTC PUID=0 PGID=0

RUN set -ex && \
export DEBIAN_FRONTEND=noninteractive && \
apt update -y && \
apt install -y gosu dumb-init && \
apt autoremove -y && \
apt clean && \
rm -rf /var/lib/apt/lists/*
ADD . /build
WORKDIR /build
RUN sh setup-webui.sh && mvn -B clean package --file pom.xml

FROM eclipse-temurin:17.0.10_7-jre
LABEL MAINTAINER="https://github.com/PBH-BTN/PeerBanHelper"
USER 0
ENV TZ=UTC
WORKDIR /app

COPY --chmod=755 ./docker-entrypoint.sh /app/

COPY ./target/PeerBanHelper.jar /app/

ENTRYPOINT [ "/app/docker-entrypoint.sh" ]
VOLUME /tmp
COPY --from=build build/target/PeerBanHelper.jar /app/PeerBanHelper.jar
ENV PATH "${JAVA_HOME}/bin:${PATH}"
ENTRYPOINT ["java","-Xmx256M","-XX:+UseSerialGC","-jar","PeerBanHelper.jar"]
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,41 @@ PeerBanHelper 主要由以下几个功能模块组成:
</details>
### 多拨侦测
专业PCDN用户会在一台PCDN服务器上接入多条宽带,以此提升上传带宽,称为多拨。
这类用户的刷下载工具一般也较为复杂,会利用多条宽带不同的出口IP分散流量,对抗基于下载进度的吸血检测。
此模块对多拨下载现象进行侦测,发现同一网段集中下载同一种子,即予以全部封禁。
目前已知可能误伤的情况:小ISP的骨干网出口在同一网段,造成多拨假象。如果种子涉及的BT网络主体在大陆以外,请谨慎使用。
<details>
<summary>查看示例配置文件</summary>
```yaml
multi-dialing-blocker:
enabled: false
# 子网掩码长度
# IP地址前多少位相同的视为同一个子网,位数越少范围越大,一般不需要修改
subnet-mask-length: 24
# 对于同小区IPv6地址应该取多少位掩码没有调查过,64位是不会误杀的保险值
subnet-mask-v6-length: 64
# 容许同一网段下载同一种子的IP数量,正整数
# 防止DHCP重新分配IP、碰巧有同一小区的用户下载同一种子等导致的误判
tolerate-num: 3
# 缓存持续时间(秒)
# 所有连接过的peer会记入缓存,DHCP服务会定期重新分配IP,缓存时间过长会导致误杀
cache-lifespan: 86400
# 是否追猎
# 如果某IP已判定为多拨,无视缓存时间限制继续搜寻其同伙
keep-hunting: true
# 追猎持续时间(秒)
# 和cache-lifspan作用相似,对被猎杀IP的缓存持续时间,keep-hunting为true时有效
keep-hunting-time: 2592000
```
</details>
## 添加下载器
PeerBanHelper 能够连接多个支持的下载器,并共享 IP 黑名单。但每个下载器只能被一个 PeerBanHelper 添加,多个 PBH 会导致操作 IP 黑名单时出现冲突。
Expand Down
6 changes: 0 additions & 6 deletions docker-entrypoint.sh

This file was deleted.

20 changes: 15 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

<groupId>com.ghostchu.peerbanhelper</groupId>
<artifactId>peerbanhelper</artifactId>
<version>3.3.7</version>
<version>3.4.0</version>

<name>PeerBanHelper</name>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.ghostchu.peerbanhelper.Main</mainClass>
<maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format>
Expand Down Expand Up @@ -47,7 +46,7 @@
<goal>shade</goal>
</goals>
<configuration>
<finalName>${name}</finalName>
<finalName>${project.name}</finalName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<minimizeJar>false</minimizeJar>
<createSourcesJar>false</createSourcesJar>
Expand Down Expand Up @@ -204,7 +203,9 @@
<goal>shade</goal>
</goals>
<configuration>
<finalName>${name}-SNAPSHOT-${maven.build.timestamp}-${git.commit.id.abbrev}</finalName>
<finalName>
${project.name}-SNAPSHOT-${maven.build.timestamp}-${git.commit.id.abbrev}
</finalName>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -310,6 +311,15 @@
<artifactId>flatlaf</artifactId>
<version>${flatlafVersion}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>


<!-- <dependency>-->
<!-- <groupId>com.formdev</groupId>-->
<!-- <artifactId>flatlaf-intellij-themes</artifactId>-->
Expand Down
2 changes: 1 addition & 1 deletion setup-webui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ current_wd=$(pwd)
cd "$(dirname $0)/src/main/resources"
rm -rf static
git clone --depth 1 --branch gh-pages "https://github.com/PBH-BTN/pbh-fe.git" static
echo "WebUI Version: $(git rev-parse --short HEAD)"
cd static && echo "WebUI Version: $(git rev-parse --short HEAD)"
cd $current_wd
25 changes: 15 additions & 10 deletions src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ private void registerModules() {
moduleManager.register(new PeerIdBlacklist(this, profile));
moduleManager.register(new ClientNameBlacklist(this, profile));
moduleManager.register(new ProgressCheatBlocker(this, profile));
moduleManager.register(new MultiDialingBlocker(this, profile));
//moduleManager.register(new ActiveProbing(this, profile));
moduleManager.register(new AutoRangeBan(this, profile));
moduleManager.register(new BtnNetworkOnline(this, profile));
Expand Down Expand Up @@ -523,18 +524,22 @@ public void banPeer(@NotNull PeerAddress peer, @NotNull BanMetadata banMetadata,
BAN_LIST.put(peer, banMetadata);
metrics.recordPeerBan(peer, banMetadata);
banListInvoker.forEach(i -> i.add(peer, banMetadata));
CompletableFuture.runAsync(() -> {
try {
InetAddress address = InetAddress.getByName(peer.getAddress().toString());
if (!address.getCanonicalHostName().equals(peer.getIp())) {
banMetadata.setReverseLookup(address.getCanonicalHostName());
} else {
if (mainConfig.getBoolean("lookup.dns-reverse-lookup")) {
CompletableFuture.runAsync(() -> {
try {
InetAddress address = InetAddress.getByName(peer.getAddress().toString());
if (!address.getCanonicalHostName().equals(peer.getIp())) {
banMetadata.setReverseLookup(address.getCanonicalHostName());
} else {
banMetadata.setReverseLookup("N/A");
}
} catch (UnknownHostException ignored) {
banMetadata.setReverseLookup("N/A");
}
} catch (UnknownHostException ignored) {
banMetadata.setReverseLookup("N/A");
}
}, generalExecutor);
}, generalExecutor);
} else {
banMetadata.setReverseLookup("N/A");
}
Main.getEventBus().post(new PeerBanEvent(peer, banMetadata, torrentObj, peerObj));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public MainConfigUpdateScript(YamlConfiguration conf) {
this.conf = conf;
}

@UpdateScript(version = 5)
public void optionForDnsReverseLookup() {
conf.set("lookup.dns-reverse-lookup", false);
}

@UpdateScript(version = 4)
public void defTurnOffIncrementBans() {
ConfigurationSection section = conf.getConfigurationSection("client");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public ProfileUpdateScript(YamlConfiguration conf) {
this.conf = conf;
}

@UpdateScript(version = 3)
public void multiDialingBlocker() {
conf.set("module.multi-dialing-blocker.enabled", false);
conf.set("module.multi-dialing-blocker.subnet-mask-length", 24);
conf.set("module.multi-dialing-blocker.subnet-mask-v6-length", 64);
conf.set("module.multi-dialing-blocker.tolerate-num", 3);
conf.set("module.multi-dialing-blocker.cache-lifespan", 86400);
conf.set("module.multi-dialing-blocker.keep-hunting", true);
conf.set("module.multi-dialing-blocker.keep-hunting-time", 2592000);
}

@UpdateScript(version = 2)
public void newRuleSyntax() {
List<String> peerId = conf.getStringList("module.peer-id-blacklist.exclude-peer-id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,10 @@ public String getMetadata(String key) throws SQLException {
}
}

public long queryBanLogsCount(Date from, Date to) throws SQLException {
public long queryBanLogsCount() throws SQLException {
try (Connection connection = manager.getConnection()) {
PreparedStatement ps;
if (from == null && to == null) {
ps = connection.prepareStatement("SELECT COUNT(*) AS count FROM ban_logs");
} else {
if (from == null || to == null) {
throw new IllegalArgumentException("from or null cannot be null if any provided");
} else {
ps = connection.prepareStatement("SELECT COUNT(*) AS count FROM ban_logs");
}
}
if (from != null) {
ps.setDate(1, from);
ps.setDate(2, to);
}
@Cleanup
ResultSet set = ps.executeQuery();
ResultSet set = connection.createStatement().executeQuery("SELECT COUNT(*) AS count FROM ban_logs");
return set.getLong("count");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ public void sync() {
private void onColorThemeChanged() {
OsThemeDetector detector = OsThemeDetector.getDetector();
boolean isDarkThemeUsed = detector.isDark();
try {
setColorTheme(Class.forName(UIManager.getSystemLookAndFeelClassName()));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
if (isDarkThemeUsed) {
setColorTheme(FlatDarculaLaf.class);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,14 @@ public void append(LogEvent event) {
{
for (JTextArea textArea : textAreas) {
try {
if (textArea != null) {
if (textArea.getText().isEmpty()) {
textArea.setText(message);
} else {
textArea.append("\n" + message);
if (maxLines > 0 & textArea.getLineCount() > maxLines + 1) {
int endIdx = textArea.getDocument().getText(0, textArea.getDocument().getLength()).indexOf("\n");
textArea.getDocument().remove(0, endIdx + 1);
}
}
String content = textArea.getText();
textArea.setText(content.substring(0, content.length() - 1));
textArea.append(message);
int linesToCut = (textArea.getLineCount() - maxLines) + (maxLines / 2);
linesToCut = Math.min(linesToCut, textArea.getLineCount());
if (linesToCut > 0) {
int posOfLastLineToTrunk = textArea.getLineEndOffset(linesToCut - 1);
textArea.replaceRange("", 0, posOfLastLineToTrunk);
}
textArea.setCaretPosition(textArea.getDocument().getLength());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
Expand Down
Loading

0 comments on commit 4257f8e

Please sign in to comment.