Skip to content

Commit

Permalink
Splash screen msg for port conflict/other errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rithvikvibhu committed Feb 6, 2022
1 parent eeacd3f commit db2f31c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
44 changes: 13 additions & 31 deletions app/background/node/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import { VALID_NETWORKS } from '../../constants/networks';
import path from 'path';
import fs from 'fs';
import crypto from 'crypto';
import tcpPortUsed from 'tcp-port-used';
import EventEmitter from 'events';
import { NodeClient } from 'hs-client';
import { BigNumber } from 'bignumber.js';
import { ConnectionTypes, getConnection, getCustomRPC } from '../connections/service';
import FullNode from 'hsd/lib/node/fullnode';
import SPVNode from 'hsd/lib/node/spvnode';
import plugin from 'hsd/lib/wallet/plugin';
import Address from 'hsd/lib/primitives/address';
const blake2b = require('bcrypto/lib/blake2b');
const secp256k1 = require('bcrypto/lib/secp256k1');
const {safeEqual} = require('bcrypto/lib/safe');
import pkg from 'hsd/lib/pkg';
import { prefixHash } from '../../db/names';
import { get, put } from '../db/service';
import {dispatchToMainWindow} from "../../mainWindow";
Expand Down Expand Up @@ -129,7 +123,19 @@ export class NodeService extends EventEmitter {

switch (conn.type) {
case ConnectionTypes.P2P:
await this.startNode();
try {
await this.startNode();
} catch (error) {
if (error.code === 'EADDRINUSE') {
throw new Error(`
Could not bind to ${error.address}:${error.port}.
Please make sure no other hsd or Bob Wallet instance is running.
Quit Bob, and try again.`);
} else {
throw error;
}
return;
}
await this.setHSDLocalClient();
dispatchToMainWindow({
type: SET_CUSTOM_RPC_STATUS,
Expand Down Expand Up @@ -186,12 +192,6 @@ export class NodeService extends EventEmitter {
return;
}

const portsFree = await checkHSDPortsFree(this.network);

if (!portsFree) {
throw new Error('hsd ports in use. Please make sure no other hsd instance is running, quit Bob, and try again.');
}

console.log(`Starting node on ${this.networkName} network.`);

const dir = await this.getDir();
Expand Down Expand Up @@ -569,24 +569,6 @@ export class NodeService extends EventEmitter {
}
}

async function checkHSDPortsFree(network) {
const ports = [
network.port,
network.rpcPort,
// network.walletPort,
network.nsPort,
];

for (const port of ports) {
const inUse = await tcpPortUsed.check(port);
if (inUse) {
return false;
}
}

return true;
}

export const service = new NodeService();

const sName = 'Node';
Expand Down
2 changes: 2 additions & 0 deletions app/ducks/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SET_FEE_INFO,
SET_CUSTOM_RPC_STATUS,
START_NETWORK_CHANGE,
START_ERROR,
STOP,
START_NODE_STATUS_CHANGE,
START_RPC_TEST,
Expand Down Expand Up @@ -88,6 +89,7 @@ export const start = (network) => async (dispatch) => {
} catch (error) {
console.error('node start error', error);
dispatch({ type: STOP });
dispatch({ type: START_ERROR, payload: error.message });
} finally {
dispatch({ type: END_NODE_STATUS_CHANGE });
}
Expand Down
2 changes: 1 addition & 1 deletion app/ducks/nodeReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function nodeReducer(state = getInitialState(), action = {}) {
},
};
case START_ERROR:
return {...state, error: action.payload.error};
return {...state, error: action.payload};
case SET_NODE_INFO:
return {
...state,
Expand Down
6 changes: 5 additions & 1 deletion app/pages/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,15 @@ const OPEN_ROUTES = [
]

const ProtectedRoute = (props) => {
if (OPEN_ROUTES.includes(props.location.pathname)) {
return <Route {...props} />;
}

if (!props.wallets.length) {
return <Redirect to="/funding-options" />;
}

if (props.isLocked && !OPEN_ROUTES.includes(props.location.pathname)) {
if (props.isLocked) {
return <Redirect to="/login" />;
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"jsdom": "^16.4.0",
"jsdom-global": "^3.0.2",
"mini-css-extract-plugin": "0.4.4",
"node-sass": "4.13.1",
"node-sass": "^4.14.1",
"redux-logger": "3.0.6",
"resolve-url-loader": "3.0.0",
"sass-loader": "7.1.0",
Expand Down Expand Up @@ -179,7 +179,6 @@
"sha3": "2.0.0",
"shakedex": "https://github.com/chikeichan/shakedex#patch-3",
"source-map-support": "0.5.9",
"tcp-port-used": "1.0.1",
"uuid": "3.3.3",
"winston": "3.1.0"
}
Expand Down

0 comments on commit db2f31c

Please sign in to comment.