public bool AddNode(string endpointStr, string command) { Guard.NotNull(this.ConnectionManager, nameof(this.ConnectionManager)); IPEndPoint endpoint = NodeSettings.ConvertToEndpoint(endpointStr, this.ConnectionManager.Network.DefaultPort); switch (command) { case "add": this.ConnectionManager.AddNodeAddress(endpoint); break; case "remove": this.ConnectionManager.RemoveNodeAddress(endpoint); break; case "onetry": this.ConnectionManager.Connect(endpoint); break; default: throw new ArgumentException("command"); } return(true); }
/// <summary> /// Loads the rpc settings from the application configuration. /// </summary> /// <param name="nodeSettings">Application configuration.</param> private void LoadSettingsFromConfig(NodeSettings nodeSettings) { var config = nodeSettings.ConfigReader; this.Server = config.GetOrDefault <bool>("server", false); this.RPCPort = nodeSettings.Network.RPCPort; if (this.Server) { this.RpcUser = config.GetOrDefault <string>("rpcuser", null); this.RpcPassword = config.GetOrDefault <string>("rpcpassword", null); this.RPCPort = config.GetOrDefault <int>("rpcport", nodeSettings.Network.RPCPort); 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 => NodeSettings.ConvertToEndpoint(p, this.RPCPort)) .ToList(); } catch (FormatException) { throw new ConfigurationException("Invalid rpcbind value"); } } }
public bool AddNode(string endpointStr, string command) { var endpoint = NodeSettings.ConvertToEndpoint(endpointStr, _FullNode.Network.DefaultPort); switch (command) { case "add": _FullNode.ConnectionManager.AddNode(endpoint); break; case "remove": _FullNode.ConnectionManager.RemoveNode(endpoint); break; case "onetry": _FullNode.ConnectionManager.Connect(endpoint); break; default: throw new ArgumentException("command"); } return(true); }
/// <summary> /// Loads the rpc settings from the application configuration. /// </summary> /// <param name="config">Application configuration.</param> public void Load(NodeSettings nodeSettings) { var config = nodeSettings.ConfigReader; this.Server = config.GetOrDefault <bool>("server", false); if (!this.Server) { return; } this.RpcUser = config.GetOrDefault <string>("rpcuser", null); this.RpcPassword = config.GetOrDefault <string>("rpcpassword", null); if (this.RpcPassword == null && this.RpcUser != null) { throw new ConfigurationException("rpcpassword should be provided"); } if (this.RpcUser == null && this.RpcPassword != null) { throw new ConfigurationException("rpcuser should be provided"); } var defaultPort = config.GetOrDefault <int>("rpcport", nodeSettings.Network.RPCPort); this.RPCPort = defaultPort; try { this.Bind = config .GetAll("rpcbind") .Select(p => NodeSettings.ConvertToEndpoint(p, defaultPort)) .ToList(); } catch (FormatException) { throw new ConfigurationException("Invalid rpcbind value"); } try { this.AllowIp = config .GetAll("rpcallowip") .Select(p => IPAddress.Parse(p)) .ToList(); } catch (FormatException) { throw new ConfigurationException("Invalid rpcallowip value"); } if (this.AllowIp.Count == 0) { this.Bind.Clear(); this.Bind.Add(new IPEndPoint(IPAddress.Parse("::1"), defaultPort)); this.Bind.Add(new IPEndPoint(IPAddress.Parse("127.0.0.1"), defaultPort)); if (config.Contains("rpcbind")) { nodeSettings.Logger.LogWarning("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect"); } } if (this.Bind.Count == 0) { this.Bind.Add(new IPEndPoint(IPAddress.Parse("::"), defaultPort)); this.Bind.Add(new IPEndPoint(IPAddress.Parse("0.0.0.0"), defaultPort)); } this.callback?.Invoke(this); }