public void Update(List <ConnectionStasticRecord> records) { var now = DateTime.Now; LastActivate = now; foreach (var r in records) { _allConnections.GetOrAdd(r.TcpRow, c => new ConnectionContext(c)).Update(r); } // Remove inactivated connections _allConnections.Values.Where(it => now.Subtract(it.LastActivate).TotalMinutes > 1) .Select(it => it.Connection).ToList().ForEach(c => _allConnections.TryRemove(c, out var _)); var validConnections = _allConnections.Values.Where(it => it.IsValidRTT()).ToList(); if (validConnections.Count == 0) { RTT = null; } else { var rttConn = validConnections.Max(); RTT = new ConnectionPing { Connection = rttConn.ConnectionID, Ping = rttConn.RTT }; Lost = validConnections.Select(it => it.Lost).Max(); } }
private void HandleNewSample(double rtt, DateTime sampleTime) { var now = sampleTime.EpochMillis(); _records[now] = rtt; var windowLeft = now - 5 * 1000; // window size = 5s // Remove records out of window _records.Keys.TakeWhile(it => it < windowLeft).ToList().ForEach(it => _records.Remove(it)); // Use the min value in that window as the current ping CurrentPing = new ConnectionPing() { Connection = Connection, Ping = _records.Values.Min(), SampleTime = sampleTime, }; OnPingSample?.Invoke(CurrentPing); }
private void PacketMonitorOnOnPingSample(ConnectionPing ping) { CurrentPing = ping; }
private void MonitorOnOnPingSample(ConnectionPing ping) { CurrentPing = _connections.Select(it => it.Value.CurrentPing).Max(); OnPingSample?.Invoke(CurrentPing); }