From b11e68cfd8b8914da3fb2b49943a3ecfaa6a642f Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:20:12 +0800 Subject: [PATCH] Remove StatisticsV2rayService Remove ProtosLib project --- v2rayN/ProtosLib/ProtosLib.csproj | 20 --- v2rayN/ProtosLib/Statistics.proto | 53 ------- v2rayN/ProtosLib/Tests.cs | 13 -- .../ServiceLib/Handler/StatisticsHandler.cs | 4 - v2rayN/ServiceLib/ServiceLib.csproj | 1 - .../Statistics/StatisticsV2rayService.cs | 135 ------------------ v2rayN/v2rayN.sln | 6 - 7 files changed, 232 deletions(-) delete mode 100644 v2rayN/ProtosLib/ProtosLib.csproj delete mode 100644 v2rayN/ProtosLib/Statistics.proto delete mode 100644 v2rayN/ProtosLib/Tests.cs delete mode 100644 v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs diff --git a/v2rayN/ProtosLib/ProtosLib.csproj b/v2rayN/ProtosLib/ProtosLib.csproj deleted file mode 100644 index 0b22dfb8..00000000 --- a/v2rayN/ProtosLib/ProtosLib.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - net8.0 - enable - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - diff --git a/v2rayN/ProtosLib/Statistics.proto b/v2rayN/ProtosLib/Statistics.proto deleted file mode 100644 index db96ac02..00000000 --- a/v2rayN/ProtosLib/Statistics.proto +++ /dev/null @@ -1,53 +0,0 @@ -syntax = "proto3"; - -package v2ray.core.app.stats.command; -option csharp_namespace = "ProtosLib.Statistics"; - -message GetStatsRequest { - // Name of the stat counter. - string name = 1; - // Whether or not to reset the counter to fetching its value. - bool reset = 2; -} - -message Stat { - string name = 1; - int64 value = 2; -} - -message GetStatsResponse { - Stat stat = 1; -} - -message QueryStatsRequest { - string pattern = 1; - bool reset = 2; -} - -message QueryStatsResponse { - repeated Stat stat = 1; -} - -message SysStatsRequest { -} - -message SysStatsResponse { - uint32 NumGoroutine = 1; - uint32 NumGC = 2; - uint64 Alloc = 3; - uint64 TotalAlloc = 4; - uint64 Sys = 5; - uint64 Mallocs = 6; - uint64 Frees = 7; - uint64 LiveObjects = 8; - uint64 PauseTotalNs = 9; - uint32 Uptime = 10; -} - -service StatsService { - rpc GetStats(GetStatsRequest) returns (GetStatsResponse) {} - rpc QueryStats(QueryStatsRequest) returns (QueryStatsResponse) {} - rpc GetSysStats(SysStatsRequest) returns (SysStatsResponse) {} -} - -message Config {} diff --git a/v2rayN/ProtosLib/Tests.cs b/v2rayN/ProtosLib/Tests.cs deleted file mode 100644 index e1eb85b1..00000000 --- a/v2rayN/ProtosLib/Tests.cs +++ /dev/null @@ -1,13 +0,0 @@ -using ProtosLib.Statistics; - -namespace ProtosLib -{ - public class Tests - { - private StatsService.StatsServiceClient client_; - - public Tests() - { - } - } -} \ No newline at end of file diff --git a/v2rayN/ServiceLib/Handler/StatisticsHandler.cs b/v2rayN/ServiceLib/Handler/StatisticsHandler.cs index e9060cc3..1c307d11 100644 --- a/v2rayN/ServiceLib/Handler/StatisticsHandler.cs +++ b/v2rayN/ServiceLib/Handler/StatisticsHandler.cs @@ -10,9 +10,7 @@ private List _lstServerStat; private Action? _updateFunc; - //private StatisticsV2rayService? _statisticsV2Ray; private StatisticsXrayService? _statisticsXray; - private StatisticsSingboxService? _statisticsSingbox; public List ServerStat => _lstServerStat; @@ -28,7 +26,6 @@ await InitData(); - //_statisticsV2Ray = new StatisticsV2rayService(config, UpdateServerStatHandler); _statisticsXray = new StatisticsXrayService(config, UpdateServerStatHandler); _statisticsSingbox = new StatisticsSingboxService(config, UpdateServerStatHandler); } @@ -37,7 +34,6 @@ { try { - //_statisticsV2Ray?.Close(); _statisticsXray?.Close(); _statisticsSingbox?.Close(); } diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj index 52c068df..8a8fb5c6 100644 --- a/v2rayN/ServiceLib/ServiceLib.csproj +++ b/v2rayN/ServiceLib/ServiceLib.csproj @@ -49,7 +49,6 @@ - diff --git a/v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs b/v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs deleted file mode 100644 index 66419576..00000000 --- a/v2rayN/ServiceLib/Services/Statistics/StatisticsV2rayService.cs +++ /dev/null @@ -1,135 +0,0 @@ -using Grpc.Core; -using Grpc.Net.Client; -using ProtosLib.Statistics; - -namespace ServiceLib.Services.Statistics -{ - public class StatisticsV2rayService - { - private Models.Config _config; - private GrpcChannel? _channel; - private StatsService.StatsServiceClient? _client; - private bool _exitFlag; - private Action? _updateFunc; - - public StatisticsV2rayService(Models.Config config, Action updateFunc) - { - _config = config; - _updateFunc = updateFunc; - _exitFlag = false; - - GrpcInit(); - - Task.Run(Run); - } - - private void GrpcInit() - { - if (_channel is null) - { - try - { - _channel = GrpcChannel.ForAddress($"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}"); - _client = new StatsService.StatsServiceClient(_channel); - } - catch (Exception ex) - { - Logging.SaveLog(ex.Message, ex); - } - } - } - - public void Close() - { - _exitFlag = true; - } - - private async void Run() - { - while (!_exitFlag) - { - await Task.Delay(1000); - try - { - if (!_config.IsRunningCore(ECoreType.Xray)) - { - continue; - } - if (_channel?.State == ConnectivityState.Ready) - { - QueryStatsResponse? res = null; - try - { - if (_client != null) - res = await _client.QueryStatsAsync(new QueryStatsRequest() { Pattern = "", Reset = true }); - } - catch - { - } - - if (res != null) - { - ParseOutput(res.Stat, out ServerSpeedItem server); - _updateFunc?.Invoke(server); - } - } - if (_channel != null) - await _channel.ConnectAsync(); - } - catch - { - } - } - } - - private void ParseOutput(Google.Protobuf.Collections.RepeatedField source, out ServerSpeedItem server) - { - server = new(); - long aggregateProxyUp = 0; - long aggregateProxyDown = 0; - try - { - foreach (Stat stat in source) - { - string name = stat.Name; - long value = stat.Value / 1024; //KByte - string[] nStr = name.Split(">>>".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); - string type = ""; - - name = name.Trim(); - - name = nStr[1]; - type = nStr[3]; - - if (name.StartsWith(Global.ProxyTag)) - { - if (type == "uplink") - { - aggregateProxyUp += value; - } - else if (type == "downlink") - { - aggregateProxyDown += value; - } - } - else if (name == Global.DirectTag) - { - if (type == "uplink") - { - server.DirectUp = value; - } - else if (type == "downlink") - { - server.DirectDown = value; - } - } - } - server.ProxyUp = aggregateProxyUp; - server.ProxyDown = aggregateProxyDown; - } - catch - { - } - } - } -} \ No newline at end of file diff --git a/v2rayN/v2rayN.sln b/v2rayN/v2rayN.sln index f898d47e..ea0fd985 100644 --- a/v2rayN/v2rayN.sln +++ b/v2rayN/v2rayN.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.3.32811.315 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "v2rayN", "v2rayN\v2rayN.csproj", "{6DE127CA-1763-4236-B297-D2EF9CB2EC9B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProtosLib", "ProtosLib\ProtosLib.csproj", "{C5F24BB0-9CC1-44DD-82FF-D545F081819B}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PacLib", "PacLib\PacLib.csproj", "{EE4E6CD8-8353-446B-8F29-A841A02AE5EC}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceLib", "ServiceLib\ServiceLib.csproj", "{1B6456C4-FFAA-4298-80F6-7B689A6E9243}" @@ -25,10 +23,6 @@ Global {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Release|Any CPU.Build.0 = Release|Any CPU - {C5F24BB0-9CC1-44DD-82FF-D545F081819B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C5F24BB0-9CC1-44DD-82FF-D545F081819B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C5F24BB0-9CC1-44DD-82FF-D545F081819B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C5F24BB0-9CC1-44DD-82FF-D545F081819B}.Release|Any CPU.Build.0 = Release|Any CPU {EE4E6CD8-8353-446B-8F29-A841A02AE5EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EE4E6CD8-8353-446B-8F29-A841A02AE5EC}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE4E6CD8-8353-446B-8F29-A841A02AE5EC}.Release|Any CPU.ActiveCfg = Release|Any CPU