refactor utils.

This commit is contained in:
Christopher Jeffrey 2016-05-19 21:31:04 -07:00
parent 39a8ecc398
commit b4bfe53bfe
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 10 additions and 12 deletions

View File

@ -119,7 +119,7 @@ function Peer(pool, options) {
assert(typeof this.host === 'string');
assert(typeof this.port === 'number');
this.hostname = utils.stringifyHost(this);
this.hostname = utils.hostname(this.host, this.port);
if (!this.socket)
throw new Error('No socket');
@ -247,28 +247,26 @@ Peer.prototype._init = function init() {
Peer.prototype.createSocket = function createSocket(port, host) {
var self = this;
var hostname = utils.hostname(host, port);
var socket, net;
if (this._createSocket) {
socket = this._createSocket(port, host);
} else if (bcoin.isBrowser) {
throw new Error('Please include a `createSocket` callback.');
} else {
if (bcoin.isBrowser)
throw new Error('Please include a `createSocket` callback.');
net = require('n' + 'et');
socket = net.connect(port, host);
}
if (utils.isIP(host) === 6)
host = '[' + host + ']';
bcoin.debug(
'Connecting to %s:%d (priority=%s).',
host, port, this.priority);
hostname, this.priority);
socket.on('connect', function() {
bcoin.debug(
'Connected to %s:%d (priority=%s).',
host, port, self.priority);
hostname, self.priority);
});
return socket;

View File

@ -843,8 +843,8 @@ utils.isBTC = function isBTC(value) {
* Parse a hostname.
* @example
* utils.parseHost('127.0.0.1:3000');
* @param {String|Seed} addr
* @returns {Seed}
* @param {String} addr
* @returns {Object} Contains `host` and `port`.
*/
utils.parseHost = function parseHost(addr) {
@ -867,12 +867,12 @@ utils.parseHost = function parseHost(addr) {
};
/**
* Stringify a host.
* Concatenate a host and port.
* @param {Seed} seed
* @returns {String}
*/
utils.stringifyHost = function stringifyHost(seed) {
utils.hostname = function hostname(seed) {
var host = seed.host;
if (utils.isIP(host) === 6)