Пример #1
0
        private static string[] GetFederatedPublicKeysFromArguments()
        {
            string[] pubKeys = null;

            int federatedPublicKeyCount = 0;

            if (ConfigReader.GetAll("fedpubkeys").FirstOrDefault() != null)
            {
                pubKeys = ConfigReader.GetAll("fedpubkeys").FirstOrDefault().Split(',');
                federatedPublicKeyCount = pubKeys.Count();
            }

            if (federatedPublicKeyCount == 0)
            {
                throw new ArgumentException("No federation member public keys specified.");
            }

            if (federatedPublicKeyCount % 2 == 0)
            {
                throw new ArgumentException("The federation must have an odd number of members.");
            }

            if (federatedPublicKeyCount > 15)
            {
                throw new ArgumentException("The federation can only have up to fifteen members.");
            }

            return(pubKeys);
        }
Пример #2
0
        /// <summary>
        /// Initializes an instance of the object from the node configuration.
        /// </summary>
        /// <param name="nodeSettings">The node configuration.</param>
        /// <param name="network">The network managment.</param>
        public xServerSettings(NodeSettings nodeSettings, Network network)
        {
            Guard.NotNull(nodeSettings, nameof(nodeSettings));
            Guard.NotNull(network, nameof(network));

            this.logger  = nodeSettings.LoggerFactory.CreateLogger(typeof(xServerSettings).FullName);
            this.network = network;

            TextFileConfiguration config = nodeSettings.ConfigReader;

            this.addxServerNodeLock = new object();

            lock (this.addxServerNodeLock)
            {
                this.addxServerNode = new List <NetworkXServer>();
            }

            try
            {
                foreach (NetworkXServer addNode in config.GetAll("addxservernode", this.logger).Select(c => c.ToIPXServerEndPoint(4242, 0)))
                {
                    this.AddAddNode(addNode);
                }
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'addxservernode' parameter.");
            }

            AddSeedNodes();
        }
Пример #3
0
        public void FailsToGetAllKeysWithArrayArgsAssignmentWithSpaces()
        {
            // Arrange
            var textFileConfiguration = new TextFileConfiguration(new[] { "test = testValue1", "-test = testValue2" });

            // Act
            string[] result = textFileConfiguration.GetAll("test");
            // Assert
            Assert.Empty(result);
        }
Пример #4
0
        public void GetAllWithArrayArgs()
        {
            // Arrange
            var textFileConfiguration = new TextFileConfiguration(new[] { "test" });

            // Act
            string[] result = textFileConfiguration.GetAll("test");
            // Assert
            Assert.Equal("1", result[0]);
        }
Пример #5
0
        public void GetMimeValueWithFileString()
        {
            // Arrange
            var textFileConfiguration = new TextFileConfiguration("azurekey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");

            // Act
            string[] result = textFileConfiguration.GetAll("azurekey");
            // Assert
            Assert.Single(result);
            Assert.Equal("Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", result[0]);
        }
Пример #6
0
        public void GetAllSuccessMultipleKeysWithStringArgs()
        {
            // Arrange
            var textFileConfiguration = new TextFileConfiguration("test = testValue \n\r -test = testValue2");

            // Act
            string[] result = textFileConfiguration.GetAll("test");
            // Assert
            Assert.Equal(2, result.Length);
            Assert.Equal("testValue", result[0]);
            Assert.Equal("testValue2", result[1]);
        }
Пример #7
0
        public void GetAllKeysWithArrayArgsAssignment_NoSpace_()
        {
            // Arrange
            var textFileConfiguration = new TextFileConfiguration(new[] { "test=testValue1", "-test=testValue2" });

            // Act
            string[] result = textFileConfiguration.GetAll("test");
            // Assert
            Assert.Equal(2, result.Length);
            Assert.Equal("testValue1", result[0]);
            Assert.Equal("testValue2", result[1]);
        }
Пример #8
0
        public void GetAllWithArrayArgsNoAssignment()
        {
            // Arrange
            var textFileConfiguration = new TextFileConfiguration(new[] { "test", "-test" });

            // Act
            string[] result = textFileConfiguration.GetAll("test");
            // Assert
            Assert.Equal(2, result.Length);
            Assert.Equal("1", result[0]);
            Assert.Equal("1", result[1]);
        }
        /// <summary>
        /// Loads the rpc settings from the application configuration.
        /// </summary>
        /// <param name="nodeSettings">Application configuration.</param>
        private void LoadSettingsFromConfig(NodeSettings nodeSettings)
        {
            TextFileConfiguration config = nodeSettings.ConfigReader;

            this.Server         = config.GetOrDefault <bool>("server", false, this.logger);
            this.RPCPort        = config.GetOrDefault <int>("rpcport", nodeSettings.Network.DefaultRPCPort, this.logger);
            this.RPCContentType = config.GetOrDefault("rpccontenttype", "application/json; charset=utf-8", this.logger);

            if (this.Server)
            {
                this.RpcUser     = config.GetOrDefault <string>("rpcuser", null, this.logger);
                this.RpcPassword = config.GetOrDefault <string>("rpcpassword", null); // No logging!

                try
                {
                    this.AllowIp = config
                                   .GetAll("rpcallowip", this.logger)
                                   .Select(p => IPAddressBlock.Parse(p))
                                   .ToList();
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid rpcallowip value");
                }

                try
                {
                    this.DefaultBindings = config
                                           .GetAll("rpcbind", this.logger)
                                           .Select(p => p.ToIPEndPoint(this.RPCPort))
                                           .ToList();
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid rpcbind value");
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Loads the rpc settings from the application configuration.
        /// </summary>
        /// <param name="nodeSettings">Application configuration.</param>
        private void LoadSettingsFromConfig(NodeSettings nodeSettings)
        {
            TextFileConfiguration config = nodeSettings.ConfigReader;

            this.Server  = config.GetOrDefault <bool>("server", false);
            this.RPCPort = config.GetOrDefault <int>("rpcport", nodeSettings.Network.RPCPort);

            if (this.Server)
            {
                this.RpcUser     = config.GetOrDefault <string>("rpcuser", null);
                this.RpcPassword = config.GetOrDefault <string>("rpcpassword", null);

                try
                {
                    this.AllowIp = config
                                   .GetAll("rpcallowip")
                                   .Select(p => IPAddress.Parse(p))
                                   .ToList();
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid rpcallowip value");
                }

                try
                {
                    this.DefaultBindings = config
                                           .GetAll("rpcbind")
                                           .Select(p => p.ToIPEndPoint(this.RPCPort))
                                           .ToList();
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid rpcbind value");
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Load the consensus settings from the config settings.
        /// </summary>
        /// <returns>These consensus config settings.</returns>
        private ConsensusSettings LoadFromConfig()
        {
            TextFileConfiguration config = this.nodeSettings.ConfigReader;

            this.UseCheckpoints = config.GetOrDefault <bool>("checkpoints", true);

            if (config.GetAll("assumevalid").Any(i => i.Equals("0"))) // 0 means validate all blocks.
            {
                this.BlockAssumedValid = null;
            }
            else
            {
                this.BlockAssumedValid = config.GetOrDefault <uint256>("assumevalid", this.nodeSettings.Network.Consensus.DefaultAssumeValid);
            }

            this.logger.LogDebug("Checkpoints are {0}.", this.UseCheckpoints ? "enabled" : "disabled");
            this.logger.LogDebug("Assume valid block is '{0}'.", this.BlockAssumedValid == null ? "disabled" : this.BlockAssumedValid.ToString());

            return(this);
        }
Пример #12
0
        public ConsensusSettings(NodeSettings nodeSettings)
        {
            Guard.NotNull(nodeSettings, nameof(nodeSettings));

            TextFileConfiguration config = nodeSettings.ConfigReader;

            this.UseCheckpoints = config.GetOrDefault <bool>("checkpoints", true);

            if (config.GetAll("assumevalid").Any(i => i.Equals("0"))) // 0 means validate all blocks.
            {
                this.BlockAssumedValid = null;
            }
            else
            {
                this.BlockAssumedValid = config.GetOrDefault <uint256>("assumevalid", nodeSettings.Network.Consensus.DefaultAssumeValid);
            }

            ILogger logger = nodeSettings.LoggerFactory.CreateLogger(typeof(ConsensusSettings).FullName);

            logger.LogDebug("Checkpoints are {0}.", this.UseCheckpoints ? "enabled" : "disabled");
            logger.LogDebug("Assume valid block is '{0}'.", this.BlockAssumedValid == null ? "disabled" : this.BlockAssumedValid.ToString());
        }
Пример #13
0
        /// <summary>
        /// Initializes an instance of the object from the node configuration.
        /// </summary>
        /// <param name="nodeSettings">The node configuration.</param>
        public ConnectionManagerSettings(NodeSettings nodeSettings)
        {
            Guard.NotNull(nodeSettings, nameof(nodeSettings));

            this.logger = nodeSettings.LoggerFactory.CreateLogger(typeof(ConnectionManagerSettings).FullName);

            this.addNodeLock = new object();

            this.Connect = new List <IPEndPoint>();

            lock (this.addNodeLock)
            {
                this.addNode = new List <IPEndPoint>();
            }

            this.Bind      = new List <NodeServerEndpoint>();
            this.Whitelist = new List <IPEndPoint>();

            TextFileConfiguration config = nodeSettings.ConfigReader;

            try
            {
                this.Connect.AddRange(config.GetAll("connect", this.logger).Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'connect' parameter.");
            }

            try
            {
                foreach (IPEndPoint addNode in config.GetAll("addnode", this.logger).Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)))
                {
                    this.AddAddNode(addNode);
                }
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'addnode' parameter.");
            }

            this.Port = config.GetOrDefault <int>("port", nodeSettings.Network.DefaultPort, this.logger);

            try
            {
                IEnumerable <IPEndPoint> whitebindEndpoints = config.GetAll("whitebind", this.logger).Select(s => s.ToIPEndPoint(this.Port));

                this.Bind = whitebindEndpoints.Where(x => x.Address.AnyIP()).Select(x => new NodeServerEndpoint(x, true)).ToList();

                foreach (IPEndPoint endPoint in whitebindEndpoints.Where(x => !x.Address.AnyIP()))
                {
                    if (this.Bind.Select(x => x.Endpoint).Any(x => x.Contains(endPoint)))
                    {
                        continue;
                    }

                    this.Bind.Add(new NodeServerEndpoint(endPoint, true));
                }
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'whitebind' parameter");
            }

            try
            {
                foreach (NodeServerEndpoint endPoint in config.GetAll("bind").Select(c => new NodeServerEndpoint(c.ToIPEndPoint(this.Port), false)))
                {
                    if (this.Bind.Select(x => x.Endpoint).Any(x => x.Contains(endPoint.Endpoint)))
                    {
                        continue;
                    }

                    this.Bind.Add(endPoint);
                }
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'bind' parameter");
            }

            if (this.Bind.Count == 0)
            {
                this.Bind.Add(new NodeServerEndpoint(new IPEndPoint(IPAddress.Parse("0.0.0.0"), this.Port), false));
            }

            try
            {
                this.Whitelist.AddRange(config.GetAll("whitelist", this.logger).Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'whitelist' parameter.");
            }

            string externalIp = config.GetOrDefault <string>("externalip", null, this.logger);

            if (externalIp != null)
            {
                try
                {
                    this.ExternalEndpoint = externalIp.ToIPEndPoint(this.Port);
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid 'externalip' parameter");
                }
            }

            if (this.ExternalEndpoint == null)
            {
                this.ExternalEndpoint = new IPEndPoint(IPAddress.Loopback, this.Port);
            }

            this.BanTimeSeconds = config.GetOrDefault <int>("bantime", nodeSettings.Network.DefaultBanTimeSeconds, this.logger);

            // Listen option will default to true in case there are no connect option specified.
            // When running the node with connect option listen flag has to be explicitly passed to the node to enable listen flag.
            this.Listen = config.GetOrDefault <bool>("listen", !this.Connect.Any(), this.logger);

            this.MaxOutboundConnections = config.GetOrDefault <int>("maxoutboundconnections", nodeSettings.Network.DefaultMaxOutboundConnections, this.logger);
            if (this.MaxOutboundConnections <= 0)
            {
                throw new ConfigurationException("The 'maxoutboundconnections' must be greater than zero.");
            }

            this.MaxInboundConnections = config.GetOrDefault <int>("maxinboundconnections", nodeSettings.Network.DefaultMaxInboundConnections, this.logger);
            if (this.MaxInboundConnections < 0)
            {
                throw new ConfigurationException("The 'maxinboundconnections' must be greater or equal to zero.");
            }

            this.InitialConnectionTarget = config.GetOrDefault("initialconnectiontarget", 1, this.logger);
            this.SyncTimeEnabled         = config.GetOrDefault <bool>("synctime", true, this.logger);
            this.RelayTxes        = !config.GetOrDefault("blocksonly", DefaultBlocksOnly, this.logger);
            this.IpRangeFiltering = config.GetOrDefault <bool>("IpRangeFiltering", true, this.logger);

            var agentPrefix = config.GetOrDefault("agentprefix", string.Empty, this.logger).Replace("-", string.Empty);

            if (agentPrefix.Length > MaximumAgentPrefixLength)
            {
                agentPrefix = agentPrefix.Substring(0, MaximumAgentPrefixLength);
            }

            this.Agent = string.IsNullOrEmpty(agentPrefix) ? nodeSettings.Agent : $"{agentPrefix}-{nodeSettings.Agent}";
            this.logger.LogDebug("Agent set to '{0}'.", this.Agent);

            this.DisableAddNodePeerConnector = config.GetOrDefault("disableaddnodeconnector", false, this.logger);
        }
Пример #14
0
        /// <summary>
        /// Loads the rpc settings from the application configuration.
        /// </summary>
        /// <param name="nodeSettings">Application configuration.</param>
        private void LoadSettingsFromConfig(NodeSettings nodeSettings)
        {
            TextFileConfiguration config = nodeSettings.ConfigReader;

            this.Server         = config.GetOrDefault <bool>("server", false, this.logger);
            this.RPCPort        = config.GetOrDefault <int>("rpcport", nodeSettings.Network.DefaultRPCPort, this.logger);
            this.RPCContentType = config.GetOrDefault("rpccontenttype", "application/json; charset=utf-8", this.logger);

            if (this.Server)
            {
                this.RpcUser     = config.GetOrDefault <string>("rpcuser", null, this.logger);
                this.RpcPassword = config.GetOrDefault <string>("rpcpassword", null); // No logging!

                try
                {
                    this.AllowIp = config
                                   .GetAll("rpcallowip", this.logger)
                                   .Select(p => IPAddressBlock.Parse(p))
                                   .ToList();
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid rpcallowip value");
                }

                try
                {
                    this.DefaultBindings = config
                                           .GetAll("rpcbind", this.logger)
                                           .Select(p => p.ToIPEndPoint(this.RPCPort))
                                           .ToList();
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid rpcbind value");
                }

                // If the "Bind" list has not been specified via callback.
                if (this.Bind.Count == 0)
                {
                    this.Bind = this.DefaultBindings;
                }

                if (this.AllowIp.Count == 0)
                {
                    if (this.Bind.Count > 0)
                    {
                        this.logger.LogWarning("WARNING: RPC bind selection (-rpcbind) was ignored because allowed ip's (-rpcallowip) were not specified, refusing to allow everyone to connect");
                    }

                    this.Bind.Clear();
                    this.Bind.Add(new IPEndPoint(IPAddress.Parse("::1"), this.RPCPort));
                    this.Bind.Add(new IPEndPoint(IPAddress.Parse("127.0.0.1"), this.RPCPort));
                }

                if (this.Bind.Count == 0)
                {
                    this.Bind.Add(new IPEndPoint(IPAddress.Parse("::"), this.RPCPort));
                    this.Bind.Add(new IPEndPoint(IPAddress.Parse("0.0.0.0"), this.RPCPort));
                }
            }
        }
        /// <summary>
        /// Initializes an instance of the object from the node configuration.
        /// </summary>
        /// <param name="nodeSettings">The node configuration.</param>
        public ConnectionManagerSettings(NodeSettings nodeSettings)
        {
            Guard.NotNull(nodeSettings, nameof(nodeSettings));

            this.logger = nodeSettings.LoggerFactory.CreateLogger(typeof(ConnectionManagerSettings).FullName);

            this.Connect   = new List <IPEndPoint>();
            this.AddNode   = new List <IPEndPoint>();
            this.Bind      = new List <NodeServerEndpoint>();
            this.Whitelist = new List <IPEndPoint>();

            TextFileConfiguration config = nodeSettings.ConfigReader;

            try
            {
                this.Connect.AddRange(config.GetAll("connect", this.logger).Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'connect' parameter.");
            }

            try
            {
                this.AddNode.AddRange(config.GetAll("addnode", this.logger).Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'addnode' parameter.");
            }

            this.Port = config.GetOrDefault <int>("port", nodeSettings.Network.DefaultPort, this.logger);

            try
            {
                this.Bind.AddRange(config.GetAll("bind").Select(c => new NodeServerEndpoint(c.ToIPEndPoint(this.Port), false)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'bind' parameter");
            }

            try
            {
                IEnumerable <IPEndPoint> whitebindEndpoints = config.GetAll("whitebind", this.logger).Select(s => s.ToIPEndPoint(this.Port));

                List <IPEndPoint> networkEndpoints = this.Bind.Select(x => x.Endpoint).ToList();

                foreach (IPEndPoint whiteBindEndpoint in whitebindEndpoints)
                {
                    if (whiteBindEndpoint.CanBeMappedTo(networkEndpoints, out IPEndPoint outEndpoint))
                    {
                        // White-list white-bind endpoint if we are currently listening to it.
                        NodeServerEndpoint listenToThisEndpoint = this.Bind.SingleOrDefault(x => x.Endpoint.Equals(outEndpoint));

                        if (listenToThisEndpoint != null)
                        {
                            listenToThisEndpoint.Whitelisted = true;
                        }
                    }
                    else
                    {
                        // Add to list of network interfaces if we are not.
                        this.Bind.Add(new NodeServerEndpoint(whiteBindEndpoint, true));
                    }
                }
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'whitebind' parameter");
            }

            if (this.Bind.Count == 0)
            {
                this.Bind.Add(new NodeServerEndpoint(new IPEndPoint(IPAddress.Parse("0.0.0.0"), this.Port), false));
            }
            else
            {
                var ports = this.Bind.Select(l => l.Endpoint.Port).ToList();

                if (ports.Count != ports.Distinct().Count())
                {
                    throw new ConfigurationException("Invalid attempt to bind the same port twice");
                }
            }

            try
            {
                this.Whitelist.AddRange(config.GetAll("whitelist", this.logger).Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'whitelist' parameter.");
            }

            string externalIp = config.GetOrDefault <string>("externalip", null, this.logger);

            if (externalIp != null)
            {
                try
                {
                    this.ExternalEndpoint = externalIp.ToIPEndPoint(this.Port);
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid 'externalip' parameter");
                }
            }

            if (this.ExternalEndpoint == null)
            {
                this.ExternalEndpoint = new IPEndPoint(IPAddress.Loopback, this.Port);
            }

            this.BanTimeSeconds = config.GetOrDefault <int>("bantime", nodeSettings.Network.IsTest() ? DefaultMisbehavingBantimeSecondsTestnet : DefaultMisbehavingBantimeSeconds, this.logger);

            // Listen option will default to true in case there are no connect option specified.
            // When running the node with connect option listen flag has to be explicitly passed to the node to enable listen flag.
            this.Listen = config.GetOrDefault <bool>("listen", !this.Connect.Any(), this.logger);

            this.MaxOutboundConnections = config.GetOrDefault <int>("maxoutboundconnections", nodeSettings.Network.DefaultMaxOutboundConnections, this.logger);
            if (this.MaxOutboundConnections <= 0)
            {
                throw new ConfigurationException("The 'maxoutboundconnections' must be greater than zero.");
            }

            this.MaxInboundConnections = config.GetOrDefault <int>("maxinboundconnections", nodeSettings.Network.DefaultMaxInboundConnections, this.logger);
            if (this.MaxInboundConnections < 0)
            {
                throw new ConfigurationException("The 'maxinboundconnections' must be greater or equal to zero.");
            }

            this.InitialConnectionTarget = config.GetOrDefault("initialconnectiontarget", 1, this.logger);
            this.SyncTimeEnabled         = config.GetOrDefault <bool>("synctime", true, this.logger);
            this.RelayTxes        = !config.GetOrDefault("blocksonly", DefaultBlocksOnly, this.logger);
            this.IpRangeFiltering = config.GetOrDefault <bool>("IpRangeFiltering", true, this.logger);

            var agentPrefix = config.GetOrDefault("agentprefix", string.Empty, this.logger).Replace("-", string.Empty);

            if (agentPrefix.Length > MaximumAgentPrefixLength)
            {
                agentPrefix = agentPrefix.Substring(0, MaximumAgentPrefixLength);
            }

            this.Agent = string.IsNullOrEmpty(agentPrefix) ? nodeSettings.Agent : $"{agentPrefix}-{nodeSettings.Agent}";
            this.logger.LogDebug("Agent set to '{0}'.", this.Agent);

            this.IsGateway = config.GetOrDefault <bool>("gateway", false, this.logger);
        }
        /// <summary>
        /// Initializes an instance of the object from the node configuration.
        /// </summary>
        /// <param name="nodeSettings">The node configuration.</param>
        public ConnectionManagerSettings(NodeSettings nodeSettings)
        {
            Guard.NotNull(nodeSettings, nameof(nodeSettings));

            this.logger = nodeSettings.LoggerFactory.CreateLogger(typeof(ConnectionManagerSettings).FullName);
            this.logger.LogTrace("({0}:'{1}')", nameof(nodeSettings), nodeSettings.Network.Name);

            this.Connect = new List <IPEndPoint>();
            this.AddNode = new List <IPEndPoint>();
            this.Listen  = new List <NodeServerEndpoint>();

            TextFileConfiguration config = nodeSettings.ConfigReader;

            try
            {
                this.Connect.AddRange(config.GetAll("connect", this.logger)
                                      .Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'connect' parameter.");
            }

            try
            {
                this.AddNode.AddRange(config.GetAll("addnode", this.logger)
                                      .Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'addnode' parameter.");
            }

            int port = config.GetOrDefault <int>("port", nodeSettings.Network.DefaultPort, this.logger);

            try
            {
                this.Listen.AddRange(config.GetAll("bind")
                                     .Select(c => new NodeServerEndpoint(c.ToIPEndPoint(port), false)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'bind' parameter");
            }

            try
            {
                this.Listen.AddRange(config.GetAll("whitebind", this.logger)
                                     .Select(c => new NodeServerEndpoint(c.ToIPEndPoint(port), true)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'listen' parameter");
            }

            if (this.Listen.Count == 0)
            {
                this.Listen.Add(new NodeServerEndpoint(new IPEndPoint(IPAddress.Parse("0.0.0.0"), port), false));
            }

            string externalIp = config.GetOrDefault <string>("externalip", null, this.logger);

            if (externalIp != null)
            {
                try
                {
                    this.ExternalEndpoint = externalIp.ToIPEndPoint(port);
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid 'externalip' parameter");
                }
            }

            if (this.ExternalEndpoint == null)
            {
                this.ExternalEndpoint = new IPEndPoint(IPAddress.Loopback, port);
            }

            this.BanTimeSeconds             = config.GetOrDefault <int>("bantime", ConnectionManagerSettings.DefaultMisbehavingBantimeSeconds, this.logger);
            this.MaxOutboundConnections     = config.GetOrDefault <int>("maxoutboundconnections", ConnectionManagerSettings.DefaultMaxOutboundConnections, this.logger);
            this.BurstModeTargetConnections = config.GetOrDefault("burstModeTargetConnections", 1, this.logger);
            this.SyncTimeEnabled            = config.GetOrDefault <bool>("synctime", true, this.logger);
            this.RelayTxes        = !config.GetOrDefault("blocksonly", DefaultBlocksOnly, this.logger);
            this.IpRangeFiltering = config.GetOrDefault <bool>("IpRangeFiltering", true, this.logger);

            var agentPrefix = config.GetOrDefault("agentprefix", string.Empty, this.logger).Replace("-", string.Empty);

            if (agentPrefix.Length > MaximumAgentPrefixLength)
            {
                agentPrefix = agentPrefix.Substring(0, MaximumAgentPrefixLength);
            }

            this.Agent = string.IsNullOrEmpty(agentPrefix) ? nodeSettings.Agent : $"{agentPrefix}-{nodeSettings.Agent}";
            this.logger.LogDebug("Agent set to '{0}'.", this.Agent);

            this.logger.LogTrace("(-)");
        }
        /// <summary>
        /// Loads the ConnectionManager related settings from the application configuration.
        /// </summary>
        /// <param name="nodeSettings">Application configuration.</param>
        public void Load(NodeSettings nodeSettings)
        {
            TextFileConfiguration config = nodeSettings.ConfigReader;

            try
            {
                this.Connect.AddRange(config.GetAll("connect")
                                      .Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'connect' parameter.");
            }

            try
            {
                this.AddNode.AddRange(config.GetAll("addnode")
                                      .Select(c => c.ToIPEndPoint(nodeSettings.Network.DefaultPort)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'addnode' parameter.");
            }

            int port = config.GetOrDefault <int>("port", nodeSettings.Network.DefaultPort);

            try
            {
                this.Listen.AddRange(config.GetAll("bind")
                                     .Select(c => new NodeServerEndpoint(c.ToIPEndPoint(port), false)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'bind' parameter");
            }

            try
            {
                this.Listen.AddRange(config.GetAll("whitebind")
                                     .Select(c => new NodeServerEndpoint(c.ToIPEndPoint(port), true)));
            }
            catch (FormatException)
            {
                throw new ConfigurationException("Invalid 'listen' parameter");
            }

            if (this.Listen.Count == 0)
            {
                this.Listen.Add(new NodeServerEndpoint(new IPEndPoint(IPAddress.Parse("0.0.0.0"), port), false));
            }

            string externalIp = config.GetOrDefault <string>("externalip", null);

            if (externalIp != null)
            {
                try
                {
                    this.ExternalEndpoint = externalIp.ToIPEndPoint(port);
                }
                catch (FormatException)
                {
                    throw new ConfigurationException("Invalid 'externalip' parameter");
                }
            }

            if (this.ExternalEndpoint == null)
            {
                this.ExternalEndpoint = new IPEndPoint(IPAddress.Loopback, nodeSettings.Network.DefaultPort);
            }

            this.BanTimeSeconds             = config.GetOrDefault <int>("bantime", ConnectionManagerSettings.DefaultMisbehavingBantimeSeconds);
            this.MaxOutboundConnections     = config.GetOrDefault <int>("maxoutboundconnections", ConnectionManagerSettings.DefaultMaxOutboundConnections);
            this.BurstModeTargetConnections = config.GetOrDefault("burstModeTargetConnections", 1);
        }