Skip to content

Commit

Permalink
Remove Routing Basic function
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Nov 20, 2024
1 parent 9cbe2b9 commit a2413fd
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 394 deletions.
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Handler/AppHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ from t33 in t3b.DefaultIfEmpty()

public async Task<List<RoutingItem>?> RoutingItems()
{
return await SQLiteHelper.Instance.TableAsync<RoutingItem>().Where(it => it.Locked == false).OrderBy(t => t.Sort).ToListAsync();
return await SQLiteHelper.Instance.TableAsync<RoutingItem>().OrderBy(t => t.Sort).ToListAsync();
}

public async Task<RoutingItem?> GetRoutingItem(string id)
{
return await SQLiteHelper.Instance.TableAsync<RoutingItem>().FirstOrDefaultAsync(it => it.Locked == false && it.Id == id);
return await SQLiteHelper.Instance.TableAsync<RoutingItem>().FirstOrDefaultAsync(it => it.Id == id);
}

public async Task<List<DNSItem>?> DNSItems()
Expand Down
22 changes: 12 additions & 10 deletions v2rayN/ServiceLib/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ public class ConfigHandler
config.Inbound[0].Protocol = EInboundProtocol.socks.ToString();
}
}
config.RoutingBasicItem ??= new()
{
EnableRoutingAdvanced = true
};

config.RoutingBasicItem ??= new();

if (Utils.IsNullOrEmpty(config.RoutingBasicItem.DomainStrategy))
{
Expand Down Expand Up @@ -1600,7 +1598,7 @@ public static async Task<RoutingItem> GetDefaultRouting(Config config)
var item = await AppHandler.Instance.GetRoutingItem(config.RoutingBasicItem.RoutingIndexId);
if (item is null)
{
var item2 = await SQLiteHelper.Instance.TableAsync<RoutingItem>().FirstOrDefaultAsync(t => t.Locked == false);
var item2 = await SQLiteHelper.Instance.TableAsync<RoutingItem>().FirstOrDefaultAsync();
await SetDefaultRouting(config, item2);
return item2;
}
Expand Down Expand Up @@ -1674,6 +1672,15 @@ public static async Task<int> InitBuiltinRouting(Config config, bool blImportAdv
{
var ver = "V3-";
var items = await AppHandler.Instance.RoutingItems();

//TODO Temporary code to be removed later
var lockItem = items?.FirstOrDefault(t => t.Locked == true);
if (lockItem != null)
{
await ConfigHandler.RemoveRoutingItem(lockItem);
items = await AppHandler.Instance.RoutingItems();
}

if (!blImportAdvancedRules && items.Where(t => t.Remarks.StartsWith(ver)).ToList().Count > 0)
{
return 0;
Expand Down Expand Up @@ -1714,11 +1721,6 @@ public static async Task<int> InitBuiltinRouting(Config config, bool blImportAdv
return 0;
}

public static async Task<RoutingItem?> GetLockedRoutingItem(Config config)
{
return await SQLiteHelper.Instance.TableAsync<RoutingItem>().FirstOrDefaultAsync(it => it.Locked == true);
}

public static async Task RemoveRoutingItem(RoutingItem routingItem)
{
await SQLiteHelper.Instance.DeleteAsync(routingItem);
Expand Down
1 change: 0 additions & 1 deletion v2rayN/ServiceLib/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public class RoutingBasicItem
public string DomainStrategy4Singbox { get; set; }
public string DomainMatcher { get; set; }
public string RoutingIndexId { get; set; }
public bool EnableRoutingAdvanced { get; set; }
}

[Serializable]
Expand Down
18 changes: 0 additions & 18 deletions v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
Original file line number Diff line number Diff line change
Expand Up @@ -847,12 +847,6 @@
<data name="menuRoutingAdvancedSetDefault" xml:space="preserve">
<value>Set as active rule</value>
</data>
<data name="menuRoutingBasic" xml:space="preserve">
<value>عملکرد پایه</value>
</data>
<data name="menuRoutingBasicImportRules" xml:space="preserve">
<value>واردات قوانین اساسی</value>
</data>
<data name="TbdomainMatcher" xml:space="preserve">
<value>تطبیق دامنه</value>
</data>
Expand Down
6 changes: 0 additions & 6 deletions v2rayN/ServiceLib/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,6 @@
<data name="menuRoutingAdvancedSetDefault" xml:space="preserve">
<value>Set as active rule(Enter)</value>
</data>
<data name="menuRoutingBasic" xml:space="preserve">
<value>Basic Function</value>
</data>
<data name="menuRoutingBasicImportRules" xml:space="preserve">
<value>Import Basic Rules</value>
</data>
<data name="TbdomainMatcher" xml:space="preserve">
<value>Domain Matcher</value>
</data>
Expand Down
6 changes: 0 additions & 6 deletions v2rayN/ServiceLib/Resx/ResUI.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,6 @@
<data name="menuRoutingAdvancedSetDefault" xml:space="preserve">
<value>Установить как активное правило</value>
</data>
<data name="menuRoutingBasic" xml:space="preserve">
<value>Основные функции</value>
</data>
<data name="menuRoutingBasicImportRules" xml:space="preserve">
<value>Импорт основных правил</value>
</data>
<data name="TbdomainMatcher" xml:space="preserve">
<value>Сопоставитель доменов</value>
</data>
Expand Down
6 changes: 0 additions & 6 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,6 @@
<data name="menuRoutingAdvancedSetDefault" xml:space="preserve">
<value>设为活动规则 (Enter)</value>
</data>
<data name="menuRoutingBasic" xml:space="preserve">
<value>基础功能</value>
</data>
<data name="menuRoutingBasicImportRules" xml:space="preserve">
<value>一键导入基础规则</value>
</data>
<data name="TbdomainMatcher" xml:space="preserve">
<value>域名匹配算法</value>
</data>
Expand Down
6 changes: 0 additions & 6 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,6 @@
<data name="menuRoutingAdvancedSetDefault" xml:space="preserve">
<value>設為活動規則 (Enter)</value>
</data>
<data name="menuRoutingBasic" xml:space="preserve">
<value>基礎功能</value>
</data>
<data name="menuRoutingBasicImportRules" xml:space="preserve">
<value>一鍵匯入基礎規則</value>
</data>
<data name="TbdomainMatcher" xml:space="preserve">
<value>域名匹配演算法</value>
</data>
Expand Down
60 changes: 20 additions & 40 deletions v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>

await GenLog(singboxConfig);
//GenDns(new(), singboxConfig);
singboxConfig.inbounds.Clear();
singboxConfig.inbounds.Clear();
singboxConfig.outbounds.RemoveAt(0);

var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
Expand Down Expand Up @@ -499,13 +499,10 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
inbound.sniff_override_destination = _config.Inbound[0].RouteOnly ? false : _config.Inbound[0].SniffingEnabled;
inbound.domain_strategy = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainStrategy4Singbox) ? null : _config.RoutingBasicItem.DomainStrategy4Singbox;

if (_config.RoutingBasicItem.EnableRoutingAdvanced)
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (Utils.IsNotEmpty(routing.DomainStrategy4Singbox))
{
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (Utils.IsNotEmpty(routing.DomainStrategy4Singbox))
{
inbound.domain_strategy = routing.DomainStrategy4Singbox;
}
inbound.domain_strategy = routing.DomainStrategy4Singbox;
}

//http
Expand Down Expand Up @@ -958,28 +955,13 @@ private async Task<int> GenRouting(SingboxConfig singboxConfig)
});
}

if (_config.RoutingBasicItem.EnableRoutingAdvanced)
{
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (routing != null)
{
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet);
foreach (var item in rules ?? [])
{
if (item.Enabled)
{
await GenRoutingUserRule(item, singboxConfig.route.rules);
}
}
}
}
else
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (routing != null)
{
var lockedItem = await ConfigHandler.GetLockedRoutingItem(_config);
if (lockedItem != null)
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet);
foreach (var item in rules ?? [])
{
var rules = JsonUtils.Deserialize<List<RulesItem>>(lockedItem.RuleSet);
foreach (var item in rules ?? [])
if (item.Enabled)
{
await GenRoutingUserRule(item, singboxConfig.route.rules);
}
Expand Down Expand Up @@ -1334,20 +1316,18 @@ static void AddRuleSets(List<string> ruleSets, List<string>? rule_set)

//load custom ruleset file
List<Ruleset4Sbox> customRulesets = [];
if (_config.RoutingBasicItem.EnableRoutingAdvanced)

var routing = await ConfigHandler.GetDefaultRouting(_config);
if (Utils.IsNotEmpty(routing.CustomRulesetPath4Singbox))
{
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (Utils.IsNotEmpty(routing.CustomRulesetPath4Singbox))
{
var result = Utils.LoadResource(routing.CustomRulesetPath4Singbox);
if (Utils.IsNotEmpty(result))
{
customRulesets = (JsonUtils.Deserialize<List<Ruleset4Sbox>>(result) ?? [])
.Where(t => t.tag != null)
.Where(t => t.type != null)
.Where(t => t.format != null)
.ToList();
}
var result = Utils.LoadResource(routing.CustomRulesetPath4Singbox);
if (Utils.IsNotEmpty(result))
{
customRulesets = (JsonUtils.Deserialize<List<Ruleset4Sbox>>(result) ?? [])
.Where(t => t.tag != null)
.Where(t => t.type != null)
.Where(t => t.format != null)
.ToList();
}
}

Expand Down
34 changes: 9 additions & 25 deletions v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
}

await GenLog(v2rayConfig);
v2rayConfig.inbounds.Clear();
v2rayConfig.inbounds.Clear();
v2rayConfig.outbounds.Clear();
v2rayConfig.routing.rules.Clear();

Expand Down Expand Up @@ -316,7 +316,7 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
{
continue;
}

//inbound
Inbounds4Ray inbound = new()
{
Expand Down Expand Up @@ -467,33 +467,17 @@ private async Task<int> GenRouting(V2rayConfig v2rayConfig)
v2rayConfig.routing.domainStrategy = _config.RoutingBasicItem.DomainStrategy;
v2rayConfig.routing.domainMatcher = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainMatcher) ? null : _config.RoutingBasicItem.DomainMatcher;

if (_config.RoutingBasicItem.EnableRoutingAdvanced)
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (routing != null)
{
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (routing != null)
if (Utils.IsNotEmpty(routing.DomainStrategy))
{
if (Utils.IsNotEmpty(routing.DomainStrategy))
{
v2rayConfig.routing.domainStrategy = routing.DomainStrategy;
}
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet);
foreach (var item in rules)
{
if (item.Enabled)
{
var item2 = JsonUtils.Deserialize<RulesItem4Ray>(JsonUtils.Serialize(item));
await GenRoutingUserRule(item2, v2rayConfig);
}
}
v2rayConfig.routing.domainStrategy = routing.DomainStrategy;
}
}
else
{
var lockedItem = await ConfigHandler.GetLockedRoutingItem(_config);
if (lockedItem != null)
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet);
foreach (var item in rules)
{
var rules = JsonUtils.Deserialize<List<RulesItem>>(lockedItem.RuleSet);
foreach (var item in rules)
if (item.Enabled)
{
var item2 = JsonUtils.Deserialize<RulesItem4Ray>(JsonUtils.Serialize(item));
await GenRoutingUserRule(item2, v2rayConfig);
Expand Down
Loading

0 comments on commit a2413fd

Please sign in to comment.