diff --git a/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/config/ProxyConfig.java b/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/config/ProxyConfig.java index ebe8376d..9f81668f 100644 --- a/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/config/ProxyConfig.java +++ b/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/config/ProxyConfig.java @@ -40,5 +40,6 @@ public class ProxyConfig { private String licenseKey; private Integer threadCount; private String clientId; + private Boolean transferLogEnable; } } diff --git a/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/core/ProxyClientService.java b/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/core/ProxyClientService.java index a039983b..8953184e 100644 --- a/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/core/ProxyClientService.java +++ b/neutrino-proxy-client/src/main/java/org/dromara/neutrinoproxy/client/core/ProxyClientService.java @@ -1,6 +1,7 @@ package org.dromara.neutrinoproxy.client.core; import cn.hutool.core.util.StrUtil; +import io.netty.handler.logging.LoggingHandler; import org.dromara.neutrinoproxy.client.config.ProxyConfig; import org.dromara.neutrinoproxy.client.util.ProxyUtil; import org.dromara.neutrinoproxy.core.ProxyMessage; @@ -119,7 +120,9 @@ public class ProxyClientService { if (proxyConfig.getClient().getSslEnable()) { ch.pipeline().addLast(createSslHandler()); } -// ch.pipeline().addFirst(new LoggingHandler(ProxyClientService.class)); + if (null != proxyConfig.getClient().getTransferLogEnable() && proxyConfig.getClient().getTransferLogEnable()) { + ch.pipeline().addFirst(new LoggingHandler(ProxyClientService.class)); + } ch.pipeline().addLast(new ProxyMessageDecoder(proxyConfig.getProtocol().getMaxFrameLength(), proxyConfig.getProtocol().getLengthFieldOffset(), proxyConfig.getProtocol().getLengthFieldLength(), proxyConfig.getProtocol().getLengthAdjustment(), proxyConfig.getProtocol().getInitialBytesToStrip())); diff --git a/neutrino-proxy-client/src/main/resources/app.yml b/neutrino-proxy-client/src/main/resources/app.yml index 386790ee..4ebc28dd 100644 --- a/neutrino-proxy-client/src/main/resources/app.yml +++ b/neutrino-proxy-client/src/main/resources/app.yml @@ -22,3 +22,4 @@ neutrino: obtain-license-interval: 5 license-key: ${LICENSE_KEY:} client-id: ${CLIENT_ID:} + transfer-log-enable: ${CLIENT_LOG:false} diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfig.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfig.java index 0ec22f42..e3176b03 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfig.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfig.java @@ -49,6 +49,7 @@ public class ProxyConfig { private Integer httpsProxyPort; private String keyStorePassword; private String jksPath; + private Boolean transferLogEnable; } @Data @@ -60,6 +61,7 @@ public class ProxyConfig { private String keyStorePassword; private String keyManagerPassword; private String jksPath; + private Boolean transferLogEnable; } } diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfiguration.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfiguration.java index 7aa5a712..b7537641 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfiguration.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/base/proxy/ProxyConfiguration.java @@ -4,6 +4,7 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.logging.LoggingHandler; import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum; import org.dromara.neutrinoproxy.core.ProxyMessage; import org.dromara.neutrinoproxy.core.ProxyMessageHandler; @@ -12,6 +13,7 @@ import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.nio.NioEventLoopGroup; import org.dromara.neutrinoproxy.server.proxy.core.BytesMetricsHandler; +import org.dromara.neutrinoproxy.server.proxy.core.ProxyTunnelServer; import org.dromara.neutrinoproxy.server.proxy.core.TcpVisitorChannelHandler; import org.noear.solon.Solon; import org.noear.solon.annotation.Bean; @@ -51,13 +53,18 @@ public class ProxyConfiguration implements LifecycleBean { @Bean("tcpServerBootstrap") public ServerBootstrap tcpServerBootstrap(@Inject("serverBossGroup") NioEventLoopGroup serverBossGroup, - @Inject("serverWorkerGroup") NioEventLoopGroup serverWorkerGroup) { + @Inject("serverWorkerGroup") NioEventLoopGroup serverWorkerGroup, + @Inject ProxyConfig proxyConfig + ) { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(serverBossGroup, serverWorkerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { + if (null != proxyConfig.getServer().getTransferLogEnable() && proxyConfig.getServer().getTransferLogEnable()) { + ch.pipeline().addFirst(new LoggingHandler(ProxyTunnelServer.class)); + } ch.pipeline().addFirst(new BytesMetricsHandler()); ch.pipeline().addLast(new TcpVisitorChannelHandler()); } diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/ProxyTunnelServer.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/ProxyTunnelServer.java index bd7e8c35..bb510d1a 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/ProxyTunnelServer.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/ProxyTunnelServer.java @@ -1,5 +1,6 @@ package org.dromara.neutrinoproxy.server.proxy.core; +import io.netty.handler.logging.LoggingHandler; import org.dromara.neutrinoproxy.core.ProxyMessageDecoder; import org.dromara.neutrinoproxy.core.ProxyMessageEncoder; import org.dromara.neutrinoproxy.core.util.FileUtil; @@ -111,7 +112,9 @@ public class ProxyTunnelServer implements EventListener { } private void proxyServerCommonInitHandler(SocketChannel ch) { -// ch.pipeline().addFirst(new LoggingHandler(ProxyServerRunner.class)); + if (null != proxyConfig.getTunnel().getTransferLogEnable() && proxyConfig.getTunnel().getTransferLogEnable()) { + ch.pipeline().addFirst(new LoggingHandler(ProxyTunnelServer.class)); + } ch.pipeline().addLast(new ProxyMessageDecoder(proxyConfig.getProtocol().getMaxFrameLength(), proxyConfig.getProtocol().getLengthFieldOffset(), proxyConfig.getProtocol().getLengthFieldLength(), proxyConfig.getProtocol().getLengthAdjustment(), proxyConfig.getProtocol().getInitialBytesToStrip())); diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpProxy.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpProxy.java index bac549a6..fb00568b 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpProxy.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpProxy.java @@ -6,9 +6,11 @@ import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.logging.LoggingHandler; import lombok.extern.slf4j.Slf4j; import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig; import org.dromara.neutrinoproxy.server.proxy.core.BytesMetricsHandler; +import org.dromara.neutrinoproxy.server.proxy.core.ProxyTunnelServer; import org.noear.solon.annotation.Component; import org.noear.solon.annotation.Inject; import org.noear.solon.core.event.AppLoadEndEvent; @@ -40,6 +42,9 @@ public class HttpProxy implements EventListener { .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { + if (null != proxyConfig.getServer().getTransferLogEnable() && proxyConfig.getServer().getTransferLogEnable()) { + ch.pipeline().addFirst(new LoggingHandler(ProxyTunnelServer.class)); + } ch.pipeline().addFirst(new BytesMetricsHandler()); ch.pipeline().addLast(new HttpVisitorChannelHandler(proxyConfig.getServer().getDomainName())); } diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpsProxy.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpsProxy.java index c3d7dd14..57edda35 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpsProxy.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/enhance/HttpsProxy.java @@ -6,12 +6,14 @@ import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.logging.LoggingHandler; import io.netty.handler.ssl.SslHandler; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.dromara.neutrinoproxy.core.util.FileUtil; import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig; import org.dromara.neutrinoproxy.server.proxy.core.BytesMetricsHandler; +import org.dromara.neutrinoproxy.server.proxy.core.ProxyTunnelServer; import org.noear.solon.annotation.Component; import org.noear.solon.annotation.Inject; import org.noear.solon.core.event.AppLoadEndEvent; @@ -48,6 +50,9 @@ public class HttpsProxy implements EventListener { .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { + if (null != proxyConfig.getServer().getTransferLogEnable() && proxyConfig.getServer().getTransferLogEnable()) { + ch.pipeline().addFirst(new LoggingHandler(ProxyTunnelServer.class)); + } ch.pipeline().addLast(createSslHandler()); ch.pipeline().addFirst(new BytesMetricsHandler()); ch.pipeline().addLast(new HttpVisitorChannelHandler(proxyConfig.getServer().getDomainName())); diff --git a/neutrino-proxy-server/src/main/resources/app.yml b/neutrino-proxy-server/src/main/resources/app.yml index d144ea42..fc9fdd02 100644 --- a/neutrino-proxy-server/src/main/resources/app.yml +++ b/neutrino-proxy-server/src/main/resources/app.yml @@ -20,6 +20,7 @@ neutrino: key-store-password: ${STORE_PASS:123456} key-manager-password: ${MGR_PASS:123456} jks-path: ${JKS_PATH:classpath:/test.jks} + transfer-log-enable: ${TUNNEL_LOG:false} server: boss-thread-count: 5 work-thread-count: 20 @@ -29,6 +30,7 @@ neutrino: domain-name: ${DOMAIN_NAME:} key-store-password: ${HTTPS_STORE_PASS:} jks-path: ${HTTPS_JKS_PATH:} + transfer-log-enable: ${SERVER_LOG:false} data: db: type: ${DB_TYPE:sqlite}