mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-15 04:22:27 -04:00
Lots of little changes to libretroshare. Improvements mainly focused
on configuration storage and loading: * Improved Configuration Manager (almost finished) * Mutex protections for Configuration system * added Configuration storage to p3ConnectMgr. * added Configuration storage to p3MsgService. * bugfixes in p3GeneralConfig. * Added Config Save notification where necessary. * added safe FinalConfigSave before exit(). * added RsPeerNetItem + RsPeerStunItem (serialiser) * reordered startup for correct config loading. * enabled Loading of certs in AuthXPGP. * move sockaddr_clear() to util/rsnet.h * switched p3MsgService sendMessage checking to pqiMonitor syste,. * corrected pqiarchive saving of PeerIds. * added setNetworkMode() & setVisState() to p3ConnectMgr. * added Mutex protection to p3ranking. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@336 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2c69fd7eaf
commit
806b8285f2
36 changed files with 1712 additions and 599 deletions
|
@ -331,3 +331,11 @@ int RsServer::UpdateAllConfig()
|
|||
|
||||
|
||||
|
||||
void RsServer::ConfigFinalSave()
|
||||
{
|
||||
/* force saving of transfers */
|
||||
server->saveFileTransferStatus();
|
||||
mConfigMgr->completeConfiguration();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
|
||||
#include "rsserver/p3face.h"
|
||||
#include <sstream>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
@ -215,6 +216,23 @@ void RsServer::run()
|
|||
|
||||
/* Tick slow services */
|
||||
mRanking->tick();
|
||||
|
||||
|
||||
/* force saving test */
|
||||
#if 0
|
||||
std::string opt;
|
||||
std::string val = "VALUE";
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "SEC:" << lastSec;
|
||||
opt = out.str();
|
||||
}
|
||||
|
||||
mGeneralConfig->setSetting(opt, val);
|
||||
#endif
|
||||
|
||||
mConfigMgr->tick(); /* saves stuff */
|
||||
|
||||
}
|
||||
|
||||
// every 60 loops (> 1 min)
|
||||
|
@ -222,29 +240,14 @@ void RsServer::run()
|
|||
{
|
||||
loop = 0;
|
||||
|
||||
// save the config every 5 minutes.
|
||||
if (min % 5 == 1)
|
||||
{
|
||||
//ConfigSave();
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
/* hack to update for now
|
||||
* Only occassionally - cos disabled
|
||||
*/
|
||||
// channel_list_ok = false;
|
||||
// update_channels();
|
||||
#endif
|
||||
|
||||
|
||||
//std::cerr << "RsServer::run() UpdateAllFiles()" << std::endl;
|
||||
//UpdateAllFiles();
|
||||
}
|
||||
/* force saving FileTransferStatus */
|
||||
server->saveFileTransferStatus();
|
||||
|
||||
/* hour loop */
|
||||
if (++min >= 60)
|
||||
{
|
||||
min = 0;
|
||||
}
|
||||
// update_dirlist();
|
||||
}
|
||||
|
||||
// slow update tick as well.
|
||||
|
|
|
@ -454,15 +454,24 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||
|
||||
/**************************************************************************/
|
||||
|
||||
// set the directories for full configuration load.
|
||||
mAuthMgr -> setConfigDirectories(config->basedir.c_str(), configCertDir.c_str());
|
||||
//sslr -> loadCertificates(configConfFile.c_str());
|
||||
// Load up Certificates, and Old Configuration (if present)
|
||||
|
||||
std::string certConfigFile = config->basedir.c_str();
|
||||
std::string certNeighDir = config->basedir.c_str();
|
||||
if (certConfigFile != "")
|
||||
{
|
||||
certConfigFile += "/";
|
||||
certNeighDir += "/";
|
||||
}
|
||||
certConfigFile += configConfFile;
|
||||
certNeighDir += configCertDir;
|
||||
|
||||
// Create Classes.
|
||||
// filedex server.
|
||||
server = new filedexserver();
|
||||
server->setConfigDir(config->basedir.c_str());
|
||||
/* if we've loaded an old format file! */
|
||||
bool oldFormat = false;
|
||||
std::map<std::string, std::string> oldConfigMap;
|
||||
|
||||
mAuthMgr -> setConfigDirectories(certConfigFile, certNeighDir);
|
||||
((AuthXPGP *) mAuthMgr) -> loadCertificates(oldFormat, oldConfigMap);
|
||||
|
||||
|
||||
|
||||
|
@ -479,15 +488,36 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||
CacheStrapper *mCacheStrapper = new CacheStrapper(ownId, queryPeriod);
|
||||
ftfiler *mCacheTransfer = new ftfiler(mCacheStrapper);
|
||||
|
||||
p3ConfigMgr *mConfigMgr = new p3ConfigMgr(config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn");
|
||||
|
||||
SecurityPolicy *none = secpolicy_create();
|
||||
pqih = new pqisslpersongrp(none, flags);
|
||||
//pqih = new pqipersongrpDummy(none, flags);
|
||||
|
||||
// filedex server.
|
||||
server = new filedexserver();
|
||||
server->setConfigDir(config->basedir.c_str());
|
||||
server->setSaveDir(config->homePath.c_str()); /* Default Save Dir - config will overwrite */
|
||||
server->setSearchInterface(pqih, mAuthMgr, mConnMgr);
|
||||
|
||||
mConfigMgr = new p3ConfigMgr(config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn");
|
||||
mGeneralConfig = new p3GeneralConfig();
|
||||
|
||||
|
||||
// Setup Peer Interface.
|
||||
rsPeers = new p3Peers(mConnMgr, mAuthMgr);
|
||||
|
||||
/* create Services */
|
||||
ad = new p3disc(mAuthMgr, mConnMgr);
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
p3GameLauncher *gameLauncher = new p3GameLauncher();
|
||||
|
||||
pqih -> addService(ad);
|
||||
pqih -> addService(msgSrv);
|
||||
pqih -> addService(chatSrv);
|
||||
pqih -> addService(gameLauncher);
|
||||
|
||||
/* so need to Monitor too! */
|
||||
|
||||
/**************************************************************************/
|
||||
mConnMgr->setDhtMgr(mDhtMgr);
|
||||
mConnMgr->setUpnpMgr(mUpnpMgr);
|
||||
|
@ -496,16 +526,18 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||
|
||||
mConnMgr->addMonitor(pqih);
|
||||
mConnMgr->addMonitor(mCacheStrapper);
|
||||
mConnMgr->addMonitor(ad);
|
||||
mConnMgr->addMonitor(msgSrv);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
mConfigMgr->addConfiguration(CONFIG_TYPE_FSERVER, server); //"server.cfg");
|
||||
mConfigMgr->addConfiguration(CONFIG_TYPE_PEERS, mConnMgr);
|
||||
mConfigMgr->addConfiguration("server.cfg", server);
|
||||
mConfigMgr->addConfiguration("peers.cfg", mConnMgr);
|
||||
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
|
||||
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
server->setSearchInterface(pqih, mAuthMgr, mConnMgr);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* (2) Load configuration files */
|
||||
|
@ -513,6 +545,25 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||
|
||||
mConfigMgr->loadConfiguration();
|
||||
|
||||
/**************************************************************************/
|
||||
/* Hack Old Configuration into new System (first load only) */
|
||||
/**************************************************************************/
|
||||
|
||||
if (oldFormat)
|
||||
{
|
||||
/* transfer all authenticated peers to friend list */
|
||||
std::list<std::string> authIds;
|
||||
mAuthMgr->getAuthenticatedList(authIds);
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = authIds.begin(); it != authIds.end(); it++)
|
||||
{
|
||||
mConnMgr->addFriend(*it);
|
||||
}
|
||||
|
||||
/* move other configuration options */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* trigger generalConfig loading for classes that require it */
|
||||
/**************************************************************************/
|
||||
|
@ -607,25 +658,7 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||
|
||||
pqih->AddSearchModule(mod);
|
||||
|
||||
// Set Default Save Dir. pre-load
|
||||
// Load from config will overwrite...
|
||||
server->setSaveDir(config->homePath.c_str());
|
||||
|
||||
//server->load_config();
|
||||
|
||||
/* create Services */
|
||||
ad = new p3disc(mAuthMgr, mConnMgr);
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
p3GameLauncher *gameLauncher = new p3GameLauncher();
|
||||
|
||||
pqih -> addService(ad);
|
||||
pqih -> addService(msgSrv);
|
||||
pqih -> addService(chatSrv);
|
||||
pqih -> addService(gameLauncher);
|
||||
|
||||
/* so need to Monitor too! */
|
||||
mConnMgr->addMonitor(ad);
|
||||
|
||||
/* create Cache Services */
|
||||
std::string config_dir = config->basedir;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "server/filedexserver.h"
|
||||
//#include "pqi/pqissl.h"
|
||||
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
|
@ -246,7 +247,8 @@ virtual int ConfigSetIncomingDir( std::string dir );
|
|||
|
||||
virtual int ConfigSetDataRates( int total, int indiv );
|
||||
virtual int ConfigSetBootPrompt( bool on );
|
||||
//virtual int ConfigSave( );
|
||||
|
||||
virtual void ConfigFinalSave( );
|
||||
|
||||
private:
|
||||
int UpdateAllConfig();
|
||||
|
@ -275,6 +277,10 @@ int UpdateAllConfig();
|
|||
/* caches (that need ticking) */
|
||||
p3Ranking *mRanking;
|
||||
|
||||
/* Config */
|
||||
p3ConfigMgr *mConfigMgr;
|
||||
p3GeneralConfig *mGeneralConfig;
|
||||
|
||||
// Worker Data.....
|
||||
|
||||
};
|
||||
|
|
|
@ -234,7 +234,11 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
|
|||
/* get from mConnectMgr */
|
||||
peerConnectState pcs;
|
||||
|
||||
if (!mConnMgr->getFriendNetStatus(id, pcs))
|
||||
if (id == mAuthMgr->OwnId())
|
||||
{
|
||||
mConnMgr->getOwnNetStatus(pcs);
|
||||
}
|
||||
else if (!mConnMgr->getFriendNetStatus(id, pcs))
|
||||
{
|
||||
if (!mConnMgr->getOthersNetStatus(id, pcs))
|
||||
{
|
||||
|
@ -256,7 +260,7 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
|
|||
d.localPort = ntohs(pcs.localaddr.sin_port);
|
||||
d.extAddr = inet_ntoa(pcs.serveraddr.sin_addr);
|
||||
d.extPort = ntohs(pcs.serveraddr.sin_port);
|
||||
d.lastConnect = 0;
|
||||
d.lastConnect = pcs.lastcontact;
|
||||
d.connectPeriod = 0;
|
||||
|
||||
/* Translate */
|
||||
|
@ -269,8 +273,32 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
|
|||
if (pcs.state & RS_PEER_S_CONNECTED)
|
||||
d.state |= RS_PEER_STATE_CONNECTED;
|
||||
|
||||
d.netMode = 0;
|
||||
// TODO if (pcs.type & RS_NET_CONN_TCP_EXTERNAL)
|
||||
switch(pcs.netMode)
|
||||
{
|
||||
case RS_NET_MODE_EXT:
|
||||
d.netMode = RS_NETMODE_EXT;
|
||||
break;
|
||||
case RS_NET_MODE_UDP:
|
||||
d.netMode = RS_NETMODE_UDP;
|
||||
break;
|
||||
case RS_NET_MODE_UNKNOWN:
|
||||
case RS_NET_MODE_ERROR:
|
||||
case RS_NET_MODE_UPNP:
|
||||
default:
|
||||
d.netMode = RS_NETMODE_UPNP;
|
||||
break;
|
||||
}
|
||||
|
||||
d.visState = 0;
|
||||
if (!(pcs.visState & RS_VIS_STATE_NODISC))
|
||||
{
|
||||
d.visState |= RS_VS_DISC_ON;
|
||||
}
|
||||
|
||||
if (!(pcs.visState & RS_VIS_STATE_NODHT))
|
||||
{
|
||||
d.visState |= RS_VS_DHT_ON;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -372,16 +400,49 @@ bool p3Peers::setExtAddress(std::string id, std::string addr_str, uint16_t port
|
|||
}
|
||||
|
||||
|
||||
bool p3Peers::setNetworkMode(std::string id, uint32_t netMode)
|
||||
bool p3Peers::setNetworkMode(std::string id, uint32_t extNetMode)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setNetworkMode() " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* translate */
|
||||
uint32_t netMode = 0;
|
||||
switch(extNetMode)
|
||||
{
|
||||
case RS_NETMODE_UDP:
|
||||
netMode = RS_NET_MODE_UDP;
|
||||
break;
|
||||
case RS_NETMODE_EXT:
|
||||
netMode = RS_NET_MODE_EXT;
|
||||
break;
|
||||
default:
|
||||
case RS_NETMODE_UPNP:
|
||||
netMode = RS_NET_MODE_UPNP;
|
||||
break;
|
||||
}
|
||||
|
||||
return mConnMgr->setNetworkMode(id, netMode);
|
||||
}
|
||||
|
||||
|
||||
bool p3Peers::setVisState(std::string id, uint32_t extVisState)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setVisState() " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t visState = 0;
|
||||
if (!(extVisState & RS_VS_DHT_ON))
|
||||
visState |= RS_VIS_STATE_NODHT;
|
||||
if (!(extVisState & RS_VS_DISC_ON))
|
||||
visState |= RS_VIS_STATE_NODISC;
|
||||
|
||||
return mConnMgr->setVisState(id, visState);
|
||||
}
|
||||
|
||||
/* Auth Stuff */
|
||||
std::string p3Peers::GetRetroshareInvite()
|
||||
{
|
||||
|
|
|
@ -61,6 +61,7 @@ virtual bool connectAttempt(std::string id);
|
|||
virtual bool setLocalAddress(std::string id, std::string addr, uint16_t port);
|
||||
virtual bool setExtAddress(std::string id, std::string addr, uint16_t port);
|
||||
virtual bool setNetworkMode(std::string id, uint32_t netMode);
|
||||
virtual bool setVisState(std::string id, uint32_t mode);
|
||||
|
||||
/* Auth Stuff */
|
||||
virtual std::string GetRetroshareInvite();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue