From 94cc36a08f80c994e1bff9985be4c38f9a2f7ccf Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 7 May 2023 16:35:46 +0800 Subject: [PATCH] Rename the v2ray configuration class --- v2rayN/v2rayN/Handler/CoreConfigV2ray.cs | 111 ++++++++--------- v2rayN/v2rayN/Mode/V2rayConfig.cs | 144 +++++++++++++---------- 2 files changed, 138 insertions(+), 117 deletions(-) diff --git a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs index e7a99ad2..b4ef45f8 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs @@ -96,24 +96,24 @@ namespace v2rayN.Handler { try { - v2rayConfig.inbounds = new List(); + v2rayConfig.inbounds = new List(); - Inbounds? inbound = GetInbound(_config.inbound[0], Global.InboundSocks, 0, true); + Inbounds4Ray? inbound = GetInbound(_config.inbound[0], Global.InboundSocks, 0, true); v2rayConfig.inbounds.Add(inbound); //http - Inbounds? inbound2 = GetInbound(_config.inbound[0], Global.InboundHttp, 1, false); + Inbounds4Ray? inbound2 = GetInbound(_config.inbound[0], Global.InboundHttp, 1, false); v2rayConfig.inbounds.Add(inbound2); if (_config.inbound[0].allowLANConn) { if (_config.inbound[0].newPort4LAN) { - Inbounds inbound3 = GetInbound(_config.inbound[0], Global.InboundSocks2, 2, true); + Inbounds4Ray inbound3 = GetInbound(_config.inbound[0], Global.InboundSocks2, 2, true); inbound3.listen = "0.0.0.0"; v2rayConfig.inbounds.Add(inbound3); - Inbounds inbound4 = GetInbound(_config.inbound[0], Global.InboundHttp2, 3, false); + Inbounds4Ray inbound4 = GetInbound(_config.inbound[0], Global.InboundHttp2, 3, false); inbound4.listen = "0.0.0.0"; v2rayConfig.inbounds.Add(inbound4); @@ -121,10 +121,10 @@ namespace v2rayN.Handler if (!Utils.IsNullOrEmpty(_config.inbound[0].user) && !Utils.IsNullOrEmpty(_config.inbound[0].pass)) { inbound3.settings.auth = "password"; - inbound3.settings.accounts = new List { new AccountsItem() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } }; + inbound3.settings.accounts = new List { new AccountsItem4Ray() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } }; inbound4.settings.auth = "password"; - inbound4.settings.accounts = new List { new AccountsItem() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } }; + inbound4.settings.accounts = new List { new AccountsItem4Ray() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } }; } } else @@ -141,7 +141,7 @@ namespace v2rayN.Handler return 0; } - private Inbounds? GetInbound(InItem inItem, string tag, int offset, bool bSocks) + private Inbounds4Ray? GetInbound(InItem inItem, string tag, int offset, bool bSocks) { string result = Utils.GetEmbedText(Global.v2raySampleInbound); if (Utils.IsNullOrEmpty(result)) @@ -149,7 +149,7 @@ namespace v2rayN.Handler return null; } - var inbound = Utils.FromJson(result); + var inbound = Utils.FromJson(result); if (inbound == null) { return null; @@ -187,7 +187,8 @@ namespace v2rayN.Handler { if (item.enabled) { - routingUserRule(item, v2rayConfig); + var item2 = Utils.FromJson(Utils.ToJson(item)); + routingUserRule(item2, v2rayConfig); } } } @@ -200,7 +201,8 @@ namespace v2rayN.Handler var rules = Utils.FromJson>(lockedItem.ruleSet); foreach (var item in rules) { - routingUserRule(item, v2rayConfig); + var item2 = Utils.FromJson(Utils.ToJson(item)); + routingUserRule(item2, v2rayConfig); } } } @@ -213,7 +215,7 @@ namespace v2rayN.Handler return 0; } - private int routingUserRule(RulesItem rules, V2rayConfig v2rayConfig) + private int routingUserRule(RulesItem4Ray rules, V2rayConfig v2rayConfig) { try { @@ -291,13 +293,13 @@ namespace v2rayN.Handler { try { - Outbounds outbound = v2rayConfig.outbounds[0]; + Outbounds4Ray outbound = v2rayConfig.outbounds[0]; if (node.configType == EConfigType.VMess) { - VnextItem vnextItem; + VnextItem4Ray vnextItem; if (outbound.settings.vnext.Count <= 0) { - vnextItem = new VnextItem(); + vnextItem = new VnextItem4Ray(); outbound.settings.vnext.Add(vnextItem); } else @@ -307,10 +309,10 @@ namespace v2rayN.Handler vnextItem.address = node.address; vnextItem.port = node.port; - UsersItem usersItem; + UsersItem4Ray usersItem; if (vnextItem.users.Count <= 0) { - usersItem = new UsersItem(); + usersItem = new UsersItem4Ray(); vnextItem.users.Add(usersItem); } else @@ -337,10 +339,10 @@ namespace v2rayN.Handler } else if (node.configType == EConfigType.Shadowsocks) { - ServersItem serversItem; + ServersItem4Ray serversItem; if (outbound.settings.servers.Count <= 0) { - serversItem = new ServersItem(); + serversItem = new ServersItem4Ray(); outbound.settings.servers.Add(serversItem); } else @@ -362,10 +364,10 @@ namespace v2rayN.Handler } else if (node.configType == EConfigType.Socks) { - ServersItem serversItem; + ServersItem4Ray serversItem; if (outbound.settings.servers.Count <= 0) { - serversItem = new ServersItem(); + serversItem = new ServersItem4Ray(); outbound.settings.servers.Add(serversItem); } else @@ -380,14 +382,14 @@ namespace v2rayN.Handler if (!Utils.IsNullOrEmpty(node.security) && !Utils.IsNullOrEmpty(node.id)) { - SocksUsersItem socksUsersItem = new() + SocksUsersItem4Ray socksUsersItem = new() { user = node.security, pass = node.id, level = 1 }; - serversItem.users = new List() { socksUsersItem }; + serversItem.users = new List() { socksUsersItem }; } outboundMux(node, outbound, false); @@ -397,10 +399,10 @@ namespace v2rayN.Handler } else if (node.configType == EConfigType.VLESS) { - VnextItem vnextItem; + VnextItem4Ray vnextItem; if (outbound.settings.vnext.Count <= 0) { - vnextItem = new VnextItem(); + vnextItem = new VnextItem4Ray(); outbound.settings.vnext.Add(vnextItem); } else @@ -410,10 +412,10 @@ namespace v2rayN.Handler vnextItem.address = node.address; vnextItem.port = node.port; - UsersItem usersItem; + UsersItem4Ray usersItem; if (vnextItem.users.Count <= 0) { - usersItem = new UsersItem(); + usersItem = new UsersItem4Ray(); vnextItem.users.Add(usersItem); } else @@ -447,10 +449,10 @@ namespace v2rayN.Handler } else if (node.configType == EConfigType.Trojan) { - ServersItem serversItem; + ServersItem4Ray serversItem; if (outbound.settings.servers.Count <= 0) { - serversItem = new ServersItem(); + serversItem = new ServersItem4Ray(); outbound.settings.servers.Add(serversItem); } else @@ -479,11 +481,11 @@ namespace v2rayN.Handler return 0; } - private int outboundMux(ProfileItem node, Outbounds outbound, bool enabled) + private int outboundMux(ProfileItem node, Outbounds4Ray outbound, bool enabled) { try { - if (_config.coreBasicItem.muxEnabled) + if (enabled) { outbound.mux.enabled = true; outbound.mux.concurrency = 8; @@ -501,7 +503,7 @@ namespace v2rayN.Handler return 0; } - private int boundStreamSettings(ProfileItem node, StreamSettings streamSettings) + private int boundStreamSettings(ProfileItem node, StreamSettings4Ray streamSettings) { try { @@ -526,7 +528,7 @@ namespace v2rayN.Handler { streamSettings.security = node.streamSecurity; - TlsSettings tlsSettings = new() + TlsSettings4Ray tlsSettings = new() { allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? _config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure), alpn = node.GetAlpn(), @@ -548,7 +550,7 @@ namespace v2rayN.Handler { streamSettings.security = node.streamSecurity; - TlsSettings realitySettings = new() + TlsSettings4Ray realitySettings = new() { fingerprint = node.fingerprint.IsNullOrEmpty() ? _config.coreBasicItem.defFingerprint : node.fingerprint, serverName = sni, @@ -564,7 +566,7 @@ namespace v2rayN.Handler switch (node.GetNetwork()) { case "kcp": - KcpSettings kcpSettings = new() + KcpSettings4Ray kcpSettings = new() { mtu = _config.kcpItem.mtu, tti = _config.kcpItem.tti @@ -576,7 +578,7 @@ namespace v2rayN.Handler kcpSettings.congestion = _config.kcpItem.congestion; kcpSettings.readBufferSize = _config.kcpItem.readBufferSize; kcpSettings.writeBufferSize = _config.kcpItem.writeBufferSize; - kcpSettings.header = new Header + kcpSettings.header = new Header4Ray { type = node.headerType }; @@ -588,8 +590,8 @@ namespace v2rayN.Handler break; //ws case "ws": - WsSettings wsSettings = new(); - wsSettings.headers = new Headers(); + WsSettings4Ray wsSettings = new(); + wsSettings.headers = new Headers4Ray(); string path = node.path; if (!string.IsNullOrWhiteSpace(host)) { @@ -608,7 +610,7 @@ namespace v2rayN.Handler break; //h2 case "h2": - HttpSettings httpSettings = new(); + HttpSettings4Ray httpSettings = new(); if (!string.IsNullOrWhiteSpace(host)) { @@ -621,11 +623,11 @@ namespace v2rayN.Handler break; //quic case "quic": - QuicSettings quicsettings = new() + QuicSettings4Ray quicsettings = new() { security = host, key = node.path, - header = new Header + header = new Header4Ray { type = node.headerType } @@ -645,7 +647,7 @@ namespace v2rayN.Handler break; case "grpc": - GrpcSettings grpcSettings = new() + GrpcSettings4Ray grpcSettings = new() { serviceName = node.path, multiMode = (node.headerType == Global.GrpcmultiMode), @@ -661,9 +663,9 @@ namespace v2rayN.Handler //tcp if (node.headerType == Global.TcpHeaderHttp) { - TcpSettings tcpSettings = new() + TcpSettings4Ray tcpSettings = new() { - header = new Header + header = new Header4Ray { type = node.headerType } @@ -736,7 +738,7 @@ namespace v2rayN.Handler //} } //servers.Add("localhost"); - v2rayConfig.dns = new Mode.Dns + v2rayConfig.dns = new Mode.Dns4Ray { servers = servers }; @@ -754,13 +756,13 @@ namespace v2rayN.Handler if (_config.guiItem.enableStatistics) { string tag = Global.InboundAPITagName; - API apiObj = new(); - Policy policyObj = new(); - SystemPolicy policySystemSetting = new(); + API4Ray apiObj = new(); + Policy4Ray policyObj = new(); + SystemPolicy4Ray policySystemSetting = new(); string[] services = { "StatsService" }; - v2rayConfig.stats = new Stats(); + v2rayConfig.stats = new Stats4Ray(); apiObj.tag = tag; apiObj.services = services.ToList(); @@ -773,8 +775,8 @@ namespace v2rayN.Handler if (!v2rayConfig.inbounds.Exists(item => item.tag == tag)) { - Inbounds apiInbound = new(); - Inboundsettings apiInboundSettings = new(); + Inbounds4Ray apiInbound = new(); + Inboundsettings4Ray apiInboundSettings = new(); apiInbound.tag = tag; apiInbound.listen = Global.Loopback; apiInbound.port = Global.statePort; @@ -786,12 +788,13 @@ namespace v2rayN.Handler if (!v2rayConfig.routing.rules.Exists(item => item.outboundTag == tag)) { - RulesItem apiRoutingRule = new() + RulesItem4Ray apiRoutingRule = new() { inboundTag = new List { tag }, outboundTag = tag, type = "field" }; + v2rayConfig.routing.rules.Add(apiRoutingRule); } } @@ -891,7 +894,7 @@ namespace v2rayN.Handler it.allowTest = true; //inbound - Inbounds inbound = new() + Inbounds4Ray inbound = new() { listen = Global.Loopback, port = port, @@ -923,7 +926,7 @@ namespace v2rayN.Handler v2rayConfig.outbounds.Add(v2rayConfigCopy.outbounds[0]); //rule - RulesItem rule = new() + RulesItem4Ray rule = new() { inboundTag = new List { inbound.tag }, outboundTag = v2rayConfigCopy.outbounds[0].tag, diff --git a/v2rayN/v2rayN/Mode/V2rayConfig.cs b/v2rayN/v2rayN/Mode/V2rayConfig.cs index a9888312..b20f526d 100644 --- a/v2rayN/v2rayN/Mode/V2rayConfig.cs +++ b/v2rayN/v2rayN/Mode/V2rayConfig.cs @@ -11,28 +11,28 @@ namespace v2rayN.Mode /// /// 日志配置 /// - public Log log { get; set; } + public Log4Ray log { get; set; } /// /// 传入连接配置 /// - public List inbounds { get; set; } + public List inbounds { get; set; } /// /// 传出连接配置 /// - public List outbounds { get; set; } + public List outbounds { get; set; } /// /// 统计需要, 空对象 /// - public Stats stats { get; set; } + public Stats4Ray stats { get; set; } /// - public API api { get; set; } + public API4Ray api { get; set; } /// - public Policy policy; + public Policy4Ray policy; /// /// DNS 配置 @@ -42,30 +42,30 @@ namespace v2rayN.Mode /// /// 路由配置 /// - public Routing routing { get; set; } + public Routing4Ray routing { get; set; } } - public class Stats + public class Stats4Ray { }; - public class API + public class API4Ray { public string tag { get; set; } public List services { get; set; } } - public class Policy + public class Policy4Ray { - public SystemPolicy system; + public SystemPolicy4Ray system; } - public class SystemPolicy + public class SystemPolicy4Ray { public bool statsOutboundUplink; public bool statsOutboundDownlink; } - public class Log + public class Log4Ray { /// /// @@ -83,7 +83,7 @@ namespace v2rayN.Mode public string loglevel { get; set; } } - public class Inbounds + public class Inbounds4Ray { public string tag { get; set; } @@ -105,20 +105,20 @@ namespace v2rayN.Mode /// /// /// - public Sniffing sniffing { get; set; } + public Sniffing4Ray sniffing { get; set; } /// /// /// - public Inboundsettings settings { get; set; } + public Inboundsettings4Ray settings { get; set; } /// /// /// - public StreamSettings streamSettings { get; set; } + public StreamSettings4Ray streamSettings { get; set; } } - public class Inboundsettings + public class Inboundsettings4Ray { /// /// @@ -143,7 +143,7 @@ namespace v2rayN.Mode /// /// /// - public List clients { get; set; } + public List clients { get; set; } /// /// VLESS @@ -152,10 +152,10 @@ namespace v2rayN.Mode public bool allowTransparent { get; set; } - public List accounts { get; set; } + public List accounts { get; set; } } - public class UsersItem + public class UsersItem4Ray { /// /// @@ -188,14 +188,14 @@ namespace v2rayN.Mode public string flow { get; set; } } - public class Sniffing + public class Sniffing4Ray { public bool enabled { get; set; } public List destOverride { get; set; } public bool routeOnly { get; set; } } - public class Outbounds + public class Outbounds4Ray { /// /// 默认值agentout @@ -210,35 +210,35 @@ namespace v2rayN.Mode /// /// /// - public Outboundsettings settings { get; set; } + public Outboundsettings4Ray settings { get; set; } /// /// /// - public StreamSettings streamSettings { get; set; } + public StreamSettings4Ray streamSettings { get; set; } /// /// /// - public Mux mux { get; set; } + public Mux4Ray mux { get; set; } } - public class Outboundsettings + public class Outboundsettings4Ray { /// /// /// - public List vnext { get; set; } + public List vnext { get; set; } /// /// /// - public List servers { get; set; } + public List servers { get; set; } /// /// /// - public Response response { get; set; } + public Response4Ray response { get; set; } /// /// @@ -251,7 +251,7 @@ namespace v2rayN.Mode public int? userLevel { get; set; } } - public class VnextItem + public class VnextItem4Ray { /// /// @@ -266,10 +266,10 @@ namespace v2rayN.Mode /// /// /// - public List users { get; set; } + public List users { get; set; } } - public class ServersItem + public class ServersItem4Ray { /// /// @@ -314,10 +314,10 @@ namespace v2rayN.Mode /// /// /// - public List users { get; set; } + public List users { get; set; } } - public class SocksUsersItem + public class SocksUsersItem4Ray { /// /// @@ -335,7 +335,7 @@ namespace v2rayN.Mode public int level { get; set; } } - public class Mux + public class Mux4Ray { /// /// @@ -348,7 +348,7 @@ namespace v2rayN.Mode public int concurrency { get; set; } } - public class Response + public class Response4Ray { /// /// @@ -356,7 +356,7 @@ namespace v2rayN.Mode public string type { get; set; } } - public class Dns + public class Dns4Ray { /// /// @@ -364,7 +364,7 @@ namespace v2rayN.Mode public List servers { get; set; } } - public class Routing + public class Routing4Ray { /// /// @@ -379,10 +379,28 @@ namespace v2rayN.Mode /// /// /// - public List rules { get; set; } + public List rules { get; set; } } - public class StreamSettings + [Serializable] + public class RulesItem4Ray + { + public string type { get; set; } + + public string port { get; set; } + + public List inboundTag { get; set; } + + public string outboundTag { get; set; } + + public List ip { get; set; } + + public List domain { get; set; } + + public List protocol { get; set; } + } + + public class StreamSettings4Ray { /// /// @@ -397,45 +415,45 @@ namespace v2rayN.Mode /// /// /// - public TlsSettings tlsSettings { get; set; } + public TlsSettings4Ray tlsSettings { get; set; } /// /// Tcp传输额外设置 /// - public TcpSettings tcpSettings { get; set; } + public TcpSettings4Ray tcpSettings { get; set; } /// /// Kcp传输额外设置 /// - public KcpSettings kcpSettings { get; set; } + public KcpSettings4Ray kcpSettings { get; set; } /// /// ws传输额外设置 /// - public WsSettings wsSettings { get; set; } + public WsSettings4Ray wsSettings { get; set; } /// /// h2传输额外设置 /// - public HttpSettings httpSettings { get; set; } + public HttpSettings4Ray httpSettings { get; set; } /// /// QUIC /// - public QuicSettings quicSettings { get; set; } + public QuicSettings4Ray quicSettings { get; set; } /// /// VLESS only /// - public TlsSettings realitySettings { get; set; } + public TlsSettings4Ray realitySettings { get; set; } /// /// grpc /// - public GrpcSettings grpcSettings { get; set; } + public GrpcSettings4Ray grpcSettings { get; set; } } - public class TlsSettings + public class TlsSettings4Ray { /// /// 是否允许不安全连接(用于客户端) @@ -460,15 +478,15 @@ namespace v2rayN.Mode public string? spiderX { get; set; } } - public class TcpSettings + public class TcpSettings4Ray { /// /// 数据包头部伪装设置 /// - public Header header { get; set; } + public Header4Ray header { get; set; } } - public class Header + public class Header4Ray { /// /// 伪装 @@ -486,7 +504,7 @@ namespace v2rayN.Mode public object response { get; set; } } - public class KcpSettings + public class KcpSettings4Ray { /// /// @@ -526,7 +544,7 @@ namespace v2rayN.Mode /// /// /// - public Header header { get; set; } + public Header4Ray header { get; set; } /// /// @@ -534,7 +552,7 @@ namespace v2rayN.Mode public string seed { get; set; } } - public class WsSettings + public class WsSettings4Ray { /// /// @@ -544,10 +562,10 @@ namespace v2rayN.Mode /// /// /// - public Headers headers { get; set; } + public Headers4Ray headers { get; set; } } - public class Headers + public class Headers4Ray { /// /// @@ -561,7 +579,7 @@ namespace v2rayN.Mode public string UserAgent { get; set; } } - public class HttpSettings + public class HttpSettings4Ray { /// /// @@ -574,7 +592,7 @@ namespace v2rayN.Mode public List host { get; set; } } - public class QuicSettings + public class QuicSettings4Ray { /// /// @@ -589,10 +607,10 @@ namespace v2rayN.Mode /// /// /// - public Header header { get; set; } + public Header4Ray header { get; set; } } - public class GrpcSettings + public class GrpcSettings4Ray { public string serviceName { get; set; } public bool multiMode { get; set; } @@ -602,7 +620,7 @@ namespace v2rayN.Mode public int initial_windows_size { get; set; } } - public class AccountsItem + public class AccountsItem4Ray { /// ///