public string UpdateManifest() { try { Engine.Instance.Log(Engine.LogType.Verbose, Messages.ManifestUpdate); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters["act"] = "manifest"; XmlDocument xmlDoc = AirExchange.Fetch(Messages.ManifestUpdate, parameters); lock (Manifest) { if (Manifest == null) { Manifest = (new XmlDocument()).DocumentElement; } Manifest = Manifest.OwnerDocument.ImportNode(xmlDoc.DocumentElement, true); //Manifest = xmlDoc.DocumentElement; // Update with the local time Manifest.Attributes["time"].Value = Utils.UnixTimeStamp().ToString(); } Engine.Instance.PostManifestUpdate(); Engine.Instance.Log(Engine.LogType.Verbose, Messages.ManifestDone); return(""); } catch (Exception e) { return(Messages.Format(Messages.ManifestFailed, e.Message)); } }
public static XmlDocument Fetch(string title, Dictionary <string, string> parameters) { parameters["login"] = Engine.Instance.Storage.Get("login"); parameters["password"] = Engine.Instance.Storage.Get("password"); parameters["system"] = Platform.Instance.GetSystemCode(); parameters["version"] = Constants.VersionInt.ToString(CultureInfo.InvariantCulture); List <string> hosts = new List <string>(); if (Engine.Instance.Storage.Manifest != null) { XmlNodeList nodesHosts = Engine.Instance.Storage.Manifest.SelectNodes("//hosts/host"); foreach (XmlNode nodeHost in nodesHosts) { hosts.Add(nodeHost.Attributes["address"].Value); } } // Debugging /* * hosts.Clear(); * hosts.Add("invalidhostname.airvpn.org"); * hosts.Add("54.93.175.114"); */ string firstError = ""; int hostN = 0; foreach (string host in hosts) { hostN++; if (Utils.IsIP(host) == false) { // If locked network are enabled, skip the hostname and try only by IP. // To avoid DNS issue (generally, to avoid losing time). if (Engine.Instance.NetworkLockManager.IsDnsResolutionAvailable(host) == false) { continue; } } try { RouteScope routeScope = new RouteScope(host); XmlDocument xmlDoc = AirExchange.FetchHost(host, parameters); routeScope.End(); if (xmlDoc == null) { throw new Exception("No answer."); } if (xmlDoc.DocumentElement.Attributes["error"] != null) { throw new Exception(xmlDoc.DocumentElement.Attributes["error"].Value); } return(xmlDoc); } catch (Exception e) { string info = e.Message; string proxyMode = Engine.Instance.Storage.Get("proxy.mode").ToLowerInvariant(); string proxyAuth = Engine.Instance.Storage.Get("proxy.auth").ToLowerInvariant(); if (proxyMode != "none") { info += ", with '" + proxyMode + "' proxy and '" + proxyAuth + "' auth"; } Engine.Instance.Log(Engine.LogType.Verbose, Messages.Format(Messages.ExchangeTryFailed, title, hostN.ToString(), info)); if (firstError == "") { firstError = e.Message; } } } throw new Exception(firstError); }