Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WhitelistManager"/> class.
        /// </summary>
        /// <param name="dateTimeProvider">The provider for datetime.</param>
        /// <param name="loggerFactory">The factory to create the logger.</param>
        /// <param name="peerAddressManager">The manager implementation for peer addresses.</param>
        /// <param name="dnsServer">The DNS server.</param>
        /// <param name="connectionSettings">The connection settings.</param>
        public WhitelistManager(IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, IPeerAddressManager peerAddressManager, IDnsServer dnsServer, ConnectionManagerSettings connectionSettings, DnsSettings dnsSettings)
        {
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            Guard.NotNull(dnsServer, nameof(dnsServer));
            Guard.NotNull(dnsSettings, nameof(dnsSettings));
            Guard.NotNull(connectionSettings, nameof(connectionSettings));

            this.dateTimeProvider = dateTimeProvider;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
            this.peerAddressManager = peerAddressManager;
            this.dnsServer = dnsServer;
            this.dnsSettings = dnsSettings;                      
            this.externalEndpoint = connectionSettings.ExternalEndpoint;            
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DnsFeature"/> class.
        /// </summary>
        /// <param name="dnsServer">The DNS server.</param>
        /// <param name="whitelistManager">The whitelist manager.</param>
        /// <param name="loggerFactory">The factory to create the logger.</param>
        /// <param name="nodeLifetime">The node lifetime object used for graceful shutdown.</param>
        /// <param name="nodeSettings">The node settings object containing node configuration.</param>
        /// <param name="dataFolders">The data folders of the system.</param>
        /// <param name="asyncLoopFactory">The asynchronous loop factory.</param>
        public DnsFeature(IDnsServer dnsServer, IWhitelistManager whitelistManager, ILoggerFactory loggerFactory, INodeLifetime nodeLifetime, DnsSettings dnsSettings, NodeSettings nodeSettings, DataFolder dataFolders, IAsyncLoopFactory asyncLoopFactory)
        {
            Guard.NotNull(dnsServer, nameof(dnsServer));
            Guard.NotNull(whitelistManager, nameof(whitelistManager));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(nodeSettings, nameof(nodeSettings));
            Guard.NotNull(dataFolders, nameof(dataFolders));
            Guard.NotNull(asyncLoopFactory, nameof(asyncLoopFactory));

            this.dnsServer        = dnsServer;
            this.whitelistManager = whitelistManager;
            this.logger           = loggerFactory.CreateLogger(this.GetType().FullName);
            this.asyncLoopFactory = asyncLoopFactory;
            this.nodeLifetime     = nodeLifetime;
            this.dnsSettings      = DnsSettings.Load(nodeSettings, dnsSettings);
            this.dataFolders      = dataFolders;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WhitelistManager"/> class.
        /// </summary>
        /// <param name="dateTimeProvider">The provider for datetime.</param>
        /// <param name="loggerFactory">The factory to create the logger.</param>
        /// <param name="peerAddressManager">The manager implementation for peer addresses.</param>
        /// <param name="dnsServer">The DNS server.</param>
        /// <param name="connectionSettings">The connection settings.</param>
        /// <param name="dnsSettings">The DNS settings.</param>
        /// <param name="peerBanning">Peer banning component.</param>
        public WhitelistManager(IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, IPeerAddressManager peerAddressManager, IDnsServer dnsServer, ConnectionManagerSettings connectionSettings, DnsSettings dnsSettings, IPeerBanning peerBanning)
        {
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            Guard.NotNull(dnsServer, nameof(dnsServer));
            Guard.NotNull(dnsSettings, nameof(dnsSettings));
            Guard.NotNull(connectionSettings, nameof(connectionSettings));
            Guard.NotNull(peerBanning, nameof(peerBanning));

            this.dateTimeProvider   = dateTimeProvider;
            this.logger             = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
            this.peerAddressManager = peerAddressManager;
            this.dnsServer          = dnsServer;
            this.dnsSettings        = dnsSettings;
            this.externalEndpoint   = connectionSettings.ExternalEndpoint;
            this.peerBanning        = peerBanning;
        }
Esempio n. 4
0
        /// <inheritdoc />
        public void Seed(DnsSettings dnsSettings)
        {
            // Check if SOA record exists for host.
            int count = this.Get(new Question(new Domain(dnsSettings.DnsHostName), RecordType.SOA)).Count;

            if (count == 0)
            {
                // Add SOA record for host.
                this.entries.Add(new StartOfAuthorityResourceRecord(new Domain(dnsSettings.DnsHostName), new Domain(dnsSettings.DnsNameServer), new Domain(dnsSettings.DnsMailBox.Replace('@', '.'))));
            }

            // Check if NS record exists for host.
            count = this.Get(new Question(new Domain(dnsSettings.DnsHostName), RecordType.NS)).Count;
            if (count == 0)
            {
                // Add NS record for host.
                this.entries.Add(new NameServerResourceRecord(new Domain(dnsSettings.DnsHostName), new Domain(dnsSettings.DnsNameServer)));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DnsSeedServer"/> class with the port to listen on.
        /// </summary>
        /// <param name="client">The UDP client to use to receive DNS requests and send DNS responses.</param>
        /// <param name="masterFile">The initial DNS masterfile.</param>
        /// <param name="asyncLoopFactory">The async loop factory.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="dateTimeProvider">The <see cref="DateTime"/> provider.</param>
        /// <param name="nodeSettings">The node settings object containing node configuration.</param>
        /// <param name="dataFolders">The data folders of the system.</param>
        public DnsSeedServer(IUdpClient client, IMasterFile masterFile, IAsyncLoopFactory asyncLoopFactory, INodeLifetime nodeLifetime, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, DnsSettings dnsSettings, DataFolder dataFolders)
        {
            Guard.NotNull(client, nameof(client));
            Guard.NotNull(masterFile, nameof(masterFile));
            Guard.NotNull(asyncLoopFactory, nameof(asyncLoopFactory));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.NotNull(dnsSettings, nameof(dnsSettings));
            Guard.NotNull(dataFolders, nameof(dataFolders));

            this.udpClient        = client;
            this.masterFile       = masterFile;
            this.asyncLoopFactory = asyncLoopFactory;
            this.nodeLifetime     = nodeLifetime;
            this.logger           = loggerFactory.CreateLogger(this.GetType().FullName);
            this.dateTimeProvider = dateTimeProvider;
            this.dnsSettings      = dnsSettings;
            this.dataFolders      = dataFolders;
            this.metrics          = new DnsMetric();
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DnsFeature"/> class.
        /// </summary>
        /// <param name="dnsServer">The DNS server.</param>
        /// <param name="whitelistManager">The whitelist manager.</param>
        /// <param name="loggerFactory">The factory to create the logger.</param>
        /// <param name="nodeLifetime">The node lifetime object used for graceful shutdown.</param>
        /// <param name="nodeSettings">The node settings object containing node configuration.</param>
        /// <param name="dnsSettings">Defines the DNS settings for the node</param>
        /// <param name="dataFolders">The data folders of the system.</param>
        /// <param name="asyncLoopFactory">The asynchronous loop factory.</param>
        /// <param name="connectionManager">Manager of node's network connections.</param>
        /// <param name="unreliablePeerBehavior">Instance of the UnreliablePeerBehavior that will be added to the connectionManager Template.</param>
        public DnsFeature(IDnsServer dnsServer, IWhitelistManager whitelistManager, ILoggerFactory loggerFactory, INodeLifetime nodeLifetime, DnsSettings dnsSettings, NodeSettings nodeSettings, DataFolder dataFolders, IAsyncLoopFactory asyncLoopFactory, IConnectionManager connectionManager, UnreliablePeerBehavior unreliablePeerBehavior)
        {
            Guard.NotNull(dnsServer, nameof(dnsServer));
            Guard.NotNull(whitelistManager, nameof(whitelistManager));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(nodeSettings, nameof(nodeSettings));
            Guard.NotNull(dataFolders, nameof(dataFolders));
            Guard.NotNull(asyncLoopFactory, nameof(asyncLoopFactory));
            Guard.NotNull(connectionManager, nameof(connectionManager));
            Guard.NotNull(unreliablePeerBehavior, nameof(unreliablePeerBehavior));

            this.dnsServer              = dnsServer;
            this.whitelistManager       = whitelistManager;
            this.logger                 = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
            this.asyncLoopFactory       = asyncLoopFactory;
            this.nodeLifetime           = nodeLifetime;
            this.nodeSettings           = nodeSettings;
            this.dnsSettings            = dnsSettings;
            this.dataFolders            = dataFolders;
            this.connectionManager      = connectionManager;
            this.unreliablePeerBehavior = unreliablePeerBehavior;
        }
        /// <summary>
        /// Loads the DNS related settings from the application configuration.
        /// </summary>
        /// <param name="nodeSettings">Application configuration.</param>
        /// <param name "dnsSettings">Existing DnsSettings object to add loaded values to.</param>
        public static DnsSettings Load(NodeSettings nodeSettings, DnsSettings dnsSettings = null)
        {
            ILogger logger = nodeSettings.LoggerFactory.CreateLogger(typeof(DnsSettings).FullName);

            logger.LogTrace("()");

            dnsSettings = dnsSettings ?? new DnsSettings();

            TextFileConfiguration config = nodeSettings.ConfigReader;

            dnsSettings.DnsListenPort = config.GetOrDefault <int>("dnslistenport", DefaultDnsListenPort);
            logger.LogDebug("DNS Seed Service listen port is {0}, if running as DNS Seed.", dnsSettings.DnsListenPort);

            dnsSettings.DnsFullNode = config.GetOrDefault <bool>("dnsfullnode", false);
            if (dnsSettings.DnsFullNode)
            {
                logger.LogDebug("DNS Seed Service is set to run as a full node, if running as DNS Seed.", dnsSettings.DnsListenPort);
            }

            dnsSettings.DnsPeerBlacklistThresholdInSeconds = config.GetOrDefault("dnspeerblacklistthresholdinseconds", DefaultDnsPeerBlacklistThresholdInSeconds);
            logger.LogDebug("DnsPeerBlacklistThresholdInSeconds set to {0}.", dnsSettings.DnsPeerBlacklistThresholdInSeconds);

            dnsSettings.DnsHostName = config.GetOrDefault <string>("dnshostname", null);
            logger.LogDebug("DNS Seed Service host name set to {0}.", dnsSettings.DnsHostName);

            dnsSettings.DnsNameServer = config.GetOrDefault <string>("dnsnameserver", null);
            logger.LogDebug("DNS Seed Service nameserver set to {0}.", dnsSettings.DnsNameServer);

            dnsSettings.DnsMailBox = config.GetOrDefault <string>("dnsmailbox", null);
            logger.LogDebug("DNS Seed Service mailbox set to {0}.", dnsSettings.DnsMailBox);

            dnsSettings.callback?.Invoke(dnsSettings);

            logger.LogTrace("(-)");

            return(dnsSettings);
        }
Esempio n. 8
0
 /// <summary>
 /// Get the default configuration.
 /// </summary>
 /// <param name="builder">The string builder to add the settings to.</param>
 /// <param name="network">The network to base the defaults off.</param>
 public static void BuildDefaultConfigurationFile(StringBuilder builder, Network network)
 {
     DnsSettings.BuildDefaultConfigurationFile(builder, network);
 }
Esempio n. 9
0
 /// <summary>
 /// Prints command-line help.
 /// </summary>
 /// <param name="network">The network to extract values from.</param>
 public static void PrintHelp(Network network)
 {
     DnsSettings.PrintHelp(network);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="WhitelistManager"/> class.
        /// </summary>
        /// <param name="dateTimeProvider">The provider for datetime.</param>
        /// <param name="loggerFactory">The factory to create the logger.</param>
        /// <param name="peerAddressManager">The manager implementation for peer addresses.</param>
        /// <param name="dnsServer">The DNS server.</param>
        /// <param name="nodeSettings">The node settings.</param>
        public WhitelistManager(IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, IPeerAddressManager peerAddressManager, IDnsServer dnsServer, NodeSettings nodeSettings, DnsSettings dnsSettings)
        {
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            Guard.NotNull(dnsServer, nameof(dnsServer));
            Guard.NotNull(nodeSettings, nameof(nodeSettings));
            Guard.NotNull(dnsSettings, nameof(dnsSettings));
            Guard.NotNull(dnsSettings.DnsHostName, nameof(dnsSettings.DnsHostName));
            Guard.NotNull(nodeSettings.ConnectionManager, nameof(nodeSettings.ConnectionManager));

            this.dateTimeProvider   = dateTimeProvider;
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
            this.peerAddressManager = peerAddressManager;
            this.dnsServer          = dnsServer;
            this.dnsPeerBlacklistThresholdInSeconds = dnsSettings.DnsPeerBlacklistThresholdInSeconds;
            this.dnsHostName      = dnsSettings.DnsHostName;
            this.externalEndpoint = nodeSettings.ConnectionManager.ExternalEndpoint;
            this.fullNodeMode     = dnsSettings.DnsFullNode;
        }