Page 1 of 1

Unable to connect to WAMP from NodeJS

Posted: Mon Apr 24, 2017 11:27 pm
by aspect
I have tried everything and am unable to connect to WAMP from NodeJs. Funny thing is that I see that site UI is connecting properly with same credentials and practically the same code. I tried autobahn and wampy, all with no results. As if the websocket doesn't respond.

Here is some test code:

Code: Select all

var autobahn = require('autobahn');
var wampConnection = null;
var wampUser = 'web';
var wampPassword = wampUser;					

function onChallenge(wampSession, method, extra) {
  console.log("challenge:",arguments);
	if (method == 'wampcra') {
		return autobahn.auth_cra.sign(wampPassword, extra.challenge);
	}
};

function connectionOpen(session, details) {
  console.log("connection open", arguments);
};

wampConnection = new autobahn.Connection({
	url : 'wss://live.prohashing.com:443/ws',
	realm : 'mining',
	authmethods: ['wampcra'],
	authid: wampUser,
	onchallenge: onChallenge
});

wampConnection.onopen = connectionOpen;
wampConnection.open();
Similar code clearly works in the browser, but I am at a loss at this point... any suggestions?

Re: Unable to connect to WAMP from NodeJS

Posted: Tue Apr 25, 2017 7:36 am
by Steve Sokolowski
aspect wrote:I have tried everything and am unable to connect to WAMP from NodeJs. Funny thing is that I see that site UI is connecting properly with same credentials and practically the same code. I tried autobahn and wampy, all with no results. As if the websocket doesn't respond.

Here is some test code:

Code: Select all

var autobahn = require('autobahn');
var wampConnection = null;
var wampUser = 'web';
var wampPassword = wampUser;					

function onChallenge(wampSession, method, extra) {
  console.log("challenge:",arguments);
	if (method == 'wampcra') {
		return autobahn.auth_cra.sign(wampPassword, extra.challenge);
	}
};

function connectionOpen(session, details) {
  console.log("connection open", arguments);
};

wampConnection = new autobahn.Connection({
	url : 'wss://live.prohashing.com:443/ws',
	realm : 'mining',
	authmethods: ['wampcra'],
	authid: wampUser,
	onchallenge: onChallenge
});

wampConnection.onopen = connectionOpen;
wampConnection.open();
Similar code clearly works in the browser, but I am at a loss at this point... any suggestions?
There was someone else here who had this problem, and managed to solve it by running the code in a browser. Since you had the same problem, I think that indicates there is some difference between the browser and node.js and it's important to figure out what it is for this case. Perhaps you could track down the person from that post and figure out who it is?

Also, in your logging statements, you have a variable "arguments" that isn't defined.

Re: Unable to connect to WAMP from NodeJS

Posted: Tue Apr 25, 2017 8:41 am
by aspect
arguments is a JavaScript keyword which contains an object of arguments of the function...

https://developer.mozilla.org/en/docs/W ... /arguments

Re: Unable to connect to WAMP from NodeJS

Posted: Tue Apr 25, 2017 9:32 am
by aspect
Right now, my theory is that either autobahn and wampy packages both use somehow incompatible websocket module or server has some type of cross-origin policy that allows only web browser to connect..

Do you have "Access-Control-Allow-Origin" type of setting in whatever serves the WAMP websocket? what is the language/library/tech that serves your WAMP connections?

Re: Unable to connect to WAMP from NodeJS

Posted: Tue Apr 25, 2017 12:10 pm
by Steve Sokolowski
aspect wrote:Right now, my theory is that either autobahn and wampy packages both use somehow incompatible websocket module or server has some type of cross-origin policy that allows only web browser to connect..

Do you have "Access-Control-Allow-Origin" type of setting in whatever serves the WAMP websocket? what is the language/library/tech that serves your WAMP connections?
Hmmm, I didn't consider that. Let me investigate that and I'll get back to you later in the evening.

Re: Unable to connect to WAMP from NodeJS

Posted: Tue Apr 25, 2017 8:57 pm
by aspect
Found the problem. For any connection using NodeJS, you must enable the following global setting:

Code: Select all

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
This is due to the fact that something is wrong with the SSL certificate on the server - it either doesn't match domain, does not support subdomains, self-generated etc etc.

All is working now. Mind you... way too much data for what this should be... I mean real-time stats are awesome and such, but if for example general_updates would be coming in once every 15-60 sec that would be sufficient.. I am gonna have to imprint this on internal object and then do my own periodic data relay. Maybe it would make sense to implement throttling on your end as well. Would lessen the load on your servers significantly. I've noticed that UI of the site is rather heavy and from what I can see, it is due to that.. from what I see even 5 sec throttling would help significantly..

Re: Unable to connect to WAMP from NodeJS

Posted: Wed Apr 26, 2017 8:12 am
by Steve Sokolowski
aspect wrote:Found the problem. For any connection using NodeJS, you must enable the following global setting:

Code: Select all

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
This is due to the fact that something is wrong with the SSL certificate on the server - it either doesn't match domain, does not support subdomains, self-generated etc etc.

All is working now. Mind you... way too much data for what this should be... I mean real-time stats are awesome and such, but if for example general_updates would be coming in once every 15-60 sec that would be sufficient.. I am gonna have to imprint this on internal object and then do my own periodic data relay. Maybe it would make sense to implement throttling on your end as well. Would lessen the load on your servers significantly. I've noticed that UI of the site is rather heavy and from what I can see, it is due to that.. from what I see even 5 sec throttling would help significantly..
We might be able to throttle it down a little bit, but the problem is that we need this data for debugging. It's not useful to look at CPU usage on one screen and the WAMP data on another and see the CPU usage go up, only to see a 5s average on profitability later. To debug things, we need to be able to correlate issues by time.

The other reason is that people who rely on these updates for NiceHash ordering can't wait for 5s to make decisions based upon this data.

I think that one thing that is happening is that there are updates being sent when a coin reevaluation occurs and there is no change to any field in the data. I just fixed that and I think that it will reduce the amount of data being sent by about 1000 times. Did the problem go away?

I'll also assign a task to Chris to review the SSL certificate configuration.

Re: Unable to connect to WAMP from NodeJS

Posted: Fri Apr 28, 2017 3:50 am
by Chris Sokolowski
We were using a certificate signed by COMODO. I generated a new SSL certificate signed by the EFF. Can you check again to see if this one verifies without changing that config value?