Skip to content

Commit

Permalink
Allow SushiPoolMiner to switch host when losing connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkha committed Apr 18, 2019
1 parent dd87052 commit 4ddf093
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hiveos/h-manifest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CUSTOM_NAME=sushi-miner-cuda

# Optional version of your custom miner package
CUSTOM_VERSION=2.0.0
CUSTOM_VERSION=2.0.1

# Full path to miner config file
CUSTOM_CONFIG_FILENAME=/hive/miners/custom/${CUSTOM_NAME}/miner.conf
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sushi-miner-cuda",
"version": "2.0.0",
"version": "2.0.1",
"main": "index.js",
"homepage": "https://sushipool.com/",
"description": "",
Expand Down
8 changes: 6 additions & 2 deletions src/SushiPoolMiner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const crypto = require('crypto');
const Nimiq = require('@nimiq/core');
const Miner = require('./Miner');
const WebSocket = require('ws');
const Utils = require('./Utils');

const GENESIS_HASH_MAINNET = 'Jkqvik+YKKdsVQY12geOtGYwahifzANxC+6fZJyGnRI=';

Expand Down Expand Up @@ -43,10 +44,13 @@ class SushiPoolMiner extends Nimiq.Observable {

this._ws.on('close', (code, reason) => {
let timeout = Math.floor(Math.random() * 25) + 5;
Nimiq.Log.w(SushiPoolMiner, `Connection lost. Reconnecting in ${timeout} seconds`);
this._host = Utils.getNewHost(this._host);
Nimiq.Log.w(SushiPoolMiner, `Connection lost. Reconnecting in ${timeout} seconds to ${this._host}`);
this._stopMining();
if (!this._closed) {
setTimeout(() => this.connect(host, port), timeout * 1000);
setTimeout(() => {
this.connect(this._host, port);
}, timeout * 1000);
}
});

Expand Down
17 changes: 17 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ exports.readConfigFile = function (fileName) {
}
}

exports.getNewHost = function(currentHost) {
const FALLBACK_HOSTS = [
'eu.sushipool.com',
'us.sushipool.com',
'asia.sushipool.com'
];
let idx = FALLBACK_HOSTS.indexOf(currentHost);
if (idx !== -1) {
// if current host is found in fallback hosts, then try the next one
idx = (idx + 1) % FALLBACK_HOSTS.length;
} else { // otherwise just randomly choose one fallback host
idx = Math.floor(Math.random() * FALLBACK_HOSTS.length);
}
const newHost = FALLBACK_HOSTS[idx];
return newHost;
}

exports.getDeviceOptions = function (config) {
const devices = Array.isArray(config.devices) ? config.devices : [];
const memory = Array.isArray(config.memory) ? config.memory : [];
Expand Down

0 comments on commit 4ddf093

Please sign in to comment.