public static void Main(string[] args) { CommandLineParser cmd = CommandLineParser.Parse(args); Log.CreateInstance(true); Serializer.Initialize(); if (!GetApiKeyArg(cmd)) { Environment.Exit(1); } string url = cmd["url"].Value; string returnString, errorString; if (!NetHelper.HttpRequest(url, out returnString, out errorString)) { Log.Instance.Write(Log_Severity.Error, errorString); return; } GetPeerListResponseData peerList = JsonConvert.DeserializeObject <GetPeerListResponseData>(returnString); NodeMapDataStore nmap = new NodeMapDataStore(); if (File.Exists("NodeMap.xml")) { Log.Instance.Write("Loading node map data from file"); nmap = new ObjectSerializer().Deserialize <NodeMapDataStore>(XDocument.Load("NodeMap.xml")); } bool ne; RunList(peerList.GrayList, ref nmap, out ne); RunList(peerList.WhiteList, ref nmap, out ne); new ObjectSerializer().Serialize(nmap, "NodeMap.xml"); Log.Instance.Write($"DONE! {nmap.NodeMap.Count} nodes in map"); }
private static void RunList(List <GetPeerListResponseDataItem> list, ref NodeMapDataStore nmap, out bool newEntryCreated) { newEntryCreated = false; foreach (var p in list) { string ip = GetIpFromInteger(p.IP); string hash = ip.GetHashString(); if (nmap.NodeMap.ContainsKey(hash) || p.IP == 0) { Log.Instance.Write($"Skipping IP: {ip}"); continue; } DateTime now = DateTime.UtcNow; DateTime ls = TimeStampToDateTime(p.LastSeen); int age = (now - ls).Days; if (age > 14) { Log.Instance.Write($"Skipping Stale IP: {ip}. {age} days old"); continue; } ulong ts = RoundTimestamp(p.LastSeen); SubmitParams e = new SubmitParams(); e.Address = ip; e.LastAccessTime = ts; e.Version = "0.0.0.0"; if (nmap.Add(e, out newEntryCreated)) { Log.Instance.Write($"Added IP: {ip}"); } } }