From 7e3b699aaed77dc17751b2e962cd1d7fc72d2505 Mon Sep 17 00:00:00 2001 From: qi Date: Thu, 21 Nov 2019 10:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E9=83=A8=E5=88=86=E8=BF=87?= =?UTF-8?q?=E6=9C=9Fneety=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fengfei/lanproxy/client/ClientChannelMannager.java | 2 +- .../fengfei/lanproxy/client/ProxyClientContainer.java | 2 ++ .../lanproxy/client/handlers/ClientChannelHandler.java | 2 +- proxy-common/pom.xml | 6 ++++++ .../org/fengfei/lanproxy/common/container/Container.java | 6 ++++++ .../fengfei/lanproxy/server/ProxyServerContainer.java | 1 + .../org/fengfei/lanproxy/server/SslContextCreator.java | 1 + .../org/fengfei/lanproxy/server/config/ProxyConfig.java | 8 +++++--- .../org/fengfei/lanproxy/server/config/web/ApiRoute.java | 2 +- .../lanproxy/server/config/web/HttpRequestHandler.java | 2 +- .../org/fengfei/lanproxy/server/config/web/MimeType.java | 4 ++-- .../lanproxy/server/config/web/routes/RouteConfig.java | 9 +++++---- .../lanproxy/server/handlers/ServerChannelHandler.java | 6 +++--- .../lanproxy/server/handlers/UserChannelHandler.java | 6 +++--- 14 files changed, 38 insertions(+), 19 deletions(-) diff --git a/proxy-client/src/main/java/org/fengfei/lanproxy/client/ClientChannelMannager.java b/proxy-client/src/main/java/org/fengfei/lanproxy/client/ClientChannelMannager.java index 6860871..c6859d7 100644 --- a/proxy-client/src/main/java/org/fengfei/lanproxy/client/ClientChannelMannager.java +++ b/proxy-client/src/main/java/org/fengfei/lanproxy/client/ClientChannelMannager.java @@ -70,7 +70,7 @@ public class ClientChannelMannager { proxyChanel.close(); } else { proxyChanel.config().setOption(ChannelOption.AUTO_READ, true); - proxyChanel.attr(Constants.NEXT_CHANNEL).remove(); + proxyChanel.attr(Constants.NEXT_CHANNEL).set(null); proxyChannelPool.offer(proxyChanel); logger.debug("return ProxyChanel to the pool, channel is {}, pool size is {} ", proxyChanel, proxyChannelPool.size()); } diff --git a/proxy-client/src/main/java/org/fengfei/lanproxy/client/ProxyClientContainer.java b/proxy-client/src/main/java/org/fengfei/lanproxy/client/ProxyClientContainer.java index 9126336..733aa56 100644 --- a/proxy-client/src/main/java/org/fengfei/lanproxy/client/ProxyClientContainer.java +++ b/proxy-client/src/main/java/org/fengfei/lanproxy/client/ProxyClientContainer.java @@ -68,6 +68,8 @@ public class ProxyClientContainer implements Container, ChannelStatusListener { } }); + + bootstrap = new Bootstrap(); bootstrap.group(workerGroup); bootstrap.channel(NioSocketChannel.class); diff --git a/proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/ClientChannelHandler.java b/proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/ClientChannelHandler.java index 22aa24b..f56ed86 100644 --- a/proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/ClientChannelHandler.java +++ b/proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/ClientChannelHandler.java @@ -72,7 +72,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandlergson 2.7 + + + com.alibaba + fastjson + 1.2.62 + diff --git a/proxy-common/src/main/java/org/fengfei/lanproxy/common/container/Container.java b/proxy-common/src/main/java/org/fengfei/lanproxy/common/container/Container.java index 505970c..63b8eb3 100644 --- a/proxy-common/src/main/java/org/fengfei/lanproxy/common/container/Container.java +++ b/proxy-common/src/main/java/org/fengfei/lanproxy/common/container/Container.java @@ -2,7 +2,13 @@ package org.fengfei.lanproxy.common.container; public interface Container { + /** + * 启动容器 + */ void start(); + /** + * 停止容器 + */ void stop(); } diff --git a/proxy-server/src/main/java/org/fengfei/lanproxy/server/ProxyServerContainer.java b/proxy-server/src/main/java/org/fengfei/lanproxy/server/ProxyServerContainer.java index 6a9c8c5..6c5687e 100644 --- a/proxy-server/src/main/java/org/fengfei/lanproxy/server/ProxyServerContainer.java +++ b/proxy-server/src/main/java/org/fengfei/lanproxy/server/ProxyServerContainer.java @@ -92,6 +92,7 @@ public class ProxyServerContainer implements Container, ConfigChangedListener { } + @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming") private void initializeSSLTCPTransport(String host, int port, final SSLContext sslContext) { ServerBootstrap b = new ServerBootstrap(); b.group(serverBossGroup, serverWorkerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer() { diff --git a/proxy-server/src/main/java/org/fengfei/lanproxy/server/SslContextCreator.java b/proxy-server/src/main/java/org/fengfei/lanproxy/server/SslContextCreator.java index 644e826..b1d7c2b 100644 --- a/proxy-server/src/main/java/org/fengfei/lanproxy/server/SslContextCreator.java +++ b/proxy-server/src/main/java/org/fengfei/lanproxy/server/SslContextCreator.java @@ -22,6 +22,7 @@ import org.fengfei.lanproxy.common.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming") public class SslContextCreator { private static Logger logger = LoggerFactory.getLogger(SslContextCreator.class); diff --git a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/ProxyConfig.java b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/ProxyConfig.java index ef78fee..d8e619a 100644 --- a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/ProxyConfig.java +++ b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/ProxyConfig.java @@ -183,8 +183,8 @@ public class ProxyConfig implements Serializable { clients = new ArrayList(); } - Map> clientInetPortMapping = new HashMap>(); - Map inetPortLanInfoMapping = new HashMap(); + Map> clientInetPortMapping = new HashMap>(clients.size()); + Map inetPortLanInfoMapping = new HashMap(clients.size()); // 构造端口映射关系 for (Client client : clients) { @@ -406,7 +406,9 @@ public class ProxyConfig implements Serializable { * */ public static interface ConfigChangedListener { - + /** + * 配置更新回调 + */ void onChanged(); } } diff --git a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/ApiRoute.java b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/ApiRoute.java index 3364d43..4272e7b 100644 --- a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/ApiRoute.java +++ b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/ApiRoute.java @@ -71,7 +71,7 @@ public class ApiRoute { middleware.preRequest(request); } - URI uri = new URI(request.getUri()); + URI uri = new URI(request.uri()); RequestHandler handler = routes.get(uri.getPath()); ResponseInfo responseInfo = null; if (handler != null) { diff --git a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/HttpRequestHandler.java b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/HttpRequestHandler.java index 32295c8..ccfa628 100644 --- a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/HttpRequestHandler.java +++ b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/HttpRequestHandler.java @@ -104,7 +104,7 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler h = new HashMap(); static { @@ -211,7 +211,7 @@ public class MimeType { public static String parseSuffix(String url) { try { - Matcher matcher = pattern.matcher(url); + Matcher matcher = PATTERN.matcher(url); String[] spUrl = url.toString().split("/"); int len = spUrl.length; String endUrl = spUrl[len - 1]; diff --git a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/routes/RouteConfig.java b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/routes/RouteConfig.java index 9ffc8c3..c9c1021 100644 --- a/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/routes/RouteConfig.java +++ b/proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/routes/RouteConfig.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import io.netty.handler.codec.http.HttpHeaderNames; import org.fengfei.lanproxy.common.JsonUtil; import org.fengfei.lanproxy.server.ProxyChannelManager; import org.fengfei.lanproxy.server.config.ProxyConfig; @@ -50,7 +51,7 @@ public class RouteConfig { @Override public void preRequest(FullHttpRequest request) { - String cookieHeader = request.headers().get(HttpHeaders.Names.COOKIE); + String cookieHeader = request.headers().get(HttpHeaderNames.COOKIE); boolean authenticated = false; if (cookieHeader != null) { String[] cookies = cookieHeader.split(";"); @@ -64,7 +65,7 @@ public class RouteConfig { } } - String auth = request.headers().get(HttpHeaders.Names.AUTHORIZATION); + String auth = request.headers().get(HttpHeaderNames.AUTHORIZATION); if (!authenticated && auth != null) { String[] authArr = auth.split(" "); if (authArr.length == 2 && authArr[0].equals(ProxyConfig.getInstance().getConfigAdminUsername()) && authArr[1].equals(ProxyConfig.getInstance().getConfigAdminPassword())) { @@ -72,11 +73,11 @@ public class RouteConfig { } } - if (!LOGIN_URL.equals(request.getUri()) && !authenticated) { + if (!LOGIN_URL.equals(request.uri()) && !authenticated) { throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED); } - logger.info("handle request for api {}", request.getUri()); + logger.info("handle request for api {}", request.uri()); } }); diff --git a/proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/ServerChannelHandler.java b/proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/ServerChannelHandler.java index 59aff7b..ccb7d9e 100644 --- a/proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/ServerChannelHandler.java +++ b/proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/ServerChannelHandler.java @@ -83,9 +83,9 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler { ProxyChannelManager.removeUserChannelFromCmdChannel(cmdChannel, userId); Channel proxyChannel = userChannel.attr(Constants.NEXT_CHANNEL).get(); if (proxyChannel != null && proxyChannel.isActive()) { - proxyChannel.attr(Constants.NEXT_CHANNEL).remove(); - proxyChannel.attr(Constants.CLIENT_KEY).remove(); - proxyChannel.attr(Constants.USER_ID).remove(); + proxyChannel.attr(Constants.NEXT_CHANNEL).set(null); + proxyChannel.attr(Constants.CLIENT_KEY).set(null); + proxyChannel.attr(Constants.USER_ID).set(null); proxyChannel.config().setOption(ChannelOption.AUTO_READ, true); // 通知客户端,用户连接已经断开