net: handle public ip and port better.
This commit is contained in:
parent
dc839062bf
commit
b212eed282
@ -1,66 +1,105 @@
|
|||||||
# Sample bcoin config file (~/.bcoin/bcoin.conf)
|
# Sample bcoin config file (~/.bcoin/bcoin.conf)
|
||||||
|
|
||||||
|
#
|
||||||
# Options
|
# Options
|
||||||
network: main
|
#
|
||||||
|
|
||||||
|
# network: main
|
||||||
use-workers: true
|
use-workers: true
|
||||||
# max-workers: 4
|
# max-workers: 4
|
||||||
# worker-timeout: 5000
|
# worker-timeout: 5000
|
||||||
# sigcache-size: 50000
|
# sigcache-size: 50000
|
||||||
|
|
||||||
|
#
|
||||||
# Node
|
# Node
|
||||||
|
#
|
||||||
|
|
||||||
prefix: ~/.bcoin
|
prefix: ~/.bcoin
|
||||||
db: leveldb
|
db: leveldb
|
||||||
max-files: 64
|
max-files: 64
|
||||||
cache-size: 100
|
cache-size: 100
|
||||||
# fast: false
|
fast: false
|
||||||
|
|
||||||
|
#
|
||||||
# Logger
|
# Logger
|
||||||
|
#
|
||||||
|
|
||||||
log-level: debug
|
log-level: debug
|
||||||
log-console: true
|
log-console: true
|
||||||
log-file: true
|
log-file: true
|
||||||
|
|
||||||
|
#
|
||||||
# Chain
|
# Chain
|
||||||
# witness: true
|
#
|
||||||
# prune: false
|
|
||||||
|
witness: true
|
||||||
|
prune: false
|
||||||
use-checkpoints: true
|
use-checkpoints: true
|
||||||
coin-cache: 40
|
coin-cache: 40
|
||||||
index-tx: false
|
index-tx: false
|
||||||
index-address: false
|
index-address: false
|
||||||
|
|
||||||
|
#
|
||||||
# Mempool
|
# Mempool
|
||||||
# limit-free: true
|
#
|
||||||
# limit-free-relay: 15
|
|
||||||
# reject-absurd-fees: true
|
|
||||||
# replace-by-fee: false
|
|
||||||
|
|
||||||
|
limit-free: true
|
||||||
|
limit-free-relay: 15
|
||||||
|
reject-absurd-fees: true
|
||||||
|
replace-by-fee: false
|
||||||
|
|
||||||
|
#
|
||||||
# Pool
|
# Pool
|
||||||
# selfish: false
|
#
|
||||||
headers: false
|
|
||||||
|
selfish: false
|
||||||
|
headers: true
|
||||||
compact: true
|
compact: true
|
||||||
bip151: true
|
bip151: true
|
||||||
# proxy-server: localhost
|
no-discovery: false
|
||||||
# preferred-seed: seed.bitcoin.sipa.be
|
|
||||||
# no-discovery: false
|
|
||||||
# port: 8333
|
|
||||||
listen: true
|
listen: true
|
||||||
max-outbound: 8
|
max-outbound: 8
|
||||||
max-inbound: 30
|
max-inbound: 30
|
||||||
|
|
||||||
|
# Websocket Proxy Server (Browser Only)
|
||||||
|
proxy-server: localhost
|
||||||
|
|
||||||
|
# Custom list of DNS seeds
|
||||||
|
# seeds: seed.bitcoin.sipa.be
|
||||||
|
|
||||||
|
# Local Host & Port (to listen on)
|
||||||
|
host: ::
|
||||||
|
# port: 8333
|
||||||
|
|
||||||
|
# Public Host & Port (to advertise to peers)
|
||||||
|
# public-host: 0.0.0.0
|
||||||
|
# public-port: 8444
|
||||||
|
|
||||||
|
# BIP151 AuthDB and Identity Key
|
||||||
bip150: false
|
bip150: false
|
||||||
identity-key: 74b4147957813b62cc8987f2b711ddb31f8cb46dcbf71502033da66053c8780a
|
identity-key: 74b4147957813b62cc8987f2b711ddb31f8cb46dcbf71502033da66053c8780a
|
||||||
auth-peers: ./authorized-peers
|
auth-peers: ./authorized-peers
|
||||||
known-peers: ./known-peers
|
known-peers: ./known-peers
|
||||||
|
|
||||||
|
# Always try to connect to these nodes.
|
||||||
# nodes: 127.0.0.1,127.0.0.2
|
# nodes: 127.0.0.1,127.0.0.2
|
||||||
|
|
||||||
|
#
|
||||||
# Miner
|
# Miner
|
||||||
# payout-address: 1111111111111111111114oLvT2
|
#
|
||||||
# coinbase-flags: mined by bcoin
|
|
||||||
|
|
||||||
|
coinbase-flags: mined by bcoin
|
||||||
|
# payout-address: 1111111111111111111114oLvT2,1111111111111111111114oLvT2
|
||||||
|
|
||||||
|
#
|
||||||
# HTTP
|
# HTTP
|
||||||
|
#
|
||||||
|
|
||||||
|
http-host: ::
|
||||||
|
# http-port: 8332
|
||||||
# ssl-cert: @/ssl/cert.crt
|
# ssl-cert: @/ssl/cert.crt
|
||||||
# ssl-key: @/ssl/priv.key
|
# ssl-key: @/ssl/priv.key
|
||||||
# http-port: 8332
|
service-key: bikeshed
|
||||||
# http-host: 0.0.0.0
|
|
||||||
# service-key: bikeshed
|
|
||||||
api-key: bikeshed
|
api-key: bikeshed
|
||||||
wallet-auth: false
|
wallet-auth: false
|
||||||
# no-auth: false
|
no-auth: false
|
||||||
|
|||||||
@ -13,7 +13,7 @@ var RPCClient = require('./rpcclient');
|
|||||||
var Amount = require('../btc/amount');
|
var Amount = require('../btc/amount');
|
||||||
var util = require('../utils/util');
|
var util = require('../utils/util');
|
||||||
var co = require('../utils/co');
|
var co = require('../utils/co');
|
||||||
var request = require('./request').promise;
|
var request = require('./request');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BCoin HTTP client.
|
* BCoin HTTP client.
|
||||||
|
|||||||
@ -507,49 +507,35 @@ Request.prototype._onEnd = function _onEnd(err) {
|
|||||||
* @param {String?} options.expect - Type to expect (see options.type).
|
* @param {String?} options.expect - Type to expect (see options.type).
|
||||||
* Error will be returned if the response is not of this type.
|
* Error will be returned if the response is not of this type.
|
||||||
* @param {Number?} options.limit - Byte limit on response.
|
* @param {Number?} options.limit - Byte limit on response.
|
||||||
* @param {Function?} callback - Will return a stream if not present.
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function request(options, callback) {
|
function request(options) {
|
||||||
var stream;
|
|
||||||
|
|
||||||
if (!callback) {
|
|
||||||
stream = new Request(options);
|
|
||||||
stream.start();
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof options === 'string')
|
if (typeof options === 'string')
|
||||||
options = { uri: options };
|
options = { uri: options };
|
||||||
|
|
||||||
options.buffer = true;
|
options.buffer = true;
|
||||||
|
|
||||||
stream = new Request(options);
|
return new Promise(function(resolve, reject) {
|
||||||
|
var stream = new Request(options);
|
||||||
|
|
||||||
stream.on('error', function(err) {
|
stream.on('error', function(err) {
|
||||||
callback(err);
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('end', function() {
|
||||||
|
resolve(stream);
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.start();
|
||||||
|
stream.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('end', function() {
|
|
||||||
callback(null, stream, stream.body);
|
|
||||||
});
|
|
||||||
|
|
||||||
stream.start();
|
|
||||||
stream.end();
|
|
||||||
|
|
||||||
return stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
request.promise = function promise(options) {
|
request.stream = function _stream(options) {
|
||||||
return new Promise(function(resolve, reject) {
|
var stream = new Request(options);
|
||||||
request(options, function(err, res) {
|
stream.start();
|
||||||
if (err) {
|
return stream;
|
||||||
reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(res);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -45,7 +45,7 @@ function RPCClient(options) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
RPCClient.prototype.call = co(function* call(method, params) {
|
RPCClient.prototype.call = co(function* call(method, params) {
|
||||||
var res = yield request.promise({
|
var res = yield request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
uri: this.uri,
|
uri: this.uri,
|
||||||
pool: true,
|
pool: true,
|
||||||
|
|||||||
@ -516,8 +516,14 @@ MinerOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.version = options.version;
|
this.version = options.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.address)
|
if (options.address) {
|
||||||
this.addresses.push(new Address(options.address));
|
if (Array.isArray(options.address)) {
|
||||||
|
for (i = 0; i < options.address.length; i++)
|
||||||
|
this.addresses.push(new Address(options.address[i]));
|
||||||
|
} else {
|
||||||
|
this.addresses.push(new Address(options.address));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (options.addresses) {
|
if (options.addresses) {
|
||||||
assert(Array.isArray(options.addresses));
|
assert(Array.isArray(options.addresses));
|
||||||
|
|||||||
@ -396,7 +396,7 @@ Pool.prototype.listen = co(function* listen() {
|
|||||||
if (!this.options.listen)
|
if (!this.options.listen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
yield this.server.listen(this.address.port, '0.0.0.0');
|
yield this.server.listen(this.options.port, this.options.host);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3083,7 +3083,7 @@ Pool.prototype.getIP = co(function* getIP() {
|
|||||||
throw new Error('Could not find IP.');
|
throw new Error('Could not find IP.');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res = yield request.promise({
|
res = yield request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: 'http://icanhazip.com',
|
uri: 'http://icanhazip.com',
|
||||||
expect: 'txt',
|
expect: 'txt',
|
||||||
@ -3112,7 +3112,7 @@ Pool.prototype.getIP2 = co(function* getIP2() {
|
|||||||
if (request.unsupported)
|
if (request.unsupported)
|
||||||
throw new Error('Could not find IP.');
|
throw new Error('Could not find IP.');
|
||||||
|
|
||||||
res = yield request.promise({
|
res = yield request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: 'http://checkip.dyndns.org',
|
uri: 'http://checkip.dyndns.org',
|
||||||
expect: 'html',
|
expect: 'html',
|
||||||
@ -3263,12 +3263,26 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
|
|
||||||
if (options.host != null) {
|
if (options.host != null) {
|
||||||
assert(typeof options.host === 'string');
|
assert(typeof options.host === 'string');
|
||||||
this.host = options.host;
|
assert(IP.version(options.host) !== -1, '`host` must be an IP.');
|
||||||
|
this.host = IP.normalize(options.host);
|
||||||
|
if (IP.isRoutable(this.host))
|
||||||
|
this.address.setHost(this.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.port != null) {
|
if (options.port != null) {
|
||||||
assert(typeof options.port === 'number');
|
assert(typeof options.port === 'number');
|
||||||
this.port = options.port;
|
this.port = options.port;
|
||||||
|
this.address.setPort(this.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.publicHost != null) {
|
||||||
|
assert(typeof options.publicHost === 'string');
|
||||||
|
this.address.setHost(options.publicHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.publicPort != null) {
|
||||||
|
assert(typeof options.port === 'number');
|
||||||
|
this.address.setPort(options.publicPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.maxOutbound != null) {
|
if (options.maxOutbound != null) {
|
||||||
@ -3410,7 +3424,7 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.requiredServices = options.requiredServices;
|
this.requiredServices = options.requiredServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.address.fromOptions(this);
|
this.address.services = this.services;
|
||||||
this.address.ts = this.network.now();
|
this.address.ts = this.network.now();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@ -199,13 +199,16 @@ config.parseData = function parseData(data, prefix, dirname) {
|
|||||||
options.maxOutbound = num(data.maxoutbound);
|
options.maxOutbound = num(data.maxoutbound);
|
||||||
options.maxInbound = num(data.maxinbound);
|
options.maxInbound = num(data.maxinbound);
|
||||||
options.noDiscovery = bool(data.nodiscovery);
|
options.noDiscovery = bool(data.nodiscovery);
|
||||||
|
options.publicHost = str(data.publichost);
|
||||||
|
options.publicPort = num(data.publicport);
|
||||||
|
options.host = str(data.host);
|
||||||
options.port = num(data.port);
|
options.port = num(data.port);
|
||||||
options.listen = bool(data.listen);
|
options.listen = bool(data.listen);
|
||||||
options.knownPeers = file(data.knownpeers, prefix, dirname, 'utf8');
|
options.knownPeers = file(data.knownpeers, prefix, dirname, 'utf8');
|
||||||
options.authPeers = file(data.authpeers, prefix, dirname, 'utf8');
|
options.authPeers = file(data.authpeers, prefix, dirname, 'utf8');
|
||||||
|
|
||||||
// Miner
|
// Miner
|
||||||
options.payoutAddress = str(data.payoutaddress);
|
options.payoutAddress = list(data.payoutaddress);
|
||||||
options.coinbaseFlags = str(data.coinbaseflags);
|
options.coinbaseFlags = str(data.coinbaseflags);
|
||||||
|
|
||||||
// HTTP
|
// HTTP
|
||||||
|
|||||||
@ -115,6 +115,9 @@ function FullNode(options) {
|
|||||||
seeds: this.options.seeds,
|
seeds: this.options.seeds,
|
||||||
nodes: this.options.nodes,
|
nodes: this.options.nodes,
|
||||||
noDiscovery: this.options.noDiscovery,
|
noDiscovery: this.options.noDiscovery,
|
||||||
|
publicHost: this.options.publicHost,
|
||||||
|
publicPort: this.options.publicPort,
|
||||||
|
host: this.options.host,
|
||||||
port: this.options.port,
|
port: this.options.port,
|
||||||
listen: this.options.listen
|
listen: this.options.listen
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user