更新配置文件为yml

master
liangqi 4 years ago
parent a5f4f1d0fc
commit 9e71918466
  1. 4
      pom.xml
  2. 2
      proxy-client/pom.xml
  3. 8
      proxy-client/src/main/java/org/fengfei/lanproxy/client/ClientChannelMannager.java
  4. 12
      proxy-client/src/main/java/org/fengfei/lanproxy/client/ProxyClientContainer.java
  5. 22
      proxy-client/src/main/java/org/fengfei/lanproxy/client/config/Client.java
  6. 71
      proxy-client/src/main/java/org/fengfei/lanproxy/client/config/ClientConfig.java
  7. 32
      proxy-client/src/main/java/org/fengfei/lanproxy/client/config/Server.java
  8. 42
      proxy-client/src/main/java/org/fengfei/lanproxy/client/config/Ssl.java
  9. 4
      proxy-client/src/main/resources/config.properties
  10. 9
      proxy-client/src/main/resources/config.yml
  11. 7
      proxy-common/pom.xml
  12. 2
      proxy-server/pom.xml
  13. 18
      proxy-server/src/main/resources/config.yml

@ -49,8 +49,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version> <version>3.1</version>
<configuration> <configuration>
<source>1.7</source> <source>1.8</source>
<target>1.7</target> <target>1.8</target>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>

@ -51,6 +51,7 @@
<version>2.4</version> <version>2.4</version>
<configuration> <configuration>
<excludes> <excludes>
<exclude>*.yml</exclude>
<exclude>*.properties</exclude> <exclude>*.properties</exclude>
<exclude>*.sh</exclude> <exclude>*.sh</exclude>
<exclude>*.bat</exclude> <exclude>*.bat</exclude>
@ -76,6 +77,7 @@
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>
<include>*.yml</include>
<include>*.properties</include> <include>*.properties</include>
<include>*.jks</include> <include>*.jks</include>
</includes> </includes>

@ -6,6 +6,8 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import org.fengfei.lanproxy.client.config.ClientConfig;
import org.fengfei.lanproxy.client.config.Server;
import org.fengfei.lanproxy.client.listener.ProxyChannelBorrowListener; import org.fengfei.lanproxy.client.listener.ProxyChannelBorrowListener;
import org.fengfei.lanproxy.common.Config; import org.fengfei.lanproxy.common.Config;
import org.fengfei.lanproxy.protocol.Constants; import org.fengfei.lanproxy.protocol.Constants;
@ -44,7 +46,8 @@ public class ClientChannelMannager {
private static volatile Channel cmdChannel; private static volatile Channel cmdChannel;
private static Config config = Config.getInstance(); // private static Config config = Config.getInstance();
private static ClientConfig clientConfig = ClientConfig.getInstance();
public static void borrowProxyChanel(Bootstrap bootstrap, final ProxyChannelBorrowListener borrowListener) { public static void borrowProxyChanel(Bootstrap bootstrap, final ProxyChannelBorrowListener borrowListener) {
Channel channel = proxyChannelPool.poll(); Channel channel = proxyChannelPool.poll();
@ -53,7 +56,8 @@ public class ClientChannelMannager {
return; return;
} }
bootstrap.connect(config.getStringValue("server.host"), config.getIntValue("server.port")).addListener(new ChannelFutureListener() { Server server = clientConfig.getServer();
bootstrap.connect(server.getHost(), server.getPort()).addListener(new ChannelFutureListener() {
@Override @Override
public void operationComplete(ChannelFuture future) throws Exception { public void operationComplete(ChannelFuture future) throws Exception {

@ -5,6 +5,9 @@ import java.util.Arrays;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import org.fengfei.lanproxy.client.config.Client;
import org.fengfei.lanproxy.client.config.ClientConfig;
import org.fengfei.lanproxy.client.config.Server;
import org.fengfei.lanproxy.client.handlers.ClientChannelHandler; import org.fengfei.lanproxy.client.handlers.ClientChannelHandler;
import org.fengfei.lanproxy.client.handlers.RealServerChannelHandler; import org.fengfei.lanproxy.client.handlers.RealServerChannelHandler;
import org.fengfei.lanproxy.client.listener.ChannelStatusListener; import org.fengfei.lanproxy.client.listener.ChannelStatusListener;
@ -51,7 +54,8 @@ public class ProxyClientContainer implements Container, ChannelStatusListener {
private Bootstrap realServerBootstrap; private Bootstrap realServerBootstrap;
private Config config = Config.getInstance(); // private Config config = Config.getInstance();
private ClientConfig clientConfig = ClientConfig.getInstance();
private SSLContext sslContext; private SSLContext sslContext;
@ -116,13 +120,15 @@ public class ProxyClientContainer implements Container, ChannelStatusListener {
* 连接代理服务器 * 连接代理服务器
*/ */
private void connectProxyServer() { private void connectProxyServer() {
bootstrap.connect(config.getStringValue("server.host"), config.getIntValue("server.port")).addListener((ChannelFuture future)->{ Server server = clientConfig.getServer();
Client client = clientConfig.getClient();
bootstrap.connect(server.getHost(), server.getPort()).addListener((ChannelFuture future)->{
if (future.isSuccess()){ if (future.isSuccess()){
// 连接成功,向服务器发送客户端认证信息(clientKey) // 连接成功,向服务器发送客户端认证信息(clientKey)
ClientChannelMannager.setCmdChannel(future.channel()); ClientChannelMannager.setCmdChannel(future.channel());
ProxyMessage proxyMessage = new ProxyMessage(); ProxyMessage proxyMessage = new ProxyMessage();
proxyMessage.setType(ProxyMessage.C_TYPE_AUTH); proxyMessage.setType(ProxyMessage.C_TYPE_AUTH);
proxyMessage.setUri(config.getStringValue("client.key")); proxyMessage.setUri(client.getKey());
future.channel().writeAndFlush(proxyMessage); future.channel().writeAndFlush(proxyMessage);
sleepTimeMill = 1000; sleepTimeMill = 1000;
LOGGER.info("connect proxy server success, {}", future.channel()); LOGGER.info("connect proxy server success, {}", future.channel());

@ -0,0 +1,22 @@
package org.fengfei.lanproxy.client.config;
/**
* @Description TODO
* @Author qi
**/
public class Client {
/**
*
*/
private String key;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}

@ -0,0 +1,71 @@
package org.fengfei.lanproxy.client.config;
import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;
/**
* @Description 客户端配置文件
* @Author qi
**/
public class ClientConfig {
/**
* 默认配置文件位置
*/
public static final String DEFAULT_YML_PATH = "/config.yml";
/**
* 客户端配置
*/
private Client client;
/**
* ssl配置
*/
private Ssl ssl;
/**
* 配置
*/
private Server server;
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public Ssl getSsl() {
return ssl;
}
public void setSsl(Ssl ssl) {
this.ssl = ssl;
}
public Server getServer() {
return server;
}
public void setServer(Server server) {
this.server = server;
}
public static ClientConfig getInstance(String ymlPath){
InputStream inputStream = null;
try {
inputStream = ClientConfig.class.getResourceAsStream(ymlPath);
} catch (Exception e) {
e.printStackTrace();
}
Yaml yaml = new Yaml();
ClientConfig clientConfig = yaml.loadAs(inputStream, ClientConfig.class);
return clientConfig;
}
public static ClientConfig getInstance(){
return getInstance(DEFAULT_YML_PATH);
}
}

@ -0,0 +1,32 @@
package org.fengfei.lanproxy.client.config;
/**
* @Description 服务器配置
* @Author qi
**/
public class Server {
/**
* 地址
*/
private String host;
/**
* 端口
*/
private int port;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
}

@ -0,0 +1,42 @@
package org.fengfei.lanproxy.client.config;
/**
* @Description https连接设置
* @Author qi
**/
public class Ssl {
/**
* 是否开启https
*/
private boolean enable;
/**
*
*/
private String jksPath;
private String keyStorePassword;
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public String getJksPath() {
return jksPath;
}
public void setJksPath(String jksPath) {
this.jksPath = jksPath;
}
public String getKeyStorePassword() {
return keyStorePassword;
}
public void setKeyStorePassword(String keyStorePassword) {
this.keyStorePassword = keyStorePassword;
}
}

@ -1,9 +1,9 @@
client.key=client client.key=client
ssl.enable=false ssl.enable=false
ssl.jksPath=test.jks ssl.jksPath=test.jks
ssl.keyStorePassword=123456 ssl.keyStorePassword=98c93fdc78f34e0c8619c32bcf65ff7a
server.host=127.0.0.1 server.host=106.12.122.216
#default ssl port is 4993 #default ssl port is 4993
server.port=4900 server.port=4900

@ -0,0 +1,9 @@
client:
key: client
ssl:
enable: false
jksPath: test.jks
keyStorePassword: 98c93fdc78f34e0c8619c32bcf65ff7a
server:
host: 106.12.122.216
port: 4900

@ -22,5 +22,12 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.62</version> <version>1.2.62</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.9.5</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -31,6 +31,7 @@
<version>2.4</version> <version>2.4</version>
<configuration> <configuration>
<excludes> <excludes>
<exclude>*.yml</exclude>
<exclude>*.properties</exclude> <exclude>*.properties</exclude>
<exclude>*.sh</exclude> <exclude>*.sh</exclude>
<exclude>*.bat</exclude> <exclude>*.bat</exclude>
@ -76,6 +77,7 @@
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>
<include>*.yml</include>
<include>*.properties</include> <include>*.properties</include>
<include>*.json</include> <include>*.json</include>
<include>*.jks</include> <include>*.jks</include>

@ -0,0 +1,18 @@
server:
bind: 0.0.0.0
port: 4900
ssl:
enable: true
bind: 0.0.0.0
port: 4993
jksPath: test.jks
keyStorePassword: 123456
keyManagerPassword: 123456
needsClientAuth: false
config:
server:
bind: 0.0.0.0
port: 8090
admin:
username: admin
password: admin
Loading…
Cancel
Save