mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
commit
c948517c3d
32 changed files with 1171 additions and 1063 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "hash_cache.h"
|
||||
#include "filelist_io.h"
|
||||
#include "file_sharing_defaults.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
|
||||
//#define HASHSTORAGE_DEBUG 1
|
||||
|
||||
|
@ -478,7 +479,7 @@ bool HashStorage::try_load_import_old_hash_cache()
|
|||
{
|
||||
// compute file name
|
||||
|
||||
std::string base_dir = rsAccounts->PathAccountDirectory();
|
||||
std::string base_dir = RsAccounts::AccountDirectory();
|
||||
std::string old_cache_filename = base_dir + "/" + "file_cache.bin" ;
|
||||
|
||||
// check for unencrypted
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include "retroshare/rsids.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "rsserver/rsaccounts.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
|
||||
#include "rsserver/p3face.h"
|
||||
|
||||
|
@ -48,7 +48,7 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
|
|||
{
|
||||
// make sure the base directory exists
|
||||
|
||||
std::string base_dir = rsAccounts->PathAccountDirectory();
|
||||
std::string base_dir = RsAccounts::AccountDirectory();
|
||||
|
||||
if(base_dir.empty())
|
||||
throw std::runtime_error("Cannot create base directory to store/access file sharing files.") ;
|
||||
|
|
|
@ -39,12 +39,12 @@
|
|||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
|
||||
#include "rsitems/rsfiletransferitems.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "rsserver/p3face.h"
|
||||
#include "rsserver/rsaccounts.h"
|
||||
#include "turtle/p3turtle.h"
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
|
@ -148,8 +148,9 @@ void ftServer::SetupFtServer()
|
|||
mFtController = new ftController(mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType);
|
||||
mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra);
|
||||
|
||||
std::string emergencySaveDir = rsAccounts->PathAccountDirectory();
|
||||
std::string emergencyPartialsDir = rsAccounts->PathAccountDirectory();
|
||||
std::string emergencySaveDir = RsAccounts::AccountDirectory();
|
||||
std::string emergencyPartialsDir = RsAccounts::AccountDirectory();
|
||||
|
||||
if (emergencySaveDir != "")
|
||||
{
|
||||
emergencySaveDir += "/";
|
||||
|
|
|
@ -32,9 +32,6 @@ static struct RsLog::logInfo pqipersongrpzoneInfo = {RsLog::Default, "pqipersong
|
|||
/****
|
||||
* #define PQI_DISABLE_UDP 1
|
||||
***/
|
||||
#ifdef RETROTOR
|
||||
#define PQI_DISABLE_UDP 1
|
||||
#endif
|
||||
|
||||
/********************************** SSL Specific features ***************************/
|
||||
|
||||
|
|
|
@ -121,51 +121,80 @@ class RsInit
|
|||
|
||||
|
||||
|
||||
/* Seperate Class for dealing with Accounts */
|
||||
/* Seperate static Class for dealing with Accounts */
|
||||
|
||||
namespace RsAccounts
|
||||
class RsAccountsDetail ;
|
||||
|
||||
class RsAccounts
|
||||
{
|
||||
/**
|
||||
* @brief ConfigDirectory (normally ~/.retroshare) you can call this method
|
||||
* even before initialisation (you can't with some other methods)
|
||||
* @see RsAccountsDetail::PathBaseDirectory()
|
||||
*/
|
||||
std::string ConfigDirectory();
|
||||
public:
|
||||
// Should be called once before everything else.
|
||||
|
||||
static bool init(const std::string &opt_base_dir, int& error_code);
|
||||
|
||||
/**
|
||||
* @brief DataDirectory
|
||||
* you can call this method even before initialisation (you can't with some other methods)
|
||||
* @param check if set to true and directory does not exist, return empty string
|
||||
* @return path where global platform independent files are stored, like bdboot.txt or webinterface files
|
||||
*/
|
||||
std::string DataDirectory(bool check = true);
|
||||
* @brief ConfigDirectory (normally ~/.retroshare) you can call this method
|
||||
* even before initialisation (you can't with some other methods)
|
||||
*
|
||||
* On linux: ~/.retroshare/
|
||||
*
|
||||
* @see RsAccountsDetail::PathBaseDirectory()
|
||||
*/
|
||||
static std::string ConfigDirectory();
|
||||
|
||||
std::string PGPDirectory();
|
||||
std::string AccountDirectory();
|
||||
/**
|
||||
* @brief DataDirectory
|
||||
* you can call this method even before initialisation (you can't with some other methods)
|
||||
* @param check if set to true and directory does not exist, return empty string
|
||||
* @return path where global platform independent files are stored, like bdboot.txt or webinterface files
|
||||
*/
|
||||
static std::string systemDataDirectory(bool check = true);
|
||||
static std::string PGPDirectory();
|
||||
|
||||
// PGP Accounts.
|
||||
int GetPGPLogins(std::list<RsPgpId> &pgpIds);
|
||||
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
|
||||
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
|
||||
static int GetPGPLogins(std::list<RsPgpId> &pgpIds);
|
||||
static int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
|
||||
static bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
|
||||
|
||||
// PGP Support Functions.
|
||||
bool ExportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;
|
||||
bool ImportIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error) ;
|
||||
bool ImportIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error) ;
|
||||
void GetUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys);
|
||||
bool CopyGnuPGKeyrings() ;
|
||||
static bool ExportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;
|
||||
static bool ImportIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error) ;
|
||||
static bool ImportIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error) ;
|
||||
static void GetUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys);
|
||||
static bool CopyGnuPGKeyrings() ;
|
||||
|
||||
// Rs Accounts
|
||||
bool SelectAccount(const RsPeerId& id);
|
||||
static bool SelectAccount(const RsPeerId& id);
|
||||
static bool GetPreferredAccountId(RsPeerId &id);
|
||||
static bool GetAccountIds(std::list<RsPeerId> &ids);
|
||||
|
||||
bool GetPreferredAccountId(RsPeerId &id);
|
||||
bool GetAccountIds(std::list<RsPeerId> &ids);
|
||||
bool GetAccountDetails(const RsPeerId &id,
|
||||
RsPgpId &gpgId, std::string &gpgName,
|
||||
std::string &gpgEmail, std::string &location);
|
||||
static bool GetAccountDetails(const RsPeerId &id, RsPgpId &gpgId, std::string &gpgName, std::string &gpgEmail, std::string &location);
|
||||
|
||||
bool GenerateSSLCertificate(const RsPgpId& pgp_id, const std::string& org, const std::string& loc, const std::string& country, const bool ishiddenloc, const std::string& passwd, RsPeerId &sslId, std::string &errString);
|
||||
static bool createNewAccount(const RsPgpId& pgp_id, const std::string& org, const std::string& loc, const std::string& country, bool ishiddenloc,bool is_auto_tor, const std::string& passwd, RsPeerId &sslId, std::string &errString);
|
||||
|
||||
static void storeSelectedAccount() ;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// All methods bellow can only be called ones SelectAccount() as been called. //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool getCurrentAccountOptions(bool& is_hidden,bool& is_tor_auto,bool& is_first_time) ;
|
||||
|
||||
static bool checkCreateAccountDirectory(); // Generate the hierarchy of directories below ~/.retroshare/[SSL dir]/
|
||||
static bool isHiddenNode() ; // true if the running node is a hidden node. Used to choose which services to start.
|
||||
static bool isTorAuto() ; // true if the running node is a hidden node using automated Tor management
|
||||
|
||||
static std::string AccountDirectory(); // linux: ~/.retroshare/[SSL dir]/
|
||||
static std::string AccountKeysDirectory(); // linux: ~/.retroshare/[SSL dir]/keys/
|
||||
static std::string AccountPathCertFile(); // linux: ~/.retroshare/[SSL dir]/keys/user_cert.pem
|
||||
static std::string AccountPathKeyFile(); // linux: ~/.retroshare/[SSL dir]/keys/user_pk.pem
|
||||
static std::string AccountLocationName();
|
||||
|
||||
static bool lockPreferredAccount() ; // are these methods any useful??
|
||||
static void unlockPreferredAccount() ;
|
||||
|
||||
private:
|
||||
static RsAccountsDetail *rsAccounts ;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
#include <openssl/ssl.h>
|
||||
|
||||
// Global singleton declaration of data.
|
||||
RsAccountsDetail *rsAccounts;
|
||||
RsAccountsDetail *RsAccounts::rsAccounts;
|
||||
|
||||
/* Uses private class - so must be hidden */
|
||||
static bool checkAccount(const std::string &accountdir, AccountDetails &account,std::map<std::string,std::vector<std::string> >& unsupported_keys);
|
||||
|
@ -67,11 +67,8 @@ RsAccountsDetail::RsAccountsDetail() : mAccountsLocked(false), mPreferredId("")
|
|||
bool RsAccountsDetail::loadAccounts()
|
||||
{
|
||||
int failing_accounts ;
|
||||
#ifdef RETROTOR
|
||||
getAvailableAccounts(mAccounts,failing_accounts,mUnsupportedKeys,true);
|
||||
#else
|
||||
#warning we might need some switch here for hidden nodes only
|
||||
getAvailableAccounts(mAccounts,failing_accounts,mUnsupportedKeys,false);
|
||||
#endif
|
||||
|
||||
loadPreferredAccount();
|
||||
checkPreferredId();
|
||||
|
@ -105,7 +102,7 @@ bool RsAccountsDetail::checkAccountDirectory()
|
|||
return false;
|
||||
}
|
||||
|
||||
return setupAccount(PathAccountDirectory());
|
||||
return setupAccount(getCurrentAccountPathAccountDirectory());
|
||||
}
|
||||
|
||||
#warning we need to clean that up. Login should only ask for a SSL id, instead of a std::string.
|
||||
|
@ -219,7 +216,7 @@ std::string RsAccountsDetail::PathBaseDirectory()
|
|||
}
|
||||
|
||||
|
||||
std::string RsAccountsDetail::PathAccountDirectory()
|
||||
std::string RsAccountsDetail::getCurrentAccountPathAccountDirectory()
|
||||
{
|
||||
std::string path;
|
||||
|
||||
|
@ -235,9 +232,9 @@ std::string RsAccountsDetail::PathAccountDirectory()
|
|||
return path;
|
||||
}
|
||||
|
||||
std::string RsAccountsDetail::PathAccountKeysDirectory()
|
||||
std::string RsAccountsDetail::getCurrentAccountPathAccountKeysDirectory()
|
||||
{
|
||||
std::string path = PathAccountDirectory();
|
||||
std::string path = getCurrentAccountPathAccountDirectory();
|
||||
if (path.empty())
|
||||
{
|
||||
return path;
|
||||
|
@ -247,9 +244,9 @@ std::string RsAccountsDetail::PathAccountKeysDirectory()
|
|||
return path;
|
||||
}
|
||||
|
||||
std::string RsAccountsDetail::PathKeyFile()
|
||||
std::string RsAccountsDetail::getCurrentAccountPathKeyFile()
|
||||
{
|
||||
std::string path = PathAccountKeysDirectory();
|
||||
std::string path = getCurrentAccountPathAccountKeysDirectory();
|
||||
if (path.empty())
|
||||
{
|
||||
return path;
|
||||
|
@ -259,9 +256,9 @@ std::string RsAccountsDetail::PathKeyFile()
|
|||
return path;
|
||||
}
|
||||
|
||||
std::string RsAccountsDetail::PathCertFile()
|
||||
std::string RsAccountsDetail::getCurrentAccountPathCertFile()
|
||||
{
|
||||
std::string path = PathAccountKeysDirectory();
|
||||
std::string path = getCurrentAccountPathAccountKeysDirectory();
|
||||
if (path.empty())
|
||||
{
|
||||
return path;
|
||||
|
@ -270,7 +267,7 @@ std::string RsAccountsDetail::PathCertFile()
|
|||
return path;
|
||||
}
|
||||
|
||||
std::string RsAccountsDetail::LocationName()
|
||||
std::string RsAccountsDetail::getCurrentAccountLocationName()
|
||||
{
|
||||
std::map<RsPeerId, AccountDetails>::const_iterator it;
|
||||
it = mAccounts.find(mPreferredId);
|
||||
|
@ -450,7 +447,7 @@ bool RsAccountsDetail::storePreferredAccount()
|
|||
*
|
||||
*/
|
||||
|
||||
bool RsAccountsDetail::getPreferredAccountId(RsPeerId &id)
|
||||
bool RsAccountsDetail::getCurrentAccountId(RsPeerId &id)
|
||||
{
|
||||
id = mPreferredId;
|
||||
return (!mPreferredId.isNull());
|
||||
|
@ -479,7 +476,7 @@ bool RsAccountsDetail::getAccountIds(std::list<RsPeerId> &ids)
|
|||
}
|
||||
|
||||
|
||||
bool RsAccountsDetail::getAccountDetails(const RsPeerId &id,
|
||||
bool RsAccountsDetail::getCurrentAccountDetails(const RsPeerId &id,
|
||||
RsPgpId &gpgId, std::string &gpgName,
|
||||
std::string &gpgEmail, std::string &location)
|
||||
{
|
||||
|
@ -496,14 +493,16 @@ bool RsAccountsDetail::getAccountDetails(const RsPeerId &id,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool RsAccountsDetail::getAccountOptions(bool &ishidden, bool &isFirstTimeRun)
|
||||
bool RsAccountsDetail::getCurrentAccountOptions(bool &ishidden,bool& isautotor, bool &isFirstTimeRun)
|
||||
{
|
||||
std::map<RsPeerId, AccountDetails>::iterator it;
|
||||
it = mAccounts.find(mPreferredId);
|
||||
if (it != mAccounts.end())
|
||||
{
|
||||
ishidden = it->second.mIsHiddenLoc;
|
||||
ishidden = it->second.mIsHiddenLoc;
|
||||
isFirstTimeRun = it->second.mFirstRun;
|
||||
isautotor = it->second.mIsAutoTor;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -598,7 +597,9 @@ bool RsAccountsDetail::getAvailableAccounts(std::map<RsPeerId, AccountDetails> &
|
|||
std::string lochex = (*it).substr(6); // rest of string.
|
||||
|
||||
bool hidden_location = false;
|
||||
bool auto_tor = false;
|
||||
bool valid_prefix = false;
|
||||
|
||||
if (prefix == "LOC06_")
|
||||
{
|
||||
valid_prefix = true;
|
||||
|
@ -607,6 +608,8 @@ bool RsAccountsDetail::getAvailableAccounts(std::map<RsPeerId, AccountDetails> &
|
|||
{
|
||||
valid_prefix = true;
|
||||
hidden_location = true;
|
||||
|
||||
auto_tor = RsDirUtil::checkDirectory(mBaseDirectory+"/"+*it+"/hidden_service");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -626,7 +629,9 @@ bool RsAccountsDetail::getAvailableAccounts(std::map<RsPeerId, AccountDetails> &
|
|||
|
||||
AccountDetails tmpId;
|
||||
tmpId.mIsHiddenLoc = hidden_location;
|
||||
tmpId.mIsAutoTor = auto_tor;
|
||||
tmpId.mAccountDir = *it;
|
||||
|
||||
if (checkAccount(accountdir, tmpId,unsupported_keys))
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
|
@ -692,7 +697,7 @@ static bool checkAccount(const std::string &accountdir, AccountDetails &account,
|
|||
std::cerr << "issuerName: " << account.mPgpId << " id: " << account.mSslId << std::endl;
|
||||
#endif
|
||||
|
||||
if(! rsAccounts->GetPGPLoginDetails(account.mPgpId, account.mPgpName, account.mPgpEmail))
|
||||
if(! RsAccounts::GetPGPLoginDetails(account.mPgpId, account.mPgpName, account.mPgpEmail))
|
||||
return false ;
|
||||
|
||||
if(!AuthGPG::getAuthGPG()->haveSecretKey(account.mPgpId))
|
||||
|
@ -983,7 +988,7 @@ bool RsAccountsDetail::copyGnuPGKeyrings()
|
|||
|
||||
|
||||
/* Create SSL Certificates */
|
||||
bool RsAccountsDetail::GenerateSSLCertificate(const RsPgpId& pgp_id, const std::string& org, const std::string& loc, const std::string& country, const bool ishiddenloc, const std::string& passwd, RsPeerId &sslId, std::string &errString)
|
||||
bool RsAccountsDetail::GenerateSSLCertificate(const RsPgpId& pgp_id, const std::string& org, const std::string& loc, const std::string& country, bool ishiddenloc,bool isautotor, const std::string& passwd, RsPeerId &sslId, std::string &errString)
|
||||
{
|
||||
/* select the PGP Identity first */
|
||||
if (!SelectPGPAccount(pgp_id))
|
||||
|
@ -1136,6 +1141,7 @@ bool RsAccountsDetail::GenerateSSLCertificate(const RsPgpId& pgp_id, const s
|
|||
|
||||
newAccount.mLocation = loc;
|
||||
newAccount.mIsHiddenLoc = ishiddenloc;
|
||||
newAccount.mIsAutoTor = isautotor;
|
||||
|
||||
newAccount.mFirstRun = true;
|
||||
|
||||
|
@ -1259,11 +1265,51 @@ bool RsInit::LoadPassword(const std::string& id, const std::string& inPwd)
|
|||
* PUBLIC INTERFACE FUNCTIONS
|
||||
********************************************************************************/
|
||||
|
||||
bool RsAccounts::init(const std::string& opt_base_dir,int& error_code)
|
||||
{
|
||||
rsAccounts = new RsAccountsDetail ;
|
||||
|
||||
// first check config directories, and set bootstrap values.
|
||||
if(!rsAccounts->setupBaseDirectory(opt_base_dir))
|
||||
{
|
||||
error_code = RS_INIT_BASE_DIR_ERROR ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// Setup PGP stuff.
|
||||
std::string pgp_dir = rsAccounts->PathPGPDirectory();
|
||||
|
||||
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
||||
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
||||
|
||||
AuthGPG::init( pgp_dir + "/retroshare_public_keyring.gpg",
|
||||
pgp_dir + "/retroshare_secret_keyring.gpg",
|
||||
pgp_dir + "/retroshare_trustdb.gpg",
|
||||
pgp_dir + "/lock");
|
||||
|
||||
// load Accounts.
|
||||
if (!rsAccounts->loadAccounts())
|
||||
{
|
||||
error_code = RS_INIT_NO_KEYRING ;
|
||||
return false ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Directories.
|
||||
std::string RsAccounts::ConfigDirectory() { return RsAccountsDetail::PathBaseDirectory(); }
|
||||
std::string RsAccounts::DataDirectory(bool check) { return RsAccountsDetail::PathDataDirectory(check); }
|
||||
std::string RsAccounts::systemDataDirectory(bool check) { return RsAccountsDetail::PathDataDirectory(check); }
|
||||
std::string RsAccounts::PGPDirectory() { return rsAccounts->PathPGPDirectory(); }
|
||||
std::string RsAccounts::AccountDirectory() { return rsAccounts->PathAccountDirectory(); }
|
||||
std::string RsAccounts::AccountDirectory() { return rsAccounts->getCurrentAccountPathAccountDirectory(); }
|
||||
std::string RsAccounts::AccountKeysDirectory() { return rsAccounts->getCurrentAccountPathAccountKeysDirectory(); }
|
||||
std::string RsAccounts::AccountPathCertFile() { return rsAccounts->getCurrentAccountPathCertFile(); }
|
||||
std::string RsAccounts::AccountPathKeyFile() { return rsAccounts->getCurrentAccountPathKeyFile(); }
|
||||
std::string RsAccounts::AccountLocationName() { return rsAccounts->getCurrentAccountLocationName(); }
|
||||
|
||||
bool RsAccounts::lockPreferredAccount() { return rsAccounts->lockPreferredAccount();} // are these methods any useful??
|
||||
void RsAccounts::unlockPreferredAccount() { rsAccounts->unlockPreferredAccount(); }
|
||||
|
||||
bool RsAccounts::checkCreateAccountDirectory() { return rsAccounts->checkAccountDirectory(); }
|
||||
|
||||
// PGP Accounts.
|
||||
int RsAccounts::GetPGPLogins(std::list<RsPgpId> &pgpIds)
|
||||
|
@ -1307,6 +1353,7 @@ bool RsAccounts::CopyGnuPGKeyrings()
|
|||
return rsAccounts->copyGnuPGKeyrings();
|
||||
}
|
||||
|
||||
void RsAccounts::storeSelectedAccount() { rsAccounts->storePreferredAccount() ;}
|
||||
// Rs Accounts
|
||||
bool RsAccounts::SelectAccount(const RsPeerId &id)
|
||||
{
|
||||
|
@ -1315,7 +1362,40 @@ bool RsAccounts::SelectAccount(const RsPeerId &id)
|
|||
|
||||
bool RsAccounts::GetPreferredAccountId(RsPeerId &id)
|
||||
{
|
||||
return rsAccounts->getPreferredAccountId(id);
|
||||
return rsAccounts->getCurrentAccountId(id);
|
||||
}
|
||||
|
||||
bool RsAccounts::getCurrentAccountOptions(bool& is_hidden,bool& is_tor_auto,bool& is_first_time)
|
||||
{
|
||||
return rsAccounts->getCurrentAccountOptions(is_hidden,is_tor_auto,is_first_time);
|
||||
}
|
||||
bool RsAccounts::isHiddenNode()
|
||||
{
|
||||
bool hidden = false ;
|
||||
bool is_tor_only = false ;
|
||||
bool is_first_time = false ;
|
||||
|
||||
if(!getCurrentAccountOptions(hidden,is_tor_only,is_first_time))
|
||||
{
|
||||
std::cerr << "(EE) Critical problem: RsAccounts::getCurrentAccountOptions() called but no account chosen!" << std::endl;
|
||||
throw std::runtime_error("inconsistent configuration") ;
|
||||
}
|
||||
|
||||
return hidden ;
|
||||
}
|
||||
bool RsAccounts::isTorAuto()
|
||||
{
|
||||
bool hidden = false ;
|
||||
bool is_tor_only = false ;
|
||||
bool is_first_time = false ;
|
||||
|
||||
if(!getCurrentAccountOptions(hidden,is_tor_only,is_first_time))
|
||||
{
|
||||
std::cerr << "(EE) Critical problem: RsAccounts::getCurrentAccountOptions() called but no account chosen!" << std::endl;
|
||||
throw std::runtime_error("inconsistent configuration") ;
|
||||
}
|
||||
|
||||
return is_tor_only ;
|
||||
}
|
||||
|
||||
bool RsAccounts::GetAccountIds(std::list<RsPeerId> &ids)
|
||||
|
@ -1327,12 +1407,12 @@ bool RsAccounts::GetAccountDetails(const RsPeerId &id,
|
|||
RsPgpId &pgpId, std::string &pgpName,
|
||||
std::string &pgpEmail, std::string &location)
|
||||
{
|
||||
return rsAccounts->getAccountDetails(id, pgpId, pgpName, pgpEmail, location);
|
||||
return rsAccounts->getCurrentAccountDetails(id, pgpId, pgpName, pgpEmail, location);
|
||||
}
|
||||
|
||||
bool RsAccounts::GenerateSSLCertificate(const RsPgpId& pgp_id, const std::string& org, const std::string& loc, const std::string& country, const bool ishiddenloc, const std::string& passwd, RsPeerId &sslId, std::string &errString)
|
||||
bool RsAccounts::createNewAccount(const RsPgpId& pgp_id, const std::string& org, const std::string& loc, const std::string& country, bool ishiddenloc, bool isautotor, const std::string& passwd, RsPeerId &sslId, std::string &errString)
|
||||
{
|
||||
return rsAccounts->GenerateSSLCertificate(pgp_id, org, loc, country, ishiddenloc, passwd, sslId, errString);
|
||||
return rsAccounts->GenerateSSLCertificate(pgp_id, org, loc, country, ishiddenloc, isautotor, passwd, sslId, errString);
|
||||
}
|
||||
|
||||
/*********************************************************************************
|
||||
|
|
|
@ -49,6 +49,7 @@ class AccountDetails
|
|||
std::string mLocation;
|
||||
bool mIsHiddenLoc;
|
||||
bool mFirstRun;
|
||||
bool mIsAutoTor;
|
||||
|
||||
};
|
||||
|
||||
|
@ -58,9 +59,6 @@ class RsAccountsDetail
|
|||
RsAccountsDetail();
|
||||
|
||||
// These functions are externally accessible via RsAccounts namespace.
|
||||
|
||||
|
||||
|
||||
// These functions are accessible from inside libretroshare.
|
||||
|
||||
bool setupBaseDirectory(std::string alt_basedir);
|
||||
|
@ -87,52 +85,43 @@ class RsAccountsDetail
|
|||
// PGP Path is only dependent on BaseDirectory.
|
||||
std::string PathPGPDirectory();
|
||||
|
||||
// Below are dependent on mPreferredId.
|
||||
std::string PathAccountDirectory();
|
||||
std::string PathAccountKeysDirectory();
|
||||
std::string PathKeyFile();
|
||||
std::string PathCertFile();
|
||||
std::string LocationName();
|
||||
// Generate a new account based on a given PGP key returns its SSL id and sets it to be the preferred account.
|
||||
|
||||
bool GenerateSSLCertificate(const RsPgpId& gpg_id, const std::string& org, const std::string& loc, const std::string& country, bool ishiddenloc, bool is_auto_tor,const std::string& passwd, RsPeerId &sslId, std::string &errString);
|
||||
|
||||
// PGP Accounts.
|
||||
|
||||
int GetPGPLogins(std::list<RsPgpId> &pgpIds);
|
||||
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
|
||||
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
|
||||
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
|
||||
|
||||
bool SelectPGPAccount(const RsPgpId& pgpId);
|
||||
bool SelectPGPAccount(const RsPgpId& pgpId);
|
||||
|
||||
// PGP Support Functions.
|
||||
bool exportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;
|
||||
bool importIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error) ;
|
||||
bool importIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error) ;
|
||||
void getUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys);
|
||||
void getUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys);
|
||||
bool copyGnuPGKeyrings() ;
|
||||
|
||||
|
||||
// Selecting Rs Account.
|
||||
bool getAccountIds(std::list<RsPeerId> &ids);
|
||||
bool selectAccountByString(const std::string &prefUserString);
|
||||
bool selectId(const RsPeerId& preferredId);
|
||||
|
||||
// Details of Rs Account.
|
||||
bool getPreferredAccountId(RsPeerId &id);
|
||||
bool getAccountDetails(const RsPeerId &id, RsPgpId& gpgId, std::string &gpgName, std::string &gpgEmail, std::string &location);
|
||||
|
||||
bool getAccountOptions(bool &ishidden, bool &isFirstTimeRun);
|
||||
|
||||
|
||||
bool getAccountIds(std::list<RsPeerId> &ids);
|
||||
|
||||
bool GenerateSSLCertificate(const RsPgpId& gpg_id,
|
||||
const std::string& org, const std::string& loc,
|
||||
const std::string& country, const bool ishiddenloc,
|
||||
const std::string& passwd, RsPeerId &sslId,
|
||||
std::string &errString);
|
||||
|
||||
// From init file.
|
||||
bool storePreferredAccount();
|
||||
bool loadPreferredAccount();
|
||||
|
||||
// Details of current Rs Account.
|
||||
bool getCurrentAccountId(RsPeerId &id);
|
||||
bool getCurrentAccountDetails(const RsPeerId &id, RsPgpId& gpgId, std::string &gpgName, std::string &gpgEmail, std::string &location);
|
||||
bool getCurrentAccountOptions(bool &ishidden, bool &isautotor, bool &isFirstTimeRun);
|
||||
|
||||
std::string getCurrentAccountPathAccountDirectory();
|
||||
std::string getCurrentAccountPathAccountKeysDirectory();
|
||||
std::string getCurrentAccountPathKeyFile();
|
||||
std::string getCurrentAccountPathCertFile();
|
||||
std::string getCurrentAccountLocationName();
|
||||
|
||||
|
||||
private:
|
||||
bool checkPreferredId();
|
||||
|
||||
|
@ -155,6 +144,4 @@ class RsAccountsDetail
|
|||
std::map<std::string,std::vector<std::string> > mUnsupportedKeys ;
|
||||
};
|
||||
|
||||
// Global singleton declaration of data.
|
||||
extern RsAccountsDetail *rsAccounts;
|
||||
|
||||
|
|
|
@ -431,26 +431,10 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
|||
AuthSSL::AuthSSLInit();
|
||||
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL, "");
|
||||
|
||||
rsAccounts = new RsAccountsDetail();
|
||||
int error_code ;
|
||||
|
||||
// first check config directories, and set bootstrap values.
|
||||
if(!rsAccounts->setupBaseDirectory(opt_base_dir))
|
||||
return RS_INIT_BASE_DIR_ERROR ;
|
||||
|
||||
// Setup PGP stuff.
|
||||
std::string pgp_dir = rsAccounts->PathPGPDirectory();
|
||||
|
||||
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
||||
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
||||
|
||||
AuthGPG::init( pgp_dir + "/retroshare_public_keyring.gpg",
|
||||
pgp_dir + "/retroshare_secret_keyring.gpg",
|
||||
pgp_dir + "/retroshare_trustdb.gpg",
|
||||
pgp_dir + "/lock");
|
||||
|
||||
// load Accounts.
|
||||
if (!rsAccounts->loadAccounts())
|
||||
return RS_INIT_NO_KEYRING ;
|
||||
if(!RsAccounts::init(opt_base_dir,error_code))
|
||||
return error_code ;
|
||||
|
||||
// choose alternative account.
|
||||
if(prefUserString != "")
|
||||
|
@ -464,7 +448,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
|||
return RS_INIT_AUTH_FAILED ;
|
||||
}
|
||||
|
||||
if(rsAccounts->selectId(ssl_id))
|
||||
if(RsAccounts::SelectAccount(ssl_id))
|
||||
{
|
||||
std::cerr << "Auto-selectng account ID " << ssl_id << std::endl;
|
||||
return RS_INIT_HAVE_ACCOUNT;
|
||||
|
@ -474,7 +458,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
|||
#ifdef RS_AUTOLOGIN
|
||||
/* check that we have selected someone */
|
||||
RsPeerId preferredId;
|
||||
bool existingUser = rsAccounts->getPreferredAccountId(preferredId);
|
||||
bool existingUser = RsAccounts::GetPreferredAccountId(preferredId);
|
||||
|
||||
if (existingUser)
|
||||
{
|
||||
|
@ -550,44 +534,43 @@ bool RsInit::LoadPassword(const std::string& inPwd)
|
|||
*/
|
||||
int RsInit::LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath)
|
||||
{
|
||||
if (!rsAccounts->lockPreferredAccount())
|
||||
try
|
||||
{
|
||||
return 3; // invalid PreferredAccount.
|
||||
if (!RsAccounts::lockPreferredAccount())
|
||||
throw 3; // invalid PreferredAccount.
|
||||
|
||||
// Logic that used to be external to RsInit...
|
||||
RsPeerId accountId;
|
||||
if (!RsAccounts::GetPreferredAccountId(accountId))
|
||||
throw 3; // invalid PreferredAccount;
|
||||
|
||||
RsPgpId pgpId;
|
||||
std::string pgpName, pgpEmail, location;
|
||||
|
||||
if(!RsAccounts::GetAccountDetails(accountId, pgpId, pgpName, pgpEmail, location))
|
||||
throw 3; // invalid PreferredAccount;
|
||||
|
||||
if(0 == AuthGPG::getAuthGPG() -> GPGInit(pgpId))
|
||||
throw 3; // PGP Error.
|
||||
|
||||
int retVal = LockConfigDirectory(RsAccounts::AccountDirectory(), lockFilePath);
|
||||
|
||||
if(retVal > 0)
|
||||
throw retVal ;
|
||||
|
||||
if(LoadCertificates(autoLoginNT) != 1)
|
||||
{
|
||||
UnlockConfigDirectory();
|
||||
throw 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int retVal = 0;
|
||||
|
||||
// Logic that used to be external to RsInit...
|
||||
RsPeerId accountId;
|
||||
if (!rsAccounts->getPreferredAccountId(accountId))
|
||||
{
|
||||
retVal = 3; // invalid PreferredAccount;
|
||||
}
|
||||
|
||||
RsPgpId pgpId;
|
||||
std::string pgpName, pgpEmail, location;
|
||||
|
||||
if (retVal == 0 && !rsAccounts->getAccountDetails(accountId, pgpId, pgpName, pgpEmail, location))
|
||||
retVal = 3; // invalid PreferredAccount;
|
||||
|
||||
if (retVal == 0 && !rsAccounts->SelectPGPAccount(pgpId))
|
||||
retVal = 3; // PGP Error.
|
||||
|
||||
if(retVal == 0)
|
||||
retVal = LockConfigDirectory(rsAccounts->PathAccountDirectory(), lockFilePath);
|
||||
|
||||
if(retVal == 0 && LoadCertificates(autoLoginNT) != 1)
|
||||
{
|
||||
UnlockConfigDirectory();
|
||||
retVal = 3;
|
||||
}
|
||||
|
||||
if(retVal != 0)
|
||||
{
|
||||
rsAccounts->unlockPreferredAccount();
|
||||
}
|
||||
|
||||
return retVal;
|
||||
catch(int retVal)
|
||||
{
|
||||
RsAccounts::unlockPreferredAccount();
|
||||
return retVal ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -603,20 +586,20 @@ int RsInit::LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath
|
|||
int RsInit::LoadCertificates(bool autoLoginNT)
|
||||
{
|
||||
RsPeerId preferredId;
|
||||
if (!rsAccounts->getPreferredAccountId(preferredId))
|
||||
if (!RsAccounts::GetPreferredAccountId(preferredId))
|
||||
{
|
||||
std::cerr << "No Account Selected" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (rsAccounts->PathCertFile() == "")
|
||||
if (RsAccounts::AccountPathCertFile() == "")
|
||||
{
|
||||
std::cerr << "RetroShare needs a certificate" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rsAccounts->PathKeyFile() == "")
|
||||
if (RsAccounts::AccountPathKeyFile() == "")
|
||||
{
|
||||
std::cerr << "RetroShare needs a key" << std::endl;
|
||||
return 0;
|
||||
|
@ -638,9 +621,10 @@ int RsInit::LoadCertificates(bool autoLoginNT)
|
|||
}
|
||||
}
|
||||
|
||||
std::cerr << "rsAccounts->PathKeyFile() : " << rsAccounts->PathKeyFile() << std::endl;
|
||||
std::cerr << "rsAccounts->PathKeyFile() : " << RsAccounts::AccountPathKeyFile() << std::endl;
|
||||
|
||||
if(0 == AuthSSL::getAuthSSL() -> InitAuth(rsAccounts->PathCertFile().c_str(), rsAccounts->PathKeyFile().c_str(), rsInitConfig->passwd.c_str(), rsAccounts->LocationName()))
|
||||
if(0 == AuthSSL::getAuthSSL() -> InitAuth(RsAccounts::AccountPathCertFile().c_str(), RsAccounts::AccountPathKeyFile().c_str(), rsInitConfig->passwd.c_str(),
|
||||
RsAccounts::AccountLocationName()))
|
||||
{
|
||||
std::cerr << "SSL Auth Failed!";
|
||||
return 0 ;
|
||||
|
@ -665,7 +649,7 @@ int RsInit::LoadCertificates(bool autoLoginNT)
|
|||
rsInitConfig->gxs_passwd = rsInitConfig->passwd;
|
||||
rsInitConfig->passwd = "";
|
||||
|
||||
rsAccounts->storePreferredAccount();
|
||||
RsAccounts::storeSelectedAccount();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -673,7 +657,7 @@ int RsInit::LoadCertificates(bool autoLoginNT)
|
|||
bool RsInit::RsClearAutoLogin()
|
||||
{
|
||||
RsPeerId preferredId;
|
||||
if (!rsAccounts->getPreferredAccountId(preferredId))
|
||||
if (!RsAccounts::getSelectedAccountId(preferredId))
|
||||
{
|
||||
std::cerr << "RsInit::RsClearAutoLogin() No Account Selected" << std::endl;
|
||||
return 0;
|
||||
|
@ -833,11 +817,8 @@ RsGRouter *rsGRouter = NULL ;
|
|||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
#ifndef RETROTOR
|
||||
#include "tcponudp/tou.h"
|
||||
#include "tcponudp/rsudpstack.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef RS_USE_BITDHT
|
||||
#include "dht/p3bitdht.h"
|
||||
|
@ -884,6 +865,17 @@ RsControl *RsControl::instance()
|
|||
|
||||
int RsServer::StartupRetroShare()
|
||||
{
|
||||
RsPeerId ownId = AuthSSL::getAuthSSL()->OwnId();
|
||||
|
||||
std::cerr << "========================================================================" << std::endl;
|
||||
std::cerr << "== RsInit:: starting up Retroshare core ==" << std::endl;
|
||||
std::cerr << "== ==" << std::endl;
|
||||
std::cerr << "== Account/SSL ID : " << ownId << " ==" << std::endl;
|
||||
std::cerr << "== Node type : " << (RsAccounts::isHiddenNode()?"Hidden":"Normal") << " ==" << std::endl;
|
||||
if(RsAccounts::isHiddenNode())
|
||||
std::cerr << "== Tor/I2P configuration : " << (RsAccounts::isTorAuto()?"Tor Auto":"Manual ") << " ==" << std::endl;
|
||||
std::cerr << "========================================================================" << std::endl;
|
||||
|
||||
/**************************************************************************/
|
||||
/* STARTUP procedure */
|
||||
/**************************************************************************/
|
||||
|
@ -899,8 +891,6 @@ int RsServer::StartupRetroShare()
|
|||
return false ;
|
||||
}
|
||||
|
||||
RsPeerId ownId = AuthSSL::getAuthSSL()->OwnId();
|
||||
|
||||
/**************************************************************************/
|
||||
/* Any Initial Configuration (Commandline Options) */
|
||||
/**************************************************************************/
|
||||
|
@ -909,7 +899,7 @@ int RsServer::StartupRetroShare()
|
|||
std::cerr << "set the debugging to crashMode." << std::endl;
|
||||
if ((!rsInitConfig->haveLogFile) && (!rsInitConfig->outStderr))
|
||||
{
|
||||
std::string crashfile = rsAccounts->PathAccountDirectory();
|
||||
std::string crashfile = RsAccounts::AccountDirectory();
|
||||
crashfile += "/" + configLogFileName;
|
||||
setDebugCrashMode(crashfile.c_str());
|
||||
}
|
||||
|
@ -921,7 +911,7 @@ int RsServer::StartupRetroShare()
|
|||
}
|
||||
|
||||
/* check account directory */
|
||||
if (!rsAccounts->checkAccountDirectory())
|
||||
if (!RsAccounts::checkCreateAccountDirectory())
|
||||
{
|
||||
std::cerr << "RsServer::StartupRetroShare() - Fatal Error....." << std::endl;
|
||||
std::cerr << "checkAccount failed!" << std::endl;
|
||||
|
@ -933,8 +923,8 @@ int RsServer::StartupRetroShare()
|
|||
// Load up Certificates, and Old Configuration (if present)
|
||||
std::cerr << "Load up Certificates, and Old Configuration (if present)." << std::endl;
|
||||
|
||||
std::string emergencySaveDir = rsAccounts->PathAccountDirectory();
|
||||
std::string emergencyPartialsDir = rsAccounts->PathAccountDirectory();
|
||||
std::string emergencySaveDir = RsAccounts::AccountDirectory();
|
||||
std::string emergencyPartialsDir = RsAccounts::AccountDirectory();
|
||||
if (emergencySaveDir != "")
|
||||
{
|
||||
emergencySaveDir += "/";
|
||||
|
@ -948,13 +938,15 @@ int RsServer::StartupRetroShare()
|
|||
/**************************************************************************/
|
||||
std::cerr << "Load Configuration" << std::endl;
|
||||
|
||||
mConfigMgr = new p3ConfigMgr(rsAccounts->PathAccountDirectory());
|
||||
mConfigMgr = new p3ConfigMgr(RsAccounts::AccountDirectory());
|
||||
mGeneralConfig = new p3GeneralConfig();
|
||||
|
||||
// Get configuration options from rsAccounts.
|
||||
bool isHiddenNode = false;
|
||||
bool isFirstTimeRun = false;
|
||||
rsAccounts->getAccountOptions(isHiddenNode, isFirstTimeRun);
|
||||
bool isTorAuto = false;
|
||||
|
||||
RsAccounts::getCurrentAccountOptions(isHiddenNode,isTorAuto, isFirstTimeRun);
|
||||
|
||||
/**************************************************************************/
|
||||
/* setup classes / structures */
|
||||
|
@ -995,36 +987,40 @@ int RsServer::StartupRetroShare()
|
|||
sockaddr_clear(&tmpladdr);
|
||||
tmpladdr.sin_port = htons(rsInitConfig->port);
|
||||
|
||||
rsUdpStack *mDhtStack = NULL ;
|
||||
|
||||
if(!RsAccounts::isHiddenNode())
|
||||
{
|
||||
#ifdef LOCALNET_TESTING
|
||||
|
||||
rsUdpStack *mDhtStack = new rsUdpStack(UDP_TEST_RESTRICTED_LAYER, tmpladdr);
|
||||
mDhtStack = new rsUdpStack(UDP_TEST_RESTRICTED_LAYER, tmpladdr);
|
||||
|
||||
/* parse portRestrictions */
|
||||
unsigned int lport, uport;
|
||||
/* parse portRestrictions */
|
||||
unsigned int lport, uport;
|
||||
|
||||
if (doPortRestrictions)
|
||||
{
|
||||
if (2 == sscanf(portRestrictions.c_str(), "%u-%u", &lport, &uport))
|
||||
if (doPortRestrictions)
|
||||
{
|
||||
std::cerr << "Adding Port Restriction (" << lport << "-" << uport << ")";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to parse Port Restrictions ... exiting";
|
||||
std::cerr << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (2 == sscanf(portRestrictions.c_str(), "%u-%u", &lport, &uport))
|
||||
{
|
||||
std::cerr << "Adding Port Restriction (" << lport << "-" << uport << ")";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to parse Port Restrictions ... exiting";
|
||||
std::cerr << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mDhtStack->getUdpLayer();
|
||||
url->addRestrictedPortRange(lport, uport);
|
||||
}
|
||||
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mDhtStack->getUdpLayer();
|
||||
url->addRestrictedPortRange(lport, uport);
|
||||
}
|
||||
#else //LOCALNET_TESTING
|
||||
#ifdef RS_USE_BITDHT
|
||||
rsUdpStack *mDhtStack = new rsUdpStack(tmpladdr);
|
||||
mDhtStack = new rsUdpStack(tmpladdr);
|
||||
#endif
|
||||
#endif //LOCALNET_TESTING
|
||||
}
|
||||
|
||||
#ifdef RS_USE_BITDHT
|
||||
|
||||
|
@ -1032,12 +1028,12 @@ int RsServer::StartupRetroShare()
|
|||
#define BITDHT_FILTERED_IP_FILENAME "bdfilter.txt"
|
||||
|
||||
|
||||
std::string bootstrapfile = rsAccounts->PathAccountDirectory();
|
||||
std::string bootstrapfile = RsAccounts::AccountDirectory();
|
||||
if (bootstrapfile != "")
|
||||
bootstrapfile += "/";
|
||||
bootstrapfile += BITDHT_BOOTSTRAP_FILENAME;
|
||||
|
||||
std::string filteredipfile = rsAccounts->PathAccountDirectory();
|
||||
std::string filteredipfile = RsAccounts::AccountDirectory();
|
||||
if (filteredipfile != "")
|
||||
filteredipfile += "/";
|
||||
filteredipfile += BITDHT_FILTERED_IP_FILENAME;
|
||||
|
@ -1077,7 +1073,7 @@ int RsServer::StartupRetroShare()
|
|||
bdbootRF.close();
|
||||
}
|
||||
#else
|
||||
std::string installfile = rsAccounts->PathDataDirectory();
|
||||
std::string installfile = RsAccounts::systemDataDirectory();
|
||||
installfile += "/";
|
||||
installfile += BITDHT_BOOTSTRAP_FILENAME;
|
||||
|
||||
|
@ -1104,96 +1100,105 @@ int RsServer::StartupRetroShare()
|
|||
/* construct the rest of the stack, important to build them in the correct order! */
|
||||
/* MOST OF THIS IS COMMENTED OUT UNTIL THE REST OF libretroshare IS READY FOR IT! */
|
||||
|
||||
UdpSubReceiver *udpReceivers[RSUDP_NUM_TOU_RECVERS];
|
||||
int udpTypes[RSUDP_NUM_TOU_RECVERS];
|
||||
p3BitDht *mBitDht = NULL ;
|
||||
rsDht = NULL ;
|
||||
rsFixedUdpStack *mProxyStack = NULL ;
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
// FIRST DHT STUNNER.
|
||||
UdpStunner *mDhtStunner = new UdpStunner(mDhtStack);
|
||||
mDhtStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
||||
mDhtStack->addReceiver(mDhtStunner);
|
||||
|
||||
#ifdef LOCALNET_TESTING
|
||||
mDhtStunner->SetAcceptLocalNet();
|
||||
#endif
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
|
||||
// NEXT BITDHT.
|
||||
p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile, filteredipfile);
|
||||
|
||||
/* install external Pointer for Interface */
|
||||
rsDht = mBitDht;
|
||||
|
||||
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
|
||||
UdpRelayReceiver *mRelay = new UdpRelayReceiver(mDhtStack);
|
||||
udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX] = mRelay; /* RELAY Connections (DHT Port) */
|
||||
udpTypes[RSUDP_TOU_RECVER_RELAY_IDX] = TOU_RECEIVER_TYPE_UDPRELAY;
|
||||
mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX]);
|
||||
|
||||
// LAST ON THIS STACK IS STANDARD DIRECT TOU
|
||||
udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX] = new UdpPeerReceiver(mDhtStack); /* standard DIRECT Connections (DHT Port) */
|
||||
udpTypes[RSUDP_TOU_RECVER_DIRECT_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
|
||||
mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX]);
|
||||
|
||||
// NOW WE BUILD THE SECOND STACK.
|
||||
// Create the Second UdpStack... Port should be random (but openable!).
|
||||
// We do this by binding to xx.xx.xx.xx:0 which which gives us a random port.
|
||||
|
||||
struct sockaddr_in sndladdr;
|
||||
sockaddr_clear(&sndladdr);
|
||||
|
||||
#ifdef LOCALNET_TESTING
|
||||
|
||||
// // HACK Proxy Port near Dht Port - For Relay Testing.
|
||||
// uint16_t rndport = rsInitConfig->port + 3;
|
||||
// sndladdr.sin_port = htons(rndport);
|
||||
|
||||
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(UDP_TEST_RESTRICTED_LAYER, sndladdr);
|
||||
|
||||
/* portRestrictions already parsed */
|
||||
if (doPortRestrictions)
|
||||
if(!RsAccounts::isHiddenNode())
|
||||
{
|
||||
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mProxyStack->getUdpLayer();
|
||||
url->addRestrictedPortRange(lport, uport);
|
||||
}
|
||||
#else
|
||||
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(sndladdr);
|
||||
#endif
|
||||
UdpSubReceiver *udpReceivers[RSUDP_NUM_TOU_RECVERS];
|
||||
int udpTypes[RSUDP_NUM_TOU_RECVERS];
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
// FIRSTLY THE PROXY STUNNER.
|
||||
UdpStunner *mProxyStunner = new UdpStunner(mProxyStack);
|
||||
mProxyStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
||||
mProxyStack->addReceiver(mProxyStunner);
|
||||
// FIRST DHT STUNNER.
|
||||
UdpStunner *mDhtStunner = new UdpStunner(mDhtStack);
|
||||
mDhtStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
||||
mDhtStack->addReceiver(mDhtStunner);
|
||||
|
||||
#ifdef LOCALNET_TESTING
|
||||
mProxyStunner->SetAcceptLocalNet();
|
||||
mDhtStunner->SetAcceptLocalNet();
|
||||
#endif
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
|
||||
// FINALLY THE PROXY UDP CONNECTIONS
|
||||
udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX] = new UdpPeerReceiver(mProxyStack); /* PROXY Connections (Alt UDP Port) */
|
||||
udpTypes[RSUDP_TOU_RECVER_PROXY_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
|
||||
mProxyStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX]);
|
||||
// NEXT BITDHT.
|
||||
|
||||
// REAL INITIALISATION - WITH THREE MODES
|
||||
tou_init((void **) udpReceivers, udpTypes, RSUDP_NUM_TOU_RECVERS);
|
||||
|
||||
mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile, filteredipfile);
|
||||
|
||||
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
|
||||
UdpRelayReceiver *mRelay = new UdpRelayReceiver(mDhtStack);
|
||||
udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX] = mRelay; /* RELAY Connections (DHT Port) */
|
||||
udpTypes[RSUDP_TOU_RECVER_RELAY_IDX] = TOU_RECEIVER_TYPE_UDPRELAY;
|
||||
mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX]);
|
||||
|
||||
// LAST ON THIS STACK IS STANDARD DIRECT TOU
|
||||
udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX] = new UdpPeerReceiver(mDhtStack); /* standard DIRECT Connections (DHT Port) */
|
||||
udpTypes[RSUDP_TOU_RECVER_DIRECT_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
|
||||
mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX]);
|
||||
|
||||
/* install external Pointer for Interface */
|
||||
rsDht = mBitDht;
|
||||
|
||||
// NOW WE BUILD THE SECOND STACK.
|
||||
// Create the Second UdpStack... Port should be random (but openable!).
|
||||
// We do this by binding to xx.xx.xx.xx:0 which which gives us a random port.
|
||||
|
||||
struct sockaddr_in sndladdr;
|
||||
sockaddr_clear(&sndladdr);
|
||||
|
||||
#ifdef LOCALNET_TESTING
|
||||
|
||||
// // HACK Proxy Port near Dht Port - For Relay Testing.
|
||||
// uint16_t rndport = rsInitConfig->port + 3;
|
||||
// sndladdr.sin_port = htons(rndport);
|
||||
|
||||
mProxyStack = new rsFixedUdpStack(UDP_TEST_RESTRICTED_LAYER, sndladdr);
|
||||
|
||||
/* portRestrictions already parsed */
|
||||
if (doPortRestrictions)
|
||||
{
|
||||
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mProxyStack->getUdpLayer();
|
||||
url->addRestrictedPortRange(lport, uport);
|
||||
}
|
||||
#else
|
||||
mProxyStack = new rsFixedUdpStack(sndladdr);
|
||||
#endif
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
mBitDht->setupConnectBits(mDhtStunner, mProxyStunner, mRelay);
|
||||
// FIRSTLY THE PROXY STUNNER.
|
||||
UdpStunner *mProxyStunner = new UdpStunner(mProxyStack);
|
||||
mProxyStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
||||
mProxyStack->addReceiver(mProxyStunner);
|
||||
|
||||
#ifdef LOCALNET_TESTING
|
||||
mProxyStunner->SetAcceptLocalNet();
|
||||
#endif
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
|
||||
// FINALLY THE PROXY UDP CONNECTIONS
|
||||
udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX] = new UdpPeerReceiver(mProxyStack); /* PROXY Connections (Alt UDP Port) */
|
||||
udpTypes[RSUDP_TOU_RECVER_PROXY_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
|
||||
mProxyStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX]);
|
||||
|
||||
// REAL INITIALISATION - WITH THREE MODES
|
||||
tou_init((void **) udpReceivers, udpTypes, RSUDP_NUM_TOU_RECVERS);
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
mBitDht->setupConnectBits(mDhtStunner, mProxyStunner, mRelay);
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
mBitDht->setupConnectBits(mRelay);
|
||||
mBitDht->setupConnectBits(mRelay);
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
mNetMgr->setAddrAssist(new stunAddrAssist(mDhtStunner), new stunAddrAssist(mProxyStunner));
|
||||
mNetMgr->setAddrAssist(new stunAddrAssist(mDhtStunner), new stunAddrAssist(mProxyStunner));
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
// #else //RS_USE_BITDHT
|
||||
// /* install NULL Pointer for rsDht Interface */
|
||||
// rsDht = NULL;
|
||||
// #else //RS_USE_BITDHT
|
||||
// /* install NULL Pointer for rsDht Interface */
|
||||
// rsDht = NULL;
|
||||
#endif //RS_USE_BITDHT
|
||||
}
|
||||
|
||||
|
||||
/**************************** BITDHT ***********************************/
|
||||
|
@ -1208,7 +1213,7 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/****** New Ft Server **** !!! */
|
||||
ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl);
|
||||
ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory());
|
||||
ftserver->setConfigDirectory(RsAccounts::AccountDirectory());
|
||||
|
||||
ftserver->SetupFtServer() ;
|
||||
|
||||
|
@ -1224,12 +1229,12 @@ int RsServer::StartupRetroShare()
|
|||
std::vector<std::string> plugins_directories ;
|
||||
|
||||
#ifdef __APPLE__
|
||||
plugins_directories.push_back(rsAccounts->PathDataDirectory()) ;
|
||||
plugins_directories.push_back(RsAccounts::systemDataDirectory()) ;
|
||||
#endif
|
||||
#if !defined(WINDOWS_SYS) && defined(PLUGIN_DIR)
|
||||
plugins_directories.push_back(std::string(PLUGIN_DIR)) ;
|
||||
#endif
|
||||
std::string extensions_dir = rsAccounts->PathBaseDirectory() + "/extensions6/" ;
|
||||
std::string extensions_dir = RsAccounts::ConfigDirectory() + "/extensions6/" ;
|
||||
plugins_directories.push_back(extensions_dir) ;
|
||||
|
||||
if(!RsDirUtil::checkCreateDirectory(extensions_dir))
|
||||
|
@ -1272,7 +1277,7 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
#ifdef RS_ENABLE_GXS
|
||||
|
||||
std::string currGxsDir = rsAccounts->PathAccountDirectory() + "/gxs";
|
||||
std::string currGxsDir = RsAccounts::AccountDirectory() + "/gxs";
|
||||
RsDirUtil::checkCreateDirectory(currGxsDir);
|
||||
|
||||
RsNxsNetMgr* nxsMgr = new RsNxsNetMgrImpl(serviceCtrl);
|
||||
|
@ -1557,17 +1562,17 @@ int RsServer::StartupRetroShare()
|
|||
#endif
|
||||
|
||||
// new services to test.
|
||||
#ifndef RETROTOR
|
||||
p3BanList *mBanList = new p3BanList(serviceCtrl, mNetMgr);
|
||||
rsBanList = mBanList ;
|
||||
pqih -> addService(mBanList, true);
|
||||
#else
|
||||
rsBanList = NULL ;
|
||||
#endif
|
||||
|
||||
#ifdef RS_USE_BITDHT
|
||||
mBitDht->setupPeerSharer(mBanList);
|
||||
#endif
|
||||
p3BanList *mBanList = NULL;
|
||||
|
||||
if(!RsAccounts::isHiddenNode())
|
||||
{
|
||||
mBanList = new p3BanList(serviceCtrl, mNetMgr);
|
||||
rsBanList = mBanList ;
|
||||
pqih -> addService(mBanList, true);
|
||||
}
|
||||
else
|
||||
rsBanList = NULL ;
|
||||
|
||||
p3BandwidthControl *mBwCtrl = new p3BandwidthControl(pqih);
|
||||
pqih -> addService(mBwCtrl, true);
|
||||
|
@ -1581,30 +1586,34 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/**************************************************************************/
|
||||
|
||||
if(!RsAccounts::isHiddenNode())
|
||||
{
|
||||
#ifdef RS_USE_BITDHT
|
||||
mNetMgr->addNetAssistConnect(1, mBitDht);
|
||||
mNetMgr->addNetListener(mDhtStack);
|
||||
mNetMgr->addNetListener(mProxyStack);
|
||||
mBitDht->setupPeerSharer(mBanList);
|
||||
|
||||
mNetMgr->addNetAssistConnect(1, mBitDht);
|
||||
mNetMgr->addNetListener(mDhtStack);
|
||||
mNetMgr->addNetListener(mProxyStack);
|
||||
#endif
|
||||
|
||||
#ifdef RS_ENABLE_ZEROCONF
|
||||
p3ZeroConf *mZeroConf = new p3ZeroConf(
|
||||
AuthGPG::getAuthGPG()->getGPGOwnId(), ownId,
|
||||
mLinkMgr, mNetMgr, mPeerMgr);
|
||||
mNetMgr->addNetAssistConnect(2, mZeroConf);
|
||||
mNetMgr->addNetListener(mZeroConf);
|
||||
p3ZeroConf *mZeroConf = new p3ZeroConf(
|
||||
AuthGPG::getAuthGPG()->getGPGOwnId(), ownId,
|
||||
mLinkMgr, mNetMgr, mPeerMgr);
|
||||
mNetMgr->addNetAssistConnect(2, mZeroConf);
|
||||
mNetMgr->addNetListener(mZeroConf);
|
||||
#endif
|
||||
|
||||
#ifdef RS_ENABLE_ZCNATASSIST
|
||||
// Apple's UPnP & NAT-PMP assistance.
|
||||
p3zcNatAssist *mZcNatAssist = new p3zcNatAssist();
|
||||
mNetMgr->addNetAssistFirewall(1, mZcNatAssist);
|
||||
// Apple's UPnP & NAT-PMP assistance.
|
||||
p3zcNatAssist *mZcNatAssist = new p3zcNatAssist();
|
||||
mNetMgr->addNetAssistFirewall(1, mZcNatAssist);
|
||||
#else
|
||||
// Original UPnP Interface.
|
||||
pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
|
||||
mNetMgr->addNetAssistFirewall(1, mUpnpMgr);
|
||||
// Original UPnP Interface.
|
||||
pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
|
||||
mNetMgr->addNetAssistFirewall(1, mUpnpMgr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* need to Monitor too! */
|
||||
|
@ -1637,9 +1646,10 @@ int RsServer::StartupRetroShare()
|
|||
mConfigMgr->addConfiguration("p3History.cfg" , mHistoryMgr);
|
||||
mConfigMgr->addConfiguration("p3Status.cfg" , mStatusSrv);
|
||||
mConfigMgr->addConfiguration("turtle.cfg" , tr);
|
||||
#ifndef RETROTOR
|
||||
mConfigMgr->addConfiguration("banlist.cfg" , mBanList);
|
||||
#endif
|
||||
|
||||
if(mBanList != NULL)
|
||||
mConfigMgr->addConfiguration("banlist.cfg" , mBanList);
|
||||
|
||||
mConfigMgr->addConfiguration("servicecontrol.cfg", serviceCtrl);
|
||||
mConfigMgr->addConfiguration("reputations.cfg" , mReputations);
|
||||
#ifdef ENABLE_GROUTER
|
||||
|
@ -1647,7 +1657,8 @@ int RsServer::StartupRetroShare()
|
|||
#endif
|
||||
|
||||
#ifdef RS_USE_BITDHT
|
||||
mConfigMgr->addConfiguration("bitdht.cfg" , mBitDht);
|
||||
if(mBitDht != NULL)
|
||||
mConfigMgr->addConfiguration("bitdht.cfg" , mBitDht);
|
||||
#endif
|
||||
|
||||
#ifdef RS_ENABLE_GXS
|
||||
|
@ -1874,7 +1885,8 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
//mDhtMgr->start();
|
||||
#ifdef RS_USE_BITDHT
|
||||
mBitDht->start();
|
||||
if(mBitDht != NULL)
|
||||
mBitDht->start();
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
|
@ -1910,6 +1922,10 @@ int RsServer::StartupRetroShare()
|
|||
/* Startup this thread! */
|
||||
start("rs main") ;
|
||||
|
||||
std::cerr << "========================================================================" << std::endl;
|
||||
std::cerr << "== RsInit:: Retroshare core started ==" << std::endl;
|
||||
std::cerr << "========================================================================" << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <pqi/authgpg.h>
|
||||
#include "rsloginhandler.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "rsaccounts.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
|
||||
//#define DEBUG_RSLOGINHANDLER 1
|
||||
|
||||
|
@ -91,7 +91,7 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const RsPeerId& ssl_id,std::string&
|
|||
|
||||
std::string RsLoginHandler::getSSLPasswdFileName(const RsPeerId& /*ssl_id*/)
|
||||
{
|
||||
return rsAccounts->PathAccountKeysDirectory() + "/" + "ssl_passphrase.pgp";
|
||||
return RsAccounts::AccountKeysDirectory() + "/" + "ssl_passphrase.pgp";
|
||||
}
|
||||
|
||||
#ifdef RS_AUTOLOGIN
|
||||
|
@ -755,7 +755,7 @@ bool RsLoginHandler::clearAutoLogin(const RsPeerId& ssl_id)
|
|||
|
||||
std::string RsLoginHandler::getAutologinFileName(const RsPeerId& /*ssl_id*/)
|
||||
{
|
||||
return rsAccounts->PathAccountKeysDirectory() + "/" + "help.dta" ;
|
||||
return RsAccounts::AccountKeysDirectory() + "/" + "help.dta" ;
|
||||
}
|
||||
|
||||
#endif // RS_AUTOLOGIN
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "rsserver/p3face.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "rsserver/rsaccounts.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "rsdiscspace.h"
|
||||
#include <util/rsthreads.h>
|
||||
|
||||
|
@ -166,13 +166,13 @@ bool RsDiscSpace::checkForDiscSpace(RsDiscSpace::DiscLocation loc)
|
|||
#endif
|
||||
break ;
|
||||
|
||||
case RS_CONFIG_DIRECTORY: rs = crossSystemDiskStats(rsAccounts->PathAccountDirectory().c_str(),free_blocks,block_size) ;
|
||||
case RS_CONFIG_DIRECTORY: rs = crossSystemDiskStats(RsAccounts::AccountDirectory().c_str(),free_blocks,block_size) ;
|
||||
#ifdef DEBUG_RSDISCSPACE
|
||||
std::cerr << " path = " << RsInit::RsConfigDirectory() << std::endl ;
|
||||
#endif
|
||||
break ;
|
||||
|
||||
case RS_PGP_DIRECTORY: rs = crossSystemDiskStats(rsAccounts->PathPGPDirectory().c_str(),free_blocks,block_size) ;
|
||||
case RS_PGP_DIRECTORY: rs = crossSystemDiskStats(RsAccounts::PGPDirectory().c_str(),free_blocks,block_size) ;
|
||||
#ifdef DEBUG_RSDISCSPACE
|
||||
std::cerr << " path = " << RsInit::RsPGPDirectory() << std::endl ;
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue