From 3d4f202cd7a99ae46af9877629759371ec42b62a Mon Sep 17 00:00:00 2001 From: DHR60 <192860629+DHR60@users.noreply.github.com> Date: Fri, 12 Jun 2026 01:47:59 +0000 Subject: [PATCH] Metrics listen directly (#9533) --- .../Models/CoreConfigs/V2rayConfig.cs | 2 +- v2rayN/ServiceLib/Sample/SampleClientConfig | 10 +----- .../CoreConfig/V2ray/V2rayStatisticService.cs | 32 ++----------------- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs index 2363aece..ffe9060b 100644 --- a/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs @@ -20,7 +20,7 @@ public class Stats4Ray public class Metrics4Ray { - public string tag { get; set; } + public string listen { get; set; } } public class Policy4Ray diff --git a/v2rayN/ServiceLib/Sample/SampleClientConfig b/v2rayN/ServiceLib/Sample/SampleClientConfig index b4ebf491..bff51980 100644 --- a/v2rayN/ServiceLib/Sample/SampleClientConfig +++ b/v2rayN/ServiceLib/Sample/SampleClientConfig @@ -17,14 +17,6 @@ ], "routing": { "domainStrategy": "IPIfNonMatch", - "rules": [ - { - "inboundTag": [ - "api" - ], - "outboundTag": "api", - "type": "field" - } - ] + "rules": [] } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayStatisticService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayStatisticService.cs index 0e51c9fe..8fd91b6a 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayStatisticService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayStatisticService.cs @@ -6,45 +6,19 @@ public partial class CoreConfigV2rayService { if (_config.GuiItem.EnableStatistics || _config.GuiItem.DisplayRealTimeSpeed) { - const string tag = nameof(EInboundProtocol.api); - Metrics4Ray apiObj = new(); + Metrics4Ray metricsObj = new(); Policy4Ray policyObj = new(); SystemPolicy4Ray policySystemSetting = new(); _coreConfig.stats = new Stats4Ray(); - apiObj.tag = tag; - _coreConfig.metrics = apiObj; + metricsObj.listen = $"{Global.Loopback}:{AppManager.Instance.StatePort}"; + _coreConfig.metrics = metricsObj; policySystemSetting.statsOutboundDownlink = true; policySystemSetting.statsOutboundUplink = true; policyObj.system = policySystemSetting; _coreConfig.policy = policyObj; - - if (!_coreConfig.inbounds.Exists(item => item.tag == tag)) - { - Inbounds4Ray apiInbound = new(); - Inboundsettings4Ray apiInboundSettings = new(); - apiInbound.tag = tag; - apiInbound.listen = Global.Loopback; - apiInbound.port = AppManager.Instance.StatePort; - apiInbound.protocol = Global.InboundAPIProtocol; - apiInboundSettings.address = Global.Loopback; - apiInbound.settings = apiInboundSettings; - _coreConfig.inbounds.Add(apiInbound); - } - - if (!_coreConfig.routing.rules.Exists(item => item.outboundTag == tag)) - { - RulesItem4Ray apiRoutingRule = new() - { - inboundTag = new List { tag }, - outboundTag = tag, - type = "field" - }; - - _coreConfig.routing.rules.Add(apiRoutingRule); - } } } }