mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-06 13:27:55 +08:00
【fix】修复无法启动问题
This commit is contained in:
parent
f2a22c177e
commit
9dc36fe8e9
@ -34,6 +34,7 @@ public class ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute extends
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
log.debug("接收到服务端需要内网穿透的数据:{}" , nettyProxyMsg);
|
log.debug("接收到服务端需要内网穿透的数据:{}" , nettyProxyMsg);
|
||||||
String clientId = nettyClientProperties.getClientId();
|
String clientId = nettyClientProperties.getClientId();
|
||||||
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
|
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
|
||||||
@ -42,7 +43,7 @@ public class ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute extends
|
|||||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||||
// 真实服务通道
|
// 真实服务通道
|
||||||
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
|
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if (nextChannel == null) {
|
if (nextChannel == null) {
|
||||||
log.error("无法获取访客:{} 真实服务", new String(visitorId));
|
log.error("无法获取访客:{} 真实服务", new String(visitorId));
|
||||||
return;
|
return;
|
||||||
@ -50,7 +51,7 @@ public class ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute extends
|
|||||||
|
|
||||||
|
|
||||||
// 把数据转到真实服务
|
// 把数据转到真实服务
|
||||||
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||||
buf.writeBytes(nettyProxyMsg.getData());
|
buf.writeBytes(nettyProxyMsg.getData());
|
||||||
|
|
||||||
nextChannel.writeAndFlush(buf);
|
nextChannel.writeAndFlush(buf);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||||
@ -25,10 +26,11 @@ public class ClientHandleUdpClientChannelActiveAdvanced extends AbstractHandleUd
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 缓存当前通道
|
// 缓存当前通道
|
||||||
byte[] clientIdByte = nettyProxyMsg.getClientId();
|
byte[] clientIdByte = nettyProxyMsg.getClientId();
|
||||||
String clientId = new String(clientIdByte);
|
String clientId = new String(clientIdByte);
|
||||||
ChannelContext.push(channelHandlerContext, clientId);
|
ChannelContext.push(channel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,11 @@ public class ClientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvan
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 关闭客户端真实通道、访客通道
|
// 关闭客户端真实通道、访客通道
|
||||||
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
realChannel.close();// 真实通道关闭
|
realChannel.close();// 真实通道关闭
|
||||||
channelHandlerContext.close(); // 数据传输通道关闭
|
channel.close(); // 数据传输通道关闭
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +26,10 @@ public class ClientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvan
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 关闭本地通信通道
|
// 关闭本地通信通道
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
channelHandlerContext.close();
|
channel.close();
|
||||||
nextChannel.close();
|
nextChannel.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ public class ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuc
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 连接成功 开启自动读取写
|
// 连接成功 开启自动读取写
|
||||||
byte[] msgClientId = nettyProxyMsg.getClientId();
|
byte[] msgClientId = nettyProxyMsg.getClientId();
|
||||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||||
@ -37,7 +38,7 @@ public class ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuc
|
|||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||||
|
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,11 @@ public class ClientHandleUdpDistributeClientTransferServerPermeateChannelConnect
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 连接成功 开启自动读取写
|
// 连接成功 开启自动读取写
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
String visitorId = new String(msgVisitorId);
|
String visitorId = new String(msgVisitorId);
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,10 @@ public class ClientHandleUdpDistributeServicePermeateClientTransferClientRespons
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel channel = channelHandlerContext.channel();
|
||||||
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
// 把数据转到真实服务
|
// 把数据转到真实服务
|
||||||
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||||
buf.writeBytes(nettyProxyMsg.getData());
|
buf.writeBytes(nettyProxyMsg.getData());
|
||||||
|
|
||||||
nextChannel.writeAndFlush(buf);
|
nextChannel.writeAndFlush(buf);
|
||||||
|
@ -19,11 +19,12 @@ public class ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvance
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 获取访客ID
|
// 获取访客ID
|
||||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||||
// 获取访客对应的真实代理通道
|
// 获取访客对应的真实代理通道
|
||||||
Channel realChannel = NettyRealIdContext.getReal(visitorId);
|
Channel realChannel = NettyRealIdContext.getReal(visitorId);
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if (nextChannel != null) {
|
if (nextChannel != null) {
|
||||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,11 @@ public class ClientHandleDistributeHttpClientProxyClientTransferRequestAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 数据发送
|
// 数据发送
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if(ObjectUtils.isNotEmpty(nextChannel)){
|
if(ObjectUtils.isNotEmpty(nextChannel)){
|
||||||
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||||
buf.writeBytes(nettyProxyMsg.getData());
|
buf.writeBytes(nettyProxyMsg.getData());
|
||||||
nextChannel.writeAndFlush(buf);
|
nextChannel.writeAndFlush(buf);
|
||||||
}else {
|
}else {
|
||||||
|
@ -26,15 +26,17 @@ public class ClientHandleDistributeHttpClientProxyServerTransferTypeAdvanced ext
|
|||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
|
||||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channelHandlerContext);
|
Channel channel = channelHandlerContext.channel();
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
|
||||||
|
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
|
||||||
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if (nextChannel == null) {
|
if (nextChannel == null) {
|
||||||
log.error("无法获取访客:{} 真实服务", visitorId);
|
log.error("无法获取访客:{} 真实服务", visitorId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 把数据转到真实服务
|
// 把数据转到真实服务
|
||||||
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||||
buf.writeBytes(nettyProxyMsg.getData());
|
buf.writeBytes(nettyProxyMsg.getData());
|
||||||
|
|
||||||
nextChannel.writeAndFlush(buf);
|
nextChannel.writeAndFlush(buf);
|
||||||
|
@ -26,11 +26,11 @@ public class ClientHandleDistributeHttpServerProxyClientTransferRequestAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 数据发送
|
// 数据发送
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if (ObjectUtils.isNotEmpty(nextChannel)) {
|
if (ObjectUtils.isNotEmpty(nextChannel)) {
|
||||||
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||||
buf.writeBytes(nettyProxyMsg.getData());
|
buf.writeBytes(nettyProxyMsg.getData());
|
||||||
nextChannel.writeAndFlush(buf);
|
nextChannel.writeAndFlush(buf);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
|
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.NettyHttpClientProxyClient;
|
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.NettyHttpClientProxyClient;
|
||||||
@ -29,6 +30,7 @@ public class ClientHandleHttpClientProxyClientTypeAdvanced extends
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||||
byte[] data = nettyProxyMsg.getData();
|
byte[] data = nettyProxyMsg.getData();
|
||||||
@ -46,6 +48,6 @@ public class ClientHandleHttpClientProxyClientTypeAdvanced extends
|
|||||||
nettyHttpClientProxyClient.setNettyClientProperties(nettyClientProperties);
|
nettyHttpClientProxyClient.setNettyClientProperties(nettyClientProperties);
|
||||||
nettyHttpClientProxyClient.setData(data);
|
nettyHttpClientProxyClient.setData(data);
|
||||||
|
|
||||||
NettyHttpClientProxyClientProxySocket.buildTransferServer(nettyHttpClientProxyClient, channelHandlerContext);
|
NettyHttpClientProxyClientProxySocket.buildTransferServer(nettyHttpClientProxyClient, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
|
package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.NettyHttpClientProxyServer;
|
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.NettyHttpClientProxyServer;
|
||||||
@ -29,6 +30,7 @@ public class ClientHandleHttpClientProxyServerTypeAdvanced extends
|
|||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||||
byte[] data = nettyProxyMsg.getData();
|
byte[] data = nettyProxyMsg.getData();
|
||||||
@ -45,7 +47,7 @@ public class ClientHandleHttpClientProxyServerTypeAdvanced extends
|
|||||||
nettyHttpClientProxyServer.setNettyClientProperties(nettyClientProperties);
|
nettyHttpClientProxyServer.setNettyClientProperties(nettyClientProperties);
|
||||||
nettyHttpClientProxyServer.setData(data);
|
nettyHttpClientProxyServer.setData(data);
|
||||||
|
|
||||||
NettyHttpClientProxyServerProxySocket.buildTransferServer(nettyHttpClientProxyServer, channelHandlerContext);
|
NettyHttpClientProxyServerProxySocket.buildTransferServer(nettyHttpClientProxyServer, channel);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ public class ClientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvance
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 关闭传输通道
|
// 关闭传输通道
|
||||||
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
realChannel.close();// 真实通道关闭
|
realChannel.close();// 真实通道关闭
|
||||||
channelHandlerContext.close(); // 数据传输通道关闭
|
channel.close(); // 数据传输通道关闭
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,11 @@ public class ClientHandleHttpDistributeClientProxyClientTransferResponseTypeAdva
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 数据发送
|
// 数据发送
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if(ObjectUtils.isNotEmpty(nextChannel)){
|
if(ObjectUtils.isNotEmpty(nextChannel)){
|
||||||
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||||
buf.writeBytes(nettyProxyMsg.getData());
|
buf.writeBytes(nettyProxyMsg.getData());
|
||||||
nextChannel.writeAndFlush(buf);
|
nextChannel.writeAndFlush(buf);
|
||||||
}else {
|
}else {
|
||||||
|
@ -65,21 +65,21 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
||||||
|
Channel newChannel = channelHandlerContext.channel();
|
||||||
|
|
||||||
String clientId = msg.getClientIdString();
|
String clientId = msg.getClientIdString();
|
||||||
String appKey = msg.getAppKeyString();
|
String appKey = msg.getAppKeyString();
|
||||||
String appSecret = msg.getAppSecretString();
|
String appSecret = msg.getAppSecretString();
|
||||||
String originalIp = msg.getOriginalIpString();
|
String originalIp = msg.getOriginalIpString();
|
||||||
ChannelContext.push(channelHandlerContext, clientId);
|
ChannelContext.push(newChannel, clientId);
|
||||||
|
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(newChannel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildAppKey(channelHandlerContext, appKey);
|
ChannelAttributeKeyUtils.buildAppKey(newChannel, appKey);
|
||||||
ChannelAttributeKeyUtils.buildAppSecret(channelHandlerContext, appSecret);
|
ChannelAttributeKeyUtils.buildAppSecret(newChannel, appSecret);
|
||||||
ChannelAttributeKeyUtils.buildOriginalIp(channelHandlerContext, originalIp);
|
ChannelAttributeKeyUtils.buildOriginalIp(newChannel, originalIp);
|
||||||
|
|
||||||
// 客户端:{},IP:{}连接成功
|
// 客户端:{},IP:{}连接成功
|
||||||
log.info("Client: {}, IP: {} Connection successful", new String(msg.getClientId()), channelHandlerContext.remoteAddress().toString());
|
log.info("Client: {}, IP: {} Connection successful", new String(msg.getClientId()), newChannel.remoteAddress().toString());
|
||||||
// 验证客户端是否时黑名单
|
// 验证客户端是否时黑名单
|
||||||
LazyNettyClientBlacklist lazyNettyClientBlacklist = new LazyNettyClientBlacklist();
|
LazyNettyClientBlacklist lazyNettyClientBlacklist = new LazyNettyClientBlacklist();
|
||||||
lazyNettyClientBlacklist.setClientId(clientId);
|
lazyNettyClientBlacklist.setClientId(clientId);
|
||||||
@ -125,7 +125,7 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
|
|||||||
}else {
|
}else {
|
||||||
// 关闭通道
|
// 关闭通道
|
||||||
log.warn("无法认证客户端:【{}】",clientId);
|
log.warn("无法认证客户端:【{}】",clientId);
|
||||||
channelHandlerContext.close();
|
newChannel.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
|
|||||||
nettyMsg.setClientTargetIp(permeateTargetIp);
|
nettyMsg.setClientTargetIp(permeateTargetIp);
|
||||||
nettyMsg.setClientTargetPort(permeateTargetPort);
|
nettyMsg.setClientTargetPort(permeateTargetPort);
|
||||||
nettyMsg.setVisitorPort(visitorPort);
|
nettyMsg.setVisitorPort(visitorPort);
|
||||||
channelHandlerContext.writeAndFlush(nettyMsg);
|
newChannel.writeAndFlush(nettyMsg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ public class ServerHandleUdpClientConnectSuccessTypeAdvanced extends AbstractHan
|
|||||||
nettyMsg.setVisitorPort(visitorPort);
|
nettyMsg.setVisitorPort(visitorPort);
|
||||||
nettyMsg.setClientId(clientId);
|
nettyMsg.setClientId(clientId);
|
||||||
nettyMsg.setData(toClientId.getBytes(StandardCharsets.UTF_8));
|
nettyMsg.setData(toClientId.getBytes(StandardCharsets.UTF_8));
|
||||||
channelHandlerContext.writeAndFlush(nettyMsg);
|
newChannel.writeAndFlush(nettyMsg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ public class ServerHandleUdpReportClientPermeateClientCloseTypeAdvanced extends
|
|||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
// 关闭 next、next transfer 通道
|
// 关闭 next、next transfer 通道
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
|
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||||
channelHandlerContext.close();
|
channel.close();
|
||||||
nextChannel.close();
|
nextChannel.close();
|
||||||
transferNextChannel.close();
|
transferNextChannel.close();
|
||||||
}
|
}
|
||||||
|
@ -29,16 +29,16 @@ public class ServerHandleUdpReportClientPermeateClientTransferCloseTypeAdvanced
|
|||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
// 关闭 next、next transfer 通道
|
// 关闭 next、next transfer 通道
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
|
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||||
|
|
||||||
// 下发关闭客户端真实通道
|
// 下发关闭客户端真实通道
|
||||||
NettyProxyMsg closeTransferNettyProxyMsg = new NettyProxyMsg();
|
NettyProxyMsg closeTransferNettyProxyMsg = new NettyProxyMsg();
|
||||||
closeTransferNettyProxyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
closeTransferNettyProxyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||||
transferNextChannel.writeAndFlush(closeTransferNettyProxyMsg);
|
transferNextChannel.writeAndFlush(closeTransferNettyProxyMsg);
|
||||||
|
|
||||||
channelHandlerContext.close();
|
channel.close();
|
||||||
nextChannel.close();
|
nextChannel.close();
|
||||||
transferNextChannel.close();
|
transferNextChannel.close();
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,10 @@ public class ServerHandleUdpReportClientPermeateServerTransferCloseTypeAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 关闭传输通信通道
|
// 关闭传输通信通道
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
nextChannel.close();
|
nextChannel.close();
|
||||||
channelHandlerContext.close();
|
channel.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ public class ServerHandleUdpReportClientPermeateServerTransferTypeAdvanced exten
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
String clientId = new String(msg.getClientId());
|
String clientId = new String(msg.getClientId());
|
||||||
Integer visitorPort = Integer.valueOf(new String(msg.getVisitorPort()));
|
Integer visitorPort = Integer.valueOf(new String(msg.getVisitorPort()));
|
||||||
byte[] visitorId = msg.getVisitorId();
|
byte[] visitorId = msg.getVisitorId();
|
||||||
@ -44,7 +45,7 @@ public class ServerHandleUdpReportClientPermeateServerTransferTypeAdvanced exten
|
|||||||
log.debug("【客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 接收服务端数据大小:[{}] 接收服务端数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
|
log.debug("【客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 接收服务端数据大小:[{}] 接收服务端数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
|
||||||
// 将数据转发访客通道
|
// 将数据转发访客通道
|
||||||
|
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if (nextChannel != null) {
|
if (nextChannel != null) {
|
||||||
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
|
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
|
||||||
buf.writeBytes(msg.getData());
|
buf.writeBytes(msg.getData());
|
||||||
@ -59,7 +60,7 @@ public class ServerHandleUdpReportClientPermeateServerTransferTypeAdvanced exten
|
|||||||
.clientId(clientId)
|
.clientId(clientId)
|
||||||
.flow(msg.getData().length)
|
.flow(msg.getData().length)
|
||||||
.build();
|
.build();
|
||||||
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
|
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
|
||||||
}
|
}
|
||||||
log.debug("客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 传输真实数据成功", new String(visitorId), clientId);
|
log.debug("客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 传输真实数据成功", new String(visitorId), clientId);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelConnectionS
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 创建目标地址连接
|
// 创建目标地址连接
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||||
@ -35,11 +36,11 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelConnectionS
|
|||||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||||
byte[] clientId = nettyProxyMsg.getClientId();// 目标客户端ID
|
byte[] clientId = nettyProxyMsg.getClientId();// 目标客户端ID
|
||||||
|
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorPort(channelHandlerContext, Integer.parseInt(new String(msgVisitorPort)));
|
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.parseInt(new String(msgVisitorPort)));
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||||
// 绑定访客通道
|
// 绑定访客通道
|
||||||
NettyTransferChannelContext.pushVisitor(channelHandlerContext,msgVisitorId);
|
NettyTransferChannelContext.pushVisitor(channel,msgVisitorId);
|
||||||
Channel clientChannel = ChannelContext.getLoadBalance(clientId);
|
Channel clientChannel = ChannelContext.getLoadBalance(clientId);
|
||||||
|
|
||||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||||
|
@ -27,6 +27,7 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelInitSuccess
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 创建目标地址连接
|
// 创建目标地址连接
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||||
@ -34,15 +35,15 @@ public class ServerHandleUdpReportClientTransferClientPermeateChannelInitSuccess
|
|||||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||||
byte[] clientId = nettyProxyMsg.getClientId();
|
byte[] clientId = nettyProxyMsg.getClientId();
|
||||||
|
|
||||||
ChannelAttributeKeyUtils.buildVisitorPort(channelHandlerContext, Integer.parseInt(new String(msgVisitorPort)));
|
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.parseInt(new String(msgVisitorPort)));
|
||||||
// next translation
|
// next translation
|
||||||
Channel nextTransferChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
|
Channel nextTransferChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
|
||||||
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channelHandlerContext);
|
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channel);
|
||||||
ChannelAttributeKeyUtils.buildTransferNextChannel(channelHandlerContext,nextTransferChannel);
|
ChannelAttributeKeyUtils.buildTransferNextChannel(channel,nextTransferChannel);
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext,clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel,clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext,msgVisitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel,msgVisitorId);
|
||||||
|
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||||
|
|
||||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||||
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);
|
clientConnectTagetNettyProxyMsg.setVisitorId(msgVisitorId);
|
||||||
|
@ -30,6 +30,9 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
|
|
||||||
// 创建目标地址连接
|
// 创建目标地址连接
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||||
@ -37,7 +40,7 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
|
|||||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||||
String clientId = nettyProxyMsg.getClientIdString();
|
String clientId = nettyProxyMsg.getClientIdString();
|
||||||
// 下发客户端初始化成功
|
// 下发客户端初始化成功
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||||
|
|
||||||
|
|
||||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||||
@ -61,7 +64,7 @@ public class ServerHandleUdpReportClientTransferClientResponseTypeAdvanced exten
|
|||||||
.flow(clientConnectTagetNettyProxyMsg.getData().length)
|
.flow(clientConnectTagetNettyProxyMsg.getData().length)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
|
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
|
||||||
}else {
|
}else {
|
||||||
log.error("can not find the client:【{}】 channelHandlerContext",clientId);
|
log.error("can not find the client:【{}】 channelHandlerContext",clientId);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 创建目标地址连接
|
// 创建目标地址连接
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||||
@ -37,8 +38,8 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
|
|||||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||||
String clientId = nettyProxyMsg.getClientIdString();
|
String clientId = nettyProxyMsg.getClientIdString();
|
||||||
// 下发客户端初始化成功
|
// 下发客户端初始化成功
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||||
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channelHandlerContext);
|
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(channel);
|
||||||
|
|
||||||
|
|
||||||
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
NettyProxyMsg clientConnectTagetNettyProxyMsg = new NettyProxyMsg();
|
||||||
@ -60,7 +61,7 @@ public class ServerHandleUdpReportClientTransferClientTypeAdvanced extends Abstr
|
|||||||
.clientId(clientId)
|
.clientId(clientId)
|
||||||
.flow(clientConnectTagetNettyProxyMsg.getData().length)
|
.flow(clientConnectTagetNettyProxyMsg.getData().length)
|
||||||
.build();
|
.build();
|
||||||
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
|
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
|
||||||
}else {
|
}else {
|
||||||
log.error("can not find the client:【{}】 channelHandlerContext",clientId);
|
log.error("can not find the client:【{}】 channelHandlerContext",clientId);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.udp.advanced;
|
package org.framework.lazy.cloud.network.heartbeat.server.netty.permeate.udp.advanced;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.server.AbstractHandleUdpReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.server.AbstractHandleUdpReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||||
@ -23,6 +24,7 @@ public class ServerHandleUdpReportClientTransferServerPermeateChannelConnectionS
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 创建目标地址连接
|
// 创建目标地址连接
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||||
@ -31,13 +33,13 @@ public class ServerHandleUdpReportClientTransferServerPermeateChannelConnectionS
|
|||||||
byte[] msgClientId = nettyProxyMsg.getClientId();
|
byte[] msgClientId = nettyProxyMsg.getClientId();
|
||||||
String clientId = new String(msgClientId);
|
String clientId = new String(msgClientId);
|
||||||
// 绑定客户端ID
|
// 绑定客户端ID
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext,clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel,clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext,msgVisitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel,msgVisitorId);
|
||||||
NettyUdpClientPermeateServerConnectRealSocket.buildNewRealServer(new String(msgVisitorId),
|
NettyUdpClientPermeateServerConnectRealSocket.buildNewRealServer(new String(msgVisitorId),
|
||||||
Integer.parseInt(new String(msgVisitorPort)),
|
Integer.parseInt(new String(msgVisitorPort)),
|
||||||
new String(msgClientTargetIp),
|
new String(msgClientTargetIp),
|
||||||
Integer.parseInt(new String(msgClientTargetPort)),
|
Integer.parseInt(new String(msgClientTargetPort)),
|
||||||
channelHandlerContext
|
channel
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,13 +44,14 @@ public class ServerHandleUdpReportDisconnectTypeAdvanced extends AbstractHandleU
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
||||||
|
Channel deathChannel = channelHandlerContext.channel();
|
||||||
// 关闭连接通知
|
// 关闭连接通知
|
||||||
String clientId = msg.getClientIdString();
|
String clientId = msg.getClientIdString();
|
||||||
log.warn("close client :{} channel", clientId);
|
log.warn("close client :{} channel", clientId);
|
||||||
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(clientId);
|
Channel deathClientChannelDTO = ChannelContext.getLoadBalance(clientId);
|
||||||
String appKey = ChannelAttributeKeyUtils.getAppKey(channelHandlerContext);
|
String appKey = ChannelAttributeKeyUtils.getAppKey(deathChannel);
|
||||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(channelHandlerContext);
|
String appSecret = ChannelAttributeKeyUtils.getAppSecret(deathChannel);
|
||||||
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(channelHandlerContext);
|
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(deathChannel);
|
||||||
if (deathClientChannelDTO != null) {
|
if (deathClientChannelDTO != null) {
|
||||||
// 服务状态离线
|
// 服务状态离线
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ public class ServerHandleUdpReportServicePermeateClientRealConnectTypeAdvanced e
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 客户端绑定端口成功
|
// 客户端绑定端口成功
|
||||||
byte[] clientId = nettyProxyMsg.getClientId();
|
byte[] clientId = nettyProxyMsg.getClientId();
|
||||||
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
|
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||||
@ -37,16 +38,16 @@ public class ServerHandleUdpReportServicePermeateClientRealConnectTypeAdvanced e
|
|||||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||||
log.info("客户端:{},绑定真实服务ip:{},port:{},成功", new String(clientId), new String(clientTargetIp), new String(clientTargetPort));
|
log.info("客户端:{},绑定真实服务ip:{},port:{},成功", new String(clientId), new String(clientTargetIp), new String(clientTargetPort));
|
||||||
// 绑定服务端访客通信通道
|
// 绑定服务端访客通信通道
|
||||||
NettyCommunicationIdContext.pushVisitor(channelHandlerContext, new String(visitorId));
|
NettyCommunicationIdContext.pushVisitor(channel, new String(visitorId));
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, visitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorPort(channelHandlerContext, Integer.valueOf(new String(visitorPort)));
|
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.valueOf(new String(visitorPort)));
|
||||||
// 访客通道开启自动读取
|
// 访客通道开启自动读取
|
||||||
Channel visitorRealChannel = NettyRealIdContext.getReal(visitorId);
|
Channel visitorRealChannel = NettyRealIdContext.getReal(visitorId);
|
||||||
visitorRealChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
visitorRealChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||||
|
|
||||||
ChannelAttributeKeyUtils.buildNextChannel(channelHandlerContext, visitorRealChannel);
|
ChannelAttributeKeyUtils.buildNextChannel(channel, visitorRealChannel);
|
||||||
ChannelAttributeKeyUtils.buildNextChannel(visitorRealChannel, channelHandlerContext);
|
ChannelAttributeKeyUtils.buildNextChannel(visitorRealChannel, channel);
|
||||||
|
|
||||||
// 或许此处还应该通知服务端 这个访客绑定的客户端真实通道打开
|
// 或许此处还应该通知服务端 这个访客绑定的客户端真实通道打开
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ public class ServerHandleUdpReportServicePermeateClientTransferTypeAdvanced exte
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
String clientId = new String(msg.getClientId());
|
String clientId = new String(msg.getClientId());
|
||||||
Integer visitorPort = Integer.valueOf(new String(msg.getVisitorPort()));
|
Integer visitorPort = Integer.valueOf(new String(msg.getVisitorPort()));
|
||||||
byte[] visitorId = msg.getVisitorId();
|
byte[] visitorId = msg.getVisitorId();
|
||||||
@ -48,7 +49,7 @@ public class ServerHandleUdpReportServicePermeateClientTransferTypeAdvanced exte
|
|||||||
// log.debug("访客ID:【{}】接收到客户端:[{}] 返回数据大小:[{}] 内网穿透返回的数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
|
// log.debug("访客ID:【{}】接收到客户端:[{}] 返回数据大小:[{}] 内网穿透返回的数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
|
||||||
// 将数据转发访客通道
|
// 将数据转发访客通道
|
||||||
Channel visitor = NettyRealIdContext.getReal(visitorId);
|
Channel visitor = NettyRealIdContext.getReal(visitorId);
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
if (nextChannel != null) {
|
if (nextChannel != null) {
|
||||||
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
|
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
|
||||||
buf.writeBytes(msg.getData());
|
buf.writeBytes(msg.getData());
|
||||||
@ -63,7 +64,7 @@ public class ServerHandleUdpReportServicePermeateClientTransferTypeAdvanced exte
|
|||||||
.clientId(clientId)
|
.clientId(clientId)
|
||||||
.flow(msg.getData().length)
|
.flow(msg.getData().length)
|
||||||
.build();
|
.build();
|
||||||
channelFlowAdapter.asyncHandler(channelHandlerContext, serverChannelFlow);
|
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
|
||||||
}
|
}
|
||||||
log.debug("访客ID:【{}】接收到客户端:[{}] 发送真实数据成功", new String(visitorId), clientId);
|
log.debug("访客ID:【{}】接收到客户端:[{}] 发送真实数据成功", new String(visitorId), clientId);
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,10 @@ public class ServerHandleUdpReportStagingClosedTypeAdvanced extends AbstractHand
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
||||||
|
Channel stagingClosedChannel = channelHandlerContext.channel();
|
||||||
String appKey = ChannelAttributeKeyUtils.getAppKey(channelHandlerContext);
|
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingClosedChannel);
|
||||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(channelHandlerContext);
|
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingClosedChannel);
|
||||||
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(channelHandlerContext);
|
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingClosedChannel);
|
||||||
|
|
||||||
byte[] clientIdBytes = msg.getClientId();
|
byte[] clientIdBytes = msg.getClientId();
|
||||||
// 获取所有通道
|
// 获取所有通道
|
||||||
|
@ -40,11 +40,12 @@ public class ServerHandleUdpReportStagingOpenedTypeAdvanced extends AbstractHand
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
protected void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg msg) {
|
||||||
|
Channel stagingOpenedChannel = channelHandlerContext.channel();
|
||||||
// 获取所有通道
|
// 获取所有通道
|
||||||
byte[] clientIdBytes = msg.getClientId();
|
byte[] clientIdBytes = msg.getClientId();
|
||||||
String appKey = ChannelAttributeKeyUtils.getAppKey(channelHandlerContext);
|
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel);
|
||||||
String appSecret = ChannelAttributeKeyUtils.getAppSecret(channelHandlerContext);
|
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingOpenedChannel);
|
||||||
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(channelHandlerContext);
|
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingOpenedChannel);
|
||||||
|
|
||||||
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes);
|
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes);
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ public class ServerHandleHttpReportClientProxyClientConnectTransferTypeAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 创建链接、发送数据
|
// 创建链接、发送数据
|
||||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||||
@ -42,13 +43,13 @@ public class ServerHandleHttpReportClientProxyClientConnectTransferTypeAdvanced
|
|||||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] clientId = nettyProxyMsg.getClientId();
|
byte[] clientId = nettyProxyMsg.getClientId();
|
||||||
String msgVisitorId = new String(visitorId);
|
String msgVisitorId = new String(visitorId);
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||||
|
|
||||||
NettyTransferChannelContext.pushVisitor(channelHandlerContext, msgVisitorId);
|
NettyTransferChannelContext.pushVisitor(channel, msgVisitorId);
|
||||||
NettyByteBuf nettyByteBuf = new NettyByteBuf();
|
NettyByteBuf nettyByteBuf = new NettyByteBuf();
|
||||||
nettyByteBuf.setData(data);
|
nettyByteBuf.setData(data);
|
||||||
ChannelAttributeKeyUtils.buildNettyByteBufData(channelHandlerContext, nettyByteBuf);
|
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
|
||||||
// 获取客户端心跳通道
|
// 获取客户端心跳通道
|
||||||
Channel loadBalance = ChannelContext.getLoadBalance(clientId);
|
Channel loadBalance = ChannelContext.getLoadBalance(clientId);
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ public class ServerHandleHttpReportClientProxyClientTransferChannelInitSuccessfu
|
|||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
|
|
||||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||||
@ -44,10 +45,10 @@ public class ServerHandleHttpReportClientProxyClientTransferChannelInitSuccessfu
|
|||||||
|
|
||||||
// next translation
|
// next translation
|
||||||
Channel nextTransferChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
|
Channel nextTransferChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
|
||||||
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channelHandlerContext);
|
ChannelAttributeKeyUtils.buildTransferNextChannel(nextTransferChannel, channel);
|
||||||
ChannelAttributeKeyUtils.buildTransferNextChannel(channelHandlerContext, nextTransferChannel);
|
ChannelAttributeKeyUtils.buildTransferNextChannel(channel, nextTransferChannel);
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||||
NettyByteBuf nettyByteBufData = ChannelAttributeKeyUtils.getNettyByteBufData(nextTransferChannel);
|
NettyByteBuf nettyByteBufData = ChannelAttributeKeyUtils.getNettyByteBufData(nextTransferChannel);
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,19 +33,20 @@ public class ServerHandleHttpReportClientProxyClientTransferCloseTypeAdvanced
|
|||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 关闭通道
|
// 关闭通道
|
||||||
|
|
||||||
// 关闭 next、next transfer 通道
|
// 关闭 next、next transfer 通道
|
||||||
|
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
|
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||||
|
|
||||||
// 下发关闭客户端真实通道
|
// 下发关闭客户端真实通道
|
||||||
NettyProxyMsg closeTransferNettyProxyMsg = new NettyProxyMsg();
|
NettyProxyMsg closeTransferNettyProxyMsg = new NettyProxyMsg();
|
||||||
closeTransferNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_);
|
closeTransferNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_CLIENT_PROXY_CLIENT_TRANSFER_CLOSE_);
|
||||||
transferNextChannel.writeAndFlush(closeTransferNettyProxyMsg);
|
transferNextChannel.writeAndFlush(closeTransferNettyProxyMsg);
|
||||||
|
|
||||||
channelHandlerContext.close();
|
channel.close();
|
||||||
nextChannel.close();
|
nextChannel.close();
|
||||||
transferNextChannel.close();
|
transferNextChannel.close();
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,9 @@ public class ServerHandleHttpReportClientProxyClientTransferResponseTypeAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 将返回数据下发客户端
|
// 将返回数据下发客户端
|
||||||
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channelHandlerContext);
|
Channel transferNextChannel = ChannelAttributeKeyUtils.getTransferNextChannel(channel);
|
||||||
|
|
||||||
if(ObjectUtils.isNotEmpty(transferNextChannel)) {
|
if(ObjectUtils.isNotEmpty(transferNextChannel)) {
|
||||||
log.info("目标客户端返回数据通过服务端下发到原始通道");
|
log.info("目标客户端返回数据通过服务端下发到原始通道");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.http.advanced;
|
package org.framework.lazy.cloud.network.heartbeat.server.netty.proxy.http.advanced;
|
||||||
|
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||||
@ -37,6 +38,7 @@ public class ServerHandleHttpReportClientProxyServerProxyTransferTypeAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 创建链接、发送数据
|
// 创建链接、发送数据
|
||||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||||
@ -56,7 +58,7 @@ public class ServerHandleHttpReportClientProxyServerProxyTransferTypeAdvanced
|
|||||||
nettyHttpClientProxyServerTransfer.setData(data);
|
nettyHttpClientProxyServerTransfer.setData(data);
|
||||||
|
|
||||||
NettyHttpClientProxyServerRealSocket
|
NettyHttpClientProxyServerRealSocket
|
||||||
.buildRealServer(nettyHttpClientProxyServerTransfer, channelHandlerContext,new String(visitorId));
|
.buildRealServer(nettyHttpClientProxyServerTransfer, channel,new String(visitorId));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,10 +31,11 @@ public class ServerHandleHttpReportClientProxyServerTransferCloseTypeAdvanced ex
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 关闭传输通信通道
|
// 关闭传输通信通道
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
nextChannel.close();
|
nextChannel.close();
|
||||||
channelHandlerContext.close();
|
channel.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ public class ServerHandleHttpReportServerProxyClientTransferChannelInitSuccessfu
|
|||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 数据下发
|
// 数据下发
|
||||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||||
|
|
||||||
@ -41,11 +42,11 @@ public class ServerHandleHttpReportServerProxyClientTransferChannelInitSuccessfu
|
|||||||
|
|
||||||
// next
|
// next
|
||||||
Channel nextChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
|
Channel nextChannel = NettyTransferChannelContext.getVisitor(msgVisitorId);
|
||||||
ChannelAttributeKeyUtils.buildNextChannel(nextChannel, channelHandlerContext);
|
ChannelAttributeKeyUtils.buildNextChannel(nextChannel, channel);
|
||||||
ChannelAttributeKeyUtils.buildNextChannel(channelHandlerContext, nextChannel);
|
ChannelAttributeKeyUtils.buildNextChannel(channel, nextChannel);
|
||||||
|
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||||
NettyByteBuf nettyByteBufData = ChannelAttributeKeyUtils.getNettyByteBufData(nextChannel);
|
NettyByteBuf nettyByteBufData = ChannelAttributeKeyUtils.getNettyByteBufData(nextChannel);
|
||||||
|
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ public class ServerHandleHttpReportServerProxyClientTransferChannelInitSuccessfu
|
|||||||
|
|
||||||
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_);
|
clientConnectTagetNettyProxyMsg.setType(ProxyMessageType.HTTP_DISTRIBUTE_SERVER_PROXY_CLIENT_TRANSFER_REQUEST_);
|
||||||
|
|
||||||
channelHandlerContext.writeAndFlush(clientConnectTagetNettyProxyMsg);
|
channel.writeAndFlush(clientConnectTagetNettyProxyMsg);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,11 @@ public class ServerHandleHttpReportServerProxyClientTransferCloseTypeAdvanced ex
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 关闭传输通信通道
|
// 关闭传输通信通道
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
nextChannel.close();
|
nextChannel.close();
|
||||||
channelHandlerContext.close();
|
channel.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,13 @@ public class ServerHandleHttpReportServerProxyClientTransferResponseTypeAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 将返回数据
|
// 将返回数据
|
||||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channelHandlerContext);
|
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||||
|
|
||||||
if(ObjectUtils.isNotEmpty(nextChannel)) {
|
if(ObjectUtils.isNotEmpty(nextChannel)) {
|
||||||
log.info("目标客户端返回数据通过服务端下发到原始通道");
|
log.info("目标客户端返回数据通过服务端下发到原始通道");
|
||||||
ByteBuf buf = channelHandlerContext.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||||
buf.writeBytes(nettyProxyMsg.getData());
|
buf.writeBytes(nettyProxyMsg.getData());
|
||||||
nextChannel.writeAndFlush(buf);
|
nextChannel.writeAndFlush(buf);
|
||||||
}else {
|
}else {
|
||||||
|
@ -32,6 +32,7 @@ public class ServerHandleHttpReportServerProxyClientTransferTypeAdvanced
|
|||||||
@Override
|
@Override
|
||||||
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
public void doHandler(ChannelHandlerContext channelHandlerContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
|
|
||||||
|
Channel channel = channelHandlerContext.channel();
|
||||||
// 创建链接、发送数据
|
// 创建链接、发送数据
|
||||||
String targetPortString = nettyProxyMsg.getTargetPortString();
|
String targetPortString = nettyProxyMsg.getTargetPortString();
|
||||||
String targetIpString = nettyProxyMsg.getTargetIpString();
|
String targetIpString = nettyProxyMsg.getTargetIpString();
|
||||||
@ -39,13 +40,13 @@ public class ServerHandleHttpReportServerProxyClientTransferTypeAdvanced
|
|||||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||||
byte[] clientId = nettyProxyMsg.getClientId();
|
byte[] clientId = nettyProxyMsg.getClientId();
|
||||||
String msgVisitorId = new String(visitorId);
|
String msgVisitorId = new String(visitorId);
|
||||||
ChannelAttributeKeyUtils.buildClientId(channelHandlerContext, clientId);
|
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||||
ChannelAttributeKeyUtils.buildVisitorId(channelHandlerContext, msgVisitorId);
|
ChannelAttributeKeyUtils.buildVisitorId(channel, msgVisitorId);
|
||||||
|
|
||||||
NettyTransferChannelContext.pushVisitor(channelHandlerContext, msgVisitorId);
|
NettyTransferChannelContext.pushVisitor(channel, msgVisitorId);
|
||||||
NettyByteBuf nettyByteBuf = new NettyByteBuf();
|
NettyByteBuf nettyByteBuf = new NettyByteBuf();
|
||||||
nettyByteBuf.setData(data);
|
nettyByteBuf.setData(data);
|
||||||
ChannelAttributeKeyUtils.buildNettyByteBufData(channelHandlerContext, nettyByteBuf);
|
ChannelAttributeKeyUtils.buildNettyByteBufData(channel, nettyByteBuf);
|
||||||
// 获取客户端心跳通道
|
// 获取客户端心跳通道
|
||||||
Channel loadBalance = ChannelContext.getLoadBalance(clientId);
|
Channel loadBalance = ChannelContext.getLoadBalance(clientId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user