コード例 #1
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");
                }
            }
        }
コード例 #2
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));
                }
            }
        }