Skip to content

Commit 3b53718

Browse files
committed
v2.1 调整代码结构,支持native打包;clientId校验缺陷调整为用户名、密码校验
1 parent 4f0aff2 commit 3b53718

File tree

72 files changed

+1584
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1584
-222
lines changed

META-INF/native-image/.lock

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22916

common/pom.xml

-60
This file was deleted.

common/src/main/resources/log4j2.xml

-28
This file was deleted.

common/src/test/resources/log4j2.xml

-23
This file was deleted.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212

1313
<modules>
14-
<module>common</module>
1514
<module>run</module>
1615
<module>_localtest</module>
1716
<module>kafkademo</module>
1817
</modules>
1918

2019
<properties>
2120
<java.version>21</java.version>
21+
<native.maven.plugin.version>0.10.2</native.maven.plugin.version>
2222
<maven.compiler.source>${java.version}</maven.compiler.source>
2323
<maven.compiler.target>${java.version}</maven.compiler.target>
2424
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

readme.md

+74-17
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,31 @@ hppt,一款可通过任意协议转发tcp端口的工具。
1414
![hppt](_doc/img/1.jpg)
1515

1616
# 快速开始
17+
[releases](https://github.com/codingmiao/hppt/releases)
18+
页面下载最新版本编译好的hppt,或自行下载源码编译。
19+
```shell
20+
#jar
21+
mvn clean package -DskipTests
22+
23+
#可选操作 打native包
24+
su graalvm
25+
cd run
26+
mvn org.graalvm.buildtools:native-maven-plugin:build
27+
```
1728

18-
本项目需要jdk21启动,请先前往[jdk官网](https://jdk.java.net/21/)
19-
下载对应你操作系统版本的jdk,然后在[releases](https://github.com/codingmiao/hppt/releases)
20-
页面下载最新版本编译好的hppt.zip,或自行下载源码编译
29+
本项目编译成了可执行文件及jar包。
30+
31+
可执行文件无环境依赖、内存占用,小单因为没有jit支持,性能略逊于jar包执行;
32+
33+
jar包执行性能更好,但多消耗一些内存,如需jar包执行,请先前往[jdk官网](https://jdk.java.net/archive/)下载对应你操作系统版本的jdk21。
2134

2235
## 示例1 通过http端口,反向代理访问内部服务器SSH端口
2336

2437
假设你有一个服务器集群,仅有一个nginx提供了80/443端口对外访问(111.222.33.44:80),你想要访问集群中的应用服务器(192.168.0.2)的22端口,则可以按如下结构部署
2538

2639
![示例1](_doc/img/3.jpg)
2740

28-
1、在集群中任一服务器上新建一个hppt目录,并上传hppt.jar、ss.yml、log4j2.xml文件到此目录下:
41+
1、在集群中任一服务器上新建一个hppt目录,并上传hppt.jar(也可用可执行文件 hppt.ext 或 hppt)、ss.yml、log4j2.xml文件到此目录下:
2942

3043
```
3144
hppt
@@ -41,23 +54,43 @@ hppt
4154
type: post
4255
#服务http端口
4356
port: 20871
44-
# 允许的客户端id
45-
clientIds:
46-
- user1
47-
- user2
57+
# 允许的客户端账号和密码
58+
clients:
59+
- user: user1
60+
password: 12345
61+
- user: user2
62+
password: 112233
4863

4964
```
5065
(注1:作为快速演示,这里的type选择了最简单的post类型,此场景下最佳性能的协议为websocket,或是有独立端口的话可以配置hppt协议,ws、hppt版的说明奋力码字中。。)
5166

5267
(注2:实际应用中,为了确保安全,建议把clientId设置得更复杂一些)
5368

54-
执行如下命令运行服务端的hppt
69+
执行如下命令运行服务端的hppt(3选1)
5570

71+
jar包运行
5672
```shell
5773
cd hppt
5874
<jdk21_path>/bin/java -jar hppt.jar ss ss.yml
5975
```
6076

77+
windows下可执行文件运行
78+
```shell
79+
cd hppt
80+
chcp 65001
81+
title "hppt"
82+
hppt.exe ss ss.yml
83+
pause
84+
```
85+
86+
linux下可执行文件运行
87+
```shell
88+
cd hppt
89+
./hppt ss ss.yml
90+
#后台运行用命令 nohup ./hppt ss ss.yml >/dev/null &
91+
```
92+
93+
6194
在nginx上增加一段配置指向hppt
6295

6396
```
@@ -87,8 +120,10 @@ hppt
87120
```yaml
88121
# 和服务端的type保持一致
89122
type: post
90-
# 客户端id,必须在服务端的clientIds列表里才能成功连接,每个客户端用一个id,不要重复
91-
clientId: user1
123+
# 客户端用户名,每个sc进程用一个,不要重复
124+
clientUser: user1
125+
# 客户端密码
126+
clientPassword: 12345
92127

93128
post:
94129
# 服务端http地址,如无法直连,用nginx代理几次填nginx的地址也ok
@@ -108,13 +143,30 @@ forwards:
108143

109144
```
110145

111-
执行如下命令启动客户端的hppt
146+
执行如下命令启动客户端的hppt(3选1)
112147

148+
jar包运行
113149
```shell
114150
cd hppt
115151
<jdk21_path>/bin/java -jar hppt.jar sc sc.yml
116152
```
117153

154+
windows下可执行文件运行
155+
```shell
156+
cd hppt
157+
chcp 65001
158+
title "hppt"
159+
hppt.exe sc sc.yml
160+
pause
161+
```
162+
163+
linux下可执行文件运行
164+
```shell
165+
cd hppt
166+
./hppt sc sc.yml
167+
#后台运行用命令 nohup ./hppt ss ss.yml >/dev/null &
168+
```
169+
118170
随后,你就可以在公司用linux连接工具访问localhost的10022端口,来登录应用服务器了
119171

120172

@@ -138,8 +190,10 @@ hppt
138190
```yaml
139191
# 通讯协议 本示例使用了性能最好的hppt协议,加r前缀表示客户端和服务端角色互换。这里也可以配http post或websocket
140192
type: rhppt
141-
# 客户端id
142-
clientId: user1
193+
# 客户端用户名,每个sc进程用一个,不要重复
194+
clientUser: user1
195+
# 客户端密码
196+
clientPassword: 12345
143197

144198
# 服务端口
145199
rhppt:
@@ -185,9 +239,12 @@ rhppt:
185239
host: "111.222.33.44"
186240
port: 20871
187241

188-
# 对应的的客户端id
189-
clientIds:
190-
- user1
242+
# 允许的客户端账号和密码
243+
clients:
244+
- user: user1
245+
password: 12345
246+
- user: user2
247+
password: 112233
191248

192249
```
193250

run/pom.xml

+63-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,48 @@
1212
<artifactId>run</artifactId>
1313
<dependencies>
1414
<dependency>
15-
<groupId>org.wowtools.hppt</groupId>
16-
<artifactId>common</artifactId>
17-
<version>1.0-SNAPSHOT</version>
18-
<scope>compile</scope>
15+
<groupId>com.squareup.okhttp3</groupId>
16+
<artifactId>okhttp</artifactId>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.lz4</groupId>
20+
<artifactId>lz4-java</artifactId>
21+
<version>1.8.0</version>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.fasterxml.jackson.dataformat</groupId>
26+
<artifactId>jackson-dataformat-yaml</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.netty</groupId>
30+
<artifactId>netty-all</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.projectlombok</groupId>
34+
<artifactId>lombok</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>ch.qos.logback</groupId>
38+
<artifactId>logback-classic</artifactId>
39+
<version>1.4.11</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.google.protobuf</groupId>
43+
<artifactId>protobuf-java</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>com.fasterxml.jackson.core</groupId>
47+
<artifactId>jackson-databind</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.wowtools</groupId>
51+
<artifactId>catframe-common</artifactId>
1952
</dependency>
2053
<dependency>
2154
<groupId>org.eclipse.jetty.toolchain</groupId>
2255
<artifactId>jetty-jakarta-servlet-api</artifactId>
2356
<version>5.0.2</version>
24-
<scope>compile</scope>
2557
</dependency>
2658
<dependency>
2759
<groupId>org.eclipse.jetty</groupId>
@@ -83,7 +115,33 @@
83115
</execution>
84116
</executions>
85117
</plugin>
118+
<!-- 打native包 -->
119+
<plugin>
120+
<groupId>org.graalvm.buildtools</groupId>
121+
<artifactId>native-maven-plugin</artifactId>
122+
<version>${native.maven.plugin.version}</version>
123+
<configuration>
124+
<buildArgs>
125+
<arg>-H:+AddAllCharsets</arg>
126+
</buildArgs>
127+
<mainClass>org.wowtools.hppt.run.Run</mainClass>
128+
<imageName>hppt</imageName>
129+
</configuration>
130+
</plugin>
86131
</plugins>
87132
</build>
88133

134+
<pluginRepositories>
135+
<pluginRepository>
136+
<id>graalvm-native-build-tools-snapshots</id>
137+
<name>GraalVM native-build-tools Snapshots</name>
138+
<url>https://raw.githubusercontent.com/graalvm/native-build-tools/snapshots</url>
139+
<releases>
140+
<enabled>false</enabled>
141+
</releases>
142+
<snapshots>
143+
<enabled>true</enabled>
144+
</snapshots>
145+
</pluginRepository>
146+
</pluginRepositories>
89147
</project>

common/src/main/java/org/wowtools/hppt/common/util/BytesUtil.java renamed to run/src/main/java/org/wowtools/hppt/common/util/BytesUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private static boolean afterWrite(ChannelFuture future, Object msg) {
145145
}
146146

147147
private static void waitChannelWritable(Channel channel) {
148-
while (!channel.isWritable()) {
148+
while (!channel.isWritable() && channel.isOpen()) {
149149
try {
150150
Thread.sleep(200);
151151
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)