Browse Source

Add some debugging and little things

pull/102/head
Jonathan "Duke" Leto 5 years ago
parent
commit
9b64c4529f
  1. 30
      src/websockets.cpp
  2. 8
      src/websockets.h

30
src/websockets.cpp

@ -1,3 +1,4 @@
// Copyright 2019 The Hush developers
#include "websockets.h"
#include "rpc.h"
@ -5,7 +6,7 @@
#include "ui_mobileappconnector.h"
#include "version.h"
// Weap the sendTextMessage to check if the connection is valid and that the parent WebServer didn't close this connection
// Wrap the sendTextMessage to check if the connection is valid and that the parent WebServer didn't close this connection
// for some reason.
void ClientWebSocket::sendTextMessage(QString m) {
if (client) {
@ -101,23 +102,32 @@ WormholeClient::~WormholeClient() {
if (timer)
timer->stop();
qDebug() << "Wormhole client destroyed";
delete timer;
}
void ws_error() {
qDebug() << "websocket error!";
}
void WormholeClient::connect() {
delete m_webSocket;
m_webSocket = new QWebSocket();
QUrl wormhole = QUrl("wss://wormhole.myhush.org:443");
QObject::connect(m_webSocket, &QWebSocket::connected, this, &WormholeClient::onConnected);
QObject::connect(m_webSocket, &QWebSocket::disconnected, this, &WormholeClient::closed);
m_webSocket->open(QUrl("wss://wormhole.myhush.org:443"));
qDebug() << "Opening connection to the SilentDragonWormhole";
m_webSocket->open(wormhole);
qDebug() << "Opened connection to " << wormhole;
//TODO: use env var to over-ride
//m_webSocket->open(QUrl("ws://127.0.0.1:7070"));
}
void WormholeClient::retryConnect() {
void WormholeClient::retryConnect() {
int max_retries = 10;
qDebug() << "Websocket retryConnect, retryCount=" << retryCount;
@ -153,11 +163,11 @@ void WormholeClient::onConnected()
QObject::connect(m_webSocket, &QWebSocket::textMessageReceived,
this, &WormholeClient::onTextMessageReceived);
auto payload = QJsonDocument( QJsonObject {
{"register", code}
}).toJson();
auto payload = QJsonDocument( QJsonObject { {"register", code} }).toJson();
qDebug() << "Sending register";
m_webSocket->sendTextMessage(payload);
qDebug() << "Sent registration message with code=" << code;
// On connected, we'll also create a timer to ping it every 4 minutes, since the websocket
// will timeout after 5 minutes
@ -284,14 +294,17 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
if (state == Qt::Checked) {
}
qDebug() << "Updating QR";
updateUIWithNewQRCode(parent);
});
// If we're not listening for the app, then start the websockets
if (!parent->isWebsocketListening()) {
QString wormholecode = "";
if (getAllowInternetConnection())
if (getAllowInternetConnection()) {
wormholecode = AppDataServer::getInstance()->getWormholeCode(AppDataServer::getInstance()->getSecretHex());
qDebug() << "Generated wormholecode=" << wormholecode;
}
parent->createWebsocket(wormholecode);
}
@ -681,6 +694,7 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, st
if (Settings::getInstance()->isSproutAddress(i))
continue;
// Filter out balances that don't have the requisite amount
// TODO: should this be amt+tx.fee?
if (allBalances->value(i) < amt)
continue;

8
src/websockets.h

@ -66,13 +66,11 @@ public:
void retryConnect();
private:
MainWindow* parent = nullptr;
MainWindow* parent = nullptr;
QWebSocket* m_webSocket = nullptr;
QTimer* timer = nullptr;
QString code;
int retryCount = 0;
unsigned int retryCount = 0;
bool shuttingDown = false;
};
@ -175,4 +173,4 @@ private:
#endif // WEBSOCKETS_H
#endif // WEBSOCKETS_H

Loading…
Cancel
Save