mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-14 10:05:51 +00:00
Compare commits
No commits in common. "7ddb46e74db7f733968925160a6334dd17260e79" and "661affd6a586a40239bbd45582068bdc09b8537b" have entirely different histories.
7ddb46e74d
...
661affd6a5
4 changed files with 50 additions and 72 deletions
|
|
@ -182,14 +182,13 @@ public class Global
|
||||||
@"https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/main/v2rayN/"
|
@"https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/main/v2rayN/"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly Dictionary<string, string> TcpHttpUserAgentTexts = new()
|
public static readonly Dictionary<string, string> UserAgentTexts = new()
|
||||||
{
|
{
|
||||||
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },
|
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },
|
||||||
{"firefox","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0" },
|
{"firefox","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0" },
|
||||||
{"safari","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" },
|
{"safari","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" },
|
||||||
{"edge","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70" },
|
{"edge","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70" },
|
||||||
{"none",""},
|
{"none",""}
|
||||||
{"golang",""}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public const string Hysteria2ProtocolShare = "hy2://";
|
public const string Hysteria2ProtocolShare = "hy2://";
|
||||||
|
|
@ -392,8 +391,9 @@ public class Global
|
||||||
[
|
[
|
||||||
"chrome",
|
"chrome",
|
||||||
"firefox",
|
"firefox",
|
||||||
|
"safari",
|
||||||
"edge",
|
"edge",
|
||||||
"golang"
|
"none"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static readonly List<string> XhttpMode =
|
public static readonly List<string> XhttpMode =
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ public class StreamSettings4Ray
|
||||||
|
|
||||||
public HysteriaSettings4Ray? hysteriaSettings { get; set; }
|
public HysteriaSettings4Ray? hysteriaSettings { get; set; }
|
||||||
|
|
||||||
public object? finalmask { get; set; }
|
public Finalmask4Ray? finalmask { get; set; }
|
||||||
|
|
||||||
public Sockopt4Ray? sockopt { get; set; }
|
public Sockopt4Ray? sockopt { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -421,8 +421,6 @@ public class HttpupgradeSettings4Ray
|
||||||
public string? path { get; set; }
|
public string? path { get; set; }
|
||||||
|
|
||||||
public string? host { get; set; }
|
public string? host { get; set; }
|
||||||
|
|
||||||
public Headers4Ray headers { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class XhttpSettings4Ray
|
public class XhttpSettings4Ray
|
||||||
|
|
@ -458,31 +456,33 @@ public class GrpcSettings4Ray
|
||||||
public int? health_check_timeout { get; set; }
|
public int? health_check_timeout { get; set; }
|
||||||
public bool? permit_without_stream { get; set; }
|
public bool? permit_without_stream { get; set; }
|
||||||
public int? initial_windows_size { get; set; }
|
public int? initial_windows_size { get; set; }
|
||||||
public string? user_agent { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HysteriaSettings4Ray
|
public class HysteriaSettings4Ray
|
||||||
{
|
{
|
||||||
public int version { get; set; }
|
public int version { get; set; }
|
||||||
public string? auth { get; set; }
|
public string? auth { get; set; }
|
||||||
|
public string? up { get; set; }
|
||||||
|
public string? down { get; set; }
|
||||||
|
public HysteriaUdpHop4Ray? udphop { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UdpHop4Ray
|
public class HysteriaUdpHop4Ray
|
||||||
{
|
{
|
||||||
public string? ports { get; set; }
|
public string? port { get; set; }
|
||||||
public string? interval { get; set; }
|
public string? interval { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Finalmask4Ray
|
public class Finalmask4Ray
|
||||||
{
|
{
|
||||||
|
public List<Mask4Ray>? tcp { get; set; }
|
||||||
public List<Mask4Ray>? udp { get; set; }
|
public List<Mask4Ray>? udp { get; set; }
|
||||||
public QuicParams4Ray? quicParams { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Mask4Ray
|
public class Mask4Ray
|
||||||
{
|
{
|
||||||
public string type { get; set; }
|
public string type { get; set; }
|
||||||
public MaskSettings4Ray? settings { get; set; }
|
public object? settings { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MaskSettings4Ray
|
public class MaskSettings4Ray
|
||||||
|
|
@ -491,14 +491,6 @@ public class MaskSettings4Ray
|
||||||
public string? domain { get; set; }
|
public string? domain { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QuicParams4Ray
|
|
||||||
{
|
|
||||||
public string? congestion { get; set; }
|
|
||||||
public string? brutalUp { get; set; }
|
|
||||||
public string? brutalDown { get; set; }
|
|
||||||
public UdpHop4Ray? udpHop { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AccountsItem4Ray
|
public class AccountsItem4Ray
|
||||||
{
|
{
|
||||||
public string user { get; set; }
|
public string user { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -224,14 +224,13 @@ public partial class CoreConfigSingboxService
|
||||||
password = protocolExtra.SalamanderPass.TrimEx(),
|
password = protocolExtra.SalamanderPass.TrimEx(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
int? upMbps = protocolExtra?.UpMbps is { } su and >= 0
|
|
||||||
|
outbound.up_mbps = protocolExtra?.UpMbps is { } su and >= 0
|
||||||
? su
|
? su
|
||||||
: _config.HysteriaItem.UpMbps;
|
: _config.HysteriaItem.UpMbps;
|
||||||
int? downMbps = protocolExtra?.DownMbps is { } sd and >= 0
|
outbound.down_mbps = protocolExtra?.DownMbps is { } sd and >= 0
|
||||||
? sd
|
? sd
|
||||||
: _config.HysteriaItem.UpMbps;
|
: _config.HysteriaItem.DownMbps;
|
||||||
outbound.up_mbps = upMbps > 0 ? upMbps : null;
|
|
||||||
outbound.down_mbps = downMbps > 0 ? downMbps : null;
|
|
||||||
var ports = protocolExtra?.Ports?.IsNullOrEmpty() == false ? protocolExtra.Ports : null;
|
var ports = protocolExtra?.Ports?.IsNullOrEmpty() == false ? protocolExtra.Ports : null;
|
||||||
if ((!ports.IsNullOrEmpty()) && (ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))
|
if ((!ports.IsNullOrEmpty()) && (ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))
|
||||||
{
|
{
|
||||||
|
|
@ -609,7 +608,7 @@ public partial class CoreConfigSingboxService
|
||||||
{
|
{
|
||||||
var node = nodesReverse[i];
|
var node = nodesReverse[i];
|
||||||
var currentTag = i == 0 ? baseTagName : $"chain-{baseTagName}-{i}-{node.Remarks}";
|
var currentTag = i == 0 ? baseTagName : $"chain-{baseTagName}-{i}-{node.Remarks}";
|
||||||
var dialerProxyTag = i != nodesReverse.Count - 1 ? $"chain-{baseTagName}-{i + 1}-{nodesReverse[i + 1].Remarks}" : null;
|
var dialerProxyTag = i != nodesReverse.Count - 1 ? $"chain-{baseTagName}-{i + 1}-{node.Remarks}" : null;
|
||||||
if (node.ConfigType.IsGroupType())
|
if (node.ConfigType.IsGroupType())
|
||||||
{
|
{
|
||||||
var childProfiles = new CoreConfigSingboxService(context with { Node = node, }).BuildGroupProxyOutbounds(currentTag);
|
var childProfiles = new CoreConfigSingboxService(context with { Node = node, }).BuildGroupProxyOutbounds(currentTag);
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,11 @@ public partial class CoreConfigV2rayService
|
||||||
var host = _node.RequestHost.TrimEx();
|
var host = _node.RequestHost.TrimEx();
|
||||||
var path = _node.Path.TrimEx();
|
var path = _node.Path.TrimEx();
|
||||||
var sni = _node.Sni.TrimEx();
|
var sni = _node.Sni.TrimEx();
|
||||||
var useragent = _config.CoreBasicItem.DefUserAgent ?? string.Empty;
|
var useragent = "";
|
||||||
|
if (!_config.CoreBasicItem.DefUserAgent.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
useragent = Global.UserAgentTexts.GetValueOrDefault(_config.CoreBasicItem.DefUserAgent, _config.CoreBasicItem.DefUserAgent);
|
||||||
|
}
|
||||||
|
|
||||||
//if tls
|
//if tls
|
||||||
if (_node.StreamSecurity == Global.StreamSecurity)
|
if (_node.StreamSecurity == Global.StreamSecurity)
|
||||||
|
|
@ -437,10 +441,10 @@ public partial class CoreConfigV2rayService
|
||||||
kcpSettings.congestion = _config.KcpItem.Congestion;
|
kcpSettings.congestion = _config.KcpItem.Congestion;
|
||||||
kcpSettings.readBufferSize = _config.KcpItem.ReadBufferSize;
|
kcpSettings.readBufferSize = _config.KcpItem.ReadBufferSize;
|
||||||
kcpSettings.writeBufferSize = _config.KcpItem.WriteBufferSize;
|
kcpSettings.writeBufferSize = _config.KcpItem.WriteBufferSize;
|
||||||
var kcpFinalmask = new Finalmask4Ray();
|
streamSettings.finalmask ??= new();
|
||||||
if (Global.KcpHeaderMaskMap.TryGetValue(_node.HeaderType, out var header))
|
if (Global.KcpHeaderMaskMap.TryGetValue(_node.HeaderType, out var header))
|
||||||
{
|
{
|
||||||
kcpFinalmask.udp =
|
streamSettings.finalmask.udp =
|
||||||
[
|
[
|
||||||
new Mask4Ray
|
new Mask4Ray
|
||||||
{
|
{
|
||||||
|
|
@ -449,24 +453,23 @@ public partial class CoreConfigV2rayService
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
kcpFinalmask.udp ??= [];
|
streamSettings.finalmask.udp ??= [];
|
||||||
if (path.IsNullOrEmpty())
|
if (path.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
kcpFinalmask.udp.Add(new Mask4Ray
|
streamSettings.finalmask.udp.Add(new Mask4Ray
|
||||||
{
|
{
|
||||||
type = "mkcp-original"
|
type = "mkcp-original"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
kcpFinalmask.udp.Add(new Mask4Ray
|
streamSettings.finalmask.udp.Add(new Mask4Ray
|
||||||
{
|
{
|
||||||
type = "mkcp-aes128gcm",
|
type = "mkcp-aes128gcm",
|
||||||
settings = new MaskSettings4Ray { password = path }
|
settings = new MaskSettings4Ray { password = path }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
streamSettings.kcpSettings = kcpSettings;
|
streamSettings.kcpSettings = kcpSettings;
|
||||||
streamSettings.finalmask = kcpFinalmask;
|
|
||||||
break;
|
break;
|
||||||
//ws
|
//ws
|
||||||
case nameof(ETransport.ws):
|
case nameof(ETransport.ws):
|
||||||
|
|
@ -492,17 +495,13 @@ public partial class CoreConfigV2rayService
|
||||||
case nameof(ETransport.httpupgrade):
|
case nameof(ETransport.httpupgrade):
|
||||||
HttpupgradeSettings4Ray httpupgradeSettings = new();
|
HttpupgradeSettings4Ray httpupgradeSettings = new();
|
||||||
|
|
||||||
if (host.IsNotEmpty())
|
|
||||||
{
|
|
||||||
httpupgradeSettings.host = host;
|
|
||||||
}
|
|
||||||
if (path.IsNotEmpty())
|
if (path.IsNotEmpty())
|
||||||
{
|
{
|
||||||
httpupgradeSettings.path = path;
|
httpupgradeSettings.path = path;
|
||||||
}
|
}
|
||||||
if (useragent.IsNotEmpty())
|
if (host.IsNotEmpty())
|
||||||
{
|
{
|
||||||
httpupgradeSettings.headers.UserAgent = useragent;
|
httpupgradeSettings.host = host;
|
||||||
}
|
}
|
||||||
streamSettings.httpupgradeSettings = httpupgradeSettings;
|
streamSettings.httpupgradeSettings = httpupgradeSettings;
|
||||||
|
|
||||||
|
|
@ -581,7 +580,6 @@ public partial class CoreConfigV2rayService
|
||||||
health_check_timeout = _config.GrpcItem.HealthCheckTimeout,
|
health_check_timeout = _config.GrpcItem.HealthCheckTimeout,
|
||||||
permit_without_stream = _config.GrpcItem.PermitWithoutStream,
|
permit_without_stream = _config.GrpcItem.PermitWithoutStream,
|
||||||
initial_windows_size = _config.GrpcItem.InitialWindowsSize,
|
initial_windows_size = _config.GrpcItem.InitialWindowsSize,
|
||||||
user_agent = useragent.NullIfEmpty(),
|
|
||||||
};
|
};
|
||||||
streamSettings.grpcSettings = grpcSettings;
|
streamSettings.grpcSettings = grpcSettings;
|
||||||
break;
|
break;
|
||||||
|
|
@ -600,32 +598,28 @@ public partial class CoreConfigV2rayService
|
||||||
: (_config.HysteriaItem.HopInterval >= 5
|
: (_config.HysteriaItem.HopInterval >= 5
|
||||||
? _config.HysteriaItem.HopInterval
|
? _config.HysteriaItem.HopInterval
|
||||||
: Global.Hysteria2DefaultHopInt).ToString();
|
: Global.Hysteria2DefaultHopInt).ToString();
|
||||||
var hy2Finalmask = new Finalmask4Ray();
|
HysteriaUdpHop4Ray? udpHop = null;
|
||||||
var quicParams = new QuicParams4Ray();
|
|
||||||
if (!ports.IsNullOrEmpty() &&
|
if (!ports.IsNullOrEmpty() &&
|
||||||
(ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))
|
(ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))
|
||||||
{
|
{
|
||||||
var udpHop = new UdpHop4Ray
|
udpHop = new HysteriaUdpHop4Ray
|
||||||
{
|
{
|
||||||
ports = ports.Replace(':', '-'),
|
port = ports.Replace(':', '-'),
|
||||||
interval = hopInterval,
|
interval = hopInterval,
|
||||||
};
|
};
|
||||||
quicParams.udpHop = udpHop;
|
|
||||||
}
|
}
|
||||||
if (upMbps > 0 || downMbps > 0)
|
streamSettings.hysteriaSettings = new()
|
||||||
{
|
{
|
||||||
quicParams.congestion = "brutal";
|
version = 2,
|
||||||
quicParams.brutalUp = upMbps > 0 ? $"{upMbps}mbps" : null;
|
auth = _node.Password,
|
||||||
quicParams.brutalDown = downMbps > 0 ? $"{downMbps}mbps" : null;
|
up = upMbps > 0 ? $"{upMbps}mbps" : null,
|
||||||
}
|
down = downMbps > 0 ? $"{downMbps}mbps" : null,
|
||||||
else
|
udphop = udpHop,
|
||||||
{
|
};
|
||||||
quicParams.congestion = "bbr";
|
|
||||||
}
|
|
||||||
hy2Finalmask.quicParams = quicParams;
|
|
||||||
if (!protocolExtra.SalamanderPass.IsNullOrEmpty())
|
if (!protocolExtra.SalamanderPass.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
hy2Finalmask.udp =
|
streamSettings.finalmask ??= new();
|
||||||
|
streamSettings.finalmask.udp =
|
||||||
[
|
[
|
||||||
new Mask4Ray
|
new Mask4Ray
|
||||||
{
|
{
|
||||||
|
|
@ -634,12 +628,6 @@ public partial class CoreConfigV2rayService
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
streamSettings.hysteriaSettings = new()
|
|
||||||
{
|
|
||||||
version = 2,
|
|
||||||
auth = _node.Password,
|
|
||||||
};
|
|
||||||
streamSettings.finalmask = hy2Finalmask;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -656,11 +644,10 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
//request Host
|
//request Host
|
||||||
var request = EmbedUtils.GetEmbedText(Global.V2raySampleHttpRequestFileName);
|
var request = EmbedUtils.GetEmbedText(Global.V2raySampleHttpRequestFileName);
|
||||||
var useragentValue = Global.TcpHttpUserAgentTexts.GetValueOrDefault(useragent, useragent);
|
|
||||||
var arrHost = host.Split(',');
|
var arrHost = host.Split(',');
|
||||||
var host2 = string.Join(",".AppendQuotes(), arrHost);
|
var host2 = string.Join(",".AppendQuotes(), arrHost);
|
||||||
request = request.Replace("$requestHost$", $"{host2.AppendQuotes()}");
|
request = request.Replace("$requestHost$", $"{host2.AppendQuotes()}");
|
||||||
request = request.Replace("$requestUserAgent$", $"{useragentValue.AppendQuotes()}");
|
request = request.Replace("$requestUserAgent$", $"{useragent.AppendQuotes()}");
|
||||||
//Path
|
//Path
|
||||||
var pathHttp = @"/";
|
var pathHttp = @"/";
|
||||||
if (path.IsNotEmpty())
|
if (path.IsNotEmpty())
|
||||||
|
|
@ -678,7 +665,7 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
if (!_node.Finalmask.IsNullOrEmpty())
|
if (!_node.Finalmask.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
streamSettings.finalmask = JsonUtils.ParseJson(_node.Finalmask);
|
streamSettings.finalmask = JsonUtils.Deserialize<Finalmask4Ray>(_node.Finalmask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -738,7 +725,7 @@ public partial class CoreConfigV2rayService
|
||||||
{
|
{
|
||||||
var node = nodesReverse[i];
|
var node = nodesReverse[i];
|
||||||
var currentTag = i == 0 ? baseTagName : $"chain-{baseTagName}-{i}-{node.Remarks}";
|
var currentTag = i == 0 ? baseTagName : $"chain-{baseTagName}-{i}-{node.Remarks}";
|
||||||
var dialerProxyTag = i != nodesReverse.Count - 1 ? $"chain-{baseTagName}-{i + 1}-{nodesReverse[i + 1].Remarks}" : null;
|
var dialerProxyTag = i != nodesReverse.Count - 1 ? $"chain-{baseTagName}-{i + 1}-{node.Remarks}" : null;
|
||||||
if (node.ConfigType.IsGroupType())
|
if (node.ConfigType.IsGroupType())
|
||||||
{
|
{
|
||||||
var childProfiles = new CoreConfigV2rayService(context with { Node = node, }).BuildGroupProxyOutbounds(currentTag);
|
var childProfiles = new CoreConfigV2rayService(context with { Node = node, }).BuildGroupProxyOutbounds(currentTag);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue