diff --git a/.run/RunServerToRemote.run.xml b/.run/RunServerToRemote.run.xml
new file mode 100644
index 0000000..62af215
--- /dev/null
+++ b/.run/RunServerToRemote.run.xml
@@ -0,0 +1,24 @@
+
+
+
+ *
* 写入文件的教程 https://cloud.tencent.com/developer/article/1895274
*/
@Slf4j
@@ -45,32 +46,51 @@ public class XrayConfigPersistor {
.withLinefeed("\n")
));
private static final String XrayResultPathPrefix = "xrayResult/";
-
+ /**
+ * XRAY端口的起始位置
+ */
+ public static final int XRAY_PORT_MAX = 20000;
/**
* 存储生成的Xray Config的临时文件目录
*/
- private static File XrayResultPath;
+ private static final File XrayResultPath;
+ /**
+ * 一个乐观锁,用于标定一次生成过程是否需要进行旧文件的清除
+ */
public static AtomicInteger cleanVersion = new AtomicInteger(0);
+ /**
+ * Xray的Port的池子, 一直递减
+ * 当进行重置的时候,需要进行清空
+ */
+ public static AtomicInteger XRAY_PORT_POOL = new AtomicInteger(XRAY_PORT_MAX);
static {
ClassPathResource resource = new ClassPathResource(XrayResultPathPrefix);
- if (resource == null) {
- // SpringBoot 打了Jar包的形式
- File file = new File("/octopus-server/xray");
- if (!file.exists()) {
- file.mkdir();
+
+ try {
+ if (resource
+ .getURL()
+ .getPath()
+ .startsWith("file:/wdd/server")) {
+ // SpringBoot 打了Jar包的形式
+ File file = new File("/octopus-server/xray");
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+
+ XrayResultPath = file;
+ } else {
+ // 本地开发的模式
+ try {
+ XrayResultPath = resource.getFile();
+ } catch (IOException e) {
+ log.error("获取XrayConfig的临时文件目录失败!");
+ throw new MyRuntimeException(e);
+ }
}
- XrayResultPath = file;
- } else {
- // 本地开发的模式
- try {
- XrayResultPath = resource.getFile();
-
- } catch (IOException e) {
- log.error("获取XrayConfig的临时文件目录失败!");
- throw new MyRuntimeException(e);
- }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
}
diff --git a/server/src/main/java/io/wdd/func/xray/service/XrayCoreServiceImpl.java b/server/src/main/java/io/wdd/func/xray/service/XrayCoreServiceImpl.java
index 3e58be0..6d29651 100644
--- a/server/src/main/java/io/wdd/func/xray/service/XrayCoreServiceImpl.java
+++ b/server/src/main/java/io/wdd/func/xray/service/XrayCoreServiceImpl.java
@@ -30,7 +30,7 @@ import static io.wdd.func.xray.beans.config.LogTemplateClass.LogTemplate;
import static io.wdd.func.xray.beans.config.OutboundVmessHTTPTemplateClass.*;
import static io.wdd.func.xray.persisit.cache.ProxyNodeCache.PROXY_NODE_MAP;
import static io.wdd.func.xray.persisit.cache.ProxyNodeCache.PROXY_NODE_TOPIC_NAME_MAP;
-import static io.wdd.func.xray.service.XrayConfigPersistor.cleanVersion;
+import static io.wdd.func.xray.service.XrayConfigPersistor.*;
@Service
@Slf4j
@@ -98,7 +98,10 @@ public class XrayCoreServiceImpl implements XrayCoreService {
.stream()
.forEach(
networkPathList -> {
+ int chainPort = XRAY_PORT_POOL.decrementAndGet();
+
generateXrayJsonSinglePath(
+ chainPort,
networkPathList,
currentVersion
);
@@ -127,12 +130,16 @@ public class XrayCoreServiceImpl implements XrayCoreService {
@Override
public HashMap