Ejemplo n.º 1
0
            private void UpdateIpv4RangeSet()
            {
                for (; ;)
                {
                    CatharsisConfig config;

                    lock (_lockObject)
                    {
                        config = _config;
                    }

                    var ipv4RangeSet = new HashSet <SearchRange <Ipv4> >();

                    // Ipv4
                    {
                        // path
                        foreach (string path in config.Ipv4Config.Paths)
                        {
                            try
                            {
                                using (var stream = new FileStream(path, FileMode.OpenOrCreate))
                                    using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
                                    {
                                        ipv4RangeSet.UnionWith(this.ParseIpv4Ranges(reader));
                                    }
                            }
                            catch (Exception e)
                            {
                                Log.Warning(e);
                            }
                        }

                        // Url
                        foreach (string url in config.Ipv4Config.Urls)
                        {
                            try
                            {
                                using (var stream = this.GetStream(url))
                                    using (var gzipStream = new GZipStream(stream, CompressionMode.Decompress))
                                        using (var reader = new StreamReader(gzipStream))
                                        {
                                            ipv4RangeSet.UnionWith(this.ParseIpv4Ranges(reader));
                                        }
                            }
                            catch (Exception e)
                            {
                                Log.Warning(e);
                            }
                        }
                    }

                    lock (_lockObject)
                    {
                        if (_config != config)
                        {
                            continue;
                        }

                        _ipv4RangeSet.Clear();
                        _ipv4RangeSet.UnionWith(ipv4RangeSet);

                        _ipv4ResultMap.Clear();

                        return;
                    }
                }
            }