mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-16 18:35:05 +08:00
【fix】 优化代理
This commit is contained in:
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.server.AbstractHandleTcpClientConnectSuccessTypeAdvanced;
|
||||
@ -201,7 +202,7 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
|
||||
serverProxyRoute.setAllowPort(routePort);
|
||||
serverProxyRoute.setRouteType(RouteType.CLIENT_PROXY_SEVER);
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(TcpMessageType.HTTP_CLIENT_PROXY_SERVER_SERVER_ROUTE_DISTRIBUTE_);
|
||||
nettyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_SERVER_ROUTE_);
|
||||
nettyMsg.setData((JSON.toJSONString(serverProxyRoute)
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
newChannel.writeAndFlush(nettyMsg);
|
||||
@ -224,7 +225,7 @@ public class ServerHandleTcpClientConnectSuccessTypeAdvanced extends AbstractHan
|
||||
clientProxyRoute.setAllowPort(routePort);
|
||||
clientProxyRoute.setRouteType(RouteType.CLIENT_PROXY_CLIENT);
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(TcpMessageType.HTTP_CLIENT_PROXY_SERVER_CLIENT_ROUTE_DISTRIBUTE_);
|
||||
nettyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_CLIENT_ROUTE_);
|
||||
nettyMsg.setData((JSON.toJSONString(clientProxyRoute)
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
newChannel.writeAndFlush(nettyMsg);
|
||||
|
@ -8,6 +8,7 @@ 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.NettyTransferChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.server.AbstractHandleHttpReportClientProxyClientConnectionTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@ -17,7 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 服务端处理客户端代理到服务端的请求
|
||||
* HTTP_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_REPORT_
|
||||
* HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_
|
||||
*/
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
@ -56,7 +57,7 @@ public class ServerHandleHttpReportClientProxyClientConnectTransferTypeAdvanced
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetIp(targetIpString);
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetPort(Integer.parseInt(targetPortString));
|
||||
clientConnectTagetNettyProxyMsg.setClientId(clientId);
|
||||
clientConnectTagetNettyProxyMsg.setType(TcpMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_SUCCESSFUL_);
|
||||
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_SUCCESSFUL_);
|
||||
if (loadBalance != null) {
|
||||
// 让客户端主动创建一个数据传输通道
|
||||
loadBalance.writeAndFlush(clientConnectTagetNettyProxyMsg);
|
||||
|
@ -7,6 +7,7 @@ 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.NettyTransferChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.server.AbstractHandleHttpReportClientProxyClientTransferChannelInitSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@ -59,7 +60,7 @@ public class ServerHandleHttpReportClientProxyClientTransferChannelInitSuccessfu
|
||||
clientConnectTagetNettyProxyMsg.setClientId(clientId);
|
||||
clientConnectTagetNettyProxyMsg.setData(nettyByteBufData.getData());
|
||||
|
||||
clientConnectTagetNettyProxyMsg.setType(TcpMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_REQUEST_);
|
||||
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_REQUEST_);
|
||||
|
||||
transferChannel.writeAndFlush(clientConnectTagetNettyProxyMsg);
|
||||
|
||||
|
@ -7,6 +7,7 @@ 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.NettyTransferChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.server.AbstractHandleHttpReportClientProxyClientTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@ -43,7 +44,7 @@ public class ServerHandleHttpReportClientProxyClientTransferCloseTypeAdvanced
|
||||
|
||||
// 下发关闭客户端真实通道
|
||||
NettyProxyMsg closeTransferNettyProxyMsg = new NettyProxyMsg();
|
||||
closeTransferNettyProxyMsg.setType(TcpMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_);
|
||||
closeTransferNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_);
|
||||
transferNextChannel.writeAndFlush(closeTransferNettyProxyMsg);
|
||||
|
||||
channel.close();
|
||||
|
@ -5,6 +5,7 @@ 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.proxy.http.server.AbstractHandleHttpReportClientProxyClientTransferResponseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@ -15,7 +16,7 @@ import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 服务端处理客户端代理到服务端的请求
|
||||
* HTTP_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_REPORT_
|
||||
* HTTP_REPORT_CLIENT_PROXY_CLIENT_TRANSFER_CONNECTION_
|
||||
*/
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
@ -39,7 +40,7 @@ public class ServerHandleHttpReportClientProxyClientTransferResponseTypeAdvanced
|
||||
log.info("目标客户端返回数据通过服务端下发到原始通道");
|
||||
NettyProxyMsg responseProxyMsg = new NettyProxyMsg();
|
||||
responseProxyMsg.setData(nettyProxyMsg.getData());
|
||||
responseProxyMsg.setType(TcpMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_);
|
||||
responseProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_RESPONSE_);
|
||||
transferNextChannel.writeAndFlush(responseProxyMsg);
|
||||
}else {
|
||||
log.error("无法将数据下发给原始客户端");
|
||||
|
@ -20,7 +20,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务端处理客户端代理到服务端的请求
|
||||
* HTTP_CLIENT_PROXY_SERVER_TRANSFER_REPORT_
|
||||
* HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_
|
||||
*/
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
|
@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 远程代理服务通道关闭
|
||||
* HTTP_CLIENT_PROXY_SERVER_TRANSFER_CLOSE_REPORT_
|
||||
* HTTP_REPORT_CLIENT_PROXY_SERVER_TRANSFER_CLOSE_
|
||||
*/
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
|
@ -57,7 +57,7 @@ public class ServerHandleHttpReportServerProxyClientTransferChannelInitSuccessfu
|
||||
clientConnectTagetNettyProxyMsg.setClientId(clientId);
|
||||
clientConnectTagetNettyProxyMsg.setData(nettyByteBufData.getData());
|
||||
|
||||
clientConnectTagetNettyProxyMsg.setType(TcpMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_);
|
||||
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_);
|
||||
|
||||
transferChannel.writeAndFlush(clientConnectTagetNettyProxyMsg);
|
||||
|
||||
|
@ -8,6 +8,7 @@ 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.NettyTransferChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.server.AbstractHttpServerProxyClientTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@ -53,7 +54,7 @@ public class ServerHandleHttpReportServerProxyClientTransferTypeAdvanced
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetIp(targetIpString);
|
||||
clientConnectTagetNettyProxyMsg.setClientTargetPort(Integer.parseInt(targetPortString));
|
||||
clientConnectTagetNettyProxyMsg.setClientId(clientId);
|
||||
clientConnectTagetNettyProxyMsg.setType(TcpMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_);
|
||||
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_CONNECTION_SUCCESSFUL_);
|
||||
if (loadBalance != null) {
|
||||
// 让客户端主动创建一个数据传输通道
|
||||
loadBalance.writeAndFlush(clientConnectTagetNettyProxyMsg);
|
||||
|
@ -8,7 +8,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
/**
|
||||
@ -39,7 +39,7 @@ public class NettyHttpClientProxyServerRealHandler extends SimpleChannelInboundH
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
// 将数据返回给客户端
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(TcpMessageType.HTTP_CLIENT_PROXY_SERVER_TRANSFER_DISTRIBUTE_);
|
||||
nettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_TRANSFER_);
|
||||
nettyProxyMsg.setData(bytes);
|
||||
|
||||
nextChannel.writeAndFlush(nettyProxyMsg);
|
||||
|
@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.protocol.route.ClientProxyRoute;
|
||||
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteType;
|
||||
@ -73,7 +73,7 @@ public class LazyNettyClientRouteRepositoryImpl implements LazyNettyClientRout
|
||||
// 发送所有客户端本地路由刷新
|
||||
ChannelContext.getChannels().forEach((channelClientId, channels) -> {
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(TcpMessageType.HTTP_CLIENT_PROXY_SERVER_CLIENT_ROUTE_DISTRIBUTE_);
|
||||
nettyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_CLIENT_ROUTE_);
|
||||
nettyMsg.setData((JSON.toJSONString(clientProxyRoute)
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
// 发送所有客户端ID
|
||||
|
@ -4,13 +4,12 @@ import com.alibaba.fastjson.JSON;
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.ProxyMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.protocol.route.ServerProxyRoute;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.entity.LazyNettyServerRouteDO;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.converter.LazyNettyServerRouteConverter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.mapper.LazyNettyServerRouteMapper;
|
||||
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.server.route.LazyNettyServerRouteRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@ -71,7 +70,7 @@ public class LazyNettyServerRouteRepositoryImpl implements LazyNettyServerRout
|
||||
// 发送所有客户端本地路由刷新
|
||||
ChannelContext.getChannels().forEach((clientId, channels) -> {
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(TcpMessageType.HTTP_CLIENT_PROXY_SERVER_SERVER_ROUTE_DISTRIBUTE_);
|
||||
nettyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_SERVER_SERVER_ROUTE_);
|
||||
nettyMsg.setData((JSON.toJSONString(clientProxyServerRoute)
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
// 发送所有客户端ID
|
||||
|
Reference in New Issue
Block a user