/// <summary>
        /// Refreshes the managed whitelist.
        /// </summary>
        public void RefreshWhitelist()
        {
            this.logger.LogTrace("()");

            DateTimeOffset activePeerLimit = this.dateTimeProvider.GetTimeOffset().AddSeconds(-this.dnsPeerBlacklistThresholdInSeconds);

            var whitelist = this.peerAddressManager.Peers.Where(p => p.Value.LastConnectionHandshake > activePeerLimit).Select(p => p.Value);

            if (!this.fullNodeMode)
            {
                // Exclude the current external ip address from DNS as its not a full node.
                whitelist = whitelist.Where(p => !p.NetworkAddress.Endpoint.Match(this.externalEndpoint));
            }

            IMasterFile masterFile = new DnsSeedMasterFile();

            foreach (PeerAddress whitelistEntry in whitelist)
            {
                Domain domain = new Domain(this.dnsHostName);

                IPAddressResourceRecord resourceRecord = new IPAddressResourceRecord(domain, whitelistEntry.NetworkAddress.Endpoint.Address);
                masterFile.Add(resourceRecord);
            }

            this.dnsServer.SwapMasterfile(masterFile);

            this.logger.LogTrace("(-)");
        }
Esempio n. 2
0
        /// <summary>
        /// Refreshes the managed whitelist.
        /// </summary>
        public void RefreshWhitelist()
        {
            this.logger.LogTrace("()");

            this.dnsPeerBlacklistThresholdInSeconds = this.dnsSettings.DnsPeerBlacklistThresholdInSeconds;
            this.dnsHostName  = this.dnsSettings.DnsHostName;
            this.fullNodeMode = this.dnsSettings.DnsFullNode;

            DateTimeOffset activePeerLimit = this.dateTimeProvider.GetTimeOffset().AddSeconds(-this.dnsPeerBlacklistThresholdInSeconds);

            IEnumerable <PeerAddress> whitelist = this.peerAddressManager.Peers.Where(p => p.LastSeen > activePeerLimit);

            if (!this.fullNodeMode)
            {
                // Exclude the current external ip address from DNS as its not a full node.
                whitelist = whitelist.Where(p => !p.Endpoint.Match(this.externalEndpoint));
            }

            IMasterFile masterFile = new DnsSeedMasterFile();

            foreach (PeerAddress whitelistEntry in whitelist)
            {
                if (this.peerBanning.IsBanned(whitelistEntry.Endpoint))
                {
                    this.logger.LogDebug("{0}:{1} is banned, therefore removing from masterfile.", whitelistEntry.Endpoint.Address, whitelistEntry.Endpoint.Port);
                    continue;
                }

                var domain = new Domain(this.dnsHostName);

                // Is this an IPv4 embedded address? If it is, make sure an 'A' record is added to the DNS master file, rather than an 'AAAA' record.
                if (whitelistEntry.Endpoint.Address.IsIPv4MappedToIPv6)
                {
                    IPAddress ipv4Address    = whitelistEntry.Endpoint.Address.MapToIPv4();
                    var       resourceRecord = new IPAddressResourceRecord(domain, ipv4Address);
                    masterFile.Add(resourceRecord);
                }
                else
                {
                    var resourceRecord = new IPAddressResourceRecord(domain, whitelistEntry.Endpoint.Address);
                    masterFile.Add(resourceRecord);
                }
            }

            this.dnsServer.SwapMasterfile(masterFile);

            this.logger.LogTrace("(-)");
        }