Browse Source

spv auto round robin reconnect

v0.25
pbca26 7 years ago
parent
commit
ebdd1513ed
  1. 2
      react/src/components/dashboard/settings/settings.spvServersPanel.js
  2. 65
      react/src/components/dashboard/walletsData/walletsData.js
  3. 2
      react/src/components/dashboard/walletsData/walletsData.render.js
  4. 3
      react/src/translate/en.js
  5. 41
      react/src/util/serverRandom.js

2
react/src/components/dashboard/settings/settings.spvServersPanel.js

@ -60,7 +60,7 @@ class SPVServersPanel extends React.Component {
)
);
}
})
});
}
updateInput(e) {

65
react/src/components/dashboard/walletsData/walletsData.js

@ -10,6 +10,10 @@ import {
getDashboardUpdate,
shepherdElectrumTransactions,
toggleClaimInterestModal,
shepherdElectrumCheckServerConnection,
shepherdElectrumSetServer,
electrumServerChanged,
triggerToaster,
} from '../../../actions/actionCreators';
import Store from '../../../store';
import {
@ -25,6 +29,7 @@ import {
WalletsDataRender,
} from './walletsData.render';
import { secondsToString } from '../../../util/time';
import getRandomElectrumServer from '../../../util/serverRandom';
/*import { SocketProvider } from 'socket.io-react';
import io from 'socket.io-client';
@ -52,12 +57,14 @@ class WalletsData extends React.Component {
coin: null,
txhistory: null,
loading: false,
reconnectInProgress: false,
};
this.openDropMenu = this.openDropMenu.bind(this);
this.handleClickOutside = this.handleClickOutside.bind(this);
this.refreshTxHistory = this.refreshTxHistory.bind(this);
this.openClaimInterestModal = this.openClaimInterestModal.bind(this);
this.displayClaimInterestUI = this.displayClaimInterestUI.bind(this);
this.spvAutoReconnect = this.spvAutoReconnect.bind(this);
}
componentWillMount() {
@ -294,6 +301,7 @@ class WalletsData extends React.Component {
txhistory: this.props.ActiveCoin.txhistory,
showPagination: this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory.length >= this.state.defaultPageSize,
itemsListColumns: this.generateItemsListColumns(this.props.ActiveCoin.txhistory.length),
reconnectInProgress: false,
});
}
@ -301,21 +309,62 @@ class WalletsData extends React.Component {
this.props.ActiveCoin.txhistory === 'no data') {
_stateChange = Object.assign({}, _stateChange, {
itemsList: 'no data',
reconnectInProgress: false,
});
} else if (this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'loading') {
_stateChange = Object.assign({}, _stateChange, {
itemsList: 'loading',
reconnectInProgress: false,
});
} else if ((this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'connection error or incomplete data') ||
(this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'cant get current height')) {
_stateChange = Object.assign({}, _stateChange, {
itemsList: 'connection error',
reconnectInProgress: this.props.Dashboard.electrumCoins[this.props.ActiveCoin.coin].serverList !== 'none' ? true : false,
});
if (!this.state.reconnectInProgress) {
this.spvAutoReconnect();
}
}
this.setState(Object.assign({}, _stateChange));
}
spvAutoReconnect() {
let _spvServers = this.props.Dashboard.electrumCoins[this.props.ActiveCoin.coin].serverList;
let _server = [
this.props.Dashboard.electrumCoins[this.props.ActiveCoin.coin].server.ip,
this.props.Dashboard.electrumCoins[this.props.ActiveCoin.coin].server.port
];
const _randomServer = getRandomElectrumServer(_spvServers, _server.join(':'));
shepherdElectrumCheckServerConnection(_randomServer.ip, _randomServer.port)
.then((res) => {
if (res.result) {
shepherdElectrumSetServer(this.props.ActiveCoin.coin, _randomServer.ip, _randomServer.port)
.then((serverSetRes) => {
Store.dispatch(
triggerToaster(
`${this.props.ActiveCoin.coin} SPV server set to ${_randomServer.ip}:${_randomServer.port}`,
translate('TOASTR.WALLET_NOTIFICATION'),
'success'
)
);
Store.dispatch(electrumServerChanged(true));
});
} else {
Store.dispatch(
triggerToaster(
`${this.props.ActiveCoin.coin} SPV server ${_randomServer.ip}:${_randomServer.port} is unreachable!`,
translate('TOASTR.WALLET_NOTIFICATION'),
'error'
)
);
}
});
}
isFullySynced() {
const _progress = this.props.ActiveCoin.progress;
@ -362,12 +411,16 @@ class WalletsData extends React.Component {
<tr className="hover--none">
<td
colSpan="7"
className="table-cell-offset-16 color-warning">
{ translate('DASHBOARD.SPV_CONN_ERROR') }
<span className={ this.props.Dashboard.electrumCoins[this.props.ActiveCoin.coin].serverList !== 'none' ? '' : 'hide' }>
<br/>{ translate('DASHBOARD.SPV_CONN_ERROR_P1') }
<br/>{ translate('DASHBOARD.SPV_CONN_ERROR_P2') }
</span>
className="table-cell-offset-16">
<div className="color-warning">
{ translate('DASHBOARD.SPV_CONN_ERROR') }
</div>
<div className={ this.props.Dashboard.electrumCoins[this.props.ActiveCoin.coin].serverList !== 'none' ? '' : 'hide' }>
<div className="color-warning">Trying to switch to another server...</div>
<br />
<strong>How to switch manually:</strong>
<br/>{ translate('DASHBOARD.SPV_CONN_ERROR_P1') }
</div>
</td>
</tr>
);

2
react/src/components/dashboard/walletsData/walletsData.render.js

@ -266,6 +266,8 @@ export const WalletsDataRender = function() {
{ this.props.ActiveCoin.txhistory !== 'loading' &&
this.props.ActiveCoin.txhistory !== 'no data' &&
this.props.ActiveCoin.txhistory !== 'connection error' &&
this.props.ActiveCoin.txhistory !== 'connection error or incomplete data' &&
this.props.ActiveCoin.txhistory !== 'cant get current height' &&
<div className="col-sm-4 search-box">
<input
className="form-control"

3
react/src/translate/en.js

@ -453,8 +453,7 @@ export const _lang = {
'QR_ERR_NO_VIDEO_DEVICE': 'Error: No video input devices found!',
'QR_ERR_UNKNOWN': 'Error: unknown error!',
'SPV_CONN_ERROR': 'Connection error!',
'SPV_CONN_ERROR_P1': 'Try to connect to another SPV server.',
'SPV_CONN_ERROR_P2': 'To do that go to "Settings", select "SPV Server List" tab, choose new server and click "OK".',
'SPV_CONN_ERROR_P1': 'Go to "Settings", select "SPV Server List" tab, choose new server and click "OK".',
'FAILED_TX_INFO': 'Transaction failed or blocks reindexing is in progress. Failed transactions usually rejected after a while resulting in your funds being credited back.',
'SPV_CLAIMED_INTEREST': 'Claimed interest',
'CLAIM_INTEREST_HELPER_BAR_P1': 'You have',

41
react/src/util/serverRandom.js

@ -0,0 +1,41 @@
const getRandomIntInclusive = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min; // the maximum is inclusive and the minimum is inclusive
}
export const getRandomElectrumServer = (servers, excludeServer) => {
let randomServer;
let _servers = [];
for (let i = 0; i < servers.length; i++) {
if (excludeServer !== servers[i]) {
_servers.push(servers[i]);
}
}
// pick a random server to communicate with
if (_servers &&
_servers.length > 0) {
const _randomServerId = getRandomIntInclusive(0, _servers.length - 1);
const _randomServer = _servers[_randomServerId];
const _serverDetails = _randomServer.split(':');
if (_serverDetails.length === 2) {
return {
ip: _serverDetails[0],
port: _serverDetails[1],
};
}
} else {
const _serverDetails = _servers[0].split(':');
return {
ip: _serverDetails[0],
port: _serverDetails[1],
};
}
}
export default getRandomElectrumServer;
Loading…
Cancel
Save