From d099e44ff67a65069517bcd1dbecd2833cede1b7 Mon Sep 17 00:00:00 2001 From: ariansharifi <67752326+ariansharifi@users.noreply.github.com> Date: Mon, 5 Oct 2026 09:36:52 +0100 Subject: [PATCH] Fix subscription custom configs ignoring custom config socks port (#10296) * Fix subscription custom configs ignoring custom config socks port Full Xray/sing-box configs imported from a subscription no longer got the subscription's "Custom config socks port" (SubItem.PreSocksPort) after eff5845 and 9638b4c. 7.24.4 and earlier copied it onto every imported config, and the Clash, Hysteria2 and raw-file paths still do. Without it, GetPreSocksItem builds no pre-socks core for these profiles, so they cannot be used in TUN mode. Setting the port on the profile is not a workaround, because every subscription update re-creates the profiles. * Add regression test for subscription custom config socks port --- .../ConfigHandlerCustomSubscriptionTests.cs | 42 +++++++++++++++++++ v2rayN/ServiceLib/Handler/ConfigHandler.cs | 8 ++-- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs diff --git a/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs b/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs new file mode 100644 index 00000000..9a957ae0 --- /dev/null +++ b/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs @@ -0,0 +1,42 @@ +using ServiceLib.Tests.CoreConfig; + +namespace ServiceLib.Tests.Handler; + +public class ConfigHandlerCustomSubscriptionTests +{ + private const string FullXrayConfigs = """ + [ + {"remarks":"custom-1","inbounds":[{"tag":"socks","listen":"127.0.0.1","port":10808,"protocol":"socks","settings":{"auth":"noauth","udp":true}}],"outbounds":[{"tag":"proxy","protocol":"vless","settings":{"vnext":[{"address":"127.0.0.1","port":443,"users":[{"id":"00000000-0000-0000-0000-000000000001","encryption":"none"}]}]},"streamSettings":{"network":"tcp"}}],"routing":{"domainStrategy":"AsIs","rules":[]}}, + {"remarks":"custom-2","inbounds":[{"tag":"socks","listen":"127.0.0.1","port":10808,"protocol":"socks","settings":{"auth":"noauth","udp":true}}],"outbounds":[{"tag":"proxy","protocol":"vless","settings":{"vnext":[{"address":"127.0.0.1","port":443,"users":[{"id":"00000000-0000-0000-0000-000000000001","encryption":"none"}]}]},"streamSettings":{"network":"tcp"}}],"routing":{"domainStrategy":"AsIs","rules":[]}} + ] + """; + + [Test] + public async Task AddBatchServers_FullConfigsFromSubscription_InheritSubscriptionPreSocksPort() + { + var config = CoreConfigTestFactory.CreateConfig(); + CoreConfigTestFactory.BindAppManagerConfig(config); + SQLiteHelper.Instance.CreateTable(); + SQLiteHelper.Instance.CreateTable(); + + var subId = $"sub-{Guid.NewGuid():N}"; + await SQLiteHelper.Instance.ReplaceAsync(new SubItem + { + Id = subId, + Remarks = "sub", + Url = "http://127.0.0.1/sub", + PreSocksPort = 10808, + }); + + var count = await ConfigHandler.AddBatchServers(config, FullXrayConfigs, subId, true); + var profiles = await AppManager.Instance.ProfileItems(subId) ?? []; + + await count.Should().BeEqualTo(2); + await profiles.Should().HaveCount(2); + foreach (var profile in profiles) + { + await profile.ConfigType.Should().BeEqualTo(EConfigType.Custom); + await profile.PreSocksPort.Should().BeEqualTo(10808); + } + } +} diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index b09b7391..3bfa1f23 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1778,7 +1778,7 @@ public static class ConfigHandler } if (lstProfiles.Count > 0) { - var count = await AddBatchCustomServers(config, lstProfiles, subid, isSub); + var count = await AddBatchCustomServers(config, lstProfiles, subid, isSub, subItem); if (count > 0) { return count; @@ -1824,7 +1824,7 @@ public static class ConfigHandler if (lstProfiles?.Count > 0) { - var count = await AddBatchCustomServers(config, lstProfiles, subid, isSub); + var count = await AddBatchCustomServers(config, lstProfiles, subid, isSub, subItem); if (count > 0) { return count; @@ -1838,7 +1838,8 @@ public static class ConfigHandler Config config, List lstProfiles, string subid, - bool isSub) + bool isSub, + SubItem? subItem) { var count = 0; foreach (var it in lstProfiles) @@ -1848,6 +1849,7 @@ public static class ConfigHandler if (it.ConfigType == EConfigType.Custom) { + it.PreSocksPort = subItem?.PreSocksPort; if (await AddCustomServer(config, it, true) == 0) { count++;