/// <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="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="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(); }
/// <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); }
/// <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; }