Refactor basic settings

pull/3301/head
2dust 2023-02-10 14:16:59 +08:00
parent 9b05736746
commit 1ff1962425
5 changed files with 76 additions and 70 deletions

View File

@ -44,12 +44,6 @@ namespace v2rayN.Handler
{ {
config = new Config config = new Config
{ {
logEnabled = false,
loglevel = "warning",
//Mux
muxEnabled = false,
enableStatistics = false, enableStatistics = false,
statisticsFreshRate = 1, statisticsFreshRate = 1,
@ -57,6 +51,16 @@ namespace v2rayN.Handler
enableRoutingAdvanced = true enableRoutingAdvanced = true
}; };
} }
if (config.coreBasicItem == null)
{
config.coreBasicItem = new()
{
logEnabled = false,
loglevel = "warning",
muxEnabled = false,
};
}
//本地监听 //本地监听
if (config.inbound == null) if (config.inbound == null)
@ -647,7 +651,7 @@ namespace v2rayN.Handler
} }
if (Utils.IsNullOrEmpty(profileItem.allowInsecure)) if (Utils.IsNullOrEmpty(profileItem.allowInsecure))
{ {
profileItem.allowInsecure = config.defAllowInsecure.ToString().ToLower(); profileItem.allowInsecure = config.coreBasicItem.defAllowInsecure.ToString().ToLower();
} }
AddServerCommon(ref config, profileItem); AddServerCommon(ref config, profileItem);
@ -781,7 +785,7 @@ namespace v2rayN.Handler
profileItem.configVersion = 2; profileItem.configVersion = 2;
if (Utils.IsNullOrEmpty(profileItem.allowInsecure)) if (Utils.IsNullOrEmpty(profileItem.allowInsecure))
{ {
profileItem.allowInsecure = config.defAllowInsecure.ToString().ToLower(); profileItem.allowInsecure = config.coreBasicItem.defAllowInsecure.ToString().ToLower();
} }
if (!Utils.IsNullOrEmpty(profileItem.network) && !Global.networks.Contains(profileItem.network)) if (!Utils.IsNullOrEmpty(profileItem.network) && !Global.networks.Contains(profileItem.network))
{ {

View File

@ -73,29 +73,29 @@ namespace v2rayN.Handler
{ {
if (blExport) if (blExport)
{ {
if (config.logEnabled) if (config.coreBasicItem.logEnabled)
{ {
v2rayConfig.log.loglevel = config.loglevel; v2rayConfig.log.loglevel = config.coreBasicItem.loglevel;
} }
else else
{ {
v2rayConfig.log.loglevel = config.loglevel; v2rayConfig.log.loglevel = config.coreBasicItem.loglevel;
v2rayConfig.log.access = ""; v2rayConfig.log.access = "";
v2rayConfig.log.error = ""; v2rayConfig.log.error = "";
} }
} }
else else
{ {
if (config.logEnabled) if (config.coreBasicItem.logEnabled)
{ {
var dtNow = DateTime.Now; var dtNow = DateTime.Now;
v2rayConfig.log.loglevel = config.loglevel; v2rayConfig.log.loglevel = config.coreBasicItem.loglevel;
v2rayConfig.log.access = Utils.GetLogPath($"Vaccess_{dtNow.ToString("yyyy-MM-dd")}.txt"); v2rayConfig.log.access = Utils.GetLogPath($"Vaccess_{dtNow.ToString("yyyy-MM-dd")}.txt");
v2rayConfig.log.error = Utils.GetLogPath($"Verror_{dtNow.ToString("yyyy-MM-dd")}.txt"); v2rayConfig.log.error = Utils.GetLogPath($"Verror_{dtNow.ToString("yyyy-MM-dd")}.txt");
} }
else else
{ {
v2rayConfig.log.loglevel = config.loglevel; v2rayConfig.log.loglevel = config.coreBasicItem.loglevel;
v2rayConfig.log.access = ""; v2rayConfig.log.access = "";
v2rayConfig.log.error = ""; v2rayConfig.log.error = "";
} }
@ -348,8 +348,8 @@ namespace v2rayN.Handler
} }
//Mux //Mux
outbound.mux.enabled = config.muxEnabled; outbound.mux.enabled = config.coreBasicItem.muxEnabled;
outbound.mux.concurrency = config.muxEnabled ? 8 : -1; outbound.mux.concurrency = config.coreBasicItem.muxEnabled ? 8 : -1;
boundStreamSettings(node, "out", outbound.streamSettings); boundStreamSettings(node, "out", outbound.streamSettings);
@ -452,8 +452,8 @@ namespace v2rayN.Handler
usersItem.encryption = node.security; usersItem.encryption = node.security;
//Mux //Mux
outbound.mux.enabled = config.muxEnabled; outbound.mux.enabled = config.coreBasicItem.muxEnabled;
outbound.mux.concurrency = config.muxEnabled ? 8 : -1; outbound.mux.concurrency = config.coreBasicItem.muxEnabled ? 8 : -1;
boundStreamSettings(node, "out", outbound.streamSettings); boundStreamSettings(node, "out", outbound.streamSettings);
@ -548,15 +548,15 @@ namespace v2rayN.Handler
string host = node.requestHost.TrimEx(); string host = node.requestHost.TrimEx();
string sni = node.sni; string sni = node.sni;
string useragent = ""; string useragent = "";
if (!config.defUserAgent.IsNullOrEmpty()) if (!config.coreBasicItem.defUserAgent.IsNullOrEmpty())
{ {
try try
{ {
useragent = Global.userAgentTxt[config.defUserAgent]; useragent = Global.userAgentTxt[config.coreBasicItem.defUserAgent];
} }
catch (KeyNotFoundException) catch (KeyNotFoundException)
{ {
useragent = config.defUserAgent; useragent = config.coreBasicItem.defUserAgent;
} }
} }
@ -567,9 +567,9 @@ namespace v2rayN.Handler
TlsSettings tlsSettings = new TlsSettings TlsSettings tlsSettings = new TlsSettings
{ {
allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.defAllowInsecure.ToString().ToLower() : node.allowInsecure), allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure),
alpn = node.GetAlpn(), alpn = node.GetAlpn(),
fingerprint = node.fingerprint.IsNullOrEmpty() ? config.defFingerprint : node.fingerprint fingerprint = node.fingerprint.IsNullOrEmpty() ? config.coreBasicItem.defFingerprint : node.fingerprint
}; };
if (!string.IsNullOrWhiteSpace(sni)) if (!string.IsNullOrWhiteSpace(sni))
{ {
@ -589,9 +589,9 @@ namespace v2rayN.Handler
TlsSettings xtlsSettings = new TlsSettings TlsSettings xtlsSettings = new TlsSettings
{ {
allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.defAllowInsecure.ToString().ToLower() : node.allowInsecure), allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure),
alpn = node.GetAlpn(), alpn = node.GetAlpn(),
fingerprint = node.fingerprint.IsNullOrEmpty() ? config.defFingerprint : node.fingerprint fingerprint = node.fingerprint.IsNullOrEmpty() ? config.coreBasicItem.defFingerprint : node.fingerprint
}; };
if (!string.IsNullOrWhiteSpace(sni)) if (!string.IsNullOrWhiteSpace(sni))
{ {

View File

@ -8,34 +8,14 @@
{ {
#region property #region property
/// <summary>
/// 允许日志
/// </summary>
public bool logEnabled
{
get; set;
}
/// <summary>
/// 日志等级
/// </summary>
public string loglevel
{
get; set;
}
public string indexId public string indexId
{ {
get; set; get; set;
} }
/// <summary>
/// 允许Mux多路复用
/// </summary>
public bool muxEnabled
{
get; set;
}
/// <summary> /// <summary>
/// ///
@ -87,17 +67,7 @@
get; set; get; set;
} }
/// <summary>
/// 是否允许不安全连接
/// </summary>
public bool defAllowInsecure { get; set; }
public string defFingerprint { get; set; }
/// <summary>
/// 默认用户代理
/// </summary>
public string defUserAgent { get; set; }
/// <summary> /// <summary>
/// 域名解析策略 /// 域名解析策略
@ -144,6 +114,7 @@
#region other entities #region other entities
public CoreBasicItem coreBasicItem { get; set; }
public TunModeItem tunModeItem { get; set; } public TunModeItem tunModeItem { get; set; }
public KcpItem kcpItem { get; set; } public KcpItem kcpItem { get; set; }
public GrpcItem grpcItem { get; set; } public GrpcItem grpcItem { get; set; }

View File

@ -2,6 +2,37 @@
namespace v2rayN.Mode namespace v2rayN.Mode
{ {
public class CoreBasicItem
{
/// <summary>
/// 允许日志
/// </summary>
public bool logEnabled { get; set; }
/// <summary>
/// 日志等级
/// </summary>
public string loglevel { get; set; }
/// <summary>
/// 允许Mux多路复用
/// </summary>
public bool muxEnabled { get; set; }
/// <summary>
/// 是否允许不安全连接
/// </summary>
public bool defAllowInsecure { get; set; }
public string defFingerprint { get; set; }
/// <summary>
/// 默认用户代理
/// </summary>
public string defUserAgent { get; set; }
}
[Serializable] [Serializable]
public class InItem public class InItem
{ {

View File

@ -116,12 +116,12 @@ namespace v2rayN.ViewModels
newPort4LAN = inbound.newPort4LAN; newPort4LAN = inbound.newPort4LAN;
user = inbound.user; user = inbound.user;
pass = inbound.pass; pass = inbound.pass;
muxEnabled = _config.muxEnabled; muxEnabled = _config.coreBasicItem.muxEnabled;
logEnabled = _config.logEnabled; logEnabled = _config.coreBasicItem.logEnabled;
loglevel = _config.loglevel; loglevel = _config.coreBasicItem.loglevel;
defAllowInsecure = _config.defAllowInsecure; defAllowInsecure = _config.coreBasicItem.defAllowInsecure;
defFingerprint = _config.defFingerprint; defFingerprint = _config.coreBasicItem.defFingerprint;
defUserAgent = _config.defUserAgent; defUserAgent = _config.coreBasicItem.defUserAgent;
#endregion #endregion
#region Core DNS #region Core DNS
@ -287,12 +287,12 @@ namespace v2rayN.ViewModels
{ {
_config.inbound.RemoveAt(1); _config.inbound.RemoveAt(1);
} }
_config.logEnabled = logEnabled; _config.coreBasicItem.logEnabled = logEnabled;
_config.loglevel = loglevel; _config.coreBasicItem.loglevel = loglevel;
_config.muxEnabled = muxEnabled; _config.coreBasicItem.muxEnabled = muxEnabled;
_config.defAllowInsecure = defAllowInsecure; _config.coreBasicItem.defAllowInsecure = defAllowInsecure;
_config.defFingerprint = defFingerprint; _config.coreBasicItem.defFingerprint = defFingerprint;
_config.defUserAgent = defUserAgent; _config.coreBasicItem.defUserAgent = defUserAgent;
//DNS //DNS