@ -68,12 +68,12 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
} else {
if ( config - > hushDaemon ) {
// hushd is configured to run as a daemon, so we must wait for a few seconds
// to let it start up.
// to let it start up.
main - > logger - > write ( " hushd is daemon=1. Waiting for it to start up " ) ;
this - > showInformation ( QObject : : tr ( " hushd is set to run as daemon " ) , QObject : : tr ( " Waiting for hushd " ) ) ;
QTimer : : singleShot ( 5000 , [ = ] ( ) { doAutoConnect ( /* don't attempt to start ehushd */ false ) ; } ) ;
} else {
// Something is wrong.
// Something is wrong.
// We're going to attempt to connect to the one in the background one last time
// and see if that works, else throw an error
main - > logger - > write ( " Unknown problem while trying to start hushd! " ) ;
@ -81,7 +81,7 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
}
}
} else {
// We tried to start ehushd previously, and it didn't work. So, show the error.
// We tried to start ehushd previously, and it didn't work. So, show the error.
main - > logger - > write ( " Couldn't start embedded hushd for unknown reason " ) ;
QString explanation ;
if ( config - > hushDaemon ) {
@ -90,18 +90,18 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
" Please remove the following line from your HUSH3.conf and restart SilentDragon \n "
" daemon=1 " ) ;
} else {
explanation = QString ( ) % QObject : : tr ( " Couldn't start the embedded hushd. \n \n "
" Please try restarting. \n \n If you previously started hushd with custom arguments, you might need to reset HUSH3.conf. \n \n "
" If all else fails, please run hushd manually. " ) %
explanation = QString ( ) % QObject : : tr ( " Couldn't start the embedded hushd. \n \n "
" Please try restarting. \n \n If you previously started hushd with custom arguments, you might need to reset HUSH3.conf. \n \n "
" If all else fails, please run hushd manually. " ) %
( ehushd ? QObject : : tr ( " The process returned " ) + " : \n \n " % ehushd - > errorString ( ) : QString ( " " ) ) ;
}
this - > showError ( explanation ) ;
}
}
} else {
// HUSH3.conf exists, there's no connection, and the user asked us not to start hushd. Error!
main - > logger - > write ( " Not using embedded and couldn't connect to hushd " ) ;
QString explanation = QString ( ) % QObject : : tr ( " Couldn't connect to hushd configured in HUSH3.conf. \n \n "
QString explanation = QString ( ) % QObject : : tr ( " Couldn't connect to hushd configured in HUSH3.conf. \n \n "
" Not starting embedded hushd because --no-embedded was passed " ) ;
this - > showError ( explanation ) ;
}
@ -114,7 +114,7 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
// Fall back to manual connect
doManualConnect ( ) ;
}
}
}
}
QString randomPassword ( ) {
@ -136,7 +136,7 @@ QString randomPassword() {
/**
* This will create a new HUSH3 . conf and download params if they cannot be found
*/
*/
void ConnectionLoader : : createHushConf ( ) {
main - > logger - > write ( __func__ ) ;
@ -260,7 +260,7 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
}
// The downloaded file is written to a new name, and then renamed when the operation completes.
currentOutput = new QFile ( QDir ( paramsDir ) . filePath ( filename + " .part " ) ) ;
currentOutput = new QFile ( QDir ( paramsDir ) . filePath ( filename + " .part " ) ) ;
if ( ! currentOutput - > open ( QIODevice : : WriteOnly ) ) {
main - > logger - > write ( " Couldn't open " + currentOutput - > fileName ( ) + " for writing " ) ;
@ -268,12 +268,12 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
}
main - > logger - > write ( " Downloading to " + filename ) ;
qDebug ( ) < < " Downloading " < < url < < " to " < < filename ;
QNetworkRequest request ( url ) ;
request . setAttribute ( QNetworkRequest : : FollowRedirectsAttribute , true ) ;
currentDownload = client - > get ( request ) ;
downloadTime . start ( ) ;
// Download Progress
QObject : : connect ( currentDownload , & QNetworkReply : : downloadProgress , [ = ] ( auto done , auto total ) {
// calculate the download speed
@ -293,7 +293,7 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
QObject : : tr ( " Downloading " ) % filename % ( filesRemaining > 1 ? " ( + " % QString : : number ( filesRemaining ) % QObject : : tr ( " more remaining ) " ) : QString ( " " ) ) ,
QString : : number ( done / 1024 / 1024 , ' f ' , 0 ) % QObject : : tr ( " MB of " ) % QString : : number ( total / 1024 / 1024 , ' f ' , 0 ) + QObject : : tr ( " MB at " ) % QString : : number ( speed , ' f ' , 2 ) % unit ) ;
} ) ;
// Download Finished
QObject : : connect ( currentDownload , & QNetworkReply : : finished , [ = ] ( ) {
// Rename file
@ -306,22 +306,22 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
if ( currentDownload - > error ( ) ) {
main - > logger - > write ( " Downloading " + filename + " failed " ) ;
this - > showError ( QObject : : tr ( " Downloading " ) + filename + QObject : : tr ( " failed. Please check the help site for more info " ) ) ;
this - > showError ( QObject : : tr ( " Downloading " ) + filename + QObject : : tr ( " failed. Please check the help site for more info " ) ) ;
} else {
doNextDownload ( cb ) ;
}
} ) ;
// Download new data available.
// Download new data available.
QObject : : connect ( currentDownload , & QNetworkReply : : readyRead , [ = ] ( ) {
currentOutput - > write ( currentDownload - > readAll ( ) ) ;
} ) ;
} ) ;
}
bool ConnectionLoader : : startEmbeddedHushd ( ) {
if ( ! Settings : : getInstance ( ) - > useEmbedded ( ) )
if ( ! Settings : : getInstance ( ) - > useEmbedded ( ) )
return false ;
main - > logger - > write ( " Trying to start embedded hushd " ) ;
// Static because it needs to survive even after this method returns.
@ -330,13 +330,13 @@ bool ConnectionLoader::startEmbeddedHushd() {
if ( ehushd ! = nullptr ) {
if ( ehushd - > state ( ) = = QProcess : : NotRunning ) {
if ( ! processStdErrOutput . isEmpty ( ) ) {
QMessageBox : : critical ( main , QObject : : tr ( " hushd error " ) , " hushd said: " + processStdErrOutput ,
QMessageBox : : critical ( main , QObject : : tr ( " hushd error " ) , " hushd said: " + processStdErrOutput ,
QMessageBox : : Ok ) ;
}
return false ;
} else {
return true ;
}
}
}
QDir appPath ( QCoreApplication : : applicationDirPath ( ) ) ;
@ -346,7 +346,7 @@ bool ConnectionLoader::startEmbeddedHushd() {
# else
auto hushdProgram = appPath . absoluteFilePath ( " hushd " ) ;
# endif
//if (!QFile(hushdProgram).exists()) {
if ( ! QFile : : exists ( hushdProgram ) ) {
qDebug ( ) < < " Can't find hushd at " < < hushdProgram ;
@ -435,7 +435,7 @@ void ConnectionLoader::doManualConnect() {
auto connection = makeConnection ( config ) ;
refreshHushdState ( connection , [ = ] ( ) {
QString explanation = QString ( )
% QObject : : tr ( " Could not connect to hushd configured in settings. \n \n "
% QObject : : tr ( " Could not connect to hushd configured in settings. \n \n "
" Please set the host/port and user/password in the Edit->Settings menu. " ) ;
showError ( explanation ) ;
@ -448,7 +448,7 @@ void ConnectionLoader::doManualConnect() {
void ConnectionLoader : : doRPCSetConnection ( Connection * conn ) {
rpc - > setEHushd ( ehushd ) ;
rpc - > setConnection ( conn ) ;
d - > accept ( ) ;
delete this ;
@ -456,7 +456,7 @@ void ConnectionLoader::doRPCSetConnection(Connection* conn) {
Connection * ConnectionLoader : : makeConnection ( std : : shared_ptr < ConnectionConfig > config ) {
QNetworkAccessManager * client = new QNetworkAccessManager ( main ) ;
QUrl myurl ;
myurl . setScheme ( " http " ) ;
myurl . setHost ( config . get ( ) - > host ) ;
@ -465,10 +465,10 @@ Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> c
QNetworkRequest * request = new QNetworkRequest ( ) ;
request - > setUrl ( myurl ) ;
request - > setHeader ( QNetworkRequest : : ContentTypeHeader , " text/plain " ) ;
QString userpass = config . get ( ) - > rpcuser % " : " % config . get ( ) - > rpcpassword ;
QString headerData = " Basic " + userpass . toLocal8Bit ( ) . toBase64 ( ) ;
request - > setRawHeader ( " Authorization " , headerData . toLocal8Bit ( ) ) ;
request - > setRawHeader ( " Authorization " , headerData . toLocal8Bit ( ) ) ;
return new Connection ( main , client , request , config ) ;
}
@ -489,20 +489,20 @@ void ConnectionLoader::refreshHushdState(Connection* connection, std::function<v
QTimer : : singleShot ( 1000 , [ = ] ( ) { this - > doRPCSetConnection ( connection ) ; } ) ;
} ,
[ = ] ( QNetworkReply * reply , const QJsonValue & res ) {
// Failed, see what it is.
// Failed, see what it is.
auto err = reply - > error ( ) ;
//qDebug() << err << res;
if ( err = = QNetworkReply : : NetworkError : : ConnectionRefusedError ) {
if ( err = = QNetworkReply : : NetworkError : : ConnectionRefusedError ) {
refused ( ) ;
} else if ( err = = QNetworkReply : : NetworkError : : AuthenticationRequiredError ) {
main - > logger - > write ( " Authentication failed " ) ;
QString explanation = QString ( ) %
QString explanation = QString ( ) %
QObject : : tr ( " Authentication failed. The username / password you specified was "
" not accepted by hushd. Try changing it in the Edit->Settings menu " ) ;
this - > showError ( explanation ) ;
} else if ( err = = QNetworkReply : : NetworkError : : InternalServerError & &
} else if ( err = = QNetworkReply : : NetworkError : : InternalServerError & &
! res . isNull ( ) ) {
// The server is loading, so just poll until it succeeds
QString status = res [ " error " ] . toObject ( ) [ " message " ] . toString ( ) ;
@ -526,9 +526,10 @@ void ConnectionLoader::refreshHushdState(Connection* connection, std::function<v
void ConnectionLoader : : showInformation ( QString info , QString detail ) {
static int rescanCount = 0 ;
if ( detail . toLower ( ) . startsWith ( " rescan " ) ) {
qDebug ( ) < < " showInformation detail = " + detail . toLower ( ) ;
rescanCount + + ;
}
if ( rescanCount > 10 ) {
detail = detail + " \n " + QObject : : tr ( " This may take several hours, grab some popcorn " ) ;
}
@ -541,9 +542,9 @@ void ConnectionLoader::showInformation(QString info, QString detail) {
}
/**
* Show error will close the loading dialog and show an error .
* Show error will close the loading dialog and show an error .
*/
void ConnectionLoader : : showError ( QString explanation ) {
void ConnectionLoader : : showError ( QString explanation ) {
rpc - > setEHushd ( nullptr ) ;
rpc - > noConnection ( ) ;
@ -659,8 +660,8 @@ bool ConnectionLoader::verifyParams() {
/**
* Try to automatically detect a HUSH3 / HUSH3 . conf file in the correct location and load parameters
*/
std : : shared_ptr < ConnectionConfig > ConnectionLoader : : autoDetectHushConf ( ) {
*/
std : : shared_ptr < ConnectionConfig > ConnectionLoader : : autoDetectHushConf ( ) {
auto confLocation = locateHushConfFile ( ) ;
if ( confLocation . isNull ( ) ) {
@ -682,7 +683,7 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectHushConf() {
hushconf - > usingHushConf = true ;
hushconf - > hushDir = QFileInfo ( confLocation ) . absoluteDir ( ) . absolutePath ( ) ;
hushconf - > hushDaemon = false ;
Settings : : getInstance ( ) - > setUsingHushConf ( confLocation ) ;
while ( ! in . atEnd ( ) ) {
@ -733,21 +734,21 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectHushConf() {
hushconf - > rpcuser ,
hushconf - > rpcpassword ) ;
// In addition to the HUSH3/HUSH3.conf file, also double check the params.
// In addition to the HUSH3/HUSH3.conf file, also double check the params.
return std : : shared_ptr < ConnectionConfig > ( hushconf ) ;
}
// Load connection settings from the UI, which indicates an unknown, external hushd
std : : shared_ptr < ConnectionConfig > ConnectionLoader : : loadFromSettings ( ) {
// Load from the QT Settings.
// Load from the QT Settings.
QSettings s ;
auto host = s . value ( " connection/host " ) . toString ( ) ;
auto port = s . value ( " connection/port " ) . toString ( ) ;
auto username = s . value ( " connection/rpcuser " ) . toString ( ) ;
auto password = s . value ( " connection/rpcpassword " ) . toString ( ) ;
if ( username . isEmpty ( ) | | password . isEmpty ( ) )
return nullptr ;
@ -762,8 +763,8 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::loadFromSettings() {
/***********************************************************************************
* Connection Class
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Connection : : Connection ( MainWindow * m , QNetworkAccessManager * c , QNetworkRequest * r ,
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Connection : : Connection ( MainWindow * m , QNetworkAccessManager * c , QNetworkRequest * r ,
std : : shared_ptr < ConnectionConfig > conf ) {
this - > restclient = c ;
this - > request = r ;
@ -796,7 +797,7 @@ void Connection::doRPC(const QJsonValue& payload, const std::function<void(QJson
// Ignoring callback because shutdown in progress
return ;
}
QJsonDocument jd_reply = QJsonDocument : : fromJson ( reply - > readAll ( ) ) ;
QJsonValue parsed ;
@ -808,13 +809,13 @@ void Connection::doRPC(const QJsonValue& payload, const std::function<void(QJson
if ( reply - > error ( ) ! = QNetworkReply : : NoError ) {
ne ( reply , parsed ) ;
return ;
}
}
if ( parsed . isNull ( ) ) {
ne ( reply , " Unknown error " ) ;
}
cb ( parsed [ " result " ] ) ;
cb ( parsed [ " result " ] ) ;
} ) ;
}
@ -850,7 +851,7 @@ void Connection::showTxError(const QString& error) {
/**
* Prevent all future calls from going through
*/
*/
void Connection : : shutdown ( ) {
shutdownInProgress = true ;
}