mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-16 21:12:31 -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
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue