Exemple #1
0
    public async Task InitializeAsync(CancellationToken cancel = default)
    {
        using (BenchmarkLogger.Measure())
        {
            using (await IndexLock.LockAsync(cancel).ConfigureAwait(false))
                using (await MatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
                    using (await ImmatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false))
                    {
                        await EnsureBackwardsCompatibilityAsync().ConfigureAwait(false);

                        if (Network == Network.RegTest)
                        {
                            MatureIndexFileManager.DeleteMe();             // RegTest is not a global ledger, better to delete it.
                            ImmatureIndexFileManager.DeleteMe();
                        }
                        cancel.ThrowIfCancellationRequested();

                        if (!MatureIndexFileManager.Exists())
                        {
                            await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToLine() }, CancellationToken.None).ConfigureAwait(false);
                        }
                        cancel.ThrowIfCancellationRequested();

                        await InitializeFiltersAsync(cancel).ConfigureAwait(false);
                    }
        }
    }
        public override DocIdSet GetDocIdSet(Lucene.Net.Index.IndexReader reader)
        {
            var geoHashValues = FieldCache_Fields.DEFAULT.GetStrings(reader, _geoHashField);

            int docBase = NextDocBase;

            NextDocBase += reader.MaxDoc();

            return(new GeoHashFilteredDocIdSet(StartingFilter.GetDocIdSet(reader), geoHashValues, DistanceLookupCache, _lat, _lng, docBase, Distance, Distances));
        }
        public override int GetHashCode()
        {
            int h = Distance.GetHashCode();

            h ^= StartingFilter.GetHashCode();
            h ^= _lat.GetHashCode();
            h ^= _lng.GetHashCode();
            h ^= _geoHashField.GetHashCode();

            return(h);
        }
Exemple #4
0
        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            double[] latIndex = FieldCache_Fields.DEFAULT.GetDoubles(reader, _latField);
            double[] lngIndex = FieldCache_Fields.DEFAULT.GetDoubles(reader, _lngField);

            int docBase = NextDocBase;

            NextDocBase += reader.MaxDoc();

            return(new LatLongFilteredDocIdSet(StartingFilter.GetDocIdSet(reader), latIndex, lngIndex, DistanceLookupCache, _lat, _lng, Distance, docBase, Distances));
        }
Exemple #5
0
        public async Task InitializeAsync(string workFolderPath, Network network, HashChain hashChain)
        {
            WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
            Network        = Guard.NotNull(nameof(network), network);
            HashChain      = Guard.NotNull(nameof(hashChain), hashChain);
            var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");

            MatureIndexFileManager = new IoManager(indexFilePath, digestRandomIndex: -1);
            var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");

            ImmatureIndexFileManager = new IoManager(immatureIndexFilePath, digestRandomIndex: -1);

            StartingFilter = StartingFilters.GetStartingFilter(Network);
            StartingHeight = StartingFilters.GetStartingHeight(Network);

            ImmatureFilters = new List <FilterModel>(150);

            IndexLock = new AsyncLock();

            using (await IndexLock.LockAsync())
            {
                using (await MatureIndexFileManager.Mutex.LockAsync())
                    using (await ImmatureIndexFileManager.Mutex.LockAsync())
                    {
                        IoHelpers.EnsureDirectoryExists(WorkFolderPath);

                        await TryEnsureBackwardsCompatibilityAsync();

                        if (Network == Network.RegTest)
                        {
                            MatureIndexFileManager.DeleteMe();                     // RegTest is not a global ledger, better to delete it.
                            ImmatureIndexFileManager.DeleteMe();
                        }

                        if (!MatureIndexFileManager.Exists())
                        {
                            await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToHeightlessLine() });
                        }

                        await InitializeFiltersAsync();
                    }
            }
        }
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is GeoHashDistanceFilter))
            {
                return(false);
            }

            var other = (GeoHashDistanceFilter)o;

            if (!StartingFilter.Equals(other.StartingFilter) || Distance != other.Distance || _lat != other._lat || _lng != other._lng || _geoHashField.Equals(other._geoHashField))
            {
                return(false);
            }

            return(true);
        }
        public async Task InitializeAsync()
        {
            using (BenchmarkLogger.Measure())
            {
                var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");
                MatureIndexFileManager = new DigestableSafeMutexIoManager(indexFilePath, digestRandomIndex: -1);
                var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");
                ImmatureIndexFileManager = new DigestableSafeMutexIoManager(immatureIndexFilePath, digestRandomIndex: -1);

                StartingFilter = StartingFilters.GetStartingFilter(Network);
                StartingHeight = StartingFilter.Header.Height;

                ImmatureFilters = new List <FilterModel>(150);

                IndexLock = new AsyncLock();

                using (await IndexLock.LockAsync().ConfigureAwait(false))
                    using (await MatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
                        using (await ImmatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
                        {
                            IoHelpers.EnsureDirectoryExists(WorkFolderPath);

                            await EnsureBackwardsCompatibilityAsync().ConfigureAwait(false);

                            if (Network == Network.RegTest)
                            {
                                MatureIndexFileManager.DeleteMe();                 // RegTest is not a global ledger, better to delete it.
                                ImmatureIndexFileManager.DeleteMe();
                            }

                            if (!MatureIndexFileManager.Exists())
                            {
                                await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToLine() }).ConfigureAwait(false);
                            }

                            await InitializeFiltersAsync().ConfigureAwait(false);
                        }
            }
        }
        public async Task InitializeAsync(string workFolderPath, Network network, SmartHeaderChain hashChain)
        {
            using (BenchmarkLogger.Measure())
            {
                WorkFolderPath   = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
                Network          = Guard.NotNull(nameof(network), network);
                SmartHeaderChain = Guard.NotNull(nameof(hashChain), hashChain);
                var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");
                MatureIndexFileManager = new DigestableSafeMutexIoManager(indexFilePath, digestRandomIndex: -1);
                var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");
                ImmatureIndexFileManager = new DigestableSafeMutexIoManager(immatureIndexFilePath, digestRandomIndex: -1);

                StartingFilter = StartingFilters.GetStartingFilter(Network);
                StartingHeight = StartingFilter.Header.Height;

                ImmatureFilters = new List <FilterModel>(150);

                IndexLock = new AsyncLock();

                using (await IndexLock.LockAsync().ConfigureAwait(false))
                    using (await MatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
                        using (await ImmatureIndexFileManager.Mutex.LockAsync().ConfigureAwait(false))
                        {
                            IoHelpers.EnsureDirectoryExists(WorkFolderPath);

                            await EnsureBackwardsCompatibilityAsync().ConfigureAwait(false);

                            if (Network == NBitcoin.Altcoins.Litecoin.Instance.Regtest)
                            {
                                MatureIndexFileManager.DeleteMe();                 // RegTest is not a global ledger, better to delete it.
                                ImmatureIndexFileManager.DeleteMe();
                            }

                            if (!MatureIndexFileManager.Exists())
                            {
                                await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToLine() }).ConfigureAwait(false);
                            }

                            await InitializeFiltersAsync().ConfigureAwait(false);
                        }
            }
        }