mods to support hidden node: setup & cert sharing.

Also removed old configuration mode from p3cfgmgr



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6720 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2013-09-09 02:10:49 +00:00
parent 683e75aeef
commit bfd915864b
13 changed files with 387 additions and 919 deletions

View File

@ -18,6 +18,7 @@ static const std::string EXTERNAL_IP_BEGIN_SECTION ( "--EXT--" );
static const std::string LOCAL_IP_BEGIN_SECTION ( "--LOCAL--" );
static const std::string SSLID_BEGIN_SECTION ( "--SSLID--" );
static const std::string LOCATION_BEGIN_SECTION ( "--LOCATION--" );
static const std::string HIDDEN_NODE_BEGIN_SECTION ( "--HIDDEN--" );
static const uint8_t CERTIFICATE_PTAG_PGP_SECTION = 0x01 ;
static const uint8_t CERTIFICATE_PTAG_EXTIPANDPORT_SECTION = 0x02 ;
@ -26,6 +27,7 @@ static const uint8_t CERTIFICATE_PTAG_DNS_SECTION = 0x04 ;
static const uint8_t CERTIFICATE_PTAG_SSLID_SECTION = 0x05 ;
static const uint8_t CERTIFICATE_PTAG_NAME_SECTION = 0x06 ;
static const uint8_t CERTIFICATE_PTAG_CHECKSUM_SECTION = 0x07 ;
static const uint8_t CERTIFICATE_PTAG_HIDDENNODE_SECTION = 0x08 ;
static bool is_acceptable_radix64Char(char c)
{
@ -76,10 +78,18 @@ std::string RsCertificate::toStdString() const
addPacket( CERTIFICATE_PTAG_PGP_SECTION , binary_pgp_key , binary_pgp_key_size , buf, p, BS ) ;
if(!only_pgp)
{
if (hidden_node)
{
addPacket( CERTIFICATE_PTAG_HIDDENNODE_SECTION, (unsigned char *)hidden_node_address.c_str(), hidden_node_address.length() , buf, p, BS ) ;
}
else
{
addPacket( CERTIFICATE_PTAG_EXTIPANDPORT_SECTION, ipv4_external_ip_and_port , 6 , buf, p, BS ) ;
addPacket( CERTIFICATE_PTAG_LOCIPANDPORT_SECTION, ipv4_internal_ip_and_port , 6 , buf, p, BS ) ;
addPacket( CERTIFICATE_PTAG_DNS_SECTION , (unsigned char *)dns_name.c_str() , dns_name.length() , buf, p, BS ) ;
}
addPacket( CERTIFICATE_PTAG_NAME_SECTION , (unsigned char *)location_name.c_str() ,location_name.length() , buf, p, BS ) ;
addPacket( CERTIFICATE_PTAG_SSLID_SECTION , location_id.toByteArray() ,location_id.SIZE_IN_BYTES, buf, p, BS ) ;
}
@ -143,14 +153,31 @@ RsCertificate::RsCertificate(const RsPeerDetails& Detail, const unsigned char *b
location_id = SSLIdType( Detail.id ) ;
location_name = Detail.location ;
if (Detail.isHiddenNode)
{
hidden_node = true;
hidden_node_address = Detail.hiddenNodeAddress;
memset(ipv4_internal_ip_and_port,0,6) ;
memset(ipv4_external_ip_and_port,0,6) ;
dns_name = "" ;
}
else
{
hidden_node = false;
hidden_node_address = "";
scan_ip(Detail.localAddr,Detail.localPort,ipv4_internal_ip_and_port) ;
scan_ip(Detail.extAddr,Detail.extPort,ipv4_external_ip_and_port) ;
dns_name = Detail.dyndns ;
}
}
else
{
only_pgp = true ;
hidden_node = false;
hidden_node_address = "";
location_id = SSLIdType() ;
location_name = "" ;
memset(ipv4_internal_ip_and_port,0,6) ;
@ -253,6 +280,13 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_HIDDENNODE_SECTION:
hidden_node_address = std::string((char *)buf,s);
hidden_node = true;
buf = &buf[s];
break ;
case CERTIFICATE_PTAG_LOCIPANDPORT_SECTION:
if(s != 6)
{
@ -314,6 +348,17 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
return true ;
}
std::string RsCertificate::hidden_node_string() const
{
if ((!only_pgp) && (hidden_node))
{
return hidden_node_address;
}
std::string empty;
return empty;
}
std::string RsCertificate::sslid_string() const
{
if (only_pgp)
@ -793,6 +838,17 @@ std::string RsCertificate::toStdString_oldFormat() const
res += location_name ;
res += ";\n" ;
if (hidden_node)
{
std::ostringstream os ;
os << HIDDEN_NODE_BEGIN_SECTION;
os << hidden_node_address << ";";
res += os.str() ;
res += "\n" ;
}
else
{
std::ostringstream os ;
os << LOCAL_IP_BEGIN_SECTION ;
os << (int)ipv4_internal_ip_and_port[0] << "." << (int)ipv4_internal_ip_and_port[1] << "." << (int)ipv4_internal_ip_and_port[2] << "." << (int)ipv4_internal_ip_and_port[3] ;
@ -808,6 +864,8 @@ std::string RsCertificate::toStdString_oldFormat() const
res += os.str() ;
res += "\n" ;
}
return res ;
}

View File

@ -37,6 +37,8 @@ class RsCertificate
std::string location_name_string() const { return location_name; }
std::string dns_string() const { return dns_name ; }
std::string sslid_string() const;
std::string hidden_node_string() const;
std::string armouredPGPKey() const ;
unsigned short ext_port_us() const ;
@ -70,7 +72,9 @@ class RsCertificate
SSLIdType location_id ;
std::string pgp_version ;
std::string dns_name ;
std::string hidden_node_address;
bool only_pgp ; // does the cert contain only pgp info?
bool hidden_node; // IP or hidden Node Address.
};

View File

@ -43,15 +43,10 @@
#define BACKEDUP_SAVE
p3ConfigMgr::p3ConfigMgr(std::string dir, std::string fname, std::string signame)
:basedir(dir), metafname(fname), metasigfname(signame), cfgMtx("p3ConfigMgr"),
p3ConfigMgr::p3ConfigMgr(std::string dir)
:basedir(dir), cfgMtx("p3ConfigMgr"),
mConfigSaveActive(true)
{
oldConfigType = checkForGlobalSigConfig();
// configuration to load correct global types
pqiConfig::globalConfigType = oldConfigType;
}
void p3ConfigMgr::tick()
@ -123,241 +118,12 @@ void p3ConfigMgr::saveConfig()
}
/* save metaconfig */
}
if(ok && oldConfigType)
removeOldConfigType();
return;
}
void p3ConfigMgr::removeOldConfigType()
{
std::string fName = basedir + "/" + metafname;
std::string sigfName = basedir + "/" + metasigfname;
remove(fName.c_str());
remove(sigfName.c_str());
//now set globalconfig type to false so mgr saves
oldConfigType = false;
pqiConfig::globalConfigType = oldConfigType;
}
void p3ConfigMgr::globalSaveConfig()
{
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::globalSaveConfig()";
std::cerr << std::endl;
#endif
RsConfigKeyValueSet *item = new RsConfigKeyValueSet();
std::map<uint32_t, pqiConfig *>::iterator it;
for(it = configs.begin(); it != configs.end(); it++)
{
if (it->second->HasConfigChanged(1))
{
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::globalSaveConfig() Saving Element: ";
std::cerr << it->first;
std::cerr << std::endl;
#endif
it->second->saveConfiguration();
}
/* save metaconfig */
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::globalSaveConfig() Element: ";
std::cerr << it->first << " Hash: " << it->second->Hash();
std::cerr << std::endl;
#endif
if (it->second->Hash() == "")
{
/* skip if no hash */
continue;
}
RsTlvKeyValue kv;
rs_sprintf(kv.key, "%lu", it->first);
kv.value = it->second->Hash();
item->tlvkvs.pairs.push_back(kv);
}
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::globalSaveConfig() Complete MetaConfigItem: ";
std::cerr << std::endl;
item->print(std::cerr, 20);
#endif
/* construct filename */
std::string fname = basedir;
std::string sign_fname = basedir;
std::string fname_backup, sign_fname_backup; // back up files
if (basedir != "")
{
fname += "/";
sign_fname += "/";
}
fname += metafname;
sign_fname += metasigfname;
fname_backup = fname + ".tmp";
sign_fname_backup = sign_fname + ".tmp";
/* Write the data to a stream */
uint32_t bioflags = BIN_FLAGS_WRITEABLE;
BinMemInterface *configbio = new BinMemInterface(1000, bioflags);
RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsGeneralConfigSerialiser());
pqistore store(rss, "CONFIG", configbio, BIN_FLAGS_WRITEABLE);
store.SendItem(item);
/* sign data */
std::string signature;
AuthSSL::getAuthSSL()->SignData(configbio->memptr(), configbio->memsize(), signature);
/* write signature to configuration */
BinMemInterface *signbio = new BinMemInterface(signature.c_str(),
signature.length(), BIN_FLAGS_READABLE);
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::globalSaveConfig() MetaFile Signature:";
std::cerr << std::endl;
std::cerr << signature;
std::cerr << std::endl;
#endif
// begin two pass save
backedUpFileSave(fname, fname_backup, sign_fname, sign_fname_backup, configbio, signbio);
delete signbio;
}
bool p3ConfigMgr::backedUpFileSave(const std::string& fname, const std::string& fname_backup, const std::string& sign_fname,
const std::string& sign_fname_backup, BinMemInterface* configbio, BinMemInterface* signbio){
FILE *file = NULL, *sign = NULL;
char *config_buff=NULL, *sign_buff=NULL;
int size_file=0, size_sign=0;
// begin two pass saving by writing to back up file instead
if (!configbio->writetofile(fname_backup.c_str()) || !signbio->writetofile(sign_fname_backup.c_str()))
{
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::backedupFileSave() Failed write to Backup MetaFiles " << fname_backup
<< " and " << sign_fname_backup;
std::cerr << std::endl;
#endif
return false;
}
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() Save file and keeps a back up " << std::endl;
#endif
// open file from which to collect buffer
file = RsDirUtil::rs_fopen(fname.c_str(), "rb");
sign = RsDirUtil::rs_fopen(sign_fname.c_str(), "rb");
// if failed then create files
if((file == NULL) || (sign == NULL)){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() failed to open meta files " << fname << std::endl;
#endif
file = RsDirUtil::rs_fopen(fname.c_str(), "wb");
sign = RsDirUtil::rs_fopen(sign_fname.c_str(), "wb");
if((file == NULL) || (sign == NULL)){
std::cerr << "p3Config::backedUpFileSave() failed to open backup meta files" << fname_backup << std::endl;
return false;
}
}
//determine file size
fseek(file, 0L, SEEK_END);
size_file = ftell(file);
fseek(file, 0L, SEEK_SET);
fseek(sign, 0L, SEEK_END);
size_sign = ftell(sign);
fseek(sign, 0L, SEEK_SET);
if((size_file) > 0 && (size_sign > 0)){
//read this into a buffer
config_buff = new char[size_file];
fread(config_buff, 1, size_file, file);
//read this into a buffer
sign_buff = new char[size_sign];
fread(sign_buff, 1, size_sign, sign);
}
fclose(file);
fclose(sign);
// rename back-up to current file
if(!RsDirUtil::renameFile(fname_backup, fname) || !RsDirUtil::renameFile(sign_fname_backup, sign_fname)){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() Failed to rename backup meta files: " << std::endl
<< fname_backup << " to " << fname << std::endl
<< sign_fname_backup << " to " << sign_fname << std::endl;
#endif
if (config_buff)
delete[] config_buff;
if (sign_buff)
delete[] sign_buff;
return true;
}
if((size_file) > 0 && (size_sign > 0)){
// now write actual back-up file
file = RsDirUtil::rs_fopen(fname_backup.c_str(), "wb");
sign = RsDirUtil::rs_fopen(sign_fname_backup.c_str(), "wb");
if((file == NULL) || (sign == NULL)){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() fopen failed for file: " << fname_backup << std::endl;
#endif
delete[] config_buff;
delete[] sign_buff;
return true;
}
if(size_file != (int) fwrite(config_buff,1, size_file, file))
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "Write error", "Error while writing backup configuration file " + fname_backup + "\nIs your disc full or out of quota ?");
if(size_sign != (int) fwrite(sign_buff, 1, size_sign, sign))
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "Write error", "Error while writing main signature file " + sign_fname_backup + "\nIs your disc full or out of quota ?");
fclose(file);
fclose(sign);
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() finished backed up save. " << std::endl;
#endif
delete[] config_buff;
delete[] sign_buff;
}
return true;
}
void p3ConfigMgr::loadConfiguration()
{
if(oldConfigType)
globalLoadConfig();
else
loadConfig();
return;
@ -385,222 +151,6 @@ void p3ConfigMgr::loadConfig()
return;
}
void p3ConfigMgr::globalLoadConfig()
{
RsStackMutex stack(cfgMtx); /***** LOCK STACK MUTEX ****/
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration()";
std::cerr << std::endl;
#endif
/* construct filename */
std::string fname = basedir;
std::string sign_fname = basedir;
std::string fname_backup, sign_fname_backup;
if (basedir != "")
{
fname += "/";
sign_fname += "/";
}
fname += metafname;
sign_fname += metasigfname;
// temporary files
fname_backup = fname + ".tmp";
sign_fname_backup = sign_fname + ".tmp";
BinMemInterface* membio = new BinMemInterface(1000, BIN_FLAGS_READABLE);
// Will attempt to get signature first from meta file then if that fails try temporary meta files, these will correspond to temp configs
bool pass = getSignAttempt(fname, sign_fname, membio);
// if first attempt fails then try and temporary files
if(!pass){
#ifdef CONFIG_DEBUG
std::cerr << "\np3ConfigMgr::loadConfiguration(): Trying to load METACONFIG item and METASIGN with temporary files";
std::cerr << std::endl;
#endif
pass = getSignAttempt(fname_backup, sign_fname_backup , membio);
if(!pass){
#ifdef CONFIG_DEBUG
std::cerr << "\np3ConfigMgr::loadConfiguration(): failed to load METACONFIG item and METASIGN";
std::cerr << std::endl;
#endif
return;
}
}
membio->fseek(0); /* go back to start of file */
RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsGeneralConfigSerialiser());
pqistore stream(rss, "CONFIG", membio, BIN_FLAGS_READABLE);
RsItem *rsitem = stream.GetItem();
RsConfigKeyValueSet *item = dynamic_cast<RsConfigKeyValueSet *>(rsitem);
if (!item)
{
delete rsitem;
return;
}
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration() Loaded MetaConfigItem: ";
std::cerr << std::endl;
item->print(std::cerr, 20);
#endif
/* extract info from KeyValueSet */
std::list<RsTlvKeyValue>::iterator it;
for(it = item->tlvkvs.pairs.begin(); it != item->tlvkvs.pairs.end(); it++)
{
/* find the configuration */
uint32_t confId = atoi(it->key.c_str());
std::string hashin = it->value;
/*********************** HACK TO CHANGE CACHE CONFIG ID *********
* REMOVE IN A MONTH OR TWO
*/
if (confId == CONFIG_TYPE_CACHE_OLDID)
{
confId = CONFIG_TYPE_CACHE;
}
/*********************** HACK TO CHANGE CACHE CONFIG ID *********/
std::map<uint32_t, pqiConfig *>::iterator cit;
cit = configs.find(confId);
if (cit != configs.end())
{
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration() Element: ";
std::cerr << confId << " Hash: " << hashin;
std::cerr << std::endl;
#endif
(cit->second)->loadConfiguration(hashin);
/* force config to CHANGED to force saving into new non-global sig format */
cit->second->IndicateConfigChanged();
// cit->second->HasConfigChanged(0);
// cit->second->HasConfigChanged(1);
}
}
delete item;
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration() Done!";
std::cerr << std::endl;
#endif
}
bool p3ConfigMgr::getSignAttempt(std::string& metaConfigFname, std::string& metaSignFname, BinMemInterface* membio){
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() metaConfigFname : " << metaConfigFname;
std::cerr << std::endl;
std::cerr << "p3ConfigMgr::getSignAttempt() metaSignFname : " << metaSignFname;
std::cerr << std::endl;
#endif
/* read signature */
BinMemInterface *signbio = new BinMemInterface(1000, BIN_FLAGS_READABLE);
if (!signbio->readfromfile(metaSignFname.c_str()))
{
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() Failed to Load MetaSignFile";
std::cerr << std::endl;
#endif
/* HACK to load the old one (with the wrong directory)
* THIS SHOULD BE REMOVED IN A COUPLE OF VERSIONS....
* ONLY HERE TO CORRECT BAD MISTAKE IN EARLIER VERSIONS.
*/
metaSignFname = metasigfname;
metaConfigFname = metafname;
if (!signbio->readfromfile(metaSignFname.c_str()))
{
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() HACK: Failed to Load ALT MetaSignFile";
std::cerr << std::endl;
#endif
}
else
{
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() HACK: Loaded ALT MetaSignFile";
std::cerr << std::endl;
#endif
}
}
std::string oldsignature((char *) signbio->memptr(), signbio->memsize());
delete signbio;
if (!membio->readfromfile(metaConfigFname.c_str()))
{
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() Failed to Load MetaFile";
std::cerr << std::endl;
#endif
// delete membio;
// return ;
}
/* get signature */
std::string signature;
AuthSSL::getAuthSSL()->SignData(membio->memptr(), membio->memsize(), signature);
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() New MetaFile Signature:";
std::cerr << std::endl;
std::cerr << signature;
std::cerr << std::endl;
#endif
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() Orig MetaFile Signature:";
std::cerr << std::endl;
std::cerr << oldsignature;
std::cerr << std::endl;
#endif
if (signature != oldsignature)
{
/* Failed */
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() Signature Check Failed";
std::cerr << std::endl;
#endif
return false;
}
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::getSignAttempt() Signature Check Passed!";
std::cerr << std::endl;
#endif
return true;
}
void p3ConfigMgr::addConfiguration(std::string file, pqiConfig *conf)
{
@ -635,32 +185,7 @@ void p3ConfigMgr::completeConfiguration()
mConfigSaveActive = false;
}
bool p3ConfigMgr::checkForGlobalSigConfig()
{
bool oldTypeExists;
FILE *metaFile = NULL, *metaSig = NULL;
std::string fName = basedir + "/" + metafname;
std::string sigName = basedir + "/" + metasigfname;
metaFile = RsDirUtil::rs_fopen(fName.c_str(), "r");
metaSig = RsDirUtil::rs_fopen(sigName.c_str(), "r");
// check if files exist
if((metaFile != NULL) && (metaSig != NULL))
{
oldTypeExists = true;
fclose(metaFile);
fclose(metaSig);
}
else
oldTypeExists = false;
return oldTypeExists;
}
p3Config::p3Config(uint32_t t)
:pqiConfig(t)
@ -671,9 +196,6 @@ p3Config::p3Config(uint32_t t)
bool p3Config::loadConfiguration(std::string &loadHash)
{
if(globalConfigType)
return loadGlobalConfig(loadHash);
else
return loadConfig();
}
@ -790,128 +312,6 @@ bool p3Config::loadAttempt(const std::string& cfgFname,const std::string& signFn
return true;
}
bool p3Config::loadGlobalConfig(std::string &loadHash)
{
bool pass = false;
std::string cfg_fname = Filename();
std::string cfg_fname_backup = cfg_fname + ".tmp";
std::string hashstr;
std::list<RsItem *> load;
#ifdef CONFIG_DEBUG
std::string success_fname = cfg_fname;
std::cerr << "p3Config::loadConfiguration(): Attempting to load configuration file" << cfg_fname << std::endl;
#endif
pass = getHashAttempt(loadHash, hashstr, cfg_fname, load);
if(!pass){
load.clear();
pass = getHashAttempt(loadHash, hashstr, cfg_fname_backup, load);
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() ERROR: Failed to get Hash from " << success_fname << std::endl;
success_fname = cfg_fname_backup;
#endif
if(!pass){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() ERROR: Failed to get Hash from " << success_fname << std::endl;
#endif
return false;
}
}
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration(): SUCCESS: configuration file loaded" << success_fname << std::endl;
#endif
setHash(hashstr);
return loadList(load);
}
bool p3Config::getHashAttempt(const std::string& loadHash, std::string& hashstr,const std::string& cfg_fname,
std::list<RsItem *>& load){
std::list<RsItem *>::iterator it;
uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_READABLE;
BinInterface *bio = new BinFileInterface(cfg_fname.c_str(), bioflags);
PQInterface *stream = NULL;
std::string tempString, msgConfigFileName;
std::string filename = Filename() ;
std::string::reverse_iterator rit = filename.rbegin();
// get the msgconfig file name
for(int i =0; (i <= 7) && (rit != filename.rend()); i++)
{
tempString.push_back(*rit);
rit++;
}
rit = tempString.rbegin();
for(; rit !=tempString.rend(); rit++)
msgConfigFileName.push_back(*rit);
if(msgConfigFileName == "msgs.cfg")
stream = new pqiarchive(setupSerialiser(), bio, bioflags);
else
stream = new pqistore(setupSerialiser(), "CONFIG", bio, bioflags);
RsItem *item = NULL;
while(NULL != (item = stream->GetItem()))
{
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() loaded item:";
std::cerr << std::endl;
item->print(std::cerr, 0);
std::cerr << std::endl;
#endif
load.push_back(item);
}
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() loaded " << load.size();
std::cerr << " Elements from File: " << cfg_fname;
std::cerr << std::endl;
#endif
/* check hash */
hashstr = bio->gethash();
// if hash then atmpt load with temporary file
if (hashstr != loadHash)
{
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::loadConfiguration() ERROR: Hash != MATCHloaded";
std::cerr << std::endl;
#endif
/* bad load */
for(it = load.begin(); it != load.end(); it++)
{
delete (*it);
}
setHash("");
delete stream;
return false;
}
delete stream;
return true;
}
bool p3Config::saveConfiguration()
{
return saveConfig();
@ -1003,176 +403,6 @@ bool p3Config::saveConfig()
}
bool p3Config::saveGlobalConfig()
{
bool cleanup = true;
std::list<RsItem *> toSave;
saveList(cleanup, toSave);
std::string cfg_fname = Filename(); // get configuration file name
std::string cfg_fname_backup = Filename()+".tmp"; // backup file for two pass save
#ifdef CONFIG_DEBUG
std::cerr << "Writting p3config file " << cfg_fname << std::endl ;
std::cerr << "p3Config::saveConfiguration() toSave " << toSave.size();
std::cerr << " Elements to File: " << cfg_fname;
std::cerr << std::endl;
#endif
// saves current config and keeps back-up (old configuration)
if(!backedUpFileSave(cfg_fname, cfg_fname_backup, toSave, cleanup)){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::saveConfiguration(): Failed to save file" << std::endl;
#endif
return false;
}
saveDone(); // callback to inherited class to unlock any Mutexes protecting saveList() data
return true;
}
bool p3Config::backedUpFileSave(const std::string& cfg_fname, const std::string& cfg_fname_backup, std::list<RsItem* >& itemList,
bool cleanup){
uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_WRITEABLE;
uint32_t stream_flags = BIN_FLAGS_WRITEABLE;
bool written = true;
FILE* cfg_file = NULL;
char* buff=NULL;
int size_file = 0;
if (!cleanup)
stream_flags |= BIN_FLAGS_NO_DELETE;
BinInterface *bio = new BinFileInterface(cfg_fname_backup.c_str(), bioflags);
pqistore *stream = new pqistore(setupSerialiser(), "CONFIG", bio, stream_flags);
std::list<RsItem *>::iterator it;
for(it = itemList.begin(); it != itemList.end(); it++)
{
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() save item:";
std::cerr << std::endl;
(*it)->print(std::cerr, 0);
std::cerr << std::endl;
#endif
written = written && stream->SendItem(*it);
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() saved ";
#endif
}
/* store the hash */
setHash(bio->gethash());
// bio is taken care of in stream's destructor
delete stream;
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() Save file and keeps a back up " << std::endl;
#endif
// open file from which to collect buffer
cfg_file = RsDirUtil::rs_fopen(cfg_fname.c_str(), "rb");
// if it fails to open, create file,but back-up file will now be empty
if(cfg_file == NULL){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() fopen failed for file: " << cfg_fname << std::endl;
#endif
cfg_file = RsDirUtil::rs_fopen(cfg_fname.c_str(), "wb");
if(cfg_file == NULL)
{
std::cerr << "p3Config::backedUpFileSave() fopen failed for file:" << cfg_fname << std::endl;
return false ;
}
}
//determine file size
fseek(cfg_file, 0L, SEEK_END);
size_file = ftell(cfg_file);
if(size_file < 0) // ftell returns -1 when fails
{
fclose(cfg_file);
size_file = 0 ;
}
fseek(cfg_file, 0L, SEEK_SET);
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave(): Size of file: " << size_file << std::endl;
#endif
// no point continuing, empty files all have same hash
if(size_file > 0){
//read this into a data buffer
buff = new char[size_file];
fread(buff, 1, size_file, cfg_file);
}
fclose(cfg_file);
// rename back-up to current file, if this fails should return false hash's will not match at startup
if(!RsDirUtil::renameFile(cfg_fname_backup, cfg_fname)){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() Failed to rename file" << cfg_fname_backup << " to "
<< cfg_fname << std::endl;
#endif
written &= false; // at least one file save should be successful
}
if(size_file > 0)
{
// now write actual back-up file
cfg_file = RsDirUtil::rs_fopen(cfg_fname_backup.c_str(), "wb");
if(cfg_file == NULL){
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() fopen failed for file: " << cfg_fname_backup << std::endl;
#endif
}
if(size_file != (int) fwrite(buff, 1, size_file, cfg_file))
{
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "Write error", "Error while writing backup configuration file " + cfg_fname_backup + "\nIs your disc full or out of quota ?");
fclose(cfg_file);
delete[] buff;
return false ;
}
fclose(cfg_file);
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() finished backed up save. " << std::endl;
#endif
delete[] buff;
written |= true; // either backup or current file should have been saved
}
#ifdef CONFIG_DEBUG
std::cerr << "p3Config::backedUpFileSave() finished backed up save. " << std::endl;
#endif
return written;
}
/**************************** CONFIGURATION CLASSES ********************/
p3GeneralConfig::p3GeneralConfig()
@ -1313,8 +543,6 @@ bool p3GeneralConfig::loadList(std::list<RsItem *>& load)
* only the Indication and hash really need it
*/
bool pqiConfig::globalConfigType = false;
pqiConfig::pqiConfig(uint32_t t)
: cfgMtx("pqiConfig"), ConfInd(2), type(t)
{

View File

@ -63,7 +63,6 @@ const uint32_t CONFIG_TYPE_GENERAL = 0x0001;
const uint32_t CONFIG_TYPE_PEERS = 0x0002;
const uint32_t CONFIG_TYPE_FSERVER = 0x0003;
const uint32_t CONFIG_TYPE_MSGS = 0x0004;
const uint32_t CONFIG_TYPE_CACHE_OLDID = 0x0005;
const uint32_t CONFIG_TYPE_AUTHGPG = 0x0006;
/* new FileTransfer */
@ -155,8 +154,6 @@ void setHash(const std::string& h);
RsMutex cfgMtx;
static bool globalConfigType;
private:
/**
@ -200,10 +197,8 @@ class p3ConfigMgr
/**
* @param bdir base directory: where config files will be saved
* @param fname file name for global configuration
* @param signame file name for global signature
*/
p3ConfigMgr(std::string bdir, std::string fname, std::string signame);
p3ConfigMgr(std::string bdir);
/**
* checks and update all added configurations
@ -237,31 +232,6 @@ class p3ConfigMgr
private:
/**
* this checks for the global config file and signature and determines class's mode of operation
* @return global file rs-v0.#.cfg and rs-v0.#.sgn are present
* @deprecated
*/
bool checkForGlobalSigConfig();
/**
* removes theoldconfiguration type
* @deprecated
*/
void removeOldConfigType();
/**
* to save old style global-signature configuration files
* @deprecated
*/
void globalSaveConfig();
/**
* to load up old style global-signature config files
* @deprecated
*/
void globalLoadConfig();
/**
* saves configuration of pqiconfigs in object configs
*/
@ -272,33 +242,10 @@ class p3ConfigMgr
*/
void loadConfig();
/**
* checks if signature and configuration file's signature matches
* @return false if signature file does not match configuration file's signature
*/
bool getSignAttempt(std::string& metaConfigFname, std::string& metaSignFname, BinMemInterface* membio);
/**
* takes current configuration which is stored in back-up file, and moves it to actual config file
* then stores data that was in actual config file into back-up, Corresponding signatures and handled
* simlarly in parallel
*@param fname the name of the first configuration file checked
*@param fname_backup the seconf file, backup, checked if first file does not exist or is corrupted
*@param sign file name in which signature is kept
*@param sign_backup file name in which signature which correspond to backup config is kept
*@param configbio to write config to file
*@param signbio to write signature config to file
*/
bool backedUpFileSave(const std::string& fname, const std::string& fname_backup,const std::string& sign,
const std::string& sign_backup, BinMemInterface* configbio, BinMemInterface* signbio);
const std::string basedir;
const std::string metafname;
const std::string metasigfname;
RsMutex cfgMtx; /* below is protected */
bool oldConfigType;
bool mConfigSaveActive;
std::map<uint32_t, pqiConfig *> configs;
};
@ -351,26 +298,9 @@ virtual void saveDone() { return; }
private:
/**
* takes current configuration which is stored in back-up file, and moves it to actual config file
* then stores data that was in actual config file into back-up, This is an rs specific solution
* @param fname the name of the first configuration file checked
* @param fname_backup the seconf file, backup, checked if first file does not exist or is corrupted
*/
bool backedUpFileSave(const std::string& fname, const std::string& fname_backup, std::list<RsItem* >& toSave,
bool cleanup);
/*
* for retrieving hash files
*/
bool getHashAttempt(const std::string& loadHash, std::string& hashstr, const std::string& fname, std::list<RsItem *>& load);
bool loadConfig();
bool saveConfig();
bool loadGlobalConfig(std::string& hash);
bool saveGlobalConfig();
bool loadAttempt(const std::string&,const std::string&, std::list<RsItem *>& load);
}; /* end of p3Config */

View File

@ -380,6 +380,13 @@ void p3NetMgrIMPL::netStartup()
mNetStatus = RS_NET_EXT_SETUP;
break;
case RS_NET_MODE_TRY_LOOPBACK:
std::cerr << "p3NetMgrIMPL::netStartup() TRY_LOOPBACK mode";
std::cerr << std::endl;
mNetMode |= RS_NET_MODE_HIDDEN;
mNetStatus = RS_NET_LOOPBACK;
break;
default: // Fall through.
#ifdef NETMGR_DEBUG_RESET
@ -535,6 +542,7 @@ void p3NetMgrIMPL::netTick()
case RS_NET_LOOPBACK:
//don't do a shutdown because a client in a computer without local network might be usefull for debug.
//shutdown();
std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#endif
@ -905,7 +913,18 @@ bool p3NetMgrIMPL::checkNetAddress()
struct in_addr prefAddr;
struct sockaddr_in oldAddr;
if (mNetMode & RS_NET_MODE_TRY_LOOPBACK)
{
std::cerr << "p3NetMgrIMPL::checkNetAddress() LOOPBACK ... forcing to 127.0.0.1";
std::cerr << std::endl;
inet_aton("127.0.0.1", &prefAddr);
validAddr = true;
}
else
{
validAddr = getPreferredInterface(mLocalAddr.sin_addr, prefAddr);
}
/* if we don't have a valid address - reset */
if (!validAddr)
@ -1108,12 +1127,12 @@ bool p3NetMgrIMPL::setNetworkMode(uint32_t netMode)
oldNetMode = mNetMode;
#ifdef NETMGR_DEBUG
//#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgrIMPL::setNetworkMode()";
std::cerr << " Existing netMode: " << mNetMode;
std::cerr << " Input netMode: " << netMode;
std::cerr << std::endl;
#endif
//#endif
mNetMode &= ~(RS_NET_MODE_TRYMODE);
switch(netMode & RS_NET_MODE_ACTUAL)
@ -1125,7 +1144,7 @@ bool p3NetMgrIMPL::setNetworkMode(uint32_t netMode)
mNetMode |= RS_NET_MODE_TRY_UPNP;
break;
case RS_NET_MODE_HIDDEN:
mNetMode |= RS_NET_MODE_TRY_UDP; // FOR THE MOMENT HIDDEN acts like = UDP.
mNetMode |= RS_NET_MODE_TRY_LOOPBACK;
break;
default:
case RS_NET_MODE_UDP:

View File

@ -124,7 +124,7 @@ p3PeerMgrIMPL::p3PeerMgrIMPL( const std::string& ssl_own_id,
// setup default ProxyServerAddress.
sockaddr_clear(&mProxyServerAddress);
inet_aton("127.0.0.1", &(mProxyServerAddress.sin_addr));
mProxyServerAddress.sin_port = htons(7050);
mProxyServerAddress.sin_port = htons(9100);
}
@ -142,18 +142,45 @@ void p3PeerMgrIMPL::setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr)
mNetMgr = netMgr;
}
bool p3PeerMgrIMPL::setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort)
{
std::cerr << "p3PeerMgrIMPL::setupHiddenNode()";
std::cerr << " Address: " << hiddenAddress;
std::cerr << " Port: " << hiddenPort;
std::cerr << std::endl;
setOwnNetworkMode(RS_NET_MODE_HIDDEN);
mOwnState.hiddenNode = true;
mOwnState.hiddenPort = hiddenPort;
mOwnState.hiddenDomain = hiddenAddress;
// switch off DHT too.
setOwnVisState(RS_VIS_STATE_GRAY);
// Force the Port.
struct sockaddr_in loopback;
sockaddr_clear(&loopback);
inet_aton("127.0.0.1", &(loopback.sin_addr));
loopback.sin_port = htons(hiddenPort);
setLocalAddress(AuthSSL::getAuthSSL()->OwnId(), loopback);
return true;
}
bool p3PeerMgrIMPL::setOwnNetworkMode(uint32_t netMode)
{
bool changed = false;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG
//#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::setOwnNetworkMode() :";
std::cerr << " Existing netMode: " << mOwnState.netMode;
std::cerr << " Input netMode: " << netMode;
std::cerr << std::endl;
#endif
//#endif
if (mOwnState.netMode != (netMode & RS_NET_MODE_ACTUAL))
{
@ -290,28 +317,50 @@ bool p3PeerMgrIMPL::isHiddenPeer(const std::string &ssl_id)
it = mFriendList.find(ssl_id);
if (it == mFriendList.end())
{
return (it->second).hiddenNode;
std::cerr << "p3PeerMgrIMPL::isHiddenPeer(" << ssl_id << ") Missing Peer => false";
std::cerr << std::endl;
return false;
}
/* is it hidden ?? */
return false;
std::cerr << "p3PeerMgrIMPL::isHiddenPeer(" << ssl_id << ") = " << (it->second).hiddenNode;
std::cerr << std::endl;
return (it->second).hiddenNode;
}
bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::string &domain_addr, const uint16_t domain_port)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort()";
std::cerr << std::endl;
if (ssl_id == AuthSSL::getAuthSSL()->OwnId())
{
mOwnState.hiddenNode = true;
mOwnState.hiddenDomain = domain_addr;
mOwnState.hiddenPort = domain_port;
std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set own State";
std::cerr << std::endl;
return true;
}
/* check for existing */
std::map<std::string, peerState>::iterator it;
it = mFriendList.find(ssl_id);
if (it == mFriendList.end())
{
std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Peer Not Found";
std::cerr << std::endl;
return false;
}
it->second.hiddenDomain = domain_addr;
it->second.hiddenPort = domain_port;
it->second.hiddenNode = true;
std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set Peers State";
std::cerr << std::endl;
return true;
}
@ -1414,6 +1463,8 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
item->dyndns = mOwnState.dyndns;
mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList);
mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList);
item->domain_addr = mOwnState.hiddenDomain;
item->domain_port = mOwnState.hiddenPort;
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::saveList() Own Config Item:" << std::endl;

View File

@ -60,7 +60,7 @@ const uint32_t RS_NET_MODE_TRYMODE = 0xff00;
const uint32_t RS_NET_MODE_TRY_EXT = 0x0100;
const uint32_t RS_NET_MODE_TRY_UPNP = 0x0200;
const uint32_t RS_NET_MODE_TRY_UDP = 0x0400;
const uint32_t RS_NET_MODE_TRY_HIDDEN = 0x0800;
const uint32_t RS_NET_MODE_TRY_LOOPBACK = 0x0800;
/* Actual State */
const uint32_t RS_NET_MODE_ACTUAL = 0x00ff;
@ -315,6 +315,8 @@ virtual bool haveOnceConnected();
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr);
bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort);
void tick();
const std::string getOwnId();

View File

@ -67,6 +67,9 @@ bool pqisslpersongrp::locked_getCryptoParams(const std::string& id,RsPeerCryptoP
pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *listener)
{
std::cerr << "pqisslpersongrp::locked_createPerson() PeerId: " << id;
std::cerr << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::createPerson() PeerId: " + id);
pqiperson *pqip = new pqiperson(id, this);
@ -74,6 +77,9 @@ pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *li
// If using proxy, then only create a proxy item, otherwise can use any.
if (mPeerMgr->isHiddenPeer(id))
{
std::cerr << "pqisslpersongrp::locked_createPerson() Is Hidden Peer!";
std::cerr << std::endl;
pqisslproxy *pqis = new pqisslproxy((pqissllistener *) listener, pqip, mLinkMgr);
/* construct the serialiser ....
@ -96,6 +102,9 @@ pqiperson * pqisslpersongrp::locked_createPerson(std::string id, pqilistener *li
}
else
{
std::cerr << "pqisslpersongrp::locked_createPerson() Is Normal Peer!";
std::cerr << std::endl;
pqissl *pqis = new pqissl((pqissllistener *) listener, pqip, mLinkMgr);
/* construct the serialiser ....

View File

@ -44,6 +44,7 @@
#include <list>
#include <map>
#include <vector>
#include <stdint.h>
/*!
* Initialisation Class (not publicly disclosed to RsIFace)
@ -95,6 +96,12 @@ class RsInit
// copies existing gnupg keyrings to the new place of the OpenPGP-SDK version. Returns true on success.
static bool copyGnuPGKeyrings() ;
/*!
* Setup Hidden Location;
*/
static bool SetHiddenLocation(const std::string& hiddenaddress, uint16_t port);
/*!
* Login GGP
*/

View File

@ -54,7 +54,8 @@ const uint32_t RS_TRUST_LVL_ULTIMATE = 5;
const uint32_t RS_NETMODE_UDP = 0x0001;
const uint32_t RS_NETMODE_UPNP = 0x0002;
const uint32_t RS_NETMODE_EXT = 0x0003;
const uint32_t RS_NETMODE_UNREACHABLE = 0x0004;
const uint32_t RS_NETMODE_HIDDEN = 0x0004;
const uint32_t RS_NETMODE_UNREACHABLE = 0x0005;
/* Visibility */
const uint32_t RS_VS_DHT_ON = 0x0001;
@ -206,6 +207,10 @@ class RsPeerDetails
/* Network details (only valid if friend) */
uint32_t state;
bool isHiddenNode;
std::string hiddenNodeAddress;
// Filled in for Standard Node.
std::string localAddr;
uint16_t localPort;
std::string extAddr;
@ -310,6 +315,8 @@ class RsPeers
/* Network Stuff */
virtual bool connectAttempt(const std::string &ssl_id) = 0;
virtual bool setLocation(const std::string &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs
virtual bool setHiddenNode(const std::string &id, const std::string &hidden_node_address) = 0;
virtual bool setLocalAddress(const std::string &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setExtAddress( const std::string &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setDynDNS(const std::string &id, const std::string &addr) = 0;

View File

@ -107,6 +107,10 @@ std::string RsPeerNetModeString(uint32_t netModel)
{
str = "UDP Mode";
}
else if (netModel == RS_NETMODE_HIDDEN)
{
str = "Hidden";
}
else if (netModel == RS_NETMODE_UNREACHABLE)
{
str = "UDP Mode (Unreachable)";
@ -302,14 +306,29 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
d.authcode = "AUTHCODE";
/* fill from pcs */
d.lastConnect = ps.lastcontact;
d.connectPeriod = 0;
if (ps.hiddenNode)
{
d.isHiddenNode = true;
rs_sprintf(d.hiddenNodeAddress, "%s:%u", ps.hiddenDomain.c_str(), ps.hiddenPort);
d.localAddr = "hidden";
d.localPort = 0;
d.extAddr = "hidden";
d.extPort = 0;
d.dyndns = "";
}
else
{
d.isHiddenNode = false;
d.hiddenNodeAddress = "";
d.localAddr = rs_inet_ntoa(ps.localaddr.sin_addr);
d.localPort = ntohs(ps.localaddr.sin_port);
d.extAddr = rs_inet_ntoa(ps.serveraddr.sin_addr);
d.extPort = ntohs(ps.serveraddr.sin_port);
d.dyndns = ps.dyndns;
d.lastConnect = ps.lastcontact;
d.connectPeriod = 0;
std::list<pqiIpAddress>::iterator it;
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
@ -326,6 +345,7 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
rs_sprintf(toto, "%u %ld sec", ntohs(it->mAddr.sin_port), time(NULL) - it->mSeenTime);
d.ipAddressList.push_back("E:" + rs_inet_ntoa(it->mAddr.sin_addr) + ":" + toto);
}
}
switch(ps.netMode & RS_NET_MODE_ACTUAL)
@ -339,6 +359,9 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
case RS_NET_MODE_UDP:
d.netMode = RS_NETMODE_UDP;
break;
case RS_NET_MODE_HIDDEN:
d.netMode = RS_NETMODE_HIDDEN;
break;
case RS_NET_MODE_UNREACHABLE:
case RS_NET_MODE_UNKNOWN:
default:
@ -706,6 +729,53 @@ bool p3Peers::getAllowServerIPDetermination()
return mNetMgr->getIPServersEnabled() ;
}
bool p3Peers::setLocation(const std::string &ssl_id, const std::string &location)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setLocation() " << ssl_id << std::endl;
#endif
return mPeerMgr->setLocation(ssl_id, location);
}
bool p3Peers::setHiddenNode(const std::string &id, const std::string &hidden_node_address)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setHiddenNode() " << id << std::endl;
#endif
size_t cpos = hidden_node_address.rfind(':');
if (cpos == std::string::npos)
{
std::cerr << "p3Peers::setHiddenNode() Failed to parse (:) " << hidden_node_address << std::endl;
return false;
}
int lenport = hidden_node_address.length() - (cpos + 1); // +1 to skip over : char.
if (lenport <= 0)
{
std::cerr << "p3Peers::setHiddenNode() Missing Port: " << hidden_node_address << std::endl;
return false;
}
std::string domain = hidden_node_address.substr(0, cpos);
std::string port = hidden_node_address.substr(cpos + 1, std::string::npos);
int portint = atoi(port.c_str());
if ((portint < 0) || (portint > 65535))
{
std::cerr << "p3Peers::setHiddenNode() Invalid Port: " << hidden_node_address << std::endl;
return false;
}
std::cerr << "p3Peers::setHiddenNode() Domain: " << domain << " Port: " << portint;
std::cerr << std::endl;
mPeerMgr->setNetworkMode(id, RS_NET_MODE_HIDDEN);
mPeerMgr->setHiddenDomainPort(id, domain, (uint16_t) portint);
return true;
}
bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_str, uint16_t port)
{
#ifdef P3PEERS_DEBUG
@ -731,14 +801,6 @@ bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_st
return false;
}
bool p3Peers::setLocation(const std::string &ssl_id, const std::string &location)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setLocation() " << ssl_id << std::endl;
#endif
return mPeerMgr->setLocation(ssl_id, location);
}
bool p3Peers::setExtAddress(const std::string &id, const std::string &addr_str, uint16_t port)
{
#ifdef P3PEERS_DEBUG
@ -791,6 +853,9 @@ bool p3Peers::setNetworkMode(const std::string &id, uint32_t extNetMode)
case RS_NETMODE_UDP:
netMode = RS_NET_MODE_UDP;
break;
case RS_NETMODE_HIDDEN:
netMode = RS_NET_MODE_HIDDEN;
break;
case RS_NETMODE_UNREACHABLE:
netMode = RS_NET_MODE_UNREACHABLE;
break;
@ -923,13 +988,22 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai
pd.id = cert.sslid_string() ;
pd.location = cert.location_name_string();
pd.isOnlyGPGdetail = pd.id.empty();
pd.service_perm_flags = RS_SERVICE_PERM_ALL ;
if (pd.isHiddenNode)
{
pd.hiddenNodeAddress = cert.hidden_node_string();
}
else
{
pd.localAddr = cert.loc_ip_string();
pd.localPort = cert.loc_port_us();
pd.extAddr = cert.ext_ip_string();
pd.extPort = cert.ext_port_us();
pd.dyndns = cert.dns_string() ;
pd.isOnlyGPGdetail = pd.id.empty();
pd.service_perm_flags = RS_SERVICE_PERM_ALL ;
}
}
catch(uint32_t e)
{

View File

@ -84,6 +84,8 @@ virtual bool removeFriendLocation(const std::string &sslId);
/* Network Stuff */
virtual bool connectAttempt(const std::string &id);
virtual bool setLocation(const std::string &ssl_id, const std::string &location);//location is shown in the gui to differentiate ssl certs
virtual bool setHiddenNode(const std::string &id, const std::string &hidden_node_address);
virtual bool setLocalAddress(const std::string &id, const std::string &addr, uint16_t port);
virtual bool setExtAddress(const std::string &id, const std::string &addr, uint16_t port);
virtual bool setDynDNS(const std::string &id, const std::string &dyndns);

View File

@ -125,6 +125,11 @@ class RsInitConfig
static unsigned short port;
static std::string inet ;
/* v0.6 features */
static bool forceApiUpgrade;
static std::string hiddenNodeAddress;
static uint16_t hiddenNodePort;
/* Logging */
static bool haveLogFile;
static bool outStderr;
@ -185,6 +190,11 @@ bool RsInitConfig::forceLocalAddr;
unsigned short RsInitConfig::port;
std::string RsInitConfig::inet;
/* v0.6 features */
bool RsInitConfig::forceApiUpgrade = false;
std::string RsInitConfig::hiddenNodeAddress;
uint16_t RsInitConfig::hiddenNodePort;
/* Logging */
bool RsInitConfig::haveLogFile;
bool RsInitConfig::outStderr;
@ -1437,6 +1447,8 @@ bool RsInit::setupAccount(const std::string& accountdir)
/***************************** FINAL LOADING OF SETUP *************************/
/* Login SSL */
bool RsInit::LoadPassword(const std::string& id, const std::string& inPwd)
{
@ -1708,6 +1720,16 @@ void RsInit::setAutoLogin(bool autoLogin){
RsInitConfig::autoLogin = autoLogin;
}
/* Setup Hidden Location; */
bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
{
/* parse the bugger (todo) */
RsInitConfig::hiddenNodeAddress = hiddenaddress;
RsInitConfig::hiddenNodePort = port;
return true;
}
/*
*
* Init Part of RsServer... needs the private
@ -1891,13 +1913,65 @@ int RsServer::StartupRetroShare()
emergencySaveDir += "Downloads";
emergencyPartialsDir += "Partials";
/**************************************************************************/
/* setup Configuration */
/**************************************************************************/
std::cerr << "Load Configuration" << std::endl;
mConfigMgr = new p3ConfigMgr(RsInitConfig::configDir);
mGeneralConfig = new p3GeneralConfig();
// Add General.cfg, and load - this allows key early options.
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
std::string dummy2("dummy");
mGeneralConfig->loadConfiguration(dummy2);
// NOTE: if we lose GeneralConfiguration - then RS will fail to start.
// as API_VERSION won't exist. Furthermore HIDDEN node status will be lost.
// We can potentially detect HIDDEN node cofig from "peers.cfg",
// If this is lost too - in real trouble.
#define RS_API_VERSION_OPT "RS_API"
#define RS_API_VERSION_STRING "0.6.0"
#define RS_HIDDEN_NODE_OPT "HIDDEN_NODE"
#define RS_HIDDEN_NODE_YES "YES"
bool forceApiUpgrade = false;
if ((RsInitConfig::firsttime_run) || (forceApiUpgrade))
{
mGeneralConfig->setSetting(RS_API_VERSION_OPT, RS_API_VERSION_STRING);
}
bool setupHiddenNode = false;
if (!RsInitConfig::hiddenNodeAddress.empty())
{
setupHiddenNode = true;
mGeneralConfig->setSetting(RS_HIDDEN_NODE_OPT, RS_HIDDEN_NODE_YES);
}
// BASIC COMPARISION FOR NOW... can be extended later if needed.
std::string version = mGeneralConfig->getSetting(RS_API_VERSION_OPT);
if (version != RS_API_VERSION_STRING)
{
std::cerr << "Aborting: Old Retroshare Configuration";
std::cerr << std::endl;
abort();
}
bool isHiddenNode = false;
if (RS_HIDDEN_NODE_YES == mGeneralConfig->getSetting(RS_HIDDEN_NODE_OPT))
{
isHiddenNode = true;
std::cerr << "Retroshare: Hidden Node";
std::cerr << std::endl;
}
/**************************************************************************/
/* setup classes / structures */
/**************************************************************************/
std::cerr << "setup classes / structures" << std::endl;
/* History Manager */
mHistoryMgr = new p3HistoryMgr();
mPeerMgr = new p3PeerMgrIMPL( AuthSSL::getAuthSSL()->OwnId(),
@ -1914,6 +1988,7 @@ int RsServer::StartupRetroShare()
mPeerMgr->setManagers(mLinkMgr, mNetMgr);
mNetMgr->setManagers(mPeerMgr, mLinkMgr);
//load all the SSL certs as friends
// std::list<std::string> sslIds;
// AuthSSL::getAuthSSL()->getAuthenticatedList(sslIds);
@ -2117,9 +2192,6 @@ int RsServer::StartupRetroShare()
rsFiles = ftserver;
mConfigMgr = new p3ConfigMgr(RsInitConfig::configDir, "rs-v0.5.cfg", "rs-v0.5.sgn");
mGeneralConfig = new p3GeneralConfig();
/* create Cache Services */
std::string config_dir = RsInitConfig::configDir;
std::string localcachedir = config_dir + "/cache/local";
@ -2139,7 +2211,6 @@ int RsServer::StartupRetroShare()
mPluginsManager = new RsPluginManager(RsInitConfig::main_executable_hash) ;
rsPlugins = mPluginsManager ;
mConfigMgr->addConfiguration("plugins.cfg", mPluginsManager);
mPluginsManager->loadConfiguration() ;
// These are needed to load plugins: plugin devs might want to know the place of
@ -2456,7 +2527,6 @@ int RsServer::StartupRetroShare()
mConfigMgr->loadConfiguration();
mConfigMgr->addConfiguration("peers.cfg", mPeerMgr);
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
mConfigMgr->addConfiguration("chat.cfg", chatSrv);
@ -2519,6 +2589,12 @@ int RsServer::StartupRetroShare()
}
if (setupHiddenNode)
{
mPeerMgr->setupHiddenNode(RsInitConfig::hiddenNodeAddress, RsInitConfig::hiddenNodePort);
}
#if 0
/* must load the trusted_peer before setting up the pqipersongrp */
if (firsttime_run)
@ -2641,6 +2717,7 @@ int RsServer::StartupRetroShare()
{
msgSrv->loadWelcomeMsg();
ftserver->shareDownloadDirectory(true);
mGeneralConfig->saveConfiguration();
}
// load up the help page