|
|
|
@ -7,7 +7,6 @@ import java.util.List; |
|
|
|
|
import javax.net.ssl.SSLContext; |
|
|
|
|
import javax.net.ssl.SSLEngine; |
|
|
|
|
|
|
|
|
|
import org.fengfei.lanproxy.common.Config; |
|
|
|
|
import org.fengfei.lanproxy.common.container.Container; |
|
|
|
|
import org.fengfei.lanproxy.common.container.ContainerHelper; |
|
|
|
|
import org.fengfei.lanproxy.protocol.IdleCheckHandler; |
|
|
|
@ -16,6 +15,7 @@ import org.fengfei.lanproxy.protocol.ProxyMessageEncoder; |
|
|
|
|
import org.fengfei.lanproxy.server.config.ProxyConfig; |
|
|
|
|
import org.fengfei.lanproxy.server.config.ProxyConfig.ConfigChangedListener; |
|
|
|
|
import org.fengfei.lanproxy.server.config.web.WebConfigContainer; |
|
|
|
|
import org.fengfei.lanproxy.server.config.yml.ServerConfig; |
|
|
|
|
import org.fengfei.lanproxy.server.handlers.ServerChannelHandler; |
|
|
|
|
import org.fengfei.lanproxy.server.handlers.UserChannelHandler; |
|
|
|
|
import org.fengfei.lanproxy.server.metrics.handler.BytesMetricsHandler; |
|
|
|
@ -53,6 +53,8 @@ public class ProxyServerContainer implements Container, ConfigChangedListener { |
|
|
|
|
|
|
|
|
|
private NioEventLoopGroup serverBossGroup; |
|
|
|
|
|
|
|
|
|
private ServerConfig serverConfig = ServerConfig.getInstance(); |
|
|
|
|
|
|
|
|
|
public ProxyServerContainer() { |
|
|
|
|
|
|
|
|
|
serverBossGroup = new NioEventLoopGroup(); |
|
|
|
@ -82,9 +84,11 @@ public class ProxyServerContainer implements Container, ConfigChangedListener { |
|
|
|
|
throw new RuntimeException(ex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Config.getInstance().getBooleanValue("server.ssl.enable", false)) { |
|
|
|
|
String host = Config.getInstance().getStringValue("server.ssl.bind", "0.0.0.0"); |
|
|
|
|
int port = Config.getInstance().getIntValue("server.ssl.port"); |
|
|
|
|
if (serverConfig.getServer().getSsl().isEnable()) { |
|
|
|
|
|
|
|
|
|
String host = serverConfig.getServer().getSsl().getBind(); |
|
|
|
|
|
|
|
|
|
int port = serverConfig.getServer().getPort(); |
|
|
|
|
initializeSSLTCPTransport(host, port, new SslContextCreator().initSSLContext()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -101,7 +105,8 @@ public class ProxyServerContainer implements Container, ConfigChangedListener { |
|
|
|
|
public void initChannel(SocketChannel ch) throws Exception { |
|
|
|
|
ChannelPipeline pipeline = ch.pipeline(); |
|
|
|
|
try { |
|
|
|
|
pipeline.addLast("ssl", createSslHandler(sslContext, Config.getInstance().getBooleanValue("server.ssl.needsClientAuth", false))); |
|
|
|
|
|
|
|
|
|
pipeline.addLast("ssl", createSslHandler(sslContext, serverConfig.getServer().getSsl().isNeedsClientAuth())); |
|
|
|
|
ch.pipeline().addLast(new ProxyMessageDecoder(MAX_FRAME_LENGTH, LENGTH_FIELD_OFFSET, LENGTH_FIELD_LENGTH, LENGTH_ADJUSTMENT, INITIAL_BYTES_TO_STRIP)); |
|
|
|
|
ch.pipeline().addLast(new ProxyMessageEncoder()); |
|
|
|
|
ch.pipeline().addLast(new IdleCheckHandler(IdleCheckHandler.READ_IDLE_TIME, IdleCheckHandler.WRITE_IDLE_TIME, 0)); |
|
|
|
|