mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
- Added basic infrastructure to plugin system in libretroshare and retroshare-gui.
- ported LinksCloud to a new plugin, and removed it from main sources Next moves: - add gui for managing plugins - handle windows compilation git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4275 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
3925a7114a
commit
a2c91a7924
28 changed files with 4676 additions and 243 deletions
|
@ -88,8 +88,9 @@ void setP3Interface(P3Interface *pqi);
|
|||
/* add Config Items (Extra, Controller) */
|
||||
void addConfigComponents(p3ConfigMgr *mgr);
|
||||
|
||||
CacheStrapper *getCacheStrapper();
|
||||
CacheTransfer *getCacheTransfer();
|
||||
virtual CacheStrapper *getCacheStrapper();
|
||||
virtual CacheTransfer *getCacheTransfer();
|
||||
|
||||
std::string OwnId();
|
||||
|
||||
/* Final Setup (once everything is assigned) */
|
||||
|
|
|
@ -128,6 +128,7 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
|
|||
retroshare/rsforums.h \
|
||||
retroshare/rsiface.h \
|
||||
retroshare/rsinit.h \
|
||||
retroshare/rsplugin.h \
|
||||
retroshare/rsloginhandler.h \
|
||||
retroshare/rsmsgs.h \
|
||||
retroshare/rsnotify.h \
|
||||
|
@ -137,6 +138,8 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
|
|||
retroshare/rsturtle.h \
|
||||
retroshare/rstypes.h
|
||||
|
||||
HEADERS += plugins/pluginmanager.h
|
||||
|
||||
HEADERS += $$PUBLIC_HEADERS
|
||||
|
||||
# public headers to be...
|
||||
|
@ -359,7 +362,6 @@ HEADERS += rsserver/p3discovery.h \
|
|||
rsserver/p3msgs.h \
|
||||
rsserver/p3peers.h \
|
||||
rsserver/p3photo.h \
|
||||
rsserver/p3rank.h \
|
||||
rsserver/p3status.h
|
||||
|
||||
HEADERS += serialiser/rsbaseitems.h \
|
||||
|
@ -373,7 +375,6 @@ HEADERS += serialiser/rsbaseitems.h \
|
|||
serialiser/rsgameitems.h \
|
||||
serialiser/rsmsgitems.h \
|
||||
serialiser/rsphotoitems.h \
|
||||
serialiser/rsrankitems.h \
|
||||
serialiser/rsserial.h \
|
||||
serialiser/rsserviceids.h \
|
||||
serialiser/rsserviceitems.h \
|
||||
|
@ -396,7 +397,6 @@ HEADERS += services/p3channels.h \
|
|||
services/p3msgservice.h \
|
||||
services/p3photoservice.h \
|
||||
services/p3portservice.h \
|
||||
services/p3ranking.h \
|
||||
services/p3service.h \
|
||||
services/p3statusservice.h \
|
||||
services/p3tunnel.h
|
||||
|
@ -477,13 +477,14 @@ SOURCES += rsserver/p3discovery.cc \
|
|||
rsserver/p3msgs.cc \
|
||||
rsserver/p3peers.cc \
|
||||
rsserver/p3photo.cc \
|
||||
rsserver/p3rank.cc \
|
||||
rsserver/p3status.cc \
|
||||
rsserver/rsiface.cc \
|
||||
rsserver/rsinit.cc \
|
||||
rsserver/rsloginhandler.cc \
|
||||
rsserver/rstypes.cc
|
||||
|
||||
SOURCES += plugins/pluginmanager.cc
|
||||
|
||||
SOURCES += serialiser/rsbaseitems.cc \
|
||||
serialiser/rsbaseserial.cc \
|
||||
serialiser/rsblogitems.cc \
|
||||
|
@ -495,7 +496,6 @@ SOURCES += serialiser/rsbaseitems.cc \
|
|||
serialiser/rsgameitems.cc \
|
||||
serialiser/rsmsgitems.cc \
|
||||
serialiser/rsphotoitems.cc \
|
||||
serialiser/rsrankitems.cc \
|
||||
serialiser/rsserial.cc \
|
||||
serialiser/rsstatusitems.cc \
|
||||
serialiser/rstlvaddrs.cc \
|
||||
|
@ -517,7 +517,6 @@ SOURCES += services/p3channels.cc \
|
|||
services/p3msgservice.cc \
|
||||
services/p3photoservice.cc \
|
||||
services/p3portservice.cc \
|
||||
services/p3ranking.cc \
|
||||
services/p3service.cc \
|
||||
services/p3statusservice.cc
|
||||
# removed because getPeer() doesn t exist services/p3tunnel.cc
|
||||
|
@ -548,13 +547,11 @@ SOURCES += util/folderiterator.cc \
|
|||
|
||||
minimal {
|
||||
SOURCES -= rsserver/p3msgs.cc \
|
||||
rsserver/p3rank.cc \
|
||||
rsserver/p3status.cc \
|
||||
rsserver/p3photo.cc
|
||||
|
||||
SOURCES -= serialiser/rsforumitems.cc \
|
||||
serialiser/rsstatusitems.cc \
|
||||
serialiser/rsrankitems.cc \
|
||||
serialiser/rschannelitems.cc \
|
||||
serialiser/rsgameitems.cc \
|
||||
serialiser/rsphotoitems.cc
|
||||
|
@ -562,7 +559,6 @@ minimal {
|
|||
SOURCES -= services/p3forums.cc \
|
||||
services/p3msgservice.cc \
|
||||
services/p3statusservice.cc \
|
||||
services/p3ranking.cc \
|
||||
services/p3channels.cc \
|
||||
services/p3gamelauncher.cc \
|
||||
services/p3photoservice.cc
|
||||
|
|
25
libretroshare/src/plugins/pluginclasses.h
Normal file
25
libretroshare/src/plugins/pluginclasses.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <dbase/cachestrapper.h>
|
||||
|
||||
// The following class abstracts the construction of a cache service. The user only has to
|
||||
// supply RS with a type ID. If the ID is already in use, RS will complain.
|
||||
//
|
||||
class RsCacheService: public CacheSource, public CacheStore, public p3Config
|
||||
{
|
||||
public:
|
||||
RsCacheService(uint16_t type,uint32_t config_type,uint32_t tick_delay_in_seconds) ;
|
||||
|
||||
uint32_t tickDelay() const { return _tick_delay_in_seconds ; }
|
||||
virtual void tick() {}
|
||||
|
||||
// Functions from p3config
|
||||
//
|
||||
virtual RsSerialiser *setupSerialiser() { return NULL ; }
|
||||
virtual bool saveList(bool&, std::list<RsItem*>&) { return false ;}
|
||||
virtual bool loadList(std::list<RsItem*>&) { return false ;}
|
||||
|
||||
private:
|
||||
uint32_t _tick_delay_in_seconds ;
|
||||
};
|
||||
|
205
libretroshare/src/plugins/pluginmanager.cc
Normal file
205
libretroshare/src/plugins/pluginmanager.cc
Normal file
|
@ -0,0 +1,205 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "pluginmanager.h"
|
||||
#include <dirent.h>
|
||||
#include <util/folderiterator.h>
|
||||
#include <ft/ftserver.h>
|
||||
#include <dbase/cachestrapper.h>
|
||||
#include <retroshare/rsplugin.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <pqi/pqiservice.h>
|
||||
#include <plugins/pluginclasses.h>
|
||||
|
||||
// lets disable the plugin system for now, as it's unfinished.
|
||||
#define WINDOWS_SYS
|
||||
#ifndef WINDOWS_SYS
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
std::string RsPluginManager::_plugin_entry_symbol ;
|
||||
std::string RsPluginManager::_local_cache_dir ;
|
||||
std::string RsPluginManager::_remote_cache_dir ;
|
||||
ftServer *RsPluginManager::_ftserver = NULL ;
|
||||
p3ConnectMgr *RsPluginManager::_connectmgr = NULL ;
|
||||
|
||||
typedef RsPlugin *(*RetroSharePluginEntry)(void) ;
|
||||
RsPluginHandler *rsPlugins ;
|
||||
|
||||
void RsPluginManager::setCacheDirectories(const std::string& local_cache, const std::string& remote_cache)
|
||||
{
|
||||
_local_cache_dir = local_cache ;
|
||||
_remote_cache_dir = remote_cache ;
|
||||
}
|
||||
|
||||
bool RsPluginManager::acceptablePluginName(const std::string& name)
|
||||
{
|
||||
// Needs some windows specific code here
|
||||
//
|
||||
#ifdef WINDOWS_SYS
|
||||
return name.size() > 4 && !strcmp(name.c_str()+name.size()-3,".dll") ;
|
||||
#else
|
||||
return name.size() > 3 && !strcmp(name.c_str()+name.size()-3,".so") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void RsPluginManager::loadPlugins(const std::vector<std::string>& plugin_directories)
|
||||
{
|
||||
_plugin_entry_symbol = "RETROSHARE_PLUGIN_provide" ;
|
||||
|
||||
// 0 - get the list of files to read
|
||||
|
||||
for(uint32_t i=0;i<plugin_directories.size();++i)
|
||||
{
|
||||
librs::util::FolderIterator dirIt(plugin_directories[i]);
|
||||
if(!dirIt.isValid())
|
||||
{
|
||||
std::cerr << "Plugin directory : " << plugin_directories[i] << " does not exist." << std::endl ;
|
||||
return ;
|
||||
}
|
||||
|
||||
while(dirIt.readdir())
|
||||
{
|
||||
std::string fname;
|
||||
dirIt.d_name(fname);
|
||||
std::string fullname = plugin_directories[i] + "/" + fname;
|
||||
|
||||
if(!acceptablePluginName(fullname))
|
||||
continue ;
|
||||
|
||||
std::cerr << "Found plugin " << fullname << std::endl;
|
||||
std::cerr << " Loading plugin..." << std::endl;
|
||||
|
||||
loadPlugin(fullname) ;
|
||||
}
|
||||
dirIt.closedir();
|
||||
}
|
||||
|
||||
std::cerr << "Loaded a total of " << _plugins.size() << " plugins." << std::endl;
|
||||
}
|
||||
|
||||
bool RsPluginManager::loadPlugin(const std::string& plugin_name)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
std::cerr << " Loading plugin " << plugin_name << std::endl;
|
||||
|
||||
// The following choice is somewhat dangerous since the program can stop when a symbol can
|
||||
// not be resolved. However, this is the only way to bind a single .so for both the
|
||||
// interface and command line executables.
|
||||
|
||||
int link_mode = RTLD_NOW | RTLD_GLOBAL ; // RTLD_NOW
|
||||
//int link_mode = RTLD_GLOBAL ;
|
||||
|
||||
// Warning: this temporary vector is necessary, because linking with a .so that would include BundleManager.h
|
||||
// is going to call the initialization of the static members of bundleManager a second time, and therefore
|
||||
// will erase whatever is already initialized. So I first open all libraries, then fill the vectors.
|
||||
//
|
||||
void *handle = dlopen(plugin_name.c_str(),link_mode) ;
|
||||
|
||||
if(handle == NULL)
|
||||
{
|
||||
std::cerr << " Cannot open plugin: " << dlerror() << std::endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
void *pf = dlsym(handle,_plugin_entry_symbol.c_str()) ;
|
||||
|
||||
if(pf == NULL)
|
||||
std::cerr << dlerror() << std::endl ;
|
||||
else
|
||||
std::cerr << " Added function entry for symbol " << _plugin_entry_symbol << std::endl ;
|
||||
|
||||
RsPlugin *p = ( (*(RetroSharePluginEntry)pf)() ) ;
|
||||
|
||||
if(p == NULL)
|
||||
{
|
||||
std::cerr << " Plugin entry function " << _plugin_entry_symbol << " returns NULL ! It should return an object of type RsPlugin* " << std::endl;
|
||||
return false ;
|
||||
}
|
||||
_plugins.push_back(p) ;
|
||||
|
||||
if(link_mode & RTLD_LAZY)
|
||||
{
|
||||
std::cerr << " Symbols have been linked in LAZY mode. This means that undefined symbols may" << std::endl ;
|
||||
std::cerr << " crash your program any time." << std::endl ;
|
||||
}
|
||||
#else
|
||||
std::cerr << " Plugin load is yet unimplemented under windows." << std::endl;
|
||||
#endif
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
p3ConnectMgr *RsPluginManager::getConnectMgr() const
|
||||
{
|
||||
assert(_connectmgr != NULL) ;
|
||||
return _connectmgr ;
|
||||
}
|
||||
ftServer *RsPluginManager::getFileServer() const
|
||||
{
|
||||
assert(_ftserver != NULL) ;
|
||||
return _ftserver ;
|
||||
}
|
||||
const std::string& RsPluginManager::getLocalCacheDir() const
|
||||
{
|
||||
assert(!_local_cache_dir.empty()) ;
|
||||
return _local_cache_dir ;
|
||||
}
|
||||
const std::string& RsPluginManager::getRemoteCacheDir() const
|
||||
{
|
||||
assert(!_remote_cache_dir.empty()) ;
|
||||
return _remote_cache_dir ;
|
||||
}
|
||||
void RsPluginManager::slowTickPlugins(time_t seconds)
|
||||
{
|
||||
for(uint32_t i=0;i<_plugins.size();++i)
|
||||
if(_plugins[i]->rs_cache_service() != NULL && (seconds % _plugins[i]->rs_cache_service()->tickDelay() ))
|
||||
{
|
||||
std::cerr << " ticking plugin " << _plugins[i]->getPluginName() << std::endl;
|
||||
_plugins[i]->rs_cache_service()->tick() ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsPluginManager::registerCacheServices()
|
||||
{
|
||||
std::cerr << " Registering cache services." << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<_plugins.size();++i)
|
||||
if(_plugins[i]->rs_cache_service() != NULL)
|
||||
{
|
||||
rsFiles->getCacheStrapper()->addCachePair(CachePair(_plugins[i]->rs_cache_service(),_plugins[i]->rs_cache_service(),CacheId(_plugins[i]->rs_service_id(), 0))) ;
|
||||
std::cerr << " adding new cache pair for plugin " << _plugins[i]->getPluginName() << ", with RS_ID " << _plugins[i]->rs_service_id() << std::endl ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsPluginManager::registerClientServices(p3ServiceServer *pqih)
|
||||
{
|
||||
std::cerr << " Registering pqi services." << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<_plugins.size();++i)
|
||||
if(_plugins[i]->rs_pqi_service() != NULL)
|
||||
{
|
||||
pqih->addService(_plugins[i]->rs_pqi_service()) ;
|
||||
std::cerr << " Added pqi service for plugin " << _plugins[i]->getPluginName() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void RsPluginManager::addConfigurations(p3ConfigMgr *ConfigMgr)
|
||||
{
|
||||
std::cerr << " Registering configuration files." << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<_plugins.size();++i)
|
||||
if(_plugins[i]->configurationFileName().length() > 0)
|
||||
{
|
||||
ConfigMgr->addConfiguration(_plugins[i]->configurationFileName(), _plugins[i]->rs_cache_service());
|
||||
std::cerr << " Added configuration for plugin " << _plugins[i]->getPluginName() << ", with file " << _plugins[i]->configurationFileName() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
RsCacheService::RsCacheService(uint16_t service_type,uint32_t config_type,uint32_t tick_delay)
|
||||
: CacheSource(service_type, true, rsPlugins->getFileServer()->getCacheStrapper(), rsPlugins->getLocalCacheDir()),
|
||||
CacheStore (service_type, true, rsPlugins->getFileServer()->getCacheStrapper(), rsPlugins->getFileServer()->getCacheTransfer(), rsPlugins->getRemoteCacheDir()),
|
||||
p3Config(config_type), // CONFIG_TYPE_RANK_LINK
|
||||
_tick_delay_in_seconds(tick_delay)
|
||||
{
|
||||
}
|
||||
|
48
libretroshare/src/plugins/pluginmanager.h
Normal file
48
libretroshare/src/plugins/pluginmanager.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <retroshare/rsplugin.h>
|
||||
|
||||
class p3ConfigMgr ;
|
||||
class p3ServiceServer ;
|
||||
class p3ConnectMgr ;
|
||||
|
||||
class RsPluginManager: public RsPluginHandler
|
||||
{
|
||||
public:
|
||||
RsPluginManager() {}
|
||||
virtual ~RsPluginManager() {}
|
||||
|
||||
virtual int nbPlugins() const { return _plugins.size() ; }
|
||||
virtual RsPlugin *plugin(int i) { return _plugins[i] ; }
|
||||
|
||||
virtual void slowTickPlugins(time_t sec) ;
|
||||
virtual void addConfigurations(p3ConfigMgr *cfgMgr) ;
|
||||
virtual const std::string& getLocalCacheDir() const ;
|
||||
virtual const std::string& getRemoteCacheDir() const ;
|
||||
virtual ftServer *getFileServer() const ;
|
||||
virtual p3ConnectMgr *getConnectMgr() const ;
|
||||
|
||||
static void setPluginEntrySymbol(const std::string& s) { _plugin_entry_symbol = s ; }
|
||||
static bool acceptablePluginName(const std::string& s) ;
|
||||
static void setCacheDirectories(const std::string& local,const std::string& remote) ;
|
||||
static void setFileServer(ftServer *ft) { _ftserver = ft ; }
|
||||
static void setConnectMgr(p3ConnectMgr *cm) { _connectmgr = cm ; }
|
||||
|
||||
void loadPlugins(const std::vector<std::string>& plugin_directories) ;
|
||||
|
||||
void registerCacheServices() ;
|
||||
void registerClientServices(p3ServiceServer *pqih) ;
|
||||
private:
|
||||
bool loadPlugin(const std::string& shared_library_name) ;
|
||||
|
||||
std::vector<RsPlugin *> _plugins ;
|
||||
|
||||
static std::string _plugin_entry_symbol ;
|
||||
static std::string _remote_cache_dir ;
|
||||
static std::string _local_cache_dir ;
|
||||
static ftServer *_ftserver ;
|
||||
static p3ConnectMgr *_connectmgr ;
|
||||
};
|
||||
|
|
@ -82,7 +82,6 @@ const uint32_t CONFIG_TYPE_TURTLE = 0x0020;
|
|||
/* wish these ids where higher...
|
||||
* may move when switch to v0.5
|
||||
*/
|
||||
const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011;
|
||||
const uint32_t CONFIG_TYPE_CHAT = 0x0012;
|
||||
const uint32_t CONFIG_TYPE_STATUS = 0x0013;
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ class RsFiles;
|
|||
extern RsFiles *rsFiles;
|
||||
|
||||
class Expression;
|
||||
class CacheStrapper ;
|
||||
class CacheTransfer;
|
||||
|
||||
/* These are used mainly by ftController at the moment */
|
||||
const uint32_t RS_FILE_CTRL_PAUSE = 0x00000100;
|
||||
|
@ -194,7 +196,8 @@ class RsFiles
|
|||
virtual void setWatchPeriod(int minutes) =0;
|
||||
virtual int watchPeriod() const =0;
|
||||
|
||||
|
||||
virtual CacheStrapper *getCacheStrapper() =0;
|
||||
virtual CacheTransfer *getCacheTransfer() =0;
|
||||
|
||||
virtual bool getShareDownloadDirectory() = 0;
|
||||
virtual bool shareDownloadDirectory(bool share) = 0;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
|
||||
#include "rsserver/p3face.h"
|
||||
#include "retroshare/rsplugin.h"
|
||||
|
||||
#include "tcponudp/tou.h"
|
||||
#include <sstream>
|
||||
|
@ -55,7 +56,6 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
|||
mChannels = NULL;
|
||||
mForums = NULL;
|
||||
/* caches (that need ticking) */
|
||||
mRanking = NULL;
|
||||
|
||||
/* Config */
|
||||
mConfigMgr = NULL;
|
||||
|
@ -96,185 +96,148 @@ static double getCurrentTS()
|
|||
void RsServer::run()
|
||||
{
|
||||
|
||||
double timeDelta = 0.25;
|
||||
double minTimeDelta = 0.1; // 25;
|
||||
double maxTimeDelta = 0.5;
|
||||
double kickLimit = 0.15;
|
||||
double timeDelta = 0.25;
|
||||
double minTimeDelta = 0.1; // 25;
|
||||
double maxTimeDelta = 0.5;
|
||||
double kickLimit = 0.15;
|
||||
|
||||
double avgTickRate = timeDelta;
|
||||
double avgTickRate = timeDelta;
|
||||
|
||||
double lastts, ts;
|
||||
lastts = ts = getCurrentTS();
|
||||
double lastts, ts;
|
||||
lastts = ts = getCurrentTS();
|
||||
|
||||
long lastSec = 0; /* for the slower ticked stuff */
|
||||
long lastSec = 0; /* for the slower ticked stuff */
|
||||
|
||||
int min = 0;
|
||||
int loop = 0;
|
||||
int min = 0;
|
||||
int loop = 0;
|
||||
|
||||
while(isRunning())
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
ts = getCurrentTS();
|
||||
double delta = ts - lastts;
|
||||
|
||||
/* for the fast ticked stuff */
|
||||
if (delta > timeDelta)
|
||||
while(isRunning())
|
||||
{
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "Delta: " << delta << std::endl;
|
||||
std::cerr << "Time Delta: " << timeDelta << std::endl;
|
||||
std::cerr << "Avg Tick Rate: " << avgTickRate << std::endl;
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
lastts = ts;
|
||||
ts = getCurrentTS();
|
||||
double delta = ts - lastts;
|
||||
|
||||
/******************************** RUN SERVER *****************/
|
||||
lockRsCore();
|
||||
|
||||
int moreToTick = ftserver -> tick();
|
||||
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "RsServer::run() ftserver->tick(): moreToTick: " << moreToTick << std::endl;
|
||||
#endif
|
||||
|
||||
unlockRsCore();
|
||||
|
||||
/* tick the connection Manager */
|
||||
mConnMgr->tick();
|
||||
/******************************** RUN SERVER *****************/
|
||||
|
||||
/* adjust tick rate depending on whether there is more.
|
||||
*/
|
||||
|
||||
avgTickRate = 0.2 * timeDelta + 0.8 * avgTickRate;
|
||||
|
||||
if (1 == moreToTick)
|
||||
/* for the fast ticked stuff */
|
||||
if (delta > timeDelta)
|
||||
{
|
||||
timeDelta = 0.9 * avgTickRate;
|
||||
if (timeDelta > kickLimit)
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "Delta: " << delta << std::endl;
|
||||
std::cerr << "Time Delta: " << timeDelta << std::endl;
|
||||
std::cerr << "Avg Tick Rate: " << avgTickRate << std::endl;
|
||||
#endif
|
||||
|
||||
lastts = ts;
|
||||
|
||||
/******************************** RUN SERVER *****************/
|
||||
lockRsCore();
|
||||
|
||||
int moreToTick = ftserver -> tick();
|
||||
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "RsServer::run() ftserver->tick(): moreToTick: " << moreToTick << std::endl;
|
||||
#endif
|
||||
|
||||
unlockRsCore();
|
||||
|
||||
/* tick the connection Manager */
|
||||
mConnMgr->tick();
|
||||
/******************************** RUN SERVER *****************/
|
||||
|
||||
/* adjust tick rate depending on whether there is more.
|
||||
*/
|
||||
|
||||
avgTickRate = 0.2 * timeDelta + 0.8 * avgTickRate;
|
||||
|
||||
if (1 == moreToTick)
|
||||
{
|
||||
/* force next tick in one sec
|
||||
* if we are reading data.
|
||||
*/
|
||||
timeDelta = kickLimit;
|
||||
avgTickRate = kickLimit;
|
||||
timeDelta = 0.9 * avgTickRate;
|
||||
if (timeDelta > kickLimit)
|
||||
{
|
||||
/* force next tick in one sec
|
||||
* if we are reading data.
|
||||
*/
|
||||
timeDelta = kickLimit;
|
||||
avgTickRate = kickLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timeDelta = 1.1 * avgTickRate;
|
||||
}
|
||||
|
||||
/* limiter */
|
||||
if (timeDelta < minTimeDelta)
|
||||
{
|
||||
timeDelta = minTimeDelta;
|
||||
}
|
||||
else if (timeDelta > maxTimeDelta)
|
||||
{
|
||||
timeDelta = maxTimeDelta;
|
||||
}
|
||||
|
||||
/* Fast Updates */
|
||||
|
||||
|
||||
/* now we have the slow ticking stuff */
|
||||
/* stuff ticked once a second (but can be slowed down) */
|
||||
if ((int) ts > lastSec)
|
||||
{
|
||||
lastSec = (int) ts;
|
||||
|
||||
// Every second! (UDP keepalive).
|
||||
//tou_tick_stunkeepalive();
|
||||
|
||||
// every five loops (> 5 secs)
|
||||
if (loop % 5 == 0)
|
||||
else
|
||||
{
|
||||
// update_quick_stats();
|
||||
timeDelta = 1.1 * avgTickRate;
|
||||
}
|
||||
|
||||
// Update All Every 5 Seconds.
|
||||
// These Update Functions do the locking themselves.
|
||||
/* limiter */
|
||||
if (timeDelta < minTimeDelta)
|
||||
{
|
||||
timeDelta = minTimeDelta;
|
||||
}
|
||||
else if (timeDelta > maxTimeDelta)
|
||||
{
|
||||
timeDelta = maxTimeDelta;
|
||||
}
|
||||
|
||||
/* Fast Updates */
|
||||
|
||||
|
||||
/* now we have the slow ticking stuff */
|
||||
/* stuff ticked once a second (but can be slowed down) */
|
||||
if ((int) ts > lastSec)
|
||||
{
|
||||
lastSec = (int) ts;
|
||||
|
||||
// Every second! (UDP keepalive).
|
||||
//tou_tick_stunkeepalive();
|
||||
|
||||
// every five loops (> 5 secs)
|
||||
if (loop % 5 == 0)
|
||||
{
|
||||
// update_quick_stats();
|
||||
|
||||
// Update All Every 5 Seconds.
|
||||
// These Update Functions do the locking themselves.
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "RsServer::run() Updates()" << std::endl;
|
||||
std::cerr << "RsServer::run() Updates()" << std::endl;
|
||||
#endif
|
||||
|
||||
// These two have been completed!
|
||||
//std::cerr << "RsServer::run() UpdateAllCerts()" << std::endl;
|
||||
//UpdateAllCerts();
|
||||
//std::cerr << "RsServer::run() UpdateAllNetwork()" << std::endl;
|
||||
//UpdateAllNetwork();
|
||||
|
||||
// currently Dummy Functions.
|
||||
//std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl;
|
||||
|
||||
//std::cerr << "RsServer::run() ";
|
||||
//std::cerr << "UpdateRemotePeople()"<<std::endl;
|
||||
//UpdateRemotePeople();
|
||||
|
||||
//std::cerr << "RsServer::run() UpdateAllFiles()" << std::endl;
|
||||
//UpdateAllFiles();
|
||||
|
||||
//std::cerr << "RsServer::run() UpdateAllConfig()" << std::endl;
|
||||
UpdateAllConfig();
|
||||
UpdateAllConfig();
|
||||
|
||||
|
||||
mConfigMgr->tick(); /* saves stuff */
|
||||
|
||||
//std::cerr << "RsServer::run() CheckDHT()" << std::endl;
|
||||
//CheckNetworking();
|
||||
}
|
||||
|
||||
// every 60 loops (> 1 min)
|
||||
if (++loop >= 60)
|
||||
{
|
||||
loop = 0;
|
||||
|
||||
/* force saving FileTransferStatus TODO */
|
||||
//ftserver->saveFileTransferStatus();
|
||||
|
||||
/* see if we need to resave certs */
|
||||
//AuthSSL::getAuthSSL()->CheckSaveCertificates();
|
||||
|
||||
/* hour loop */
|
||||
if (++min >= 60)
|
||||
{
|
||||
min = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tick slow services */
|
||||
#ifndef MINIMAL_LIBRS
|
||||
if (mRanking)
|
||||
mRanking->tick();
|
||||
#endif // MINIMAL_LIBRS
|
||||
if(rsPlugins)
|
||||
rsPlugins->slowTickPlugins((time_t)ts);
|
||||
|
||||
#if 0
|
||||
std::string opt;
|
||||
std::string val = "VALUE";
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "SEC:" << lastSec;
|
||||
opt = out.str();
|
||||
}
|
||||
// slow update tick as well.
|
||||
// update();
|
||||
} // end of slow tick.
|
||||
|
||||
mGeneralConfig->setSetting(opt, val);
|
||||
#endif
|
||||
|
||||
mConfigMgr->tick(); /* saves stuff */
|
||||
|
||||
}
|
||||
|
||||
// every 60 loops (> 1 min)
|
||||
if (++loop >= 60)
|
||||
{
|
||||
loop = 0;
|
||||
|
||||
/* force saving FileTransferStatus TODO */
|
||||
//ftserver->saveFileTransferStatus();
|
||||
|
||||
/* see if we need to resave certs */
|
||||
//AuthSSL::getAuthSSL()->CheckSaveCertificates();
|
||||
|
||||
/* hour loop */
|
||||
if (++min >= 60)
|
||||
{
|
||||
min = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// slow update tick as well.
|
||||
// update();
|
||||
} // end of slow tick.
|
||||
|
||||
} // end of only once a second.
|
||||
}
|
||||
return;
|
||||
} // end of only once a second.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "services/p3disc.h"
|
||||
#include "services/p3msgservice.h"
|
||||
#include "services/p3chatservice.h"
|
||||
#include "services/p3ranking.h"
|
||||
#include "services/p3blogs.h"
|
||||
#include "services/p3statusservice.h"
|
||||
#include "services/p3channels.h"
|
||||
|
@ -165,7 +164,6 @@ class RsServer: public RsControl, public RsThread
|
|||
p3Channels *mChannels;
|
||||
p3Forums *mForums;
|
||||
/* caches (that need ticking) */
|
||||
p3Ranking *mRanking;
|
||||
|
||||
/* Config */
|
||||
p3ConfigMgr *mConfigMgr;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "util/rsrandom.h"
|
||||
#include "util/folderiterator.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "plugins/pluginmanager.h"
|
||||
#include "rsserver/rsloginhandler.h"
|
||||
|
||||
#include <list>
|
||||
|
@ -1703,7 +1704,6 @@ RsTurtle *rsTurtle = NULL ;
|
|||
#include "services/p3msgservice.h"
|
||||
#include "services/p3chatservice.h"
|
||||
#include "services/p3gamelauncher.h"
|
||||
#include "services/p3ranking.h"
|
||||
#include "services/p3photoservice.h"
|
||||
#include "services/p3forums.h"
|
||||
#include "services/p3channels.h"
|
||||
|
@ -1725,7 +1725,6 @@ RsTurtle *rsTurtle = NULL ;
|
|||
/* Implemented Rs Interfaces */
|
||||
#include "rsserver/p3face.h"
|
||||
#include "rsserver/p3peers.h"
|
||||
#include "rsserver/p3rank.h"
|
||||
#include "rsserver/p3msgs.h"
|
||||
#include "rsserver/p3discovery.h"
|
||||
#include "rsserver/p3photo.h"
|
||||
|
@ -1916,11 +1915,39 @@ int RsServer::StartupRetroShare()
|
|||
rsFiles = ftserver;
|
||||
|
||||
|
||||
mConfigMgr = new p3ConfigMgr(RsInitConfig::configDir, "rs-v0.5.cfg", "rs-v0.5.sgn");
|
||||
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";
|
||||
std::string remotecachedir = config_dir + "/cache/remote";
|
||||
std::string channelsdir = config_dir + "/channels";
|
||||
std::string blogsdir = config_dir + "/blogs";
|
||||
std::string forumdir = config_dir + "/forums";
|
||||
std::string plugins_dir = "." ;
|
||||
|
||||
|
||||
std::vector<std::string> plugins_directories ;
|
||||
plugins_directories.push_back(".") ; // this list should be saved/set to some correct value.
|
||||
// possible entries include: /usr/lib/retroshare, ~/.retroshare/extensions/, etc.
|
||||
|
||||
RsPluginManager *mPluginsManager = new RsPluginManager ;
|
||||
rsPlugins = mPluginsManager ;
|
||||
|
||||
// These are needed to load plugins: plugin devs might want to know the place of
|
||||
// cache directories, get pointers to cache strapper, or access ownId()
|
||||
//
|
||||
mPluginsManager->setCacheDirectories(localcachedir,remotecachedir) ;
|
||||
mPluginsManager->setFileServer(ftserver) ;
|
||||
mPluginsManager->setConnectMgr(mConnMgr) ;
|
||||
|
||||
// Now load the plugins. This parses the available SO/DLL files for known symbols.
|
||||
//
|
||||
mPluginsManager->loadPlugins(plugins_directories) ;
|
||||
|
||||
/* create Services */
|
||||
ad = new p3disc(mConnMgr, pqih);
|
||||
ad = new p3disc(mConnMgr, pqih);
|
||||
#ifndef MINIMAL_LIBRS
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
|
@ -1943,51 +1970,32 @@ int RsServer::StartupRetroShare()
|
|||
pqih -> addService(msgSrv);
|
||||
pqih -> addService(chatSrv);
|
||||
pqih ->addService(mStatusSrv);
|
||||
|
||||
#endif // MINIMAL_LIBRS
|
||||
|
||||
/* create Cache Services */
|
||||
std::string config_dir = RsInitConfig::configDir;
|
||||
std::string localcachedir = config_dir + "/cache/local";
|
||||
std::string remotecachedir = config_dir + "/cache/remote";
|
||||
std::string channelsdir = config_dir + "/channels";
|
||||
std::string blogsdir = config_dir + "/blogs";
|
||||
std::string forumdir = config_dir + "/forums";
|
||||
|
||||
|
||||
#ifndef MINIMAL_LIBRS
|
||||
mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */
|
||||
mCacheStrapper, mCacheTransfer,
|
||||
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
|
||||
|
||||
CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0));
|
||||
mCacheStrapper -> addCachePair(cp); /* end of declaration */
|
||||
mForums = new p3Forums(RS_SERVICE_TYPE_FORUM, mCacheStrapper, mCacheTransfer, localcachedir, remotecachedir, forumdir);
|
||||
|
||||
mForums = new p3Forums(RS_SERVICE_TYPE_FORUM,
|
||||
mCacheStrapper, mCacheTransfer,
|
||||
localcachedir, remotecachedir, forumdir);
|
||||
|
||||
CachePair cp4(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0));
|
||||
mCacheStrapper -> addCachePair(cp4);
|
||||
mCacheStrapper -> addCachePair( CachePair(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0)));
|
||||
pqih -> addService(mForums); /* This must be also ticked as a service */
|
||||
|
||||
mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL,
|
||||
mCacheStrapper, mCacheTransfer, rsFiles,
|
||||
localcachedir, remotecachedir, channelsdir);
|
||||
mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL, mCacheStrapper, mCacheTransfer, rsFiles, localcachedir, remotecachedir, channelsdir);
|
||||
|
||||
CachePair cp5(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0));
|
||||
mCacheStrapper -> addCachePair(cp5);
|
||||
mCacheStrapper -> addCachePair(CachePair(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0)));
|
||||
pqih -> addService(mChannels); /* This must be also ticked as a service */
|
||||
#ifdef RS_USE_BLOGS
|
||||
p3Blogs *mBlogs = new p3Blogs(RS_SERVICE_TYPE_QBLOG,
|
||||
mCacheStrapper, mCacheTransfer, rsFiles,
|
||||
localcachedir, remotecachedir, blogsdir);
|
||||
p3Blogs *mBlogs = new p3Blogs(RS_SERVICE_TYPE_QBLOG, mCacheStrapper, mCacheTransfer, rsFiles, localcachedir, remotecachedir, blogsdir);
|
||||
|
||||
CachePair cp6(mBlogs, mBlogs, CacheId(RS_SERVICE_TYPE_QBLOG, 0));
|
||||
mCacheStrapper -> addCachePair(cp6);
|
||||
mCacheStrapper -> addCachePair(CachePair(mBlogs, mBlogs, CacheId(RS_SERVICE_TYPE_QBLOG, 0)));
|
||||
pqih -> addService(mBlogs); /* This must be also ticked as a service */
|
||||
|
||||
#endif
|
||||
|
||||
// now add plugin objects inside the loop:
|
||||
// - client services provided by plugins.
|
||||
// - cache services provided by plugins.
|
||||
//
|
||||
mPluginsManager->registerClientServices(pqih) ;
|
||||
mPluginsManager->registerCacheServices() ;
|
||||
|
||||
#ifndef RS_RELEASE
|
||||
p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr);
|
||||
|
@ -2044,13 +2052,14 @@ int RsServer::StartupRetroShare()
|
|||
#ifdef RS_USE_BLOGS
|
||||
mConfigMgr->addConfiguration("blogs.cfg", mBlogs);
|
||||
#endif
|
||||
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
|
||||
mConfigMgr->addConfiguration("forums.cfg", mForums);
|
||||
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
||||
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
|
||||
#endif // MINIMAL_LIBRS
|
||||
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
||||
mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
||||
mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
||||
|
||||
mPluginsManager->addConfigurations(mConfigMgr) ;
|
||||
|
||||
ftserver->addConfiguration(mConfigMgr);
|
||||
|
||||
|
@ -2210,10 +2219,9 @@ int RsServer::StartupRetroShare()
|
|||
rsDisc = new p3Discovery(ad);
|
||||
|
||||
#ifndef MINIMAL_LIBRS
|
||||
rsMsgs = new p3Msgs(msgSrv, chatSrv);
|
||||
rsMsgs = new p3Msgs(msgSrv, chatSrv);
|
||||
rsForums = mForums;
|
||||
rsChannels = mChannels;
|
||||
rsRanks = new p3Rank(mRanking);
|
||||
#ifdef RS_USE_BLOGS
|
||||
rsBlogs = mBlogs;
|
||||
#endif
|
||||
|
@ -2228,7 +2236,6 @@ int RsServer::StartupRetroShare()
|
|||
#endif
|
||||
#endif // MINIMAL_LIBRS
|
||||
|
||||
|
||||
#ifndef MINIMAL_LIBRS
|
||||
/* put a welcome message in! */
|
||||
if (RsInitConfig::firsttime_run)
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
|
||||
/* These are Cache Only */
|
||||
const uint16_t RS_SERVICE_TYPE_FILE_INDEX = 0x0001;
|
||||
const uint16_t RS_SERVICE_TYPE_RANK = 0x0002;
|
||||
|
||||
/* These are Services only */
|
||||
const uint16_t RS_SERVICE_TYPE_DISC = 0x0011;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue