Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Usable port for wallet-service
Browse files Browse the repository at this point in the history
  • Loading branch information
davehlong committed Jul 22, 2019
1 parent e083cbd commit 2cb8af6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
11 changes: 11 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ function storeNodeList(pnodes) {

let validNodes = [];
pnodes.forEach(node => {
if(node.hasOwnProperty('cache')) {
if (!config.remoteNodeCacheSupported && true === node.cache) {
return;
}
}
if(node.hasOwnProperty('ssl')) {
if (!config.remoteNodeSslSupported && true === node.ssl) {
return;
}
}

let item = `${node.url}:${node.port}`;
validNodes.push(item);
});
Expand Down
12 changes: 1 addition & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 28 additions & 7 deletions src/js/ws_manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const fs = require('fs');
const os = require('os');
const net = require('net');
const childProcess = require('child_process');
const log = require('electron-log');
const Store = require('electron-store');
Expand All @@ -20,6 +21,7 @@ const SERVICE_LOG_DEBUG = wsession.get('debug');
const SERVICE_LOG_LEVEL_DEFAULT = 0;
const SERVICE_LOG_LEVEL_DEBUG = 5;
const SERVICE_LOG_LEVEL = (SERVICE_LOG_DEBUG ? SERVICE_LOG_LEVEL_DEBUG : SERVICE_LOG_LEVEL_DEFAULT);
const SERVICE_MIN_LISTEN_PORT = 10101;

const ERROR_WALLET_EXEC = `Failed to start ${config.walletServiceBinaryFilename}. Set the path to ${config.walletServiceBinaryFilename} properly in the settings tab.`;
const ERROR_WALLET_PASSWORD = 'Failed to load your wallet, please check your password';
Expand Down Expand Up @@ -54,16 +56,32 @@ var PlenteumWalletManager = function () {
this.fusionTxHash = [];
};

PlenteumWalletManager.prototype.getUnusedPort = function() {
let port = SERVICE_MIN_LISTEN_PORT;
const server = net.createServer();
return new Promise((resolve, reject) => server
.on('error', error => error.code === 'EADDRINUSE' ? server.listen(++port) : reject(error))
.on('listening', () => server.close(() => resolve(port)))
.listen(port));
};

PlenteumWalletManager.prototype.init = function () {
this._getSettings();
if (this.serviceApi !== null) return;

let cfg = {
service_host: this.serviceHost,
service_port: this.servicePort,
service_password: this.servicePassword
};
this.serviceApi = new PlenteumWalletApi(cfg);
this.getUnusedPort().then(port => {
console.log(`${port} is available`);
this.servicePort = port;
let cfg = {
service_host: this.serviceHost,
service_port: this.servicePort,
service_password: this.servicePassword
};
this.serviceApi = new PlenteumWalletApi(cfg);
}).catch((err) => {
log.error("Unable to find a port to listen to, please check your firewall settings");
log.error(err.message);
});
};

PlenteumWalletManager.prototype._getSettings = function () {
Expand Down Expand Up @@ -164,6 +182,7 @@ PlenteumWalletManager.prototype.startService = function (walletFile, password, o
let serviceArgs = this.serviceArgsDefault.concat([
'-w', walletFile,
'-p', password,
'--bind-port', this.servicePort,
'--log-level', 0,
'--log-file', path.join(remote.app.getPath('temp'), 'ts.log'), // macOS failed without this
'--address'
Expand Down Expand Up @@ -216,11 +235,13 @@ PlenteumWalletManager.prototype._spawnService = function (walletFile, password,
let serviceArgs = this.serviceArgsDefault.concat([
'--container-file', walletFile,
'--container-password', password,
'--bind-port', this.servicePort,
'--enable-cors', '*',
'--daemon-address', this.daemonHost,
'--daemon-port', this.daemonPort,
'--log-level', SERVICE_LOG_LEVEL,
'--log-file', logFile
'--log-file', logFile,
'--init-timeout', timeout
]);


Expand Down
6 changes: 6 additions & 0 deletions src/js/wsui_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,7 @@ function handleWalletOpen() {
wsutil.showToast('Network connectivity problem detected, node list update can not be performed');
return;
}

if (!confirm("Refreshing node list may take a while to complete, are you sure?")) return;
fetchNodeInfo(true);
});
Expand Down Expand Up @@ -2562,6 +2563,10 @@ function initHandlers() {
};

if (dialogType === 'saveFile') {
dialogOpts.defaultPath = path.join(
recentDir,
`new_wallet_${(new Date()).getTime()}.${config.walletFileDefaultExt}`
);
dialogOpts.title = `Select directory to store your ${targetName}, and give it a filename.`;
dialogOpts.buttonLabel = 'OK';

Expand Down Expand Up @@ -2991,6 +2996,7 @@ document.addEventListener('DOMContentLoaded', () => {
setTimeout(() => initNodeSelection, 500);
}
} else {
walletOpenRefreshNodes.classList.add('hidden');
fetchFromRaw();
}
}, false);
Expand Down

0 comments on commit 2cb8af6

Please sign in to comment.