|
|
@ -11,6 +11,7 @@ import io.netty.channel.ChannelFuture;
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
import io.netty.channel.ChannelInitializer;
|
|
|
|
import io.netty.channel.ChannelInitializer;
|
|
|
|
import io.netty.channel.ChannelPipeline;
|
|
|
|
import io.netty.channel.ChannelPipeline;
|
|
|
|
|
|
|
|
import io.netty.channel.ChannelPromise;
|
|
|
|
import io.netty.channel.EventLoopGroup;
|
|
|
|
import io.netty.channel.EventLoopGroup;
|
|
|
|
import io.netty.channel.SimpleChannelInboundHandler;
|
|
|
|
import io.netty.channel.SimpleChannelInboundHandler;
|
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
@ -34,6 +35,7 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ForwardClientSocketClientHandler.class);
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ForwardClientSocketClientHandler.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ChannelPromise handshakeFuture;
|
|
|
|
private final URI localServerURI;
|
|
|
|
private final URI localServerURI;
|
|
|
|
|
|
|
|
|
|
|
|
public ForwardClientSocketClientHandler(URI localServerURI) {
|
|
|
|
public ForwardClientSocketClientHandler(URI localServerURI) {
|
|
|
@ -83,8 +85,8 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Channel localChannel = b.connect(localServerURI.getHost(), localServerURI.getPort()).sync().channel();
|
|
|
|
Channel localChannel = b.connect(localServerURI.getHost(), localServerURI.getPort()).sync().channel();
|
|
|
|
localFrameHandler.handshakeFuture()
|
|
|
|
this.handshakeFuture = localFrameHandler.handshakeFuture();
|
|
|
|
.addListener(new GenericFutureListener<ChannelFuture>() {
|
|
|
|
handshakeFuture.addListener(new GenericFutureListener<ChannelFuture>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void operationComplete(ChannelFuture future) throws Exception {
|
|
|
|
public void operationComplete(ChannelFuture future) throws Exception {
|
|
|
|
ChannelPipeline pipeline = future.channel().pipeline();
|
|
|
|
ChannelPipeline pipeline = future.channel().pipeline();
|
|
|
@ -93,7 +95,7 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
localFrameHandler.handshakeFuture().sync();
|
|
|
|
handshakeFuture.sync();
|
|
|
|
ctx.pipeline().remove(ForwardClientSocketClientHandler.this);
|
|
|
|
ctx.pipeline().remove(ForwardClientSocketClientHandler.this);
|
|
|
|
ctx.pipeline().addLast(new RelayHandler(localChannel));
|
|
|
|
ctx.pipeline().addLast(new RelayHandler(localChannel));
|
|
|
|
logger.info("ForwardClientSocketClientHandler connect local arthas server success");
|
|
|
|
logger.info("ForwardClientSocketClientHandler connect local arthas server success");
|
|
|
@ -105,7 +107,10 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
|
|
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
|
|
|
cause.printStackTrace();
|
|
|
|
logger.error("ForwardClientSocketClient channel: {}" , ctx.channel(), cause);
|
|
|
|
|
|
|
|
if (!handshakeFuture.isDone()) {
|
|
|
|
|
|
|
|
handshakeFuture.setFailure(cause);
|
|
|
|
|
|
|
|
}
|
|
|
|
ctx.close();
|
|
|
|
ctx.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|