Browse Source

Try to prevent crash from invalid retryCount values

pull/87/head
Duke Leto 5 years ago
parent
commit
d484960d27
  1. 12
      src/mainwindow.cpp
  2. 37
      src/websockets.cpp

12
src/mainwindow.cpp

@ -109,11 +109,6 @@ MainWindow::MainWindow(QWidget *parent) :
// Initialize to the balances tab
ui->tabWidget->setCurrentIndex(0);
// The zcashd tab is hidden by default, and only later added in if the embedded zcashd is started
//zcashdtab = ui->tabWidget->widget(4);
//ui->tabWidget->removeTab(4);
// TODO: setting to decide whether to auto-close embedded hushd when closing SilentDragon
setupSendTab();
setupTransactionsTab();
setupReceiveTab();
@ -137,9 +132,12 @@ MainWindow::MainWindow(QWidget *parent) :
}
void MainWindow::createWebsocket(QString wormholecode) {
qDebug() << "Listening for app connections on port 8777";
// Create the websocket server, for listening to direct connections
wsserver = new WSServer(8777, false, this);
int wsport = 8777;
// TODO: env var
bool msgDebug = true;
wsserver = new WSServer(wsport, msgDebug, this);
qDebug() << "Listening for app connections on port " << wsport;
if (!wormholecode.isEmpty()) {
// Connect to the wormhole service

37
src/websockets.cpp

@ -118,15 +118,22 @@ void WormholeClient::connect() {
}
void WormholeClient::retryConnect() {
QTimer::singleShot(5 * 1000 * pow(2, retryCount), [=]() {
if (retryCount < 10) {
this->retryCount++;
qDebug() << "Retrying websocket connection, retrycount=" << this->retryCount;
connect();
} else {
qDebug() << "Retry count of " << retryCount << " exceeded, will not attempt retry any more";
}
});
int max_retries = 10;
qDebug() << "Websocket retryConnect, retryCount=" << retryCount;
if (retryCount>=0 && retryCount<=max_retries) {
QTimer::singleShot(5 * 1000 * pow(2, retryCount), [=]() {
if (retryCount < max_retries) {
this->retryCount++;
qDebug() << "Retrying websocket connection, retrycount=" << this->retryCount;
connect();
} else {
qDebug() << "Retry count of " << retryCount << " exceeded, will not attempt retry any more";
}
});
} else {
qDebug() << "Invalid retryCount=" << retryCount << " detected!";
}
}
// Called when the websocket is closed. If this was closed without our explicitly closing it,
@ -157,11 +164,9 @@ void WormholeClient::onConnected()
timer = new QTimer(parent);
QObject::connect(timer, &QTimer::timeout, [=]() {
if (!shuttingDown && m_webSocket->isValid()) {
auto payload = QJsonDocument(QJsonObject {
{"ping", "ping"}
}).toJson();
qDebug() << "Sending Ping";
m_webSocket->sendTextMessage(payload);
auto payload = QJsonDocument(QJsonObject { {"ping", "ping"} }).toJson();
qint64 bytes = m_webSocket->sendTextMessage(payload);
qDebug() << "Sent ping, " << bytes << " bytes";
}
});
qDebug() << "Starting timer";
@ -647,6 +652,7 @@ void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWin
// "sendTx" command. This method will actually send money, so be careful with everything
void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, std::shared_ptr<ClientWebSocket> pClient) {
qDebug() << "processSendTx";
auto error = [=](QString reason) {
auto r = QJsonDocument(QJsonObject{
{"errorCode", -1},
@ -682,7 +688,7 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, st
}
if (bals.isEmpty()) {
error(QObject::tr("No sapling or transparent addresses with enough balance to spend."));
error(QObject::tr("No addresses with enough balance to spend! Try sweeping funds into one address"));
return;
}
@ -782,6 +788,7 @@ void AppDataServer::processGetInfo(QJsonObject jobj, MainWindow* mainWindow, std
void AppDataServer::processGetTransactions(MainWindow* mainWindow, std::shared_ptr<ClientWebSocket> pClient) {
QJsonArray txns;
auto model = mainWindow->getRPC()->getTransactionsModel();
qDebug() << "processGetTransactions";
// Manually add pending ops, so that computing transactions will also show up
auto wtxns = mainWindow->getRPC()->getWatchingTxns();

Loading…
Cancel
Save