Merge pull request #438 from reedrosenbluth/proxy

Proxy Support
This commit is contained in:
Chris Clark
2015-07-20 18:22:59 -07:00
3 changed files with 57 additions and 12 deletions

50
npm-shrinkwrap.json generated
View File

@@ -9,12 +9,12 @@
"resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz"
},
"babel-runtime": {
"version": "5.4.7",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-5.4.7.tgz",
"version": "5.7.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-5.7.0.tgz",
"dependencies": {
"core-js": {
"version": "0.9.13",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-0.9.13.tgz"
"version": "0.9.18",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-0.9.18.tgz"
}
}
},
@@ -26,6 +26,36 @@
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-1.2.1.tgz"
},
"https-proxy-agent": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-1.0.0.tgz",
"dependencies": {
"agent-base": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-2.0.0.tgz",
"dependencies": {
"semver": {
"version": "4.3.6",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz"
}
}
},
"debug": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
"dependencies": {
"ms": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz"
}
}
},
"extend": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.0.tgz"
}
}
},
"is-my-json-valid": {
"version": "2.12.0",
"resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.12.0.tgz",
@@ -55,8 +85,8 @@
}
},
"lodash": {
"version": "3.9.3",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.9.3.tgz"
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.0.tgz"
},
"lru-cache": {
"version": "2.5.2",
@@ -82,12 +112,10 @@
},
"sjcl-extended": {
"version": "1.0.3",
"from": "ripple/sjcl-extended#1.0.3",
"resolved": "git://github.com/ripple/sjcl-extended.git#908218e0db4fccd08c4e3f1f7269b72f8d93c270",
"resolved": "git://github.com/ripple/sjcl-extended.git#d8cf8b22e7d97193c54e1f65113e3edcf200ca17",
"dependencies": {
"sjcl": {
"version": "1.0.3",
"from": "sjcl@>=1.0.3 <2.0.0",
"resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.3.tgz"
}
}
@@ -115,8 +143,8 @@
"resolved": "https://registry.npmjs.org/options/-/options-0.0.6.tgz"
},
"ultron": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.1.tgz"
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz"
},
"utf-8-validate": {
"version": "1.1.0",

View File

@@ -19,6 +19,7 @@
"babel-runtime": "^5.5.4",
"bignumber.js": "^2.0.3",
"extend": "~1.2.1",
"https-proxy-agent": "^1.0.0",
"is-my-json-valid": "^2.12.0",
"lodash": "^3.1.0",
"lru-cache": "~2.5.0",

View File

@@ -3,6 +3,7 @@
const _ = require('lodash');
const util = require('util');
const url = require('url');
const HttpsProxyAgent = require('https-proxy-agent');
const LRU = require('lru-cache');
const EventEmitter = require('events').EventEmitter;
const RippleError = require('./').RippleError;
@@ -436,7 +437,18 @@ Server.prototype.connect = function() {
log.info(this.getServerID(), 'connect');
}
const ws = this._ws = new WebSocket(this._opts.url);
if (this._remote.hasOwnProperty('proxy')) {
const parsed = url.parse(this._opts.url);
const opts = url.parse(this._remote.proxy);
opts.secureEndpoint = parsed.protocol === 'wss:';
const agent = new HttpsProxyAgent(opts);
this._ws = new WebSocket(this._opts.url, {agent: agent});
} else {
this._ws = new WebSocket(this._opts.url);
}
const ws = this._ws;
this._shouldConnect = true;
@@ -521,6 +533,8 @@ Server.prototype._retryConnect = function() {
this._retry += 1;
/*eslint-disable */
const retryTimeout = (this._retry < 40)
// First, for 2 seconds: 20 times per second
? (1000 / 20)
@@ -533,6 +547,8 @@ Server.prototype._retryConnect = function() {
// Then: once every 30 seconds
: (30 * 1000);
/*eslint-enable */
function connectionRetry() {
if (self._shouldConnect) {
if (self._remote.trace) {