rpc: better errors.
This commit is contained in:
parent
11a90dd7da
commit
612f6a987c
@ -272,7 +272,7 @@ RPC.prototype.addNode = co(function* addNode(args, help) {
|
||||
addr = this.pool.hosts.addNode(node);
|
||||
; // fall through
|
||||
case 'onetry':
|
||||
addr = NetAddress.fromHostname(node, this.network);
|
||||
addr = parseNetAddress(node, this.network);
|
||||
|
||||
if (!this.pool.peers.get(addr.hostname)) {
|
||||
peer = this.pool.createOutbound(addr);
|
||||
@ -296,7 +296,7 @@ RPC.prototype.disconnectNode = co(function* disconnectNode(args, help) {
|
||||
if (help || args.length !== 1)
|
||||
throw new RPCError(errs.MISC_ERROR, 'disconnectnode "node"');
|
||||
|
||||
addr = IP.fromHostname(addr, this.network.port);
|
||||
addr = parseIP(addr, this.network);
|
||||
peer = this.pool.peers.get(addr.hostname);
|
||||
|
||||
if (peer)
|
||||
@ -316,7 +316,7 @@ RPC.prototype.getAddedNodeInfo = co(function* getAddedNodeInfo(args, help) {
|
||||
throw new RPCError(errs.MISC_ERROR, 'getaddednodeinfo ( "node" )');
|
||||
|
||||
if (args.length === 1)
|
||||
target = IP.fromHostname(addr, this.network.port);
|
||||
target = parseIP(addr, this.network);
|
||||
|
||||
for (i = 0; i < hosts.nodes.length; i++) {
|
||||
node = hosts.nodes[i];
|
||||
@ -460,12 +460,7 @@ RPC.prototype.setBan = co(function* setBan(args, help) {
|
||||
'setban "ip(/netmask)" "add|remove" (bantime) (absolute)');
|
||||
}
|
||||
|
||||
try {
|
||||
addr = NetAddress.fromHostname(addr, this.network);
|
||||
} catch (e) {
|
||||
throw new RPCError(errs.CLIENT_INVALID_IP_OR_SUBNET,
|
||||
'Invalid IP or subnet.');
|
||||
}
|
||||
addr = parseNetAddress(addr, this.network);
|
||||
|
||||
switch (action) {
|
||||
case 'add':
|
||||
@ -2810,6 +2805,24 @@ function parseSecret(raw, network) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseIP(addr, network) {
|
||||
try {
|
||||
return IP.fromHostname(addr, network.port);
|
||||
} catch (e) {
|
||||
throw new RPCError(errs.CLIENT_INVALID_IP_OR_SUBNET,
|
||||
'Invalid IP address or subnet.');
|
||||
}
|
||||
}
|
||||
|
||||
function parseNetAddress(addr, network) {
|
||||
try {
|
||||
return NetAddress.fromHostname(addr, network);
|
||||
} catch (e) {
|
||||
throw new RPCError(errs.CLIENT_INVALID_IP_OR_SUBNET,
|
||||
'Invalid IP address or subnet.');
|
||||
}
|
||||
}
|
||||
|
||||
function toDifficulty(bits) {
|
||||
var shift = (bits >>> 24) & 0xff;
|
||||
var diff = 0x0000ffff / (bits & 0x00ffffff);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user