browser: add dns resolution.
This commit is contained in:
parent
2c2ad461af
commit
5683d708dd
@ -178,7 +178,7 @@ function formatWallet(wallet) {
|
||||
html += 'Current Address: <b>' + wallet.getAddress() + '</b><br>';
|
||||
}
|
||||
|
||||
html += 'Extended Private Key: <b>' + key.toBase58() + '</b><br>';
|
||||
html += 'Extended Private Key: <b>' + key.xprivkey + '</b><br>';
|
||||
html += 'Mnemonic: <b>' + key.mnemonic.phrase + '</b><br>';
|
||||
|
||||
wallet.getBalance().then(function(balance) {
|
||||
@ -215,7 +215,7 @@ options = bcoin.config({
|
||||
network: 'segnet4',
|
||||
db: 'leveldb',
|
||||
useWorkers: true,
|
||||
coinCache: true,
|
||||
coinCache: 30000000,
|
||||
logger: logger
|
||||
});
|
||||
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var net = require('net');
|
||||
var dns = require('dns');
|
||||
var IOServer = require('socket.io');
|
||||
var util = require('../lib/utils/util');
|
||||
var IP = require('../lib/utils/ip');
|
||||
var BufferWriter = require('../lib/utils/writer');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var NAME_REGEX = /^[a-z0-9\-\.]+?\.(?:be|me|org|com|net|ch|de)$/i;
|
||||
|
||||
var TARGET = new Buffer(
|
||||
'0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
||||
'hex');
|
||||
@ -61,6 +64,41 @@ WSProxy.prototype._handleSocket = function _handleSocket(ws) {
|
||||
ws.on('tcp connect', function(port, host, nonce) {
|
||||
self._handleConnect(ws, port, host, nonce);
|
||||
});
|
||||
|
||||
ws.on('dns resolve', function(name, record, callback) {
|
||||
self._handleResolve(ws, name, record, callback);
|
||||
});
|
||||
};
|
||||
|
||||
WSProxy.prototype._handleResolve = function _handleResolve(ws, name, record, callback) {
|
||||
if (typeof name !== 'string') {
|
||||
ws.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof record !== 'string') {
|
||||
ws.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
ws.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NAME_REGEX.test(name) || name.length > 200) {
|
||||
this.log('Client sent a bad domain: %s.', name);
|
||||
ws.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
dns.resolve(name, record, function(err, result) {
|
||||
if (err) {
|
||||
callback({ message: err.message, code: err.code });
|
||||
return;
|
||||
}
|
||||
callback(null, result);
|
||||
});
|
||||
};
|
||||
|
||||
WSProxy.prototype._handleConnect = function _handleConnect(ws, port, host, nonce) {
|
||||
@ -84,7 +122,7 @@ WSProxy.prototype._handleConnect = function _handleConnect(ws, port, host, nonce
|
||||
|
||||
if (this.pow) {
|
||||
if (!util.isNumber(nonce)) {
|
||||
this.log('Client did not solve proof of work.', state.host);
|
||||
this.log('Client did not solve proof of work (%s).', state.host);
|
||||
ws.emit('tcp close');
|
||||
ws.disconnect();
|
||||
return;
|
||||
|
||||
@ -6,6 +6,26 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
exports.resolve = function resolve(host) {
|
||||
return Promise.reject(new Error('No DNS results.'));
|
||||
var ProxySocket = require('./proxysocket');
|
||||
var socket;
|
||||
|
||||
exports.resolve = function resolve(host, proxy) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!socket)
|
||||
socket = new ProxySocket(proxy);
|
||||
|
||||
socket.resolve(host, 'A', function(err, result) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.length === 0) {
|
||||
reject(new Error('No DNS results.'));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -10,4 +10,3 @@ exports.Peer = require('./peer');
|
||||
exports.Pool = require('./pool');
|
||||
exports.tcp = require('./tcp');
|
||||
exports.dns = require('./dns');
|
||||
exports.time = require('./time');
|
||||
|
||||
@ -2166,6 +2166,7 @@ function HostList(pool) {
|
||||
this.network = pool.network;
|
||||
this.logger = pool.logger;
|
||||
this.maxOutbound = pool.maxOutbound;
|
||||
this.proxyServer = pool.proxyServer;
|
||||
this.list = new List();
|
||||
this.seeds = [];
|
||||
this.map = {};
|
||||
@ -2381,7 +2382,7 @@ HostList.prototype.populate = co(function* populate(seed) {
|
||||
this.logger.info('Resolving hosts from seed: %s.', seed.host);
|
||||
|
||||
try {
|
||||
hosts = yield dns.resolve(seed.host);
|
||||
hosts = yield dns.resolve(seed.host, this.proxyServer);
|
||||
} catch (e) {
|
||||
this.logger.error(e);
|
||||
return;
|
||||
|
||||
@ -92,6 +92,19 @@ ProxySocket.prototype._init = function _init() {
|
||||
});
|
||||
};
|
||||
|
||||
ProxySocket.prototype.resolve = function resolve(name, record, callback) {
|
||||
var e;
|
||||
this.socket.emit('dns resolve', name, record, function(err, results) {
|
||||
if (err) {
|
||||
e = new Error(err.message);
|
||||
e.code = err.code || null;
|
||||
callback(e);
|
||||
return;
|
||||
}
|
||||
callback(null, results);
|
||||
});
|
||||
};
|
||||
|
||||
ProxySocket.prototype.connect = function connect(port, host) {
|
||||
var nonce = 0;
|
||||
var i, pow;
|
||||
@ -104,8 +117,10 @@ ProxySocket.prototype.connect = function connect(port, host) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.info)
|
||||
return this.once('info', connect.bind(this, port, host));
|
||||
if (!this.info) {
|
||||
this.once('info', connect.bind(this, port, host));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.info.pow) {
|
||||
util.log(
|
||||
|
||||
@ -3,3 +3,4 @@
|
||||
exports.constants = require('./constants');
|
||||
exports.networks = require('./networks');
|
||||
exports.Network = require('./network');
|
||||
exports.timedata = require('./timedata');
|
||||
|
||||
@ -12,6 +12,7 @@ exports.lazy = require('./lazy');
|
||||
exports.Locker = require('./locker');
|
||||
exports.MappedLocker = exports.Locker.Mapped;
|
||||
exports.LRU = require('./lru');
|
||||
exports.List = require('./list');
|
||||
exports.murmur3 = require('./murmur3');
|
||||
exports.nextTick = require('./nexttick');
|
||||
exports.nfkd = require('./nfkd');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user