|
|
@ -118,21 +118,28 @@ void WormholeClient::connect() { |
|
|
|
} |
|
|
|
|
|
|
|
void WormholeClient::retryConnect() { |
|
|
|
QTimer::singleShot(5 * 1000 * pow(2, retryCount), [=]() { |
|
|
|
if (retryCount < 10) { |
|
|
|
qDebug() << "Retrying websocket connection"; |
|
|
|
this->retryCount++; |
|
|
|
connect(); |
|
|
|
} |
|
|
|
else { |
|
|
|
qDebug() << "Retry count 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,
|
|
|
|
// then we need to try and reconnect
|
|
|
|
void WormholeClient::closed() { |
|
|
|
qDebug() << "Closing websocket"; |
|
|
|
if (!shuttingDown) { |
|
|
|
retryConnect(); |
|
|
|
} |
|
|
@ -157,17 +164,18 @@ void WormholeClient::onConnected() |
|
|
|
timer = new QTimer(parent); |
|
|
|
QObject::connect(timer, &QTimer::timeout, [=]() { |
|
|
|
if (!shuttingDown && m_webSocket->isValid()) { |
|
|
|
auto payload = QJsonDocument(QJsonObject { |
|
|
|
{"ping", "ping"} |
|
|
|
}).toJson(); |
|
|
|
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"; |
|
|
|
timer->start(4 * 60 * 1000); // 4 minutes
|
|
|
|
} |
|
|
|
|
|
|
|
void WormholeClient::onTextMessageReceived(QString message) |
|
|
|
{ |
|
|
|
qDebug() << "Websocket received msg: " << message; |
|
|
|
AppDataServer::getInstance()->processMessage(message, parent, std::make_shared<ClientWebSocket>(m_webSocket), AppConnectionType::INTERNET); |
|
|
|
} |
|
|
|
|
|
|
@ -198,6 +206,7 @@ QString AppDataServer::getWormholeCode(QString secretHex) { |
|
|
|
delete[] out1; |
|
|
|
delete[] secret; |
|
|
|
|
|
|
|
qDebug() << "Created wormhole secretHex"; |
|
|
|
return wmcodehex; |
|
|
|
} |
|
|
|
|
|
|
@ -322,6 +331,7 @@ void AppDataServer::updateUIWithNewQRCode(MainWindow* mainwindow) { |
|
|
|
return; |
|
|
|
|
|
|
|
QString uri = "ws://" + ipv4Addr + ":8777"; |
|
|
|
qDebug() << "Websocket URI: " << uri; |
|
|
|
|
|
|
|
// Get a new secret
|
|
|
|
unsigned char* secretBin = new unsigned char[crypto_secretbox_KEYBYTES]; |
|
|
@ -343,13 +353,16 @@ void AppDataServer::updateUIWithNewQRCode(MainWindow* mainwindow) { |
|
|
|
} |
|
|
|
|
|
|
|
void AppDataServer::registerNewTempSecret(QString tmpSecretHex, bool allowInternet, MainWindow* main) { |
|
|
|
qDebug() << "Registering new tempSecret, allowInternet=" << allowInternet; |
|
|
|
tempSecret = tmpSecretHex; |
|
|
|
|
|
|
|
delete tempWormholeClient; |
|
|
|
tempWormholeClient = nullptr; |
|
|
|
|
|
|
|
if (allowInternet) |
|
|
|
if (allowInternet) { |
|
|
|
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret)); |
|
|
|
qDebug() << "Created new wormhole client"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
QString AppDataServer::connDesc(AppConnectionType t) { |
|
|
@ -639,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}, |
|
|
@ -674,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; |
|
|
|
} |
|
|
|
|
|
|
@ -774,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(); |
|
|
|