1
0
anycmd 4 жил өмнө
parent
commit
fd6ad10b74

+ 0 - 6
src/AppModels/AppRoot.partials.KernelOutputKeywordViewModels.cs

@@ -37,12 +37,6 @@ namespace NTMiner {
                                 _dicByKernelOutputId[item.KernelOutputId].Add(vm);
                             }
                         }
-                        // TODO:给事件处理程序引入执行顺序改变,引入几个典型的顺序后可以避免很多为了顺序而构建的事件类型
-                        if (NTMinerContext.Instance.CurrentMineContext != null) {
-                            if (KernelOutputVms.TryGetKernelOutputVm(NTMinerContext.Instance.CurrentMineContext.KernelOutput.GetId(), out KernelOutputViewModel kernelOutputVm)) {
-                                kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputKeywords));
-                            }
-                        }
                     });
                 BuildEventPath<UserKernelOutputKeywordAddedEvent>("添加了内核输出过滤器后刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                     path: message => {

+ 5 - 0
src/AppViews0/Views/Ucs/KernelOutputKeywords.xaml.cs

@@ -26,6 +26,11 @@ namespace NTMiner.Views.Ucs {
             this.Vm = new KernelOutputKeywordsViewModel();
             this.DataContext = this.Vm;
             InitializeComponent();
+            this.OnLoaded(window => {
+                window.BuildEventPath<KernelOutputKeywordLoadedEvent>("刷新Vm内存", LogEnum.None, this.GetType(), PathPriority.BelowNormal, message => {
+                    this.Vm.KernelOutputVm?.OnPropertyChanged(nameof(KernelOutputViewModel.KernelOutputKeywords));
+                });
+            });
             VirtualRoot.Execute(new LoadKernelOutputKeywordCommand());
         }
 

+ 5 - 0
src/AppViews0/Views/Ucs/KernelOutputPage.xaml.cs

@@ -25,6 +25,11 @@ namespace NTMiner.Views.Ucs {
             this.Vm = new KernelOutputPageViewModel();
             this.DataContext = this.Vm;
             InitializeComponent();
+            this.OnLoaded(window => {
+                window.BuildEventPath<KernelOutputKeywordLoadedEvent>("刷新Vm内存", LogEnum.None, this.GetType(), PathPriority.BelowNormal, message => {
+                    this.Vm.CurrentKernelOutputVm?.OnPropertyChanged(nameof(KernelOutputViewModel.KernelOutputKeywords));
+                });
+            });
             if (selectedKernelOutputVm != null) {
                 Vm.CurrentKernelOutputVm = selectedKernelOutputVm;
             }

+ 10 - 0
src/NTMiner.Controllers/IRemoteIpController.cs

@@ -0,0 +1,10 @@
+using NTMiner.ServerNode;
+
+namespace NTMiner.Controllers {
+    public interface IRemoteIpController {
+        /// <summary>
+        /// 需签名
+        /// </summary>
+        TopNRemoteIpsResponse TopNRemoteIps(DataRequest<int> request);
+    }
+}

+ 1 - 0
src/NTMiner.Controllers/NTMiner.Controllers.csproj

@@ -47,6 +47,7 @@
     <Compile Include="IMinerClientController.cs" />
     <Compile Include="IMqCountController.cs" />
     <Compile Include="INTMinerFileController.cs" />
+    <Compile Include="IRemoteIpController.cs" />
     <Compile Include="IReportBinaryController.cs" />
     <Compile Include="IServerMessageBinaryController`1.cs" />
     <Compile Include="IUserAppSettingController.cs" />

+ 3 - 0
src/NTMinerDataSchemas/NTMinerDataSchemas.csproj

@@ -93,6 +93,7 @@
     <Compile Include="ServerNode\IClientTestId.cs" />
     <Compile Include="ServerNode\IMqReceivedCount.cs" />
     <Compile Include="ServerNode\IMqSendCount.cs" />
+    <Compile Include="ServerNode\IRemoteIpEntry.cs" />
     <Compile Include="ServerNode\MqCountData.cs" />
     <Compile Include="ServerNode\MqReceivedCountData.cs" />
     <Compile Include="ServerNode\MqSendCountData.cs" />
@@ -106,7 +107,9 @@
     <Compile Include="ServerNode\IVarServerState.cs" />
     <Compile Include="ServerNode\IVarWsServerNode.cs" />
     <Compile Include="ServerNode\IWebApiServerState.cs" />
+    <Compile Include="ServerNode\RemoteIpEntryDto.cs" />
     <Compile Include="ServerNode\ServerAddress.cs" />
+    <Compile Include="ServerNode\TopNRemoteIpsResponse.cs" />
     <Compile Include="ServerNode\WebApiServerState.cs" />
     <Compile Include="ServerNode\WsStatus.cs" />
     <Compile Include="Core\OperationResultDto.cs" />

+ 11 - 0
src/NTMinerDataSchemas/ServerNode/IRemoteIpEntry.cs

@@ -0,0 +1,11 @@
+using System;
+
+namespace NTMiner.ServerNode {
+    public interface IRemoteIpEntry {
+        // IPAddress类型不支持序列化
+        string RemoteIp { get; }
+        int ActionTimes { get; }
+        DateTime LastActionOn { get; }
+        long ActionSpeed { get; }
+    }
+}

+ 15 - 0
src/NTMinerDataSchemas/ServerNode/RemoteIpEntryDto.cs

@@ -0,0 +1,15 @@
+using System;
+
+namespace NTMiner.ServerNode {
+    public class RemoteIpEntryDto : IRemoteIpEntry {
+        public RemoteIpEntryDto() { }
+
+        public string RemoteIp { get; set; }
+
+        public int ActionTimes { get; set; }
+
+        public DateTime LastActionOn { get; set; }
+
+        public long ActionSpeed { get; set; }
+    }
+}

+ 22 - 0
src/NTMinerDataSchemas/ServerNode/TopNRemoteIpsResponse.cs

@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+
+namespace NTMiner.ServerNode {
+    public class TopNRemoteIpsResponse : ResponseBase {
+        public TopNRemoteIpsResponse() {
+            this.Data = new List<RemoteIpEntryDto>();
+        }
+
+        public static TopNRemoteIpsResponse Ok(List<RemoteIpEntryDto> data, int total) {
+            return new TopNRemoteIpsResponse() {
+                StateCode = 200,
+                ReasonPhrase = "Ok",
+                Description = "成功",
+                Data = data,
+                Total = total
+            };
+        }
+
+        public List<RemoteIpEntryDto> Data { get; set; }
+        public int Total { get; set; }
+    }
+}

+ 3 - 3
src/NTMinerServer/ServerRoot.cs

@@ -12,10 +12,10 @@ namespace NTMiner {
         internal static void SetClientTestId(IClientTestId clientTestId) {
             _clientTestId = clientTestId;
         }
-        public static readonly IRemoteIpSet _remoteEndPointSet = new RemoteIpSet();
-        public static IRemoteIpSet RemoteEndPointSet {
+        public static readonly IRemoteIpSet _remoteIpSet = new RemoteIpSet();
+        public static IRemoteIpSet RemoteIpSet {
             get {
-                return _remoteEndPointSet;
+                return _remoteIpSet;
             }
         }
 

+ 3 - 7
src/ServerCommon/IpSet/IRemoteIpSet.cs

@@ -1,10 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace NTMiner.IpSet {
+namespace NTMiner.IpSet {
     public interface IRemoteIpSet {
+        int Count { get; }
+        RemoteIpEntry[] GetTopNRemoteIpEntries(int n);
     }
 }

+ 11 - 0
src/ServerCommon/IpSet/Impl/RemoteIpSet.cs

@@ -44,5 +44,16 @@ namespace NTMiner.IpSet.Impl {
                 }
             });
         }
+
+        public int Count {
+            get { return _dicByIp.Count; }
+        }
+
+        public RemoteIpEntry[] GetTopNRemoteIpEntries(int n) {
+            if (n <= 0) {
+                return new RemoteIpEntry[0];
+            }
+            return _dicByIp.Values.OrderByDescending(a => a.ActionTimes).Take(n).ToArray();
+        }
     }
 }

+ 33 - 2
src/ServerCommon/IpSet/RemoteIpEntry.cs

@@ -1,19 +1,41 @@
-using System;
+using NTMiner.ServerNode;
+using System;
 using System.Collections.Generic;
 using System.Net;
 
 namespace NTMiner.IpSet {
-    public class RemoteIpEntry {
+    public class RemoteIpEntry : IRemoteIpEntry {
         public RemoteIpEntry(IPAddress remoteIp) {
             this.RemoteIp = remoteIp;
             this.DateTimes = new Queue<DateTime>();
         }
 
         public IPAddress RemoteIp { get; private set; }
+        string IRemoteIpEntry.RemoteIp {
+            get { return this.RemoteIp.ToString(); }
+        }
         public int ActionTimes { get; private set; }
         public DateTime LastActionOn { get; private set; }
         public Queue<DateTime> DateTimes { get; private set; }
 
+        public long ActionSpeed {
+            get {
+                var data = DateTimes.ToArray();
+                if (data.Length < 2) {
+                    return 0;
+                }
+                double seconds = (LastActionOn - data[0]).TotalSeconds;
+                if (seconds == 0) {
+                    return long.MaxValue;
+                }
+                var speed = (long)(data.Length / seconds);
+                if (speed < 0) {
+                    return long.MaxValue;
+                }
+                return speed;
+            }
+        }
+
         public void IncActionTimes() {
             this.LastActionOn = DateTime.Now;
             this.ActionTimes++;
@@ -22,5 +44,14 @@ namespace NTMiner.IpSet {
                 this.DateTimes.Dequeue();
             }
         }
+
+        public RemoteIpEntryDto ToDto() {
+            return new RemoteIpEntryDto {
+                ActionSpeed = this.ActionSpeed,
+                ActionTimes = this.ActionTimes,
+                LastActionOn = this.LastActionOn,
+                RemoteIp = ((IRemoteIpEntry)this).RemoteIp
+            };
+        }
     }
 }

+ 1 - 1
src/UnitTests/IPTests.cs

@@ -1,5 +1,4 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using NTMiner;
 using NTMiner.Core.MinerClient;
 using System;
 using System.Net;
@@ -49,6 +48,7 @@ namespace NTMiner {
         public void IPAddressHashCodeTest() {
             IPAddress iPAddress1 = IPAddress.Parse("111.222.222.111");
             IPAddress iPAddress2 = IPAddress.Parse("111.222.222.111");
+            Console.WriteLine(iPAddress1.ToString());
             Assert.AreEqual(iPAddress1.GetHashCode(), iPAddress2.GetHashCode());
         }
     }

+ 17 - 0
src/WebApiServer/Controllers/RemoteIpController.cs

@@ -0,0 +1,17 @@
+using NTMiner.ServerNode;
+using System.Linq;
+using System.Web.Http;
+
+namespace NTMiner.Controllers {
+    public class RemoteIpController : ApiControllerBase, IRemoteIpController {
+        [Role.Admin]
+        [HttpPost]
+        public TopNRemoteIpsResponse TopNRemoteIps([FromBody] DataRequest<int> request) {
+            if (request == null || request.Data <= 0) {
+                return ResponseBase.InvalidInput<TopNRemoteIpsResponse>("参数错误");
+            }
+            var data = ServerRoot.RemoteIpSet.GetTopNRemoteIpEntries(request.Data).Select(a => a.ToDto()).ToList();
+            return TopNRemoteIpsResponse.Ok(data, ServerRoot.RemoteIpSet.Count);
+        }
+    }
+}

+ 1 - 0
src/WebApiServer/WebApiServer.csproj

@@ -104,6 +104,7 @@
     <Compile Include="Controllers\GpuNameController.cs" />
     <Compile Include="Controllers\MqCountController.cs" />
     <Compile Include="Controllers\NTMinerFileController.cs" />
+    <Compile Include="Controllers\RemoteIpController.cs" />
     <Compile Include="Controllers\ReportBinaryController.cs" />
     <Compile Include="Controllers\ServerMessageBinaryController.cs" />
     <Compile Include="Core\IGpuNameSet.cs" />