Rename the v2ray configuration class

pull/3828/head
2dust 2023-05-07 16:35:46 +08:00
parent 4fcae44fb7
commit 94cc36a08f
2 changed files with 138 additions and 117 deletions

View File

@ -96,24 +96,24 @@ namespace v2rayN.Handler
{
try
{
v2rayConfig.inbounds = new List<Inbounds>();
v2rayConfig.inbounds = new List<Inbounds4Ray>();
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<AccountsItem> { new AccountsItem() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } };
inbound3.settings.accounts = new List<AccountsItem4Ray> { new AccountsItem4Ray() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } };
inbound4.settings.auth = "password";
inbound4.settings.accounts = new List<AccountsItem> { new AccountsItem() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } };
inbound4.settings.accounts = new List<AccountsItem4Ray> { 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<Inbounds>(result);
var inbound = Utils.FromJson<Inbounds4Ray>(result);
if (inbound == null)
{
return null;
@ -187,7 +187,8 @@ namespace v2rayN.Handler
{
if (item.enabled)
{
routingUserRule(item, v2rayConfig);
var item2 = Utils.FromJson<RulesItem4Ray>(Utils.ToJson(item));
routingUserRule(item2, v2rayConfig);
}
}
}
@ -200,7 +201,8 @@ namespace v2rayN.Handler
var rules = Utils.FromJson<List<RulesItem>>(lockedItem.ruleSet);
foreach (var item in rules)
{
routingUserRule(item, v2rayConfig);
var item2 = Utils.FromJson<RulesItem4Ray>(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>() { socksUsersItem };
serversItem.users = new List<SocksUsersItem4Ray>() { 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<string> { 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<string> { inbound.tag },
outboundTag = v2rayConfigCopy.outbounds[0].tag,

View File

@ -11,28 +11,28 @@ namespace v2rayN.Mode
/// <summary>
/// 日志配置
/// </summary>
public Log log { get; set; }
public Log4Ray log { get; set; }
/// <summary>
/// 传入连接配置
/// </summary>
public List<Inbounds> inbounds { get; set; }
public List<Inbounds4Ray> inbounds { get; set; }
/// <summary>
/// 传出连接配置
/// </summary>
public List<Outbounds> outbounds { get; set; }
public List<Outbounds4Ray> outbounds { get; set; }
/// <summary>
/// 统计需要, 空对象
/// </summary>
public Stats stats { get; set; }
public Stats4Ray stats { get; set; }
/// </summary>
public API api { get; set; }
public API4Ray api { get; set; }
/// </summary>
public Policy policy;
public Policy4Ray policy;
/// <summary>
/// DNS 配置
@ -42,30 +42,30 @@ namespace v2rayN.Mode
/// <summary>
/// 路由配置
/// </summary>
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<string> 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
{
/// <summary>
///
@ -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
/// <summary>
///
/// </summary>
public Sniffing sniffing { get; set; }
public Sniffing4Ray sniffing { get; set; }
/// <summary>
///
/// </summary>
public Inboundsettings settings { get; set; }
public Inboundsettings4Ray settings { get; set; }
/// <summary>
///
/// </summary>
public StreamSettings streamSettings { get; set; }
public StreamSettings4Ray streamSettings { get; set; }
}
public class Inboundsettings
public class Inboundsettings4Ray
{
/// <summary>
///
@ -143,7 +143,7 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public List<UsersItem> clients { get; set; }
public List<UsersItem4Ray> clients { get; set; }
/// <summary>
/// VLESS
@ -152,10 +152,10 @@ namespace v2rayN.Mode
public bool allowTransparent { get; set; }
public List<AccountsItem> accounts { get; set; }
public List<AccountsItem4Ray> accounts { get; set; }
}
public class UsersItem
public class UsersItem4Ray
{
/// <summary>
///
@ -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<string> destOverride { get; set; }
public bool routeOnly { get; set; }
}
public class Outbounds
public class Outbounds4Ray
{
/// <summary>
/// 默认值agentout
@ -210,35 +210,35 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public Outboundsettings settings { get; set; }
public Outboundsettings4Ray settings { get; set; }
/// <summary>
///
/// </summary>
public StreamSettings streamSettings { get; set; }
public StreamSettings4Ray streamSettings { get; set; }
/// <summary>
///
/// </summary>
public Mux mux { get; set; }
public Mux4Ray mux { get; set; }
}
public class Outboundsettings
public class Outboundsettings4Ray
{
/// <summary>
///
/// </summary>
public List<VnextItem> vnext { get; set; }
public List<VnextItem4Ray> vnext { get; set; }
/// <summary>
///
/// </summary>
public List<ServersItem> servers { get; set; }
public List<ServersItem4Ray> servers { get; set; }
/// <summary>
///
/// </summary>
public Response response { get; set; }
public Response4Ray response { get; set; }
/// <summary>
///
@ -251,7 +251,7 @@ namespace v2rayN.Mode
public int? userLevel { get; set; }
}
public class VnextItem
public class VnextItem4Ray
{
/// <summary>
///
@ -266,10 +266,10 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public List<UsersItem> users { get; set; }
public List<UsersItem4Ray> users { get; set; }
}
public class ServersItem
public class ServersItem4Ray
{
/// <summary>
///
@ -314,10 +314,10 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public List<SocksUsersItem> users { get; set; }
public List<SocksUsersItem4Ray> users { get; set; }
}
public class SocksUsersItem
public class SocksUsersItem4Ray
{
/// <summary>
///
@ -335,7 +335,7 @@ namespace v2rayN.Mode
public int level { get; set; }
}
public class Mux
public class Mux4Ray
{
/// <summary>
///
@ -348,7 +348,7 @@ namespace v2rayN.Mode
public int concurrency { get; set; }
}
public class Response
public class Response4Ray
{
/// <summary>
///
@ -356,7 +356,7 @@ namespace v2rayN.Mode
public string type { get; set; }
}
public class Dns
public class Dns4Ray
{
/// <summary>
///
@ -364,7 +364,7 @@ namespace v2rayN.Mode
public List<string> servers { get; set; }
}
public class Routing
public class Routing4Ray
{
/// <summary>
///
@ -379,10 +379,28 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public List<RulesItem> rules { get; set; }
public List<RulesItem4Ray> rules { get; set; }
}
public class StreamSettings
[Serializable]
public class RulesItem4Ray
{
public string type { get; set; }
public string port { get; set; }
public List<string> inboundTag { get; set; }
public string outboundTag { get; set; }
public List<string> ip { get; set; }
public List<string> domain { get; set; }
public List<string> protocol { get; set; }
}
public class StreamSettings4Ray
{
/// <summary>
///
@ -397,45 +415,45 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public TlsSettings tlsSettings { get; set; }
public TlsSettings4Ray tlsSettings { get; set; }
/// <summary>
/// Tcp传输额外设置
/// </summary>
public TcpSettings tcpSettings { get; set; }
public TcpSettings4Ray tcpSettings { get; set; }
/// <summary>
/// Kcp传输额外设置
/// </summary>
public KcpSettings kcpSettings { get; set; }
public KcpSettings4Ray kcpSettings { get; set; }
/// <summary>
/// ws传输额外设置
/// </summary>
public WsSettings wsSettings { get; set; }
public WsSettings4Ray wsSettings { get; set; }
/// <summary>
/// h2传输额外设置
/// </summary>
public HttpSettings httpSettings { get; set; }
public HttpSettings4Ray httpSettings { get; set; }
/// <summary>
/// QUIC
/// </summary>
public QuicSettings quicSettings { get; set; }
public QuicSettings4Ray quicSettings { get; set; }
/// <summary>
/// VLESS only
/// </summary>
public TlsSettings realitySettings { get; set; }
public TlsSettings4Ray realitySettings { get; set; }
/// <summary>
/// grpc
/// </summary>
public GrpcSettings grpcSettings { get; set; }
public GrpcSettings4Ray grpcSettings { get; set; }
}
public class TlsSettings
public class TlsSettings4Ray
{
/// <summary>
/// 是否允许不安全连接(用于客户端)
@ -460,15 +478,15 @@ namespace v2rayN.Mode
public string? spiderX { get; set; }
}
public class TcpSettings
public class TcpSettings4Ray
{
/// <summary>
/// 数据包头部伪装设置
/// </summary>
public Header header { get; set; }
public Header4Ray header { get; set; }
}
public class Header
public class Header4Ray
{
/// <summary>
/// 伪装
@ -486,7 +504,7 @@ namespace v2rayN.Mode
public object response { get; set; }
}
public class KcpSettings
public class KcpSettings4Ray
{
/// <summary>
///
@ -526,7 +544,7 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public Header header { get; set; }
public Header4Ray header { get; set; }
/// <summary>
///
@ -534,7 +552,7 @@ namespace v2rayN.Mode
public string seed { get; set; }
}
public class WsSettings
public class WsSettings4Ray
{
/// <summary>
///
@ -544,10 +562,10 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
public Headers headers { get; set; }
public Headers4Ray headers { get; set; }
}
public class Headers
public class Headers4Ray
{
/// <summary>
///
@ -561,7 +579,7 @@ namespace v2rayN.Mode
public string UserAgent { get; set; }
}
public class HttpSettings
public class HttpSettings4Ray
{
/// <summary>
///
@ -574,7 +592,7 @@ namespace v2rayN.Mode
public List<string> host { get; set; }
}
public class QuicSettings
public class QuicSettings4Ray
{
/// <summary>
///
@ -589,10 +607,10 @@ namespace v2rayN.Mode
/// <summary>
///
/// </summary>
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
{
/// <summary>
///