[server][xary] -修改bug
This commit is contained in:
24
.run/RunServerToRemote.run.xml
Normal file
24
.run/RunServerToRemote.run.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="RunServerToRemote" type="docker-deploy" factoryName="dockerfile"
|
||||||
|
server-name="UbuntuStation">
|
||||||
|
<deployment type="dockerfile">
|
||||||
|
<settings>
|
||||||
|
<option name="imageTag" value="remote-idea"/>
|
||||||
|
<option name="containerName" value="octopus-server-idea"/>
|
||||||
|
<option name="portBindings">
|
||||||
|
<list>
|
||||||
|
<DockerPortBindingImpl>
|
||||||
|
<option name="containerPort" value="9999"/>
|
||||||
|
<option name="hostPort" value="9999"/>
|
||||||
|
</DockerPortBindingImpl>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="sourceFilePath" value="server/Dockerfile-shanghai-remote-idea"/>
|
||||||
|
</settings>
|
||||||
|
</deployment>
|
||||||
|
<method v="2">
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="SkipTest-Package"
|
||||||
|
run_configuration_type="MavenRunConfiguration"/>
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
31
.run/SkipTest-Package.run.xml
Normal file
31
.run/SkipTest-Package.run.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="SkipTest-Package" type="MavenRunConfiguration" factoryName="Maven">
|
||||||
|
<MavenSettings>
|
||||||
|
<option name="myGeneralSettings"/>
|
||||||
|
<option name="myRunnerSettings"/>
|
||||||
|
<option name="myRunnerParameters">
|
||||||
|
<MavenRunnerParameters>
|
||||||
|
<option name="profiles">
|
||||||
|
<set/>
|
||||||
|
</option>
|
||||||
|
<option name="goals">
|
||||||
|
<list>
|
||||||
|
<option value="clean"/>
|
||||||
|
<option value="-DskipTests=true"/>
|
||||||
|
<option value="package"/>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="pomFileName"/>
|
||||||
|
<option name="profilesMap">
|
||||||
|
<map>
|
||||||
|
<entry key="pom.xml" value="true"/>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="resolveToWorkspace" value="false"/>
|
||||||
|
<option name="workingDirPath" value="$PROJECT_DIR$"/>
|
||||||
|
</MavenRunnerParameters>
|
||||||
|
</option>
|
||||||
|
</MavenSettings>
|
||||||
|
<method v="2"/>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
server/Dockerfile-shanghai-remote-idea
Normal file
23
server/Dockerfile-shanghai-remote-idea
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
# Base images that the image needs to depend on
|
||||||
|
FROM icederce/eclipse-temurin-11-jre-focal
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
|
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms2048m -Xmx2048m -Dfile.encoding=utf-8 -Dspring.profiles.active=k3s -Dspring.cloud.nacos.config.group=k3s -Dspring.cloud.nacos.config.extension-configs[0].dataId=common-k3s.yaml -Dspring.cloud.nacos.config.extension-configs[0].group=k3s -Ddebug=true -Dlogging.level.io.wdd.server=debug"
|
||||||
|
|
||||||
|
# Set time zone
|
||||||
|
RUN set -eux; \
|
||||||
|
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \
|
||||||
|
echo $TZ > /etc/timezone \
|
||||||
|
|
||||||
|
# Create Folder
|
||||||
|
RUN mkdir -p /wdd
|
||||||
|
|
||||||
|
# Define the work dir
|
||||||
|
WORKDIR /wdd
|
||||||
|
|
||||||
|
# Copy the jar and rename it
|
||||||
|
COPY ./target/server-*.jar /wdd/server.jar
|
||||||
|
|
||||||
|
# When the docker container starts, run the jar
|
||||||
|
ENTRYPOINT exec java ${JAVA_OPTS} -jar /wdd/server.jar
|
||||||
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
/**
|
/**
|
||||||
* 获取rerouces目录 https://blog.csdn.net/pengpengpeng85/article/details/84785575
|
* 获取rerouces目录 https://blog.csdn.net/pengpengpeng85/article/details/84785575
|
||||||
* <p>
|
* <p>
|
||||||
|
* <p>
|
||||||
* 写入文件的教程 https://cloud.tencent.com/developer/article/1895274
|
* 写入文件的教程 https://cloud.tencent.com/developer/article/1895274
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -45,32 +46,51 @@ public class XrayConfigPersistor {
|
|||||||
.withLinefeed("\n")
|
.withLinefeed("\n")
|
||||||
));
|
));
|
||||||
private static final String XrayResultPathPrefix = "xrayResult/";
|
private static final String XrayResultPathPrefix = "xrayResult/";
|
||||||
|
/**
|
||||||
|
* XRAY端口的起始位置
|
||||||
|
*/
|
||||||
|
public static final int XRAY_PORT_MAX = 20000;
|
||||||
/**
|
/**
|
||||||
* 存储生成的Xray Config的临时文件目录
|
* 存储生成的Xray Config的临时文件目录
|
||||||
*/
|
*/
|
||||||
private static File XrayResultPath;
|
private static final File XrayResultPath;
|
||||||
|
/**
|
||||||
|
* 一个乐观锁,用于标定一次生成过程是否需要进行旧文件的清除
|
||||||
|
*/
|
||||||
public static AtomicInteger cleanVersion = new AtomicInteger(0);
|
public static AtomicInteger cleanVersion = new AtomicInteger(0);
|
||||||
|
/**
|
||||||
|
* Xray的Port的池子, 一直递减
|
||||||
|
* 当进行重置的时候,需要进行清空
|
||||||
|
*/
|
||||||
|
public static AtomicInteger XRAY_PORT_POOL = new AtomicInteger(XRAY_PORT_MAX);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ClassPathResource resource = new ClassPathResource(XrayResultPathPrefix);
|
ClassPathResource resource = new ClassPathResource(XrayResultPathPrefix);
|
||||||
if (resource == null) {
|
|
||||||
// SpringBoot 打了Jar包的形式
|
try {
|
||||||
File file = new File("/octopus-server/xray");
|
if (resource
|
||||||
if (!file.exists()) {
|
.getURL()
|
||||||
file.mkdir();
|
.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;
|
} catch (IOException e) {
|
||||||
} else {
|
throw new RuntimeException(e);
|
||||||
// 本地开发的模式
|
|
||||||
try {
|
|
||||||
XrayResultPath = resource.getFile();
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("获取XrayConfig的临时文件目录失败!");
|
|
||||||
throw new MyRuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.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_MAP;
|
||||||
import static io.wdd.func.xray.persisit.cache.ProxyNodeCache.PROXY_NODE_TOPIC_NAME_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
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -98,7 +98,10 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
.stream()
|
.stream()
|
||||||
.forEach(
|
.forEach(
|
||||||
networkPathList -> {
|
networkPathList -> {
|
||||||
|
int chainPort = XRAY_PORT_POOL.decrementAndGet();
|
||||||
|
|
||||||
generateXrayJsonSinglePath(
|
generateXrayJsonSinglePath(
|
||||||
|
chainPort,
|
||||||
networkPathList,
|
networkPathList,
|
||||||
currentVersion
|
currentVersion
|
||||||
);
|
);
|
||||||
@@ -127,12 +130,16 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
@Override
|
@Override
|
||||||
public HashMap<String, ProxyNode> manualUpdateProxyNodeListCache() {
|
public HashMap<String, ProxyNode> manualUpdateProxyNodeListCache() {
|
||||||
|
|
||||||
|
// 重新手动获取所有的ProxyNode缓存信息
|
||||||
xrayDBOperator.CacheAllProxyNodeInfo();
|
xrayDBOperator.CacheAllProxyNodeInfo();
|
||||||
|
|
||||||
|
// 清空 XRAY_PORT_POOL
|
||||||
|
XRAY_PORT_POOL.set(XRAY_PORT_MAX);
|
||||||
|
|
||||||
return PROXY_NODE_TOPIC_NAME_MAP;
|
return PROXY_NODE_TOPIC_NAME_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateXrayJsonSinglePath(List<ProxyNode> networkPathList, int currentVersion) {
|
private void generateXrayJsonSinglePath(int chainPort, List<ProxyNode> networkPathList, int currentVersion) {
|
||||||
|
|
||||||
int pathLength = networkPathList.size();
|
int pathLength = networkPathList.size();
|
||||||
|
|
||||||
@@ -153,10 +160,6 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
.email(tag + "@octopus.io")
|
.email(tag + "@octopus.io")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
int port = 19999;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int pos = 0; pos < pathLength; pos++) {
|
for (int pos = 0; pos < pathLength; pos++) {
|
||||||
|
|
||||||
ProxyNode proxyNode = networkPathList.get(pos);
|
ProxyNode proxyNode = networkPathList.get(pos);
|
||||||
@@ -165,7 +168,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
XrayConfig xrayConfig = doBuildXrayConfig(
|
XrayConfig xrayConfig = doBuildXrayConfig(
|
||||||
tag,
|
tag,
|
||||||
clientObject,
|
clientObject,
|
||||||
port,
|
chainPort,
|
||||||
networkPathList,
|
networkPathList,
|
||||||
pos
|
pos
|
||||||
);
|
);
|
||||||
@@ -182,7 +185,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private XrayConfig doBuildXrayConfig(String tag, ClientObject clientObject, int port, List<ProxyNode> networkPathList, int pos) {
|
private XrayConfig doBuildXrayConfig(String tag, ClientObject clientObject, int chainPort, List<ProxyNode> networkPathList, int pos) {
|
||||||
|
|
||||||
// 需要从现有的XrayConfig基础上进行生成
|
// 需要从现有的XrayConfig基础上进行生成
|
||||||
// 尝试从 缓存层获取
|
// 尝试从 缓存层获取
|
||||||
@@ -201,7 +204,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
buildInbound(
|
buildInbound(
|
||||||
xrayConfig,
|
xrayConfig,
|
||||||
clientObject,
|
clientObject,
|
||||||
port,
|
chainPort,
|
||||||
tag
|
tag
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -213,7 +216,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
pos,
|
pos,
|
||||||
clientObject,
|
clientObject,
|
||||||
tag,
|
tag,
|
||||||
port
|
chainPort
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置 路由信息
|
// 设置 路由信息
|
||||||
@@ -262,7 +265,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
ruleObjectList.add(ruleObject);
|
ruleObjectList.add(ruleObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildOutbound(XrayConfig xrayConfig, List<ProxyNode> networkPathList, int pos, ClientObject clientObject, String tag, Integer port) {
|
private void buildOutbound(XrayConfig xrayConfig, List<ProxyNode> networkPathList, int pos, ClientObject clientObject, String tag, Integer chainPort) {
|
||||||
|
|
||||||
// 从缓存中获取
|
// 从缓存中获取
|
||||||
List<OutboundObject> outboundObjectList = xrayConfig.getOutbounds();
|
List<OutboundObject> outboundObjectList = xrayConfig.getOutbounds();
|
||||||
@@ -313,7 +316,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
.getPublicIPv4());
|
.getPublicIPv4());
|
||||||
|
|
||||||
// 端口
|
// 端口
|
||||||
serverObject.setPort(port);
|
serverObject.setPort(chainPort);
|
||||||
|
|
||||||
serverObject.setUsers(
|
serverObject.setUsers(
|
||||||
List.of(clientObject)
|
List.of(clientObject)
|
||||||
@@ -322,7 +325,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
outboundObjectList.add(vmessOutbound);
|
outboundObjectList.add(vmessOutbound);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildInbound(XrayConfig xrayConfig, ClientObject clientObject, Integer port, String tag) {
|
private void buildInbound(XrayConfig xrayConfig, ClientObject clientObject, Integer chainPort, String tag) {
|
||||||
|
|
||||||
// 从缓存中获取
|
// 从缓存中获取
|
||||||
List<InboundObject> inboundObjectList = xrayConfig.getInbounds();
|
List<InboundObject> inboundObjectList = xrayConfig.getInbounds();
|
||||||
@@ -345,7 +348,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
inboundObject.setTag(tag);
|
inboundObject.setTag(tag);
|
||||||
|
|
||||||
// todo port怎么办
|
// todo port怎么办
|
||||||
inboundObject.setPort(port);
|
inboundObject.setPort(chainPort);
|
||||||
// 设置 listen地址
|
// 设置 listen地址
|
||||||
inboundObject.setListen(ListenAddress);
|
inboundObject.setListen(ListenAddress);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user