public override void OnRun() { Dictionary <string, ConnectionInfo> servers; lock (Engine.Instance.Connections) servers = new Dictionary <string, ConnectionInfo>(Engine.Instance.Connections); int timeNow = UtilsCore.UnixTimeStamp(); int interval = Engine.Instance.Storage.GetInt("discover.interval"); foreach (ConnectionInfo infoServer in servers.Values) { if (m_cancelRequested) { return; } if (infoServer.NeedDiscover) { if (timeNow - infoServer.LastDiscover >= interval) { DiscoverIp(infoServer); } } } m_timeEvery = 60000; }
public string GetStatsString() { Dictionary <string, ConnectionInfo> servers; lock (Engine.Instance.Connections) servers = new Dictionary <string, ConnectionInfo>(Engine.Instance.Connections); int timeNow = UtilsCore.UnixTimeStamp(); int interval = Engine.Instance.Storage.GetInt("discover.interval"); int nTotal = 0; int nPending = 0; foreach (ConnectionInfo infoServer in servers.Values) { if (infoServer.NeedDiscover) { nTotal++; if (timeNow - infoServer.LastDiscover >= interval) { nPending++; } } } return(nPending + " pending / " + nTotal); }
public override string Refresh() { base.Refresh(); try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters["act"] = "manifest"; parameters["ts"] = Conversions.ToString(m_lastFetchTime); XmlDocument xmlDoc = Fetch(Messages.ManifestUpdate, parameters); lock (Storage) { if (Manifest != null) { Storage.DocumentElement.RemoveChild(Manifest); } Manifest = Storage.ImportNode(xmlDoc.DocumentElement, true); Storage.DocumentElement.AppendChild(Manifest); // Update with the local time Manifest.Attributes["time"].Value = UtilsCore.UnixTimeStamp().ToString(); m_lastFetchTime = UtilsCore.UnixTimeStamp(); } return(""); } catch (Exception e) { return(MessagesFormatter.Format(Messages.ManifestFailed, e.Message)); } }
public void PingResult(ConnectionInfo infoServer, Int64 result) { infoServer.PingTests++; infoServer.LastPingResult = UtilsCore.UnixTimeStamp(); if (result == -1) { infoServer.PingFailedConsecutive++; if (infoServer.PingFailedConsecutive >= 5) { infoServer.Ping = -1; } } else { infoServer.LastPingSuccess = infoServer.LastPingResult; infoServer.PingFailedConsecutive = 0; if (infoServer.Ping == -1) { infoServer.Ping = result; } else { infoServer.Ping = (infoServer.Ping + result) / 2; } } Engine.Instance.MarkServersListUpdated(); }
public PingerStats GetStats() { PingerStats stats = new PingerStats(); int timeNow = UtilsCore.UnixTimeStamp(); int iTotal = 0; List <ConnectionInfo> connections = GetConnectionsToPing(); foreach (ConnectionInfo infoConnection in connections) { int deltaValid = GetPingerDelayValid(infoConnection); if ((stats.OlderCheckDate == 0) || (stats.OlderCheckDate > infoConnection.LastPingResult)) { stats.OlderCheckDate = infoConnection.LastPingResult; } if ((stats.LatestCheckDate == 0) || (stats.LatestCheckDate < infoConnection.LastPingResult)) { stats.LatestCheckDate = infoConnection.LastPingResult; } iTotal++; if ((infoConnection.CanPing()) && (timeNow - infoConnection.LastPingResult > deltaValid)) { stats.Invalid++; } } stats.Valid = (stats.Invalid == 0); return(stats); }
public void DiscoverIp(ConnectionInfo connection) { IpAddress ip = connection.IpsEntry.FirstPreferIPv4; if (ip != null) { Json jDoc = DiscoverIpData(ip.Address, ""); if (jDoc != null) { // Node parsing if (jDoc.HasKey("country_code")) { string countryCode = Conversions.ToString(jDoc["country_code"].Value).Trim().ToLowerInvariant(); if (CountriesManager.IsCountryCode(countryCode)) { if (connection.CountryCode != countryCode) { connection.CountryCode = countryCode; Engine.Instance.MarkServersListUpdated(); Engine.Instance.MarkAreasListUpdated(); } } } if (jDoc.HasKey("city_name")) { string cityName = Conversions.ToString(jDoc["city_name"].Value).Trim(); if (cityName == "N/A") { cityName = ""; } if (cityName != "") { connection.Location = cityName; Engine.Instance.MarkServersListUpdated(); } } if ((jDoc.HasKey("latitude")) && (jDoc.HasKey("longitude"))) { double latitude = Conversions.ToDouble(jDoc["latitude"].Value); double longitude = Conversions.ToDouble(jDoc["longitude"].Value); connection.Latitude = latitude; connection.Longitude = longitude; Engine.Instance.MarkServersListUpdated(); } } } connection.LastDiscover = UtilsCore.UnixTimeStamp(); connection.Provider.OnChangeConnection(connection); }
public override bool GetNeedRefresh() { int minInterval = RefreshInterval; if (minInterval == -1) { minInterval = 60 * 60 * 24; } if (m_lastTryRefresh + minInterval > UtilsCore.UnixTimeStamp()) { return(false); } return(true); }
public override string OnRefresh() { base.OnRefresh(); // Engine.Instance.Logs.LogVerbose(MessagesFormatter.Format(Messages.ProviderRefreshStart, Title)); try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters["act"] = "manifest"; parameters["ts"] = Conversions.ToString(m_lastFetchTime); XmlDocument xmlDoc = Fetch(MessagesFormatter.Format(Messages.ProviderRefreshStart, Title), parameters); lock (Storage) { if (Manifest != null) { Storage.DocumentElement.RemoveChild(Manifest); } Manifest = Storage.ImportNode(xmlDoc.DocumentElement, true); Storage.DocumentElement.AppendChild(Manifest); // Update with the local time Manifest.Attributes["time"].Value = UtilsCore.UnixTimeStamp().ToString(); m_lastFetchTime = UtilsCore.UnixTimeStamp(); } Engine.Instance.Logs.LogVerbose(MessagesFormatter.Format(Messages.ProviderRefreshDone, Title)); string msg = GetFrontMessage(); if ((msg != "") && (m_frontMessages.Contains(msg) == false)) { Engine.Instance.OnFrontMessage(msg); m_frontMessages.Add(msg); } return(""); } catch (Exception e) { Engine.Instance.Logs.LogVerbose(MessagesFormatter.Format(Messages.ProviderRefreshFail, Title, e.Message)); return(MessagesFormatter.Format(Messages.ProviderRefreshFail, Title, e.Message)); } }
public override void OnRun() { Dictionary <string, ConnectionInfo> servers; for (;;) { m_checkNow = false; lock (Engine.Connections) servers = new Dictionary <string, ConnectionInfo>(Engine.Connections); int timeNow = UtilsCore.UnixTimeStamp(); int interval = Engine.Instance.Storage.GetInt("discover.interval"); foreach (ConnectionInfo infoServer in servers.Values) { if (CancelRequested) { return; } if (infoServer.NeedDiscover) { if (timeNow - infoServer.LastDiscover >= interval) { DiscoverIp(infoServer); } } } for (int i = 0; i < 600; i++) // Every minute { Sleep(100); if (CancelRequested) { return; } if (m_checkNow) { break; } } } }
public void Hit(long d, long u) { int ts = UtilsCore.UnixTimeStamp(); lock (this) { foreach (Chart c in ChartsList) { c.Hit(d, u, ts); } } if (UpdateEvent != null) { UpdateEvent(this, null); } }
public override bool GetNeedRefresh() { int minInterval = RefreshInterval; { // Temp until option migration minInterval = Engine.Instance.Storage.GetInt("advanced.manifest.refresh"); if (minInterval == 0) { return(false); } if (minInterval != -1) { minInterval *= 60; } } if ((Manifest != null) && (minInterval == -1)) // Pick server recommended { minInterval = Manifest.GetAttributeInt("next_update", -1); if (minInterval != -1) { minInterval *= 60; } } if (minInterval == -1) { minInterval = 60 * 60 * 24; } if (m_lastTryRefresh + minInterval > UtilsCore.UnixTimeStamp()) { return(false); } return(true); }
public override void OnRun() { if (GetCanRun() == false) { m_timeEvery = 1000; } else { Dictionary <string, ConnectionInfo> connections; // Note: If Pinger is not enabled, works like all ping results is 0. bool enabled = GetEnabled(); int timeNow = UtilsCore.UnixTimeStamp(); int jobsLimit = Engine.Instance.Storage.GetInt("pinger.jobs"); lock (Engine.Instance.Connections) connections = new Dictionary <string, ConnectionInfo>(Engine.Instance.Connections); bool startOne = false; foreach (ConnectionInfo connectionInfo in connections.Values) { if (GetCanRun() == false) { break; } int delaySuccess = GetPingerDelaySuccess(connectionInfo); int delayRetry = GetPingerDelayRetry(connectionInfo); int delay = delaySuccess; if (connectionInfo.PingFailedConsecutive > 0) { delay = delayRetry; } if (timeNow - connectionInfo.LastPingTest >= delay) { bool canPingServer = enabled; if (connectionInfo.CanPing() == false) { canPingServer = false; } if (canPingServer) { if (Jobs.Count < jobsLimit) { connectionInfo.LastPingTest = timeNow; PingerJob job = new PingerJob(); job.Server = connectionInfo; ThreadPool.QueueUserWorkItem(new WaitCallback(DoPing), job); startOne = true; } } else { if (connectionInfo.Ping != -1) { //connectionInfo.LastPingTest = timeNow; // <2.13.4 connectionInfo.LastPingTest = 0; connectionInfo.PingTests = 0; connectionInfo.PingFailedConsecutive = 0; connectionInfo.Ping = -1; connectionInfo.LastPingResult = connectionInfo.LastPingTest; connectionInfo.LastPingSuccess = connectionInfo.LastPingTest; Engine.Instance.MarkServersListUpdated(); } } } if (m_cancelRequested) { return; } } if (startOne) { m_timeEvery = 100; } else { m_timeEvery = 1000; } } }
public override string OnRefresh() { base.OnRefresh(); // Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("ProviderRefreshStart, Title)); try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters["act"] = "manifest"; parameters["ts"] = Conversions.ToString(m_lastFetchTime); XmlDocument xmlDoc = Fetch(LanguageManager.GetText("ProviderRefreshStart", Title), parameters); lock (Storage) { if (Manifest != null) { Storage.DocumentElement.RemoveChild(Manifest); } Manifest = Storage.ImportNode(xmlDoc.DocumentElement, true); Storage.DocumentElement.AppendChild(Manifest); // Update with the local time Manifest.Attributes["time"].Value = UtilsCore.UnixTimeStamp().ToString(); m_lastFetchTime = UtilsCore.UnixTimeStamp(); } Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("ProviderRefreshDone", Title)); // Show important messages foreach (XmlElement xmlMessage in Manifest.SelectNodes("messages/message")) { if ((xmlMessage.HasAttribute("from_time")) && (UtilsCore.UnixTimeStamp() < Conversions.ToInt64(xmlMessage.GetAttribute("from_time")))) { continue; } if ((xmlMessage.HasAttribute("to_time")) && (UtilsCore.UnixTimeStamp() > Conversions.ToInt64(xmlMessage.GetAttribute("to_time")))) { continue; } Json jMessage = new Json(); jMessage["text"].Value = xmlMessage.GetAttribute("text"); jMessage["url"].Value = xmlMessage.GetAttribute("url"); jMessage["link"].Value = xmlMessage.GetAttribute("link"); jMessage["html"].Value = xmlMessage.GetAttribute("html"); string text = jMessage["text"].Value as string; if (m_frontMessages.Contains(text) == false) { Json jCommand = new Json(); jCommand["command"].Value = "ui.frontmessage"; jCommand["message"].Value = jMessage; Engine.Instance.UiManager.Broadcast(jCommand); m_frontMessages.Add(text); } } return(""); } catch (Exception e) { Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("ProviderRefreshFail", Title, e.Message)); return(LanguageManager.GetText("ProviderRefreshFail", Title, e.Message)); } }