mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
attempt at fixing tor bootstrap. Not working yet
This commit is contained in:
parent
139b22b41a
commit
da86da29ff
@ -159,6 +159,7 @@ public:
|
||||
ERR_ALREADY_RUNNING, /// Another istance is running already
|
||||
ERR_CANT_ACQUIRE_LOCK, /// Another istance is already running?
|
||||
ERR_NO_AVAILABLE_ACCOUNT, /// Used in retroshare-service -U list when no account is available
|
||||
ERR_CANNOT_CONFIGURE_TOR, /// cannot start/configure Tor for an auto-tor node
|
||||
ERR_UNKNOWN /// Unkown error, maybe password is wrong?
|
||||
};
|
||||
|
||||
@ -184,6 +185,7 @@ public:
|
||||
static bool isPortable();
|
||||
static bool isWindowsXP();
|
||||
static bool collectEntropy(uint32_t bytes) ;
|
||||
static bool startAutoTor();
|
||||
|
||||
/*!
|
||||
* \brief lockFilePath
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "util/folderiterator.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "retroshare/rstor.h"
|
||||
#include "retroshare/rsnotify.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "plugins/pluginmanager.h"
|
||||
@ -1923,6 +1924,46 @@ int RsServer::StartupRetroShare()
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool RsInit::startAutoTor()
|
||||
{
|
||||
std::cerr << "(II) node is an automated Tor node => launching Tor auto-configuration." << std::endl;
|
||||
// Now that we know the Tor service running, and we know the SSL id, we can make sure it provides a viable hidden service
|
||||
|
||||
std::string tor_hidden_service_dir = RsAccounts::AccountDirectory() + "/hidden_service/" ;
|
||||
|
||||
RsTor::setTorDataDirectory(RsAccounts::ConfigDirectory() + "/tor/");
|
||||
RsTor::setHiddenServiceDirectory(tor_hidden_service_dir); // re-set it, because now it's changed to the specific location that is run
|
||||
|
||||
RsDirUtil::checkCreateDirectory(std::string(tor_hidden_service_dir)) ;
|
||||
|
||||
if(! RsTor::start() || RsTor::hasError())
|
||||
{
|
||||
std::cerr << "(EE) Tor cannot be started on your system: "+RsTor::errorMessage() << std::endl ;
|
||||
return false ;
|
||||
}
|
||||
std::cerr << "(II) Tor has been started." << std::endl;
|
||||
|
||||
// now start/create the hidden service as needed.
|
||||
|
||||
std::string service_id;
|
||||
RsTor::setupHiddenService();
|
||||
|
||||
while(RsTor::torStatus() != RsTorStatus::READY && RsTor::getHiddenServiceStatus(service_id) != RsTorHiddenServiceStatus::ONLINE) // runs until some status is reached: either tor works, or it fails.
|
||||
{
|
||||
rstime::rs_usleep(0.5*1000*1000) ;
|
||||
|
||||
std::cerr << "(II) Hidden service ID: " << service_id << ", status: " << (int)RsTor::getHiddenServiceStatus(service_id) << std::endl;
|
||||
if(RsTor::hasError())
|
||||
{
|
||||
std::string error_msg = RsTor::errorMessage();
|
||||
|
||||
std::cerr << "(EE) Tor hidden service cannot be started: " << error_msg << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RsInit::LoadCertificateStatus RsLoginHelper::attemptLogin(const RsPeerId& account, const std::string& password)
|
||||
{
|
||||
if(isLoggedIn()) return RsInit::ERR_ALREADY_RUNNING;
|
||||
@ -1942,6 +1983,16 @@ RsInit::LoadCertificateStatus RsLoginHelper::attemptLogin(const RsPeerId& accoun
|
||||
rsNotify->setDisableAskPassword(false) ;
|
||||
rsNotify->clearPgpPassphrase() ;
|
||||
|
||||
bool is_hidden_node = false;
|
||||
bool is_auto_tor = false ;
|
||||
bool is_first_time = false ;
|
||||
|
||||
RsAccounts::getCurrentAccountOptions(is_hidden_node,is_auto_tor,is_first_time);
|
||||
|
||||
if(is_auto_tor)
|
||||
if(!RsInit::startAutoTor())
|
||||
return RsInit::ERR_CANNOT_CONFIGURE_TOR;
|
||||
|
||||
if(ret == RsInit::OK && RsControl::instance()->StartupRetroShare() == 1)
|
||||
return RsInit::OK;
|
||||
|
||||
|
@ -604,14 +604,14 @@ RsTorHiddenServiceStatus RsTor::getHiddenServiceStatus(std::string& service_id)
|
||||
auto list = instance()->control()->hiddenServices();
|
||||
|
||||
if(list.empty())
|
||||
return RsTorHiddenServiceStatus::NOT_CREATRED;
|
||||
return RsTorHiddenServiceStatus::NOT_CREATED;
|
||||
|
||||
service_id = (*list.begin())->serviceId().toStdString();
|
||||
|
||||
switch((*list.begin())->status())
|
||||
{
|
||||
default:
|
||||
case Tor::HiddenService::NotCreated: return RsTorHiddenServiceStatus::NOT_CREATRED;
|
||||
case Tor::HiddenService::NotCreated: return RsTorHiddenServiceStatus::NOT_CREATED;
|
||||
case Tor::HiddenService::Offline : return RsTorHiddenServiceStatus::OFFLINE;
|
||||
case Tor::HiddenService::Online : return RsTorHiddenServiceStatus::ONLINE;
|
||||
}
|
||||
|
@ -22,7 +22,10 @@
|
||||
#include "util/stacktrace.h"
|
||||
#include "util/argstream.h"
|
||||
#include "util/rskbdinput.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "retroshare/rstor.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
||||
#ifdef RS_JSONAPI
|
||||
#include "retroshare/rsjsonapi.h"
|
||||
@ -47,6 +50,7 @@ static CrashStackTrace gCrashStackTrace;
|
||||
|
||||
# include "util/androiddebug.h"
|
||||
#endif // def __ANDROID__
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
@ -95,7 +99,9 @@ int main(int argc, char* argv[])
|
||||
#ifdef __ANDROID__
|
||||
AndroidStdIOCatcher dbg; (void) dbg;
|
||||
QAndroidService app(argc, argv);
|
||||
#endif // def __ANDROID__
|
||||
#else // def __ANDROID__
|
||||
QCoreApplication app(argc,argv); // needed for TorManaer (that uses QDir). To be removed when TorManager doesn't use Qt anymore.
|
||||
#endif
|
||||
|
||||
signal(SIGINT, signalHandler);
|
||||
signal(SIGTERM, signalHandler);
|
||||
@ -311,6 +317,35 @@ int main(int argc, char* argv[])
|
||||
<< std::endl;
|
||||
return -result;
|
||||
}
|
||||
|
||||
if(RsAccounts::isTorAuto())
|
||||
{
|
||||
|
||||
std::cerr << "(II) Hidden service is ready:" << std::endl;
|
||||
|
||||
std::string service_id ;
|
||||
std::string onion_address ;
|
||||
uint16_t service_port ;
|
||||
uint16_t service_target_port ;
|
||||
uint16_t proxy_server_port ;
|
||||
std::string service_target_address ;
|
||||
std::string proxy_server_address ;
|
||||
|
||||
RsTor::getHiddenServiceInfo(service_id,onion_address,service_port,service_target_address,service_target_port);
|
||||
RsTor::getProxyServerInfo(proxy_server_address,proxy_server_port) ;
|
||||
|
||||
std::cerr << " onion address : " << onion_address << std::endl;
|
||||
std::cerr << " service_id : " << service_id << std::endl;
|
||||
std::cerr << " service port : " << service_port << std::endl;
|
||||
std::cerr << " target port : " << service_target_port << std::endl;
|
||||
std::cerr << " target address : " << service_target_address << std::endl;
|
||||
|
||||
std::cerr << "Setting proxy server to " << service_target_address << ":" << service_target_port << std::endl;
|
||||
|
||||
rsPeers->setLocalAddress(rsPeers->getOwnId(), service_target_address, service_target_port);
|
||||
rsPeers->setHiddenNode(rsPeers->getOwnId(), onion_address, service_port);
|
||||
rsPeers->setProxyServer(RS_HIDDEN_TYPE_TOR, proxy_server_address,proxy_server_port) ;
|
||||
}
|
||||
}
|
||||
#endif // def RS_SERVICE_TERMINAL_LOGIN
|
||||
|
||||
|
@ -22,7 +22,9 @@
|
||||
|
||||
TARGET = retroshare-service
|
||||
|
||||
QT += core
|
||||
CONFIG += qt
|
||||
|
||||
QT += core network
|
||||
QT -= gui
|
||||
|
||||
!include("../../libretroshare/src/use_libretroshare.pri"):error("Including")
|
||||
|
Loading…
Reference in New Issue
Block a user