stop using hostname getter.
This commit is contained in:
parent
29cac3515a
commit
435f631f05
@ -76,6 +76,7 @@ function Peer(pool, options) {
|
||||
this.socket = null;
|
||||
this.host = null;
|
||||
this.port = 0;
|
||||
this.hostname = null;
|
||||
this._createSocket = this.options.createSocket;
|
||||
this.priority = this.options.priority;
|
||||
this.chain = this.pool.chain;
|
||||
@ -118,6 +119,8 @@ function Peer(pool, options) {
|
||||
assert(typeof this.host === 'string');
|
||||
assert(typeof this.port === 'number');
|
||||
|
||||
this.hostname = utils.stringifyHost(this);
|
||||
|
||||
if (!this.socket)
|
||||
throw new Error('No socket');
|
||||
|
||||
@ -214,7 +217,7 @@ Peer.prototype._init = function init() {
|
||||
|
||||
self.write(self.framer.getAddr());
|
||||
|
||||
self.sendInv(self.pool.inv.list);
|
||||
self.sendInv(self.pool.inv.items);
|
||||
|
||||
if (self.pool.options.filterRate != null) {
|
||||
self.write(self.framer.feeFilter({
|
||||
@ -1435,15 +1438,6 @@ Peer.prototype.sendReject = function sendReject(obj, code, reason, score) {
|
||||
return this.pool.reject(this, obj, code, reason, score);
|
||||
};
|
||||
|
||||
Peer.prototype.__defineGetter__('hostname', function() {
|
||||
var host = this.host;
|
||||
|
||||
if (utils.isIP(host) === 6)
|
||||
host = '[' + host + ']';
|
||||
|
||||
return host + ':' + this.port;
|
||||
});
|
||||
|
||||
/**
|
||||
* Inspect the peer.
|
||||
* @returns {String}
|
||||
|
||||
@ -180,7 +180,7 @@ function Pool(options) {
|
||||
|
||||
// Currently broadcasted objects
|
||||
this.inv = {
|
||||
list: [],
|
||||
items: [],
|
||||
map: {},
|
||||
timeout: options.invTimeout || 60000,
|
||||
interval: options.invInterval || 3000
|
||||
@ -1674,7 +1674,7 @@ Pool.prototype.announce = function announce(msg) {
|
||||
this.peers.load.sendInv(msg);
|
||||
|
||||
for (i = 0; i < this.peers.regular.length; i++)
|
||||
this.peers.all[i].sendInv(msg);
|
||||
this.peers.regular[i].sendInv(msg);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1694,7 +1694,7 @@ Pool.prototype.destroy = function destroy(callback) {
|
||||
|
||||
this.stopSync();
|
||||
|
||||
this.inv.list.slice().forEach(function(entry) {
|
||||
this.inv.items.slice().forEach(function(entry) {
|
||||
entry.finish();
|
||||
});
|
||||
|
||||
@ -2177,7 +2177,7 @@ BroadcastItem.prototype.start = function start() {
|
||||
assert(!this.pool.inv.map[this.hash], 'Already started.');
|
||||
|
||||
this.pool.inv.map[this.hash] = this;
|
||||
utils.binaryInsert(this.pool.inv.list, this, compare);
|
||||
utils.binaryInsert(this.pool.inv.items, this, compare);
|
||||
|
||||
this.refresh();
|
||||
|
||||
@ -2201,8 +2201,7 @@ BroadcastItem.prototype.refresh = function refresh() {
|
||||
self.finish(new Error('Timed out.'));
|
||||
}, this.pool.inv.timeout);
|
||||
|
||||
for (i = 0; i < this.pool.peers.all.length; i++)
|
||||
this.pool.peers.all[i].sendInv(this);
|
||||
this.pool.announce(this);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2220,7 +2219,7 @@ BroadcastItem.prototype.finish = function finish(err) {
|
||||
this.timeout = null;
|
||||
|
||||
delete this.pool.inv.map[this.hash];
|
||||
utils.binaryRemove(this.pool.inv.list, this, compare);
|
||||
utils.binaryRemove(this.pool.inv.items, this, compare);
|
||||
|
||||
for (i = 0; i < this.callback.length; i++)
|
||||
this.callback[i](err);
|
||||
|
||||
@ -865,6 +865,21 @@ utils.parseHost = function parseHost(addr) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Stringify a host.
|
||||
* @param {Seed} seed
|
||||
* @returns {String}
|
||||
*/
|
||||
|
||||
utils.stringifyHost = function stringifyHost(seed) {
|
||||
var host = seed.host;
|
||||
|
||||
if (utils.isIP(host) === 6)
|
||||
host = '[' + host + ']';
|
||||
|
||||
return host + ':' + seed.port;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test whether a string is an IP address.
|
||||
* @param {String?} ip
|
||||
|
||||
Loading…
Reference in New Issue
Block a user