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
f88e0e2b7f
commit
6e79901be3
@ -9,12 +9,13 @@ import io.netty.handler.codec.socksx.v5.Socks5AddressType;
|
|||||||
import io.netty.handler.codec.socksx.v5.Socks5CommandRequestDecoder;
|
import io.netty.handler.codec.socksx.v5.Socks5CommandRequestDecoder;
|
||||||
import io.netty.handler.codec.socksx.v5.Socks5CommandStatus;
|
import io.netty.handler.codec.socksx.v5.Socks5CommandStatus;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
|
|
||||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
|
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
|
||||||
|
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
|
||||||
|
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettySocketChannelContext;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socket.AbstractHandleSocketLocalProxyTypeAdvanced;
|
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.socket.AbstractHandleSocketLocalProxyTypeAdvanced;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
|
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyClient2DestInboundHandler;
|
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyProxy2realInboundHandler;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettyDest2ClientInboundHandler;
|
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocketReal2ProxyInboundHandler;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
|
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.NettySocks5CommandRequestHandler;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -32,13 +33,14 @@ public class NettySocketProtocolHandleSocketLocalProxyTypeAdvanced
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {
|
||||||
Channel channel = nettyChannelContext.channel();
|
NettySocketChannelContext nettySocketChannelContext = (NettySocketChannelContext) nettyChannelContext;
|
||||||
ChannelHandlerContext channelHandlerContext = nettyChannelContext.channelHandlerContext();
|
Channel channel = nettySocketChannelContext.channel();
|
||||||
|
ChannelHandlerContext channelHandlerContext = nettySocketChannelContext.channelHandlerContext();
|
||||||
EventLoopGroup group = EventLoopGroupFactory.createClientWorkGroup();
|
EventLoopGroup group = EventLoopGroupFactory.createClientWorkGroup();
|
||||||
String host = nettyProxyMsg.getTargetIpString();
|
String host = nettyProxyMsg.getTargetIpString();
|
||||||
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
Integer port = Integer.parseInt(nettyProxyMsg.getTargetPortString());
|
||||||
Bootstrap b = new Bootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
Socks5AddressType socks5AddressType=Socks5AddressType.IPv4;
|
Socks5AddressType socks5AddressType = nettySocketChannelContext.getSocks5AddressType();
|
||||||
|
|
||||||
b.group(group)
|
b.group(group)
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
@ -46,7 +48,7 @@ public class NettySocketProtocolHandleSocketLocalProxyTypeAdvanced
|
|||||||
.handler(new ChannelInitializer<SocketChannel>() {
|
.handler(new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel ch) throws Exception {
|
protected void initChannel(SocketChannel ch) throws Exception {
|
||||||
ch.pipeline().addLast(new NettyDest2ClientInboundHandler(channelHandlerContext));
|
ch.pipeline().addLast(new NettySocketReal2ProxyInboundHandler(channelHandlerContext));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
log.info("准备连接目标服务器,ip={},port={}", host, port);
|
log.info("准备连接目标服务器,ip={},port={}", host, port);
|
||||||
@ -55,7 +57,7 @@ public class NettySocketProtocolHandleSocketLocalProxyTypeAdvanced
|
|||||||
if (future.isSuccess()) {
|
if (future.isSuccess()) {
|
||||||
log.info("目标服务器连接成功");
|
log.info("目标服务器连接成功");
|
||||||
//添加客户端转发请求到服务端的Handler
|
//添加客户端转发请求到服务端的Handler
|
||||||
channel.pipeline().addLast(new NettyClient2DestInboundHandler(future));
|
channel.pipeline().addLast(new NettyProxy2realInboundHandler(future));
|
||||||
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, socks5AddressType);
|
DefaultSocks5CommandResponse commandResponse = new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, socks5AddressType);
|
||||||
channel.writeAndFlush(commandResponse);
|
channel.writeAndFlush(commandResponse);
|
||||||
channel.pipeline().remove(NettySocks5CommandRequestHandler.class);
|
channel.pipeline().remove(NettySocks5CommandRequestHandler.class);
|
||||||
|
@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class NettyTcpProxySocketApplicationListener implements SocketApplicationListener {
|
public class NettySocketProxySocketApplicationListener implements SocketApplicationListener {
|
||||||
|
|
||||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
@ -21,7 +21,7 @@ public class NettyTcpProxySocketApplicationListener implements SocketApplication
|
|||||||
private ChannelFuture channelFuture;
|
private ChannelFuture channelFuture;
|
||||||
private final ProtocolProxyProperties protocolProxyProperties;
|
private final ProtocolProxyProperties protocolProxyProperties;
|
||||||
|
|
||||||
public NettyTcpProxySocketApplicationListener(NettyTcpProxyFilter nettyTcpProxyFilter, ProtocolProxyProperties protocolProxyProperties) {
|
public NettySocketProxySocketApplicationListener(NettyTcpProxyFilter nettyTcpProxyFilter, ProtocolProxyProperties protocolProxyProperties) {
|
||||||
this.nettyTcpProxyFilter = nettyTcpProxyFilter;
|
this.nettyTcpProxyFilter = nettyTcpProxyFilter;
|
||||||
this.protocolProxyProperties = protocolProxyProperties;
|
this.protocolProxyProperties = protocolProxyProperties;
|
||||||
}
|
}
|
||||||
@ -34,8 +34,8 @@ public class NettyTcpProxySocketApplicationListener implements SocketApplication
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doRunning() throws Exception {
|
public void doRunning() throws Exception {
|
||||||
ProtocolProxyProperties.TcpProtocolProxy tcpProtocolProxy = protocolProxyProperties.getTcpProtocolProxy();
|
ProtocolProxyProperties.SocketProtocolProxy socketProtocolProxy = protocolProxyProperties.getSocketProtocolProxy();
|
||||||
Integer tcpProtocolProxyPort = tcpProtocolProxy.getPort();
|
Integer socketProtocolProxyPort = socketProtocolProxy.getPort();
|
||||||
try {
|
try {
|
||||||
ServerBootstrap b = new ServerBootstrap();
|
ServerBootstrap b = new ServerBootstrap();
|
||||||
b.group(bossGroup, workerGroup)
|
b.group(bossGroup, workerGroup)
|
||||||
@ -53,19 +53,19 @@ public class NettyTcpProxySocketApplicationListener implements SocketApplication
|
|||||||
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||||
|
|
||||||
.childHandler(nettyTcpProxyFilter);
|
.childHandler(nettyTcpProxyFilter);
|
||||||
channelFuture = b.bind(tcpProtocolProxyPort).sync();
|
channelFuture = b.bind(socketProtocolProxyPort).sync();
|
||||||
|
|
||||||
channelFuture.addListener((ChannelFutureListener) channelFuture -> {
|
channelFuture.addListener((ChannelFutureListener) channelFuture -> {
|
||||||
// 服务器已启动
|
// 服务器已启动
|
||||||
log.info("TCP 协议代理 服务器启动成功 【{}】", tcpProtocolProxyPort);
|
log.info("Socket 协议代理 服务器启动成功 【{}】", socketProtocolProxyPort);
|
||||||
});
|
});
|
||||||
channelFuture.channel().closeFuture().sync();
|
channelFuture.channel().closeFuture().sync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("启动TCP 协议代理 失败,端口:{}", tcpProtocolProxyPort, e);
|
log.error("启动Socket 协议代理 失败,端口:{}", socketProtocolProxyPort, e);
|
||||||
} finally {
|
} finally {
|
||||||
destroy();
|
destroy();
|
||||||
// 服务器已关闭
|
// 服务器已关闭
|
||||||
log.warn("TCP 协议代理 服务关闭");
|
log.warn("Socket 协议代理 服务关闭");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,11 +11,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class NettyClient2DestInboundHandler extends ChannelInboundHandlerAdapter {
|
public class NettyProxy2realInboundHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
private final ChannelFuture dstChannelFuture;
|
private final ChannelFuture dstChannelFuture;
|
||||||
|
|
||||||
public NettyClient2DestInboundHandler(ChannelFuture dstChannelFuture) {
|
public NettyProxy2realInboundHandler(ChannelFuture dstChannelFuture) {
|
||||||
this.dstChannelFuture = dstChannelFuture;
|
this.dstChannelFuture = dstChannelFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public class NettyClient2DestInboundHandler extends ChannelInboundHandlerAdapter
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
log.error("NettyClient2DestInboundHandler exception", cause);
|
log.error("NettyProxy2realInboundHandler exception", cause);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,11 +9,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class NettyDest2ClientInboundHandler extends ChannelInboundHandlerAdapter {
|
public class NettySocketReal2ProxyInboundHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
private final ChannelHandlerContext clientChannelHandlerContext;
|
private final ChannelHandlerContext clientChannelHandlerContext;
|
||||||
|
|
||||||
public NettyDest2ClientInboundHandler(ChannelHandlerContext clientChannelHandlerContext) {
|
public NettySocketReal2ProxyInboundHandler(ChannelHandlerContext clientChannelHandlerContext) {
|
||||||
this.clientChannelHandlerContext = clientChannelHandlerContext;
|
this.clientChannelHandlerContext = clientChannelHandlerContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class NettyDest2ClientInboundHandler extends ChannelInboundHandlerAdapter
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
log.error("NettyDest2ClientInboundHandler exception", cause);
|
log.error("NettySocketReal2ProxyInboundHandler exception", cause);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.init;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.protocol.context.NettyHttpProxySocketApplicationListener;
|
import org.framework.lazy.cloud.network.heartbeat.protocol.context.NettyHttpProxySocketApplicationListener;
|
||||||
import org.framework.lazy.cloud.network.heartbeat.protocol.context.NettyTcpProxySocketApplicationListener;
|
import org.framework.lazy.cloud.network.heartbeat.protocol.context.NettySocketProxySocketApplicationListener;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({NettyHttpProxySocketApplicationListener.class,
|
@Import({NettyHttpProxySocketApplicationListener.class,
|
||||||
NettyTcpProxySocketApplicationListener.class})
|
NettySocketProxySocketApplicationListener.class})
|
||||||
public class InitProtocolProxySocket {
|
public class InitProtocolProxySocket {
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,11 +21,8 @@ public class ProtocolProxyProperties {
|
|||||||
/**
|
/**
|
||||||
* tcp协议代理
|
* tcp协议代理
|
||||||
*/
|
*/
|
||||||
private TcpProtocolProxy tcpProtocolProxy = new TcpProtocolProxy();
|
private SocketProtocolProxy socketProtocolProxy = new SocketProtocolProxy();
|
||||||
/**
|
|
||||||
* udp协议代理
|
|
||||||
*/
|
|
||||||
private UdpProtocolProxy udpProtocolProxy = new UdpProtocolProxy();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -35,12 +32,8 @@ public class ProtocolProxyProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class TcpProtocolProxy {
|
public static class SocketProtocolProxy {
|
||||||
private Integer port=9001;
|
private Integer port=9001;
|
||||||
}
|
}
|
||||||
@Data
|
|
||||||
public static class UdpProtocolProxy {
|
|
||||||
private Integer port=10001;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user