[server][ xray]- 新增功能代码
This commit is contained in:
@@ -1,17 +1,20 @@
|
|||||||
package io.wdd.func.controller;
|
package io.wdd.func.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import io.wdd.common.beans.response.R;
|
||||||
import io.wdd.func.xray.beans.node.ProxyNode;
|
import io.wdd.func.xray.beans.node.ProxyNode;
|
||||||
|
import io.wdd.func.xray.beans.node.XrayConfigInfo;
|
||||||
import io.wdd.func.xray.service.XrayConfigDistribute;
|
import io.wdd.func.xray.service.XrayConfigDistribute;
|
||||||
import io.wdd.func.xray.service.XrayCoreService;
|
import io.wdd.func.xray.service.XrayCoreService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static io.wdd.func.xray.beans.node.ProxyNodeSet.*;
|
import static io.wdd.func.xray.beans.node.ProxyNodeSet.*;
|
||||||
|
|
||||||
@@ -26,10 +29,39 @@ public class XrayController {
|
|||||||
@Resource
|
@Resource
|
||||||
XrayConfigDistribute xrayConfigDistribute;
|
XrayConfigDistribute xrayConfigDistribute;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/chain/transform")
|
||||||
|
@ApiOperation("[解析] - 解析代理链字符串")
|
||||||
|
public R<List<List<ProxyNode>>> transformProxyChainString(
|
||||||
|
@ApiParam(name = "proxyChainList", value = "代理链字符串,seoul2->tokyo2, 多条链使用,分隔")
|
||||||
|
@RequestParam("proxyChainList") List<String> proxyChainList
|
||||||
|
) {
|
||||||
|
|
||||||
|
return R.ok(
|
||||||
|
xrayCoreService.transformProxyChainString(proxyChainList)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/chain/debug")
|
||||||
|
@ApiOperation("[解析] - 代理链完整配置")
|
||||||
|
public R<List<XrayConfigInfo>> debugProxyChainString(
|
||||||
|
@ApiParam(name = "proxyChainList", value = "代理链字符串,seoul2->tokyo2, 多条链使用,分隔")
|
||||||
|
@RequestParam("proxyChainList") List<String> proxyChainList
|
||||||
|
) {
|
||||||
|
|
||||||
|
return R.ok(
|
||||||
|
xrayCoreService.generateXrayConfigFromNodeList(
|
||||||
|
xrayCoreService.transformProxyChainString(proxyChainList)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/test")
|
@GetMapping("/test")
|
||||||
public void test() {
|
public void test() {
|
||||||
|
|
||||||
ArrayList<ArrayList<ProxyNode>> allNetworkPathList = new ArrayList<>();
|
List<List<ProxyNode>> allNetworkPathList = new ArrayList<>();
|
||||||
|
|
||||||
ArrayList<ProxyNode> pathA = new ArrayList<>(
|
ArrayList<ProxyNode> pathA = new ArrayList<>(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
@@ -73,7 +105,7 @@ public class XrayController {
|
|||||||
// allNetworkPathList.add(pathB);
|
// allNetworkPathList.add(pathB);
|
||||||
// allNetworkPathList.add(pathC);
|
// allNetworkPathList.add(pathC);
|
||||||
|
|
||||||
xrayCoreService.generateXrayJsonFromNodeList(allNetworkPathList);
|
xrayCoreService.generateXrayConfigFromNodeList(allNetworkPathList);
|
||||||
|
|
||||||
xrayConfigDistribute.uploadXrayConfigToOSS(allNetworkPathList.get(0));
|
xrayConfigDistribute.uploadXrayConfigToOSS(allNetworkPathList.get(0));
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.wdd.func.xray.beans.node;
|
|||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import io.wdd.func.oss.config.OctopusObjectSummary;
|
import io.wdd.func.oss.config.OctopusObjectSummary;
|
||||||
|
import io.wdd.func.xray.beans.xray.XrayConfig;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -26,6 +27,8 @@ public class XrayConfigInfo {
|
|||||||
@ApiModelProperty("保存生成的XrayConfig文件,全路径")
|
@ApiModelProperty("保存生成的XrayConfig文件,全路径")
|
||||||
File xrayConfigFile;
|
File xrayConfigFile;
|
||||||
|
|
||||||
|
@ApiModelProperty("生成的实际的xray的配置内容")
|
||||||
|
XrayConfig xrayConfig;
|
||||||
|
|
||||||
@ApiModelProperty("xray config file的对象存储的相关信息")
|
@ApiModelProperty("xray config file的对象存储的相关信息")
|
||||||
OctopusObjectSummary objectSummary;
|
OctopusObjectSummary objectSummary;
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ public class XrayConfigDistribute {
|
|||||||
"grep",
|
"grep",
|
||||||
"-c",
|
"-c",
|
||||||
"active (running)"
|
"active (running)"
|
||||||
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -114,7 +113,7 @@ public class XrayConfigDistribute {
|
|||||||
@Resource
|
@Resource
|
||||||
AsyncExecutionService executionService;
|
AsyncExecutionService executionService;
|
||||||
|
|
||||||
public void uploadXrayConfigToOSS(ArrayList<ProxyNode> networkPathList) {
|
public void uploadXrayConfigToOSS(List<ProxyNode> networkPathList) {
|
||||||
|
|
||||||
// 所有的文件全部存储至一个对象存储的后端中
|
// 所有的文件全部存储至一个对象存储的后端中
|
||||||
OssConfig ossConfig = ossBackendSelect.oneRandom();
|
OssConfig ossConfig = ossBackendSelect.oneRandom();
|
||||||
@@ -143,7 +142,7 @@ public class XrayConfigDistribute {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildXrayUpdateResult(ArrayList<ProxyNode> networkPathList) {
|
public void buildXrayUpdateResult(List<ProxyNode> networkPathList) {
|
||||||
|
|
||||||
String formatTimeString = TimeUtils.currentFormatTimeString();
|
String formatTimeString = TimeUtils.currentFormatTimeString();
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public class XrayConfigPersistor {
|
|||||||
XrayConfigInfo xrayConfigInfo = new XrayConfigInfo();
|
XrayConfigInfo xrayConfigInfo = new XrayConfigInfo();
|
||||||
xrayConfigInfo.setXrayConfigFile(xrayConfigFile);
|
xrayConfigInfo.setXrayConfigFile(xrayConfigFile);
|
||||||
xrayConfigInfo.setXrayConfigFileName(fileName);
|
xrayConfigInfo.setXrayConfigFileName(fileName);
|
||||||
|
xrayConfigInfo.setXrayConfig(xrayConfig);
|
||||||
|
|
||||||
return xrayConfigInfo;
|
return xrayConfigInfo;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
package io.wdd.func.xray.service;
|
package io.wdd.func.xray.service;
|
||||||
|
|
||||||
import io.wdd.func.xray.beans.node.ProxyNode;
|
import io.wdd.func.xray.beans.node.ProxyNode;
|
||||||
|
import io.wdd.func.xray.beans.node.XrayConfigInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
public interface XrayCoreService {
|
public interface XrayCoreService {
|
||||||
|
|
||||||
void generateXrayJsonFromNodeList(ArrayList<ArrayList<ProxyNode>> allNetworkPathList);
|
/**
|
||||||
|
* 解析代理链字符串,返回完整的代理列表
|
||||||
|
*
|
||||||
|
* @param proxyChainList 代理链字符串
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<List<ProxyNode>> transformProxyChainString(List<String> proxyChainList);
|
||||||
|
|
||||||
|
|
||||||
|
List<XrayConfigInfo> generateXrayConfigFromNodeList(List<List<ProxyNode>> allNetworkPathList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static io.wdd.func.xray.beans.config.InboundVmessHTTPTemplateClass.InboundVmessHTTPTemplate;
|
import static io.wdd.func.xray.beans.config.InboundVmessHTTPTemplateClass.InboundVmessHTTPTemplate;
|
||||||
import static io.wdd.func.xray.beans.config.InboundVmessHTTPTemplateClass.ListenAddress;
|
import static io.wdd.func.xray.beans.config.InboundVmessHTTPTemplateClass.ListenAddress;
|
||||||
@@ -34,15 +33,37 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
@Resource
|
@Resource
|
||||||
XrayConfigPersistor xrayConfigPersistor;
|
XrayConfigPersistor xrayConfigPersistor;
|
||||||
|
|
||||||
|
private static final String ProxyChainSplitor = "->";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateXrayJsonFromNodeList(ArrayList<ArrayList<ProxyNode>> allNetworkPathList) {
|
public List<List<ProxyNode>> transformProxyChainString(List<String> proxyChainList) {
|
||||||
|
|
||||||
|
|
||||||
|
proxyChainList
|
||||||
|
.stream()
|
||||||
|
.map(
|
||||||
|
proxyChain -> Arrays
|
||||||
|
.stream(proxyChain.split(ProxyChainSplitor))
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<XrayConfigInfo> generateXrayConfigFromNodeList(List<List<ProxyNode>> allNetworkPathList) {
|
||||||
|
|
||||||
// 需要根据所有的交叉链路进行计算
|
// 需要根据所有的交叉链路进行计算
|
||||||
// A -> B -> C -> D
|
// A -> B -> C -> D
|
||||||
// B -> D
|
// B -> D
|
||||||
// A -> B -> F
|
// A -> B -> F
|
||||||
// B点需要具有 4对inbound和outbound对
|
// A点需要具有 2对inbound和outbound对
|
||||||
|
// B点需要具有 3对inbound和outbound对
|
||||||
// C点需要具有 2对inbound和outbound对
|
// C点需要具有 2对inbound和outbound对
|
||||||
|
// D点需要具有 2对inbound和outbound对
|
||||||
|
// F点需要具有 1对inbound和outbound对
|
||||||
|
|
||||||
|
|
||||||
// 解析所有的Node对
|
// 解析所有的Node对
|
||||||
@@ -66,10 +87,24 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 拿到所有的proxyNode
|
||||||
|
Set<ProxyNode> proxyNodeSet = allNetworkPathList
|
||||||
|
.stream()
|
||||||
|
.flatMap(
|
||||||
|
networkPathList -> networkPathList.stream()
|
||||||
|
)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
// 返回所有的配置
|
||||||
|
return proxyNodeSet
|
||||||
|
.stream()
|
||||||
|
.map(
|
||||||
|
ProxyNode::getXrayConfigInfo
|
||||||
|
)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateXrayJsonSinglePath(ArrayList<ProxyNode> networkPathList) {
|
private void generateXrayJsonSinglePath(List<ProxyNode> networkPathList) {
|
||||||
int pathLength = networkPathList.size();
|
int pathLength = networkPathList.size();
|
||||||
|
|
||||||
// 采用 VMESS + websocket的形式形成 链状代理
|
// 采用 VMESS + websocket的形式形成 链状代理
|
||||||
@@ -125,9 +160,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private XrayConfig doBuildXrayConfig(boolean isOutBoundFree, String tag, ClientObject clientObject, int port, List<ProxyNode> networkPathList, int pos) {
|
||||||
|
|
||||||
private XrayConfig doBuildXrayConfig(boolean isOutBoundFree, String tag, ClientObject clientObject, int port, ArrayList<ProxyNode> networkPathList, int pos) {
|
|
||||||
|
|
||||||
XrayConfig xrayConfig = new XrayConfig();
|
XrayConfig xrayConfig = new XrayConfig();
|
||||||
|
|
||||||
@@ -204,7 +237,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
xrayConfig.setRouting(routingObject);
|
xrayConfig.setRouting(routingObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildOutbound(XrayConfig xrayConfig, ArrayList<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 port) {
|
||||||
io.wdd.func.xray.beans.xray.protocol.outbound.VMESS vmessOutbound = new io.wdd.func.xray.beans.xray.protocol.outbound.VMESS();
|
io.wdd.func.xray.beans.xray.protocol.outbound.VMESS vmessOutbound = new io.wdd.func.xray.beans.xray.protocol.outbound.VMESS();
|
||||||
try {
|
try {
|
||||||
BeanUtils.copyProperties(
|
BeanUtils.copyProperties(
|
||||||
@@ -291,7 +324,7 @@ public class XrayCoreServiceImpl implements XrayCoreService {
|
|||||||
* @param networkPathList 网络路径节点
|
* @param networkPathList 网络路径节点
|
||||||
* @return 路径Tag
|
* @return 路径Tag
|
||||||
*/
|
*/
|
||||||
private String generatePathTag(ArrayList<ProxyNode> networkPathList) {
|
private String generatePathTag(List<ProxyNode> networkPathList) {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
networkPathList
|
networkPathList
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class XrayGenerateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void go(){
|
public void go(){
|
||||||
|
|
||||||
xrayCoreService.generateXrayJsonFromNodeList(null);
|
xrayCoreService.generateXrayConfigFromNodeList(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user