We do it for the zlulz

This commit is contained in:
Duke Leto
2021-01-02 17:50:36 -05:00
parent 47262f5395
commit cc523a0a86
46 changed files with 10438 additions and 7283 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2019-2020 The Hush developers
// Copyright 2019-2021 The Hush developers
// GPLv3
#include "Chat.h"

View File

@@ -1,4 +1,4 @@
// Copyright 2019-2020 The Hush developers
// Copyright 2019-2021 The Hush developers
// GPLv3
#include "ContactDataStore.h"

View File

@@ -1,4 +1,4 @@
// Copyright 2019-2020 The Hush developers
// Copyright 2019-2021 The Hush developers
// GPLv3
#ifndef FILESYSTEM_H
#define FILESYSTEM_H

View File

@@ -1,4 +1,4 @@
// Copyright 2019-2020 The Hush developers
// Copyright 2019-2021 The Hush developers
// GPLv3
#include "ContactItem.h"
#include "chatmodel.h"

View File

@@ -1,4 +1,4 @@
// Copyright 2019-2020 The Hush developers
// Copyright 2019-2021 The Hush developers
// GPLv3
#include "ContactRequest.h"

View File

@@ -35,7 +35,7 @@ QLabel
</rect>
</property>
<property name="text">
<string>Lorem ipsum dolor sit amet</string>
<string>Speak And Transact Freely With Hush</string>
</property>
</widget>
<widget class="QLabel" name="lblTimestamp">
@@ -48,7 +48,7 @@ QLabel
</rect>
</property>
<property name="text">
<string>12/03/2020 12:34</string>
<string>01/01/2021 12:34</string>
</property>
</widget>
</widget>

View File

@@ -76,69 +76,71 @@ void ConnectionLoader::loadProgress()
void ConnectionLoader::ShowProgress()
{
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
config->dangerous = false;
config->server = Settings::getInstance()->getSettings().server;
auto connection = makeConnection(config);
auto me = this;
auto me = this;
qDebug() << __func__ << ": server=" << config->server
<< " connection=" << connection << " me=" << me;
isSyncing = new QAtomicInteger<bool>();
isSyncing->store(true);
main->logger->write("isSyncing");
isSyncing = new QAtomicInteger<bool>();
isSyncing->store(true);
main->logger->write("isSyncing");
// Do a sync after import
syncTimer = new QTimer(main);
main->logger->write("Beginning sync after import wif");
connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) {
isSyncing->store(false);
// Cancel the timer
syncTimer->deleteLater();
// When sync is done, set the connection
this->doRPCSetConnectionShield(connection);
});
// While it is syncing, we'll show the status updates while it is alive.
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
// Check the sync status
if (isSyncing != nullptr && isSyncing->load()) {
// Get the sync status
try {
connection->doRPC("syncstatus", "", [=](json reply) {
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end())
{
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
me->showInformation(
"Synced " + QString::number(synced) + " / " + QString::number(total)
);
}
},
[=](QString err) {
qDebug() << "Sync error" << err;
});
}catch (...)
{
main->logger->write("catch sync progress reply");
}
}
});
// Do a sync after import
syncTimer = new QTimer(main);
main->logger->write("Beginning sync after import wif");
connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) {
isSyncing->store(false);
// Cancel the timer
syncTimer->deleteLater();
// When sync is done, set the connection
this->doRPCSetConnectionShield(connection);
});
// While it is syncing, we'll show the status updates while it is alive.
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
// Check the sync status
if (isSyncing != nullptr && isSyncing->load()) {
// Get the sync status
try {
connection->doRPC("syncstatus", "", [=](json reply) {
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end())
{
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
me->showInformation(
"Synced " + QString::number(synced) + " / " + QString::number(total)
);
}
},
[=](QString err) {
qDebug() << "Sync error" << err;
});
}catch (...)
{
main->logger->write("catch sync progress reply");
}
}
});
syncTimer->setInterval(1* 1000);
syncTimer->start();
main->logger->write("Start sync timer");
syncTimer->setInterval(1* 1000);
syncTimer->start();
main->logger->write("Start sync timer");
}
void ConnectionLoader::doAutoConnect()
{
qDebug() << "Doing autoconnect";
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
config->dangerous = false;
config->server = Settings::getInstance()->getSettings().server;
qDebug() << __func__ << " server=" << config->server;
// Initialize the library
main->logger->write(QObject::tr("Attempting to initialize library with ") + config->server);
@@ -159,9 +161,7 @@ void ConnectionLoader::doAutoConnect()
return;
}
}
else
{
} else {
main->logger->write(QObject::tr("Create/restore wallet."));
createOrRestore(config->dangerous, config->server);
d->show();
@@ -169,6 +169,9 @@ void ConnectionLoader::doAutoConnect()
auto connection = makeConnection(config);
auto me = this;
qDebug() << __func__ << ": server=" << config->server
<< " connection=" << connection << " me=" << me << endl;
// After the lib is initialized, try to do get info
connection->doRPC("info", "", [=](auto reply) {
@@ -248,19 +251,14 @@ void ConnectionLoader::doRPCSetConnection(Connection* conn)
d->accept();
QTimer::singleShot(1, [=]() { delete this; });
try
{
QFile plaintextWallet(dirwalletconnection);
main->logger->write("Path to Wallet.dat : " );
plaintextWallet.remove();
}catch (...)
{
main->logger->write("no Plaintext wallet.dat");
}
try {
QFile plaintextWallet(dirwalletconnection);
main->logger->write("Path to Wallet.dat : " );
plaintextWallet.remove();
} catch (...) {
main->logger->write("no Plaintext wallet.dat");
}
}
@@ -272,24 +270,18 @@ void ConnectionLoader::doRPCSetConnectionShield(Connection* conn)
main->getRPC()->shield([=] (auto) {});
QTimer::singleShot(1, [=]() { delete this; });
try
{
QFile plaintextWallet(dirwalletconnection);
main->logger->write("Path to Wallet.dat : " );
plaintextWallet.remove();
}catch (...)
{
main->logger->write("no Plaintext wallet.dat");
}
try {
QFile plaintextWallet(dirwalletconnection);
main->logger->write("Path to Wallet.dat : " );
plaintextWallet.remove();
} catch (...) {
main->logger->write("no Plaintext wallet.dat");
}
}
Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> config)
{
qDebug() << __func__;
return new Connection(main, config);
}
@@ -317,6 +309,8 @@ void ConnectionLoader::showError(QString explanation)
QString litelib_process_response(char* resp)
{
qDebug() << __func__ << ": " << resp;
char* resp_copy = new char[strlen(resp) + 1];
//a safer version of strcpy
strncpy(resp_copy, resp, strlen(resp)+1);
@@ -365,6 +359,7 @@ Connection::Connection(MainWindow* m, std::shared_ptr<ConnectionConfig> conf)
{
this->config = conf;
this->main = m;
qDebug() << __func__;
// Register the JSON type as a type that can be passed between signals and slots.
qRegisterMetaType<json>("json");
}
@@ -375,10 +370,7 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
// Ignoring RPC because shutdown in progress
return;
// qDebug() << "Doing RPC: " << cmd;
qDebug() << __func__ << ": " << cmd;
// Create a runner.
auto runner = new Executor(cmd, args);
@@ -393,6 +385,7 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb)
{
qDebug() << __func__ << ": " << cmd;
doRPC(cmd, args, cb, [=] (QString err) {
this->showTxError(err);
});
@@ -400,6 +393,7 @@ void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb)
{
qDebug() << __func__ << ": " << cmd;
doRPC(cmd, args, cb, [=] (auto) {
// Ignored error handling
});
@@ -407,6 +401,7 @@ void Connection::doRPCIgnoreError(const QString cmd, const QString args, const s
void Connection::showTxError(const QString& error)
{
qDebug() << __func__ << ": " << error;
if (error.isNull())
return;

View File

@@ -17,14 +17,16 @@ ContactModel *contactModel = new ContactModel();
using json = nlohmann::json;
Controller::Controller(MainWindow* main)
{
auto cl = new ConnectionLoader(main, this);
qDebug() << __func__ << ": cl=" << cl << endl;
// Execute the load connection async, so we can set up the rest of RPC properly.
QTimer::singleShot(1, [=]() { cl->loadConnection(); });
qDebug() << __func__ << "after loadConnection" << endl;
this->main = main;
this->ui = main->ui;
@@ -32,9 +34,6 @@ Controller::Controller(MainWindow* main)
balancesTableModel = new BalancesTableModel(main->ui->balancesTable);
main->ui->balancesTable->setModel(balancesTableModel);
// Call the supply once
// supplyUpdate();
// Setup transactions table model
transactionsTableModel = new TxTableModel(ui->transactionsTable);
main->ui->transactionsTable->setModel(transactionsTableModel);
@@ -755,7 +754,7 @@ void Controller::updateUIBalances()
CAmount balAvailable = balT + balVerified;
if (balZ < 0)
balZ = CAmount::fromqint64(0);
double price = (Settings::getInstance()->getBTCPrice() / 1000);
// double price = (Settings::getInstance()->getBTCPrice() / 1000);
// ui->PriceMemo->setText(" The price of \n one HushChat \n Message is :\n BTC " + (QLocale(QLocale::English).toString(price, 'f',8))
//+ " Messages left :" + ((balTotal.toDecimalhushString()) /0.0001) );
// Balances table
@@ -1361,7 +1360,7 @@ void Controller::refreshTransactions() {
const unsigned char *header = reinterpret_cast<const unsigned char *>(ba1.constData());
int encryptedMemoSize1 = ba.length();
int headersize = ba1.length();
//int headersize = ba1.length();
//////unsigned char* as message from QString
#define MESSAGE2 (const unsigned char *) encryptedMemo
@@ -1604,10 +1603,12 @@ void Controller::executeTransaction(Tx tx,
void Controller::checkForUpdate(bool silent)
{
// No checking for updates, needs testing with Gitea
return;
if (!zrpc->haveConnection())
return noConnection();
QUrl cmcURL("https://api.github.com/repos/MyHush/SilentDragonLite/releases");
QUrl cmcURL("https://git.hush.is/repos/MyHush/SilentDragonLite/releases");
QNetworkRequest req;
req.setUrl(cmcURL);
@@ -1661,7 +1662,7 @@ void Controller::checkForUpdate(bool silent)
QMessageBox::Yes, QMessageBox::Cancel);
if (ans == QMessageBox::Yes)
{
QDesktopServices::openUrl(QUrl("https://github.com/MyHush/SilentDragonLite/releases"));
QDesktopServices::openUrl(QUrl("https://git.hush.is/hush/SilentDragonLite/releases"));
}
else
{

View File

@@ -5,7 +5,6 @@
#define RPCCLIENT_H
#include "precompiled.h"
#include "camount.h"
#include "datamodel.h"
#include "balancestablemodel.h"

View File

@@ -42,7 +42,6 @@
using json = nlohmann::json;
#ifdef Q_OS_WIN
auto dirwallet = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite/silentdragonlite-wallet.dat");
auto dirwalletenc = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite/silentdragonlite-wallet-enc.dat");
@@ -63,6 +62,7 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
qDebug() << __func__ << endl;
// Include css
QString theme_name;
@@ -86,9 +86,7 @@ MainWindow::MainWindow(QWidget *parent) :
}else{}
logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log"));
// Check for encryption
// Check for encryption
if(fileExists(dirwalletenc))
{
@@ -117,7 +115,7 @@ MainWindow::MainWindow(QWidget *parent) :
// File a bug
QObject::connect(ui->actionFile_a_bug, &QAction::triggered, [=]() {
QDesktopServices::openUrl(QUrl("https://github.com/MyHush/SilentDragonLite/issues/new"));
QDesktopServices::openUrl(QUrl("https://git.hush.is/hush/SilentDragonLite/issues/new"));
});
// Set up check for updates action
@@ -300,11 +298,6 @@ MainWindow::MainWindow(QWidget *parent) :
// Initialize to the balances tab
ui->tabWidget->setCurrentIndex(0);
// The hushd tab is hidden by default, and only later added in if the embedded hushd is started
//hushdtab = ui->tabWidget->widget(4);
//ui->tabWidget->removeTab(4);
setupSendTab();
setupTransactionsTab();
setupReceiveTab();
@@ -317,6 +310,7 @@ MainWindow::MainWindow(QWidget *parent) :
restoreSavedStates();
if (AppDataServer::getInstance()->isAppConnected()) {
qDebug() << __func__ << ": app is connected to wormhole";
auto ads = AppDataServer::getInstance();
QString wormholecode = "";
@@ -399,15 +393,12 @@ void MainWindow::closeEvent(QCloseEvent* event) {
s.sync();
// Let the RPC know to shut down any running service.
rpc->shutdownhushd();
int passphraselenght = DataStore::getChatDataStore()->getPassword().length();
// Check is encryption is ON for SDl
if(passphraselenght > 0)
{
// Check is encryption is ON for SDl
if(passphraselenght > 0) {
// delete old file before
//auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
@@ -449,14 +440,10 @@ void MainWindow::closeEvent(QCloseEvent* event) {
}
void MainWindow::closeEventpw(QCloseEvent* event) {
// Let the RPC know to shut down any running service.
rpc->shutdownhushd();
}
void MainWindow::encryptWallet() {
QDialog d(this);
@@ -465,7 +452,6 @@ void MainWindow::encryptWallet() {
// Handle edits on the password box
auto fnPasswordEdited = [=](const QString&) {
// Enable the OK button if the passwords match.
QString password = ed.txtPassword->text();
@@ -755,6 +741,7 @@ void MainWindow::setMoneyMemo(QString moneymemo)
}
void MainWindow::setupStatusBar() {
qDebug() << __func__ << endl;
// Status Bar
loadingLabel = new QLabel();
loadingMovie = new QMovie(":/icons/res/loading.gif");
@@ -853,8 +840,11 @@ void MainWindow::setupSettingsModal() {
// List of default servers
settings.cmbServer->addItem("https://lite.hush.is");
settings.cmbServer->addItem("6onaaujm4ozaokzu.onion:80");
settings.cmbServer->addItem("https://miodrag.zone:9876");
settings.cmbServer->addItem("https://hush.leto.net:5420");
//TODO: seperate lists of https/Tor servers, only show user or attempt
// connection to .onion if user has it enabled
//settings.cmbServer->addItem("6onaaujm4ozaokzu.onion:80");
// Load current values into the dialog
auto conf = Settings::getInstance()->getSettings();

View File

@@ -1964,7 +1964,7 @@
</action>
<action name="actionCheck_for_Updates">
<property name="text">
<string>Check github.com for &amp;updates</string>
<string>Check git for &amp;updates</string>
</property>
</action>
<action name="actionExport_All_Private_Keys">

View File

@@ -21,7 +21,18 @@ Config Settings::getSettings() {
// Load from the QT Settings.
QSettings s;
// this domain is stolen and malicious!
auto malicious = "https://lite.myhush.org";
auto server = s.value("connection/server").toString();
if(server == malicious) {
server = "https://lite.hush.is";
qDebug() << "Replacing malicious SDL server with " << server;
s.setValue("connection/server", server);
s.sync();
// re-init to load correct settings
init();
}
if (server.trimmed().isEmpty()) {
server = Settings::getDefaultServer();
}
@@ -239,10 +250,6 @@ void Settings::set_theme_name(QString theme_name) {
QSettings().setValue("options/theme_name", theme_name);
}
//=================================
// Static Stuff
//=================================
@@ -263,8 +270,21 @@ void Settings::saveRestoreTableHeader(QTableView* table, QDialog* d, QString tab
});
}
QString Settings::getRandomServer() {
// we don't need cryptographic random-ness, but we want
// clients to never get "stuck" with the same server, which
// prevents various attacks
QList<QString> servers;
//TODO: This should be a much larger list which we randomly choose from
servers[0] = "https://lite.hush.is";
servers[1] = "https://miodrag.zone:9876";
servers[2] = "https://hush.leto.net:5420";
int x = rand() % 3;
return servers[1];
}
QString Settings::getDefaultServer() {
return "https://lite.hush.is";
return "https://miodrag.zone:9876";
}
void Settings::openAddressInExplorer(QString address) {
@@ -278,7 +298,6 @@ void Settings::openTxInExplorer(QString txid) {
}
const QString Settings::txidStatusMessage = QString(QObject::tr("Tx submitted (right click to copy) txid:"));
QString Settings::getTokenName() {

View File

@@ -158,6 +158,7 @@ public:
static QString getDonationAddr();
static QString getDefaultServer();
static QString getRandomServer();
static CAmount getMinerFee();
static int getMaxMobileAppTxns() { return 30; }
@@ -171,8 +172,8 @@ public:
static const QString labelRegExp;
static const int updateSpeed = 30 * 1000; // 30 sec
static const int quickUpdateSpeed = 5 * 1000; // 3 sec
static const int priceRefreshSpeed = 5 * 60 * 1000; // 15 min
static const int quickUpdateSpeed = 5 * 1000; // 5 sec
static const int priceRefreshSpeed = 5 * 60 * 1000; // 5 min
private:
// This class can only be accessed through Settings::getInstance()

View File

@@ -167,7 +167,7 @@
</rect>
</property>
<property name="text">
<string>Check github for updates at startup</string>
<string>Check git for updates at startup</string>
</property>
</widget>
<widget class="QLabel" name="label_8">
@@ -180,7 +180,7 @@
</rect>
</property>
<property name="text">
<string>Connect to github on startup to check for updates</string>
<string>Connect to git on startup to check for updates</string>
</property>
</widget>
<widget class="QLabel" name="label_20">