117 Commits

Author SHA1 Message Date
wujiawei
c34f1239d8 [fix] 修复native打包与mapper不兼容问题,切换至自定义bean拷贝 2025-06-10 09:26:40 +08:00
wujiawei
edaa4b84d7 Revert "[fix] 修复native打包与mapper不兼容问题,切换至自定义bean拷贝"
This reverts commit 6c6584fdb9.
2025-06-10 09:26:16 +08:00
wujiawei
6c6584fdb9 [fix] 修复native打包与mapper不兼容问题,切换至自定义bean拷贝 2025-06-09 16:41:24 +08:00
wujiawei
221623e9c0 [fix] 修复native打包与mapper不兼容问题,切换至自定义bean拷贝 2025-06-09 16:23:25 +08:00
wujiawei
ff150eb31c [fix] 修复native打包与mapper不兼容问题,切换至自定义bean拷贝 2025-06-09 16:19:55 +08:00
wujiawei
e1de673b52 [fix] 修复native打包与mapper不兼容问题,切换至自定义bean拷贝 2025-06-09 14:56:45 +08:00
wujiawei
01a2937414 [fix] 修复native打包与mapper不兼容问题,切换至自定义bean拷贝 2025-06-09 14:40:06 +08:00
wujiawei
e8383c78ad [fix] 添加代理流量监控 2025-06-07 11:13:34 +08:00
wujiawei
1a08fe64e9 [fix] 修改唯一索引问题 2025-06-07 01:31:43 +08:00
wujiawei
ca87968469 [fix] 修改唯一索引问题 2025-06-07 01:25:08 +08:00
wujiawei
903ba88787 [fix] 修改枚举问题 2025-06-07 00:36:20 +08:00
wujiawei
0505d6d201 [fix] 添加代理流量统计 2025-06-07 00:27:02 +08:00
wujiawei
556cb3fd1b [fix] 添加代理流量统计 2025-06-07 00:26:37 +08:00
wujiawei
ddb709c3a8 [fix] socks、http代理 添加流量计费 2025-06-06 23:13:01 +08:00
wujiawei
9cd85abe1d [fix] socks、http代理 添加流量计费 2025-06-06 23:01:52 +08:00
wujiawei
664bafdc86 Merge remote-tracking branch 'origin/master' 2025-06-06 22:14:20 +08:00
wujiawei
3b9379a7aa [fix] socks、http代理 添加流量计费 2025-06-06 21:25:31 +08:00
WJWJW
17306c348a fix 2025-06-04 15:58:15 +08:00
wujiawei
e518e20cc1 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-client-start/pom.xml
2025-06-03 13:42:24 +08:00
wujiawei
a27506299e [fix] 测试mapstruct 打包native异常问题 2025-06-03 13:41:54 +08:00
wujiawei
40de2dbe4d [fix] 2025-06-02 14:25:12 +08:00
wujiawei
06869dcd2f 【fix】 cgroup2fs环境 2025-05-31 18:49:33 +08:00
wujiawei
c9b866885a 【fix】 cgroup2fs环境 2025-05-31 18:36:34 +08:00
wujiawei
f496f12fe3 【fix】 cgroup2fs环境 2025-05-31 18:25:49 +08:00
wujiawei
6e6ce666b8 【fix】注释 <!-- <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
        <!--            <artifactId>spring-boot-starter-actuator</artifactId>-->
        <!--        </dependency>-->
        原因与服务器架构x86 飞牛os不兼容
2025-05-31 18:23:55 +08:00
WJWJW
f82e9e5f0a fix 2025-05-31 17:53:45 +08:00
wujiawei
26e4990f0a 【fix】注释 <!-- <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
        <!--            <artifactId>spring-boot-starter-actuator</artifactId>-->
        <!--        </dependency>-->
        原因与服务器架构x86 飞牛os不兼容
2025-05-31 17:50:26 +08:00
wujiawei
833e97a89d 【fix】 2025-05-30 16:51:00 +08:00
wujiawei
dab44fc1a2 【fix】 2025-05-27 11:04:18 +08:00
wujiawei
200a636379 【fix】 2025-05-27 09:58:14 +08:00
wujiawei
08b8e2dbb8 【fix】md 2025-05-26 10:58:40 +08:00
wujiawei
e7df027d65 【fix】md 2025-05-23 11:32:32 +08:00
wujiawei
071b844d68 【fix】md 2025-05-22 17:00:08 +08:00
wujiawei
afa4d5c360 【fix】添加流程图 2025-05-22 15:14:40 +08:00
wujiawei
c057d7b2d5 【fix】修复服务端socks代理客户端时断时续问题 2025-05-20 15:59:37 +08:00
wujiawei
7f9cebec8a 【fix】init route ip 2025-05-13 21:32:19 +08:00
wujiawei
32a641ce99 【fix】init route ip 2025-05-13 11:15:21 +08:00
wujiawei
a3c88ffa9f 【fix】init route ip 2025-05-08 12:34:55 +08:00
wujiawei
466faacb93 【fix】log 2025-05-08 11:43:48 +08:00
wujiawei
687770e086 【fix】log 2025-05-08 10:35:28 +08:00
wujiawei
32c757ef5e 【fix】error 2025-05-08 09:47:44 +08:00
wujiawei
68f4c92366 【fix】修改 * 端口问题 2025-05-08 09:09:09 +08:00
wujiawei
ad7fa61067 【fix】修改虚拟路由问题 2025-05-08 08:50:40 +08:00
wujiawei
fe3adeee03 【fix】添加 @Role(BeanDefinition.ROLE_INFRASTRUCTURE) 2025-05-07 17:47:23 +08:00
wujiawei
2e40988ef4 【fix】添加 @Role(BeanDefinition.ROLE_INFRASTRUCTURE) 2025-05-07 15:59:45 +08:00
wujiawei
5528ef6ebd 【fix】添加虚拟路由管理 2025-05-07 14:33:27 +08:00
wujiawei
9401c27572 【fix】添加虚拟路由管理 2025-05-07 12:13:20 +08:00
wujiawei
c852e3b351 【fix】添加虚拟路由管理 2025-05-07 12:04:40 +08:00
wujiawei
17b220a76a 【fix】添加虚拟路由管理 2025-05-07 11:27:14 +08:00
wujiawei
191e23fc83 【fix】添加虚拟路由管理 2025-05-07 11:13:56 +08:00
wujiawei
96929044fa 【fix】添加虚拟路由管理 2025-05-07 11:09:19 +08:00
wujiawei
965142793c 【fix】添加虚拟路由管理 2025-05-06 17:48:41 +08:00
wujiawei
9a44a598ef 【fix】添加虚拟路由管理 2025-05-06 17:27:35 +08:00
wujiawei
c2c350a28a 【fix】bug 2025-05-06 09:43:39 +08:00
wujiawei
8cc3b4858a 【fix】bug 2025-05-05 23:41:14 +08:00
wujiawei
3c32a5d157 【fix】客户端代理客户端 2025-05-05 23:20:54 +08:00
wujiawei
578429777a 【fix】客户端代理客户端 2025-05-05 23:12:04 +08:00
wujiawei
5eba201979 【fix】新增本地socks代理服务端 2025-05-05 21:47:04 +08:00
wujiawei
f8a9ca4264 【fix】新增本地socks代理服务端 2025-05-05 20:20:58 +08:00
wujiawei
7af14b4251 【fix】新增本地socks代理服务端 2025-05-04 13:35:09 +08:00
wujiawei
24fe9e4bc9 【fix】新增本地socks代理服务端 2025-05-03 23:34:28 +08:00
wujiawei
2adf5e4749 【fix】新增本地socks代理服务端 2025-05-03 22:39:41 +08:00
wujiawei
b7f099d3a4 【fix】新增本地socks代理服务端 2025-05-03 22:36:21 +08:00
wujiawei
f0fd22ccd4 【fix】1.3.1-JDK17-SNAPSHOT 2025-05-03 10:41:36 +08:00
wujiawei
7b26e9cb60 【fix】1.3.1-JDK17-SNAPSHOT 2025-05-03 10:40:46 +08:00
wujiawei
6e79901be3 【fix】修复无法启动问题 2025-04-30 18:53:36 +08:00
wujiawei
f88e0e2b7f 【fix】修复无法启动问题 2025-04-30 18:18:32 +08:00
wujiawei
9324b516fd 【fix】修复无法启动问题 2025-04-30 16:59:10 +08:00
wujiawei
a6c46c3cba 【fix】修复无法启动问题 2025-04-30 16:12:51 +08:00
wujiawei
66956636b9 【fix】修复无法启动问题 2025-04-30 16:08:53 +08:00
wujiawei
9dc36fe8e9 【fix】修复无法启动问题 2025-04-30 16:02:07 +08:00
wujiawei
f2a22c177e 【fix】 2025-04-30 15:19:56 +08:00
wujiawei
98587b442c 【fix】 添加socket5代理demo 2025-04-30 13:54:40 +08:00
wujiawei
e51ad201de 【fix】 优化代理 2025-04-29 09:15:59 +08:00
wujiawei
d8a8b630ae 【fix】 优化代理 2025-04-08 16:52:07 +08:00
wujiawei
e0f461460a 【fix】 优化代理 2025-04-08 16:43:29 +08:00
wujiawei
75acddadca 【fix】 优化代理 2025-04-08 16:41:14 +08:00
wujiawei
50e67f54e3 【fix】 so nice serve proxy client is easy 2025-04-08 12:52:30 +08:00
wujiawei
3444e90d3d 【fix】 so nice serve proxy client is easy 2025-04-07 21:50:05 +08:00
wujiawei
b1b329aae1 【fix】 bug fix 2025-04-06 23:03:12 +08:00
wujiawei
26283de998 【fix】 bug fix 2025-04-06 22:54:57 +08:00
wujiawei
9c5000f995 【fix】 bug fix 2025-04-06 22:43:01 +08:00
wujiawei
532d05d4a8 【fix】 bug fix 2025-04-06 22:24:01 +08:00
wujiawei
402f6f0ac1 【fix】 bug fix 2025-04-06 22:18:22 +08:00
wujiawei
a5a3d7d6f2 【fix】 bug fix 2025-04-06 21:59:48 +08:00
wujiawei
e4c33f34c1 【fix】 bug fix 2025-04-06 21:28:55 +08:00
wujiawei
394dfdf337 【fix】 bug fix 2025-04-06 21:27:22 +08:00
wujiawei
9b44a199be 【fix】 bug fix 2025-04-06 21:24:12 +08:00
wujiawei
fe8a2c865a 【fix】 添加客户端代理客户端 2025-04-06 18:52:31 +08:00
wujiawei
ba8ca7bcd9 【fix】 添加服务端、客户端路由管理接口 2025-04-06 01:26:21 +08:00
wujiawei
9a211ad200 【fix】 添加服务端、客户端路由管理接口 2025-04-06 01:07:35 +08:00
wujiawei
40ab82de35 【fix】 添加服务端、客户端路由管理接口 2025-04-06 00:43:04 +08:00
wujiawei
8728cd5d54 【fix】 添加服务端、客户端路由管理接口 2025-04-06 00:41:38 +08:00
wujiawei
3f7f10bcd5 【fix】 添加服务端、客户端路由管理接口 2025-04-05 21:05:57 +08:00
wujiawei
269a0f2ba2 【fix】 添加服务端、客户端路由管理接口 2025-04-05 18:01:26 +08:00
wujiawei
8f02c03d42 【fix】 添加服务端、客户端路由管理接口 2025-04-05 18:01:23 +08:00
wujiawei
9e1da9649e 【fix】 支持本地代理 2025-04-05 13:09:45 +08:00
wujiawei
074ab4f217 【fix】 ip is null 2025-04-03 11:32:07 +08:00
wujiawei
07e8b20449 【fix】 http代理顺利验证通过 2025-03-22 12:40:21 +08:00
wujiawei
2a98ec0589 【fix】 http代理顺利验证通过 2025-03-22 00:09:18 +08:00
wujiawei
3321e0dd7b 【fix】 添加协议解析处理 2025-03-21 20:57:44 +08:00
wujiawei
cf9438a7da 【fix】 域名解析正常 2025-03-14 21:07:42 +08:00
wujiawei
4690bc85b3 【fix】 add dns module; 2025-03-08 23:16:32 +08:00
wujiawei
2389a25e11 【fix】 优化使用 EventLoopGroup bossGroup = EventLoopGroupFactory.createBossGroup();
EventLoopGroup workerGroup = EventLoopGroupFactory.createWorkerGroup();
2025-02-18 17:21:00 +08:00
wujiawei
cf10347939 【fix】 控制mysql占用内存在150mb左右 2025-02-11 11:26:48 +08:00
wujiawei
98b4701978 This is a Kubernetes configuration file that defines several resources, including:
1. A Pod named `mysql` in the `default` namespace.
2. A Service named `mysql` in the `default` namespace that exposes the Pod's port 3306 and provides a persistent volume for the database data.
3. An Ingress resource that routes incoming requests to the `mysql` service.

The configuration also defines several environment variables, including:

1. `MYSQL_CNF`: a ConfigMap containing a MySQL configuration file (`cnf`) with various settings such as `sql_mode`, `log_timestamps`, and `slow_query_log`.

Here is an annotated version of the configuration:

**Pod:**
```yaml
apiVersion: v1
kind: Pod
metadata:
  name: mysql
spec:
  containers:
  - name: mysql
    image: your-mysql-image
    env:
    - name: MYSQL_CNF
      valueFrom:
        configMapKeyRef:
          name: mysql-cnf
          key: cnf
```
This Pod runs a container with the `your-mysql-image` and uses the `MYSQL_CNF` environment variable to set the MySQL configuration.

**Service:**
```yaml
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  selector:
    app: mysql
  ports:
  - name: mysql
    port: 3306
    targetPort: 3306
  persistentVolumeClaim:
    claimName: mysql-pvc
```
This Service exposes the `mysql` container's port 3306 and provides a persistent volume (`mysql-pvc`) for the database data.

**Ingress:**
```yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: mysql-ingress
spec:
  rules:
  - host: your-ingress-hostname.com
    http:
      paths:
      - path: /
        backend:
          serviceName: mysql
          servicePort: 3306
```
This Ingress resource routes incoming requests to the `mysql` Service's port 3306.

**ConfigMap:**
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-cnf
data:
  cnf: |
    [mysql]
    no-auto-rehash

    [mysqld]
    skip-host-cache
    skip-name-resolve
    max_connections=1000
    lower_case_table_names=0
    default-time-zone='+08:00'
    sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
    log_timestamps='SYSTEM'

    binlog_expire_logs_seconds = 2
    innodb_flush_log_at_trx_commit=2
    group_concat_max_len=1024
```
This ConfigMap contains the MySQL configuration file (`cnf`) with various settings and values.
2025-02-11 10:15:48 +08:00
wujiawei
7da5f58263 [fix] 修复客户端负载问题 2025-01-22 10:20:26 +08:00
wujiawei
a019561c06 [fix] 调整是否统计流量,避免网络问题导致流量缺口,数据丢失 2025-01-16 09:52:03 +08:00
wujiawei
f985cdac8f [fix] 修复数据存乎导致主线程问题 2025-01-09 17:26:12 +08:00
wujiawei
7429cff23a [fix] 版本调整 2025-01-03 13:55:41 +08:00
wujiawei
9fa3359569 [fix] 优化tcp、udp架构 test 2024-12-21 21:57:14 +08:00
wujiawei
fac28c4fc8 [fix] 优化tcp、udp架构 test 2024-12-17 15:14:09 +08:00
wujiawei
f9188037a0 [fix] 优化tcp、udp架构 test 2024-12-17 13:22:16 +08:00
wujiawei
f19b1cae68 [fix] 优化tcp、udp架构 2024-12-17 10:47:25 +08:00
wujiawei
0df0a42b2c [fix] 优化tcp、udp架构 2024-12-16 20:14:45 +08:00
wujiawei
2b3c7cb7c2 [fix] 优化tcp、udp架构 2024-12-16 18:59:02 +08:00
wujiawei
daeba59a43 [fix] 优化tcp、udp架构 2024-12-16 18:53:08 +08:00
931 changed files with 33289 additions and 4932 deletions

View File

@@ -7,15 +7,15 @@
#### 操作步骤拥有公网ip的服务器开发6001web、7001端口tcp然后执行命令启动服务端
```shell
docker run -d -it -p 6001:6001 -p 7001:7001 -e spring.profiles.active=prod -e MAIN_DB_HOST=localhost:3306 -e MAIN_DB_PASSWORD=root -e MAIN_DB_PASSWORD=root --name wu-lazy-cloud-heartbeat-server-start registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server-start:1.2.9-JDK17-SNAPSHOT
docker run -d -it -p 6001:6001 -p 7001:7001 -e spring.profiles.active=prod -e MAIN_DB_HOST=localhost:3306 -e MAIN_DB_PASSWORD=root -e MAIN_DB_PASSWORD=root --name wu-lazy-cloud-heartbeat-server-start registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server-start:1.3.1-JDK17-SNAPSHOT
```
#### 操作步骤:杭州本地机房所在网络服务器启动客户端、你老家所在网络中启动客户端,命令如下
```shell
docker run -d -it --privileged --name hangzhou-client --restart=always -e spring.lazy.netty.client.inet-host=公网IP -e spring.lazy.netty.client.inet-port=7001 -e spring.lazy.netty.client.client-id="hangzhou-jifang" registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.2.9-JDK17-SNAPSHOT
docker run -d -it --privileged --name hangzhou-client --restart=always -e spring.lazy.netty.client.inet-host=公网IP -e spring.lazy.netty.client.inet-port=7001 -e spring.lazy.netty.client.client-id="hangzhou-jifang" registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.1-JDK17-SNAPSHOT
```
```shell
docker run -d -it --privileged --name my-home-client --restart=always -e spring.lazy.netty.client.inet-host=公网IP -e spring.lazy.netty.client.inet-port=7001 -e spring.lazy.netty.client.client-id="my-home" registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.2.9-JDK17-SNAPSHOT
docker run -d -it --privileged --name my-home-client --restart=always -e spring.lazy.netty.client.inet-host=公网IP -e spring.lazy.netty.client.inet-port=7001 -e spring.lazy.netty.client.client-id="my-home" registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.1-JDK17-SNAPSHOT
```
#### 操作步骤:配置端口
![client_permeate_port_pool.png](client_permeate_port_pool.png)

View File

@@ -3,7 +3,7 @@
#### 模块说明
| 模块 | 所属层级 | 描述 | 端口 |
|------------------------------------------------------------------------------------|------|------------------------|----------------------------------------------------------------|
|------------------------------------------------------------------|------|------------------------|----------------------------------------------------------------|
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 基础模块 | 基于Netty数据解码、编码、通道处理器声明 | 无 |
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 启动模块 | 内网穿透服务端 | http端口6001、tcp端口:7001 (默认tcp端口=http端口+1000 如6001+1000=7001) |
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 启动模块 | 内网穿透客户端 | 6004 |

61
LazyDNS.puml Normal file
View File

@@ -0,0 +1,61 @@
@startuml
title 动态DNS
actor 访客 as User
package "服务端(公网)" as dns_server_{
component [服务端私有网络A]{
[mysql:(172.1.1.4:3306)] as dns_server_remote_local_
[clickhouse:(172.1.1.5:3306)]
}
component [服务端私有网络B]{
[mysql:(172.1.2.4:3306)]
[clickhouse:(172.1.2.5:3306)]
}
}
package "客户端(私有网络)" as dns_remote_local_{
component [客户端私有网络A]{
[mysql:(162.1.1.4:3306)] as dns_client_remote_local_
[clickhouse:(162.1.1.5:3306)]
}
component [客户端私有网络B]{
[mysql:(162.1.2.4:3306)]
[clickhouse:(162.1.2.5:3306)]
}
}
package "客户端(用户本地)" as dns_local_ {
}
note "用户本地网络" as local_net_
note "服务端网络" as server_net_
note "客户端私有网络" as remote_net_
'(User) .... local_condition_
'local_condition_ ... (target)
[User] ...right...> dns_local_: DNS连接到本地
dns_local_ ...right...> local_net_: 访问本地网络本地DNS
dns_local_ ...up...> dns_server_remote_local_: 远程DNS解析
dns_server_ ...up...> server_net_: server本地的网络
dns_server_ ...down...> dns_remote_local_: 访问的地址在远程的客户端中
dns_remote_local_ ...down...> dns_client_remote_local_: 远程客户端所在的私有网络
dns_remote_local_ ...down...> remote_net_: 远程客户端中的其他网络
@enduml

BIN
Proxies_Config_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 KiB

BIN
Proxies_Config_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 KiB

BIN
Proxies_Config_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 KiB

BIN
Proxies_Config_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 KiB

BIN
Proxifier3.8.0.dmg Normal file

Binary file not shown.

33
Proxy.md Normal file
View File

@@ -0,0 +1,33 @@
### 使用手册
#### Mac 使用方式
##### 获取socks或者http代理服务器信息
ip127.0.0.1 port9001socks、8001http
##### 使用Wi-Fi代理
注意如下方式只能代理浏览器请求,无法代理其他应用请求
![mac_http_proxy.png](mac_http_proxy.png)
![mac_socks_proxy.png](mac_socks_proxy.png)
##### 使用第三方软件全局代理[Proxifier3.8.0.dmg](Proxifier3.8.0.dmg)
注册码
# Proxifier Mac
cracked@macked.app
8TB85-UWT64-AKK2R-XGBDY-F2UP5
# Proxifier Standard Edition
cracked@macked.app
4JB8X-9YMEZ-BD332-PPNN3-46P48
# Proxifier Portable Edition
cracked@macked.app
FXBZZ-U2FPK-G5KW9-KAANW-TLGPL
- Proxifier配置
![Proxies_Config_1.png](Proxies_Config_1.png)
- 配置socks服务器地址
![Proxies_Config_2.png](Proxies_Config_2.png)
![Proxies_Config_3.png](Proxies_Config_3.png)
- 配置代理路由
![Proxies_Config_4.png](Proxies_Config_4.png)
- 展示效果
![proxy_inner_net_ui.png](proxy_inner_net_ui.png)
#### Windows 使用方式
##### 使用Wi-Fi代理
![windows_wifi_proxy.png](windows_wifi_proxy.png)

236
README.md
View File

@@ -33,7 +33,7 @@
wu-lazy-cloud-network
是一款基于([wu-framework-parent](https://gitee.com/wujiawei1207537021/wu-framework-parent)孵化出的项目内部使用Lazy
ORM操作数据库使用环境JDK17 Spring Boot 3.0.2。
ORM操作数据库使用环境JDK17 Spring Boot 3.0.2。的网络穿透、渗透工具支持Tcp、Http、Socks
主要功能:
- 服务端渗透客户端网络穿透对于没有公网IP的服务进行公网IP映射
- ![NetworkPermeateServerPermeateClient.png](NetworkPermeateServerPermeateClient.png)
@@ -43,10 +43,22 @@ ORM操作数据库使用环境JDK17 Spring Boot 3.0.2。
- ![NetworkPermeateClientPermeateServer.png](NetworkPermeateClientPermeateServer.png)
- 客户端渗透客户端----本地端口映射到另一个局域网端口
- ![NetworkPermeateClientPermeateClient.png](NetworkPermeateClientPermeateClient.png)
- 客户端代理服务端、客户端代理客户端、服务端代理服务端、服务端代理客户端VPN----异地组网搭建代理
- ![wlcn-proxy1.0-.png](wlcn-proxy1.0-.png)
[UI](https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network-server-ui)
### 内网穿透
| 模块 | 所属层级 | 描述 | 快照版本 | 发布版本 |
|--------------------------------------|------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| wu-lazy-cloud-heartbeat-common | 组件 | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-common%20wu-bionic-parent"><img src="https://img.shields.io/nexus/s/top.wu2020/wu-bionic-parent?server=https%3A%2F%2Foss.sonatype.org&style=flat&logo=log" alt="Maven" /></a> | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-common%20wu-lazy-cloud-heartbeat-common"><img src="https://img.shields.io/maven-central/v/top.wu2020/wu-lazy-cloud-heartbeat-common" alt="Maven" /></a> |
| wu-lazy-cloud-heartbeat-client | 组件 | 客户端(支持二次开发) | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-client%20wu-lazy-cloud-heartbeat-client"><img src="https://img.shields.io/nexus/s/top.wu2020/wu-lazy-cloud-heartbeat-client?server=https%3A%2F%2Foss.sonatype.org&style=flat&logo=log" alt="Maven" /></a> | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-client%20wu-lazy-cloud-heartbeat-client"><img src="https://img.shields.io/maven-central/v/top.wu2020/wu-lazy-cloud-heartbeat-client" alt="Maven" /></a> |
| wu-lazy-cloud-heartbeat-server | 组件 | 服务端(支持二次开发) | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-server%20wu-lazy-cloud-heartbeat-server"><img src="https://img.shields.io/nexus/s/top.wu2020/wu-lazy-cloud-heartbeat-server?server=https%3A%2F%2Foss.sonatype.org&style=flat&logo=log" alt="Maven" /></a> | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-server%20wu-lazy-cloud-heartbeat-server"><img src="https://img.shields.io/maven-central/v/top.wu2020/wu-lazy-cloud-heartbeat-server" alt="Maven" /></a> |
| wu-lazy-cloud-ui | ui | 服务端页面 | | |
| wu-lazy-cloud-heartbeat-client-start | 客户端 | 客户端 | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-client-start%20wu-lazy-cloud-heartbeat-client-start"><img src="https://img.shields.io/nexus/s/top.wu2020/wu-lazy-cloud-heartbeat-client-start?server=https%3A%2F%2Foss.sonatype.org&style=flat&logo=log" alt="Maven" /></a> | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-client-start%20wu-lazy-cloud-heartbeat-client-start"><img src="https://img.shields.io/maven-central/v/top.wu2020/wu-lazy-cloud-heartbeat-client-start" alt="Maven" /></a> |
| wu-lazy-cloud-heartbeat-server-start | 服务端 | 服务端 | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-server-start%20wu-lazy-cloud-heartbeat-server-start"><img src="https://img.shields.io/nexus/s/top.wu2020/wu-lazy-cloud-heartbeat-server-start?server=https%3A%2F%2Foss.sonatype.org&style=flat&logo=log" alt="Maven" /></a> | <a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-heartbeat-server-start%20wu-lazy-cloud-heartbeat-server-start"><img src="https://img.shields.io/maven-central/v/top.wu2020/wu-lazy-cloud-heartbeat-server-start" alt="Maven" /></a> |
#### 项目地址
[Gitee](https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network)
@@ -57,191 +69,6 @@ ORM操作数据库使用环境JDK17 Spring Boot 3.0.2。
![architecture.png](architecture.png)
#### 实现原理
##### 服务端创建socket服务端绑定本地端口用于客户端连接
```java
package org.framework.lazy.cloud.network.heartbeat.server.netty.socket;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import filter.netty.org.framework.lazy.cloud.network.heartbeat.server.NettyServerFilter;
public class NettyOnCloudNettyServerSocket {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
private final NettyServerFilter nettyServerFilter;// 通道业务处理
private ChannelFuture channelFuture;
public NettyOnCloudNettyServerSocket(NettyServerFilter nettyServerFilter) {
this.nettyServerFilter = nettyServerFilter;
}
/**
* 启动服务端
*
* @throws Exception
*/
public void startServer(int serverPort) throws Exception {
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
// 给服务端channel设置属性
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(nettyServerFilter)
;
channelFuture = b.bind(serverPort).sync();
channelFuture.addListener((ChannelFutureListener) channelFuture -> {
// 服务器已启动
});
channelFuture.channel().closeFuture().sync();
} finally {
shutdown();
// 服务器已关闭
}
}
public void shutdown() {
if (channelFuture != null) {
channelFuture.channel().close().syncUninterruptibly();
}
if ((bossGroup != null) && (!bossGroup.isShutdown())) {
bossGroup.shutdownGracefully();
}
if ((workerGroup != null) && (!workerGroup.isShutdown())) {
workerGroup.shutdownGracefully();
}
}
}
```
##### 客户端通过class NettyClientSocket 连接服务端
```java
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.application.ClientChangeEvent;
import filter.netty.org.framework.lazy.cloud.heartbeat.client.NettyClientFilter;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import adapter.org.framework.lazy.cloud.network.heartbeat.common.ChannelTypeAdapter;
import advanced.org.framework.lazy.cloud.network.heartbeat.common.HandleChannelTypeAdvanced;
import utils.org.framework.lazy.cloud.network.heartbeat.common.ChannelAttributeKeyUtils;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 客户端连接服务端
*/
@Slf4j
public class NettyClientSocket {
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/**
* 服务端host
*/
private final String inetHost;
/**
* 服务端端口
*/
private final int inetPort;
/**
* 当前客户端id
*/
@Getter
private final String clientId;
/**
* nacos配置信息处理应用
*/
@Getter
private final ClientNettyConfigApplication clientChangeEvent;
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
public NettyClientSocket(String inetHost, int inetPort, String clientId, ClientNettyConfigApplication clientChangeEvent, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.inetHost = inetHost;
this.inetPort = inetPort;
this.clientId = clientId;
this.clientChangeEvent = clientChangeEvent;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
public void newConnect2Server() throws InterruptedException {
newConnect2Server(inetHost, inetPort, clientId, clientChangeEvent);
}
protected void newConnect2Server(String inetHost, int inetPort, String clientId, ClientNettyConfigApplication clientChangeEvent) throws InterruptedException {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup)
.channel(NioSocketChannel.class)
.handler(new NettyClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this))
;
log.info("连接服务端IP:{},连接服务端端口:{}", inetHost, inetPort);
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
Channel channel = future.channel();
log.info("使用的客户端ID:" + clientId);
future.addListener((ChannelFutureListener) futureListener -> {
if (futureListener.isSuccess()) {
log.info("连接服务端成功");
// 告诉服务端这条连接是client的连接
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setClientId(clientId);
nettyMsg.setData((clientId).getBytes());
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
channel.writeAndFlush(nettyMsg);
// 在线
clientChangeEvent.clientOnLine(clientId);
} else {
log.info("每隔2s重连....");
// 离线
clientChangeEvent.clientOffLine(clientId);
futureListener.channel().eventLoop().schedule(() -> {
try {
newConnect2Server(inetHost, inetPort, clientId, clientChangeEvent);
} catch (InterruptedException e) {
e.printStackTrace();
}
}, 2, TimeUnit.SECONDS);
}
});
}
/**
* 关闭连接
*/
public void shutdown() {
if ((eventLoopGroup != null) && (!eventLoopGroup.isShutdown())) {
eventLoopGroup.shutdownGracefully();
}
}
}
```
##### 通过客户端与服务端建立的连接进行访客端口绑定
@@ -255,26 +82,27 @@ public class NettyClientSocket {
1.内网穿透
2.服务端自主下发数据到客户端
3.流量监控
4.网络代理socks、http
### 项目结构
| 模块 | 版本 | 描述 |
|------------------------------------------------------------------------------------------------------------|----------------------|------------------------------|
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 1.2.9-JDK17-SNAPSHOT | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) |
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 1.2.9-JDK17-SNAPSHOT | 客户端(支持二次开发) |
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 1.2.9-JDK17-SNAPSHOT | 服务端(支持二次开发) |
| [wu-lazy-cloud-heartbeat-client-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-server-start) | 1.2.9-JDK17-SNAPSHOT | 客户端样例 |
| [wu-lazy-cloud-heartbeat-server-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-client-start) | 1.2.9-JDK17-SNAPSHOT | 服务端样例 |
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 1.3.1-JDK17-SNAPSHOT | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) |
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 1.3.1-JDK17-SNAPSHOT | 客户端(支持二次开发) |
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 1.3.1-JDK17-SNAPSHOT | 服务端(支持二次开发) |
| [wu-lazy-cloud-heartbeat-client-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-server-start) | 1.3.1-JDK17-SNAPSHOT | 客户端样例 |
| [wu-lazy-cloud-heartbeat-server-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-client-start) | 1.3.1-JDK17-SNAPSHOT | 服务端样例 |
### 使用技术
| 框架 | 版本 | 描述 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|--------------|
| spring-boot | 3.0.7 | springboot框架 |
| [wu-framework-web](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-framework-web) | 1.2.9-JDK17-SNAPSHOT | web容器 |
| [Lazy -ORM](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-inner-intergration/wu-database-parent) | 1.2.9-JDK17-SNAPSHOT | ORM |
| [wu-framework-web](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-framework-web) | 1.3.1-JDK17-SNAPSHOT | web容器 |
| [Lazy -ORM](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-inner-intergration/wu-database-parent) | 1.3.1-JDK17-SNAPSHOT | ORM |
| mysql-connector-j | 8.0.33 | mysql驱动 |
| [wu-authorization-server-platform-starter](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-smart-platform/wu-authorization-server-platform-starter) | 1.2.9-JDK17-SNAPSHOT | 用户授权体系 |
| [wu-authorization-server-platform-starter](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-smart-platform/wu-authorization-server-platform-starter) | 1.3.1-JDK17-SNAPSHOT | 用户授权体系 |
### 使用环境
@@ -283,15 +111,16 @@ public class NettyClientSocket {
JAVA >=13
MAVEN
### 启动
### 启动[install.md](install.md)
docker启动
docker run -d -it -p 18080:18080 --name wu-lazy-cloud-heartbeat-server registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.2.9-JDK17-SNAPSHOT
docker run -d -it -p 18080:18080 --name wu-lazy-cloud-heartbeat-server registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.3.1-JDK17-SNAPSHOT
http://127.0.0.1:18080/swagger-ui/index.html
源码启动
### 代理工具使用[Proxy.md](Proxy.md)
#### 页面操作
@@ -342,3 +171,16 @@ public class NettyClientSocket {
客户端近七天使用流量
![clientPortPerDayFlow.png](clientPortPerDayFlow.png)
## 路由
- 客户端路由管理
![client_route.png](client_route.png)
- 客户端虚拟路由管理
- 创建一个虚拟的不存在的IP代理到指定的IP
![client_virtual_route.png](client_virtual_route.png)
- 服务端路由管理
![server_route.png](server_route.png)
- 服务端虚拟路由管理
- 创建一个虚拟的不存在的IP代理到指定的IP
![server_virtual_route.png](server_virtual_route.png)

489
client-k8s.yaml Normal file
View File

@@ -0,0 +1,489 @@
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: wu-lazy-cloud-heartbeat-local-client-start
namespace: default
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
annotations:
k8s.kuboard.cn/displayName: 内网穿透服务端(云下)
spec:
replicas: 1
selector:
matchLabels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
template:
metadata:
creationTimestamp: null
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
annotations:
kubectl.kubernetes.io/restartedAt: '2025-01-16T22:39:39+08:00'
spec:
containers:
- name: wu-lazy-cloud-heartbeat-local-client-start
image: >-
registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.1-JDK17-SNAPSHOT
env:
- name: spring.lazy.netty.client.inet-host
value: 124.222.48.62
- name: spring.lazy.netty.client.inet-port
value: '30560'
- name: spring.lazy.netty.client.client-id
value: tencent
- name: JAVA_OPTS
value: '-Xms32m -Xmx64m'
- name: logging1.level.root
value: DEBUG
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
securityContext:
privileged: true
runAsUser: 0
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: cloud-mysql
namespace: default
labels:
k8s.eip.work/layer: db
k8s.eip.work/name: cloud-mysql
k8s.kuboard.cn/name: cloud-mysql
annotations:
analysis.crane.io/replicas-recommendation: |
replicas: 1
analysis.crane.io/resource-recommendation: |
containers:
- containerName: mysql
target:
cpu: 229m
memory: 2070Mi
k8s.eip.work/displayName: 数据库
k8s.eip.work/ingress: 'false'
k8s.eip.work/service: NodePort
k8s.eip.work/workload: cloud-mysql
k8s.kuboard.cn/workload: cloud-mysql
spec:
replicas: 0
selector:
matchLabels:
k8s.eip.work/layer: db
k8s.eip.work/name: cloud-mysql
k8s.kuboard.cn/name: cloud-mysql
template:
metadata:
creationTimestamp: null
labels:
k8s.eip.work/layer: db
k8s.eip.work/name: cloud-mysql
k8s.kuboard.cn/name: cloud-mysql
annotations:
kubectl.kubernetes.io/restartedAt: '2023-10-07T09:38:51+08:00'
spec:
volumes:
- name: mysql-cnf-map
configMap:
name: mysql-cnf
items:
- key: cnf
path: custom.cnf
defaultMode: 420
- name: tz
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
type: File
containers:
- name: mysql
image: 'mysql:8.0.28'
env:
- name: MYSQL_ROOT_PASSWORD
value: wujiawei
resources:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 500m
memory: 256Mi
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
- name: mysql-cnf-map
mountPath: /etc/mysql/conf.d/custom.cnf
subPath: custom.cnf
- name: tz
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
volumeClaimTemplates:
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql-data
creationTimestamp: null
annotations:
k8s.eip.work/pvcType: Dynamic
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: nfs-storage
volumeMode: Filesystem
status:
phase: Pending
serviceName: cloud-mysql
podManagementPolicy: OrderedReady
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 0
revisionHistoryLimit: 10
persistentVolumeClaimRetentionPolicy:
whenDeleted: Retain
whenScaled: Retain
---
kind: Service
apiVersion: v1
metadata:
name: cloud-mysql
namespace: default
labels:
k8s.eip.work/layer: db
k8s.eip.work/name: cloud-mysql
k8s.kuboard.cn/name: cloud-mysql
spec:
ports:
- name: zmac2s
protocol: TCP
port: 3306
targetPort: 3306
nodePort: 30512
selector:
k8s.eip.work/layer: db
k8s.eip.work/name: cloud-mysql
type: NodePort
sessionAffinity: None
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
---
kind: Service
apiVersion: v1
metadata:
name: wu-lazy-cloud-heartbeat-local-client-start
namespace: default
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
spec:
ports:
- name: net
protocol: TCP
port: 6001
targetPort: 6001
- name: nas
protocol: TCP
port: 100
targetPort: 100
- name: kuboard
protocol: TCP
port: 101
targetPort: 101
- name: netty-client
protocol: TCP
port: 6004
targetPort: 6004
- name: nas-web-dav
protocol: TCP
port: 102
targetPort: 102
- name: rustdesk
protocol: TCP
port: 103
targetPort: 103
- name: nastool
protocol: TCP
port: 104
targetPort: 104
- name: jellyfin
protocol: TCP
port: 105
targetPort: 105
- name: qb
protocol: TCP
port: 106
targetPort: 106
- name: jackett
protocol: TCP
port: 107
targetPort: 107
- name: rustdesk-tcp
protocol: TCP
port: 108
targetPort: 108
- name: rustdesk-ip-tcp
protocol: TCP
port: 109
targetPort: 109
- name: rustdesk-ip-udp
protocol: UDP
port: 109
targetPort: 109
- name: nas-ssh
protocol: TCP
port: 110
targetPort: 110
selector:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: wu-lazy-cloud-heartbeat-local-client-start
namespace: default
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
spec:
ingressClassName: traefik
rules:
- host: net.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 6001
- host: nas.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 100
- host: kuboard.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 101
- host: client.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 6004
- host: nas-dav.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 102
- host: rustdesk.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 103
- host: nastool.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 104
- host: jellyfin.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 105
- host: qb.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 106
- host: jackett.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 107
- host: rustdesk-tcp.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 108
- host: rustdesk-ip.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 109
- host: nas-ssh.wu-framework.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wu-lazy-cloud-heartbeat-local-client-start
port:
number: 110
---
kind: ConfigMap
apiVersion: v1
metadata:
name: mysql-cnf
namespace: default
data:
cnf: >-
[mysql]
no-auto-rehash
[mysqld]
skip-host-cache
skip-name-resolve
max_connections=100
lower_case_table_names=0
table_open_cache=64
default-time-zone='+08:00'
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
log_timestamps='SYSTEM'
performance_schema_max_table_instances=400 #设置效果不明显
performance_schema=off #效果明显
table_definition_cache=400
slow_query_log=ON
binlog_expire_logs_seconds = 2
innodb_flush_log_at_trx_commit=2
group_concat_max_len=512
# 全局参数
innodb_buffer_pool_size = 20M
innodb_buffer_pool_chunk_size=20M #效果不明显
key_buffer_size = 1M
# 排序和连接参数
sort_buffer_size = 256K
join_buffer_size = 256K
# 线程缓存参数
thread_cache_size = 4
# 日志参数
innodb_log_file_size = 5M
innodb_log_buffer_size = 1M

BIN
client_route.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

BIN
client_virtual_route.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

28
install.md Normal file
View File

@@ -0,0 +1,28 @@
#### docker环境安装wlcn
##### 启动服务端
- 6001端口 webui
- 7001端口 tcp连接端口
- 8001端口 http代理端口
- 9001端口 socks代理端口
- 1001端口 自定义需要代理到客户端端口
- 打开浏览器访问界面 http://127.0.0.1:6001/netty-server-ui/index.html
```shell
docker run -d -it -p 6001:6001 -p 7001:7001 -p 8001:8001 -p 9001:9001 --name wlcn-s registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.3.1-JDK17-SNAPSHOT
```
##### 启动客户端
- 6004端口 webui
- 8001端口 http代理端口
- 9001端口 socks代理端口
- 环境变量
- spring.lazy.netty.client.inet-host 服务端IP
- spring.lazy.netty.client.inet-port 服务端tcp端口
- spring.lazy.netty.client.client-id 客户端ID
- 打开浏览器访问界面 http://127.0.0.1:6004/netty-client-local-ui/index.html
```shell
docker run -d -it --privileged -p 6004:6004 --name wlcn-c --restart=always -e spring.lazy.netty.client.inet-host=192.168.xx.xx -e spring.lazy.netty.client.inet-port=7001 -e spring.lazy.netty.client.client-id="wlcn-c" registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.1-JDK17-SNAPSHOT
```

BIN
mac_http_proxy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
mac_socks_proxy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

12
pom.xml
View File

@@ -8,12 +8,12 @@
<parent>
<artifactId>wu-framework-parent</artifactId>
<groupId>top.wu2020</groupId>
<version>1.2.9-JDK17-SNAPSHOT</version>
<version>1.3.1-JDK17-SNAPSHOT</version>
</parent>
<artifactId>wu-lazy-cloud-network</artifactId>
<packaging>pom</packaging>
<version>1.2.9-JDK17-SNAPSHOT</version>
<version>1.3.1-JDK17-SNAPSHOT</version>
<description>云上云下</description>
@@ -23,6 +23,8 @@
<module>wu-lazy-cloud-heartbeat-server-cluster</module>
<module>wu-lazy-cloud-heartbeat-client</module>
<module>wu-lazy-cloud-heartbeat-common</module>
<module>wu-lazy-cloud-heartbeat-dns</module>
<module>wu-lazy-cloud-heartbeat-protocol-proxy</module>
<!-- 样例 -->
<module>wu-lazy-cloud-heartbeat-start</module>
@@ -46,12 +48,12 @@
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.6.0.Beta1</version>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.6.0.Beta1</version>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -70,7 +72,7 @@
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-framework-dependencies</artifactId>
<version>1.2.9-JDK17-SNAPSHOT</version>
<version>1.3.1-JDK17-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>

BIN
proxy_inner_net_ui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
server_route.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

BIN
server_virtual_route.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

View File

@@ -30,4 +30,10 @@
[change] 修复通道关闭导致调度线程池submit异常问题
[change] 添加记录客户端IP
[change] 1.2.9为大版本,报文中添加数据无法向下兼容,建议服务端与客户端保持版本一致
#### 下一版本计划https
#### 1.3.1-JDK17-SNAPSHOT
[add] 新增http代理客户端代理服务端、客户端代理客户杜安、服务端代理客户端、服务端代理服务端
[add] 新增socks代理客户端代理服务端、客户端代理客户杜安、服务端代理客户端、服务端代理服务端
[add] 新增客户端路由管理、新增服务端路由管理
[add] 支持新增虚拟IP代理到指定的IP
[add] 通过页面配置,代理支持控制端口代理控制
#### 下一版本计划

BIN
windows_wifi_proxy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

BIN
wlcn-proxy1.0-.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

84
wlcn-proxy1.0.puml Normal file
View File

@@ -0,0 +1,84 @@
@startuml
title 网络代理
package "服务端" as "服务端"{
node "12.16.5.xx"{
[12.16.5.1]
[wlcn_s_a] as "wlcn服务端"
}
}
package "杭州客户端"{
node "172.16.5.xx"{
[172.16.5.1]
[wlcn_c_a] as "wlcn客户端9001"
actor Navicat_c_a as "本地Navicat"
actor App_c_a as "本地App"
actor Chrome_c_a as "本地浏览器"
[socks_proxy_a] as "杭州本地用户socks代理软件"
[socks_proxy_a]<--up--> [wlcn_c_a]:访客通过软件代理本地socks网络
[Navicat_c_a]<..up..> [socks_proxy_a]:访问服务端所在网段12.16.5.xx
[App_c_a]<..up..> [socks_proxy_a]:访问访问本地所在网段172.16.5.xx
[Chrome_c_a]<..up..> [socks_proxy_a]:访问访问另一个客户端所在网段162.16.5.xx
}
}
package "上海客户端" as "上海客户端"{
node "162.16.5.xx"{
[162.16.5.1]
[wlcn_c_b] as "wlcn客户端9001"
actor Navicat_c_b as "本地Navicat"
actor App_c_b as "本地App"
actor Chrome_c_b as "本地浏览器"
[socks_proxy_b] as "上海本地用户socks代理软件"
[socks_proxy_b]<--up--> [wlcn_c_b]:访客通过软件代理本地socks网络
[Navicat_c_b]<..up..> [socks_proxy_b]:访问服务端所在网段12.16.5.xx
[App_c_b]<..up..> [socks_proxy_b]:访问访问本地所在网段172.16.5.xx
[Chrome_c_b]<..up..> [socks_proxy_b]:访问访问另一个客户端所在网段162.16.5.xx
}
}
package "第三方局域网"{
node "152.16.5.xx"{
[152.16.5.1]
actor Navicat_c_c as "本地Navicat"
actor App_c_c as "本地App"
actor Chrome_c_c as "本地浏览器"
[socks_proxy_c] as "上海本地用户socks代理软件"
[Navicat_c_c]<..up..> [socks_proxy_c]:访问服务端所在网段12.16.5.xx
[App_c_c]<..up..> [socks_proxy_c]:访问访问上海在网段172.16.5.xx
[Chrome_c_c]<..up..> [socks_proxy_c]:访问访问杭州客户端所在网段162.16.5.xx
}
}
[wlcn_s_a] <==down==> [wlcn_c_a]: 客户端连接服务端
[wlcn_s_a] <==down==> [wlcn_c_b]: 客户端连接服务端
[wlcn_s_a]<--down--> [socks_proxy_c]:访客通过软件代理本地socks网络
@enduml

View File

@@ -10,8 +10,8 @@ mvn native:build -Pnative
### 构建docker镜像
```shell
docker build -t docker-registry.wujiawei.com/lazy/lazy-under-cloud-heartbeat-client:lazy-2.4.2-native-SNAPSHOT_latest -f Native-Dockerfile .
docker push docker-registry.wujiawei.com/lazy/lazy-under-cloud-heartbeat-client:lazy-2.4.2-native-SNAPSHOT_latest
docker build -t docker-registry.wujiawei.com/lazy/lazy-under-cloud-heartbeat-client:lazy-2.4.2-NATIVE-SNAPSHOT_latest -f Native-Dockerfile .
docker push docker-registry.wujiawei.com/lazy/lazy-under-cloud-heartbeat-client:lazy-2.4.2-NATIVE-SNAPSHOT_latest
```
## BUILD IMAGE

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-network</artifactId>
<version>1.2.9-JDK17-SNAPSHOT</version>
<version>1.3.1-JDK17-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -23,15 +23,16 @@
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-common</artifactId>
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-protocol-proxy</artifactId>
<version>1.3.1-JDK17-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.50</version>
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-framework-web-spring-starter</artifactId>
</dependency>
<!-- h2数据库驱动 -->
<dependency>
@@ -40,7 +41,11 @@
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-plus-starter</artifactId>
<artifactId>wu-framework-web-spring-starter</artifactId>
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-orm-plus-starter</artifactId>
</dependency>
</dependencies>

View File

@@ -5,5 +5,5 @@ import org.wu.framework.lazy.orm.core.stereotype.LazyScan;
@ComponentScan(basePackages = "org.framework.lazy.cloud.network.heartbeat.client")
@LazyScan(scanBasePackages = "org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity")
public class EnableHeartbeatClientAutoConfiguration {
public class EnableClientAutoConfiguration {
}

View File

@@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.application;
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
/**
* 客户端状态变更事件

View File

@@ -2,21 +2,24 @@ package org.framework.lazy.cloud.network.heartbeat.client.application.impl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.application.assembler.LazyNettyServerPropertiesDTOAssembler;
import org.framework.lazy.cloud.network.heartbeat.client.application.dto.LazyNettyServerPropertiesDTO;
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerProperties;
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerPropertiesRepository;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
import org.framework.lazy.cloud.network.heartbeat.client.application.LazyNettyServerPropertiesApplication;
import org.framework.lazy.cloud.network.heartbeat.client.application.assembler.LazyNettyServerPropertiesDTOAssembler;
import org.framework.lazy.cloud.network.heartbeat.client.application.command.lazy.netty.server.properties.*;
import org.framework.lazy.cloud.network.heartbeat.client.application.dto.LazyNettyServerPropertiesDTO;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerProperties;
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerPropertiesRepository;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.socket.NettyUdpClientSocket;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.wu.framework.core.NormalUsedString;
import org.wu.framework.database.lazy.web.plus.stereotype.LazyApplication;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.web.response.Result;
import java.util.List;
@@ -188,16 +191,33 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
String clientId = lazyNettyServerProperties.getClientId();
String appKey = lazyNettyServerProperties.getAppKey();
String appSecret = lazyNettyServerProperties.getAppSecret();
NettyClientSocket nettyClientSocket = new
NettyClientSocket(inetHost, inetPort, clientId,
NormalUsedString.DEFAULT,appKey,appSecret,
ProtocolType protocolType = lazyNettyServerProperties.getProtocolType();
NettyClientSocket nettyClientSocket;
if (ProtocolType.TCP.equals(protocolType)) {
nettyClientSocket = new
NettyTcpClientSocket(inetHost, inetPort, clientId,
NormalUsedString.DEFAULT, appKey, appSecret,
clientChangeEvent, handleChannelTypeAdvancedList);
} else if (ProtocolType.UDP.equals(protocolType)) {
nettyClientSocket = new
NettyUdpClientSocket(inetHost, inetPort, clientId,
NormalUsedString.DEFAULT, appKey, appSecret,
clientChangeEvent, handleChannelTypeAdvancedList);
} else {
nettyClientSocket = null;
}
if (nettyClientSocket == null) {
return;
}
cacheNettyClientSocketMap.put(lazyNettyServerProperties, nettyClientSocket);
// 更新状态为运行中
lazyNettyServerProperties.setConnectStatus(NettyClientStatus.RUNNING);
lazyNettyServerPropertiesRepository.story(lazyNettyServerProperties);
Thread thread = new Thread(() -> {
try {
nettyClientSocket.newConnect2Server();
@@ -237,7 +257,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
@Override
public void destroyOneClientSocket(LazyNettyServerProperties needCloseLazyNettyServerProperties) {
// 关闭指定socket
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyClientSocket) -> {
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyTcpClientSocket) -> {
String clientId = nettyServerProperties.getClientId();
String inetHost = nettyServerProperties.getInetHost();
Integer inetPort = nettyServerProperties.getInetPort();
@@ -247,7 +267,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
if (Objects.equals(clientId, needCloseClientId)
&& Objects.equals(inetPort, needCloseInetPort)
&& Objects.equals(inetHost, needCloseInetHost)) {
nettyClientSocket.shutdown();
nettyTcpClientSocket.shutdown();
// 关闭客户端:{}与服务端连接:{}:{}
log.warn("Close client: {} Connect to server: {}: {}", clientId, inetHost, inetPort);
}
@@ -260,8 +280,8 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
@Override
public void destroyClientSocket() {
// 关闭socket
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyClientSocket) -> {
nettyClientSocket.shutdown();
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyTcpClientSocket) -> {
nettyTcpClientSocket.shutdown();
String clientId = nettyServerProperties.getClientId();
String inetHost = nettyServerProperties.getInetHost();
Integer inetPort = nettyServerProperties.getInetPort();

View File

@@ -1,86 +1,459 @@
package org.framework.lazy.cloud.network.heartbeat.client.config;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
import org.springframework.boot.CommandLineRunner;
import org.framework.lazy.cloud.network.heartbeat.client.context.NettyClientSocketApplicationListener;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced.*;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced.*;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced.*;
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.socks.advanced.*;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.wu.framework.core.NormalUsedString;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Role;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Import({NettyClientSocketApplicationListener.class})
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@ConditionalOnProperty(prefix = NettyClientProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
public class ClientAutoConfiguration {
/**
* description 自动配置
@Configuration()
static class ClientTcpConfiguration {
/**
* 服务端 处理客户端心跳
*
* @author 吴佳伟
* @date 2023/09/12 18:22
* @see InitConfig
* @return ClientHandleTcpChannelHeartbeatTypeAdvanced
*/
@Deprecated
@Slf4j
public class ClientAutoConfiguration implements CommandLineRunner {
private final NettyClientProperties nettyClientProperties;
private final ClientChangeEvent clientChangeEvent;
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
public static final ThreadPoolExecutor NETTY_CLIENT_EXECUTOR = new ThreadPoolExecutor(1, 1, 200, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(1));
public ClientAutoConfiguration(NettyClientProperties nettyClientProperties,
ClientChangeEvent clientChangeEvent,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.nettyClientProperties = nettyClientProperties;
this.clientChangeEvent = clientChangeEvent;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
@Bean(destroyMethod = "shutdown")
public NettyClientSocket nettyClientSocket() {
String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort();
String clientId = nettyClientProperties.getClientId();
String appKey = nettyClientProperties.getAppKey();
String appSecret = nettyClientProperties.getAppSecret();
return new NettyClientSocket(inetHost, inetPort, clientId, NormalUsedString.DEFAULT, appKey,appSecret,clientChangeEvent, handleChannelTypeAdvancedList);
@Bean
public ClientHandleTcpChannelHeartbeatTypeAdvanced clientHandleTcpChannelHeartbeatTypeAdvanced() {
return new ClientHandleTcpChannelHeartbeatTypeAdvanced();
}
/**
* @param args
* @throws Exception
* 处理 客户端代理的真实端口自动读写
*
* @return ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced
*/
@Override
public void run(String... args) throws Exception {
String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort();
String clientId = nettyClientProperties.getClientId();
String appKey = nettyClientProperties.getAppKey();
String appSecret = nettyClientProperties.getAppSecret();
NettyClientSocket nettyClientSocket = new NettyClientSocket(
inetHost, inetPort,
clientId, NormalUsedString.DEFAULT,appKey,appSecret,
clientChangeEvent, handleChannelTypeAdvancedList);
Thread thread = new Thread(() -> {
try {
nettyClientSocket.newConnect2Server();
} catch (Exception e) {
throw new RuntimeException(e);
@Bean
public ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced clientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced() {
return new ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced();
}
});
log.info("当前服务连接Netty客户端:{},Netty端口:{}", inetHost, inetPort);
NETTY_CLIENT_EXECUTOR.execute(thread);
/**
* 处理 接收服务端发送过来的聊天信息
*
* @return ClientHandleTcpDistributeSingleClientMessageTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeSingleClientMessageTypeAdvanced clientHandleTcpDistributeSingleClientMessageTypeAdvanced() {
return new ClientHandleTcpDistributeSingleClientMessageTypeAdvanced();
}
/**
* 处理 客户端渗透服务端数据传输通道连接成功
*
* @return ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced();
}
/**
* 处理 客户端渗透客户端数据传输通道连接成功
*
* @return ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced clientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced clientHandleTcpDistributeClientTransferClientRequestTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced() {
return new ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced clientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced() {
return new ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced();
}
@Bean
public ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute clientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute(NettyClientProperties nettyClientProperties) {
return new ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute(nettyClientProperties);
}
@Bean
public ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle clientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
return new ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(clientChangeEvent);
}
@Bean
public ClientHandleTcpClientChannelActiveAdvanced clientHandleTcpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
return new ClientHandleTcpClientChannelActiveAdvanced(nettyClientProperties);
}
@Bean
public ClientHandleTcpDistributeDisconnectTypeAdvancedHandle clientHandleTcpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
return new ClientHandleTcpDistributeDisconnectTypeAdvancedHandle(clientChangeEvent);
}
@Bean
public ClientHandleTcpDistributeStagingClosedTypeAdvanced clientHandleTcpDistributeStagingClosedTypeAdvanced() {
return new ClientHandleTcpDistributeStagingClosedTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeStagingOpenedTypeAdvanced clientHandleTcpDistributeStagingOpenedTypeAdvanced() {
return new ClientHandleTcpDistributeStagingOpenedTypeAdvanced();
}
/**
* 处理 客户端渗透服务端init信息
*
* @return ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced clientHandleTcpDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
return new ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
}
/**
* 处理 客户端渗透服务端init close 信息
*
* @return ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced clientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced clientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced clientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced clientHandleTcpDistributeClientPermeateClientInitTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced clientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(
NettyClientProperties nettyClientProperties) {
return new ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties);
}
@Bean
public ClientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced();
}
}
@Configuration()
static class ClientUdpConfiguration {
/**
* 服务端 处理客户端心跳
*
* @return ClientHandleUdpChannelHeartbeatTypeAdvanced
*/
@Bean
public ClientHandleUdpChannelHeartbeatTypeAdvanced clientHandleUdpChannelHeartbeatTypeAdvanced() {
return new ClientHandleUdpChannelHeartbeatTypeAdvanced();
}
/**
* 处理 客户端代理的真实端口自动读写
*
* @return ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced
*/
@Bean
public ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced clientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced() {
return new ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced();
}
/**
* 处理 接收服务端发送过来的聊天信息
*
* @return ClientHandleUdpDistributeSingleClientMessageTypeAdvanced
*/
@Bean
public ClientHandleUdpDistributeSingleClientMessageTypeAdvanced clientHandleUdpDistributeSingleClientMessageTypeAdvanced() {
return new ClientHandleUdpDistributeSingleClientMessageTypeAdvanced();
}
/**
* 处理 客户端渗透服务端数据传输通道连接成功
*
* @return ClientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Bean
public ClientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced() {
return new ClientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced();
}
/**
* 处理 客户端渗透客户端数据传输通道连接成功
*
* @return ClientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Bean
public ClientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced() {
return new ClientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced clientHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced() {
return new ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeClientTransferClientRequestTypeAdvanced clientHandleUdpDistributeClientTransferClientRequestTypeAdvanced() {
return new ClientHandleUdpDistributeClientTransferClientRequestTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced() {
return new ClientHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeSingleClientRealCloseVisitorTypeAdvanced clientHandleUdpDistributeSingleClientRealCloseVisitorTypeAdvanced() {
return new ClientHandleUdpDistributeSingleClientRealCloseVisitorTypeAdvanced();
}
@Bean
public ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute clientHandleUdpChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
return new ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute(nettyClientProperties);
}
@Bean
public ClientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle clientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
return new ClientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle(clientChangeEvent);
}
@Bean
public ClientHandleUdpClientChannelActiveAdvanced clientHandleUdpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
return new ClientHandleUdpClientChannelActiveAdvanced(nettyClientProperties);
}
@Bean
public ClientHandleUdpDistributeDisconnectTypeAdvancedHandle clientHandleUdpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
return new ClientHandleUdpDistributeDisconnectTypeAdvancedHandle(clientChangeEvent);
}
@Bean
public ClientHandleUdpDistributeStagingClosedTypeAdvanced clientHandleUdpDistributeStagingClosedTypeAdvanced() {
return new ClientHandleUdpDistributeStagingClosedTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeStagingOpenedTypeAdvanced clientHandleUdpDistributeStagingOpenedTypeAdvanced() {
return new ClientHandleUdpDistributeStagingOpenedTypeAdvanced();
}
/**
* 处理 客户端渗透服务端init信息
*
* @return ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced
*/
@Bean
public ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced clientHandleUdpDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
return new ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
}
/**
* 处理 客户端渗透服务端init close 信息
*
* @return ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced
*/
@Bean
public ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced clientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced() {
return new ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced clientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced() {
return new ClientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced clientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced() {
return new ClientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeClientPermeateClientInitTypeAdvanced clientHandleUdpDistributeClientPermeateClientInitTypeAdvanced() {
return new ClientHandleUdpDistributeClientPermeateClientInitTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced clientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced() {
return new ClientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced();
}
@Bean
public ClientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced(
NettyClientProperties nettyClientProperties) {
return new ClientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties);
}
@Bean
public ClientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced() {
return new ClientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced();
}
}
@Configuration
static class HttpProxyConfiguration {
@Bean
public ClientHandleDistributeHttpClientProxyServerTransferTypeAdvanced clientHandleDistributeHttpClientProxyServerTypeAdvanced() {
return new ClientHandleDistributeHttpClientProxyServerTransferTypeAdvanced();
}
@Bean
public ClientHandleHttpClientProxyClientTypeAdvanced clientHandleHttpClientClientProxyClientTypeAdvanced() {
return new ClientHandleHttpClientProxyClientTypeAdvanced();
}
@Bean
public ClientHandleHttpClientProxyServerTypeAdvanced clientHandleHttpClientClientProxyServerTypeAdvanced() {
return new ClientHandleHttpClientProxyServerTypeAdvanced();
}
@Bean
public ClientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced clientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced() {
return new ClientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced();
}
@Bean
public ClientHandleDistributeHttpClientProxyServerServerRouteCloseTypeAdvanced clientHandleDistributeHttpClientProxyServerServerRouteCloseTypeAdvanced(){
return new ClientHandleDistributeHttpClientProxyServerServerRouteCloseTypeAdvanced();
}
@Bean
public ClientHandleDistributeHttpClientProxyServerClientRouteTypeAdvanced clientHandleDistributeHttpClientProxyServerClientRouteTypeAdvanced() {
return new ClientHandleDistributeHttpClientProxyServerClientRouteTypeAdvanced();
}
@Bean
public ClientHandleDistributeHttpClientProxyServerClientRouteCloseTypeAdvanced clientHandleDistributeHttpClientProxyServerClientRouteCloseTypeAdvanced(){
return new ClientHandleDistributeHttpClientProxyServerClientRouteCloseTypeAdvanced();
}
@Bean
public ClientHandleDistributeHttpClientProxyClientConnectionTransferSuccessfulAdvanced clientHandleDistributeHttpClientProxyClientConnectionTransferSuccessfulAdvanced() {
return new ClientHandleDistributeHttpClientProxyClientConnectionTransferSuccessfulAdvanced();
}
@Bean
public ClientHandleDistributeHttpClientProxyClientTransferRequestAdvanced clientHandleDistributeHttpClientProxyClientTransferRequestAdvanced() {
return new ClientHandleDistributeHttpClientProxyClientTransferRequestAdvanced();
}
@Bean
public ClientHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced clientHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced(){
return new ClientHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced();
}
@Bean
public ClientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced clientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced(){
return new ClientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced();
}
@Bean
public ClientHandleDistributeHttpServerProxyClientConnectionSuccessfulTypeAdvanced clientHandleDistributeHttpServerProxyClientConnectionSuccessfulTypeAdvanced(){
return new ClientHandleDistributeHttpServerProxyClientConnectionSuccessfulTypeAdvanced();
}
@Bean
public ClientHandleDistributeHttpServerProxyClientTransferRequestAdvanced clientHandleDistributeHttpServerProxyClientTransferRequestAdvanced(){
return new ClientHandleDistributeHttpServerProxyClientTransferRequestAdvanced();
}
}
@Configuration
static class SocksProxyConfiguration {
@Bean
public ClientHandleNettySocketProtocolHandleSocketClientProxyServerStartTypeAdvanced nettySocketProtocolHandleSocketClientProxyServerTypeAdvanced() {
return new ClientHandleNettySocketProtocolHandleSocketClientProxyServerStartTypeAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyServerConnectionTransferSuccessfulAdvanced clientHandleDistributeSocksClientProxyServerConnectionTransferSuccessfulAdvanced() {
return new ClientHandleDistributeSocksClientProxyServerConnectionTransferSuccessfulAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyServerConnectionTransferFailAdvanced clientHandleDistributeSocksClientProxyServerConnectionTransferFailAdvanced() {
return new ClientHandleDistributeSocksClientProxyServerConnectionTransferFailAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyServerTransferTransferResponseAdvanced clientHandleDistributeSocksClientProxyServerTransferTransferResponseAdvanced() {
return new ClientHandleDistributeSocksClientProxyServerTransferTransferResponseAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyServerTransferCloseAdvanced clientHandleDistributeSocksClientProxyServerTransferCloseAdvanced() {
return new ClientHandleDistributeSocksClientProxyServerTransferCloseAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyClientConnectionTransferFailAdvanced clientHandleDistributeSocksClientProxyClientConnectionTransferFailAdvanced(){
return new ClientHandleDistributeSocksClientProxyClientConnectionTransferFailAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyClientConnectionTransferSuccessfulAdvanced clientHandleDistributeSocksClientProxyClientConnectionTransferSuccessfulAdvanced(){
return new ClientHandleDistributeSocksClientProxyClientConnectionTransferSuccessfulAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyClientTransferCloseAdvanced clientHandleDistributeSocksClientProxyClientTransferCloseAdvanced(){
return new ClientHandleDistributeSocksClientProxyClientTransferCloseAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyClientTransferTransferResponseAdvanced clientHandleDistributeSocksClientProxyClientTransferTransferResponseAdvanced(){
return new ClientHandleDistributeSocksClientProxyClientTransferTransferResponseAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyClientOtherConnectionTransferAdvanced clientHandleDistributeSocksClientProxyClientOtherConnectionTransferAdvanced1(){
return new ClientHandleDistributeSocksClientProxyClientOtherConnectionTransferAdvanced();
}
@Bean
public ClientHandleDistributeSocksClientProxyClientTransferTransferRequestAdvanced clientHandleDistributeSocksClientProxyClientTransferTransferRequestAdvanced(){
return new ClientHandleDistributeSocksClientProxyClientTransferTransferRequestAdvanced();
}
@Bean
public ClientHandleSocksDistributeServerProxyClientConnectionInitTypeAdvanced clientHandleSocksDistributeServerProxyClientConnectionInitTypeAdvanced(){
return new ClientHandleSocksDistributeServerProxyClientConnectionInitTypeAdvanced();
}
@Bean
public ClientHandleSocksDistributeServerProxyClientRequestTypeAdvanced clientHandleSocksDistributeServerProxyClientRequestTypeAdvanced(){
return new ClientHandleSocksDistributeServerProxyClientRequestTypeAdvanced();
}
@Bean
public ClientHandleSocksDistributeServerProxyClientTransferCloseAdvanced clientHandleSocksDistributeServerProxyClientTransferCloseAdvanced(){
return new ClientHandleSocksDistributeServerProxyClientTransferCloseAdvanced();
}
}
}

View File

@@ -1,165 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.config;
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.*;
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Role;
import java.util.List;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@ConditionalOnProperty(prefix = NettyClientProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
public class HeartbeatClientConfiguration {
/**
* 服务端 处理客户端心跳
*
* @return ClientTcpHandleChannelHeartbeatTypeAdvanced
*/
@Bean
public ClientTcpHandleChannelHeartbeatTypeAdvanced clientChannelHeartbeatTypeAdvanced() {
return new ClientTcpHandleChannelHeartbeatTypeAdvanced();
}
/**
* 处理 客户端代理的真实端口自动读写
*
* @return ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced handleDistributeSingleClientRealAutoReadConnectTypeAdvanced() {
return new ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced();
}
/**
* 处理 接收服务端发送过来的聊天信息
*
* @return ClientHandleTcpDistributeSingleClientMessageTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeSingleClientMessageTypeAdvanced handleDistributeSingleClientMessageTypeAdvanced() {
return new ClientHandleTcpDistributeSingleClientMessageTypeAdvanced();
}
/**
* 处理 客户端渗透服务端数据传输通道连接成功
*
* @return ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced();
}
/**
* 处理 客户端渗透客户端数据传输通道连接成功
*
* @return ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced clientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced clientHandleDistributeClientTransferClientTypeAdvanced() {
return new ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleDistributeClientTransferClientResponseTypeAdvanced() {
return new ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced handleDistributeSingleClientRealCloseVisitorTypeAdvanced() {
return new ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced();
}
@Bean
public ClientHandleChannelTransferTypeAdvancedHandleDistributeTcpDistribute handleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
return new ClientHandleChannelTransferTypeAdvancedHandleDistributeTcpDistribute(nettyClientProperties);
}
@Bean
public HandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle handleDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
return new HandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(clientChangeEvent);
}
@Bean
public HandleTcpClientChannelActiveAdvanced handleClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
return new HandleTcpClientChannelActiveAdvanced(nettyClientProperties);
}
@Bean
public HandleTcpDistributeDisconnectTypeAdvancedHandle handleDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
return new HandleTcpDistributeDisconnectTypeAdvancedHandle(clientChangeEvent);
}
@Bean
public HandleTcpDistributeStagingClosedTypeAdvanced handleDistributeStagingClosedTypeAdvanced() {
return new HandleTcpDistributeStagingClosedTypeAdvanced();
}
@Bean
public HandleTcpDistributeStagingOpenedTypeAdvanced handleDistributeStagingOpenedTypeAdvanced() {
return new HandleTcpDistributeStagingOpenedTypeAdvanced();
}
/**
* 处理 客户端渗透服务端init信息
*
* @return ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced clientHandleDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
return new ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
}
/**
* 处理 客户端渗透服务端init close 信息
*
* @return ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced
*/
@Bean
public ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced clientHandleDistributeClientPermeateServerCloseTypeAdvanced( ) {
return new ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced clientHandleDistributeClientPermeateServerTransferTypeAdvanced( ) {
return new ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced clientHandleDistributeClientPermeateClientCloseTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced clientHandleDistributeClientPermeateClientInitTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced clientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced() {
return new ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced();
}
@Bean
public ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
return new ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties, handleChannelTypeAdvancedList);
}
@Bean
public ClientHandleHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced() {
return new ClientHandleHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced();
}
}

View File

@@ -1,91 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.config;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity.LazyNettyServerPropertiesDO;
import org.framework.lazy.cloud.network.heartbeat.client.application.LazyNettyServerPropertiesApplication;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import java.util.Objects;
/**
* 初始化配置
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
@Configuration
public class InitConfig implements CommandLineRunner, DisposableBean {
private final NettyClientProperties nettyClientProperties;
private final LazyLambdaStream lazyLambdaStream;
private final LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication;
public InitConfig(NettyClientProperties nettyClientProperties, LazyLambdaStream lazyLambdaStream, LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication) {
this.nettyClientProperties = nettyClientProperties;
this.lazyLambdaStream = lazyLambdaStream;
this.lazyNettyServerPropertiesApplication = lazyNettyServerPropertiesApplication;
}
@Override
public void run(String... args) throws Exception {
try {
// 存储配置到db
initDb2Config();
// 启动客户端连接
lazyNettyServerPropertiesApplication.starterAllClientSocket();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 存储配置到db
*/
public void initDb2Config() {
String clientId = nettyClientProperties.getClientId();
String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort();
String appKey = nettyClientProperties.getAppKey();
String appSecret = nettyClientProperties.getAppSecret();
if (Objects.isNull(clientId) ||
Objects.isNull(inetHost)) {
log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties);
return;
}
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO();
lazyNettyServerPropertiesDO.setClientId(clientId);
lazyNettyServerPropertiesDO.setInetHost(inetHost);
lazyNettyServerPropertiesDO.setInetPort(inetPort);
lazyNettyServerPropertiesDO.setType(PropertiesType.CONFIG);
lazyNettyServerPropertiesDO.setIsDeleted(false);
lazyNettyServerPropertiesDO.setAppKey(appKey);
lazyNettyServerPropertiesDO.setAppSecret(appSecret);
// 根据服务端端口、port 唯一性验证
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
);
if (!exists) {
lazyLambdaStream.insert(lazyNettyServerPropertiesDO);
}
}
/**
* 程序关闭后执行
*/
@Override
public void destroy() {
lazyNettyServerPropertiesApplication.destroyClientSocket();
}
}

View File

@@ -1,7 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.client.config;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@@ -30,7 +30,10 @@ public class NettyClientProperties {
*/
private String clientId;
/**
* 协议类型
*/
private ProtocolType protocolType = ProtocolType.TCP;
/**
*
* 令牌key

View File

@@ -0,0 +1,104 @@
package org.framework.lazy.cloud.network.heartbeat.client.context;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.application.LazyNettyServerPropertiesApplication;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity.LazyNettyServerPropertiesDO;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import java.util.Objects;
@Slf4j
@Component
public class NettyClientSocketApplicationListener implements ApplicationListener<ApplicationStartedEvent>, DisposableBean {
private final NettyClientProperties nettyClientProperties;
private final LazyLambdaStream lazyLambdaStream;
private final LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication;
public NettyClientSocketApplicationListener(NettyClientProperties nettyClientProperties, LazyLambdaStream lazyLambdaStream, LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication) {
this.nettyClientProperties = nettyClientProperties;
this.lazyLambdaStream = lazyLambdaStream;
this.lazyNettyServerPropertiesApplication = lazyNettyServerPropertiesApplication;
}
/**
* 存储配置到db
*/
public void initDb2Config() {
try {
String clientId = nettyClientProperties.getClientId();
String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort();
String appKey = nettyClientProperties.getAppKey();
String appSecret = nettyClientProperties.getAppSecret();
ProtocolType protocolType = nettyClientProperties.getProtocolType();
if (Objects.isNull(clientId) ||
Objects.isNull(inetHost)) {
log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties);
return;
}
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO();
lazyNettyServerPropertiesDO.setClientId(clientId);
lazyNettyServerPropertiesDO.setInetHost(inetHost);
lazyNettyServerPropertiesDO.setInetPort(inetPort);
lazyNettyServerPropertiesDO.setType(PropertiesType.CONFIG);
lazyNettyServerPropertiesDO.setIsDeleted(false);
lazyNettyServerPropertiesDO.setAppKey(appKey);
lazyNettyServerPropertiesDO.setAppSecret(appSecret);
lazyNettyServerPropertiesDO.setProtocolType(protocolType);
// 根据服务端端口、port 唯一性验证
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
.eq(LazyNettyServerPropertiesDO::getProtocolType, protocolType)
);
if (!exists) {
lazyLambdaStream.insert(lazyNettyServerPropertiesDO);
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
* Handle an application event.
*
* @param event the event to respond to
*/
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
try {
// 存储配置到db
initDb2Config();
// 启动客户端连接
lazyNettyServerPropertiesApplication.starterAllClientSocket();
} catch (Exception e) {
e.printStackTrace();
}
}
@PreDestroy
@Override
public void destroy() throws Exception {
lazyNettyServerPropertiesApplication.destroyClientSocket();
}
}

View File

@@ -1,15 +1,13 @@
package org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableField;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import java.lang.String;
import java.time.LocalDateTime;
import java.lang.Integer;
/**
* describe 服务端配置信息
*
@@ -66,6 +64,12 @@ public class LazyNettyServerProperties {
*/
@Schema(description ="类型配置、DB",name ="type",example = "")
private PropertiesType type;
/**
* 协议类型
*/
@Schema(description = "协议类型", name = "protocol_type", example = "")
private ProtocolType protocolType;
/**
* 令牌key
*/

View File

@@ -2,8 +2,8 @@ package org.framework.lazy.cloud.network.heartbeat.client.infrastructure.convert
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerProperties;
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity.LazyNettyServerPropertiesDO;
import org.mapstruct.factory.Mappers;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* describe 服务端配置信息
*

View File

@@ -5,8 +5,10 @@ import lombok.Data;
import lombok.experimental.Accessors;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.wu.framework.lazy.orm.core.stereotype.LazyTable;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableField;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableFieldId;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableFieldUnique;
import java.time.LocalDateTime;
@@ -24,6 +26,13 @@ import java.time.LocalDateTime;
public class LazyNettyServerPropertiesDO {
/**
*
* 主键ID
*/
@Schema(description ="主键ID",name ="id",example = "")
@LazyTableFieldId(name = "id", comment = "主键ID")
private Long id;
/**
*
* 客户身份ID
@@ -95,6 +104,13 @@ public class LazyNettyServerPropertiesDO {
@LazyTableField(name="type",comment="类型配置、DB",columnType="varchar(255)")
private PropertiesType type;
/**
* 协议类型
*/
@Schema(description ="协议类型",name ="protocol_type",example = "")
@LazyTableField(name="protocol_type",comment="协议类型",columnType="varchar(255)")
private ProtocolType protocolType;
/**
*
* 更新时间

View File

@@ -1,34 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
/**
* 下发 客户端渗透服务端通信通道关闭
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
*/
@Slf4j
public class ClientHandleHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
// 关闭本地通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
channel.close();
nextChannel.close();
}
}

View File

@@ -1,43 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerVisitorHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
/**
* 客户端渗透服务端数据传输通道连接成功
* @see NettyClientPermeateServerVisitorTransferSocket
* @see NettyClientPermeateServerVisitorHandler
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/
@Slf4j
public class ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param transferChannel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
// 连接成功 开启自动读取写
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
String visitorId = new String(msgVisitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(transferChannel);
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
}
}

View File

@@ -1,29 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.AbstractTcpHandleChannelHeartbeatTypeAdvanced;
/**
* 服务端 处理客户端心跳
* TCP_TYPE_HEARTBEAT
*/
public class ClientTcpHandleChannelHeartbeatTypeAdvanced extends AbstractTcpHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
NettyProxyMsg hb = new NettyProxyMsg();
hb.setType(MessageType.TCP_TYPE_HEARTBEAT);
// channel.writeAndFlush(hb);
}
}

View File

@@ -1,44 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle;
import java.util.List;
/**
* 客户端连接成功通知
*/
@Slf4j
public class HandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle extends AbstractHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle<NettyProxyMsg> {
private final ClientChangeEvent clientChangeEvent;
public HandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
this.clientChangeEvent = clientChangeEvent;
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
// 客户端ID{},客户端:{}连接成功
log.warn("Client ID: {}, Client Data : {} Connection successful", new String(msg.getClientId()), new String(msg.getData()));
// 存储其他客户端状态
List<String> clientIdList = JSONObject.parseArray(new String(msg.getData()), String.class);
for (String clientId : clientIdList) {
clientChangeEvent.clientOnLine(clientId);
}
}
}

View File

@@ -1,43 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeDisconnectTypeAdvancedHandle;
/**
* 服务端处理客户端断开连接处理
* TYPE_DISCONNECT
*/
@Slf4j
public class HandleTcpDistributeDisconnectTypeAdvancedHandle extends AbstractHandleTcpDistributeDisconnectTypeAdvancedHandle<NettyProxyMsg> {
private final ClientChangeEvent clientChangeEvent;
public HandleTcpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
this.clientChangeEvent = clientChangeEvent;
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg msg) {
// 服务下线
byte[] data = msg.getData();
byte[] clientId = msg.getClientId();
String tenantId = new String(clientId);
//客户端:{}下线
log.warn("Client: {} Offline", tenantId);
clientChangeEvent.clientOffLine(tenantId);
}
}

View File

@@ -1,30 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeStagingClosedTypeAdvanced;
/**
* 服务端下发暂存关闭消息处理
*/
@Slf4j
public class HandleTcpDistributeStagingClosedTypeAdvanced extends AbstractHandleTcpDistributeStagingClosedTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
log.info("客户端:{}离线暂存关闭", clientId);
// 修改redis 客户端暂存状态
// String stagingStatusKey = StagingConfigKeyConstant.getStagingStatusKey(clientId);
// stringRedisTemplate.opsForValue().set(stagingStatusKey, StagingStatus.CLOSED.name());
}
}

View File

@@ -1,34 +0,0 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeStagingOpenedTypeAdvanced;
/**
* 服务端下发暂存开启消息处理
*/
@Slf4j
public class HandleTcpDistributeStagingOpenedTypeAdvanced extends AbstractHandleTcpDistributeStagingOpenedTypeAdvanced<NettyProxyMsg> {
public HandleTcpDistributeStagingOpenedTypeAdvanced() {
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
//客户端:{}离线暂存开启
log.warn("Client: {} Offline temporary storage enabled", new String(msg.getClientId()));
// 修改redis 客户端暂存状态
// String stagingStatusKey = StagingConfigKeyConstant.getStagingStatusKey(clientId);
// stringRedisTemplate.opsForValue().set(stagingStatusKey, StagingStatus.OPENED.name());
}
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -11,7 +11,7 @@ import java.util.List;
@NoArgsConstructor
@Data
public class InternalNetworkClientPermeateClientVisitor implements InternalNetworkPermeate {
public class NettyClientPermeateClientVisitor implements InternalNetworkPermeate {
/**
* 当前客户端ID

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -10,7 +10,7 @@ import java.util.List;
@NoArgsConstructor
@Data
public class InternalNetworkClientPermeateServerVisitor implements InternalNetworkPermeate {
public class NettyClientPermeateServerVisitor implements InternalNetworkPermeate {
/**
* 目标地址

View File

@@ -0,0 +1,15 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate;
public interface NettyClientSocket {
/**
* 创建客户端链接服务端
* @throws InterruptedException 异常信息
*/
void newConnect2Server() throws InterruptedException;
/**
* 关闭链接
*/
void shutdown();
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.event;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event;
/**
* 客户端状态变更事件

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.event;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event;
import jakarta.annotation.Resource;

View File

@@ -0,0 +1,32 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.AbstractTcpHandleChannelHeartbeatTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 服务端 处理客户端心跳
* TCP_TYPE_HEARTBEAT
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class ClientHandleTcpChannelHeartbeatTypeAdvanced extends AbstractTcpHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
NettyProxyMsg hb = new NettyProxyMsg();
hb.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
// nettyChannelContext.writeAndFlush(hb);
}
}

View File

@@ -0,0 +1,64 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeServicePermeateClientTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 服务端处理客户端数据传输
*
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute extends AbstractHandleTcpDistributeServicePermeateClientTransferTypeAdvanced<NettyProxyMsg> {
private final NettyClientProperties nettyClientProperties;
public ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute(NettyClientProperties nettyClientProperties) {
this.nettyClientProperties = nettyClientProperties;
}
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
log.debug("接收到服务端需要内网穿透的数据:{}" , nettyProxyMsg);
String clientId = nettyClientProperties.getClientId();
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 真实服务通道
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel == null) {
log.error("无法获取访客:{} 真实服务", new String(visitorId));
return;
}
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
buf.writeBytes(nettyProxyMsg.getData());
nextChannel.writeAndFlush(buf);
}
}

View File

@@ -1,30 +1,35 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpClientChannelActiveAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpClientChannelActiveAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 客户端通道 is active
*/
public class HandleTcpClientChannelActiveAdvanced extends AbstractHandleTcpClientChannelActiveAdvanced<NettyProxyMsg> {
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class ClientHandleTcpClientChannelActiveAdvanced extends AbstractHandleTcpClientChannelActiveAdvanced<NettyProxyMsg> {
private final NettyClientProperties nettyClientProperties;
public HandleTcpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
public ClientHandleTcpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
this.nettyClientProperties = nettyClientProperties;
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
// 缓存当前通道
byte[] clientIdByte = nettyProxyMsg.getClientId();
String clientId = new String(clientIdByte);

View File

@@ -1,20 +1,23 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientPermeateClientCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateClientCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 客户端渗透客户端init close 信息
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientCloseTypeAdvanced<NettyProxyMsg> {
@@ -22,11 +25,11 @@ public class ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced exte
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));

View File

@@ -0,0 +1,74 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateClientVisitorSocket;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
import org.wu.framework.spring.utils.SpringContextHolder;
import java.util.ArrayList;
import java.util.List;
/**
* 客户端渗透客户端init信息
*
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] fromClientIdBytes = nettyProxyMsg.getClientId();
byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort();
byte[] clientTargetIpBytes = nettyProxyMsg.getClientTargetIp();
byte[] clientTargetPortBytes = nettyProxyMsg.getClientTargetPort();
byte[] toClientIdBytes = nettyProxyMsg.getData();
String fromClientId = new String(fromClientIdBytes);
String toClientId = new String(toClientIdBytes);
Integer visitorPort = Integer.parseInt(new String(visitorPortBytes));
String clientTargetIp = new String(clientTargetIpBytes);
Integer clientTargetPort = Integer.parseInt(new String(clientTargetPortBytes));
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
// ChannelFlowAdapter channelFlowAdapter = SpringContextHolder.getBean(ChannelFlowAdapter.class);
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
log.info("client permeate client from client_id:【{}】 to_client_id【{}】with visitor_port【{}】, clientTargetIp:【{}】clientTargetPort:【{}】",
fromClientId, toClientId, visitorPort, clientTargetIp, clientTargetPort);
NettyTcpClientPermeateClientVisitorSocket nettyTcpClientPermeateClientVisitorSocket =
NettyTcpClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder()
.builderClientId(fromClientId)
.builderClientTargetIp(clientTargetIp)
.builderClientTargetPort(clientTargetPort)
.builderVisitorPort(visitorPort)
.builderNettyClientProperties(nettyClientProperties)
//.builderChannelFlowAdapter(channelFlowAdapter)
.builderToClientId(toClientId)
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
.build();
try {
nettyTcpClientPermeateClientVisitorSocket.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,30 +1,35 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 下发客户端渗透客户端通信通道关闭
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
// 关闭客户端真实通道访客通道
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
realChannel.close();// 真实通道关闭

View File

@@ -1,20 +1,23 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientPermeateServerCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 客户端渗透服务端init close 信息
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerCloseTypeAdvanced<NettyProxyMsg> {
@@ -22,11 +25,11 @@ public class ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced exte
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));

View File

@@ -1,14 +1,16 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorSocket;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorSocket;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientPermeateServerInitTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerInitTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
import org.wu.framework.spring.utils.SpringContextHolder;
import java.util.ArrayList;
@@ -18,8 +20,9 @@ import java.util.List;
/**
* 客户端渗透服务端init信息
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerInitTypeAdvanced<NettyProxyMsg> {
@@ -32,11 +35,11 @@ public class ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced exten
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
// 初始化 客户端渗透服务端socket
byte[] clientIdBytes = nettyProxyMsg.getClientId();
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
@@ -44,7 +47,7 @@ public class ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced exten
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
NettyClientPermeateServerVisitorSocket nettyClientPermeateServerVisitorSocket = NettyClientPermeateServerVisitorSocket.NettyVisitorSocketBuilder.builder()
NettyTcpClientPermeateServerVisitorSocket nettyTcpClientPermeateServerVisitorSocket = NettyTcpClientPermeateServerVisitorSocket.NettyVisitorSocketBuilder.builder()
.builderClientId(new String(clientIdBytes))
.builderClientTargetIp(new String(clientTargetIp))
.builderClientTargetPort(Integer.parseInt(new String(clientTargetPort)))
@@ -53,7 +56,7 @@ public class ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced exten
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
.build();
try {
nettyClientPermeateServerVisitorSocket.start();
nettyTcpClientPermeateServerVisitorSocket.start();
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();

View File

@@ -0,0 +1,39 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 下发 客户端渗透服务端通信通道关闭
*
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
// 关闭本地通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
channel.close();
nextChannel.close();
}
}

View File

@@ -1,20 +1,24 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 服务端处理客户端数据传输
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerTransferTypeAdvanced<NettyProxyMsg> {
@@ -22,11 +26,12 @@ public class ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced e
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
log.debug("客户端渗透服务端返回数据:{}" , new String(nettyProxyMsg.getData()));
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();

View File

@@ -1,14 +1,16 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientRealSocket;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateClientRealSocket;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
import org.wu.framework.spring.utils.SpringContextHolder;
import java.util.ArrayList;
@@ -19,19 +21,20 @@ import java.util.List;
* 客户端渗透客户端数据传输通道连接成功
*
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
// 创建connect 然后发送创建成功
byte[] msgClientId = nettyProxyMsg.getClientId();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
@@ -46,7 +49,7 @@ public class ClientHandleTcpDistributeClientTransferClientPermeateChannelConnect
Integer visitorPort=Integer.parseInt(new String(msgVisitorPort));
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
NettyClientPermeateClientRealSocket.buildRealServer(
NettyTcpClientPermeateClientRealSocket.buildRealServer(
clientId,
clientTargetIp,
clientTargetPort,

View File

@@ -1,21 +1,25 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 下发 客户端渗透客户端数据传输通道init 成功
*
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced extends AbstractHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced<NettyProxyMsg> {
@@ -24,11 +28,12 @@ public class ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuc
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
// 连接成功 开启自动读取写
byte[] msgClientId = nettyProxyMsg.getClientId();
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();

View File

@@ -1,21 +1,25 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeClientTransferClientRequestTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferClientRequestTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 下发客户端渗透客户端数据传输
*
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced extends AbstractHandleTcpDistributeClientTransferClientRequestTypeAdvanced<NettyProxyMsg> {
@@ -24,11 +28,12 @@ public class ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced ex
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);

View File

@@ -0,0 +1,48 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateServerVisitorHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 客户端渗透服务端数据传输通道连接成功
* @see NettyTcpClientPermeateServerVisitorTransferSocket
* @see NettyTcpClientPermeateServerVisitorHandler
*
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
// 连接成功 开启自动读取写
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
String visitorId = new String(msgVisitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
}
}

View File

@@ -0,0 +1,47 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
import java.util.List;
/**
* 客户端连接成功通知
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle extends AbstractHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle<NettyProxyMsg> {
private final ClientChangeEvent clientChangeEvent;
public ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
this.clientChangeEvent = clientChangeEvent;
}
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
// 客户端ID{},客户端:{}连接成功
log.warn("Client ID: {}, Client Data : {} Connection successful", new String(msg.getClientId()), new String(msg.getData()));
// 存储其他客户端状态
List<String> clientIdList = JSONObject.parseArray(new String(msg.getData()), String.class);
for (String clientId : clientIdList) {
clientChangeEvent.clientOnLine(clientId);
}
}
}

View File

@@ -0,0 +1,46 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeDisconnectTypeAdvancedHandle;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 服务端处理客户端断开连接处理
* TYPE_DISCONNECT
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeDisconnectTypeAdvancedHandle extends AbstractHandleTcpDistributeDisconnectTypeAdvancedHandle<NettyProxyMsg> {
private final ClientChangeEvent clientChangeEvent;
public ClientHandleTcpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
this.clientChangeEvent = clientChangeEvent;
}
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
// 服务下线
byte[] data = msg.getData();
byte[] clientId = msg.getClientId();
String tenantId = new String(clientId);
//客户端:{}下线
log.warn("Client: {} Offline", tenantId);
clientChangeEvent.clientOffLine(tenantId);
}
}

View File

@@ -1,38 +1,43 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyServerPermeateClientRealSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpServerPermeateClientRealSocket;
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPenetrationRealClient;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
import org.wu.framework.spring.utils.SpringContextHolder;
import java.util.ArrayList;
import java.util.List;
/**
* 客户端创建真实代理同奥
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced extends AbstractHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced<NettyProxyMsg> {
private final NettyClientProperties nettyClientProperties;// 服务端地址信息
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
public ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
public ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties) {
this.nettyClientProperties = nettyClientProperties;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg msg) {
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
// 创建真实端口监听
byte[] clientIdBytes = msg.getClientId();
byte[] visitorPort = msg.getVisitorPort();
@@ -49,8 +54,9 @@ public class ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanc
.visitorId(new String(visitorIdBytes))
.build();
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
// 绑定真实服务端口
NettyServerPermeateClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
NettyTcpServerPermeateClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
}
}

View File

@@ -1,21 +1,25 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 下发客户端渗透客户端数据传输响应
*
*
* @see MessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced extends AbstractHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced<NettyProxyMsg> {
@@ -24,11 +28,12 @@ public class ClientHandleTcpDistributeServicePermeateClientTransferClientRespons
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
// 把数据转到真实服务
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);

View File

@@ -1,23 +1,26 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeSingleClientMessageTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeSingleClientMessageTypeAdvanced;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 接收服务端发送过来的聊天信息
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeSingleClientMessageTypeAdvanced extends AbstractHandleTcpDistributeSingleClientMessageTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
byte[] clientId = nettyProxyMsg.getClientId();
byte[] data = nettyProxyMsg.getData();
log.info("接收客户端:{},发送过来的聊天信息:{}", new String(clientId), new String(data));

View File

@@ -1,23 +1,28 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced extends AbstractHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
Channel channel = nettyChannelContext.channel();
// 获取访客ID
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 获取访客对应的真实代理通道

View File

@@ -1,22 +1,25 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.client.AbstractHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced extends AbstractHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyChannelContext 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
// 关闭代理的真实通道
byte[] visitorId = nettyProxyMsg.getVisitorId();
NettyRealIdContext.clear(visitorId);

View File

@@ -0,0 +1,33 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeStagingClosedTypeAdvanced;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 服务端下发暂存关闭消息处理
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeStagingClosedTypeAdvanced extends AbstractHandleTcpDistributeStagingClosedTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
log.info("客户端:{}离线暂存关闭", clientId);
// 修改redis 客户端暂存状态
// String stagingStatusKey = StagingConfigKeyConstant.getStagingStatusKey(clientId);
// stringRedisTemplate.opsForValue().set(stagingStatusKey, StagingStatus.CLOSED.name());
}
}

View File

@@ -0,0 +1,37 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeStagingOpenedTypeAdvanced;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 服务端下发暂存开启消息处理
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleTcpDistributeStagingOpenedTypeAdvanced extends AbstractHandleTcpDistributeStagingOpenedTypeAdvanced<NettyProxyMsg> {
public ClientHandleTcpDistributeStagingOpenedTypeAdvanced() {
}
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param msg 通道数据
*/
@Override
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
String clientId = new String(msg.getClientId());
//客户端:{}离线暂存开启
log.warn("Client: {} Offline temporary storage enabled", new String(msg.getClientId()));
// 修改redis 客户端暂存状态
// String stagingStatusKey = StagingConfigKeyConstant.getStagingStatusKey(clientId);
// stringRedisTemplate.opsForValue().set(stagingStatusKey, StagingStatus.OPENED.name());
}
}

View File

@@ -1,26 +1,26 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.timeout.IdleStateHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
public class NettyClientFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpClientFilter extends DebugChannelInitializer<SocketChannel> {
private final ChannelTypeAdapter channelTypeAdapter;
private final NettyClientSocket nettyClientSocket;
private final NettyTcpClientSocket nettyTcpClientSocket;
public NettyClientFilter(ChannelTypeAdapter channelTypeAdapter, NettyClientSocket nettyClientSocket) {
public NettyTcpClientFilter(ChannelTypeAdapter channelTypeAdapter, NettyTcpClientSocket nettyTcpClientSocket) {
this.channelTypeAdapter = channelTypeAdapter;
this.nettyClientSocket = nettyClientSocket;
this.nettyTcpClientSocket = nettyTcpClientSocket;
}
@Override
@@ -40,6 +40,6 @@ public class NettyClientFilter extends DebugChannelInitializer<SocketChannel> {
pipeline.addLast(new IdleStateHandler(0, 4, 0));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
pipeline.addLast("doHandler", new NettyClientHandler(channelTypeAdapter, nettyClientSocket)); //客户端的逻辑
pipeline.addLast("doHandler", new NettyTcpClientHandler(channelTypeAdapter, nettyTcpClientSocket)); //客户端的逻辑
}
}

View File

@@ -1,14 +1,14 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyServerPermeateClientRealHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientRealHandler;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
public class NettyServerPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpClientPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
/**
* This method will be called once the {@link Channel} was registered. After the method returns this instance
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
@@ -21,7 +21,7 @@ public class NettyServerPermeateClientRealFilter extends DebugChannelInitializer
// 解码编码
pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10));
pipeline.addLast(new TransferEncoder());
pipeline.addLast(new NettyServerPermeateClientRealHandler());
pipeline.addLast(new NettyTcpClientPermeateClientRealHandler());
}
}

View File

@@ -1,11 +1,11 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
@@ -14,10 +14,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInit
/**
* netty 客户端渗透通信通道
*/
public class NettyClientPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpClientPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
public NettyTcpClientPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@@ -41,6 +41,6 @@ public class NettyClientPermeateClientTransferFilter extends DebugChannelInitial
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
pipeline.addLast(new NettyProxyMsgEncoder());
pipeline.addLast(new NettyClientPermeateClientTransferHandler(channelTypeAdapter));
pipeline.addLast(new NettyTcpClientPermeateClientTransferHandler(channelTypeAdapter));
}
}

View File

@@ -0,0 +1,46 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientTransferRealHandler;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
/**
* netty 客户端连接真实服服务端访客拦截器
*/
public class NettyTcpClientPermeateClientTransferRealFilter extends DebugChannelInitializer<SocketChannel> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyTcpClientPermeateClientTransferRealFilter(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
/**
* This method will be called once the {@link Channel} was registered. After the method returns this instance
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
*
* @param ch the {@link Channel} which was registered.
* @throws Exception is thrown if an error occurs. In that case it will be handled by
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
* the {@link Channel}.
*/
@Override
protected void initChannel0(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// // 解码、编码
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
// pipeline.addLast(new NettMsgEncoder());
pipeline.addLast(new IdleStateHandler(0, 4, 0));
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
pipeline.addLast(new NettyProxyMsgEncoder());
pipeline.addLast(new NettyTcpClientPermeateClientTransferRealHandler(channelTypeAdapter));
}
}

View File

@@ -1,20 +1,20 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientVisitorHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientVisitorHandler;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
public class NettyClientPermeateClientVisitorFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpClientPermeateClientVisitorFilter extends DebugChannelInitializer<SocketChannel> {
private final InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor;
private final NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor;
public NettyClientPermeateClientVisitorFilter(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor) {
this.internalNetworkClientPermeateClientVisitor = internalNetworkClientPermeateClientVisitor;
public NettyTcpClientPermeateClientVisitorFilter(NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor) {
this.nettyClientPermeateClientVisitor = nettyClientPermeateClientVisitor;
}
@@ -31,6 +31,6 @@ public class NettyClientPermeateClientVisitorFilter extends DebugChannelInitiali
protected void initChannel0(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new ChannelDuplexHandler());
pipeline.addLast(new NettyClientPermeateClientVisitorHandler(internalNetworkClientPermeateClientVisitor));
pipeline.addLast(new NettyTcpClientPermeateClientVisitorHandler(nettyClientPermeateClientVisitor));
}
}

View File

@@ -1,11 +1,11 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateServerTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
@@ -14,10 +14,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInit
/**
* netty 客户端渗透通信通道
*/
public class NettyClientPermeateServerTransferFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpClientPermeateServerTransferFilter extends DebugChannelInitializer<SocketChannel> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateServerTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
public NettyTcpClientPermeateServerTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@@ -40,6 +40,6 @@ public class NettyClientPermeateServerTransferFilter extends DebugChannelInitial
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
pipeline.addLast(new IdleStateHandler(0, 4, 0));
pipeline.addLast(new NettyProxyMsgEncoder());
pipeline.addLast(new NettyClientPermeateServerTransferHandler(channelTypeAdapter));
pipeline.addLast(new NettyTcpClientPermeateServerTransferHandler(channelTypeAdapter));
}
}

View File

@@ -1,20 +1,20 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerVisitorHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateServerVisitorHandler;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
public class NettyClientPermeateServerVisitorFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpClientPermeateServerVisitorFilter extends DebugChannelInitializer<SocketChannel> {
private final InternalNetworkClientPermeateServerVisitor internalNetworkClientPermeateServerVisitor;
private final NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor;
public NettyClientPermeateServerVisitorFilter(InternalNetworkClientPermeateServerVisitor internalNetworkClientPermeateServerVisitor) {
this.internalNetworkClientPermeateServerVisitor = internalNetworkClientPermeateServerVisitor;
public NettyTcpClientPermeateServerVisitorFilter(NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor) {
this.nettyClientPermeateServerVisitor = nettyClientPermeateServerVisitor;
}
@@ -31,6 +31,6 @@ public class NettyClientPermeateServerVisitorFilter extends DebugChannelInitiali
protected void initChannel0(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new ChannelDuplexHandler());
pipeline.addLast(new NettyClientPermeateServerVisitorHandler(internalNetworkClientPermeateServerVisitor));
pipeline.addLast(new NettyTcpClientPermeateServerVisitorHandler(nettyClientPermeateServerVisitor));
}
}

View File

@@ -1,15 +1,14 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.buffer.UnpooledDirectByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientRealHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpServerPermeateClientRealHandler;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
public class NettyClientPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpServerPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
/**
* This method will be called once the {@link Channel} was registered. After the method returns this instance
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
@@ -22,7 +21,7 @@ public class NettyClientPermeateClientRealFilter extends DebugChannelInitializer
// 解码编码
pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10));
pipeline.addLast(new TransferEncoder());
pipeline.addLast(new NettyClientPermeateClientRealHandler());
pipeline.addLast(new NettyTcpServerPermeateClientRealHandler());
}
}

View File

@@ -1,10 +1,10 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyServerPermeateClientTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpServerPermeateClientTransferHandler;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
@@ -13,10 +13,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInit
/**
* netty 客户端连接真实服服务端访客拦截器
*/
public class NettyServerPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
public class NettyTcpServerPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyServerPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
public NettyTcpServerPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@@ -37,6 +37,6 @@ public class NettyServerPermeateClientTransferFilter extends DebugChannelInitial
// pipeline.addLast(new NettMsgEncoder());
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
pipeline.addLast(new NettyProxyMsgEncoder());
pipeline.addLast(new NettyServerPermeateClientTransferHandler(channelTypeAdapter));
pipeline.addLast(new NettyTcpServerPermeateClientTransferHandler(channelTypeAdapter));
}
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@@ -7,9 +7,9 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import java.nio.charset.StandardCharsets;
@@ -23,15 +23,15 @@ import java.util.concurrent.TimeUnit;
* @date 2023/09/13 10:29
*/
@Slf4j
public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;
private final NettyClientSocket nettyClientSocket;
private final NettyTcpClientSocket nettyTcpClientSocket;
public NettyClientHandler(ChannelTypeAdapter channelTypeAdapter, NettyClientSocket nettyClientSocket) {
public NettyTcpClientHandler(ChannelTypeAdapter channelTypeAdapter, NettyTcpClientSocket nettyTcpClientSocket) {
this.channelTypeAdapter = channelTypeAdapter;
this.nettyClientSocket = nettyClientSocket;
this.nettyTcpClientSocket = nettyTcpClientSocket;
}
/**
@@ -47,7 +47,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
// 接收服务端或者是代理端的信息
Channel channel = ctx.channel();
// log.info("type:{},clientId:{},data:{}",msg.getMysqlType(),new String(msg.getClientId()),new String(msg.getData()));
channelTypeAdapter.handler(channel, msg);
channelTypeAdapter.handler(ctx, msg);
}
/**
@@ -58,13 +58,13 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
// 建立连接时
log.info("When establishing a connection{}" , new Date());
ctx.fireChannelActive();
String clientId = nettyClientSocket.getClientId();
String clientId = nettyTcpClientSocket.getClientId();
// 处理客户端连接成功
Channel channel = ctx.channel();
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.TCP_CLIENT_CHANNEL_ACTIVE);
nettyMsg.setType(TcpMessageType.TCP_CLIENT_CHANNEL_ACTIVE);
nettyMsg.setClientId(clientId);
channelTypeAdapter.handler(channel, nettyMsg);
channelTypeAdapter.handler(ctx, nettyMsg);
}
@@ -79,7 +79,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
final EventLoop eventLoop = ctx.channel().eventLoop();
eventLoop.schedule(() -> {
try {
nettyClientSocket.newConnect2Server();
nettyTcpClientSocket.newConnect2Server();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@@ -95,20 +95,20 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
if (obj instanceof IdleStateEvent event) {
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
String clientId = nettyClientSocket.getClientId();
String clientId = nettyTcpClientSocket.getClientId();
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.TCP_TYPE_HEARTBEAT);
nettyMsg.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
nettyMsg.setData(clientId.getBytes(StandardCharsets.UTF_8));
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
ctx.writeAndFlush(nettyMsg);// 发送心跳数据
} else if (event.state() == IdleState.WRITER_IDLE) { // 如果检测到写空闲状态关闭连接
// 离线暂存通知
String clientId = nettyClientSocket.getClientId();
String clientId = nettyTcpClientSocket.getClientId();
Channel channel = ctx.channel();
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.TCP_DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION);
nettyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION);
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
channelTypeAdapter.handler(channel, nettyMsg);
channelTypeAdapter.handler(ctx, nettyMsg);
ctx.close();
}

View File

@@ -1,23 +1,20 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
/**
* 来自客户端 真实服务器返回的数据请求
*/
@Slf4j
public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
public class NettyTcpClientPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
@Override
@@ -32,7 +29,7 @@ public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHa
// 访客通信通道 上报服务端代理完成
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
NettyProxyMsg returnMessage = new NettyProxyMsg();
returnMessage.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE);
returnMessage.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE);
returnMessage.setVisitorId(visitorId);
returnMessage.setClientId(clientId);
returnMessage.setVisitorPort(visitorPort);
@@ -55,7 +52,7 @@ public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHa
if (nextChannel != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@@ -1,27 +1,23 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
/**
* 客户端访客通信通道 处理器
*/
@Slf4j
public class NettyClientPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
public class NettyTcpClientPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
public NettyTcpClientPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@@ -33,7 +29,7 @@ public class NettyClientPermeateClientTransferHandler extends SimpleChannelInbou
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}
@@ -47,7 +43,7 @@ public class NettyClientPermeateClientTransferHandler extends SimpleChannelInbou
if (nextChannel != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@@ -1,26 +1,23 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
/**
* 客户端访客通信通道 处理器
*/
@Slf4j
public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
public class NettyTcpClientPermeateClientTransferRealHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateClientTransferRealHandler(ChannelTypeAdapter channelTypeAdapter) {
public NettyTcpClientPermeateClientTransferRealHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@@ -32,7 +29,7 @@ public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelI
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}
@@ -48,7 +45,7 @@ public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelI
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.buffer.ByteBuf;
@@ -8,31 +8,31 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced.ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateClientVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.UUID;
@Slf4j
public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
private final InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor;
public class NettyTcpClientPermeateClientVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
private final NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor;
// private final NettyChannelPool nettyChannelPool = new DefaultNettyChannelPool(10);
public NettyClientPermeateClientVisitorHandler(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor) {
this.internalNetworkClientPermeateClientVisitor = internalNetworkClientPermeateClientVisitor;
public NettyTcpClientPermeateClientVisitorHandler(NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor) {
this.nettyClientPermeateClientVisitor = nettyClientPermeateClientVisitor;
}
/**
* @param ctx
* @throws Exception
* @see NettyClientPermeateServerVisitorTransferSocket
* @see NettyTcpClientPermeateServerVisitorTransferSocket
* @see ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Override
@@ -53,7 +53,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
// 判断是否有可用的通道 如果没有创建新的通道
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
// 创建访客连接客户端通道
NettyClientPermeateClientVisitorTransferSocket.buildTransferServer(internalNetworkClientPermeateClientVisitor,visitorChannel);
NettyTcpClientPermeateClientVisitorTransferSocket.buildTransferServer(nettyClientPermeateClientVisitor,visitorChannel);
log.info("客户端渗透客户端访客:【{}】端口连接成功了",visitorId);
super.channelActive(ctx);
}
@@ -72,10 +72,10 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
log.debug("【客户端渗透客户端】访客端口成功接收数据:{}", new String(bytes));
// 使用访客的通信通道
Integer visitorPort = internalNetworkClientPermeateClientVisitor.getVisitorPort();
String clientId = internalNetworkClientPermeateClientVisitor.getNettyClientProperties().getClientId();
Integer visitorPort = nettyClientPermeateClientVisitor.getVisitorPort();
String clientId = nettyClientPermeateClientVisitor.getNettyClientProperties().getClientId();
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST);
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST);
nettyProxyMsg.setVisitorId(visitorId);
nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort);
@@ -102,7 +102,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
// 通知客户端 关闭访问通道真实通道
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
myMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
nextChannel.writeAndFlush(myMsg);
}
// 关闭 访客通信通道访客真实通道

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.Channel;
@@ -7,21 +7,19 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.nio.charset.StandardCharsets;
/**
* 客户端访客通信通道 处理器
*/
@Slf4j
public class NettyClientPermeateServerTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
public class NettyTcpClientPermeateServerTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyClientPermeateServerTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
public NettyTcpClientPermeateServerTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@@ -33,7 +31,7 @@ public class NettyClientPermeateServerTransferHandler extends SimpleChannelInbou
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}
@@ -47,7 +45,7 @@ public class NettyClientPermeateServerTransferHandler extends SimpleChannelInbou
if (nextChannel != null) {
// 上报关闭服务端客户端真实通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeVisitorMsg.setType(TcpMessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}
@@ -79,7 +77,7 @@ public class NettyClientPermeateServerTransferHandler extends SimpleChannelInbou
if (obj instanceof IdleStateEvent event) {
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.TCP_TYPE_HEARTBEAT);
nettyMsg.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
ctx.writeAndFlush(nettyMsg);// 发送心跳数据
} else if (event.state() == IdleState.WRITER_IDLE) { // 如果检测到写空闲状态关闭连接
// 离线暂存通知

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.buffer.ByteBuf;
@@ -8,28 +8,28 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced.ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.UUID;
@Slf4j
public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
private final InternalNetworkClientPermeateServerVisitor internalNetworkClientPermeateServerVisitor;
public class NettyTcpClientPermeateServerVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
private final NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor;
// private final NettyChannelPool nettyChannelPool = new DefaultNettyChannelPool(10);
public NettyClientPermeateServerVisitorHandler(InternalNetworkClientPermeateServerVisitor internalNetworkClientPermeateServerVisitor) {
this.internalNetworkClientPermeateServerVisitor = internalNetworkClientPermeateServerVisitor;
public NettyTcpClientPermeateServerVisitorHandler(NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor) {
this.nettyClientPermeateServerVisitor = nettyClientPermeateServerVisitor;
}
/**
* @param ctx
* @throws Exception
* @see NettyClientPermeateServerVisitorTransferSocket
* @see NettyTcpClientPermeateServerVisitorTransferSocket
* @see ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
*/
@Override
@@ -41,14 +41,14 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
// 生成访客ID
String visitorId = UUID.randomUUID().toString();
Integer visitorPort = internalNetworkClientPermeateServerVisitor.getVisitorPort();
Integer visitorPort = nettyClientPermeateServerVisitor.getVisitorPort();
log.info("this channel with visitor port:{} use visitorId:{}", visitorPort, visitorId);
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
// 判断是否有可用的通道 如果没有创建新的通道
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
// 创建访客连接服务端通道
NettyClientPermeateServerVisitorTransferSocket.buildTransferServer(internalNetworkClientPermeateServerVisitor,visitorChannel);
NettyTcpClientPermeateServerVisitorTransferSocket.buildTransferServer(nettyClientPermeateServerVisitor,visitorChannel);
log.debug("客户端渗透服务端访客端口连接成功了,访客ID:{}", visitorId);
super.channelActive(ctx);
}
@@ -67,10 +67,10 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
log.debug("【客户端渗透服务端】访客端口成功接收数据:{}", new String(bytes));
// 使用访客的通信通道
Integer visitorPort = internalNetworkClientPermeateServerVisitor.getVisitorPort();
String clientId = internalNetworkClientPermeateServerVisitor.getNettyClientProperties().getClientId();
Integer visitorPort = nettyClientPermeateServerVisitor.getVisitorPort();
String clientId = nettyClientPermeateServerVisitor.getNettyClientProperties().getClientId();
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
nettyProxyMsg.setVisitorId(visitorId);
nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort);
@@ -95,7 +95,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
if (nextChannel != null && nextChannel.isActive()) {
// 通知服务端 关闭访问通道真实通道
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
myMsg.setType(TcpMessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
myMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(myMsg);
//通信通道
@@ -136,7 +136,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
if (nextChannel != null) {
// 下发关闭访客
NettyProxyMsg closeRealClient = new NettyProxyMsg();
closeRealClient.setType(MessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeRealClient.setType(TcpMessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
closeRealClient.setClientId(clientId);
closeRealClient.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeRealClient);

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.Channel;
@@ -6,9 +6,9 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
@@ -16,7 +16,7 @@ import org.wu.framework.core.utils.ObjectUtils;
* 来自客户端 真实服务器返回的数据请求
*/
@Slf4j
public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
public class NettyTcpServerPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
@Override
@@ -31,7 +31,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
// 访客通信通道 上报服务端代理完成
Channel visitor = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
NettyProxyMsg returnMessage = new NettyProxyMsg();
returnMessage.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER);
returnMessage.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER);
returnMessage.setVisitorId(visitorId);
returnMessage.setClientId(clientId);
returnMessage.setVisitorPort(visitorPort);
@@ -55,7 +55,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
if (visitor != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setVisitorId(visitorId);
visitor.writeAndFlush(closeVisitorMsg);
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.Channel;
@@ -6,8 +6,9 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.*;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
@@ -15,10 +16,10 @@ import org.wu.framework.core.utils.ObjectUtils;
* 客户端访客通信通道 处理器
*/
@Slf4j
public class NettyServerPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
public class NettyTcpServerPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;
public NettyServerPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
public NettyTcpServerPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
this.channelTypeAdapter = channelTypeAdapter;
}
@@ -30,7 +31,7 @@ public class NettyServerPermeateClientTransferHandler extends SimpleChannelInbou
@Override
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
Channel channel = ctx.channel();
channelTypeAdapter.handler(channel, nettyProxyMsg);
channelTypeAdapter.handler(ctx, nettyProxyMsg);
}
@@ -44,7 +45,7 @@ public class NettyServerPermeateClientTransferHandler extends SimpleChannelInbou
if (nextChannel != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
closeVisitorMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(closeVisitorMsg);
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -7,7 +7,7 @@ import io.netty.handler.timeout.IdleStateEvent;
import java.util.Date;
public class HeartBeatClientHandler extends ChannelInboundHandlerAdapter {
public class TcpHeartBeatClientHandler extends ChannelInboundHandlerAdapter {
private final int lossConnectCount = 0;
@Override

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
import io.netty.bootstrap.Bootstrap;
@@ -7,11 +7,13 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientRealFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientTransferRealFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientRealFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientTransferRealFilter;
import org.framework.lazy.cloud.network.heartbeat.common.*;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.List;
@@ -21,7 +23,7 @@ import java.util.concurrent.TimeUnit;
* 客户端连接真实服务
*/
@Slf4j
public class NettyClientPermeateClientRealSocket {
public class NettyTcpClientPermeateClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
@@ -46,7 +48,7 @@ public class NettyClientPermeateClientRealSocket {
// .option(ChannelOption.SO_BACKLOG, 128)//务端接受连接的队列长度 默认128
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyClientPermeateClientRealFilter())
.handler(new NettyTcpClientPermeateClientRealFilter())
;
@@ -113,7 +115,7 @@ public class NettyClientPermeateClientRealSocket {
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyClientPermeateClientTransferRealFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
.handler(new NettyTcpClientPermeateClientTransferRealFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
;
String inetHost = nettyClientProperties.getInetHost();
@@ -140,7 +142,7 @@ public class NettyClientPermeateClientRealSocket {
nettyProxyMsg.setClientTargetIp(clientTargetIp);
nettyProxyMsg.setClientTargetPort(clientTargetPort);
nettyProxyMsg.setVisitorPort(visitorPort);
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
transferChannel.writeAndFlush(nettyProxyMsg);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);

View File

@@ -1,23 +1,24 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientVisitorFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientVisitorFilter;
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.List;
/**
* 内网穿透 客户端渗透客户端通道
*
@@ -25,17 +26,15 @@ import java.util.List;
* @see NettyClientVisitorContext
*/
@Slf4j
public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSocket {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
private final NettyClientPermeateClientVisitorFilter nettyClientPermeateClientVisitorFilter;
public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisitorSocket {
private final NettyTcpClientPermeateClientVisitorFilter nettyTcpClientPermeateClientVisitorFilter;
@Getter
private final String clientId;
@Getter
private final int visitorPort;
public NettyClientPermeateClientVisitorSocket(NettyClientPermeateClientVisitorFilter nettyClientPermeateClientVisitorFilter, String clientId, int visitorPort) {
this.nettyClientPermeateClientVisitorFilter = nettyClientPermeateClientVisitorFilter;
public NettyTcpClientPermeateClientVisitorSocket(NettyTcpClientPermeateClientVisitorFilter nettyTcpClientPermeateClientVisitorFilter, String clientId, int visitorPort) {
this.nettyTcpClientPermeateClientVisitorFilter = nettyTcpClientPermeateClientVisitorFilter;
this.clientId = clientId;
this.visitorPort = visitorPort;
}
@@ -50,6 +49,9 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
if (visitor == null) {
ServerBootstrap bootstrap = new ServerBootstrap();
EventLoopGroup bossGroup = EventLoopGroupFactory.createBossGroup();
EventLoopGroup workerGroup = EventLoopGroupFactory.createWorkerGroup();
bootstrap
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
@@ -68,7 +70,7 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.childHandler(nettyClientPermeateClientVisitorFilter);
.childHandler(nettyTcpClientPermeateClientVisitorFilter);
try {
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
@@ -94,12 +96,6 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
}
@Override
public void close() {
if (!bossGroup.isShutdown()) {
bossGroup.shutdownGracefully();
}
if (!workerGroup.isShutdown()) {
workerGroup.shutdownGracefully();
}
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
if (visitor != null) {
@@ -260,7 +256,7 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
this.toClientId = toClientId;
return this;
}
public NettyClientPermeateClientVisitorSocket build() {
public NettyTcpClientPermeateClientVisitorSocket build() {
if (clientTargetIp == null) {
throw new IllegalArgumentException("clientTargetIp must not null");
}
@@ -270,20 +266,20 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
if (visitorPort == null) {
throw new IllegalArgumentException("visitorPort must not null");
}
InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor = new InternalNetworkClientPermeateClientVisitor();
NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor = new NettyClientPermeateClientVisitor();
internalNetworkClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId());
internalNetworkClientPermeateClientVisitor.setToClientId(toClientId);
internalNetworkClientPermeateClientVisitor.setTargetIp(clientTargetIp);
internalNetworkClientPermeateClientVisitor.setTargetPort(clientTargetPort);
internalNetworkClientPermeateClientVisitor.setVisitorPort(visitorPort);
internalNetworkClientPermeateClientVisitor.setNettyClientProperties(nettyClientProperties);
internalNetworkClientPermeateClientVisitor.setChannelFlowAdapter(channelFlowAdapter);
internalNetworkClientPermeateClientVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
nettyClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId());
nettyClientPermeateClientVisitor.setToClientId(toClientId);
nettyClientPermeateClientVisitor.setTargetIp(clientTargetIp);
nettyClientPermeateClientVisitor.setTargetPort(clientTargetPort);
nettyClientPermeateClientVisitor.setVisitorPort(visitorPort);
nettyClientPermeateClientVisitor.setNettyClientProperties(nettyClientProperties);
nettyClientPermeateClientVisitor.setChannelFlowAdapter(channelFlowAdapter);
nettyClientPermeateClientVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
NettyClientPermeateClientVisitorFilter visitorFilter = new NettyClientPermeateClientVisitorFilter(internalNetworkClientPermeateClientVisitor);
return new NettyClientPermeateClientVisitorSocket(visitorFilter, clientId, visitorPort);
NettyTcpClientPermeateClientVisitorFilter visitorFilter = new NettyTcpClientPermeateClientVisitorFilter(nettyClientPermeateClientVisitor);
return new NettyTcpClientPermeateClientVisitorSocket(visitorFilter, clientId, visitorPort);
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
import io.netty.bootstrap.Bootstrap;
@@ -7,10 +7,10 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
@@ -20,13 +20,13 @@ import java.util.concurrent.TimeUnit;
* 客户端渗透服务端传输通道
*/
@Slf4j
public class NettyClientPermeateClientVisitorTransferSocket {
public class NettyTcpClientPermeateClientVisitorTransferSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/**
* 连接服务端通信通道
*/
public static void buildTransferServer(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor, Channel visitorChannel) {
public static void buildTransferServer(NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor, Channel visitorChannel) {
Bootstrap bootstrap = new Bootstrap();
@@ -43,21 +43,21 @@ public class NettyClientPermeateClientVisitorTransferSocket {
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyClientPermeateClientTransferFilter(new ChannelTypeAdapter(internalNetworkClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
.handler(new NettyTcpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
;
NettyClientProperties nettyClientProperties = internalNetworkClientPermeateClientVisitor.getNettyClientProperties();
NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties();
String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort();
// local client id
String clientId = nettyClientProperties.getClientId();
String targetIp = internalNetworkClientPermeateClientVisitor.getTargetIp();
Integer targetPort = internalNetworkClientPermeateClientVisitor.getTargetPort();
String targetIp = nettyClientPermeateClientVisitor.getTargetIp();
Integer targetPort = nettyClientPermeateClientVisitor.getTargetPort();
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
Integer visitorPort = internalNetworkClientPermeateClientVisitor.getVisitorPort();
String toClientId = internalNetworkClientPermeateClientVisitor.getToClientId();
Integer visitorPort = nettyClientPermeateClientVisitor.getVisitorPort();
String toClientId = nettyClientPermeateClientVisitor.getToClientId();
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {} with clientId:【{}】 toClientId:【{}】 & visitorId:【{}】", inetHost, inetPort, clientId, toClientId, visitorId);
@@ -69,7 +69,7 @@ public class NettyClientPermeateClientVisitorTransferSocket {
if (futureListener.isSuccess()) {
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
// other clientId
nettyProxyMsg.setClientId(toClientId);
nettyProxyMsg.setVisitorPort(visitorPort);
@@ -90,7 +90,7 @@ public class NettyClientPermeateClientVisitorTransferSocket {
log.info("无法连接到服务端....");
eventLoopGroup.schedule(() -> {
try {
buildTransferServer(internalNetworkClientPermeateClientVisitor, visitorChannel);
buildTransferServer(nettyClientPermeateClientVisitor, visitorChannel);
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -1,17 +1,17 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateServerVisitorFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateServerVisitorFilter;
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
@@ -24,17 +24,16 @@ import java.util.List;
* @see NettyClientVisitorContext
*/
@Slf4j
public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSocket {
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
private final NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter;
public class NettyTcpClientPermeateServerVisitorSocket implements PermeateVisitorSocket {
private final NettyTcpClientPermeateServerVisitorFilter nettyTcpClientPermeateServerVisitorFilter;
@Getter
private final String clientId;
@Getter
private final int visitorPort;
public NettyClientPermeateServerVisitorSocket(NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter, String clientId, int visitorPort) {
this.nettyClientPermeateServerVisitorFilter = nettyClientPermeateServerVisitorFilter;
public NettyTcpClientPermeateServerVisitorSocket(NettyTcpClientPermeateServerVisitorFilter nettyTcpClientPermeateServerVisitorFilter, String clientId, int visitorPort) {
this.nettyTcpClientPermeateServerVisitorFilter = nettyTcpClientPermeateServerVisitorFilter;
this.clientId = clientId;
this.visitorPort = visitorPort;
}
@@ -49,6 +48,8 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
PermeateVisitorSocket visitor = NettyVisitorPortContext.getVisitorSocket(visitorPort);
if (visitor == null) {
ServerBootstrap bootstrap = new ServerBootstrap();
EventLoopGroup bossGroup = EventLoopGroupFactory.createBossGroup();
EventLoopGroup workerGroup = EventLoopGroupFactory.createWorkerGroup();
bootstrap
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
@@ -67,7 +68,7 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.childHandler(nettyClientPermeateServerVisitorFilter);
.childHandler(nettyTcpClientPermeateServerVisitorFilter);
try {
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
@@ -91,12 +92,6 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
}
@Override
public void close() {
if (!bossGroup.isShutdown()) {
bossGroup.shutdownGracefully();
}
if (!workerGroup.isShutdown()) {
workerGroup.shutdownGracefully();
}
PermeateVisitorSocket permeateVisitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
if (permeateVisitorSocket != null) {
log.warn("关闭客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
@@ -208,7 +203,7 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
}
public NettyClientPermeateServerVisitorSocket build() {
public NettyTcpClientPermeateServerVisitorSocket build() {
if (clientTargetIp == null) {
throw new IllegalArgumentException("clientTargetIp must not null");
}
@@ -218,17 +213,17 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
if (visitorPort == null) {
throw new IllegalArgumentException("visitorPort must not null");
}
InternalNetworkClientPermeateServerVisitor internalNetworkClientPermeateServerVisitor = new InternalNetworkClientPermeateServerVisitor();
NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor = new NettyClientPermeateServerVisitor();
internalNetworkClientPermeateServerVisitor.setTargetIp(clientTargetIp);
internalNetworkClientPermeateServerVisitor.setTargetPort(clientTargetPort);
internalNetworkClientPermeateServerVisitor.setVisitorPort(visitorPort);
internalNetworkClientPermeateServerVisitor.setNettyClientProperties(nettyClientProperties);
internalNetworkClientPermeateServerVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
nettyClientPermeateServerVisitor.setTargetIp(clientTargetIp);
nettyClientPermeateServerVisitor.setTargetPort(clientTargetPort);
nettyClientPermeateServerVisitor.setVisitorPort(visitorPort);
nettyClientPermeateServerVisitor.setNettyClientProperties(nettyClientProperties);
nettyClientPermeateServerVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter = new NettyClientPermeateServerVisitorFilter(internalNetworkClientPermeateServerVisitor);
return new NettyClientPermeateServerVisitorSocket(nettyClientPermeateServerVisitorFilter, clientId, visitorPort);
NettyTcpClientPermeateServerVisitorFilter nettyTcpClientPermeateServerVisitorFilter = new NettyTcpClientPermeateServerVisitorFilter(nettyClientPermeateServerVisitor);
return new NettyTcpClientPermeateServerVisitorSocket(nettyTcpClientPermeateServerVisitorFilter, clientId, visitorPort);
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
import io.netty.bootstrap.Bootstrap;
@@ -7,10 +7,10 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateServerTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateServerTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
@@ -20,15 +20,15 @@ import java.util.concurrent.TimeUnit;
* 客户端渗透服务端传输通道
*/
@Slf4j
public class NettyClientPermeateServerVisitorTransferSocket {
public class NettyTcpClientPermeateServerVisitorTransferSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/**
* 连接服务端通信通道
* <p>
* internalNetworkClientPermeateServerVisitor
* nettyClientPermeateServerVisitor
*/
public static void buildTransferServer(InternalNetworkClientPermeateServerVisitor internalNetworkClientPermeateServerVisitor, Channel visitorChannel) {
public static void buildTransferServer(NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor, Channel visitorChannel) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup)
@@ -45,20 +45,20 @@ public class NettyClientPermeateServerVisitorTransferSocket {
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyClientPermeateServerTransferFilter(new ChannelTypeAdapter(internalNetworkClientPermeateServerVisitor.getHandleChannelTypeAdvancedList())))
.handler(new NettyTcpClientPermeateServerTransferFilter(new ChannelTypeAdapter(nettyClientPermeateServerVisitor.getHandleChannelTypeAdvancedList())))
;
NettyClientProperties nettyClientProperties = internalNetworkClientPermeateServerVisitor.getNettyClientProperties();
NettyClientProperties nettyClientProperties = nettyClientPermeateServerVisitor.getNettyClientProperties();
String inetHost = nettyClientProperties.getInetHost();
int inetPort = nettyClientProperties.getInetPort();
// local client id
String clientId = nettyClientProperties.getClientId();
String targetIp = internalNetworkClientPermeateServerVisitor.getTargetIp();
Integer targetPort = internalNetworkClientPermeateServerVisitor.getTargetPort();
String targetIp = nettyClientPermeateServerVisitor.getTargetIp();
Integer targetPort = nettyClientPermeateServerVisitor.getTargetPort();
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
Integer visitorPort = internalNetworkClientPermeateServerVisitor.getVisitorPort();
Integer visitorPort = nettyClientPermeateServerVisitor.getVisitorPort();
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
log.debug("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
@@ -71,7 +71,7 @@ public class NettyClientPermeateServerVisitorTransferSocket {
if (futureListener.isSuccess()) {
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.TCP_REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
myMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
myMsg.setClientId(clientId);
myMsg.setVisitorPort(visitorPort);
myMsg.setClientTargetIp(targetIp);
@@ -89,7 +89,7 @@ public class NettyClientPermeateServerVisitorTransferSocket {
log.warn("客户端渗透服务端通信通道中断....");
eventLoopGroup.schedule(() -> {
try {
buildTransferServer(internalNetworkClientPermeateServerVisitor, visitorChannel);
buildTransferServer(nettyClientPermeateServerVisitor, visitorChannel);
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -0,0 +1,150 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientFilter;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyServerContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.net.InetAddress;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 客户端连接服务端
*/
@Slf4j
public class NettyTcpClientSocket implements NettyClientSocket {
private final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/**
* 服务端host
*/
private final String inetHost;
/**
* 服务端端口
*/
private final int inetPort;
/**
* 当前客户端id
*/
@Getter
private final String clientId;
/**
* 当前连接的服务端ID
*/
private final String serverId;
private final String appKey;
private final String appSecret;
/**
* 客户端状态变更事件
*/
@Getter
private final ClientChangeEvent clientChangeEvent;
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
public NettyTcpClientSocket(String inetHost,
int inetPort,
String clientId,
String serverId,
String appKey,
String appSecret,
ClientChangeEvent clientChangeEvent,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.inetHost = inetHost;
this.inetPort = inetPort;
this.clientId = clientId;
this.serverId = serverId;
this.appKey = appKey;
this.appSecret = appSecret;
this.clientChangeEvent = clientChangeEvent;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
protected void newTcpConnect2Server(String inetHost, int inetPort, String clientId, String serverId, ClientChangeEvent clientChangeEvent) throws InterruptedException {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
// 设置写缓冲区为1M
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
.option(ChannelOption.SO_KEEPALIVE, true)
// .childOption(ChannelOption.TCP_NODELAY, false)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
// .childOption(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyTcpClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this))
;
log.info("use clientId:{} connect to server IP:{},server port :{}", clientId, inetHost, inetPort);
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
// 客户端连接服务端的channel
Channel serviceChannel = future.channel();
future.addListener((ChannelFutureListener) futureListener -> {
if (futureListener.isSuccess()) {
log.info("clientId:{},connect to server IP:{},server port :{} isSuccess ", clientId, inetHost, inetPort);
// 告诉服务端这条连接是client的连接
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setClientId(clientId);
String hostAddress = InetAddress.getLocalHost().getHostAddress();
nettyMsg.setOriginalIpString(hostAddress);
nettyMsg.setData((clientId).getBytes());
nettyMsg.setAppKeyString(appKey);
nettyMsg.setAppSecretString(appSecret);
ChannelAttributeKeyUtils.buildClientId(serviceChannel, clientId);
serviceChannel.writeAndFlush(nettyMsg);
NettyServerContext.pushServerEndpointChannel(serverId, clientId, serviceChannel);
// 在线 客户端注册服务端成功
clientChangeEvent.clientOnLine(inetHost, inetPort,serverId, clientId);
} else {
log.warn("Reconnect every 2 seconds....");
// 离线
NettyServerContext.removeServerEndpointChannels(serverId, clientId);
clientChangeEvent.clientOffLine(inetHost, inetPort,serverId, clientId);
eventLoopGroup.schedule(() -> {
try {
newTcpConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent);
} catch (InterruptedException e) {
e.printStackTrace();
}
}, 2, TimeUnit.SECONDS);
}
});
}
/**
* 关闭连接
*/
public void shutdown() {
if ((eventLoopGroup != null) && (!eventLoopGroup.isShutdown())) {
eventLoopGroup.shutdownGracefully();
}
}
/**
* 创建客户端链接服务端
*
* @throws InterruptedException 异常信息
*/
@Override
public void newConnect2Server() throws InterruptedException {
newTcpConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent);
}
}

View File

@@ -1,4 +1,4 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
import io.netty.bootstrap.Bootstrap;
@@ -7,11 +7,13 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyServerPermeateClientRealFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyServerPermeateClientTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpServerPermeateClientRealFilter;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpServerPermeateClientTransferFilter;
import org.framework.lazy.cloud.network.heartbeat.common.*;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.List;
@@ -21,7 +23,7 @@ import java.util.concurrent.TimeUnit;
* 客户端连接真实服务
*/
@Slf4j
public class NettyServerPermeateClientRealSocket {
public class NettyTcpServerPermeateClientRealSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/**
@@ -62,7 +64,7 @@ public class NettyServerPermeateClientRealSocket {
// .option(ChannelOption.SO_BACKLOG, 128)//务端接受连接的队列长度 默认128
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyServerPermeateClientRealFilter())
.handler(new NettyTcpServerPermeateClientRealFilter())
;
@@ -149,7 +151,7 @@ public class NettyServerPermeateClientRealSocket {
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyServerPermeateClientTransferFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
.handler(new NettyTcpServerPermeateClientTransferFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
;
String inetHost = nettyClientProperties.getInetHost();
@@ -176,7 +178,7 @@ public class NettyServerPermeateClientRealSocket {
if (futureListener.isSuccess()) {
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.TCP_REPORT_SINGLE_CLIENT_REAL_CONNECT);
myMsg.setType(TcpMessageType.TCP_REPORT_SINGLE_CLIENT_REAL_CONNECT);
myMsg.setClientId(visitorClientId);
myMsg.setVisitorPort(visitorPort);
myMsg.setClientTargetIp(clientTargetIp);

View File

@@ -0,0 +1,32 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.AbstractUdpHandleChannelHeartbeatTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.constant.UdpMessageType;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
/**
* 服务端 处理客户端心跳
* UDP_TYPE_HEARTBEAT
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class ClientHandleUdpChannelHeartbeatTypeAdvanced extends AbstractUdpHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param nettyChannelContext 当前通道
* @param msg 通道数据
*/
@Override
public void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg msg) {
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(UdpMessageType.UDP_TYPE_HEARTBEAT);
// nettyChannelContext.writeAndFlush(nettyProxyMsg);
}
}

Some files were not shown because too many files have changed in this diff Show More