mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2026-02-04 23:15:52 +08:00
Compare commits
59 Commits
1.2.6-JDK1
...
1.2.7-JDK1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33e8e0bf77 | ||
|
|
485d0602af | ||
|
|
9784cc65b6 | ||
|
|
576498afc7 | ||
|
|
bc1c2b008b | ||
|
|
69e761e46f | ||
|
|
616ab03495 | ||
|
|
06c45f4fef | ||
|
|
3ec0ab3271 | ||
|
|
1a2b5b8c29 | ||
|
|
c04ba09763 | ||
|
|
4f58a675d0 | ||
|
|
a5a832aa1d | ||
|
|
ccca450e73 | ||
|
|
30dfaa8dd1 | ||
|
|
54848f5bc2 | ||
|
|
b4a495e2d8 | ||
|
|
647b1b5f4b | ||
|
|
26b72fc540 | ||
|
|
80e5e4f628 | ||
|
|
e9d0f9b904 | ||
|
|
b1bd674ada | ||
|
|
37bce25f31 | ||
|
|
eda7bb1b44 | ||
|
|
9ae7a5715e | ||
|
|
2c139c9ae1 | ||
|
|
b4daa3ba70 | ||
|
|
8f1f23eb2b | ||
|
|
b4e2f8ec3c | ||
|
|
238b2906a0 | ||
|
|
a0d246a0bf | ||
|
|
c144688a9d | ||
|
|
93549cad90 | ||
|
|
7028e001ea | ||
|
|
37d9065c5a | ||
|
|
138752e56d | ||
|
|
2166a1eee6 | ||
|
|
15da22ba2d | ||
|
|
7aa2a70a43 | ||
|
|
81e2a74cf1 | ||
|
|
17aeb842db | ||
|
|
a6ab7d32e3 | ||
|
|
b4ceae4349 | ||
|
|
731c61b34a | ||
|
|
2683bb4dee | ||
|
|
4a7bdb366f | ||
|
|
234613a76a | ||
|
|
5852aad88a | ||
|
|
ee6cafa8f2 | ||
|
|
c9798d7289 | ||
|
|
10d2d74ca3 | ||
|
|
4ec1401712 | ||
|
|
f5798114f7 | ||
|
|
9bf26e99d0 | ||
|
|
b9d75715de | ||
|
|
58aae7a67d | ||
|
|
629910e860 | ||
|
|
fd364c78e7 | ||
|
|
5ddf1337ad |
22
README.md
22
README.md
@@ -36,6 +36,8 @@ wu-lazy-cloud-network
|
||||
ORM操作数据库,主要功能是网络穿透,对于没有公网IP的服务进行公网IP映射
|
||||
使用环境JDK17 Spring Boot 3.0.2
|
||||
|
||||
[UI](https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network-server-ui)
|
||||
|
||||
#### 项目地址
|
||||
|
||||
[Gitee](https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network)
|
||||
@@ -249,22 +251,22 @@ public class NettyClientSocket {
|
||||
|
||||
| 模块 | 版本 | 描述 |
|
||||
|-----------------------------------------------------------------------------------------------------------------------------------------|----------------------|------------------------------|
|
||||
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 1.2.6-JDK17-SNAPSHOT | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) |
|
||||
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 1.2.6-JDK17-SNAPSHOT | 客户端(支持二次开发) |
|
||||
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 1.2.6-JDK17-SNAPSHOT | 服务端(支持二次开发) |
|
||||
| [wu-lazy-cloud-network-ui](wu-lazy-cloud-heartbeat-server-ui) | 1.2.6-JDK17-SNAPSHOT | 服务端页面 |
|
||||
| [wu-lazy-cloud-heartbeat-client-start](wu-lazy-cloud-heartbeat-sample/wu-lazy-cloud-heartbeat-client-sample) | 1.2.6-JDK17-SNAPSHOT | 客户端样例 |
|
||||
| [wu-lazy-cloud-heartbeat-server-start](wu-lazy-cloud-heartbeat-sample/wu-lazy-cloud-heartbeat-server-sample) | 1.2.6-JDK17-SNAPSHOT | 服务端样例 |
|
||||
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 1.2.7-JDK17-SNAPSHOT | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) |
|
||||
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 1.2.7-JDK17-SNAPSHOT | 客户端(支持二次开发) |
|
||||
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 1.2.7-JDK17-SNAPSHOT | 服务端(支持二次开发) |
|
||||
| [wu-lazy-cloud-network-ui](wu-lazy-cloud-heartbeat-server-ui) | 1.2.7-JDK17-SNAPSHOT | 服务端页面 |
|
||||
| [wu-lazy-cloud-heartbeat-client-start](wu-lazy-cloud-heartbeat-sample/wu-lazy-cloud-heartbeat-client-sample) | 1.2.7-JDK17-SNAPSHOT | 客户端样例 |
|
||||
| [wu-lazy-cloud-heartbeat-server-start](wu-lazy-cloud-heartbeat-sample/wu-lazy-cloud-heartbeat-server-sample) | 1.2.7-JDK17-SNAPSHOT | 服务端样例 |
|
||||
|
||||
### 使用技术
|
||||
|
||||
| 框架 | 版本 | 描述 |
|
||||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|--------------|
|
||||
| spring-boot | 3.0.7 | springboot框架 |
|
||||
| [wu-framework-web](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-framework-web) | 1.2.6-JDK17-SNAPSHOT | web容器 |
|
||||
| [Lazy -ORM](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-inner-intergration/wu-database-parent) | 1.2.6-JDK17-SNAPSHOT | ORM |
|
||||
| [wu-framework-web](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-framework-web) | 1.2.7-JDK17-SNAPSHOT | web容器 |
|
||||
| [Lazy -ORM](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-inner-intergration/wu-database-parent) | 1.2.7-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.6-JDK17-SNAPSHOT | 用户授权体系 |
|
||||
| [wu-authorization-server-platform-starter](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-smart-platform/wu-authorization-server-platform-starter) | 1.2.7-JDK17-SNAPSHOT | 用户授权体系 |
|
||||
|
||||
### 使用环境
|
||||
|
||||
@@ -277,7 +279,7 @@ public class NettyClientSocket {
|
||||
|
||||
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.6-JDK17-SNAPSHOT
|
||||
docker run -d -it -p 18080:18080 --name wu-lazy-cloud-heartbeat-server registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.2.7-JDK17-SNAPSHOT
|
||||
|
||||
http://127.0.0.1:18080/swagger-ui/index.html
|
||||
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -8,12 +8,12 @@
|
||||
<parent>
|
||||
<artifactId>wu-framework-parent</artifactId>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<version>1.2.6-JDK17-SNAPSHOT</version>
|
||||
<version>1.2.7-JDK17</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>wu-lazy-cloud-network</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.2.6-JDK17-SNAPSHOT</version>
|
||||
<version>1.2.7-JDK17</version>
|
||||
<description>云上云下</description>
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
<dependency>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-framework-dependencies</artifactId>
|
||||
<version>1.2.6-JDK17-SNAPSHOT</version>
|
||||
<version>1.2.7-JDK17</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
13
version.md
13
version.md
@@ -8,4 +8,15 @@
|
||||
[fix] 客户端添加按钮删除
|
||||
[fix] 修改浏览器title内网穿透
|
||||
[fix] HandleChannelTypeAdvanced 添加权重 order 越小越靠前
|
||||
[fix] 新增网络映射新增、修改、删除、自动变更
|
||||
[fix] 新增网络映射新增、修改、删除、自动变更
|
||||
|
||||
#### 1.2.7-JDK17-SNAPSHOT
|
||||
[fix] 修复网络流量统计,同步线程导致io阻塞问题
|
||||
[fix] 修改默认读缓冲区大小2M,写缓冲区大小1M
|
||||
[fix] 操作系统默认读写缓冲区大小212992(cat /proc/sys/net/core/wmem_max 、cat /proc/sys/net/core/rmem_max、cat /proc/sys/net/core/wmem_default、 cat /proc/sys/net/core/rmem_default ),通过如下命令进行修改
|
||||
sudo sysctl -w net.core.rmem_default=4194304
|
||||
sudo sysctl -w net.core.rmem_max=4194304
|
||||
sudo sysctl -w net.core.wmem_default=4194304
|
||||
sudo sysctl -w net.core.wmem_max=4194304
|
||||
[fix] 修复下线客户端、删除映射无法刷新问题
|
||||
#### 下一版本计划内网渗透
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-lazy-cloud-network</artifactId>
|
||||
<version>1.2.6-JDK17-SNAPSHOT</version>
|
||||
<version>1.2.7-JDK17</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -44,13 +44,6 @@
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven_central</id>
|
||||
<name>Maven Central</name>
|
||||
<url>https://repo.maven.apache.org/maven2/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -2,13 +2,12 @@ package org.framework.lazy.cloud.network.heartbeat.client.config;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,15 +44,48 @@ public class HeartbeatClientConfiguration {
|
||||
public ClientHandleDistributeSingleClientMessageTypeAdvanced handleDistributeSingleClientMessageTypeAdvanced() {
|
||||
return new ClientHandleDistributeSingleClientMessageTypeAdvanced();
|
||||
}
|
||||
/**
|
||||
* 处理 客户端渗透服务端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced clientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferClientRequestTypeAdvanced clientHandleDistributeClientTransferClientTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferClientRequestTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleDistributeClientTransferClientResponseTypeAdvanced() {
|
||||
return new ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced handleDistributeSingleClientRealCloseVisitorTypeAdvanced() {
|
||||
return new ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientReportHandleChannelTransferTypeAdvancedHandleDistribute handleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientReportHandleChannelTransferTypeAdvancedHandleDistribute(nettyClientProperties);
|
||||
public ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute handleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -81,10 +113,53 @@ public class HeartbeatClientConfiguration {
|
||||
return new HandleDistributeStagingOpenedTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端init信息
|
||||
*
|
||||
* @return ClientHandleDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateServerInitTypeAdvanced clientHandleDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
|
||||
}
|
||||
/**
|
||||
* 处理 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @return ClientHandleDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateServerCloseTypeAdvanced clientHandleDistributeClientPermeateServerCloseTypeAdvanced( ) {
|
||||
return new ClientHandleDistributeClientPermeateServerCloseTypeAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateServerTransferTypeAdvanced clientHandleDistributeClientPermeateServerTransferTypeAdvanced( ) {
|
||||
return new ClientHandleDistributeClientPermeateServerTransferTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeSingleClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
return new ClientHandleDistributeSingleClientRealConnectTypeAdvanced(nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
public ClientHandleDistributeClientPermeateClientCloseTypeAdvanced clientHandleDistributeClientPermeateClientCloseTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientPermeateClientCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateClientInitTypeAdvanced clientHandleDistributeClientPermeateClientInitTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientPermeateClientInitTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced clientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
return new ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPermeate;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class InternalNetworkClientPermeateClientVisitor implements InternalNetworkPermeate {
|
||||
|
||||
/**
|
||||
* 当前客户端ID
|
||||
*/
|
||||
private String fromClientId;
|
||||
/**
|
||||
* 目标客户端ID
|
||||
*/
|
||||
private String toClientId;
|
||||
/**
|
||||
* 目标地址
|
||||
*/
|
||||
private String targetIp;
|
||||
|
||||
/**
|
||||
* 目标端口
|
||||
*/
|
||||
private Integer targetPort;
|
||||
|
||||
|
||||
/**
|
||||
* 访问端口
|
||||
*/
|
||||
private Integer visitorPort;
|
||||
|
||||
/**
|
||||
* 流量适配器
|
||||
*/
|
||||
private ChannelFlowAdapter channelFlowAdapter;
|
||||
/**
|
||||
* 服务端地址信息
|
||||
*/
|
||||
private NettyClientProperties nettyClientProperties;
|
||||
|
||||
/**
|
||||
* 通道处理器
|
||||
*/
|
||||
private List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
|
||||
|
||||
|
||||
/**
|
||||
* 访客ID
|
||||
*/
|
||||
private String visitorId;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPermeate;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class InternalNetworkPermeateServerVisitor implements InternalNetworkPermeate {
|
||||
|
||||
/**
|
||||
* 目标地址
|
||||
*/
|
||||
private String targetIp;
|
||||
|
||||
/**
|
||||
* 目标端口
|
||||
*/
|
||||
private Integer targetPort;
|
||||
|
||||
|
||||
/**
|
||||
* 访问端口
|
||||
*/
|
||||
private Integer visitorPort;
|
||||
/**
|
||||
* 服务端地址信息
|
||||
*/
|
||||
private NettyClientProperties nettyClientProperties;
|
||||
|
||||
/**
|
||||
* 通道处理器
|
||||
*/
|
||||
private List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
|
||||
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeChannelTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -17,11 +17,11 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientReportHandleChannelTransferTypeAdvancedHandleDistribute extends AbstractHandleDistributeChannelTransferTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute extends AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public ClientReportHandleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
|
||||
public ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,9 @@ public class ClientReportHandleChannelTransferTypeAdvancedHandleDistribute exten
|
||||
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
// 真实服务通道
|
||||
Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
|
||||
if (realChannel == null) {
|
||||
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
if (nextChannel == null) {
|
||||
log.error("无法获取访客:{} 真实服务", new String(visitorId));
|
||||
return;
|
||||
}
|
||||
@@ -51,7 +52,7 @@ public class ClientReportHandleChannelTransferTypeAdvancedHandleDistribute exten
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
|
||||
realChannel.writeAndFlush(buf);
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateClientCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));
|
||||
PermeateVisitorSocket visitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
// 关闭当前客户端渗透服务端访客通道
|
||||
try {
|
||||
visitorSocket.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateClientInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateClientInitTypeAdvanced extends AbstractHandleDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] fromClientIdBytes = nettyProxyMsg.getClientId();
|
||||
byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIpBytes = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] clientTargetPortBytes = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] toClientIdBytes = nettyProxyMsg.getData();
|
||||
|
||||
String fromClientId = new String(fromClientIdBytes);
|
||||
String toClientId = new String(toClientIdBytes);
|
||||
Integer visitorPort = Integer.parseInt(new String(visitorPortBytes));
|
||||
String clientTargetIp = new String(clientTargetIpBytes);
|
||||
Integer clientTargetPort = Integer.parseInt(new String(clientTargetPortBytes));
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
// ChannelFlowAdapter channelFlowAdapter = SpringContextHolder.getBean(ChannelFlowAdapter.class);
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
log.info("client permeate client from client_id:【{}】 to_client_id【{}】with visitor_port【{}】, clientTargetIp:【{}】clientTargetPort:【{}】",
|
||||
fromClientId, toClientId, visitorPort, clientTargetIp, clientTargetPort);
|
||||
NettyClientPermeateClientVisitorSocket nettyClientPermeateClientVisitorSocket =
|
||||
NettyClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder()
|
||||
.builderClientId(fromClientId)
|
||||
.builderClientTargetIp(clientTargetIp)
|
||||
.builderClientTargetPort(clientTargetPort)
|
||||
.builderVisitorPort(visitorPort)
|
||||
.builderNettyClientProperties(nettyClientProperties)
|
||||
// .builderChannelFlowAdapter(channelFlowAdapter)
|
||||
.builderToClientId(toClientId)
|
||||
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
|
||||
|
||||
.build();
|
||||
try {
|
||||
nettyClientPermeateClientVisitorSocket.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateClientTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateClientTransferCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 关闭客户端真实通道、访客通道
|
||||
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
realChannel.close();// 真实通道关闭
|
||||
channel.close(); // 数据传输通道关闭
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateServerCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));
|
||||
PermeateVisitorSocket visitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
// 关闭当前客户端渗透服务端访客通道
|
||||
try {
|
||||
visitorSocket.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.wu.framework.inner.lazy.orm.spring.SpringConnectionHandler;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateServerInitTypeAdvanced extends AbstractHandleDistributeClientPermeateServerInitTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public ClientHandleDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] clientIdBytes = nettyProxyMsg.getClientId();
|
||||
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyClientPermeateServerVisitorSocket nettyClientPermeateServerVisitorSocket = NettyClientPermeateServerVisitorSocket.NettyVisitorSocketBuilder.builder()
|
||||
.builderClientId(new String(clientIdBytes))
|
||||
.builderClientTargetIp(new String(clientTargetIp))
|
||||
.builderClientTargetPort(Integer.parseInt(new String(clientTargetPort)))
|
||||
.builderVisitorPort(Integer.parseInt(new String(visitorPort)))
|
||||
.builderNettyClientProperties(nettyClientProperties)
|
||||
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
|
||||
.build();
|
||||
try {
|
||||
nettyClientPermeateServerVisitorSocket.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端处理客户端数据传输
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateServerTransferTypeAdvanced extends AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
log.debug("客户端渗透服务端返回数据:{}" , new String(nettyProxyMsg.getData()));
|
||||
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
// 真实服务通道
|
||||
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
if (nextChannel == null) {
|
||||
log.error("无法获取访客:{} 真实服务", new String(visitorId));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 创建connect 然后发送创建成功
|
||||
byte[] msgClientId = nettyProxyMsg.getClientId();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
|
||||
String clientId=new String(msgClientId);
|
||||
String clientTargetIp=new String(msgClientTargetIp);
|
||||
Integer clientTargetPort=Integer.parseInt(new String(msgClientTargetPort));
|
||||
String visitorId=new String(msgVisitorId);
|
||||
Integer visitorPort=Integer.parseInt(new String(msgVisitorPort));
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyClientPermeateClientRealSocket.buildRealServer(
|
||||
clientId,
|
||||
clientTargetIp,
|
||||
clientTargetPort,
|
||||
visitorPort,
|
||||
visitorId,
|
||||
nettyClientProperties,
|
||||
handleChannelTypeAdvancedList
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输通道init 成功
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced extends AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 连接成功 开启自动读取写
|
||||
byte[] msgClientId = nettyProxyMsg.getClientId();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientRequestTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferClientRequestTypeAdvanced extends AbstractHandleDistributeClientTransferClientRequestTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
log.info("client permeate client send request to real socket byte:{} ",new String(nettyProxyMsg.getData()));
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端数据传输通道连接成功
|
||||
* @see NettyClientPermeateServerVisitorTransferSocket
|
||||
* @see NettyClientPermeateServerVisitorHandler
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param transferChannel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 连接成功 开启自动读取写
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
String visitorId = new String(msgVisitorId);
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(transferChannel);
|
||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,11 +3,11 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyServerPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPenetrationRealClient;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,12 +15,12 @@ import java.util.List;
|
||||
* 客户端创建真实代理同奥
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeSingleClientRealConnectTypeAdvanced extends AbstractHandleDistributeSingleClientRealConnectTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced extends AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;// 服务端地址信息
|
||||
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
|
||||
|
||||
public ClientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
public ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class ClientHandleDistributeSingleClientRealConnectTypeAdvanced extends A
|
||||
.build();
|
||||
|
||||
// 绑定真实服务端口
|
||||
NettyClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
NettyServerPermeateClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输响应
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced extends AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced extends AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced<NettyProxyMsg> {
|
||||
@@ -21,8 +22,9 @@ public class ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced e
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
// 获取访客对应的真实代理通道
|
||||
Channel realChannel = NettyRealIdContext.getReal(visitorId);
|
||||
if (realChannel != null) {
|
||||
realChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
if (nextChannel != null) {
|
||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 关闭本地通信通道
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
channel.close();
|
||||
nextChannel.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
@@ -11,8 +10,9 @@ import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClien
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientFilter extends ChannelInitializer<SocketChannel> {
|
||||
public class NettyClientFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
|
||||
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
@@ -24,7 +24,7 @@ public class NettyClientFilter extends ChannelInitializer<SocketChannel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
|
||||
/* * 解码和编码,应和服务端一致 * */
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
// 解码、编码
|
||||
pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10));
|
||||
pipeline.addLast(new TransferEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateClientRealHandler());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,24 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
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 org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
/**
|
||||
* netty 客户端渗透通信通道
|
||||
*/
|
||||
public class NettyClientPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
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}.
|
||||
@@ -18,13 +30,13 @@ public class NettyClientRealFilter extends ChannelInitializer<SocketChannel> {
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
pipeline.addLast(new NettyClientRealHandler());
|
||||
// // 解码、编码
|
||||
// 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 NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateClientTransferHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientTransferRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
/**
|
||||
* netty 客户端连接真实服服务端访客拦截器
|
||||
*/
|
||||
public class NettyClientPermeateClientTransferRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateClientTransferRealFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
* @throws Exception is thrown if an error occurs. In that case it will be handled by
|
||||
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateClientTransferRealHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientPermeateClientVisitorFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
|
||||
private final InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor;
|
||||
|
||||
public NettyClientPermeateClientVisitorFilter(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor) {
|
||||
this.internalNetworkClientPermeateClientVisitor = internalNetworkClientPermeateClientVisitor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
* @throws Exception is thrown if an error occurs. In that case it will be handled by
|
||||
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
pipeline.addLast(new ChannelDuplexHandler());
|
||||
pipeline.addLast(new NettyClientPermeateClientVisitorHandler(internalNetworkClientPermeateClientVisitor));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
/**
|
||||
* netty 客户端渗透通信通道
|
||||
*/
|
||||
public class NettyClientPermeateServerTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateServerTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
* @throws Exception is thrown if an error occurs. In that case it will be handled by
|
||||
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateServerTransferHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientPermeateServerVisitorFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
|
||||
private final InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor;
|
||||
|
||||
public NettyClientPermeateServerVisitorFilter(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor) {
|
||||
this.internalNetworkPermeateServerVisitor = internalNetworkPermeateServerVisitor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
* @throws Exception is thrown if an error occurs. In that case it will be handled by
|
||||
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
pipeline.addLast(new ChannelDuplexHandler());
|
||||
pipeline.addLast(new NettyClientPermeateServerVisitorHandler(internalNetworkPermeateServerVisitor));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyServerPermeateClientRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyServerPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
// 解码、编码
|
||||
pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10));
|
||||
pipeline.addLast(new TransferEncoder());
|
||||
pipeline.addLast(new NettyServerPermeateClientRealHandler());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,21 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
|
||||
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 org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientVisitorRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyServerPermeateClientTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
/**
|
||||
* netty 客户端连接真实服服务端访客拦截器
|
||||
*/
|
||||
public class NettyClientVisitorRealFilter extends ChannelInitializer<SocketChannel> {
|
||||
public class NettyServerPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientVisitorRealFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyServerPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ public class NettyClientVisitorRealFilter extends ChannelInitializer<SocketChann
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyClientVisitorRealHandler(channelTypeAdapter));
|
||||
pipeline.addLast(new NettyServerPermeateClientTransferHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 来自客户端 真实服务器返回的数据请求
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
|
||||
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx,NettyByteBuf nettyByteBuf) {
|
||||
|
||||
byte[] bytes = nettyByteBuf.getData();
|
||||
log.debug("bytes.length:{}",bytes.length);
|
||||
log.debug("接收客户端真实服务数据:{}", new String(bytes));
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(ctx.channel());
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
// 访客通信通道 上报服务端代理完成
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
NettyProxyMsg returnMessage = new NettyProxyMsg();
|
||||
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE);
|
||||
returnMessage.setVisitorId(visitorId);
|
||||
returnMessage.setClientId(clientId);
|
||||
returnMessage.setVisitorPort(visitorPort);
|
||||
returnMessage.setData(bytes);
|
||||
|
||||
nextChannel.writeAndFlush(returnMessage);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
// 客户端真实通信通道
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
// 获取访客的传输通道
|
||||
if (ctx.channel().isWritable()) {
|
||||
log.debug("Channel is writable again");
|
||||
// 恢复之前暂停的操作,如写入数据
|
||||
} else {
|
||||
log.debug("Channel is not writable");
|
||||
// 暂停写入操作,等待可写状态
|
||||
}
|
||||
log.info("channelWritabilityChanged!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
}
|
||||
@@ -3,25 +3,33 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientVisitorRealHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
public class NettyClientPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientVisitorRealHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyClientPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
@@ -29,25 +37,19 @@ public class NettyClientVisitorRealHandler extends SimpleChannelInboundHandler<N
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
// 关闭访客
|
||||
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
|
||||
if (clientChannel != null) {
|
||||
Channel channel = clientChannel.getChannel();
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_SINGLE_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
channel.writeAndFlush(closeVisitorMsg);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
@@ -55,8 +57,14 @@ public class NettyClientVisitorRealHandler extends SimpleChannelInboundHandler<N
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
super.channelWritabilityChanged(ctx);
|
||||
if (ctx.channel().isWritable()) {
|
||||
log.debug("Channel is writable again");
|
||||
// 恢复之前暂停的操作,如写入数据
|
||||
} else {
|
||||
log.debug("Channel is not writable");
|
||||
// 暂停写入操作,等待可写状态
|
||||
}
|
||||
log.info("channelWritabilityChanged!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateClientTransferRealHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
channelTypeAdapter.handler(channel, nettyProxyMsg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
// 关闭访客
|
||||
if (nextChannel != null) {
|
||||
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
// 处理客户端本地真实通道问题
|
||||
if (ctx.channel().isWritable()) {
|
||||
log.debug("Channel is writable again");
|
||||
// 恢复之前暂停的操作,如写入数据
|
||||
} else {
|
||||
log.debug("Channel is not writable");
|
||||
// 暂停写入操作,等待可写状态
|
||||
}
|
||||
log.info("channelWritabilityChanged!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
private final InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor;
|
||||
// private final NettyChannelPool nettyChannelPool = new DefaultNettyChannelPool(10);
|
||||
|
||||
public NettyClientPermeateClientVisitorHandler(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor) {
|
||||
this.internalNetworkClientPermeateClientVisitor = internalNetworkClientPermeateClientVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
* @see NettyClientPermeateServerVisitorTransferSocket
|
||||
* @see ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
// 访客连接上代理服务器了
|
||||
Channel visitorChannel = ctx.channel();
|
||||
// 先不读取访客数据
|
||||
visitorChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
|
||||
// 生成访客ID
|
||||
String visitorId = UUID.randomUUID().toString();
|
||||
// 绑定访客真实通道
|
||||
NettyRealIdContext.pushReal(visitorChannel, visitorId);
|
||||
// 当前通道绑定访客ID
|
||||
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
|
||||
|
||||
// 判断是否有可用的通道 如果没有创建新的通道
|
||||
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
|
||||
// 创建访客连接客户端通道
|
||||
NettyClientPermeateClientVisitorTransferSocket.buildTransferServer(internalNetworkClientPermeateClientVisitor,visitorChannel);
|
||||
log.info("客户端渗透客户端访客端口连接成功了");
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
|
||||
// 访客通道
|
||||
Channel visitorChannel = ctx.channel();
|
||||
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(visitorChannel);
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
// 获取客户端通道,而后进行数据下发
|
||||
log.debug("【客户端渗透客户端】访客端口成功接收数据:{}", new String(bytes));
|
||||
|
||||
// 使用访客的通信通道
|
||||
Integer visitorPort = internalNetworkClientPermeateClientVisitor.getVisitorPort();
|
||||
String clientId = internalNetworkClientPermeateClientVisitor.getNettyClientProperties().getClientId();
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST);
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
nettyProxyMsg.setClientId(clientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setData(bytes);
|
||||
nextChannel.writeAndFlush(nettyProxyMsg);
|
||||
log.debug("【客户端渗透客户端】访客端口成功发送数据了");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(channel);
|
||||
if (StringUtil.isNullOrEmpty(visitorId)) {
|
||||
super.channelInactive(ctx);
|
||||
return;
|
||||
}
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
// 通信通道自动读写打开 ,然后关闭通信通道
|
||||
|
||||
if (nextChannel != null && nextChannel.isActive()) {
|
||||
|
||||
// nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
|
||||
// 通知客户端 关闭访问通道、真实通道
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
nextChannel.writeAndFlush(myMsg);
|
||||
}
|
||||
// 关闭 访客通信通道、访客真实通道
|
||||
NettyRealIdContext.clear(visitorId);
|
||||
NettyCommunicationIdContext.clear(visitorId);
|
||||
log.warn("【客户端渗透客户端】访客端口断开连接");
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
if (ctx.channel().isWritable()) {
|
||||
log.debug("Channel is writable again");
|
||||
// 恢复之前暂停的操作,如写入数据
|
||||
} else {
|
||||
log.debug("Channel is not writable");
|
||||
// 暂停写入操作,等待可写状态
|
||||
}
|
||||
log.info("channelWritabilityChanged!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
log.error("exceptionCaught");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateServerTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
channelTypeAdapter.handler(channel, nettyProxyMsg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
// 关闭访客
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭服务端客户端真实通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
if (ctx.channel().isWritable()) {
|
||||
log.debug("Channel is writable again");
|
||||
// 恢复之前暂停的操作,如写入数据
|
||||
} else {
|
||||
log.debug("Channel is not writable");
|
||||
// 暂停写入操作,等待可写状态
|
||||
}
|
||||
log.info("channelWritabilityChanged!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
/**
|
||||
* 心跳请求处理 * 每4秒发送一次心跳请求; *
|
||||
*/
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
|
||||
if (obj instanceof IdleStateEvent event) {
|
||||
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.TYPE_HEARTBEAT);
|
||||
ctx.writeAndFlush(nettyMsg);// 发送心跳数据
|
||||
} else if (event.state() == IdleState.WRITER_IDLE) { // 如果检测到写空闲状态,关闭连接
|
||||
// 离线、暂存通知
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
} else {
|
||||
super.userEventTriggered(ctx, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
private final InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor;
|
||||
// private final NettyChannelPool nettyChannelPool = new DefaultNettyChannelPool(10);
|
||||
|
||||
public NettyClientPermeateServerVisitorHandler(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor) {
|
||||
this.internalNetworkPermeateServerVisitor = internalNetworkPermeateServerVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
* @see NettyClientPermeateServerVisitorTransferSocket
|
||||
* @see ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
// 访客连接上代理服务器了
|
||||
Channel visitorChannel = ctx.channel();
|
||||
// 先不读取访客数据
|
||||
visitorChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
// 生成访客ID
|
||||
String visitorId = UUID.randomUUID().toString();
|
||||
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
|
||||
|
||||
log.info("this channel with visitor port:{} use visitorId:{}", visitorPort, visitorId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
|
||||
// 判断是否有可用的通道 如果没有创建新的通道
|
||||
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
|
||||
// 创建访客连接服务端通道
|
||||
NettyClientPermeateServerVisitorTransferSocket.buildTransferServer(internalNetworkPermeateServerVisitor,visitorChannel);
|
||||
log.info("客户端渗透服务端访客端口连接成功了,访客ID:{}", visitorId);
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
|
||||
// 访客通道
|
||||
Channel visitorChannel = ctx.channel();
|
||||
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(visitorChannel);
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
// 获取客户端通道,而后进行数据下发
|
||||
log.debug("【客户端渗透服务端】访客端口成功接收数据:{}", new String(bytes));
|
||||
|
||||
// 使用访客的通信通道
|
||||
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
|
||||
String clientId = internalNetworkPermeateServerVisitor.getNettyClientProperties().getClientId();
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
nettyProxyMsg.setClientId(clientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setData(bytes);
|
||||
nextChannel.writeAndFlush(nettyProxyMsg);
|
||||
// 处理访客流量
|
||||
log.info("【客户端渗透服务端】访客端口成功发送数据了 访客ID:{}", visitorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
|
||||
log.info("channel inactive:{}", visitorId);
|
||||
if (StringUtil.isNullOrEmpty(visitorId)) {
|
||||
super.channelInactive(ctx);
|
||||
return;
|
||||
}
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
// 通信通道自动读写打开 ,然后关闭通信通道
|
||||
|
||||
if (nextChannel != null && nextChannel.isActive()) {
|
||||
// 通知服务端 关闭访问通道、真实通道
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
myMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(myMsg);
|
||||
//通信通道
|
||||
nextChannel.close();
|
||||
log.info("关闭访问通道、真实通道 with visitorId:{}", visitorId);
|
||||
}else {
|
||||
log.info("channel inactive:{}", nextChannel);
|
||||
}
|
||||
// 访客通道关闭
|
||||
channel.close();
|
||||
|
||||
log.warn("【客户端渗透服务端】访客端口断开连接,访客ID:{}", visitorId);
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
if (ctx.channel().isWritable()) {
|
||||
log.info("Channel is writable again");
|
||||
// 恢复之前暂停的操作,如写入数据
|
||||
} else {
|
||||
log.info("Channel is not writable");
|
||||
// 暂停写入操作,等待可写状态
|
||||
}
|
||||
log.info("channelWritabilityChanged!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
log.error("exceptionCaught");
|
||||
|
||||
Channel channel = ctx.channel();
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(channel);
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
|
||||
// 使用通信通道 下发关闭访客
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (nextChannel != null) {
|
||||
// 下发关闭访客
|
||||
NettyProxyMsg closeRealClient = new NettyProxyMsg();
|
||||
closeRealClient.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
closeRealClient.setClientId(clientId);
|
||||
closeRealClient.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeRealClient);
|
||||
}
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,35 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 来自客户端 真实服务器返回的数据请求
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientRealHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
|
||||
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
|
||||
public void channelRead0(ChannelHandlerContext ctx,NettyByteBuf nettyByteBuf) {
|
||||
|
||||
// 客户端发送真实数据到代理了
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
byte[] bytes = nettyByteBuf.getData();
|
||||
log.debug("bytes.length:{}",bytes.length);
|
||||
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);
|
||||
Channel visitor = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
NettyProxyMsg returnMessage = new NettyProxyMsg();
|
||||
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER);
|
||||
returnMessage.setVisitorId(visitorId);
|
||||
@@ -36,11 +37,10 @@ public class NettyClientRealHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
returnMessage.setVisitorPort(visitorPort);
|
||||
returnMessage.setData(bytes);
|
||||
|
||||
visitorChannel.writeAndFlush(returnMessage);
|
||||
|
||||
|
||||
visitor.writeAndFlush(returnMessage);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
@@ -51,11 +51,11 @@ public class NettyClientRealHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
// 客户端真实通信通道
|
||||
Channel visitor = NettyCommunicationIdContext.getVisitor(visitorId);
|
||||
Channel visitor = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (visitor != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_SINGLE_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setType(MessageType.REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
visitor.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
@@ -65,6 +65,7 @@ public class NettyClientRealHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
// String vid = ctx.channel().attr(Constant.VID).get();
|
||||
// if (StringUtil.isNullOrEmpty(vid)) {
|
||||
// super.channelWritabilityChanged(ctx);
|
||||
@@ -75,7 +76,19 @@ public class NettyClientRealHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
// proxyChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
// }
|
||||
|
||||
super.channelWritabilityChanged(ctx);
|
||||
// 获取访客的传输通道
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
|
||||
if(ObjectUtils.isEmpty(visitorId)) {
|
||||
super.channelWritabilityChanged(ctx);
|
||||
return;
|
||||
}
|
||||
Channel visitorCommunicationChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (visitorCommunicationChannel != null) {
|
||||
log.debug("visitorId:{} transfer AUTO_READ:{} ",visitorId,ctx.channel().isWritable());
|
||||
visitorCommunicationChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,76 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyServerPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyServerPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, NettyProxyMsg nettyProxyMsg) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
channelTypeAdapter.handler(channel, nettyProxyMsg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
// 关闭访客
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
// 处理客户端本地真实通道问题
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
if(ObjectUtils.isEmpty(visitorId)) {
|
||||
super.channelWritabilityChanged(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
// Channel realChannel = NettyRealIdContext.getReal(visitorId);
|
||||
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
if (realChannel != null) {
|
||||
log.debug("visitorId:{} transfer AUTO_READ:{} ",visitorId,ctx.channel().isWritable());
|
||||
realChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientTransferRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 客户端连接真实服务
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientRealSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
|
||||
public static void buildRealServer(String clientId,
|
||||
String clientTargetIp,
|
||||
Integer clientTargetPort,
|
||||
Integer visitorPort,
|
||||
String visitorId,
|
||||
NettyClientProperties nettyClientProperties,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
|
||||
try {
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
// .option(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .option(ChannelOption.SO_BACKLOG, 128)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyClientPermeateClientRealFilter())
|
||||
|
||||
;
|
||||
|
||||
|
||||
bootstrap.connect(clientTargetIp, clientTargetPort).addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
// 客户端链接真实服务成功 设置自动读写false 等待访客连接成功后设置成true
|
||||
Channel realChannel = future.channel();
|
||||
realChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
log.info("访客通过 客户端:【{}】,绑定本地服务,IP:{},端口:{} 新建通道成功", clientId, clientTargetIp, clientTargetPort);
|
||||
// 客户端真实通道
|
||||
NettyRealIdContext.pushReal(realChannel, visitorId);
|
||||
// 绑定访客ID到当前真实通道属性
|
||||
ChannelAttributeKeyUtils.buildVisitorId(realChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(realChannel, clientId);
|
||||
ChannelAttributeKeyUtils.buildVisitorPort(realChannel, visitorPort);
|
||||
|
||||
// 连接服务端 然后绑定通道
|
||||
// 新建一个通道处理
|
||||
newVisitorConnect2Server(clientId,
|
||||
clientTargetIp,
|
||||
clientTargetPort,
|
||||
visitorPort,
|
||||
visitorId,realChannel, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
|
||||
|
||||
} else {
|
||||
log.error("客户:【{}】,无法连接当前网络内的目标IP:【{}】,目标端口:【{}】", clientId, clientTargetIp, clientTargetPort);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建访客连接服务端
|
||||
*
|
||||
* @param nettyClientProperties 服务端配置信息
|
||||
* @param handleChannelTypeAdvancedList 处理器适配器
|
||||
* @throws InterruptedException 异常
|
||||
*/
|
||||
protected static void newVisitorConnect2Server(String clientId,
|
||||
String clientTargetIp,
|
||||
Integer clientTargetPort,
|
||||
Integer visitorPort,
|
||||
String visitorId,
|
||||
Channel realChannel,
|
||||
NettyClientProperties nettyClientProperties,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) throws InterruptedException {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
// .option(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .option(ChannelOption.SO_BACKLOG, 256)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
.handler(new NettyClientPermeateClientTransferRealFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
|
||||
;
|
||||
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
|
||||
// String clientId = nettyClientProperties.getClientId();
|
||||
|
||||
|
||||
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
|
||||
// 使用的客户端ID:{}
|
||||
log.info("Client ID used: {}", clientId);
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
realChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
// 通知服务端访客连接成功
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
nettyProxyMsg.setClientId(clientId);
|
||||
nettyProxyMsg.setClientTargetIp(clientTargetIp);
|
||||
nettyProxyMsg.setClientTargetPort(clientTargetPort);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
|
||||
transferChannel.writeAndFlush(nettyProxyMsg);
|
||||
|
||||
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
|
||||
ChannelAttributeKeyUtils.buildNextChannel(realChannel, transferChannel);
|
||||
|
||||
// 绑定客户端真实通信通道
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
log.info("无法连接到服务端....");
|
||||
transferChannel.eventLoop().schedule(() -> {
|
||||
try {
|
||||
newVisitorConnect2Server(clientId,
|
||||
clientTargetIp,
|
||||
clientTargetPort,
|
||||
visitorPort,
|
||||
visitorId,realChannel, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientVisitorFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 内网穿透 客户端渗透客户端通道
|
||||
*
|
||||
* @see NettyVisitorPortContext
|
||||
* @see NettyClientVisitorContext
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSocket {
|
||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private final NettyClientPermeateClientVisitorFilter nettyClientPermeateClientVisitorFilter;
|
||||
@Getter
|
||||
private final String clientId;
|
||||
@Getter
|
||||
private final int visitorPort;
|
||||
|
||||
public NettyClientPermeateClientVisitorSocket(NettyClientPermeateClientVisitorFilter nettyClientPermeateClientVisitorFilter, String clientId, int visitorPort) {
|
||||
this.nettyClientPermeateClientVisitorFilter = nettyClientPermeateClientVisitorFilter;
|
||||
this.clientId = clientId;
|
||||
this.visitorPort = visitorPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动客户端本地端口渗透到服务端端口
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor == null) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap
|
||||
.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
|
||||
|
||||
// 设置读缓冲区为2M
|
||||
.childOption(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.childOption(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
|
||||
|
||||
.childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||
// .childOption(ChannelOption.TCP_NODELAY, false)
|
||||
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .childOption(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认 AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
|
||||
.childHandler(nettyClientPermeateClientVisitorFilter);
|
||||
|
||||
try {
|
||||
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
// 这里时异步处理
|
||||
log.info("客户端:[{}]访客端口:[{}] 开启", clientId, visitorPort);
|
||||
NettyVisitorPortContext.pushVisitorChannel(visitorPort, future.channel());
|
||||
|
||||
} else {
|
||||
log.error("客户端:[{}]访客端口:[{}]绑定失败", clientId, visitorPort);
|
||||
}
|
||||
});
|
||||
NettyVisitorPortContext.pushVisitorSocket(visitorPort, this);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
log.warn("客户端渗透服务端:[{}]访客端口:[{}] 重复启动", clientId, visitorPort);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void close() {
|
||||
if (!bossGroup.isShutdown()) {
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
if (!workerGroup.isShutdown()) {
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor != null) {
|
||||
|
||||
// close channel
|
||||
visitor.close();
|
||||
// remove visitor
|
||||
NettyVisitorPortContext.removeVisitorChannel(visitorPort);
|
||||
// remove client this
|
||||
NettyVisitorPortContext.removeVisitorSocket(visitorPort);
|
||||
log.warn("关闭客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
} else {
|
||||
log.warn("关闭访客端口失败 未找到客户端通道 客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class NettyClientPermeateClientVisitorSocketBuilder {
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端目标地址
|
||||
*/
|
||||
private String clientTargetIp;
|
||||
|
||||
/**
|
||||
* 客户端目标端口
|
||||
*/
|
||||
private Integer clientTargetPort;
|
||||
|
||||
|
||||
/**
|
||||
* 访问端口
|
||||
*/
|
||||
private Integer visitorPort;
|
||||
/**
|
||||
* 访客ID
|
||||
*/
|
||||
private String visitorId;
|
||||
/**
|
||||
* 目标客户端ID
|
||||
*/
|
||||
private String toClientId;
|
||||
|
||||
/**
|
||||
* 流量适配器
|
||||
*/
|
||||
private ChannelFlowAdapter channelFlowAdapter;
|
||||
/**
|
||||
* 服务端地址信息
|
||||
*/
|
||||
private NettyClientProperties nettyClientProperties;
|
||||
|
||||
/**
|
||||
* 处理器
|
||||
*/
|
||||
private List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
|
||||
|
||||
public static NettyClientPermeateClientVisitorSocketBuilder builder() {
|
||||
return new NettyClientPermeateClientVisitorSocketBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充客户端
|
||||
*
|
||||
* @param clientId 客户端
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定客户端目标IP
|
||||
*
|
||||
* @param clientTargetIp 客户端目标IP
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderClientTargetIp(String clientTargetIp) {
|
||||
this.clientTargetIp = clientTargetIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定客户端目标端口
|
||||
*
|
||||
* @param clientTargetPort 客户端目标端口
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderClientTargetPort(Integer clientTargetPort) {
|
||||
this.clientTargetPort = clientTargetPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定访客端口
|
||||
*
|
||||
* @param visitorPort 访客端口
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderVisitorPort(Integer visitorPort) {
|
||||
this.visitorPort = visitorPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定流量适配器
|
||||
*
|
||||
* @param channelFlowAdapter 流量适配器
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderChannelFlowAdapter(ChannelFlowAdapter channelFlowAdapter) {
|
||||
this.channelFlowAdapter = channelFlowAdapter;
|
||||
return this;
|
||||
} /**
|
||||
* 绑定流量适配器
|
||||
*
|
||||
* @param handleChannelTypeAdvancedList 流量适配器
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderHandleChannelTypeAdvancedList(List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 服务端地址信息
|
||||
*
|
||||
* @param nettyClientProperties 客户服务端地址配置属性
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderNettyClientProperties(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定访客ID
|
||||
*
|
||||
* @param visitorId 访客ID
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderVisitorId(String visitorId) {
|
||||
this.visitorId = visitorId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标客户端ID
|
||||
*
|
||||
* @param toClientId 目标客户端ID
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyClientPermeateClientVisitorSocketBuilder builderToClientId(String toClientId) {
|
||||
this.toClientId = toClientId;
|
||||
return this;
|
||||
}
|
||||
public NettyClientPermeateClientVisitorSocket build() {
|
||||
if (clientTargetIp == null) {
|
||||
throw new IllegalArgumentException("clientTargetIp must not null");
|
||||
}
|
||||
if (clientTargetPort == null) {
|
||||
throw new IllegalArgumentException("clientTargetPort must not null");
|
||||
}
|
||||
if (visitorPort == null) {
|
||||
throw new IllegalArgumentException("visitorPort must not null");
|
||||
}
|
||||
InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor = new InternalNetworkClientPermeateClientVisitor();
|
||||
|
||||
internalNetworkClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId());
|
||||
internalNetworkClientPermeateClientVisitor.setToClientId(toClientId);
|
||||
internalNetworkClientPermeateClientVisitor.setTargetIp(clientTargetIp);
|
||||
internalNetworkClientPermeateClientVisitor.setTargetPort(clientTargetPort);
|
||||
internalNetworkClientPermeateClientVisitor.setVisitorPort(visitorPort);
|
||||
internalNetworkClientPermeateClientVisitor.setNettyClientProperties(nettyClientProperties);
|
||||
internalNetworkClientPermeateClientVisitor.setChannelFlowAdapter(channelFlowAdapter);
|
||||
internalNetworkClientPermeateClientVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
|
||||
|
||||
|
||||
NettyClientPermeateClientVisitorFilter visitorFilter = new NettyClientPermeateClientVisitorFilter(internalNetworkClientPermeateClientVisitor);
|
||||
return new NettyClientPermeateClientVisitorSocket(visitorFilter, clientId, visitorPort);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端传输通道
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientVisitorTransferSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
/**
|
||||
* 连接服务端通信通道
|
||||
*/
|
||||
public static void buildTransferServer(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor,Channel visitorChannel) {
|
||||
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
// .option(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .option(ChannelOption.SO_BACKLOG, 256)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyClientPermeateClientTransferFilter(new ChannelTypeAdapter(internalNetworkClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
|
||||
;
|
||||
NettyClientProperties nettyClientProperties = internalNetworkClientPermeateClientVisitor.getNettyClientProperties();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
|
||||
String targetIp = internalNetworkClientPermeateClientVisitor.getTargetIp();
|
||||
Integer targetPort = internalNetworkClientPermeateClientVisitor.getTargetPort();
|
||||
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
|
||||
Integer visitorPort = internalNetworkClientPermeateClientVisitor.getVisitorPort();
|
||||
String toClientId = internalNetworkClientPermeateClientVisitor.getToClientId();
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
|
||||
// 使用的客户端ID:{}
|
||||
log.info("Client ID used: {}", clientId);
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
// other clientId
|
||||
myMsg.setClientId(toClientId);
|
||||
myMsg.setVisitorPort(visitorPort);
|
||||
myMsg.setClientTargetIp(targetIp);
|
||||
myMsg.setClientTargetPort(targetPort);
|
||||
|
||||
myMsg.setVisitorId(visitorId);
|
||||
transferChannel.writeAndFlush(myMsg);
|
||||
// 绑定客户端真实通信通道
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
|
||||
// 传输通道打开后自动读取
|
||||
ChannelAttributeKeyUtils.buildNextChannel(visitorChannel, transferChannel);
|
||||
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, visitorChannel);
|
||||
|
||||
|
||||
} else {
|
||||
log.info("无法连接到服务端....");
|
||||
transferChannel.eventLoop().schedule(() -> {
|
||||
try {
|
||||
buildTransferServer(internalNetworkClientPermeateClientVisitor,visitorChannel);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateServerVisitorFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 内网穿透 客户端渗透服务端通道
|
||||
*
|
||||
* @see NettyVisitorPortContext
|
||||
* @see NettyClientVisitorContext
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSocket {
|
||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private final NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter;
|
||||
@Getter
|
||||
private final String clientId;
|
||||
@Getter
|
||||
private final int visitorPort;
|
||||
|
||||
public NettyClientPermeateServerVisitorSocket(NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter, String clientId, int visitorPort) {
|
||||
this.nettyClientPermeateServerVisitorFilter = nettyClientPermeateServerVisitorFilter;
|
||||
this.clientId = clientId;
|
||||
this.visitorPort = visitorPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动客户端本地端口渗透到服务端端口
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
PermeateVisitorSocket visitor = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
if (visitor == null) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap
|
||||
.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
|
||||
|
||||
// 设置读缓冲区为2M
|
||||
.childOption(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.childOption(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
|
||||
|
||||
.childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||
// .childOption(ChannelOption.TCP_NODELAY, false)
|
||||
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .childOption(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认 AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
|
||||
.childHandler(nettyClientPermeateServerVisitorFilter);
|
||||
|
||||
try {
|
||||
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
// 这里时异步处理
|
||||
log.info("客户端:[{}]访客端口:[{}] 开启", clientId, visitorPort);
|
||||
|
||||
} else {
|
||||
log.error("客户端:[{}]访客端口:[{}]绑定失败", clientId, visitorPort);
|
||||
}
|
||||
});
|
||||
NettyVisitorPortContext.pushVisitorSocket(visitorPort, this);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
log.warn("客户端渗透服务端:[{}]访客端口:[{}] 重复启动", clientId, visitorPort);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void close() {
|
||||
if (!bossGroup.isShutdown()) {
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
if (!workerGroup.isShutdown()) {
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
PermeateVisitorSocket permeateVisitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
if (permeateVisitorSocket != null) {
|
||||
log.warn("关闭客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
} else {
|
||||
log.warn("关闭访客端口失败 未找到客户端通道 客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class NettyVisitorSocketBuilder {
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端目标地址
|
||||
*/
|
||||
private String clientTargetIp;
|
||||
|
||||
/**
|
||||
* 客户端目标端口
|
||||
*/
|
||||
private Integer clientTargetPort;
|
||||
|
||||
|
||||
/**
|
||||
* 访问端口
|
||||
*/
|
||||
private Integer visitorPort;
|
||||
/**
|
||||
* 服务端地址信息
|
||||
*/
|
||||
private NettyClientProperties nettyClientProperties;
|
||||
|
||||
/**
|
||||
* 处理器
|
||||
*/
|
||||
private List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
|
||||
|
||||
public static NettyVisitorSocketBuilder builder() {
|
||||
return new NettyVisitorSocketBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充客户端
|
||||
*
|
||||
* @param clientId 客户端
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public NettyVisitorSocketBuilder builderClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定客户端目标IP
|
||||
*
|
||||
* @param clientTargetIp 客户端目标IP
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyVisitorSocketBuilder builderClientTargetIp(String clientTargetIp) {
|
||||
this.clientTargetIp = clientTargetIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定客户端目标端口
|
||||
*
|
||||
* @param clientTargetPort 客户端目标端口
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyVisitorSocketBuilder builderClientTargetPort(Integer clientTargetPort) {
|
||||
this.clientTargetPort = clientTargetPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定访客端口
|
||||
*
|
||||
* @param visitorPort 访客端口
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyVisitorSocketBuilder builderVisitorPort(Integer visitorPort) {
|
||||
this.visitorPort = visitorPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定流量适配器
|
||||
*
|
||||
* @param handleChannelTypeAdvancedList 流量适配器
|
||||
* @return 当前对象
|
||||
*/
|
||||
public NettyVisitorSocketBuilder builderHandleChannelTypeAdvancedList(List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 服务端地址信息
|
||||
*
|
||||
* @param nettyClientProperties 客户服务端地址配置属性
|
||||
* @return 返回当前对象
|
||||
*/
|
||||
public NettyVisitorSocketBuilder builderNettyClientProperties(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public NettyClientPermeateServerVisitorSocket build() {
|
||||
if (clientTargetIp == null) {
|
||||
throw new IllegalArgumentException("clientTargetIp must not null");
|
||||
}
|
||||
if (clientTargetPort == null) {
|
||||
throw new IllegalArgumentException("clientTargetPort must not null");
|
||||
}
|
||||
if (visitorPort == null) {
|
||||
throw new IllegalArgumentException("visitorPort must not null");
|
||||
}
|
||||
InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor = new InternalNetworkPermeateServerVisitor();
|
||||
|
||||
internalNetworkPermeateServerVisitor.setTargetIp(clientTargetIp);
|
||||
internalNetworkPermeateServerVisitor.setTargetPort(clientTargetPort);
|
||||
internalNetworkPermeateServerVisitor.setVisitorPort(visitorPort);
|
||||
internalNetworkPermeateServerVisitor.setNettyClientProperties(nettyClientProperties);
|
||||
internalNetworkPermeateServerVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
|
||||
|
||||
|
||||
NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter = new NettyClientPermeateServerVisitorFilter(internalNetworkPermeateServerVisitor);
|
||||
return new NettyClientPermeateServerVisitorSocket(nettyClientPermeateServerVisitorFilter, clientId, visitorPort);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateServerTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端传输通道
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerVisitorTransferSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
/**
|
||||
* 连接服务端通信通道
|
||||
* <p>
|
||||
* internalNetworkPermeateServerVisitor
|
||||
*/
|
||||
public static void buildTransferServer(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor, Channel visitorChannel) {
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
// .option(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .option(ChannelOption.SO_BACKLOG, 256)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
.handler(new NettyClientPermeateServerTransferFilter(new ChannelTypeAdapter(internalNetworkPermeateServerVisitor.getHandleChannelTypeAdvancedList())))
|
||||
;
|
||||
NettyClientProperties nettyClientProperties = internalNetworkPermeateServerVisitor.getNettyClientProperties();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
|
||||
String targetIp = internalNetworkPermeateServerVisitor.getTargetIp();
|
||||
Integer targetPort = internalNetworkPermeateServerVisitor.getTargetPort();
|
||||
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
|
||||
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
|
||||
// 使用的客户端ID:{}
|
||||
log.info("Client ID used: {}", clientId);
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
myMsg.setClientId(clientId);
|
||||
myMsg.setVisitorPort(visitorPort);
|
||||
myMsg.setClientTargetIp(targetIp);
|
||||
myMsg.setClientTargetPort(targetPort);
|
||||
myMsg.setVisitorId(visitorId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
|
||||
// 传输通道打开后自动读取
|
||||
ChannelAttributeKeyUtils.buildNextChannel(visitorChannel, transferChannel);
|
||||
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, visitorChannel);
|
||||
|
||||
transferChannel.writeAndFlush(myMsg);
|
||||
|
||||
} else {
|
||||
log.info("客户端渗透服务端通信通道中断....");
|
||||
transferChannel.eventLoop().schedule(() -> {
|
||||
try {
|
||||
buildTransferServer(internalNetworkPermeateServerVisitor, visitorChannel);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,7 @@ package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.Getter;
|
||||
@@ -70,6 +67,15 @@ public class NettyClientSocket {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// .childOption(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .childOption(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this))
|
||||
;
|
||||
|
||||
|
||||
@@ -6,10 +6,9 @@ import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientVisitorRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyServerPermeateClientRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyServerPermeateClientTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
@@ -22,7 +21,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* 客户端连接真实服务
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientRealSocket {
|
||||
public class NettyServerPermeateClientRealSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,20 @@ public class NettyClientRealSocket {
|
||||
String visitorId = internalNetworkPenetrationRealClient.getVisitorId();
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
|
||||
.handler(new NettyClientRealFilter());
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
// .option(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .option(ChannelOption.SO_BACKLOG, 128)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyServerPermeateClientRealFilter())
|
||||
|
||||
;
|
||||
|
||||
|
||||
bootstrap.connect(clientTargetIp, clientTargetPort).addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
// 客户端链接真实服务成功 设置自动读写false 等待访客连接成功后设置成true
|
||||
@@ -63,7 +75,7 @@ public class NettyClientRealSocket {
|
||||
|
||||
log.info("访客通过 客户端:【{}】,绑定本地服务,IP:{},端口:{} 新建通道成功", clientId, clientTargetIp, clientTargetPort);
|
||||
// 客户端真实通道
|
||||
NettyRealIdContext.pushReal(realChannel, visitorId);
|
||||
// NettyRealIdContext.pushReal(realChannel, visitorId);
|
||||
// 绑定访客ID到当前真实通道属性
|
||||
ChannelAttributeKeyUtils.buildVisitorId(realChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(realChannel, clientId);
|
||||
@@ -72,7 +84,7 @@ public class NettyClientRealSocket {
|
||||
|
||||
|
||||
// 新建一个通道处理
|
||||
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList,realChannel);
|
||||
|
||||
// 是否等 服务端相应访客通道已经可以自动读写
|
||||
// realChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
@@ -120,11 +132,24 @@ public class NettyClientRealSocket {
|
||||
*/
|
||||
protected static void newVisitorConnect2Server(InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient,
|
||||
NettyClientProperties nettyClientProperties,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) throws InterruptedException {
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList,
|
||||
Channel realChannel) throws InterruptedException {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.handler(new NettyClientVisitorRealFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
// .option(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .option(ChannelOption.SO_BACKLOG, 256)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
.handler(new NettyServerPermeateClientTransferFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
|
||||
;
|
||||
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
@@ -147,7 +172,7 @@ public class NettyClientRealSocket {
|
||||
// 使用的客户端ID:{}
|
||||
log.info("Client ID used: {}" , visitorClientId);
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel channel = futureListener.channel();
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
@@ -158,22 +183,27 @@ public class NettyClientRealSocket {
|
||||
myMsg.setClientTargetPort(clientTargetPort);
|
||||
|
||||
myMsg.setVisitorId(visitorId);
|
||||
channel.writeAndFlush(myMsg);
|
||||
transferChannel.writeAndFlush(myMsg);
|
||||
// 绑定客户端真实通信通道
|
||||
NettyCommunicationIdContext.pushVisitor(channel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, visitorClientId);
|
||||
NettyCommunicationIdContext.pushVisitor(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, visitorClientId);
|
||||
// 客户端真实通道自动读写打开
|
||||
Channel visitor = NettyRealIdContext.getReal(visitorId);
|
||||
visitor.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
|
||||
realChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
|
||||
ChannelAttributeKeyUtils.buildNextChannel(realChannel, transferChannel);
|
||||
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
log.info("每隔2s重连....");
|
||||
// 离线
|
||||
channel.eventLoop().schedule(() -> {
|
||||
transferChannel.eventLoop().schedule(() -> {
|
||||
try {
|
||||
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList,realChannel);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-lazy-cloud-network</artifactId>
|
||||
<version>1.2.6-JDK17-SNAPSHOT</version>
|
||||
<version>1.2.7-JDK17</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>wu-lazy-cloud-heartbeat-common</artifactId>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
/**
|
||||
* describe 内网渗透 客户端渗透服务端
|
||||
*
|
||||
* @author Jia wei Wu
|
||||
* @date 2023/12/29 05:21 下午
|
||||
**/
|
||||
|
||||
public interface InternalNetworkPermeate {
|
||||
|
||||
/**
|
||||
* 目标ip
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getTargetIp();
|
||||
|
||||
/**
|
||||
* 目标ip
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void setTargetIp(String targetIp);
|
||||
|
||||
/**
|
||||
* 目标端口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Integer getTargetPort();
|
||||
|
||||
/**
|
||||
* 目标端口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void setTargetPort(Integer targetPort);
|
||||
|
||||
/**
|
||||
* 访客端口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Integer getVisitorPort();
|
||||
|
||||
/**
|
||||
* 访客端口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void setVisitorPort(Integer visitorPort);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* describe 内网穿透映射 真实服务端
|
||||
*
|
||||
* @author Jia wei Wu
|
||||
* @date 2023/12/29 05:21 下午
|
||||
**/
|
||||
@Builder
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class InternalNetworkPermeateRealServer {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 客户端目标地址
|
||||
*/
|
||||
private String clientTargetIp;
|
||||
|
||||
/**
|
||||
* 客户端目标端口
|
||||
*/
|
||||
private Integer clientTargetPort;
|
||||
|
||||
|
||||
/**
|
||||
* 访问端口
|
||||
*/
|
||||
private Integer visitorPort;
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.*;
|
||||
|
||||
/**
|
||||
* @see MessageTypeEnums
|
||||
@@ -54,7 +54,7 @@ public class MessageType {
|
||||
* 上报 客户端数据传输(内网穿透数据回传)
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER
|
||||
* @see AbstractHandleReportHandleChannelTransferTypeAdvanced
|
||||
* @see AbstractHandleReportServicePermeateClientTransferTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_TRANSFER = 0X05;
|
||||
|
||||
@@ -63,16 +63,16 @@ public class MessageType {
|
||||
* 上报 客户端创建需要代理的真实端口成功
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_SINGLE_CLIENT_REAL_CONNECT
|
||||
* @see AbstractHandleReportSingleClientRealConnectTypeAdvanced
|
||||
* @see AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_SINGLE_CLIENT_REAL_CONNECT = 0X06;
|
||||
/**
|
||||
* 上报 客户端关闭一个访客通道
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_SINGLE_CLIENT_CLOSE_VISITOR
|
||||
* @see AbstractHandleReportSingleClientCloseVisitorTypeAdvanced
|
||||
* @see AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_SINGLE_CLIENT_CLOSE_VISITOR = 0X08;
|
||||
public static final byte REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR = 0X08;
|
||||
|
||||
/**
|
||||
* 上报 客户端消息到另一个客户端
|
||||
@@ -85,7 +85,7 @@ public class MessageType {
|
||||
* 服务端通道 is active
|
||||
*
|
||||
* @see MessageTypeEnums#SERVER_CHANNEL_ACTIVE
|
||||
* @see AbstractHandleServerChannelActiveTypeAdvanced
|
||||
* @see AbstractHandleReportServerChannelActiveTypeAdvanced
|
||||
*/
|
||||
public static final byte SERVER_CHANNEL_ACTIVE = 0X10;
|
||||
|
||||
@@ -97,6 +97,123 @@ public class MessageType {
|
||||
*/
|
||||
public static final byte REPORT_CLUSTER_NODE_REGISTER_MESSAGE = 0X11;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端类型------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端数据传输通道连接成功
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @see AbstractHandleReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = 0X12;
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_SERVER_INIT
|
||||
* @see AbstractHandleReportClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_SERVER_INIT = 0X13;
|
||||
/**
|
||||
* 上报 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
* @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_SERVER_CLOSE = 0X14;
|
||||
/**
|
||||
* 上报 客户端渗透服务端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
* @see AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE = 0X15;
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端通信传输
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_SERVER_TRANSFER
|
||||
* @see AbstractHandleReportClientPermeateServerTransferTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_SERVER_TRANSFER = 0X16;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端类型------------------------------------------------------------------------------------
|
||||
* 60~90
|
||||
*/
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透客户端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_INIT
|
||||
* @see AbstractHandleReportClientPermeateClientInitTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_INIT = 0X19;
|
||||
/**
|
||||
* 上报 客户端渗透客户端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
* @see AbstractHandleReportClientPermeateClientCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_CLOSE = 0X20;
|
||||
/**
|
||||
* 上报 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @see AbstractHandleReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
* @see MessageType#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = 0X21;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透客户端数据传输通道init 成功
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL
|
||||
* @see AbstractHandleReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
|
||||
* @see MessageType#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL = 0X22;
|
||||
/**
|
||||
* 上报客户端渗透客户端数据传输请求
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER_CLIENT_REQUEST
|
||||
* @see AbstractHandleReportClientTransferClientTypeAdvanced
|
||||
* @see MessageType#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST = 0X23;
|
||||
|
||||
/**
|
||||
* 上报客户端渗透客户端数据传输结果
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
|
||||
* @see AbstractHandleReportClientTransferClientResponseTypeAdvanced
|
||||
* @see MessageType#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE = 0X24;
|
||||
|
||||
/**
|
||||
* 上报客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
* @see AbstractHandleReportClientPermeateClientTransferCloseTypeAdvanced
|
||||
* @see MessageType#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
*/
|
||||
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE = 0X25;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端接收连接成功通知
|
||||
*
|
||||
@@ -130,14 +247,14 @@ public class MessageType {
|
||||
* 下发 客户端数据传输(内网穿透数据发送)
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
|
||||
* @see AbstractHandleDistributeChannelTransferTypeAdvanced
|
||||
* @see AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_TRANSFER = -0X05;
|
||||
/**
|
||||
* 下发 客户端创建需要代理的真实端口
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT
|
||||
* @see AbstractHandleDistributeSingleClientRealConnectTypeAdvanced
|
||||
* @see AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT = -0X06;
|
||||
|
||||
@@ -155,7 +272,7 @@ public class MessageType {
|
||||
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR
|
||||
* @see AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR = -0X08;
|
||||
public static final byte DISTRIBUTE_SERVER_PERMEATE_CLIENT_REAL_CLOSE_VISITOR = -0X08;
|
||||
|
||||
/**
|
||||
* 下发 客户端消息
|
||||
@@ -181,4 +298,108 @@ public class MessageType {
|
||||
* @see AbstractHandleDistributeClusterNodeRegisterTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLUSTER_NODE_REGISTER_MESSAGE = -0X11;
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端数据传输通道连接成功
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @see AbstractHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = -0X12;
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
|
||||
* @see AbstractHandleDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT = -0X13;
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端init close信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
* @see AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE = -0X14;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
* @see AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE = -0X15;
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端通信传输
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER
|
||||
* @see AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER = -0X16;
|
||||
/**
|
||||
* 下发 客户端渗透客户端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
|
||||
* @see AbstractHandleDistributeClientPermeateClientInitTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT = -0X19;
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端init close信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
* @see AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE = -0X20;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @see AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
* @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL = -0X21;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输通道init 成功
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
|
||||
* @see AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
|
||||
* @see MessageType#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL = -0X22;
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输请求
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
* @see AbstractHandleDistributeClientTransferClientRequestTypeAdvanced
|
||||
* @see MessageType#REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST = -0X23;
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输响应
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
* @see AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced
|
||||
* @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE = -0X24;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
* @see AbstractHandleDistributeClientPermeateClientTransferCloseTypeAdvanced
|
||||
* @see MessageType#REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
*/
|
||||
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE = -0X25;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Setter
|
||||
@Getter
|
||||
public class NettyByteBuf {
|
||||
// body 长度 data 4
|
||||
public static final int bodyLength = 4;
|
||||
/**
|
||||
* 消息传输数据
|
||||
* byte[] 长度 4
|
||||
*/
|
||||
private byte[] data;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 渗透端口对应访客上下文
|
||||
*/
|
||||
public class NettyPermeateVisitorContext {
|
||||
|
||||
protected static final ConcurrentHashMap<Integer/*permeatePort*/, Object/*NettyPermeateVisitorSocket*/> PERMEATE_VISITOR_SOCKET = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 添加访客
|
||||
*
|
||||
* @param permeatePort 渗透端口
|
||||
* @param permeateVisitorSocket 渗透访客socket
|
||||
*/
|
||||
public static <T> void pushPermeateVisitorSocket(Integer permeatePort, T permeateVisitorSocket) {
|
||||
PERMEATE_VISITOR_SOCKET.put(permeatePort, permeateVisitorSocket);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过客户端ID获取客户端使用的访客socket
|
||||
*
|
||||
* @param <T> 渗透访客socket
|
||||
* @param permeatePort 渗透端口
|
||||
* @return 访客
|
||||
*/
|
||||
public static <T> T getPermeateVisitorSocket(Integer permeatePort) {
|
||||
return (T) PERMEATE_VISITOR_SOCKET.getOrDefault(permeatePort, null);
|
||||
}
|
||||
/**
|
||||
* 移除 渗透访客socket
|
||||
*
|
||||
* @param permeatePort 渗透端口
|
||||
*/
|
||||
public static void removePermeateVisitorSockets(Integer permeatePort) {
|
||||
PERMEATE_VISITOR_SOCKET.remove(permeatePort);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 访客通信通道上下文(服务端、客户端 通信)
|
||||
*/
|
||||
public class NettyTransferChannelContext {
|
||||
|
||||
protected static final ConcurrentHashMap<String, Channel> VISITOR_ID = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 添加访客
|
||||
*
|
||||
* @param visitorId 访客id
|
||||
* @param visitor 访客
|
||||
*/
|
||||
public static void pushVisitor(Channel visitor, String visitorId) {
|
||||
VISITOR_ID.put(visitorId, visitor);
|
||||
}
|
||||
/**
|
||||
* 添加访客
|
||||
*
|
||||
* @param visitorId 访客id
|
||||
* @param visitor 访客
|
||||
*/
|
||||
public static void pushVisitor(Channel visitor, byte[] visitorId) {
|
||||
VISITOR_ID.put(new String(visitorId), visitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过访客端口获取访客
|
||||
*
|
||||
* @param visitorId 访客id
|
||||
* @return 访客
|
||||
*/
|
||||
public static Channel getVisitor(String visitorId) {
|
||||
return VISITOR_ID.get(visitorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过访客端口获取访客
|
||||
*
|
||||
* @param visitorId 访客id
|
||||
* @param <T> 访客范型
|
||||
* @return 访客
|
||||
*/
|
||||
public static Channel getVisitor(byte[] visitorId) {
|
||||
return getVisitor(new String(visitorId));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除访客
|
||||
*
|
||||
* @param visitorId 访客ID
|
||||
*/
|
||||
public static void clear(String visitorId) {
|
||||
Channel visitor = getVisitor(visitorId);
|
||||
if (visitor != null) {
|
||||
VISITOR_ID.remove(visitorId);
|
||||
visitor.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除访客
|
||||
*
|
||||
* @param visitorId 访客ID
|
||||
*/
|
||||
public static void clear(byte[] visitorId) {
|
||||
clear(new String(visitorId));
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* 访客通信通道上下文(服务端、客户端 通信)
|
||||
*/
|
||||
@Deprecated
|
||||
public class NettyVisitorIdContext {
|
||||
public class NettyVisitorIdChannelContext {
|
||||
|
||||
protected static final ConcurrentHashMap<String, Object> VISITOR_ID = new ConcurrentHashMap<>();
|
||||
protected static final ConcurrentHashMap<String, Channel> VISITOR_ID = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,7 +18,7 @@ public class NettyVisitorIdContext {
|
||||
* @param visitorId 访客id
|
||||
* @param visitor 访客
|
||||
*/
|
||||
public static <T> void pushVisitor(T visitor, String visitorId) {
|
||||
public static void pushVisitor(Channel visitor, String visitorId) {
|
||||
VISITOR_ID.put(visitorId, visitor);
|
||||
|
||||
}
|
||||
@@ -28,11 +27,10 @@ public class NettyVisitorIdContext {
|
||||
* 通过访客端口获取访客
|
||||
*
|
||||
* @param visitorId 访客id
|
||||
* @param <T> 访客范型
|
||||
* @return 访客
|
||||
*/
|
||||
public static <T> T getVisitor(String visitorId) {
|
||||
return (T) VISITOR_ID.get(visitorId);
|
||||
public static Channel getVisitor(String visitorId) {
|
||||
return VISITOR_ID.get(visitorId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +40,7 @@ public class NettyVisitorIdContext {
|
||||
* @param <T> 访客范型
|
||||
* @return 访客
|
||||
*/
|
||||
public static <T> T getVisitor(byte[] visitorId) {
|
||||
public static Channel getVisitor(byte[] visitorId) {
|
||||
return getVisitor(new String(visitorId));
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -7,7 +10,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class NettyVisitorPortContext {
|
||||
|
||||
protected static final ConcurrentHashMap<Integer, Object> VISITOR_PORT = new ConcurrentHashMap<>();
|
||||
protected static final ConcurrentHashMap<Integer, Channel> VISITOR_PORT_CHANNEL = new ConcurrentHashMap<>();
|
||||
protected static final ConcurrentHashMap<Integer, PermeateVisitorSocket> VISITOR_PORT_SOCKET = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -16,11 +20,20 @@ public class NettyVisitorPortContext {
|
||||
* @param visitorPort 访客端口
|
||||
* @param visitor 访客
|
||||
*/
|
||||
public static <T> void pushVisitor(Integer visitorPort, T visitor) {
|
||||
VISITOR_PORT.put(visitorPort, visitor);
|
||||
|
||||
public static void pushVisitorChannel(Integer visitorPort, Channel visitor) {
|
||||
VISITOR_PORT_CHANNEL.put(visitorPort, visitor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加访客
|
||||
*
|
||||
* @param visitorPort 访客端口
|
||||
* @param visitorSocket 访客socket
|
||||
*/
|
||||
public static <T> void pushVisitorSocket(Integer visitorPort, PermeateVisitorSocket visitorSocket) {
|
||||
VISITOR_PORT_SOCKET.put(visitorPort, visitorSocket);
|
||||
}
|
||||
/**
|
||||
* 通过访客端口获取访客
|
||||
*
|
||||
@@ -28,8 +41,19 @@ public class NettyVisitorPortContext {
|
||||
* @param <T> 访客范型
|
||||
* @return 访客
|
||||
*/
|
||||
public static <T> T getVisitor(Integer visitorPort) {
|
||||
return (T) VISITOR_PORT.get(visitorPort);
|
||||
public static Channel getVisitorChannel(Integer visitorPort) {
|
||||
return VISITOR_PORT_CHANNEL.get(visitorPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过访客端口获取访客socket
|
||||
*
|
||||
* @param visitorPort 访客端口
|
||||
* @param <T> 访客范型
|
||||
* @return 访客
|
||||
*/
|
||||
public static PermeateVisitorSocket getVisitorSocket(Integer visitorPort) {
|
||||
return VISITOR_PORT_SOCKET.get(visitorPort);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,10 +62,25 @@ public class NettyVisitorPortContext {
|
||||
* @return 删除的访客通道
|
||||
* @param <T> 访客通道范型
|
||||
*/
|
||||
public static <T> T removeVisitor(Integer visitorPort){
|
||||
T visitor = getVisitor(visitorPort);
|
||||
public static Channel removeVisitorChannel(Integer visitorPort) {
|
||||
Channel visitor = getVisitorChannel(visitorPort);
|
||||
if(visitor!=null){
|
||||
VISITOR_PORT.remove(visitorPort);
|
||||
VISITOR_PORT_CHANNEL.remove(visitorPort);
|
||||
}
|
||||
return visitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除访客 socket
|
||||
*
|
||||
* @param visitorPort 访客通道
|
||||
* @param <T> 访客通道范型
|
||||
* @return 删除的访客通道
|
||||
*/
|
||||
public static PermeateVisitorSocket removeVisitorSocket(Integer visitorPort) {
|
||||
PermeateVisitorSocket visitor = getVisitorSocket(visitorPort);
|
||||
if (visitor != null) {
|
||||
VISITOR_PORT_SOCKET.remove(visitorPort);
|
||||
}
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.flow.ChannelFl
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.flow.HandleChannelFlowAdvanced;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 通道流量适配器
|
||||
@@ -15,6 +16,14 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class ChannelFlowAdapter {
|
||||
|
||||
|
||||
ThreadPoolExecutor CHANNEL_FLOW_ADAPTER_EXECUTOR =
|
||||
new ThreadPoolExecutor(20, 200, 3L, TimeUnit.MINUTES,
|
||||
new LinkedBlockingDeque<>(500),new ThreadPoolExecutor.AbortPolicy());
|
||||
// 线程使用完后使用主线程执行
|
||||
|
||||
|
||||
|
||||
protected final List<HandleChannelFlowAdvanced> handleChannelFlowAdvancedList;
|
||||
|
||||
public ChannelFlowAdapter(List<HandleChannelFlowAdvanced> handleChannelFlowAdvancedList) {
|
||||
@@ -38,4 +47,14 @@ public class ChannelFlowAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步处理当前数据
|
||||
*
|
||||
* @param channelFlow 通道数据
|
||||
*/
|
||||
public void asyncHandler(Channel channel, ChannelFlow channelFlow) {
|
||||
CHANNEL_FLOW_ADAPTER_EXECUTOR.submit(() -> handler(channel, channelFlow));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateClientInitTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateClientTransferCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateServerInitTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端通信传输
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输通道init 成功
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientTransferClientRequestTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端数据传输通道连接成功
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
* 下发 客户端 创建真实连接
|
||||
*/
|
||||
|
||||
public abstract class AbstractHandleDistributeSingleClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
public abstract class AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.client;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输响应
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
* 客户端处理服务端下发数据
|
||||
* DISTRIBUTE_CLIENT_TRANSFER
|
||||
*/
|
||||
public abstract class AbstractHandleDistributeChannelTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
public abstract class AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透客户端init close 信息
|
||||
* REPORT_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateClientCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_CLIENT_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透客户端init信息
|
||||
* REPORT_CLIENT_PERMEATE_CLIENT_INIT
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateClientInitTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_CLIENT_INIT.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报客户端渗透客户端通信通道关闭
|
||||
*@see MessageTypeEnums#REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateClientTransferCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端init close 信息
|
||||
* REPORT_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateServerCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_SERVER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端init信息
|
||||
* REPORT_CLIENT_PERMEATE_SERVER_INIT
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateServerInitTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_SERVER_INIT.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端通信通道关闭
|
||||
* REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端通信
|
||||
* REPORT_CLIENT_PERMEATE_SERVER_TRANSFER
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientPermeateServerTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透客户端数据传输通道连接成功
|
||||
* REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透客户端数据传输通道init
|
||||
* REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报客户端渗透客户端数据传输结果
|
||||
* REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientTransferClientResponseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报客户端渗透客户端数据传输
|
||||
* REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientTransferClientTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_TRANSFER_CLIENT_REQUEST.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.advanced.server;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端数据传输通道连接成功
|
||||
* REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
public abstract class AbstractHandleReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
* 是否支持当前类型
|
||||
*
|
||||
* @param msg 通道数据
|
||||
* @return 布尔类型 是、否
|
||||
*/
|
||||
@Override
|
||||
public boolean doSupport(NettyProxyMsg msg) {
|
||||
return MessageTypeEnums.REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL.getTypeByte() == msg.getType();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
* 服务端通道 is active
|
||||
* SERVER_CHANNEL_ACTIVE
|
||||
*/
|
||||
public abstract class AbstractHandleServerChannelActiveTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
public abstract class AbstractHandleReportServerChannelActiveTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
@@ -9,9 +9,9 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
/**
|
||||
* 服务端处理客户端 关闭一个访客
|
||||
* REPORT_SINGLE_CLIENT_CLOSE_VISITOR
|
||||
* REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR
|
||||
*/
|
||||
public abstract class AbstractHandleReportSingleClientCloseVisitorTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
public abstract class AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
* 服务端处理客户端绑定真实服务成功
|
||||
* REPORT_SINGLE_CLIENT_REAL_CONNECT
|
||||
*/
|
||||
public abstract class AbstractHandleReportSingleClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
public abstract class AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
* 服务端处理客户端上报数据
|
||||
* REPORT_CLIENT_STAGING_CLOSED
|
||||
*/
|
||||
public abstract class AbstractHandleReportHandleChannelTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
public abstract class AbstractHandleReportServicePermeateClientTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
/**
|
||||
@@ -9,7 +9,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
|
||||
/**
|
||||
* 服务端处理客户端 关闭一个访客
|
||||
* REPORT_SINGLE_CLIENT_CLOSE_VISITOR
|
||||
* REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR
|
||||
*/
|
||||
public abstract class AbstractHandleReportSingleClientMessage2OtherClientTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.allocator;
|
||||
|
||||
import io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator;
|
||||
import io.netty.channel.FixedRecvByteBufAllocator;
|
||||
import io.netty.channel.RecvByteBufAllocator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static io.netty.util.internal.ObjectUtil.checkPositive;
|
||||
|
||||
/**
|
||||
* The {@link RecvByteBufAllocator} that always yields the same buffer
|
||||
* size prediction. This predictor ignores the feed back from the I/O thread.
|
||||
* 接收数据缓冲区
|
||||
*
|
||||
* @see FixedRecvByteBufAllocator
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyRecvByteBufAllocator extends DefaultMaxMessagesRecvByteBufAllocator {
|
||||
|
||||
private final int bufferSize;
|
||||
|
||||
private final class HandleImpl extends MaxMessageHandle {
|
||||
private final int bufferSize;
|
||||
|
||||
HandleImpl(int bufferSize) {
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int guess() {
|
||||
// log.info("guess :{}", bufferSize);
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attemptedBytesRead(int bytes) {
|
||||
// log.info("attemptedBytesRead:{}", bytes);
|
||||
super.attemptedBytesRead(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attemptedBytesRead() {
|
||||
int attemptedBytesRead = super.attemptedBytesRead();
|
||||
// log.info("attemptedBytesRead result:{}", attemptedBytesRead);
|
||||
return attemptedBytesRead;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lastBytesRead(int bytes) {
|
||||
super.lastBytesRead(bytes);
|
||||
// log.info("lastBytesRead result:{}", bytes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new predictor that always returns the same prediction of
|
||||
* the specified buffer size.
|
||||
*/
|
||||
public NettyRecvByteBufAllocator(int bufferSize) {
|
||||
// checkPositive(bufferSize, "bufferSize");
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Handle newHandle() {
|
||||
return new NettyRecvByteBufAllocator.HandleImpl(bufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NettyRecvByteBufAllocator respectMaybeMoreData(boolean respectMaybeMoreData) {
|
||||
super.respectMaybeMoreData(respectMaybeMoreData);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.decoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
|
||||
import org.wu.framework.core.exception.RuntimeExceptionFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ByteBuf 解码为 byte[]
|
||||
*/
|
||||
@Slf4j
|
||||
public class TransferDecoder extends
|
||||
ByteToMessageDecoder {
|
||||
|
||||
// 上一次可以读取到到数据长度
|
||||
private long latestReadableBytes = -1;
|
||||
|
||||
private final int maxFrameLength; // 读取最大长度超出会异常
|
||||
private final int perPackageLimitLength;// 粘包时合并后到包最大大小
|
||||
|
||||
public TransferDecoder(int maxFrameLength, int perPackageLimitLength) {
|
||||
this.maxFrameLength = maxFrameLength;
|
||||
this.perPackageLimitLength = perPackageLimitLength;
|
||||
}
|
||||
|
||||
protected NettyByteBuf decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
if (in == null) {
|
||||
log.info("this byteBuf is null");
|
||||
return null;
|
||||
}
|
||||
// if (latestReadableBytes == -1) {
|
||||
//
|
||||
// latestReadableBytes = in.readableBytes();
|
||||
// // 第一次什么也不做
|
||||
// return null;
|
||||
// }
|
||||
// // 第二次了哦
|
||||
// if (in.readableBytes() > latestReadableBytes && in.readableBytes() < perPackageLimitLength) {
|
||||
// // 继续粘包
|
||||
// latestReadableBytes = in.readableBytes();
|
||||
// log.info("粘包ing:{}",latestReadableBytes);
|
||||
// return null;
|
||||
// }
|
||||
// if (in.readableBytes() > maxFrameLength) {
|
||||
// RuntimeExceptionFactory.of("readableBytes is max then maxFrameLength:" + maxFrameLength);
|
||||
// }
|
||||
// log.info("粘包结束开始处理数据:{}",latestReadableBytes);
|
||||
|
||||
byte[] bytes = new byte[in.readableBytes()];
|
||||
in.readBytes(bytes);
|
||||
NettyByteBuf nettyByteBuf = new NettyByteBuf();
|
||||
nettyByteBuf.setData(bytes);
|
||||
latestReadableBytes = -1;
|
||||
|
||||
return nettyByteBuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the from one {@link ByteBuf} to an other. This method will be called till either the input
|
||||
* {@link ByteBuf} has nothing to read when return from this method or till nothing was read from the input
|
||||
* {@link ByteBuf}.
|
||||
*
|
||||
* @param ctx the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to
|
||||
* @param in the {@link ByteBuf} from which to read data
|
||||
* @param out the {@link List} to which decoded messages should be added
|
||||
* @throws Exception is thrown if an error occurs
|
||||
*/
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
Object decoded = decode(ctx, in);
|
||||
if (decoded != null) {
|
||||
out.add(decoded);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.encoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
public class TransferEncoder extends MessageToByteEncoder<NettyByteBuf> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext channelHandlerContext,NettyByteBuf nettyByteBuf, ByteBuf byteBuf) throws Exception {
|
||||
byte[] bytes = nettyByteBuf.getData();
|
||||
byteBuf.writeBytes(bytes);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@ package org.framework.lazy.cloud.network.heartbeat.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.*;
|
||||
|
||||
/**
|
||||
@@ -36,34 +36,96 @@ public enum MessageTypeEnums {
|
||||
*/
|
||||
REPORT_CLIENT_STAGING_CLOSED(MessageType.REPORT_CLIENT_STAGING_CLOSED, "上报 客户端暂存关闭"),
|
||||
/**
|
||||
* @see AbstractHandleReportHandleChannelTransferTypeAdvanced
|
||||
* @see AbstractHandleReportServicePermeateClientTransferTypeAdvanced
|
||||
*/
|
||||
|
||||
REPORT_CLIENT_TRANSFER(MessageType.REPORT_CLIENT_TRANSFER, "上报 客户端数据传输(内网穿透数据回传)"),
|
||||
/**
|
||||
* @see AbstractHandleReportSingleClientRealConnectTypeAdvanced
|
||||
* @see AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced
|
||||
*/
|
||||
REPORT_SINGLE_CLIENT_REAL_CONNECT(MessageType.REPORT_SINGLE_CLIENT_REAL_CONNECT, "上报 客户端创建需要代理的真实端口成功"),
|
||||
/**
|
||||
* @see AbstractHandleReportSingleClientCloseVisitorTypeAdvanced
|
||||
* @see AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced
|
||||
*/
|
||||
REPORT_SINGLE_CLIENT_CLOSE_VISITOR(MessageType.REPORT_SINGLE_CLIENT_CLOSE_VISITOR, "上报 客户端关闭一个访客通道"),
|
||||
REPORT_SINGLE_CLIENT_CLOSE_VISITOR(MessageType.REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR, "上报 客户端关闭一个访客通道"),
|
||||
/**
|
||||
* @see AbstractHandleReportSingleClientMessage2OtherClientTypeAdvanced
|
||||
*/
|
||||
REPORT_SINGLE_CLIENT_MESSAGE(MessageType.REPORT_SINGLE_CLIENT_MESSAGE, "上报 客户端消息到另一个客户端"),
|
||||
/**
|
||||
* @see AbstractHandleServerChannelActiveTypeAdvanced
|
||||
* @see AbstractHandleReportServerChannelActiveTypeAdvanced
|
||||
*/
|
||||
SERVER_CHANNEL_ACTIVE(MessageType.SERVER_CHANNEL_ACTIVE, "服务端通道 is active"),
|
||||
/**
|
||||
* @see AbstractHandleReportClusterNodeRegisterTypeAdvanced
|
||||
*/
|
||||
REPORT_CLUSTER_NODE_REGISTER_MESSAGE(MessageType.REPORT_CLUSTER_NODE_REGISTER_MESSAGE, "上报 集群注册"),
|
||||
/**
|
||||
* @see AbstractHandleReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL(MessageType.REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL, "上报 客户端渗透服务端数据传输通道连接成功"),
|
||||
/**
|
||||
* @see AbstractHandleReportClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_SERVER_INIT(MessageType.REPORT_CLIENT_PERMEATE_SERVER_INIT, "上报 客户端渗透服务端init信息"),
|
||||
/**
|
||||
* 上报 客户端渗透服务端init close 信息
|
||||
* @see AbstractHandleReportClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_SERVER_CLOSE, "上报 客户端渗透服务端init close 信息"),
|
||||
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端通信通道关闭
|
||||
* @see AbstractHandleReportClientPermeateServerTransferCloseTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE, "上报 客户端渗透服务端通信通道关闭"),
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透服务端通信传输
|
||||
* @see AbstractHandleReportClientPermeateServerTransferTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_SERVER_TRANSFER(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER, "上报 客户端渗透服务端通信传输"),
|
||||
|
||||
/**
|
||||
* @see AbstractHandleReportClientPermeateClientInitTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_CLIENT_INIT(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_INIT, "上报 客户端渗透客户端init信息"),
|
||||
/**
|
||||
* 上报 客户端渗透客户端init close 信息
|
||||
* @see AbstractHandleReportClientPermeateClientCloseTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_CLIENT_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_CLOSE, "上报 客户端渗透客户端init close 信息"),
|
||||
/**
|
||||
* 上报 客户端渗透客户端数据传输通道连接成功
|
||||
* @see AbstractHandleReportClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL, "上报 客户端渗透客户端数据传输通道连接成功"),
|
||||
|
||||
/**
|
||||
* 上报 客户端渗透客户端数据传输通道init 成功
|
||||
* @see AbstractHandleReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_INIT_SUCCESSFUL(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL, "上报 客户端渗透客户端数据传输通道init成功"),
|
||||
/**
|
||||
* 上报 上报客户端渗透客户端数据传输
|
||||
* @see AbstractHandleReportClientTransferClientTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_TRANSFER_CLIENT_REQUEST(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST, "上报客户端渗透客户端数据传输"),
|
||||
/**
|
||||
* 上报客户端渗透客户端数据传输结果
|
||||
* @see AbstractHandleReportClientTransferClientResponseTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE, "上报客户端渗透客户端数据传输结果"),
|
||||
/**
|
||||
* 上报客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see AbstractHandleReportClientPermeateClientTransferCloseTypeAdvanced
|
||||
*/
|
||||
REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE, "上报客户端渗透客户端通信通道关闭"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle
|
||||
*/
|
||||
|
||||
DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION(MessageType.DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION, "下发 客户端接收连接成功通知"),
|
||||
|
||||
|
||||
@@ -80,11 +142,11 @@ public enum MessageTypeEnums {
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION(MessageType.DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION, "下发 客户端暂存关闭通知"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeChannelTransferTypeAdvanced
|
||||
* @see AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_TRANSFER(MessageType.DISTRIBUTE_CLIENT_TRANSFER, "下发 客户端数据传输(内网穿透数据发送)"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeSingleClientRealConnectTypeAdvanced
|
||||
* @see AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT, "下发 客户端创建需要代理的真实端口"),
|
||||
/**
|
||||
@@ -94,7 +156,7 @@ public enum MessageTypeEnums {
|
||||
/**
|
||||
* @see AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR, "下发 客户端关闭代理服务通道"),
|
||||
DISTRIBUTE_SINGLE_CLIENT_REAL_CLOSE_VISITOR(MessageType.DISTRIBUTE_SERVER_PERMEATE_CLIENT_REAL_CLOSE_VISITOR, "下发 客户端关闭代理服务通道"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeSingleClientMessageTypeAdvanced
|
||||
*/
|
||||
@@ -108,6 +170,64 @@ public enum MessageTypeEnums {
|
||||
*/
|
||||
DISTRIBUTE_CLUSTER_NODE_REGISTER_MESSAGE(MessageType.DISTRIBUTE_CLUSTER_NODE_REGISTER_MESSAGE, "下发 集群注册"),
|
||||
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL(MessageType.DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL, "下发 客户端渗透服务端数据传输通道连接成功"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT, "下发 客户端渗透服务端init信息"),
|
||||
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE, "下发 客户端渗透服务端init close信息"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE, "下发 客户端渗透服务端通信通道关闭"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER, "下发 客户端渗透服务端通信传输"),
|
||||
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientPermeateClientInitTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT, "下发 客户端渗透客户端init信息"),
|
||||
|
||||
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE, "下发 客户端渗透客户端init close信息"),
|
||||
/**
|
||||
* @see AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL(MessageType.DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL, "下发 客户端渗透客户端数据传输通道连接成功"),
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输通道init 成功
|
||||
* @see AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL, "下发 客户端渗透客户端数据传输通道init 成功"),
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输
|
||||
* @see AbstractHandleDistributeClientTransferClientRequestTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST, "下发客户端渗透客户端数据传输"),
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输
|
||||
* @see AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE, "下发客户端渗透客户端数据传输"),
|
||||
/**
|
||||
* 下发客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
* @see AbstractHandleDistributeClientPermeateClientTransferCloseTypeAdvanced
|
||||
*/
|
||||
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE, "下发客户端渗透客户端通信通道关闭"),
|
||||
;
|
||||
|
||||
private final byte typeByte;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.filter;
|
||||
|
||||
import io.netty.channel.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public abstract class DebugChannelInitializer<C extends Channel> extends ChannelInitializer<C> {
|
||||
|
||||
protected abstract void initChannel0(C ch) throws Exception;
|
||||
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
* @throws Exception is thrown if an error occurs. In that case it will be handled by
|
||||
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default close
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel(C ch) throws Exception {
|
||||
initChannel0(ch);
|
||||
ChannelConfig config = ch.config();
|
||||
Class<?> filterClass = this.getClass();
|
||||
// 获取默认配置
|
||||
Integer defaultRcvBufSize = config.getOption(ChannelOption.SO_RCVBUF);//读缓冲区为
|
||||
log.debug("filter:{},defaultRcvBufSize:{}", filterClass, defaultRcvBufSize);
|
||||
|
||||
Integer defaultSndBufSize = config.getOption(ChannelOption.SO_SNDBUF);//写缓冲区
|
||||
log.debug("filter:{},defaultSndBufSize:{}", filterClass, defaultSndBufSize);
|
||||
|
||||
Integer defaultConnectTimeoutMillis = config.getOption(ChannelOption.CONNECT_TIMEOUT_MILLIS);// 连接时常
|
||||
log.debug("filter:{},defaultConnectTimeoutMillis:{}", filterClass, defaultConnectTimeoutMillis);
|
||||
|
||||
RecvByteBufAllocator recvByteBufAllocator = config.getOption(ChannelOption.RCVBUF_ALLOCATOR);// 获取读缓冲区大小
|
||||
log.debug("filter:{},recvByteBufAllocator:{}", filterClass, recvByteBufAllocator);
|
||||
|
||||
int writeBufferLowWaterMark = config.getWriteBufferLowWaterMark();
|
||||
int writeBufferHighWaterMark = config.getWriteBufferHighWaterMark();
|
||||
|
||||
log.debug("filter:{}, high water mark: {}", filterClass,writeBufferHighWaterMark);
|
||||
log.debug("filter:{}, low water mark: {}", filterClass,writeBufferLowWaterMark);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.pool;
|
||||
|
||||
|
||||
/**
|
||||
* 通道连接池抽象类
|
||||
*/
|
||||
public abstract class AbstractNettyChannelPool implements NettyChannelPool {
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.pool;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* 默认netty 连接池
|
||||
*/
|
||||
public class DefaultNettyChannelPool extends AbstractNettyChannelPool implements NettyChannelPool {
|
||||
|
||||
/**
|
||||
* 连接池大小
|
||||
*/
|
||||
private final int poolSize;
|
||||
|
||||
|
||||
// 绑定访客的通道
|
||||
private final ConcurrentHashMap<String, Channel> visitorChannelMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 所有的通道
|
||||
private final List<Channel> allChannelList = new ArrayList<>();
|
||||
|
||||
// 闲置的通道
|
||||
private final List<Channel> idleChannelList = new CopyOnWriteArrayList<Channel>();
|
||||
|
||||
public DefaultNettyChannelPool(int poolSize) {
|
||||
this.poolSize = poolSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据访客ID获取可以使用的通道
|
||||
*
|
||||
* @param visitorId 访客ID
|
||||
* @return Channel 如果无法获取到闲置通道返回null
|
||||
*/
|
||||
@Override
|
||||
public Channel availableChannel(String visitorId) {
|
||||
synchronized (idleChannelList) {
|
||||
if (idleChannelList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// 获取通道
|
||||
Channel visitorChannel = null;
|
||||
for (Channel idleChannel : idleChannelList) {
|
||||
if (idleChannel.isActive()) {
|
||||
visitorChannel = idleChannel;
|
||||
}
|
||||
idleChannelList.remove(idleChannel);
|
||||
}
|
||||
if (visitorChannel == null) {
|
||||
return null;
|
||||
}
|
||||
// 绑定 通道
|
||||
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
|
||||
visitorChannelMap.put(visitorId, visitorChannel);
|
||||
return visitorChannel;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.pool;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
/**
|
||||
* 通道连接池
|
||||
*/
|
||||
public interface NettyChannelPool {
|
||||
|
||||
/**
|
||||
* 根据访客ID获取可以使用的通道
|
||||
* @param visitorId 访客ID
|
||||
* @return Channel
|
||||
*/
|
||||
Channel availableChannel(String visitorId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.common.socket;
|
||||
|
||||
public interface PermeateVisitorSocket {
|
||||
|
||||
/**
|
||||
* 启动socket
|
||||
*/
|
||||
public void start() ;
|
||||
|
||||
/**
|
||||
* 关闭socket
|
||||
*/
|
||||
public void close() ;
|
||||
}
|
||||
@@ -14,6 +14,9 @@ public class ChannelAttributeKeyUtils {
|
||||
private static final AttributeKey<Integer> OUT_FLOW = AttributeKey.newInstance("outFlow");
|
||||
private static final AttributeKey<Integer> IN_FLOW = AttributeKey.newInstance("inFlow");
|
||||
|
||||
private static final AttributeKey<Channel> NEXT_CHANNEL = AttributeKey.newInstance("nextChannel");
|
||||
private static final AttributeKey<Channel> TRANSFER_NEXT_CHANNEL = AttributeKey.newInstance("transferNextChannel");
|
||||
|
||||
|
||||
/**
|
||||
* 为通道绑定 访客属性
|
||||
@@ -131,4 +134,44 @@ public class ChannelAttributeKeyUtils {
|
||||
public static Integer getVisitorPort(Channel channel) {
|
||||
return channel.attr(VISITOR_PORT).get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 为通道绑定 下一个通道
|
||||
*
|
||||
* @param channel 通道
|
||||
* @param nextChannel 下一个通道
|
||||
*/
|
||||
public static void buildNextChannel(Channel channel, Channel nextChannel) {
|
||||
channel.attr(NEXT_CHANNEL).set(nextChannel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 通道中下一个通道
|
||||
*
|
||||
* @param channel 通道
|
||||
*/
|
||||
public static Channel getNextChannel(Channel channel) {
|
||||
return channel.attr(NEXT_CHANNEL).get();
|
||||
}
|
||||
/**
|
||||
* 为通道绑定 下一个通道
|
||||
*
|
||||
* @param channel 通道
|
||||
* @param nextChannel 下一个通道
|
||||
*/
|
||||
public static void buildTransferNextChannel(Channel channel, Channel nextChannel) {
|
||||
channel.attr(TRANSFER_NEXT_CHANNEL).set(nextChannel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 通道中下一个通道
|
||||
*
|
||||
* @param channel 通道
|
||||
*/
|
||||
public static Channel getTransferNextChannel(Channel channel) {
|
||||
return channel.attr(TRANSFER_NEXT_CHANNEL).get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-lazy-cloud-network</artifactId>
|
||||
<version>1.2.6-JDK17-SNAPSHOT</version>
|
||||
<version>1.2.7-JDK17</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-lazy-cloud-network</artifactId>
|
||||
<version>1.2.6-JDK17-SNAPSHOT</version>
|
||||
<version>1.2.7-JDK17</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.server.config;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.netty.advanced.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyClientStatsChangeApplication;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyInternalNetworkPenetrationMappingApplication;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyNettyClientBlacklistApplication;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.netty.advanced.*;
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.*;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@@ -30,12 +26,12 @@ public class HeartbeatServerConfiguration {
|
||||
/**
|
||||
* 处理 服务端处理客户端数据传输
|
||||
*
|
||||
* @return ServerHandleReportHandleChannelTransferTypeAdvanced
|
||||
* @return ServerHandleReportServicePermeateClientTransferTypeAdvanced
|
||||
*/
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Bean
|
||||
public ServerHandleReportHandleChannelTransferTypeAdvanced serverReportChannelTransferTypeAdvanced(ChannelFlowAdapter channelFlowAdapter) {
|
||||
return new ServerHandleReportHandleChannelTransferTypeAdvanced(channelFlowAdapter);
|
||||
public ServerHandleReportServicePermeateClientTransferTypeAdvanced serverReportChannelTransferTypeAdvanced(ChannelFlowAdapter channelFlowAdapter) {
|
||||
return new ServerHandleReportServicePermeateClientTransferTypeAdvanced(channelFlowAdapter);
|
||||
}
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@@ -43,8 +39,14 @@ public class HeartbeatServerConfiguration {
|
||||
public ServerHandleClientConnectSuccessTypeAdvanced serverReportConnectSuccessTypeAdvanced(
|
||||
LazyClientStatsChangeApplication lazyClientStatsChangeApplication,
|
||||
LazyNettyClientBlacklistApplication lazyNettyClientBlacklistApplication,
|
||||
LazyInternalNetworkPenetrationMappingApplication lazyInternalNetworkPenetrationMappingApplication) {
|
||||
return new ServerHandleClientConnectSuccessTypeAdvanced(lazyClientStatsChangeApplication, lazyNettyClientBlacklistApplication, lazyInternalNetworkPenetrationMappingApplication);
|
||||
LazyInternalNetworkPenetrationMappingApplication lazyInternalNetworkPenetrationMappingApplication,
|
||||
LazyInternalNetworkClientPermeateServerMappingApplication lazyInternalNetworkClientPermeateServerMappingApplication,
|
||||
LazyInternalNetworkClientPermeateClientMappingApplication lazyInternalNetworkClientPermeateClientMappingApplication) {
|
||||
return new ServerHandleClientConnectSuccessTypeAdvanced(lazyClientStatsChangeApplication,
|
||||
lazyNettyClientBlacklistApplication,
|
||||
lazyInternalNetworkPenetrationMappingApplication,
|
||||
lazyInternalNetworkClientPermeateServerMappingApplication,
|
||||
lazyInternalNetworkClientPermeateClientMappingApplication);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,14 +69,14 @@ public class HeartbeatServerConfiguration {
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Bean
|
||||
public ServerHandleReportSingleClientCloseVisitorTypeAdvanced serverReportSingleClientCloseVisitorTypeAdvanced() {
|
||||
return new ServerHandleReportSingleClientCloseVisitorTypeAdvanced();
|
||||
public ServerHandleReportServicePermeateClientCloseVisitorTypeAdvanced serverReportSingleClientCloseVisitorTypeAdvanced() {
|
||||
return new ServerHandleReportServicePermeateClientCloseVisitorTypeAdvanced();
|
||||
}
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Bean
|
||||
public ServerHandleReportSingleClientRealConnectTypeAdvanced serverReportSingleClientRealConnectTypeAdvanced() {
|
||||
return new ServerHandleReportSingleClientRealConnectTypeAdvanced();
|
||||
public ServerHandleReportServicePermeateClientRealConnectTypeAdvanced serverReportSingleClientRealConnectTypeAdvanced() {
|
||||
return new ServerHandleReportServicePermeateClientRealConnectTypeAdvanced();
|
||||
}
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user