diff --git a/server/src/main/java/io/wdd/func/xray/beans/config/InboundVmessTCPTemplateClass.java b/server/src/main/java/io/wdd/func/xray/beans/config/InboundVmessTCPTemplateClass.java new file mode 100644 index 0000000..2a9a733 --- /dev/null +++ b/server/src/main/java/io/wdd/func/xray/beans/config/InboundVmessTCPTemplateClass.java @@ -0,0 +1,31 @@ +package io.wdd.func.xray.beans.config; + +import io.wdd.func.xray.beans.xray.protocol.inbound.vmess.VMESS; +import io.wdd.func.xray.beans.xray.transport.InboundObject; +import io.wdd.func.xray.beans.xray.transport.NoneHeaderObject; +import io.wdd.func.xray.beans.xray.transport.StreamSettingsObject; +import io.wdd.func.xray.beans.xray.transport.TcpObject; + +public class InboundVmessTCPTemplateClass { + + public static InboundObject InboundVmessTCPTemplate; + + + static { + + InboundVmessTCPTemplate = new VMESS(); + + // 构建 settings- vmess-tcp-http的对象 + TcpObject tcpObject = new TcpObject(); + + // none type + NoneHeaderObject noneHeaderObject = new NoneHeaderObject(); + tcpObject.setHeader(noneHeaderObject); + + // 设置 settings属性 + StreamSettingsObject streamSettingsObject = new StreamSettingsObject(); + streamSettingsObject.setTcpSettings(tcpObject); + InboundVmessTCPTemplate.setStreamSettings(streamSettingsObject); + + } +} diff --git a/server/src/main/java/io/wdd/func/xray/beans/config/OutboundVmessHTTPTemplateClass.java b/server/src/main/java/io/wdd/func/xray/beans/config/OutboundVmessHTTPTemplateClass.java index 8d47dce..5e90fe7 100644 --- a/server/src/main/java/io/wdd/func/xray/beans/config/OutboundVmessHTTPTemplateClass.java +++ b/server/src/main/java/io/wdd/func/xray/beans/config/OutboundVmessHTTPTemplateClass.java @@ -22,7 +22,8 @@ public class OutboundVmessHTTPTemplateClass { // 构造TCP TcpObject tcpObject = new TcpObject(); - + // 设置TCP的伪装部分 + // 参考 https://www.v2ray.com/chapter_02/transport/tcp.html HttpHeaderObject httpHeaderObject = new HttpHeaderObject(); httpHeaderObject.setRequest(HttpRequestTemplate); tcpObject.setHeader(httpHeaderObject); @@ -32,7 +33,7 @@ public class OutboundVmessHTTPTemplateClass { streamSettingsObject.setTcpSettings(tcpObject); OutboundVmessHTTPTemplate.setStreamSettings(streamSettingsObject); - // 需要初始化这个 + // 需要初始化这个,作为结构的补充 VmessOutSettings vmessOutSettings = new VmessOutSettings(); OutboundConfigurationObject.ServerObject serverObject = new OutboundConfigurationObject.ServerObject(); vmessOutSettings.setVnext( @@ -42,13 +43,14 @@ public class OutboundVmessHTTPTemplateClass { ); OutboundVmessHTTPTemplate.setSettings(vmessOutSettings); - + // mux的部分 MuxObject muxObject = new MuxObject(); muxObject.setConcurrency(-1); muxObject.setEnabled(Boolean.FALSE); - OutboundVmessHTTPTemplate.setMux(muxObject); + + // 其它的部分 OutboundFree = new Freedom(); OutboundBlackHole = new Blackhole(); diff --git a/server/src/main/java/io/wdd/func/xray/beans/config/OutboundVmessTCPTemplateClass.java b/server/src/main/java/io/wdd/func/xray/beans/config/OutboundVmessTCPTemplateClass.java new file mode 100644 index 0000000..edd9299 --- /dev/null +++ b/server/src/main/java/io/wdd/func/xray/beans/config/OutboundVmessTCPTemplateClass.java @@ -0,0 +1,50 @@ +package io.wdd.func.xray.beans.config; + +import io.wdd.func.xray.beans.xray.protocol.outbound.OutboundConfigurationObject; +import io.wdd.func.xray.beans.xray.protocol.outbound.VMESS; +import io.wdd.func.xray.beans.xray.protocol.outbound.VmessOutSettings; +import io.wdd.func.xray.beans.xray.transport.*; + +import java.util.ArrayList; +import java.util.List; + + +public class OutboundVmessTCPTemplateClass { + + public static OutboundObject OutboundVmessTCPTemplate; + + static { + OutboundVmessTCPTemplate = new VMESS(); + + // 构造TCP + TcpObject tcpObject = new TcpObject(); + // 默认的Header结构为 + // { + // "header": { + // "type": "none" + // } + //} + NoneHeaderObject noneHeaderObject = new NoneHeaderObject(); + tcpObject.setHeader(noneHeaderObject); + + StreamSettingsObject streamSettingsObject = new StreamSettingsObject(); + streamSettingsObject.setTcpSettings(tcpObject); + OutboundVmessTCPTemplate.setStreamSettings(streamSettingsObject); + + // 需要初始化这个,作为结构的补充 + VmessOutSettings vmessOutSettings = new VmessOutSettings(); + OutboundConfigurationObject.ServerObject serverObject = new OutboundConfigurationObject.ServerObject(); + vmessOutSettings.setVnext( + new ArrayList<>( + List.of(serverObject) + ) + ); + OutboundVmessTCPTemplate.setSettings(vmessOutSettings); + + // mux的部分 + MuxObject muxObject = new MuxObject(); + muxObject.setConcurrency(4); + muxObject.setEnabled(Boolean.TRUE); + OutboundVmessTCPTemplate.setMux(muxObject); + } +} diff --git a/server/src/main/java/io/wdd/func/xray/beans/config/TcpHttpHeaderTemplate.java b/server/src/main/java/io/wdd/func/xray/beans/config/TcpHttpHeaderTemplate.java index daeebe4..e6c149d 100644 --- a/server/src/main/java/io/wdd/func/xray/beans/config/TcpHttpHeaderTemplate.java +++ b/server/src/main/java/io/wdd/func/xray/beans/config/TcpHttpHeaderTemplate.java @@ -11,7 +11,6 @@ public class TcpHttpHeaderTemplate { public static HTTPRequestObject HttpRequestTemplate; public static HTTPResponseObject HttpResponseTemplate; - static { List xrayFakeHostName = List.of( diff --git a/server/src/main/java/io/wdd/func/xray/beans/xray/transport/NoneHeaderObject.java b/server/src/main/java/io/wdd/func/xray/beans/xray/transport/NoneHeaderObject.java new file mode 100644 index 0000000..d38d613 --- /dev/null +++ b/server/src/main/java/io/wdd/func/xray/beans/xray/transport/NoneHeaderObject.java @@ -0,0 +1,5 @@ +package io.wdd.func.xray.beans.xray.transport; + +public class NoneHeaderObject extends TCPHeaderObject { + +} diff --git a/server/src/main/java/io/wdd/func/xray/beans/xray/transport/TransportObject.java b/server/src/main/java/io/wdd/func/xray/beans/xray/transport/TransportObject.java index 021e694..3045f64 100644 --- a/server/src/main/java/io/wdd/func/xray/beans/xray/transport/TransportObject.java +++ b/server/src/main/java/io/wdd/func/xray/beans/xray/transport/TransportObject.java @@ -30,11 +30,6 @@ abstract class TCPHeaderObject { } -class NoneHeaderObject extends TCPHeaderObject{ - -} - - class KcpObject { } 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 b238239..0e44c5f 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,10 +30,12 @@ import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.stream.Collectors; -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.InboundVmessTCPTemplateClass.InboundVmessTCPTemplate; 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.OutboundBlackHole; +import static io.wdd.func.xray.beans.config.OutboundVmessHTTPTemplateClass.OutboundFree; +import static io.wdd.func.xray.beans.config.OutboundVmessTCPTemplateClass.OutboundVmessTCPTemplate; import static io.wdd.func.xray.persisit.cache.ProxyNodeCache.*; import static io.wdd.func.xray.service.XrayConfigPersistor.*; @@ -234,6 +236,7 @@ public class XrayCoreServiceImpl implements XrayCoreService { .getXrayConfig() .getInbounds(); + // 构造Inbound Object VMESS realInboundObject = (VMESS) inboundObjectList .stream() .filter( @@ -325,6 +328,14 @@ public class XrayCoreServiceImpl implements XrayCoreService { } + /** + * 生成一条代理链 + * + * @param chainPort 代理连使用的端口 + * @param networkPathList 代理链上的每一个服务器节点 + * @param currentVersion + * @param chainTag 代理链的tag + */ private void generateXrayJsonSinglePath(int chainPort, List networkPathList, int currentVersion, String chainTag) { int pathLength = networkPathList.size(); @@ -370,6 +381,16 @@ public class XrayCoreServiceImpl implements XrayCoreService { } + /** + * 实际身长Xray的配置 + * + * @param chainTag + * @param clientObject + * @param chainPort + * @param networkPathList + * @param pos + * @return + */ private XrayConfig doBuildXrayConfig(String chainTag, ClientObject clientObject, int chainPort, List networkPathList, int pos) { // 需要从现有的XrayConfig基础上进行生成 @@ -473,7 +494,6 @@ public class XrayCoreServiceImpl implements XrayCoreService { } // 中间节点,需要进行特定的构建 - io.wdd.func.xray.beans.xray.protocol.outbound.VMESS vmessOutbound = new io.wdd.func.xray.beans.xray.protocol.outbound.VMESS(); // 深拷贝的问题 @@ -483,7 +503,7 @@ public class XrayCoreServiceImpl implements XrayCoreService { BeanUtils.copyProperties( vmessOutbound, - OutboundVmessHTTPTemplate + OutboundVmessTCPTemplate ); // 解决深拷贝的问题 @@ -544,7 +564,7 @@ public class XrayCoreServiceImpl implements XrayCoreService { try { BeanUtils.copyProperties( inboundObject, - InboundVmessHTTPTemplate + InboundVmessTCPTemplate ); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e);