improved display of tor process completion

This commit is contained in:
csoler 2021-12-18 21:30:58 +01:00
parent 7e6156566a
commit 40b965cab1
7 changed files with 73 additions and 30 deletions

View File

@ -91,14 +91,18 @@ int RsFdBinInterface::read_pending()
return mTotalInBufferBytes; return mTotalInBufferBytes;
} }
#ifdef DEBUG_FS_BIN
RsDbg() << "clintConnt: " << mCLintConnt << ", readbytes: " << readbytes ; RsDbg() << "clintConnt: " << mCLintConnt << ", readbytes: " << readbytes ;
#endif
// display some debug info // display some debug info
if(readbytes > 0) if(readbytes > 0)
{ {
//RsDbg() << "Received the following bytes: " << RsUtil::BinToHex( reinterpret_cast<unsigned char*>(inBuffer),readbytes,50) << std::endl; #ifdef DEBUG_FS_BIN
RsDbg() << "Received the following bytes: " << RsUtil::BinToHex( reinterpret_cast<unsigned char*>(inBuffer),readbytes,50) << std::endl;
RsDbg() << "Received the following bytes: " << std::string(inBuffer,readbytes) << std::endl; RsDbg() << "Received the following bytes: " << std::string(inBuffer,readbytes) << std::endl;
#endif
void *ptr = malloc(readbytes); void *ptr = malloc(readbytes);
@ -111,7 +115,9 @@ int RsFdBinInterface::read_pending()
mTotalInBufferBytes += readbytes; mTotalInBufferBytes += readbytes;
mTotalReadBytes += readbytes; mTotalReadBytes += readbytes;
#ifdef DEBUG_FS_BIN
RsDbg() << "Socket: " << mCLintConnt << ". Total read: " << mTotalReadBytes << ". Buffer size: " << mTotalInBufferBytes ; RsDbg() << "Socket: " << mCLintConnt << ". Total read: " << mTotalReadBytes << ". Buffer size: " << mTotalInBufferBytes ;
#endif
} }
return mTotalInBufferBytes; return mTotalInBufferBytes;
} }
@ -138,11 +144,15 @@ int RsFdBinInterface::write_pending()
return mTotalOutBufferBytes; return mTotalOutBufferBytes;
} }
#ifdef DEBUG_FS_BIN
RsDbg() << "clintConnt: " << mCLintConnt << ", written: " << written ; RsDbg() << "clintConnt: " << mCLintConnt << ", written: " << written ;
#endif
// display some debug info // display some debug info
#ifdef DEBUG_FS_BIN
RsDbg() << "Sent the following bytes: " << RsUtil::BinToHex( reinterpret_cast<unsigned char*>(p.first),written,50) << std::endl; RsDbg() << "Sent the following bytes: " << RsUtil::BinToHex( reinterpret_cast<unsigned char*>(p.first),written,50) << std::endl;
#endif
if(written < p.second) if(written < p.second)
{ {

View File

@ -1,6 +1,17 @@
/******************************* BEGIN WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#else
#include <ws2tcpip.h>
// Missing defines in MinGW
#ifndef MSG_WAITALL
#define MSG_WAITALL 8
#endif
#endif
/********************************* END WINDOWS/UNIX SPECIFIC PART ******************/
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>

View File

@ -86,13 +86,14 @@ void AddOnionCommand::onReply(int statusCode, const ByteArray &data)
const ByteArray keyPrefix("PrivateKey="); const ByteArray keyPrefix("PrivateKey=");
const ByteArray sidPrefix("ServiceID="); const ByteArray sidPrefix("ServiceID=");
if(data.startsWith("ServiceID=")){ if(data.startsWith(sidPrefix))
{
ByteArray service_id = data.mid(sidPrefix.size()); ByteArray service_id = data.mid(sidPrefix.size());
m_service->setServiceId(service_id); m_service->setServiceId(service_id);
} }
if (data.startsWith(keyPrefix)) { if (data.startsWith(keyPrefix))
{
ByteArray keyData(data.mid(keyPrefix.size())); ByteArray keyData(data.mid(keyPrefix.size()));
CryptoKey key; CryptoKey key;

View File

@ -36,6 +36,8 @@
#include "Useful.h" #include "Useful.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include <fstream>
using namespace Tor; using namespace Tor;
HiddenService::HiddenService(HiddenServiceClient *client) HiddenService::HiddenService(HiddenServiceClient *client)
@ -110,20 +112,42 @@ void HiddenService::setPrivateKey(const CryptoKey &key)
m_client->hiddenServicePrivateKeyChanged(); //emit privateKeyChanged(); m_client->hiddenServicePrivateKeyChanged(); //emit privateKeyChanged();
} }
void HiddenService::loadPrivateKey() bool HiddenService::loadPrivateKey()
{ {
if (m_privateKey.isLoaded() || m_dataPath.empty()) if (m_privateKey.isLoaded() || m_dataPath.empty())
return; return false;
bool ok = m_privateKey.loadFromFile(m_dataPath + "/private_key"); bool ok = m_privateKey.loadFromFile(m_dataPath + "/private_key");
if (!ok) { if (!ok) {
RsWarn() << "Failed to load hidden service key"; RsWarn() << "Failed to load hidden service key";
return; return false;
}
// Also load the onion address stored in "hostname" file. This is not needed, except for early display
// of the onion address, since the onion address will be re-computed by Tor (to the same value) when the
// service is published.
std::ifstream i((m_dataPath + "/hostname").c_str());
if(i)
{
std::string s;
i >> s;
if(ByteArray(s).endsWith(ByteArray(".onion")))
{
m_hostname = s;
m_service_id = s.substr(0,s.length() - std::string(".onion").length());
RsDbg() << "Read existing hostname: " << m_hostname;
}
i.close();
} }
if(m_client) if(m_client)
m_client->hiddenServicePrivateKeyChanged(); // emit privateKeyChanged(); m_client->hiddenServicePrivateKeyChanged(); // emit privateKeyChanged();
return true;
} }
void HiddenService::servicePublished() void HiddenService::servicePublished()

View File

@ -97,7 +97,7 @@ private:
CryptoKey m_privateKey; CryptoKey m_privateKey;
ByteArray m_service_id; ByteArray m_service_id;
void loadPrivateKey(); bool loadPrivateKey();
void setStatus(Status newStatus); void setStatus(Status newStatus);
HiddenServiceClient *m_client; HiddenServiceClient *m_client;

View File

@ -148,9 +148,12 @@ void TorManager::setHiddenServiceDirectory(const std::string &path)
d->hiddenServiceDir += '/'; d->hiddenServiceDir += '/';
} }
static bool test_listening_port(const std::string& address,uint16_t port) static bool test_listening_port(const std::string& /*address*/,uint16_t port)
{ {
int sockfd, portno; // sockaddr_storage addr;
// sockaddr_storage_fromString(address,addr);
//
int sockfd;
struct sockaddr_in serv_addr ; struct sockaddr_in serv_addr ;
/* First call to socket() function */ /* First call to socket() function */
@ -161,11 +164,10 @@ static bool test_listening_port(const std::string& address,uint16_t port)
/* Initialize socket structure */ /* Initialize socket structure */
bzero((char *) &serv_addr, sizeof(serv_addr)); bzero((char *) &serv_addr, sizeof(serv_addr));
portno = 5001;
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno); serv_addr.sin_port = htons(port);
/* Now bind the host address using bind() call.*/ /* Now bind the host address using bind() call.*/
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
@ -190,45 +192,43 @@ bool TorManager::setupHiddenService()
{ {
if(d->hiddenService != NULL) if(d->hiddenService != NULL)
{ {
std::cerr << "TorManager: setupHiddenService() called twice! Not doing anything this time." << std::endl; RsErr() << "TorManager: setupHiddenService() called twice! Not doing anything this time." ;
return true ; return true ;
} }
std::string keyData ;//= m_settings->read("serviceKey").toString(); std::string keyData ;//= m_settings->read("serviceKey").toString();
std::string legacyDir = d->hiddenServiceDir; std::string legacyDir = d->hiddenServiceDir;
std::cerr << "TorManager: setting up hidden service." << std::endl; RsDbg() << "TorManager: setting up hidden service." << std::endl;
if(legacyDir.empty()) if(legacyDir.empty())
{ {
std::cerr << "legacy dir not set! Cannot proceed." << std::endl; RsErr() << "legacy dir not set! Cannot proceed." ;
return false ; return false ;
} }
std::cerr << "Using legacy dir: " << legacyDir << std::endl; RsDbg() << "Using legacy dir: " << legacyDir ;
auto key_path = RsDirUtil::makePath(legacyDir,"/private_key"); auto key_path = RsDirUtil::makePath(legacyDir,"/private_key");
if (!legacyDir.empty() && RsDirUtil::fileExists(key_path)) if (!legacyDir.empty() && RsDirUtil::fileExists(key_path))
{ {
std::cerr << "Attempting to load key from legacy filesystem format from file \"" << key_path << "\"" << std::endl; std::cerr << "Attempting to load key from legacy filesystem format from file \"" << key_path << "\"" << std::endl;
CryptoKey key; d->hiddenService = new Tor::HiddenService(this,legacyDir);
if (!key.loadFromFile(key_path))
if(!d->hiddenService->privateKey().bytes().empty())
{ {
RsWarn() << "Cannot load legacy format key from" << legacyDir << "for conversion"; RsDbg() << "Got key from legacy dir: " ;
return false; RsDbg() << d->hiddenService->privateKey().bytes().toHex().toString() ;
} }
else
d->hiddenService = new Tor::HiddenService(this,key, legacyDir); RsWarn() << "Failed to load existing hidden service. Creating a new one." ;
std::cerr << "Got key from legacy dir: " << std::endl;
std::cerr << key.bytes().toHex().toString() << std::endl;
} }
else else
{ {
d->hiddenService = new Tor::HiddenService(this,legacyDir); d->hiddenService = new Tor::HiddenService(this,legacyDir);
std::cerr << "Creating new hidden service." << std::endl; RsDbg() << "Creating new hidden service." << std::endl;
// connect(d->hiddenService, SIGNAL(privateKeyChanged()), this, SLOT(hiddenServicePrivateKeyChanged())) ; // connect(d->hiddenService, SIGNAL(privateKeyChanged()), this, SLOT(hiddenServicePrivateKeyChanged())) ;
// connect(d->hiddenService, SIGNAL(hostnameChanged()), this, SLOT(hiddenServiceHostnameChanged())) ; // connect(d->hiddenService, SIGNAL(hostnameChanged()), this, SLOT(hiddenServiceHostnameChanged())) ;

View File

@ -163,10 +163,7 @@ void TorControlDialog::showLog()
int n = s.indexOf(QString("Bootstrapped")); int n = s.indexOf(QString("Bootstrapped"));
if(n >= 0) if(n >= 0)
{
torBootstrapStatus_LB->setText(s.mid(n+QString("Bootstrapped").length())); torBootstrapStatus_LB->setText(s.mid(n+QString("Bootstrapped").length()));
QCoreApplication::processEvents(); // forces update
}
} }
} }
//std::cerr << "Connexion Proxy: " << RsTor::socksAddress() << ":" << QString::number(RsTor::socksPort()).toStdString() << std::endl; //std::cerr << "Connexion Proxy: " << RsTor::socksAddress() << ":" << QString::number(RsTor::socksPort()).toStdString() << std::endl;