Unable to connect to WAMP from NodeJS

Encounter a problem related to the pool or have a request for a feature? Post your issue here and we will help you out.
Forum rules
Welcome to the System Support forum! Encounter a problem related to the pool? Post your issue here and we will help you out.

Keep in mind that the forums are monitored by PROHASHING less closely than the official support channels, so if you have a pressing issue, please submit an official support ticket so that our Support Analyst can look into your issue in a timely manner.

We cannot answer financial questions related to your account on a public forum, so those questions should always be submitted through the orange Support button on prohashing.com/about.

For the full list of PROHASHING forums rules, please visit https://prohashing.com/help/prohashing- ... rms-forums.
Post Reply
aspect
Posts: 6
Joined: Mon Apr 24, 2017 10:08 am

Unable to connect to WAMP from NodeJS

Post by aspect » Mon Apr 24, 2017 11:27 pm

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?
User avatar
Steve Sokolowski
Posts: 4585
Joined: Wed Aug 27, 2014 3:27 pm
Location: State College, PA

Re: Unable to connect to WAMP from NodeJS

Post by Steve Sokolowski » Tue Apr 25, 2017 7:36 am

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.
aspect
Posts: 6
Joined: Mon Apr 24, 2017 10:08 am

Re: Unable to connect to WAMP from NodeJS

Post by aspect » Tue Apr 25, 2017 8:41 am

arguments is a JavaScript keyword which contains an object of arguments of the function...

https://developer.mozilla.org/en/docs/W ... /arguments
aspect
Posts: 6
Joined: Mon Apr 24, 2017 10:08 am

Re: Unable to connect to WAMP from NodeJS

Post by aspect » Tue Apr 25, 2017 9:32 am

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?
User avatar
Steve Sokolowski
Posts: 4585
Joined: Wed Aug 27, 2014 3:27 pm
Location: State College, PA

Re: Unable to connect to WAMP from NodeJS

Post by Steve Sokolowski » Tue Apr 25, 2017 12:10 pm

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.
aspect
Posts: 6
Joined: Mon Apr 24, 2017 10:08 am

Re: Unable to connect to WAMP from NodeJS

Post by aspect » Tue Apr 25, 2017 8:57 pm

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..
User avatar
Steve Sokolowski
Posts: 4585
Joined: Wed Aug 27, 2014 3:27 pm
Location: State College, PA

Re: Unable to connect to WAMP from NodeJS

Post by Steve Sokolowski » Wed Apr 26, 2017 8:12 am

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.
User avatar
Chris Sokolowski
Site Admin
Posts: 945
Joined: Wed Aug 27, 2014 12:47 pm
Location: State College, PA

Re: Unable to connect to WAMP from NodeJS

Post by Chris Sokolowski » Fri Apr 28, 2017 3:50 am

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?
Post Reply