peer: remove _getOwnIP.
Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
d0b14008d0
commit
b2c4af302d
@ -1,7 +1,6 @@
|
|||||||
var inherits = require('inherits');
|
var inherits = require('inherits');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
var os = require('os');
|
|
||||||
|
|
||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
@ -340,7 +339,6 @@ Peer.prototype._handlePong = function handlePong() {
|
|||||||
|
|
||||||
Peer.prototype._handleGetAddr = function handleGetAddr() {
|
Peer.prototype._handleGetAddr = function handleGetAddr() {
|
||||||
var used = [];
|
var used = [];
|
||||||
var own = this._getOwnIP();
|
|
||||||
var peers = [].concat(
|
var peers = [].concat(
|
||||||
this.pool.peers.pending,
|
this.pool.peers.pending,
|
||||||
this.pool.peers.block,
|
this.pool.peers.block,
|
||||||
@ -371,8 +369,6 @@ Peer.prototype._handleGetAddr = function handleGetAddr() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (own) peers.push(own);
|
|
||||||
|
|
||||||
peers = peers.map(function(peer) {
|
peers = peers.map(function(peer) {
|
||||||
if (peer.ver === 6) {
|
if (peer.ver === 6) {
|
||||||
while (peer.ipv6.split(':').length < 8) {
|
while (peer.ipv6.split(':').length < 8) {
|
||||||
@ -402,58 +398,6 @@ Peer.prototype._handleGetAddr = function handleGetAddr() {
|
|||||||
return this._write(this.framer.addr(peers));
|
return this._write(this.framer.addr(peers));
|
||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype._getOwnIP = function getOwnIP() {
|
|
||||||
var interfaces = os.networkInterfaces()
|
|
||||||
, eth
|
|
||||||
, ipv4
|
|
||||||
, ipv6
|
|
||||||
, ip
|
|
||||||
, p4
|
|
||||||
, p6
|
|
||||||
, l;
|
|
||||||
|
|
||||||
ip = {
|
|
||||||
ipv4: '127.0.0.1',
|
|
||||||
ipv6: '0000:0000:0000:0000:0000:0000:0000:ffff',
|
|
||||||
port: 8333,
|
|
||||||
ver: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
eth = (interfaces.eth0 && interfaces.eth0.length >= 2 && interfaces.eth0)
|
|
||||||
|| (interfaces.wlan0 && interfaces.wlan0.length >= 2 && interfaces.wlan0)
|
|
||||||
|| interfaces[Object.keys(interfaces).pop()]
|
|
||||||
|| [{ address: '127.0.0.1' }, { address: '::1' }];
|
|
||||||
|
|
||||||
ipv4 = eth[0] ? eth[0].address : '127.0.0.1';
|
|
||||||
ipv6 = eth[1] ? eth[1].address : '0000:0000:0000:0000:0000:0000:0000:ffff';
|
|
||||||
|
|
||||||
p4 = ipv4.split('.').map(function(n) { return +n; });
|
|
||||||
p6 = ipv6.split(':').map(function(n) {
|
|
||||||
return parseInt(n, 16);
|
|
||||||
}).reduce(function(out, n) {
|
|
||||||
out.push((n >> 8) & 0xff);
|
|
||||||
out.push(n & 0xff);
|
|
||||||
return out;
|
|
||||||
}, []);
|
|
||||||
l = p6.length;
|
|
||||||
|
|
||||||
// Try to figure out if we're behind a NAT or not public for some reason.
|
|
||||||
if ((p4[0] !== 127 && p4[1] !== 0 && p4[2] !== 0)
|
|
||||||
&& (p4[0] !== 10 && p4[1] !== 0)
|
|
||||||
&& (p4[0] !== 168 && p4[1] !== 0)) {
|
|
||||||
ip.ipv4 = ipv4;
|
|
||||||
ip.ver = 4;
|
|
||||||
} else if ((p6[0] !== 0 && p6[1] !== 0 && p6[2] !== 1)
|
|
||||||
&& (p6[l-1] !== 0xff && p6[l-2] !== 0xff && p6[l-3] !== 0xff)) {
|
|
||||||
ip.ipv6 = ipv6;
|
|
||||||
ip.ver = 6;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ip;
|
|
||||||
};
|
|
||||||
|
|
||||||
Peer.prototype._handleInv = function handleInv(items) {
|
Peer.prototype._handleInv = function handleInv(items) {
|
||||||
// Always request advertised TXs
|
// Always request advertised TXs
|
||||||
var txs = items.filter(function(item) {
|
var txs = items.filter(function(item) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user