ip: rename some functions.
This commit is contained in:
parent
07c3177227
commit
b8324e0b09
@ -429,7 +429,7 @@ RPC.prototype.disconnectnode = co(function* disconnectnode(args) {
|
||||
throw new RPCError('disconnectnode "node"');
|
||||
|
||||
addr = toString(args[0]);
|
||||
addr = IP.parseHost(addr, this.network.port);
|
||||
addr = IP.fromHostname(addr, this.network.port);
|
||||
|
||||
peer = this.pool.peers.get(addr.hostname);
|
||||
|
||||
@ -448,7 +448,7 @@ RPC.prototype.getaddednodeinfo = co(function* getaddednodeinfo(args) {
|
||||
|
||||
if (args.length === 2) {
|
||||
addr = toString(args[1]);
|
||||
addr = IP.parseHost(addr, this.network.port);
|
||||
addr = IP.fromHostname(addr, this.network.port);
|
||||
peer = this.pool.peers.get(addr.hostname);
|
||||
if (!peer)
|
||||
throw new RPCError('Node has not been added.');
|
||||
|
||||
@ -527,7 +527,7 @@ AuthDB.prototype.addKnown = function addKnown(host, key) {
|
||||
assert(Buffer.isBuffer(key) && key.length === 33,
|
||||
'Invalid public key for known peer.');
|
||||
|
||||
addr = IP.parseHost(host);
|
||||
addr = IP.fromHostname(host);
|
||||
|
||||
if (addr.type === IP.types.DNS) {
|
||||
// Defer this for resolution.
|
||||
@ -596,7 +596,7 @@ AuthDB.prototype.getKnown = function getKnown(hostname) {
|
||||
if (known)
|
||||
return known;
|
||||
|
||||
addr = IP.parseHost(hostname);
|
||||
addr = IP.fromHostname(hostname);
|
||||
|
||||
return this.known[addr.host];
|
||||
};
|
||||
|
||||
@ -662,7 +662,7 @@ HostList.prototype.toArray = function toArray() {
|
||||
*/
|
||||
|
||||
HostList.prototype.addSeed = function addSeed(host) {
|
||||
var addr = IP.parseHost(host, this.network.port);
|
||||
var addr = IP.fromHostname(host, this.network.port);
|
||||
|
||||
if (addr.type === IP.types.DNS) {
|
||||
// Defer for resolution.
|
||||
@ -683,7 +683,7 @@ HostList.prototype.addSeed = function addSeed(host) {
|
||||
*/
|
||||
|
||||
HostList.prototype.addNode = function addNode(host) {
|
||||
var addr = IP.parseHost(host, this.network.port);
|
||||
var addr = IP.fromHostname(host, this.network.port);
|
||||
|
||||
if (addr.type === IP.types.DNS) {
|
||||
// Defer for resolution.
|
||||
|
||||
@ -246,7 +246,7 @@ NetAddress.prototype.fromHostname = function fromHostname(hostname, network) {
|
||||
|
||||
network = Network.get(network);
|
||||
|
||||
addr = IP.parseHost(hostname, network.port);
|
||||
addr = IP.fromHostname(hostname, network.port);
|
||||
|
||||
return this.fromHost(addr.host, addr.port, network);
|
||||
};
|
||||
|
||||
@ -57,7 +57,7 @@ IP.types = {
|
||||
* @returns {Object} Contains `host`, `port`, and `type`.
|
||||
*/
|
||||
|
||||
IP.parseHost = function parseHost(addr, fallback) {
|
||||
IP.fromHostname = function fromHostname(addr, fallback) {
|
||||
var parts, host, port, type, hostname, raw;
|
||||
|
||||
assert(typeof addr === 'string');
|
||||
@ -99,7 +99,7 @@ IP.parseHost = function parseHost(addr, fallback) {
|
||||
default:
|
||||
// Case:
|
||||
// ::1
|
||||
assert(IP.isV6Format(addr), 'Bad IPv6 address.');
|
||||
assert(IP.isV6String(addr), 'Bad IPv6 address.');
|
||||
host = addr;
|
||||
port = null;
|
||||
break;
|
||||
@ -117,7 +117,7 @@ IP.parseHost = function parseHost(addr, fallback) {
|
||||
port = fallback || 0;
|
||||
}
|
||||
|
||||
type = IP.getType(host);
|
||||
type = IP.getStringType(host);
|
||||
|
||||
if (type !== IP.types.DNS) {
|
||||
raw = IP.toBuffer(host);
|
||||
@ -151,7 +151,7 @@ IP.toHostname = function toHostname(host, port) {
|
||||
|
||||
assert(!/[\[\]]/.test(host), 'Bad host.');
|
||||
|
||||
type = IP.getType(host);
|
||||
type = IP.getStringType(host);
|
||||
|
||||
if (host.indexOf(':') !== -1)
|
||||
assert(type === IP.types.IPV6, 'Bad host.');
|
||||
@ -171,14 +171,14 @@ IP.toHostname = function toHostname(host, port) {
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
IP.getType = function getType(str) {
|
||||
if (IP.isV4Format(str))
|
||||
IP.getStringType = function getStringType(str) {
|
||||
if (IP.isV4String(str))
|
||||
return IP.types.IPV4;
|
||||
|
||||
if (IP.isV6Format(str))
|
||||
if (IP.isV6String(str))
|
||||
return IP.types.IPV6;
|
||||
|
||||
if (IP.isTorFormat(str))
|
||||
if (IP.isTorString(str))
|
||||
return IP.types.TOR;
|
||||
|
||||
return IP.types.DNS;
|
||||
@ -190,7 +190,7 @@ IP.getType = function getType(str) {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
IP.isV4Format = function isV4Format(str) {
|
||||
IP.isV4String = function isV4String(str) {
|
||||
assert(typeof str === 'string');
|
||||
|
||||
if (str.length < 7)
|
||||
@ -208,7 +208,7 @@ IP.isV4Format = function isV4Format(str) {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
IP.isV6Format = function isV6Format(str) {
|
||||
IP.isV6String = function isV6String(str) {
|
||||
assert(typeof str === 'string');
|
||||
|
||||
if (str.length < 2)
|
||||
@ -226,7 +226,7 @@ IP.isV6Format = function isV6Format(str) {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
IP.isTorFormat = function isTorFormat(str) {
|
||||
IP.isTorString = function isTorString(str) {
|
||||
assert(typeof str === 'string');
|
||||
|
||||
if (str.length < 7)
|
||||
@ -271,14 +271,14 @@ IP.toBuffer = function toBuffer(str) {
|
||||
|
||||
assert(typeof str === 'string');
|
||||
|
||||
if (IP.isV4Format(str)) {
|
||||
if (IP.isV4String(str)) {
|
||||
raw.fill(0);
|
||||
raw[10] = 0xff;
|
||||
raw[11] = 0xff;
|
||||
return IP.parseV4(str, raw, 12);
|
||||
}
|
||||
|
||||
if (IP.isTorFormat(str)) {
|
||||
if (IP.isTorString(str)) {
|
||||
data = TOR_ONION;
|
||||
data.copy(raw, 0);
|
||||
data = base32.decode(str.slice(0, -6));
|
||||
@ -337,7 +337,7 @@ IP.parseV6 = function parseV6(str, raw, offset) {
|
||||
|
||||
for (i = 0; i < parts.length; i++) {
|
||||
word = parts[i];
|
||||
if (IP.isV4Format(word))
|
||||
if (IP.isV4String(word))
|
||||
missing--;
|
||||
}
|
||||
|
||||
@ -369,7 +369,7 @@ IP.parseV6 = function parseV6(str, raw, offset) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IP.isV4Format(word)) {
|
||||
if (IP.isV4String(word)) {
|
||||
IP.parseV4(word, raw, offset);
|
||||
offset += 4;
|
||||
continue;
|
||||
@ -469,6 +469,25 @@ IP.isIPv6 = function isIPv6(raw) {
|
||||
return !IP.isMapped(raw) && !IP.isTor(raw);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get address type.
|
||||
* @param {Buffer} raw
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
IP.getType = function getType(raw) {
|
||||
if (IP.isIPv4(raw))
|
||||
return IP.types.IPV4;
|
||||
|
||||
if (IP.isIPv6(raw))
|
||||
return IP.types.IPV6;
|
||||
|
||||
if (IP.isTor(raw))
|
||||
return IP.types.TOR;
|
||||
|
||||
assert(false, 'Unknown type.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Test whether the host is null.
|
||||
* @returns {Boolean}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user