mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-08-23 08:30:51 +00:00
Revert "Add field to server configuration for concurrent connections to the same host"
This reverts commit 348615671a.
This commit is contained in:
@@ -361,10 +361,7 @@ var Remote = function (opts, trace) {
|
||||
|
||||
// Initialize servers
|
||||
opts.servers.forEach(function(server) {
|
||||
var i = typeof server.pool === 'number' ? server.pool : 1;
|
||||
while (i--) {
|
||||
self.add_server(server);
|
||||
}
|
||||
self.add_server(server);
|
||||
});
|
||||
|
||||
// This is used to remove EventEmitter warnings
|
||||
@@ -379,13 +376,13 @@ var Remote = function (opts, trace) {
|
||||
if (!self._transaction_subs && self._online_state === 'open') {
|
||||
self.request_subscribe('transactions').request();
|
||||
}
|
||||
self._transaction_subs += 1;
|
||||
self._transaction_subs += 1;
|
||||
}
|
||||
});
|
||||
|
||||
this.on('removeListener', function (type, listener) {
|
||||
if ('transaction_all' === type) {
|
||||
self._transaction_subs -= 1;
|
||||
self._transaction_subs -= 1;
|
||||
if (!self._transaction_subs && self._online_state === 'open') {
|
||||
self.request_unsubscribe('transactions').request();
|
||||
}
|
||||
@@ -623,8 +620,8 @@ Remote.prototype._handle_message = function (json) {
|
||||
|
||||
// All other messages
|
||||
default:
|
||||
if (this.trace) utils.logObject('remote: ' + message.type+': %s', message);
|
||||
this.emit('net_' + message.type, message);
|
||||
if (this.trace) utils.logObject('remote: '+message.type+': %s', message);
|
||||
this.emit('net_'+message.type, message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -634,8 +631,8 @@ Remote.prototype._handle_message = function (json) {
|
||||
console.log('unexpected message from trusted remote: %s', json);
|
||||
|
||||
(request || this).emit('error', {
|
||||
'error': 'remoteUnexpected',
|
||||
'error_message': 'Unexpected response from remote.'
|
||||
'error' : 'remoteUnexpected',
|
||||
'error_message' : 'Unexpected response from remote.'
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1154,8 +1151,8 @@ Remote.prototype.book = function (currency_gets, issuer_gets, currency_pays, iss
|
||||
// Return the next account sequence if possible.
|
||||
// <-- undefined or Sequence
|
||||
Remote.prototype.account_seq = function (account, advance) {
|
||||
var account = UInt160.json_rewrite(account);
|
||||
var account_info = this.accounts[account];
|
||||
account = UInt160.json_rewrite(account);
|
||||
var account_info = this.accounts[account];
|
||||
var seq;
|
||||
|
||||
if (account_info && account_info.seq) {
|
||||
@@ -1243,7 +1240,7 @@ Remote.prototype.set_secret = function (account, secret) {
|
||||
//
|
||||
// If does not exist: emit('error', 'error' : 'remoteError', 'remote' : { 'error' : 'entryNotFound' })
|
||||
Remote.prototype.request_ripple_balance = function (account, issuer, currency, current) {
|
||||
var request = this.request_ledger_entry('ripple_state'); // YYY Could be cached per ledger.
|
||||
var request = this.request_ledger_entry('ripple_state'); // YYY Could be cached per ledger.
|
||||
|
||||
return request
|
||||
.ripple_state(account, issuer, currency)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util');
|
||||
var WebSocket = require('ws');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util');
|
||||
|
||||
var utils = require('./utils');
|
||||
var utils = require('./utils');
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
@@ -20,7 +19,7 @@ var Server = function (remote, cfg) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
|
||||
if (typeof cfg !== 'object' || typeof cfg.url !== 'string') {
|
||||
if ('object' !== typeof cfg || 'string' !== typeof cfg.url) {
|
||||
throw new Error('Invalid server configuration.');
|
||||
}
|
||||
|
||||
@@ -82,15 +81,12 @@ Server.prototype.connect = function () {
|
||||
// we will automatically reconnect.
|
||||
if (this._connected === true) return;
|
||||
|
||||
if (this._remote.trace) {
|
||||
console.log('server: connect: %s', this._cfg.url);
|
||||
}
|
||||
if (this._remote.trace) console.log('server: connect: %s', this._cfg.url);
|
||||
|
||||
// Ensure any existing socket is given the command to close first.
|
||||
if (this._ws) {
|
||||
this._ws.close();
|
||||
}
|
||||
if (this._ws) this._ws.close();
|
||||
|
||||
var WebSocket = require('ws');
|
||||
var ws = this._ws = new WebSocket(this._cfg.url);
|
||||
|
||||
this._should_connect = true;
|
||||
@@ -112,9 +108,7 @@ Server.prototype.connect = function () {
|
||||
// If we are no longer the active socket, simply ignore any event
|
||||
if (ws !== self._ws) return;
|
||||
|
||||
if (self._remote.trace) {
|
||||
console.log('server: onerror: %s', e.data || e);
|
||||
}
|
||||
if (self._remote.trace) console.log('server: onerror: %s', e.data || e);
|
||||
|
||||
// Most connection errors for WebSockets are conveyed as 'close' events with
|
||||
// code 1006. This is done for security purposes and therefore unlikely to
|
||||
@@ -138,9 +132,7 @@ Server.prototype.connect = function () {
|
||||
// If we are no longer the active socket, simply ignore any event
|
||||
if (ws !== self._ws) return;
|
||||
|
||||
if (self._remote.trace) {
|
||||
console.log('server: onclose: %s', ws.readyState);
|
||||
}
|
||||
if (self._remote.trace) console.log('server: onclose: %s', ws.readyState);
|
||||
|
||||
handleConnectionClose();
|
||||
};
|
||||
@@ -150,17 +142,16 @@ Server.prototype.connect = function () {
|
||||
self._set_state('offline');
|
||||
|
||||
// Prevent additional events from this socket
|
||||
ws.removeAllListeners();
|
||||
ws.on('error', function() {});
|
||||
ws.onopen = ws.onerror = ws.onclose = ws.onmessage = function () {};
|
||||
|
||||
// Should we be connected?
|
||||
if (!self._should_connect) return;
|
||||
|
||||
// Delay and retry.
|
||||
self._retry += 1;
|
||||
|
||||
self._retry += 1;
|
||||
self._retry_timer = setTimeout(function () {
|
||||
if (self._remote.trace) console.log('server: retry');
|
||||
|
||||
if (!self._should_connect) return;
|
||||
self.connect();
|
||||
}, self._retry < 40
|
||||
@@ -170,7 +161,7 @@ Server.prototype.connect = function () {
|
||||
: self._retry < 40+60+60
|
||||
? 10*1000 // Then, for 10 minutes: once every 10 seconds
|
||||
: 30*1000); // Then: once every 30 seconds
|
||||
};
|
||||
}
|
||||
|
||||
ws.onmessage = function (msg) {
|
||||
self.emit('message', msg.data);
|
||||
|
||||
Reference in New Issue
Block a user