Merge remote-tracking branch 'origin/1.2.2-JDK17-SNAPSHOT'

This commit is contained in:
wujiawei 2024-02-06 17:50:19 +08:00
commit 58736928b0
391 changed files with 47181 additions and 2018 deletions

View File

@ -2,11 +2,11 @@
#### 模块说明
| 模块 | 所属层级 | 描述 | 端口 |
|----------------------------------------------------------------------------------------|------|------------------------|----------------------------------------------------------------|
| [middleground-cloud-heartbeat-common](middleground-cloud-heartbeat-common) | 基础模块 | 基于Netty数据解码、编码、通道处理器声明 | 无 |
| [middleground-on-cloud-heartbeat-server](middleground-on-cloud-heartbeat-server) | 启动模块 | 内网穿透服务端 | http端口6001、tcp端口:7001 (默认tcp端口=http端口+1000 如6001+1000=7001) |
| [middleground-under-cloud-heartbeat-client](middleground-under-cloud-heartbeat-client) | 启动模块 | 内网穿透客户端 | 6004 |
| 模块 | 所属层级 | 描述 | 端口 |
|------------------------------------------------------------------|------|------------------------|----------------------------------------------------------------|
| [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 |
#### 功能
@ -52,13 +52,13 @@ spring:
如果云端需要部署云上暂存+内网穿透功能:需要部署 内网穿透服务端、暂存服务、内网穿透客户端、云上离线网关
```
| 模块 | 说明 | 部署内网穿透必须 | 部署内网穿透+云上暂存必须 |
|----------------------------------------------------------------------------------------|------------|----------|---------------|
| [middleground-on-cloud-heartbeat-server](middleground-on-cloud-heartbeat-server) | 内网穿透+心跳服务端 | ☑️ | ☑️ |
| [middleground-under-cloud-heartbeat-client](middleground-under-cloud-heartbeat-client) | 内网穿透+心跳客户端 | ✖️ | ☑️ |
| [middleground-cloud-staging-provider](middleground-cloud-staging-provider) | 暂存服务 | ✖️ | ☑️ |
| [middleground-on-cloud-central-gateway](middleground-on-cloud-central-gateway) | 云上暂存网关 | ✖️ | ☑️ |
| [middleground-under-cloud-central-gateway](middleground-under-cloud-central-gateway) | 云下暂存网关 | ✖️ | ✖️ |
| 模块 | 说明 | 部署内网穿透必须 | 部署内网穿透+云上暂存必须 |
|------------------------------------------------------------------|------------|----------|---------------|
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 内网穿透+心跳服务端 | ☑️ | ☑️ |
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 内网穿透+心跳客户端 | ✖️ | ☑️ |
| [wu-lazy-cloud-staging-provider](wu-lazy-cloud-staging-provider) | 暂存服务 | ✖️ | ☑️ |
| [wu-lazy-cloud-central-gateway](wu-lazy-cloud-central-gateway) | 云上暂存网关 | ✖️ | ☑️ |
| [wu-lazy-cloud-central-gateway](wu-lazy-cloud-central-gateway) | 云下暂存网关 | ✖️ | ✖️ |
##### 云网关部署
@ -66,13 +66,13 @@ spring:
云网关部署内网穿透客户端
```
| 模块 | 说明 | 部署内网穿透必须 | 部署内网穿透+云上暂存必须 |
|----------------------------------------------------------------------------------------|------------|----------|---------------|
| [middleground-on-cloud-heartbeat-server](middleground-on-cloud-heartbeat-server) | 内网穿透+心跳服务端 | ✖️ | ✖️ |
| [middleground-under-cloud-heartbeat-client](middleground-under-cloud-heartbeat-client) | 内网穿透+心跳客户端 | ✖️ | ☑️ |
| [middleground-cloud-staging-provider](middleground-cloud-staging-provider) | 暂存服务 | ✖️ | ✖️ |
| [middleground-on-cloud-central-gateway](middleground-on-cloud-central-gateway) | 云上暂存网关 | ✖️ | ☑️ |
| [middleground-under-cloud-central-gateway](middleground-under-cloud-central-gateway) | 云下暂存网关 | ✖️ | ✖️ |
| 模块 | 说明 | 部署内网穿透必须 | 部署内网穿透+云上暂存必须 |
|------------------------------------------------------------------|------------|----------|---------------|
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 内网穿透+心跳服务端 | ✖️ | ✖️ |
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 内网穿透+心跳客户端 | ✖️ | ☑️ |
| [wu-lazy-cloud-staging-provider](wu-lazy-cloud-staging-provider) | 暂存服务 | ✖️ | ✖️ |
| [wu-lazy-cloud-central-gateway](wu-lazy-cloud-central-gateway) | 云上暂存网关 | ✖️ | ☑️ |
| [wu-lazy-cloud-central-gateway](wu-lazy-cloud-central-gateway) | 云下暂存网关 | ✖️ | ✖️ |
##### 独立租户部署
@ -81,12 +81,12 @@ spring:
内网穿透+离线暂存能力: 需要部署内网穿透客户端、离线网关、离线暂存服务
```
| 模块 | 说明 | 部署内网穿透必须 | 部署内网穿透+云上暂存必须 |
|----------------------------------------------------------------------------------------|------------|----------|---------------|
| [middleground-on-cloud-heartbeat-server](middleground-on-cloud-heartbeat-server) | 内网穿透+心跳服务端 | ✖️ | ✖️ |
| [middleground-under-cloud-heartbeat-client](middleground-under-cloud-heartbeat-client) | 内网穿透+心跳客户端 | ☑️ | ☑️ |
| [middleground-cloud-staging-provider](middleground-cloud-staging-provider) | 暂存服务 | ✖️ | ☑️ |
| [middleground-on-cloud-central-gateway](middleground-on-cloud-central-gateway) | 云上暂存网关 | ✖️ | ✖️ |
| [middleground-under-cloud-central-gateway](middleground-under-cloud-central-gateway) | 云下暂存网关 | ✖️ | ☑️ |
| 模块 | 说明 | 部署内网穿透必须 | 部署内网穿透+云上暂存必须 |
|------------------------------------------------------------------|------------|----------|---------------|
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 内网穿透+心跳服务端 | ✖️ | ✖️ |
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 内网穿透+心跳客户端 | ☑️ | ☑️ |
| [wu-lazy-cloud-staging-provider](wu-lazy-cloud-staging-provider) | 暂存服务 | ✖️ | ☑️ |
| [wu-lazy-cloud-central-gateway](wu-lazy-cloud-central-gateway) | 云上暂存网关 | ✖️ | ✖️ |
| [wu-lazy-cloud-central-gateway](wu-lazy-cloud-central-gateway) | 云下暂存网关 | ✖️ | ☑️ |

102
README.md
View File

@ -1,17 +1,101 @@
原理分析 内网穿透的实现过程主要分三步
1、启动服务端这时服务端监听了两个端口1600116002可根据启动参数修改
<p align="center">
<a target="_blank" href="https://search.maven.org/search?q=wu-lazy-cloud-network%20wu-lazy-cloud-network">
<img src="https://img.shields.io/nexus/s/top.wu2020/wu-lazy-cloud-network?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-network%20wu-lazy-cloud-network">
<img src="https://img.shields.io/maven-central/v/top.wu2020/wu-lazy-cloud-network" alt="Maven" />
</a>
<a target="_blank" href="https://www.apache.org/licenses/LICENSE-2.0.txt">
<img src="https://img.shields.io/:license-Apache2-blue.svg" alt="Apache 2" />
</a>
<a target="_blank" href="https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html">
<img src="https://img.shields.io/badge/JDK-11-green.svg" alt="jdk-11" />
</a>
<a target="_blank" href="https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html">
<img src="https://img.shields.io/badge/JDK-17-green.svg" alt="jdk-17" />
</a>
<br />
<img src="https://img.shields.io/badge/SpringBoot-v3.x-blue">
<br />
<a target="_blank" href='https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network'>
<img src='https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network/badge/star.svg' alt='Gitee star'/>
</a>
一个用来接收客户端请求16001端口
</p>
一个用来接收访客代理16002端口
#### 项目介绍
wu-lazy-cloud-network 是一款基于wu-framework-parent孵化出的项目内部使用Lazy ORM操作数据库主要功能是网络穿透对于没有公网IP的服务进行公网IP映射
使用环境JDK17 Spring Boot 3.0.2
### 功能
1.内网穿透
2.服务端自主下发数据到客户端
3.流量监控
2、启动客户端客户端访问服务端提供的16001端口建立连接server-client通道
3、访客访问代理接口16002端口服务端监听到之后创建访客ID然后通过server-client通道向客户端发送指令客户端接收指令后连接到真实服务端口8080可根据启动参数修改连接真实服务成功后客户端会重新向服务端建立一条连接访客-server通道服务端把访客和该通道进行绑定
### 项目结构
这三步最终形成了(访客-代理-客户端-真实服务)完整的通道。
| 模块 | 版本 | 描述 |
|---------------------------------------------------------------------------------------------------------------|----------------------|------------------------------|
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 1.2.2-JDK17-SNAPSHOT | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) |
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 1.2.2-JDK17-SNAPSHOT | 客户端(支持二次开发) |
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 1.2.2-JDK17-SNAPSHOT | 服务端(支持二次开发) |
| [wu-lazy-cloud-network-ui](wu-lazy-cloud-network-ui) | 1.2.2-JDK17-SNAPSHOT | 服务端页面 |
| [wu-lazy-cloud-heartbeat-client-sample](wu-lazy-cloud-heartbeat-sample/wu-lazy-cloud-heartbeat-client-sample) | 1.2.2-JDK17-SNAPSHOT | 客户端样例 |
| [wu-lazy-cloud-heartbeat-server-sample](wu-lazy-cloud-heartbeat-sample/wu-lazy-cloud-heartbeat-server-sample) | 1.2.2-JDK17-SNAPSHOT | 服务端样例 |
启动服务端 java -jar cc-server.jar 16001 16002
启动客户端 java -jar cc-client.jar 127.0.0.1 16001 8080
### 使用技术
| 框架 | 版本 | 描述 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|--------------|
| spring-boot | 3.0.7 | springboot框架 |
| [wu-framework-web](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-framework-web) | 1.2.2-JDK17-SNAPSHOT | web容器 |
| [Lazy -ORM](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-inner-intergration/wu-database-parent) | 1.2.2-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.2-JDK17-SNAPSHOT | 用户授权体系 |
### 使用环境
IDEA
Mac、Windows
JAVA >=13
MAVEN
### 启动
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.2-JDK17-SNAPSHOT
http://127.0.0.1:18080/swagger-ui/index.html
源码启动
#### 页面操作
启动项目后打开服务端界面
![img.png](url_info.png)
默认账号密码admin/admin
![img.png](login.png)
初始化项目
![img.png](init_menu.png)
添加角色
![img.png](init_role.png)
为用户授权
![img.png](authRoe2User.png)
刷新页面
![img.png](cloud_client.png)
客户端管理(客户端会自动注册)
![img.png](cloud_client.png)
网络映射管理(修改后者新增需要映射的客户端)
![img.png](mapping.png)
访客端口池管理(服务器端需要开放的端口)
![img.png](visitor_port.png)
流量管理(每个客户端使用的流量)
![img.png](flow.png)

BIN
authRoe2User.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
cloud_client.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

BIN
flow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

BIN
init_menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
init_role.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

@ -1,152 +0,0 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
k8s.kuboard.cn/displayName: 【云上云下】云上心跳服务端(新)
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: middleground-on-cloud-heartbeat-server
name: middleground-on-cloud-heartbeat-server
namespace: middleground-management
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: middleground-on-cloud-heartbeat-server
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: middleground-on-cloud-heartbeat-server
spec:
containers:
- envFrom:
- configMapRef:
name: common-cnf
image: >-
docker-registry.laihui.com/middleground/middleground-on-cloud-heartbeat-server:master_latest
imagePullPolicy: Always
name: middleground-on-cloud-heartbeat-server
resources:
limits:
memory: 512Mi
requests:
memory: 512Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
k8s.kuboard.cn/displayName: 【云上云下】云上中心网关(新)
labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: middleground-on-cloud-central-gateway
name: middleground-on-cloud-central-gateway
namespace: middleground-management
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: middleground-on-cloud-central-gateway
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: middleground-on-cloud-central-gateway
spec:
containers:
- envFrom:
- configMapRef:
name: common-cnf
image: >-
docker-registry.laihui.com/middleground/middleground-on-cloud-central-gateway:master_latest
imagePullPolicy: Always
name: middleground-on-cloud-central-gateway
resources:
limits:
memory: 384Mi
requests:
memory: 384Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
k8s.kuboard.cn/displayName: 【云上云下】暂存服务(新)
labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: middleground-cloud-staging-provider
name: middleground-cloud-staging-provider
namespace: middleground-management
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: middleground-cloud-staging-provider
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: middleground-cloud-staging-provider
spec:
containers:
- envFrom:
- configMapRef:
name: common-cnf
image: >-
docker-registry.laihui.com/middleground/middleground-cloud-staging-provider:master_latest
imagePullPolicy: Always
name: middleground-cloud-staging-provider
resources:
limits:
memory: 384Mi
requests:
memory: 384Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30

View File

@ -1,154 +0,0 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
k8s.kuboard.cn/displayName: 【云上云下】云下心跳客户端(新)
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: middleground-under-cloud-heartbeat-client
name: middleground-under-cloud-heartbeat-client
namespace: middleground-tenant-share
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: middleground-under-cloud-heartbeat-client
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: middleground-under-cloud-heartbeat-client
spec:
containers:
- envFrom:
- configMapRef:
name: common-cnf
image: >-
docker-registry.laihui.com/middleground/middleground-under-cloud-heartbeat-client:master_latest
imagePullPolicy: Always
name: middleground-under-cloud-heartbeat-client
resources:
limits:
memory: 384Mi
requests:
memory: 384Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
k8s.kuboard.cn/displayName: 【云上云下】云下中心网关(新)
labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: middleground-under-cloud-central-gateway
name: middleground-under-cloud-central-gateway
namespace: middleground-tenant-share
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: middleground-under-cloud-central-gateway
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: middleground-under-cloud-central-gateway
spec:
containers:
- envFrom:
- configMapRef:
name: common-cnf
image: >-
docker-registry.laihui.com/middleground/middleground-under-cloud-central-gateway:master_latest
imagePullPolicy: Always
name: middleground-under-cloud-central-gateway
resources:
limits:
memory: 384Mi
requests:
memory: 384Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
k8s.kuboard.cn/displayName: 【云上云下】云下暂存服务(新)
labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: middleground-cloud-staging-provider
name: middleground-cloud-staging-provider
namespace: middleground-tenant-share
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: middleground-cloud-staging-provider
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: middleground-cloud-staging-provider
spec:
containers:
- envFrom:
- configMapRef:
name: common-cnf
image: >-
docker-registry.laihui.com/middleground/middleground-cloud-staging-provider:master_latest
imagePullPolicy: Always
name: middleground-cloud-staging-provider
resources:
limits:
memory: 384Mi
requests:
memory: 384Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30

BIN
login.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 KiB

BIN
main.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

BIN
mapping.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

View File

@ -8,13 +8,13 @@
<parent>
<artifactId>wu-framework-parent</artifactId>
<groupId>top.wu2020</groupId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
<relativePath/>
</parent>
<artifactId>wu-lazy-cloud-network</artifactId>
<packaging>pom</packaging>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
<description>云上云下</description>
@ -70,7 +70,7 @@
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-framework-dependencies</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>

BIN
url_info.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

BIN
visitor_port.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

View File

@ -5,7 +5,7 @@ MAINTAINER wujiawei <1207537021@qq.com>
RUN echo "Asia/Shanghai" > /etc/timezone
COPY target/middleground-under-cloud-heartbeat-client /native-app
COPY target/lazy-cloud-heartbeat-client /native-app
ENTRYPOINT ["/bin/sh" ,"-c", "exec ./native-app"]

View File

@ -1,20 +1,19 @@
#### 构建native 镜像
```shell
mvn clean compile
mvn spring-boot:process-aot -Pnative
mvn native:build -Pnative
```
### 构建docker镜像
```shell
docker build -t docker-registry.laihui.com/middleground/middleground-under-cloud-heartbeat-client:middleground-2.4.2-native-SNAPSHOT_latest -f Native-Dockerfile .
docker push docker-registry.laihui.com/middleground/middleground-under-cloud-heartbeat-client:middleground-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
```shell
@ -26,16 +25,15 @@ docker push registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-cl
```
### run
```shell
docker run -d -it --name client -e spring.middleground.netty.inet-host=124.222.48.62 -e spring.middleground.netty.inet-port=30676 -e spring.middleground.netty.client-id=node1 registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:server-jdk17-master
docker run -d -it --name client -e spring.lazy.netty.inet-host=124.222.48.62 -e spring.lazy.netty.inet-port=30676 -e spring.lazy.netty.client-id=node1 registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:server-jdk17-master
```
```shell
gu install native-image

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-network</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -20,9 +20,9 @@
<dependencies>
<!-- 通用心跳包 -->
<dependency>
<groupId>top.wu2020</groupId>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-common</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>

View File

@ -6,7 +6,6 @@ package wu.framework.lazy.cloud.heartbeat.client.application;
public interface ClientNettyConfigApplication {
/**
* 推送客户端在线
*/
@ -19,14 +18,16 @@ public interface ClientNettyConfigApplication {
/**
* 暂存开启
* @param clientId 租户ID
*
* @param clientId 租户ID
*/
void stagingOpen(String clientId);
/**
* 暂存关闭
* @param clientId 客户端ID 对应的租户
*
* @param clientId 客户端ID 对应的租户
*/
void stagingClose(String clientId);
}

View File

@ -1,9 +1,9 @@
package wu.framework.lazy.cloud.heartbeat.client.application.impl;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import com.wu.framework.database.lazy.web.plus.stereotype.LazyApplication;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
@Slf4j
@LazyApplication

View File

@ -1,11 +1,11 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelHeartbeatTypeAdvanced;
import io.netty.channel.Channel;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
/**
@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
* TYPE_HEARTBEAT
*/
@Component
public class ClientChannelHeartbeatTypeAdvanced extends AbstractChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
public class ClientHandleChannelHeartbeatTypeAdvanced extends AbstractHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据

View File

@ -0,0 +1,28 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientMessageTypeAdvanced;
/**
* 接收服务端发送过来的聊天信息
*/
@Slf4j
@Component
public class ClientHandleDistributeSingleClientMessageTypeAdvanced extends AbstractHandleDistributeSingleClientMessageTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
byte[] clientId = nettyProxyMsg.getClientId();
byte[] data = nettyProxyMsg.getData();
log.info("接收客户端:{},发送过来的聊天信息:{}", new String(clientId), new String(data));
}
}

View File

@ -1,16 +1,16 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyRealIdContext;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeSingleClientRealAutoReadConnectTypeAdvanced;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyRealIdContext;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced;
@Slf4j
@Component
public class ClientDistributeSingleClientRealAutoReadConnectTypeAdvanced extends AbstractDistributeSingleClientRealAutoReadConnectTypeAdvanced<NettyProxyMsg> {
public class ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced extends AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
@ -22,7 +22,7 @@ public class ClientDistributeSingleClientRealAutoReadConnectTypeAdvanced extends
// 获取访客ID
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 获取访客对应的真实代理通道
Channel realChannel = NettyRealIdContext.getVisitor(visitorId);
Channel realChannel = NettyRealIdContext.getReal(visitorId);
if (realChannel != null) {
realChannel.config().setOption(ChannelOption.AUTO_READ, true);
}

View File

@ -1,16 +1,16 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyCommunicationIdContext;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyRealIdContext;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeSingleClientRealCloseVisitorTypeAdvanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.common.NettyCommunicationIdContext;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyRealIdContext;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced;
@Slf4j
@Component
public class ClientDistributeSingleClientRealCloseVisitorTypeAdvanced extends AbstractDistributeSingleClientRealCloseVisitorTypeAdvanced<NettyProxyMsg> {
public class ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced extends AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*

View File

@ -1,14 +1,14 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientRealSocket;
import wu.framework.lazy.cloud.heartbeat.common.InternalNetworkPenetrationRealClient;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeSingleClientRealConnectTypeAdvanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealConnectTypeAdvanced;
import java.util.List;
@ -17,14 +17,14 @@ import java.util.List;
*/
@Slf4j
@Component
public class ClientDistributeSingleClientRealConnectTypeAdvanced extends AbstractDistributeSingleClientRealConnectTypeAdvanced<NettyProxyMsg> {
public class ClientHandleDistributeSingleClientRealConnectTypeAdvanced extends AbstractHandleDistributeSingleClientRealConnectTypeAdvanced<NettyProxyMsg> {
private final NettyServerProperties nettyServerProperties;// 服务端地址信息
private final List<ChannelTypeAdvanced> channelTypeAdvancedList;
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
public ClientDistributeSingleClientRealConnectTypeAdvanced(NettyServerProperties nettyServerProperties, List<ChannelTypeAdvanced> channelTypeAdvancedList) {
public ClientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyServerProperties nettyServerProperties, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.nettyServerProperties = nettyServerProperties;
this.channelTypeAdvancedList = channelTypeAdvancedList;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
/**
@ -41,16 +41,18 @@ public class ClientDistributeSingleClientRealConnectTypeAdvanced extends Abstrac
byte[] clientTargetIp = msg.getClientTargetIp();
byte[] clientTargetPort = msg.getClientTargetPort();
byte[] visitorIdBytes = msg.getVisitorId();
InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient = new InternalNetworkPenetrationRealClient();
internalNetworkPenetrationRealClient.setClientId(new String(clientIdBytes));
internalNetworkPenetrationRealClient.setVisitorPort(Integer.valueOf(new String(visitorPort)));
internalNetworkPenetrationRealClient.setClientTargetIp(new String( clientTargetIp));
internalNetworkPenetrationRealClient.setClientTargetPort(Integer.valueOf(new String( clientTargetPort)));
String visitorId=new String(visitorIdBytes);// 访客ID
internalNetworkPenetrationRealClient.setVisitorId(visitorId);
InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient =
InternalNetworkPenetrationRealClient
.builder()
.clientId(new String(clientIdBytes))
.visitorPort(Integer.valueOf(new String(visitorPort)))
.clientTargetIp(new String(clientTargetIp))
.clientTargetPort(Integer.valueOf(new String(clientTargetPort)))
.visitorId(new String(visitorIdBytes))
.build();
// 绑定真实服务端口
NettyClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient,nettyServerProperties,channelTypeAdvancedList );
NettyClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyServerProperties, handleChannelTypeAdvancedList);
}
}

View File

@ -1,28 +1,29 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyRealIdContext;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeChannelTransferTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyRealIdContext;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeChannelTransferTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 服务端处理客户端数据传输
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
*/
@Slf4j
@Component
public class ClientReportChannelTransferTypeAdvanced extends AbstractDistributeChannelTransferTypeAdvanced<NettyProxyMsg> {
public class ClientReportHandleChannelTransferTypeAdvancedHandleDistribute extends AbstractHandleDistributeChannelTransferTypeAdvanced<NettyProxyMsg> {
private final NettyServerProperties nettyServerProperties;
public ClientReportChannelTransferTypeAdvanced(NettyServerProperties nettyServerProperties) {
public ClientReportHandleChannelTransferTypeAdvancedHandleDistribute(NettyServerProperties nettyServerProperties) {
this.nettyServerProperties = nettyServerProperties;
}
@ -41,7 +42,7 @@ public class ClientReportChannelTransferTypeAdvanced extends AbstractDistributeC
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
byte[] visitorId = nettyProxyMsg.getVisitorId();
// 真实服务通道
Channel realChannel = NettyRealIdContext.getVisitor(new String(visitorId));
Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
if (realChannel == null) {
log.error("无法获取访客:{} 真实服务", new String(visitorId));
return;

View File

@ -0,0 +1,33 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.common.ChannelContext;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleClientChannelActiveAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
/**
* 客户端通道 is active
*/
public class HandleClientChannelActiveAdvanced extends AbstractHandleClientChannelActiveAdvanced<NettyProxyMsg> {
private final NettyServerProperties nettyServerProperties;
public HandleClientChannelActiveAdvanced(NettyServerProperties nettyServerProperties) {
this.nettyServerProperties = nettyServerProperties;
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
// 缓存当前通道
String clientId = nettyServerProperties.getClientId();
ChannelContext.push(channel, clientId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
}
}

View File

@ -1,17 +1,13 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import com.alibaba.fastjson.JSONObject;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.common.ChannelContext;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeConnectSuccessNotificationTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
@ -19,14 +15,13 @@ import java.util.List;
*/
@Slf4j
@Component
public class DistributeConnectSuccessNotificationTypeAdvanced extends AbstractDistributeConnectSuccessNotificationTypeAdvanced <NettyProxyMsg>{
public class HandleDistributeConnectSuccessNotificationTypeAdvancedHandle extends AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle<NettyProxyMsg> {
private final ClientNettyConfigApplication clientNettyConfigApplication;
private final NettyServerProperties nettyServerProperties;
public DistributeConnectSuccessNotificationTypeAdvanced(ClientNettyConfigApplication clientNettyConfigApplication, NettyServerProperties nettyServerProperties) {
public HandleDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientNettyConfigApplication clientNettyConfigApplication) {
this.clientNettyConfigApplication = clientNettyConfigApplication;
this.nettyServerProperties = nettyServerProperties;
}
/**
@ -39,12 +34,7 @@ public class DistributeConnectSuccessNotificationTypeAdvanced extends AbstractDi
protected void doHandler(Channel channel, NettyProxyMsg msg) {
log.warn("客户端ID{},客户端:{}连接成功", new String(msg.getClientId()), new String(msg.getData()));
// 缓存当前通道
String clientId = nettyServerProperties.getClientId();
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
ChannelContext.push(channel, nettyMsg);
ChannelAttributeKeyUtils.buildClientId(channel,clientId);
// 存储其他客户端状态
List<String> clientIdList = JSONObject.parseArray(new String(msg.getData()), String.class);
for (String tenantId : clientIdList) {

View File

@ -1,12 +1,12 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeDisconnectTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeDisconnectTypeAdvancedHandle;
/**
@ -15,12 +15,12 @@ import org.springframework.stereotype.Component;
*/
@Slf4j
@Component
public class DistributeDisconnectTypeAdvanced extends AbstractDistributeDisconnectTypeAdvanced <NettyProxyMsg> {
public class HandleDistributeDisconnectTypeAdvancedHandle extends AbstractHandleDistributeDisconnectTypeAdvancedHandle<NettyProxyMsg> {
private final ClientNettyConfigApplication clientNettyConfigApplication;
public DistributeDisconnectTypeAdvanced(ClientNettyConfigApplication clientNettyConfigApplication) {
public HandleDistributeDisconnectTypeAdvancedHandle(ClientNettyConfigApplication clientNettyConfigApplication) {
this.clientNettyConfigApplication = clientNettyConfigApplication;
}
@ -36,7 +36,7 @@ public class DistributeDisconnectTypeAdvanced extends AbstractDistributeDisconne
byte[] data = msg.getData();
byte[] clientId = msg.getClientId();
String tenantId = new String(clientId);
log.warn("客户端:{}下线",tenantId);
log.warn("客户端:{}下线", tenantId);
clientNettyConfigApplication.clientOffLine(tenantId);
}

View File

@ -1,19 +1,17 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeStagingClosedTypeAdvanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeStagingClosedTypeAdvanced;
/**
* 服务端下发暂存关闭消息处理
*/
@Slf4j
@Component
public class DistributeStagingClosedTypeAdvanced extends AbstractDistributeStagingClosedTypeAdvanced <NettyProxyMsg>{
public class HandleDistributeStagingClosedTypeAdvanced extends AbstractHandleDistributeStagingClosedTypeAdvanced<NettyProxyMsg> {
/**

View File

@ -1,22 +1,20 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.advanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractDistributeStagingOpenedTypeAdvanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.AbstractHandleDistributeStagingOpenedTypeAdvanced;
/**
* 服务端下发暂存开启消息处理
*/
@Slf4j
@Component
public class DistributeStagingOpenedTypeAdvanced extends AbstractDistributeStagingOpenedTypeAdvanced<NettyProxyMsg>{
public class HandleDistributeStagingOpenedTypeAdvanced extends AbstractHandleDistributeStagingOpenedTypeAdvanced<NettyProxyMsg> {
public DistributeStagingOpenedTypeAdvanced() {
public HandleDistributeStagingOpenedTypeAdvanced() {
}

View File

@ -1,14 +1,13 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.config;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
@ -23,35 +22,32 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
@Configuration
public class AutoConfiguration implements CommandLineRunner {
public class ClientAutoConfiguration implements CommandLineRunner {
private final ServerProperties serverProperties;
private final NettyServerProperties nettyServerProperties;
private final ClientNettyConfigApplication clientNettyConfigApplication;
private final List<ChannelTypeAdvanced> channelTypeAdvancedList; // 处理服务端发送过来的数据类型
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
ThreadPoolExecutor NETTY_CLIENT_EXECUTOR = new ThreadPoolExecutor(1, 1, 200, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(1));
public AutoConfiguration(ServerProperties serverProperties,
NettyServerProperties nettyServerProperties,
ClientNettyConfigApplication clientNettyConfigApplication,
List<ChannelTypeAdvanced> channelTypeAdvancedList) {
this.serverProperties = serverProperties;
public ClientAutoConfiguration(NettyServerProperties nettyServerProperties,
ClientNettyConfigApplication clientNettyConfigApplication,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.nettyServerProperties = nettyServerProperties;
this.clientNettyConfigApplication = clientNettyConfigApplication;
this.channelTypeAdvancedList = channelTypeAdvancedList;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
@Bean(destroyMethod = "shutdown")
public NettyClientSocket nettyServerSocket() {
public NettyClientSocket nettyClientSocket() {
String inetHost = nettyServerProperties.getInetHost();
int inetPort = nettyServerProperties.getInetPort();
String clientId = nettyServerProperties.getClientId();
return new NettyClientSocket(inetHost, inetPort, clientId, clientNettyConfigApplication, channelTypeAdvancedList);
return new NettyClientSocket(inetHost, inetPort, clientId, clientNettyConfigApplication, handleChannelTypeAdvancedList);
}
/**
@ -65,7 +61,7 @@ public class AutoConfiguration implements CommandLineRunner {
String inetHost = nettyServerProperties.getInetHost();
int inetPort = nettyServerProperties.getInetPort();
String clientId = nettyServerProperties.getClientId();
NettyClientSocket nettyClientSocket = new NettyClientSocket(inetHost, inetPort, clientId, clientNettyConfigApplication, channelTypeAdvancedList);
NettyClientSocket nettyClientSocket = new NettyClientSocket(inetHost, inetPort, clientId, clientNettyConfigApplication, handleChannelTypeAdvancedList);
Thread thread = new Thread(() -> {
try {
nettyClientSocket.newConnect2Server();

View File

@ -0,0 +1,87 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.config;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Role;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import wu.framework.lazy.cloud.heartbeat.client.netty.advanced.*;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import java.util.List;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class HeartbeatClientConfiguration {
/**
* 服务端 处理客户端心跳
*
* @return ClientHandleChannelHeartbeatTypeAdvanced
*/
@Bean
public ClientHandleChannelHeartbeatTypeAdvanced clientChannelHeartbeatTypeAdvanced() {
return new ClientHandleChannelHeartbeatTypeAdvanced();
}
/**
* 处理 客户端代理的真实端口自动读写
*
* @return ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced
*/
@Bean
public ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced handleDistributeSingleClientRealAutoReadConnectTypeAdvanced() {
return new ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced();
}
/**
* 处理 接收服务端发送过来的聊天信息
*
* @return ClientHandleDistributeSingleClientMessageTypeAdvanced
*/
@Bean
public ClientHandleDistributeSingleClientMessageTypeAdvanced handleDistributeSingleClientMessageTypeAdvanced() {
return new ClientHandleDistributeSingleClientMessageTypeAdvanced();
}
@Bean
public ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced handleDistributeSingleClientRealCloseVisitorTypeAdvanced() {
return new ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced();
}
@Bean
public ClientReportHandleChannelTransferTypeAdvancedHandleDistribute handleChannelTransferTypeAdvancedHandleDistribute(NettyServerProperties nettyServerProperties) {
return new ClientReportHandleChannelTransferTypeAdvancedHandleDistribute(nettyServerProperties);
}
@Bean
public HandleDistributeConnectSuccessNotificationTypeAdvancedHandle handleDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientNettyConfigApplication clientNettyConfigApplication) {
return new HandleDistributeConnectSuccessNotificationTypeAdvancedHandle(clientNettyConfigApplication);
}
@Bean
public HandleClientChannelActiveAdvanced handleClientChannelActiveAdvanced(NettyServerProperties nettyServerProperties) {
return new HandleClientChannelActiveAdvanced(nettyServerProperties);
}
@Bean
public HandleDistributeDisconnectTypeAdvancedHandle handleDistributeDisconnectTypeAdvancedHandle(ClientNettyConfigApplication clientNettyConfigApplication) {
return new HandleDistributeDisconnectTypeAdvancedHandle(clientNettyConfigApplication);
}
@Bean
public HandleDistributeStagingClosedTypeAdvanced handleDistributeStagingClosedTypeAdvanced() {
return new HandleDistributeStagingClosedTypeAdvanced();
}
@Bean
public HandleDistributeStagingOpenedTypeAdvanced handleDistributeStagingOpenedTypeAdvanced() {
return new HandleDistributeStagingOpenedTypeAdvanced();
}
@Bean
public ClientHandleDistributeSingleClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyServerProperties nettyServerProperties,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
return new ClientHandleDistributeSingleClientRealConnectTypeAdvanced(nettyServerProperties, handleChannelTypeAdvancedList);
}
}

View File

@ -11,7 +11,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@Data
public class NettyServerProperties {
public static final String PREFIX = "spring.middleground.netty";
public static final String PREFIX = "spring.lazy.netty";
/**
* 服务端地址
*/
@ -23,7 +23,7 @@ public class NettyServerProperties {
/**
* 服务端path
*/
private String inetPath = "middleground-on-cloud-heartbeat-server";
private String inetPath = "lazy-cloud-heartbeat-server";
/**
* 客户端ID
*/

View File

@ -1,16 +1,16 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.filter;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.decoder.NettyProxyMsgDecoder;
import wu.framework.lazy.cloud.heartbeat.common.encoder.NettyProxyMsgEncoder;
import wu.framework.lazy.cloud.heartbeat.client.netty.handler.NettyClientHandler;
import io.netty.channel.ChannelInitializer;
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 wu.framework.lazy.cloud.heartbeat.client.netty.handler.NettyClientHandler;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.decoder.NettyProxyMsgDecoder;
import wu.framework.lazy.cloud.heartbeat.common.encoder.NettyProxyMsgEncoder;
public class NettyClientFilter extends ChannelInitializer<SocketChannel> {
@ -40,6 +40,6 @@ public class NettyClientFilter extends ChannelInitializer<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 NettyClientHandler(channelTypeAdapter, nettyClientSocket)); //客户端的逻辑
}
}

View File

@ -1,13 +1,13 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.filter;
import wu.framework.lazy.cloud.heartbeat.client.netty.handler.NettyClientRealHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import wu.framework.lazy.cloud.heartbeat.client.netty.handler.NettyClientRealHandler;
public class NettyClientRealFilter extends ChannelInitializer<SocketChannel> {
public class NettyClientRealFilter extends ChannelInitializer<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}.

View File

@ -1,15 +1,14 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.filter;
import wu.framework.lazy.cloud.heartbeat.client.netty.handler.NettyClientVisitorRealHandler;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.decoder.NettyProxyMsgDecoder;
import wu.framework.lazy.cloud.heartbeat.common.encoder.NettMsgEncoder;
import wu.framework.lazy.cloud.heartbeat.common.encoder.NettyProxyMsgEncoder;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import wu.framework.lazy.cloud.heartbeat.client.netty.handler.NettyClientVisitorRealHandler;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.decoder.NettyProxyMsgDecoder;
import wu.framework.lazy.cloud.heartbeat.common.encoder.NettyProxyMsgEncoder;
/**
* netty 客户端连接真实服服务端访客拦截器
@ -34,8 +33,8 @@ public class NettyClientVisitorRealFilter extends ChannelInitializer<SocketChann
protected void initChannel(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 NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
// pipeline.addLast(new NettMsgEncoder());
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
pipeline.addLast(new NettyProxyMsgEncoder());
pipeline.addLast(new NettyClientVisitorRealHandler(channelTypeAdapter));

View File

@ -8,13 +8,12 @@ import io.netty.handler.timeout.IdleStateEvent;
import java.util.Date;
public class HeartBeatClientHandler extends ChannelInboundHandlerAdapter {
private int lossConnectCount = 0;
private final int lossConnectCount = 0;
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
System.out.println("客户端循环心跳监测发送: " + new Date());
if (evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
if (evt instanceof IdleStateEvent event) {
if (event.state() == IdleState.WRITER_IDLE) {
ctx.writeAndFlush("biubiu");
}

View File

@ -1,9 +1,5 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.handler;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.EventLoop;
@ -11,6 +7,10 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import java.nio.charset.StandardCharsets;
import java.util.Date;
@ -61,7 +61,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
// 处理客户端连接成功
Channel channel = ctx.channel();
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setType(MessageType.CLIENT_CHANNEL_ACTIVE);
nettyMsg.setClientId(clientId);
channelTypeAdapter.handler(channel, nettyMsg);
@ -91,8 +91,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
*/
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
if (obj instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) obj;
if (obj instanceof IdleStateEvent event) {
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
String clientId = nettyClientSocket.getClientId();
NettyProxyMsg nettyMsg = new NettyProxyMsg();

View File

@ -1,15 +1,15 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.handler;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyCommunicationIdContext;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyCommunicationIdContext;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
/**
* 来自客户端 真实服务器返回的数据请求
@ -25,11 +25,15 @@ public class NettyClientRealHandler extends SimpleChannelInboundHandler<ByteBuf>
buf.readBytes(bytes);
log.debug("接收客户端真实服务数据:{}", new String(bytes));
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(ctx.channel());
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
// 访客通信通道 上报服务端代理完成
Channel visitorChannel = NettyCommunicationIdContext.getVisitor(visitorId);
NettyProxyMsg returnMessage = new NettyProxyMsg();
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER);
returnMessage.setVisitorId(visitorId);
returnMessage.setClientId(clientId);
returnMessage.setVisitorPort(visitorPort);
returnMessage.setData(bytes);
visitorChannel.writeAndFlush(returnMessage);

View File

@ -1,16 +1,19 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.handler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.common.ChannelContext;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
/**
* 客户端访客通信通道 处理器
*/
@Slf4j
public class NettyClientVisitorRealHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
private final ChannelTypeAdapter channelTypeAdapter;

View File

@ -1,13 +1,12 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.client.rpc.StagingNoticeApiRpc;
import wu.framework.lazy.cloud.heartbeat.common.constant.RedisChannelConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 客户端暂存开启关闭通知
*

View File

@ -1,19 +1,18 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.socket;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.common.*;
import wu.framework.lazy.cloud.heartbeat.common.*;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
import wu.framework.lazy.cloud.heartbeat.client.netty.filter.NettyClientRealFilter;
import wu.framework.lazy.cloud.heartbeat.client.netty.filter.NettyClientVisitorRealFilter;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties;
import wu.framework.lazy.cloud.heartbeat.client.netty.filter.NettyClientRealFilter;
import wu.framework.lazy.cloud.heartbeat.client.netty.filter.NettyClientVisitorRealFilter;
import wu.framework.lazy.cloud.heartbeat.common.*;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -33,9 +32,9 @@ public class NettyClientRealSocket {
*/
public static void buildRealServer(InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient,
NettyServerProperties nettyServerProperties,
List<ChannelTypeAdvanced> channelTypeAdvancedList) {
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
buildNewRealServer(internalNetworkPenetrationRealClient, nettyServerProperties, channelTypeAdvancedList);
buildNewRealServer(internalNetworkPenetrationRealClient, nettyServerProperties, handleChannelTypeAdvancedList);
}
@ -45,10 +44,13 @@ public class NettyClientRealSocket {
*/
private static void buildNewRealServer(InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient,
NettyServerProperties nettyServerProperties,
List<ChannelTypeAdvanced> channelTypeAdvancedList) {
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
try {
String clientId = internalNetworkPenetrationRealClient.getClientId();
String clientTargetIp = internalNetworkPenetrationRealClient.getClientTargetIp();
Integer clientTargetPort = internalNetworkPenetrationRealClient.getClientTargetPort();
Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort();
String visitorId = internalNetworkPenetrationRealClient.getVisitorId();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
.handler(new NettyClientRealFilter());
@ -57,22 +59,19 @@ public class NettyClientRealSocket {
// 客户端链接真实服务成功 设置自动读写false 等待访客连接成功后设置成true
Channel realChannel = future.channel();
realChannel.config().setOption(ChannelOption.AUTO_READ, false);
String clientId = internalNetworkPenetrationRealClient.getClientId();// 客户端ID
String clientTargetIp1 = internalNetworkPenetrationRealClient.getClientTargetIp();
Integer clientTargetPort1 = internalNetworkPenetrationRealClient.getClientTargetPort();
Integer visitorPort = internalNetworkPenetrationRealClient.getVisitorPort();
String visitorId = internalNetworkPenetrationRealClient.getVisitorId();
log.info("访客通过 客户端:【{}】,绑定本地服务,IP:{},端口:{} 新建通道成功", clientId, clientTargetIp1, clientTargetPort1);
log.info("访客通过 客户端:【{}】,绑定本地服务,IP:{},端口:{} 新建通道成功", clientId, clientTargetIp, clientTargetPort);
// 客户端真实通道
NettyRealIdContext.pushVisitor(realChannel, visitorId);
NettyRealIdContext.pushReal(realChannel, visitorId);
// 绑定访客ID到当前真实通道属性
ChannelAttributeKeyUtils.buildVisitorId(realChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(realChannel, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(realChannel, visitorPort);
// 通知服务端访客连接成功
// 新建一个通道处理
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyServerProperties, channelTypeAdvancedList);
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyServerProperties, handleChannelTypeAdvancedList);
// 是否等 服务端相应访客通道已经可以自动读写
// realChannel.config().setOption(ChannelOption.AUTO_READ, true);
@ -100,6 +99,8 @@ public class NettyClientRealSocket {
// future.channel().attr(Constant.VID).set(internalNetworkPenetrationRealClient);
// Constant.vrc.put(internalNetworkPenetrationRealClient, future.channel());
// ProxySocket.connectProxyServer(internalNetworkPenetrationRealClient);
} else {
log.error("客户:【{}】,无法连接当前网络内的目标IP【{}】,目标端口:【{}】", clientId, clientTargetIp, clientTargetPort);
}
});
} catch (Exception e) {
@ -113,16 +114,16 @@ public class NettyClientRealSocket {
*
* @param internalNetworkPenetrationRealClient 内网穿透信息
* @param nettyServerProperties 服务端配置信息
* @param channelTypeAdvancedList 处理器适配器
* @param handleChannelTypeAdvancedList 处理器适配器
* @throws InterruptedException 异常
*/
protected static void newVisitorConnect2Server(InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient,
NettyServerProperties nettyServerProperties,
List<ChannelTypeAdvanced> channelTypeAdvancedList) throws InterruptedException {
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) throws InterruptedException {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup)
.channel(NioSocketChannel.class)
.handler(new NettyClientVisitorRealFilter(new ChannelTypeAdapter(channelTypeAdvancedList)))
.handler(new NettyClientVisitorRealFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
;
String inetHost = nettyServerProperties.getInetHost();
@ -138,7 +139,7 @@ public class NettyClientRealSocket {
log.info("客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}", inetHost, inetPort);
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
log.info("使用的租户ID:" + clientId);
log.info("使用的客户端ID:" + clientId);
future.addListener((ChannelFutureListener) futureListener -> {
Channel channel = futureListener.channel();
if (futureListener.isSuccess()) {
@ -153,11 +154,11 @@ public class NettyClientRealSocket {
myMsg.setVisitorId(visitorId);
channel.writeAndFlush(myMsg);
// 绑定客户端真实通信通道
NettyCommunicationIdContext.pushVisitor(channel,visitorId);
NettyCommunicationIdContext.pushVisitor(channel, visitorId);
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
// 客户端真实通道自动读写打开
Channel visitor = NettyRealIdContext.getVisitor(visitorId);
Channel visitor = NettyRealIdContext.getReal(visitorId);
visitor.config().setOption(ChannelOption.AUTO_READ, true);
@ -166,7 +167,7 @@ public class NettyClientRealSocket {
// 离线
channel.eventLoop().schedule(() -> {
try {
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyServerProperties, channelTypeAdvancedList);
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyServerProperties, handleChannelTypeAdvancedList);
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@ -1,13 +1,6 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.socket;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import wu.framework.lazy.cloud.heartbeat.client.netty.filter.NettyClientFilter;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
@ -17,6 +10,13 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.client.application.ClientNettyConfigApplication;
import wu.framework.lazy.cloud.heartbeat.client.netty.filter.NettyClientFilter;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
public class NettyClientSocket {
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/**
* 服务端host
*/
@ -44,17 +45,14 @@ public class NettyClientSocket {
*/
@Getter
private final ClientNettyConfigApplication clientNettyConfigApplication;
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
private final List<ChannelTypeAdvanced> channelTypeAdvancedList; // 处理服务端发送过来的数据类型
private static final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
public NettyClientSocket(String inetHost, int inetPort, String clientId, ClientNettyConfigApplication clientNettyConfigApplication, List<ChannelTypeAdvanced> channelTypeAdvancedList) {
public NettyClientSocket(String inetHost, int inetPort, String clientId, ClientNettyConfigApplication clientNettyConfigApplication, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.inetHost = inetHost;
this.inetPort = inetPort;
this.clientId = clientId;
this.clientNettyConfigApplication = clientNettyConfigApplication;
this.channelTypeAdvancedList = channelTypeAdvancedList;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
public void newConnect2Server() throws InterruptedException {
@ -65,14 +63,14 @@ public class NettyClientSocket {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup)
.channel(NioSocketChannel.class)
.handler(new NettyClientFilter(new ChannelTypeAdapter(channelTypeAdvancedList),this))
.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);
log.info("使用的客户端ID:" + clientId);
future.addListener((ChannelFutureListener) futureListener -> {
if (futureListener.isSuccess()) {
@ -81,8 +79,8 @@ public class NettyClientSocket {
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.REPORT_CLIENT_CONNECT_SUCCESS);
nettyMsg.setClientId(clientId);
nettyMsg.setData(( clientId ).getBytes());
ChannelAttributeKeyUtils.buildClientId(channel,clientId);
nettyMsg.setData((clientId).getBytes());
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
channel.writeAndFlush(nettyMsg);
// 在线
clientNettyConfigApplication.clientOnLine(clientId);

View File

@ -3,17 +3,16 @@ package wu.framework.lazy.cloud.heartbeat.client.rpc;
import com.wu.framework.database.lazy.web.plus.stereotype.LazyRpc;
import com.wu.framework.response.Result;
import com.wu.framework.response.ResultFactory;
import io.netty.channel.Channel;
import wu.framework.lazy.cloud.heartbeat.common.ChannelContext;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import io.netty.channel.Channel;
import java.nio.charset.StandardCharsets;
import java.util.List;
@LazyRpc
public class StagingNoticeApiRpc {
public class StagingNoticeApiRpc {
/**
@ -31,9 +30,9 @@ public class StagingNoticeApiRpc {
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_OPENED);
nettyMsg.setData((clientId.toString()
nettyMsg.setData((clientId
.getBytes(StandardCharsets.UTF_8)));
nettyMsg.setClientId((clientId.toString()
nettyMsg.setClientId((clientId
.getBytes(StandardCharsets.UTF_8)));
channel.writeAndFlush(nettyMsg);
}
@ -54,9 +53,9 @@ public class StagingNoticeApiRpc {
Channel channel = clientChannel.getChannel();
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_CLOSED);
nettyMsg.setData((clientId.toString()
nettyMsg.setData((clientId
.getBytes(StandardCharsets.UTF_8)));
nettyMsg.setClientId((clientId.toString()
nettyMsg.setClientId((clientId
.getBytes(StandardCharsets.UTF_8)));
channel.writeAndFlush(nettyMsg);
}

View File

@ -1,3 +1,6 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
wu.framework.lazy.cloud.heartbeat.client.EnableHeartbeatClientAutoConfiguration
wu.framework.lazy.cloud.heartbeat.client.EnableHeartbeatClientAutoConfiguration,\
wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties,\
wu.framework.lazy.cloud.heartbeat.client.netty.config.ClientAutoConfiguration,\
wu.framework.lazy.cloud.heartbeat.client.netty.config.HeartbeatClientConfiguration

View File

@ -1 +1,4 @@
wu.framework.lazy.cloud.heartbeat.client.EnableHeartbeatClientAutoConfiguration
wu.framework.lazy.cloud.heartbeat.client.netty.config.NettyServerProperties
wu.framework.lazy.cloud.heartbeat.client.netty.config.ClientAutoConfiguration
wu.framework.lazy.cloud.heartbeat.client.netty.config.HeartbeatClientConfiguration

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-network</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
</parent>
<artifactId>wu-lazy-cloud-heartbeat-common</artifactId>

View File

@ -5,7 +5,6 @@ import io.netty.channel.ChannelId;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -17,25 +16,27 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class ChannelContext {
private final static ConcurrentHashMap<ChannelId/*channelId*/, ClientChannelImpl/*通道*/>
private final static ConcurrentHashMap<String/*clientId*/, ClientChannelImpl/*通道*/>
channelIdClientChannelDTOConcurrentHashMap = new ConcurrentHashMap<>();
/**
* 新增通道
*
* @param channel 通道
* @param nettyMsg 通道中的信息
* @param clientId 客户端ID
*/
public static void push(Channel channel, NettyProxyMsg nettyMsg) {
public static void push(Channel channel, String clientId) {
ChannelId channelId = channel.id();
byte[] clientId = nettyMsg.getClientId();
ClientChannelImpl clientChannelImpl = new ClientChannelImpl();
clientChannelImpl.setChannelId(channelId);
clientChannelImpl.setChannel(channel);
clientChannelImpl.setClientId(clientId);
channelIdClientChannelDTOConcurrentHashMap.put(channelId, clientChannelImpl);
clientChannelImpl.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
// 如果客户端已经存在 移除
if (channelIdClientChannelDTOConcurrentHashMap.containsKey(clientId)) {
// clear(clientId);
}
channelIdClientChannelDTOConcurrentHashMap.put(clientId, clientChannelImpl);
}
@ -52,7 +53,7 @@ public class ChannelContext {
clientChannelImpl.setChannelId(channelId);
clientChannelImpl.setChannel(channel);
clientChannelImpl.setClientId(clientId);
channelIdClientChannelDTOConcurrentHashMap.put(channelId, clientChannelImpl);
channelIdClientChannelDTOConcurrentHashMap.put(new String(clientId), clientChannelImpl);
}
@ -65,20 +66,6 @@ public class ChannelContext {
return new ArrayList<>(channelIdClientChannelDTOConcurrentHashMap.values());
}
/**
* 根据通道ID获取通道信息
*
* @param channelId 通道ID
* @return 通道信息
*/
public static ClientChannel get(ChannelId channelId) {
if (channelIdClientChannelDTOConcurrentHashMap.containsKey(channelId)) {
return channelIdClientChannelDTOConcurrentHashMap.get(channelId);
} else {
log.error("无法通过通道ID[" + channelId + "]获取通道信息");
return null;
}
}
/**
* 根据通道ID获取通道信息
@ -88,13 +75,9 @@ public class ChannelContext {
*/
public static ClientChannel get(byte[] clientId) {
if (channelIdClientChannelDTOConcurrentHashMap
.values().stream()
.anyMatch(clientChannelImpl -> new String(clientChannelImpl.getClientId()).equals(new String(clientId)))) {
.containsKey(new String(clientId))) {
return channelIdClientChannelDTOConcurrentHashMap
.values()
.stream()
.filter(clientChannelImpl -> new String(clientChannelImpl.getClientId()).equals(new String(clientId)))
.findFirst().get();
.get(new String(clientId));
} else {
log.error("无法通过客户端ID[" + new String(clientId) + "]获取通道信息");
return null;
@ -111,17 +94,23 @@ public class ChannelContext {
return get(clientId.getBytes(StandardCharsets.UTF_8));
}
/**
* 通过客户端通道ID移除客户端通道
* 关闭通道
*
* @param channelId 客户端通道ID
* @param clientId 客户端ID
*/
public static void remove(ChannelId channelId) {
if (channelIdClientChannelDTOConcurrentHashMap.containsKey(channelId)) {
channelIdClientChannelDTOConcurrentHashMap.remove(channelId);
public static void clear(String clientId) {
ClientChannel clientChannel = get(clientId);
if (clientChannel != null) {
remove(clientId);
Channel channel = clientChannel.getChannel();
if (channel != null && channel.isActive()) {
channel.close();
}
} else {
// log warm
log.warn("无法通过客户端通道ID:[{}]移除客户端", channelId);
log.warn("无法通过客户ID:[{}]移除客户端", clientId);
}
}
@ -133,13 +122,28 @@ public class ChannelContext {
public static void remove(byte[] clientId) {
ClientChannel clientChannel = get(clientId);
if (clientChannel != null) {
channelIdClientChannelDTOConcurrentHashMap.remove(clientChannel.getChannelId());
channelIdClientChannelDTOConcurrentHashMap.remove(new String(clientId));
} else {
// log warm
log.warn("无法通过客户ID:[{}]移除客户端", new String(clientId));
}
}
/**
* 通过客户端ID移除客户端通道
*
* @param clientId 客户端ID
*/
public static void remove(String clientId) {
ClientChannel clientChannel = get(clientId);
if (clientChannel != null) {
channelIdClientChannelDTOConcurrentHashMap.remove(clientId);
} else {
// log warm
log.warn("无法通过客户ID:[{}]移除客户端", clientId);
}
}
/**
* 客户端通道信息

View File

@ -1,5 +1,6 @@
package wu.framework.lazy.cloud.heartbeat.common;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;
@ -9,6 +10,7 @@ import lombok.experimental.Accessors;
* @author Jia wei Wu
* @date 2023/12/29 05:21 下午
**/
@Builder
@Data
@Accessors(chain = true)
public class InternalNetworkPenetrationRealClient {

View File

@ -1,22 +1,21 @@
package wu.framework.lazy.cloud.heartbeat.common;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelHeartbeatTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.*;
import wu.framework.lazy.cloud.heartbeat.common.advanced.server.*;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.*;
import wu.framework.lazy.cloud.heartbeat.common.advanced.server.*;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* @see MessageTypeEnums
* -128~ 127
* 数据取值范围 -128~ 127
* 当前约束范围 -100100
*/
public class MessageType {
/**
* 心跳
*
* @see MessageTypeEnums#TYPE_HEARTBEAT
* @see AbstractChannelHeartbeatTypeAdvanced
* @see AbstractHandleChannelHeartbeatTypeAdvanced
*/
public static final byte TYPE_HEARTBEAT = 0X00;
@ -24,28 +23,28 @@ public class MessageType {
* 客户端上报连接成功
*
* @see MessageTypeEnums#REPORT_CLIENT_CONNECT_SUCCESS
* @see AbstractReportConnectSuccessTypeAdvanced
* @see AbstractHandleClientConnectSuccessTypeAdvanced
*/
public static final byte REPORT_CLIENT_CONNECT_SUCCESS = 0X01;
/**
* 上报 客户端断开连接
*
* @see MessageTypeEnums#REPORT_CLIENT_DISCONNECTION
* @see AbstractReportDisconnectTypeAdvanced
* @see AbstractHandleReportDisconnectTypeAdvanced
*/
public static final byte REPORT_CLIENT_DISCONNECTION = 0X02;
/**
* 客户端上报暂存开启
*
* @see MessageTypeEnums#REPORT_CLIENT_STAGING_OPENED
* @see AbstractReportStagingOpenedTypeAdvanced
* @see AbstractHandleReportStagingOpenedTypeAdvanced
*/
public static final byte REPORT_CLIENT_STAGING_OPENED = 0X03;
/**
* 客户端上报暂存关闭
*
* @see MessageTypeEnums#REPORT_CLIENT_STAGING_CLOSED
* @see AbstractReportStagingClosedTypeAdvanced
* @see AbstractHandleReportStagingClosedTypeAdvanced
*/
public static final byte REPORT_CLIENT_STAGING_CLOSED = 0X04;
@ -53,7 +52,7 @@ public class MessageType {
* 上报 客户端数据传输内网穿透数据回传
*
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER
* @see AbstractReportChannelTransferTypeAdvanced
* @see AbstractHandleReportHandleChannelTransferTypeAdvanced
*/
public static final byte REPORT_CLIENT_TRANSFER = 0X05;
@ -62,37 +61,51 @@ public class MessageType {
* 上报 客户端创建需要代理的真实端口成功
*
* @see MessageTypeEnums#REPORT_SINGLE_CLIENT_REAL_CONNECT
* @see AbstractReportSingleClientRealConnectTypeAdvanced
* @see AbstractHandleReportSingleClientRealConnectTypeAdvanced
*/
public static final byte REPORT_SINGLE_CLIENT_REAL_CONNECT = 0X06;
/**
* 上报 客户端关闭一个访客通道
*
* @see MessageTypeEnums#REPORT_SINGLE_CLIENT_CLOSE_VISITOR
* @see AbstractReportSingleClientCloseVisitorTypeAdvanced
* @see AbstractHandleReportSingleClientCloseVisitorTypeAdvanced
*/
public static final byte REPORT_SINGLE_CLIENT_CLOSE_VISITOR = 0X08;
/**
* 上报 客户端消息到另一个客户端
*
* @see MessageTypeEnums#REPORT_SINGLE_CLIENT_MESSAGE
* @see AbstractHandleReportSingleClientMessage2OtherClientTypeAdvanced
*/
public static final byte REPORT_SINGLE_CLIENT_MESSAGE = 0X09;
/**
* 服务端通道 is active
*
* @see MessageTypeEnums#SERVER_CHANNEL_ACTIVE
* @see AbstractHandleServerChannelActiveTypeAdvanced
*/
public static final byte SERVER_CHANNEL_ACTIVE = 0X10;
/**
* 下发 客户端接收连接成功通知
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION
* @see AbstractDistributeConnectSuccessNotificationTypeAdvanced
* @see AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle
*/
public static final byte DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION = -0X01;
/**
* 下发 客户端断开连接通知
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION
* @see AbstractDistributeDisconnectTypeAdvanced
* @see AbstractHandleDistributeDisconnectTypeAdvancedHandle
*/
public static final byte DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION = -0X02;
/**
* 下发 客户端暂存开启通知
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_STAGING_OPENED_NOTIFICATION
* @see AbstractDistributeStagingOpenedTypeAdvanced
* @see AbstractHandleDistributeStagingOpenedTypeAdvanced
*/
public static final byte DISTRIBUTE_CLIENT_STAGING_OPENED_NOTIFICATION = -0X03;
@ -100,21 +113,21 @@ public class MessageType {
* 下发 客户端暂存关闭通知
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION
* @see AbstractDistributeStagingClosedTypeAdvanced
* @see AbstractHandleDistributeStagingClosedTypeAdvanced
*/
public static final byte DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION = -0X04;
/**
* 下发 客户端数据传输(内网穿透数据发送)
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
* @see AbstractDistributeChannelTransferTypeAdvanced
* @see AbstractHandleDistributeChannelTransferTypeAdvanced
*/
public static final byte DISTRIBUTE_CLIENT_TRANSFER = -0X05;
/**
* 下发 客户端创建需要代理的真实端口
*
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT
* @see AbstractDistributeSingleClientRealConnectTypeAdvanced
* @see AbstractHandleDistributeSingleClientRealConnectTypeAdvanced
*/
public static final byte DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT = -0X06;
@ -122,7 +135,7 @@ public class MessageType {
* 下发 客户端代理的真实端口自动读写
*
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT_AUTO_READ
* @see AbstractDistributeSingleClientRealAutoReadConnectTypeAdvanced
* @see AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced
*/
public static final byte DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT_AUTO_READ = -0X07;
@ -130,9 +143,24 @@ public class MessageType {
* 下发 客户端关闭代理服务通道
*
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR
* @see AbstractDistributeSingleClientRealCloseVisitorTypeAdvanced
* @see AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced
*/
public static final byte DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR = -0X08;
/**
* 下发 客户端消息
*
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_MESSAGE
* @see AbstractHandleDistributeSingleClientMessageTypeAdvanced
*/
public static final byte DISTRIBUTE_SINGLE_CLIENT_MESSAGE = -0X09;
/**
* 客户端通道 is active
*
* @see MessageTypeEnums#CLIENT_CHANNEL_ACTIVE
* @see AbstractHandleClientChannelActiveAdvanced
*/
public static final byte CLIENT_CHANNEL_ACTIVE = -0X10;
}

View File

@ -0,0 +1,47 @@
package wu.framework.lazy.cloud.heartbeat.common;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/**
* 访客端口对应访客上下文
*/
public class NettyClientVisitorContext {
protected static final ConcurrentHashMap<String/*clientId*/, List<Object>/*NettyVisitorSocket*/> VISITOR_SOCKET = new ConcurrentHashMap<>();
/**
* 添加访客
*
* @param clientId 客户端ID
* @param visitorSocket 客户端访客socket
*/
public static <T> void pushVisitorSocket(String clientId, T visitorSocket) {
List<Object> visitors = getVisitorSockets(clientId);
visitors.add(visitorSocket);
VISITOR_SOCKET.put(clientId, visitors);
}
/**
* 通过客户端ID获取客户端使用的访客socket
*
* @param <T> 访客范型
* @param clientId 客户端ID
* @return 访客
*/
public static <T> List<T> getVisitorSockets(String clientId) {
return (List<T>) VISITOR_SOCKET.getOrDefault(clientId, new ArrayList<>());
}
/**
* 关闭客户端访客socket
*
* @param clientId 客户端ID
*/
public static void close(String clientId) {
// getVisitorSockets(clientId)
}
}

View File

@ -1,6 +1,7 @@
package wu.framework.lazy.cloud.heartbeat.common;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.nio.charset.StandardCharsets;
@ -8,6 +9,7 @@ import java.nio.charset.StandardCharsets;
/**
* netty 代理请求数据
*/
@NoArgsConstructor
@Setter
@Getter
public class NettyProxyMsg {

View File

@ -5,7 +5,7 @@ import io.netty.channel.Channel;
import java.util.concurrent.ConcurrentHashMap;
/**
* 真实通道对应上下文
* 真实通道对应上下文 客户端服务端真实代理通道
*/
public class NettyRealIdContext {
@ -13,12 +13,12 @@ public class NettyRealIdContext {
/**
* 添加访客
* 添加真实通道
*
* @param visitorId 访客id
* @param visitor 访客
* @param visitor 访客真实通道
*/
public static <T> void pushVisitor(T visitor, String visitorId) {
public static <T> void pushReal(T visitor, String visitorId) {
REAL.put(visitorId, visitor);
}
@ -30,7 +30,7 @@ public class NettyRealIdContext {
* @param <T> 访客范型
* @return 访客
*/
public static <T> T getVisitor(String visitorId) {
public static <T> T getReal(String visitorId) {
return (T) REAL.get(visitorId);
}
@ -41,8 +41,8 @@ public class NettyRealIdContext {
* @param <T> 访客范型
* @return 访客
*/
public static <T> T getVisitor(byte[] visitorId) {
return getVisitor(new String(visitorId));
public static <T> T getReal(byte[] visitorId) {
return getReal(new String(visitorId));
}
@ -52,7 +52,7 @@ public class NettyRealIdContext {
* @param visitorId 访客ID
*/
public static void clear(String visitorId) {
Channel visitor = getVisitor(visitorId);
Channel visitor = getReal(visitorId);
if (visitor != null) {
REAL.remove(visitorId);
visitor.close();

View File

@ -5,7 +5,7 @@ import io.netty.channel.Channel;
import java.util.concurrent.ConcurrentHashMap;
/**
* 访客ID对应上下文
* 访客通信通道上下文服务端客户端 通信
*/
@Deprecated
public class NettyVisitorIdContext {

View File

@ -5,7 +5,7 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* 访客端口对应上下文
*/
public class NettyVisitorContext {
public class NettyVisitorPortContext {
protected static final ConcurrentHashMap<Integer, Object> VISITOR_PORT = new ConcurrentHashMap<>();

View File

@ -0,0 +1,41 @@
package wu.framework.lazy.cloud.heartbeat.common.adapter;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.common.advanced.flow.ChannelFlow;
import wu.framework.lazy.cloud.heartbeat.common.advanced.flow.HandleChannelFlowAdvanced;
import java.util.List;
/**
* 通道流量适配器
*
* @see HandleChannelFlowAdvanced
*/
@Slf4j
public class ChannelFlowAdapter {
protected final List<HandleChannelFlowAdvanced> handleChannelFlowAdvancedList;
public ChannelFlowAdapter(List<HandleChannelFlowAdvanced> handleChannelFlowAdvancedList) {
this.handleChannelFlowAdvancedList = handleChannelFlowAdvancedList;
}
/**
* 处理当前数据
*
* @param channelFlow 通道数据
*/
public void handler(Channel channel, ChannelFlow channelFlow) {
for (HandleChannelFlowAdvanced handleChannelTypeAdvanced : handleChannelFlowAdvancedList) {
if (handleChannelTypeAdvanced.support(channelFlow)) {
try {
handleChannelTypeAdvanced.handler(channel, channelFlow);
} catch (Exception e) {
log.error("流量统计失败:{}", e.getMessage());
}
return;
}
}
}
}

View File

@ -1,8 +1,8 @@
package wu.framework.lazy.cloud.heartbeat.common.adapter;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import java.util.List;
@ -11,10 +11,10 @@ import java.util.List;
*/
@Slf4j
public class ChannelTypeAdapter {
protected final List<ChannelTypeAdvanced> channelTypeAdvancedList;
protected final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
public ChannelTypeAdapter(List<ChannelTypeAdvanced> channelTypeAdvancedList) {
this.channelTypeAdvancedList = channelTypeAdvancedList;
public ChannelTypeAdapter(List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}
/**
@ -23,10 +23,10 @@ public class ChannelTypeAdapter {
* @param msg 通道数据
*/
public void handler(Channel channel, Object msg) {
for (ChannelTypeAdvanced channelTypeAdvanced : channelTypeAdvancedList) {
if (channelTypeAdvanced.support(msg)) {
// log.info("处理器:{},客户端:{}, 处理类型:{}",channelTypeAdvanced.getClass(),new String(msg.getClientId()),msg.getType());
channelTypeAdvanced.handler(channel, msg);
for (HandleChannelTypeAdvanced handleChannelTypeAdvanced : handleChannelTypeAdvancedList) {
if (handleChannelTypeAdvanced.support(msg)) {
// log.info("处理器:{},客户端:{}, 处理类型:{}",handleChannelTypeAdvanced.getClass(),new String(msg.getClientId()),msg.getType());
handleChannelTypeAdvanced.handler(channel, msg);
return;
}
}

View File

@ -10,7 +10,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* TYPE_HEARTBEAT
*/
public abstract class AbstractChannelHeartbeatTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleChannelHeartbeatTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -7,7 +7,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Objects;
public abstract class AbstractChannelTypeAdvanced<MSG> implements ChannelTypeAdvanced {
public abstract class AbstractHandleChannelTypeAdvanced<MSG> implements HandleChannelTypeAdvanced {
/**
* 处理当前数据
@ -28,6 +28,12 @@ public abstract class AbstractChannelTypeAdvanced<MSG> implements ChannelTypeAdv
doHandler(channel, (MSG) msg);
}
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
protected abstract boolean doSupport(MSG msg);
/**

View File

@ -1,9 +1,9 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced;
import io.netty.channel.Channel;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
import io.netty.channel.Channel;
/**
* 通道不同数据类型处理器
@ -11,7 +11,7 @@ import io.netty.channel.Channel;
* @see MessageType
* @see MessageTypeEnums
*/
public interface ChannelTypeAdvanced {
public interface HandleChannelTypeAdvanced {
/**

View File

@ -0,0 +1,25 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 客户端通道 is active
*/
public abstract class AbstractHandleClientChannelActiveAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.CLIENT_CHANNEL_ACTIVE.getTypeByte() == msg.getType();
}
}

View File

@ -1,9 +1,9 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
@ -11,7 +11,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* 客户端处理服务端下发数据
* DISTRIBUTE_CLIENT_TRANSFER
*/
public abstract class AbstractDistributeChannelTransferTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeChannelTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -1,14 +1,14 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端连接成功通知
*/
public abstract class AbstractDistributeConnectSuccessNotificationTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -1,16 +1,16 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发客户端断开连接通知
* DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION
*/
public abstract class AbstractDistributeDisconnectTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeDisconnectTypeAdvancedHandle<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -0,0 +1,25 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端关闭代理服务通道
*/
public abstract class AbstractHandleDistributeSingleClientMessageTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.DISTRIBUTE_SINGLE_CLIENT_MESSAGE.getTypeByte() == msg.getType();
}
}

View File

@ -1,9 +1,9 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
@ -12,7 +12,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT_AUTO_READ
*/
public abstract class AbstractDistributeSingleClientRealAutoReadConnectTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -1,16 +1,16 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端关闭代理服务通道
*/
public abstract class AbstractDistributeSingleClientRealCloseVisitorTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -1,16 +1,16 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端 创建真实连接
*/
public abstract class AbstractDistributeSingleClientRealConnectTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeSingleClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -2,15 +2,15 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端暂存关闭
*/
public abstract class AbstractDistributeStagingClosedTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeStagingClosedTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -2,15 +2,15 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.client;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 下发 客户端暂存开启
*/
public abstract class AbstractDistributeStagingOpenedTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleDistributeStagingOpenedTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -0,0 +1,49 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.flow;
import io.netty.channel.Channel;
/**
* 处理通道流量适配者 抽象类
*
* @see HandleChannelFlowAdvanced
*/
public abstract class AbstractHandleChannelFlowAdvanced implements HandleChannelFlowAdvanced {
/**
* 是否支持当前这种类型
*
* @param channelFlow 数据
* @return boolean
*/
@Override
public boolean support(ChannelFlow channelFlow) {
return doSupport(channelFlow);
}
/**
* 处理是否支持这种类型
*
* @param channelFlow 数据
* @return boolean
*/
protected abstract boolean doSupport(ChannelFlow channelFlow);
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelFlow 通道数据
*/
@Override
public void handler(Channel channel, ChannelFlow channelFlow) {
doHandler(channel, channelFlow);
}
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelFlow 通道数据
*/
protected abstract void doHandler(Channel channel, ChannelFlow channelFlow);
}

View File

@ -0,0 +1,37 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.flow;
import wu.framework.lazy.cloud.heartbeat.common.enums.ChannelFlowEnum;
public interface ChannelFlow {
/**
* 通道客户端ID
*
* @return 通道客户端ID
*/
String clientId();
/**
* 通道使用的端口服务端访客端口客户端真实端口
*
* @return 端口
*/
Integer port();
/**
* 通道流量类型
*
* @return ChannelFlowEnum
* @see ChannelFlowEnum
*/
ChannelFlowEnum channelFlowEnum();
/**
* 流量
*
* @return 流量
*/
Integer flow();
}

View File

@ -0,0 +1,25 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.flow;
import io.netty.channel.Channel;
/**
* 处理通道流量适配者
*/
public interface HandleChannelFlowAdvanced {
/**
* 是否支持当前这种类型
*
* @param channelFlow 数据
* @return boolean
*/
boolean support(ChannelFlow channelFlow);
/**
* 处理当前数据
*
* @param channel 当前通道
* @param channelFlow 通道数据
*/
void handler(Channel channel, ChannelFlow channelFlow);
}

View File

@ -1,14 +1,14 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 客户端连接成功上报处理器
* 服务端处理客户端连接成功
*/
public abstract class AbstractReportConnectSuccessTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleClientConnectSuccessTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -2,8 +2,8 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
@ -11,7 +11,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION
*/
public abstract class AbstractReportDisconnectTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleReportDisconnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -2,8 +2,8 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
@ -11,7 +11,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* 服务端处理客户端上报数据
* REPORT_CLIENT_STAGING_CLOSED
*/
public abstract class AbstractReportChannelTransferTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleReportHandleChannelTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -2,8 +2,8 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
@ -11,7 +11,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* 服务端处理客户端 关闭一个访客
* REPORT_SINGLE_CLIENT_CLOSE_VISITOR
*/
public abstract class AbstractReportSingleClientCloseVisitorTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleReportSingleClientCloseVisitorTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -0,0 +1,27 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 服务端处理客户端 关闭一个访客
* REPORT_SINGLE_CLIENT_CLOSE_VISITOR
*/
public abstract class AbstractHandleReportSingleClientMessage2OtherClientTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.REPORT_SINGLE_CLIENT_MESSAGE.getTypeByte() == msg.getType();
}
}

View File

@ -2,8 +2,8 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
@ -11,7 +11,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* 服务端处理客户端绑定真实服务成功
* REPORT_SINGLE_CLIENT_REAL_CONNECT
*/
public abstract class AbstractReportSingleClientRealConnectTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleReportSingleClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -2,8 +2,8 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
@ -14,7 +14,7 @@ import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
* 客户端上报暂存
*/
public abstract class AbstractReportStagingClosedTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleReportStagingClosedTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -2,15 +2,15 @@ package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.ChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 上报客户端暂存开启
*/
public abstract class AbstractReportStagingOpenedTypeAdvanced<MSG> extends AbstractChannelTypeAdvanced<NettyProxyMsg> implements ChannelTypeAdvanced {
public abstract class AbstractHandleReportStagingOpenedTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -0,0 +1,27 @@
package wu.framework.lazy.cloud.heartbeat.common.advanced.server;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.enums.MessageTypeEnums;
/**
* 服务端通道 is active
* SERVER_CHANNEL_ACTIVE
*/
public abstract class AbstractHandleServerChannelActiveTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型
*
* @param msg 通道数据
* @return 布尔类型
*/
@Override
public boolean doSupport(NettyProxyMsg msg) {
return MessageTypeEnums.SERVER_CHANNEL_ACTIVE.getTypeByte() == msg.getType();
}
}

View File

@ -1,5 +1,5 @@
package wu.framework.lazy.cloud.heartbeat.common.constant;
public class ProxyConfigConstant {
public static final String PREFIX ="spring.lazy.proxy";
public static final String PREFIX = "spring.lazy.proxy";
}

View File

@ -1,14 +1,15 @@
package wu.framework.lazy.cloud.heartbeat.common.decoder;
import wu.framework.lazy.cloud.heartbeat.common.NettyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import wu.framework.lazy.cloud.heartbeat.common.NettyMsg;
/**
* @see NettyMsg
* NettyMsg 对象解码
*/
@Deprecated
public class NettyMsgDecoder extends LengthFieldBasedFrameDecoder {
public NettyMsgDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment,

View File

@ -1,11 +1,11 @@
package wu.framework.lazy.cloud.heartbeat.common.decoder;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.TooLongFrameException;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import java.nio.ByteOrder;

View File

@ -1,15 +1,16 @@
package wu.framework.lazy.cloud.heartbeat.common.encoder;
import wu.framework.lazy.cloud.heartbeat.common.NettyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import wu.framework.lazy.cloud.heartbeat.common.NettyMsg;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
/**
* @see NettyProxyMsg
* NettyProxyMsg 对象编码
*/
@Deprecated
public class NettMsgEncoder extends MessageToByteEncoder<NettyMsg> {
public NettMsgEncoder() {
@ -37,7 +38,7 @@ public class NettMsgEncoder extends MessageToByteEncoder<NettyMsg> {
if (clientIdBytes != null) {
out.writeInt(clientIdBytes.length);
out.writeBytes(clientIdBytes);
}else {
} else {
// 防止客户端ID未填写
out.writeInt(0x00);
}

View File

@ -1,9 +1,9 @@
package wu.framework.lazy.cloud.heartbeat.common.encoder;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
/**
* @see NettyProxyMsg

View File

@ -0,0 +1,17 @@
package wu.framework.lazy.cloud.heartbeat.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 通道流量类型
*/
@Getter
@AllArgsConstructor
public enum ChannelFlowEnum {
// 出口流量
OUT_FLOW,
// 进口流量
IN_FLOW
}

View File

@ -3,7 +3,7 @@ package wu.framework.lazy.cloud.heartbeat.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractChannelHeartbeatTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
import wu.framework.lazy.cloud.heartbeat.common.advanced.client.*;
import wu.framework.lazy.cloud.heartbeat.common.advanced.server.*;
@ -14,75 +14,89 @@ import wu.framework.lazy.cloud.heartbeat.common.advanced.server.*;
@AllArgsConstructor
public enum MessageTypeEnums {
/**
* @see AbstractChannelHeartbeatTypeAdvanced
* @see AbstractHandleChannelHeartbeatTypeAdvanced
*/
TYPE_HEARTBEAT(MessageType.TYPE_HEARTBEAT, "心跳"),
/**
* @see AbstractReportConnectSuccessTypeAdvanced
* @see AbstractHandleClientConnectSuccessTypeAdvanced
*/
REPORT_CLIENT_CONNECT_SUCCESS(MessageType.REPORT_CLIENT_CONNECT_SUCCESS, "上报 客户端连接成功"),
/**
* @see AbstractReportDisconnectTypeAdvanced
* @see AbstractHandleReportDisconnectTypeAdvanced
*/
REPORT_CLIENT_DISCONNECTION(MessageType.REPORT_CLIENT_DISCONNECTION, "上报 客户端断开连接"),
/**
* @see AbstractReportStagingOpenedTypeAdvanced
* @see AbstractHandleReportStagingOpenedTypeAdvanced
*/
REPORT_CLIENT_STAGING_OPENED(MessageType.REPORT_CLIENT_STAGING_OPENED, "上报 客户端暂存开启"),
/**
* @see AbstractReportStagingClosedTypeAdvanced
* @see AbstractHandleReportStagingClosedTypeAdvanced
*/
REPORT_CLIENT_STAGING_CLOSED(MessageType.REPORT_CLIENT_STAGING_CLOSED, "上报 客户端暂存关闭"),
/**
* @see AbstractReportChannelTransferTypeAdvanced
* @see AbstractHandleReportHandleChannelTransferTypeAdvanced
*/
REPORT_CLIENT_TRANSFER(MessageType.REPORT_CLIENT_TRANSFER, "上报 客户端数据传输(内网穿透数据回传)"),
/**
* @see AbstractReportSingleClientRealConnectTypeAdvanced
* @see AbstractHandleReportSingleClientRealConnectTypeAdvanced
*/
REPORT_SINGLE_CLIENT_REAL_CONNECT(MessageType.REPORT_SINGLE_CLIENT_REAL_CONNECT, "上报 客户端创建需要代理的真实端口成功"),
/**
* @see AbstractReportSingleClientCloseVisitorTypeAdvanced
* @see AbstractHandleReportSingleClientCloseVisitorTypeAdvanced
*/
REPORT_SINGLE_CLIENT_CLOSE_VISITOR(MessageType.REPORT_SINGLE_CLIENT_CLOSE_VISITOR, "上报 客户端关闭一个访客通道"),
/**
* @see AbstractDistributeConnectSuccessNotificationTypeAdvanced
* @see AbstractHandleReportSingleClientMessage2OtherClientTypeAdvanced
*/
REPORT_SINGLE_CLIENT_MESSAGE(MessageType.REPORT_SINGLE_CLIENT_MESSAGE, "上报 客户端消息到另一个客户端"),
/**
* @see AbstractHandleServerChannelActiveTypeAdvanced
*/
SERVER_CHANNEL_ACTIVE(MessageType.SERVER_CHANNEL_ACTIVE, "服务端通道 is active"),
/**
* @see AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle
*/
DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION(MessageType.DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION, "下发 客户端接收连接成功通知"),
/**
* @see AbstractDistributeDisconnectTypeAdvanced
* @see AbstractHandleDistributeDisconnectTypeAdvancedHandle
*/
DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION(MessageType.DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION, "下发 客户端断开连接通知"),
/**
* @see AbstractDistributeStagingOpenedTypeAdvanced
* @see AbstractHandleDistributeStagingOpenedTypeAdvanced
*/
DISTRIBUTE_CLIENT_STAGING_OPENED_NOTIFICATION(MessageType.DISTRIBUTE_CLIENT_STAGING_OPENED_NOTIFICATION, "下发 客户端暂存开启通知"),
/**
* @see AbstractDistributeStagingClosedTypeAdvanced
* @see AbstractHandleDistributeStagingClosedTypeAdvanced
*/
DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION(MessageType.DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION, "下发 客户端暂存关闭通知"),
/**
* @see AbstractDistributeChannelTransferTypeAdvanced
* @see AbstractHandleDistributeChannelTransferTypeAdvanced
*/
DISTRIBUTE_CLIENT_TRANSFER(MessageType.DISTRIBUTE_CLIENT_TRANSFER, "下发 客户端数据传输(内网穿透数据发送)"),
/**
* @see AbstractDistributeSingleClientRealConnectTypeAdvanced
* @see AbstractHandleDistributeSingleClientRealConnectTypeAdvanced
*/
DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT, "下发 客户端创建需要代理的真实端口"),
/**
* @see AbstractDistributeSingleClientRealAutoReadConnectTypeAdvanced
* @see AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced
*/
DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT_AUTO_READ(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT_AUTO_READ, "下发 客户端代理的真实端口自动读写"),
/**
* @see AbstractDistributeSingleClientRealCloseVisitorTypeAdvanced
* @see AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced
*/
DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR, "下发 客户端关闭代理服务通道"),
/**
* @see AbstractHandleDistributeSingleClientMessageTypeAdvanced
*/
DISTRIBUTE_SINGLE_CLIENT_MESSAGE(MessageType.DISTRIBUTE_SINGLE_CLIENT_MESSAGE, "下发 客户端消息"),
/**
* @see AbstractHandleClientChannelActiveAdvanced
*/
CLIENT_CHANNEL_ACTIVE(MessageType.CLIENT_CHANNEL_ACTIVE, "客户端通道 is active"),
;

View File

@ -9,7 +9,10 @@ import io.netty.util.AttributeKey;
public class ChannelAttributeKeyUtils {
private static final AttributeKey<String> VISITOR_ID = AttributeKey.newInstance("visitorId");
private static final AttributeKey<Integer> VISITOR_PORT = AttributeKey.newInstance("visitorPort");
private static final AttributeKey<String> CLIENT_ID = AttributeKey.newInstance("clientId");
private static final AttributeKey<Integer> OUT_FLOW = AttributeKey.newInstance("outFlow");
private static final AttributeKey<Integer> IN_FLOW = AttributeKey.newInstance("inFlow");
/**
@ -34,7 +37,8 @@ public class ChannelAttributeKeyUtils {
/**
* 获取 通道中访客ID
* @param channel 通道
*
* @param channel 通道
*/
public static String getVisitorId(Channel channel) {
return channel.attr(VISITOR_ID).get();
@ -44,16 +48,17 @@ public class ChannelAttributeKeyUtils {
/**
* 为通道绑定 访客属性
*
* @param channel 通道
* @param channel 通道
* @param clientId 客户端ID
*/
public static void buildClientId(Channel channel, byte[] clientId) {
channel.attr(CLIENT_ID).set(new String(clientId));
}
/**
* 为通道绑定 访客属性
*
* @param channel 通道
* @param channel 通道
* @param clientId 客户端ID
*/
public static void buildClientId(Channel channel, String clientId) {
@ -62,9 +67,68 @@ public class ChannelAttributeKeyUtils {
/**
* 获取 通道中访客ID
* @param channel 通道
*
* @param channel 通道
*/
public static String getClientId(Channel channel) {
return channel.attr(CLIENT_ID).get();
}
/**
* 为通道绑定 出口流量
*
* @param channel 通道
* @param outFlow 出口流量
*/
public static void buildOutFlow(Channel channel, Integer outFlow) {
channel.attr(OUT_FLOW).set(outFlow);
}
/**
* 获取 通道中出口流量
*
* @param channel 通道
*/
public static Integer getOutFlow(Channel channel) {
return channel.attr(OUT_FLOW).get();
}
/**
* 为通道绑定 进口流量
*
* @param channel 通道
* @param inFlow 进口流量
*/
public static void buildInFlow(Channel channel, Integer inFlow) {
channel.attr(IN_FLOW).set(inFlow);
}
/**
* 获取 通道中进口流量
*
* @param channel 通道
*/
public static Integer getInFlow(Channel channel) {
return channel.attr(IN_FLOW).get();
}
/**
* 为通道绑定 通道中访客端口
*
* @param channel 通道
* @param visitorPort 进口流量
*/
public static void buildVisitorPort(Channel channel, Integer visitorPort) {
channel.attr(VISITOR_PORT).set(visitorPort);
}
/**
* 获取 通道中访客端口
*
* @param channel 通道
*/
public static Integer getVisitorPort(Channel channel) {
return channel.attr(VISITOR_PORT).get();
}
}

View File

@ -5,7 +5,7 @@
<parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-network</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
</parent>
<artifactId>wu-lazy-cloud-heartbeat-sample</artifactId>

View File

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-network</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
</parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-client</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<description>云下心跳客户端</description>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-common</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.33</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-plus-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -5,7 +5,7 @@ MAINTAINER wujiawei <1207537021@qq.com>
RUN echo "Asia/Shanghai" > /etc/timezone
COPY target/middleground-under-cloud-heartbeat-client /native-app
COPY target/wu-lazy-cloud-heartbeat-client /native-app
ENTRYPOINT ["/bin/sh" ,"-c", "exec ./native-app"]

View File

@ -9,8 +9,8 @@ mvn native:build -Pnative
```
### 构建docker镜像
```shell
docker build -t docker-registry.laihui.com/middleground/middleground-under-cloud-heartbeat-client:middleground-2.4.2-native-SNAPSHOT_latest -f Native-Dockerfile .
docker push docker-registry.laihui.com/middleground/middleground-under-cloud-heartbeat-client:middleground-2.4.2-native-SNAPSHOT_latest
docker build -t docker-registry.wujiawei.com/middleground/wu-lazy-cloud-heartbeat-client:1.2.2-JDK17-SNAPSHOT-native-SNAPSHOT_latest -f Native-Dockerfile .
docker push docker-registry.wujiawei.com/middleground/wu-lazy-cloud-heartbeat-client:1.2.2-JDK17-SNAPSHOT-native-SNAPSHOT_latest
```
@ -21,15 +21,15 @@ docker push docker-registry.laihui.com/middleground/middleground-under-cloud-hea
#docker login --username=1207537021@qq.com registry.cn-hangzhou.aliyuncs.com
docker build -t registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:server-jdk17-master .
docker push registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:server-jdk17-master
docker build -t registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:1.2.2-JDK17-SNAPSHOT .
docker push registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:1.2.2-JDK17-SNAPSHOT
```
### run
```shell
docker run -d -it --name client -e spring.middleground.netty.inet-host=124.222.48.62 -e spring.middleground.netty.inet-port=30676 -e spring.middleground.netty.client-id=node1 registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:server-jdk17-master
docker run -d -it --name client -e spring.lazy.netty.inet-host=124.222.48.62 -e spring.lazy.netty.inet-port=30676 -e spring.lazy.netty.client-id=node1 registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client:server-jdk17-master

View File

@ -5,7 +5,7 @@
<parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-sample</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -21,12 +21,34 @@
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-client</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<version>1.2.2-JDK17-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- <plugin>-->
<!-- <groupId>org.graalvm.buildtools</groupId>-->
<!-- <artifactId>native-maven-plugin</artifactId>-->
<!-- <configuration>-->
<!-- &lt;!&ndash; imageName用于设置生成的二进制文件名称 &ndash;&gt;-->
<!-- <imageName>${project.artifactId}</imageName>-->
<!-- &lt;!&ndash; mainClass用于指定main方法类路径 &ndash;&gt;-->
<!-- <mainClass>wu.framework.lazy.cloud.heartbeat.client.LazyCloudHeartbeatClientSimpleSimple</mainClass>-->
<!-- <buildArgs>-->
<!-- &#45;&#45;no-fallback-->
<!-- </buildArgs>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>build-native</id>-->
<!-- <goals>-->
<!-- <goal>compile-no-fork</goal>-->
<!-- </goals>-->
<!-- <phase>package</phase>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>

View File

@ -8,8 +8,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/
@SpringBootApplication
public class LazyCloudHeartbeatClient {
public class LazyCloudHeartbeatClientSimple {
public static void main(String[] args) {
SpringApplication.run(LazyCloudHeartbeatClient.class,args);
SpringApplication.run(LazyCloudHeartbeatClientSimple.class,args);
}
}

View File

@ -1,17 +1,17 @@
spring:
middleground:
lazy:
netty:
# inet-host: 192.168.17.221
# inet-port: 4923
# inet-path: middleground-on-cloud-heartbeat-server
# inet-host: 127.0.0.1
# inet-port: 7001
inet-path: wu-lazy-cloud-heartbeat-server
inet-host: 124.222.48.62 # 服务端地址
inet-port: 30676 #服务端端口
inet-path: middleground-on-cloud-heartbeat-server
client-id: local # 客户端ID
# inet-path: wu-lazy-cloud-heartbeat-server
client-id: wujiawei # 客户端ID
data:
redis:
host: 192.168.17.221
port: 30553
password: laihui
password: wujiawei
database: 2

View File

@ -1,12 +0,0 @@
spring:
application:
name: middleground-under-cloud-heartbeat-client
cloud:
nacos:
discovery:
server-addr: 192.168.17.221:30569
config:
server-addr: 192.168.17.221:30569

View File

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-network</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
</parent>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-server</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
<description>云上心跳服务端</description>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-framework-web</artifactId>
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-lazy-cloud-heartbeat-common</artifactId>
<version>1.2.1-JDK17-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-starter</artifactId>
</dependency>
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-plus-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.33</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

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