Skip to content

Commit 4562d4c

Browse files
committed
Add ECH config support to profile and UI
Introduces EchConfigList and EchForceQuery fields to ProfileItem and V2rayConfig models, updates related handlers and services to process these fields, and extends the AddServerWindow UI to allow user input for ECH configuration. Also adds localization entries for the new fields and updates extension methods for string handling.
1 parent bc36cf8 commit 4562d4c

22 files changed

Lines changed: 170 additions & 22 deletions

v2rayN/ServiceLib/Common/Extension.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ public static class Extension
66
{
77
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? value)
88
{
9-
return string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value);
9+
return string.IsNullOrWhiteSpace(value) || string.IsNullOrEmpty(value);
1010
}
1111

12-
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value)
12+
public static bool IsNotEmpty([NotNullWhen(false)] this string? value)
1313
{
14-
return string.IsNullOrWhiteSpace(value);
14+
return !string.IsNullOrWhiteSpace(value);
1515
}
1616

17-
public static bool IsNotEmpty([NotNullWhen(false)] this string? value)
17+
public static string? NullIfEmpty(this string? value)
1818
{
19-
return !string.IsNullOrEmpty(value);
19+
return string.IsNullOrWhiteSpace(value) ? null : value;
2020
}
2121

2222
public static bool BeginWithAny(this string s, IEnumerable<char> chars)

v2rayN/ServiceLib/Global.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,5 +626,12 @@ public class Global
626626
""
627627
];
628628

629+
public static readonly List<string> EchForceQuerys =
630+
[
631+
"none",
632+
"half",
633+
"full",
634+
];
635+
629636
#endregion const
630637
}

v2rayN/ServiceLib/Handler/ConfigHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ public static async Task<int> AddServer(Config config, ProfileItem profileItem)
253253
item.Extra = profileItem.Extra;
254254
item.MuxEnabled = profileItem.MuxEnabled;
255255
item.Cert = profileItem.Cert;
256+
item.EchConfigList = profileItem.EchConfigList;
257+
item.EchForceQuery = profileItem.EchForceQuery;
256258
}
257259

258260
var ret = item.ConfigType switch

v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ protected static int ToUriQuery(ProfileItem item, string? securityDef, ref Dicti
7070
}
7171
ToUriQueryAllowInsecure(item, ref dicQuery);
7272
}
73+
if (item.EchConfigList.IsNotEmpty())
74+
{
75+
dicQuery.Add("ech", Utils.UrlEncode(item.EchConfigList));
76+
}
7377

7478
dicQuery.Add("type", item.Network.IsNotEmpty() ? item.Network : nameof(ETransport.tcp));
7579

@@ -209,6 +213,7 @@ protected static int ResolveUriQuery(NameValueCollection query, ref ProfileItem
209213
item.ShortId = GetQueryDecoded(query, "sid");
210214
item.SpiderX = GetQueryDecoded(query, "spx");
211215
item.Mldsa65Verify = GetQueryDecoded(query, "pqv");
216+
item.EchConfigList = GetQueryDecoded(query, "ech");
212217

213218
if (_allowInsecureArray.Any(k => GetQueryDecoded(query, k) == "1"))
214219
{

v2rayN/ServiceLib/Models/ProfileItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,6 @@ public bool IsValid()
161161
public string Extra { get; set; }
162162
public bool? MuxEnabled { get; set; }
163163
public string Cert { get; set; }
164+
public string EchConfigList { get; set; }
165+
public string EchForceQuery { get; set; }
164166
}

v2rayN/ServiceLib/Models/V2rayConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ public class TlsSettings4Ray
356356
public string? mldsa65Verify { get; set; }
357357
public List<CertificateSettings4Ray>? certificates { get; set; }
358358
public bool? disableSystemRoot { get; set; }
359+
public string? echConfigList { get; set; }
360+
public string? echForceQuery { get; set; }
359361
}
360362

361363
public class CertificateSettings4Ray

v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,4 +1641,10 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
16411641
<data name="menuServerList2" xml:space="preserve">
16421642
<value>Configuration Item 2, Select and add from self-built</value>
16431643
</data>
1644+
<data name="TbEchConfigList" xml:space="preserve">
1645+
<value>EchConfigList</value>
1646+
</data>
1647+
<data name="TbEchForceQuery" xml:space="preserve">
1648+
<value>EchForceQuery</value>
1649+
</data>
16441650
</root>

v2rayN/ServiceLib/Resx/ResUI.fr.resx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,4 +1638,10 @@ Si un certificat auto-signé est utilisé ou si le système contient une CA non
16381638
<data name="menuServerList2" xml:space="preserve">
16391639
<value>Élément de config 2 : choisir et ajouter depuis self-hosted</value>
16401640
</data>
1641-
</root>
1641+
<data name="TbEchConfigList" xml:space="preserve">
1642+
<value>EchConfigList</value>
1643+
</data>
1644+
<data name="TbEchForceQuery" xml:space="preserve">
1645+
<value>EchForceQuery</value>
1646+
</data>
1647+
</root>

v2rayN/ServiceLib/Resx/ResUI.hu.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,4 +1641,10 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
16411641
<data name="menuServerList2" xml:space="preserve">
16421642
<value>Configuration Item 2, Select and add from self-built</value>
16431643
</data>
1644+
<data name="TbEchConfigList" xml:space="preserve">
1645+
<value>EchConfigList</value>
1646+
</data>
1647+
<data name="TbEchForceQuery" xml:space="preserve">
1648+
<value>EchForceQuery</value>
1649+
</data>
16441650
</root>

0 commit comments

Comments
 (0)