Browse Source

Merge branch 'duke' of https://github.com/MyHush/SilentDragon into duke

pull/87/head
Jonathan "Duke" Leto 5 years ago
parent
commit
b4860b9ea0
  1. 3
      src/connection.cpp
  2. 12
      src/mainwindow.cpp
  3. 47
      src/websockets.cpp

3
src/connection.cpp

@ -728,8 +728,7 @@ void Connection::doRPC(const json& payload, const std::function<void(json)>& cb,
return;
}
qDebug() << "RPC: " << QString::fromStdString(payload["method"]);
qDebug() << "< payload " << QString::fromStdString(payload.dump());
qDebug() << "RPC: " << QString::fromStdString(payload["method"]) << " " << QString::fromStdString(payload.dump());
QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump()));

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

47
src/websockets.cpp

@ -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();

Loading…
Cancel
Save