More bugfixes ... got the basic channels file transfer working.

* Create channels directory correctly.
 * added File Transfers to Config List.
 * connected statusChange() monitor callback.
 * fixed file sources in transfermodule.
 * fixed up transfer restarts / sleeps.
 * enabled opening files read only.
 * disabled some of the debug.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@799 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-11-13 23:03:46 +00:00
parent b0d462c93e
commit fce83cb232
16 changed files with 322 additions and 229 deletions

View File

@ -37,12 +37,9 @@
/**** /****
* #define FI_DEBUG 1 * #define FI_DEBUG 1
* #define FI_DEBUG_ALL 1
****/ ****/
#define FI_DEBUG 1
#define FI_DEBUG_ALL 1
DirEntry::~DirEntry() DirEntry::~DirEntry()
{ {
/* cleanup */ /* cleanup */

View File

@ -44,8 +44,6 @@ FileIndexStore::~FileIndexStore()
* #define FIS_DEBUG 1 * #define FIS_DEBUG 1
**/ **/
#define FIS_DEBUG 1
/* actual load, once data available */ /* actual load, once data available */
int FileIndexStore::loadCache(const CacheData &data) int FileIndexStore::loadCache(const CacheData &data)
{ {

View File

@ -352,6 +352,7 @@ bool ftController::FileRequest(std::string fname, std::string hash,
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
std::string ownId = mConnMgr->getOwnId();
uint32_t rate = 0; uint32_t rate = 0;
if (flags & RS_FILE_HINTS_BACKGROUND) if (flags & RS_FILE_HINTS_BACKGROUND)
{ {
@ -398,13 +399,21 @@ bool ftController::FileRequest(std::string fname, std::string hash,
std::cerr << "ftController::FileRequest() Adding Peer: " << *it; std::cerr << "ftController::FileRequest() Adding Peer: " << *it;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* add peer */ (dit->second).mTransfer->addFileSource(*it);
(dit->second).mTransfer->setPeerState(*it, setPeerState(dit->second.mTransfer, *it,
PQIPEER_IDLE, rate); rate, mConnMgr->isOnline(*it));
}
if (srcIds.size() == 0)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest() WARNING: No Src Peers";
std::cerr << std::endl;
#endif
}
return true; return true;
} }
}
bool doCallback = false; bool doCallback = false;
uint32_t callbackCode = 0; uint32_t callbackCode = 0;
@ -504,6 +513,13 @@ bool ftController::FileRequest(std::string fname, std::string hash,
ftFileControl ftfc(fname, savepath, destination, ftFileControl ftfc(fname, savepath, destination,
size, hash, flags, fc, tm, callbackCode); size, hash, flags, fc, tm, callbackCode);
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest() Created ftFileCreator @: " << fc;
std::cerr << std::endl;
std::cerr << "ftController::FileRequest() Created ftTransModule @: " << tm;
std::cerr << std::endl;
#endif
/* add to ClientModule */ /* add to ClientModule */
mDataplex->addTransferModule(tm, fc); mDataplex->addTransferModule(tm, fc);
@ -511,43 +527,13 @@ bool ftController::FileRequest(std::string fname, std::string hash,
tm->setFileSources(srcIds); tm->setFileSources(srcIds);
/* get current state for transfer module */ /* get current state for transfer module */
std::string ownId = mConnMgr->getOwnId();
for(it = srcIds.begin(); it != srcIds.end(); it++) for(it = srcIds.begin(); it != srcIds.end(); it++)
{ {
if (*it == ownId)
{
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest()"; std::cerr << "ftController::FileRequest() adding peer: " << *it;
std::cerr << *it << " is Self - set high rate";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
//tm->setPeerState(*it, RS_FILE_RATE_FAST | setPeerState(tm, *it, rate, mConnMgr->isOnline(*it));
// RS_FILE_PEER_ONLINE, 100000);
//tm->setPeerState(*it, PQIPEER_IDLE, 10000);
tm->setPeerState(*it, PQIPEER_IDLE, rate);
}
else if (mConnMgr->isOnline(*it))
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest()";
std::cerr << *it << " is Online";
std::cerr << std::endl;
#endif
//tm->setPeerState(*it, RS_FILE_RATE_TRICKLE |
// RS_FILE_PEER_ONLINE, 10000);
//tm->setPeerState(*it, PQIPEER_IDLE, 10000);
tm->setPeerState(*it, PQIPEER_IDLE, rate);
}
else
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest()";
std::cerr << *it << " is Offline";
std::cerr << std::endl;
#endif
//tm->setPeerState(*it, RS_FILE_PEER_OFFLINE, 10000);
tm->setPeerState(*it, PQIPEER_IDLE, rate);
}
} }
/* only need to lock before to fiddle with own variables */ /* only need to lock before to fiddle with own variables */
@ -559,6 +545,39 @@ bool ftController::FileRequest(std::string fname, std::string hash,
} }
bool ftController::setPeerState(ftTransferModule *tm, std::string id,
uint32_t maxrate, bool online)
{
if (id == mConnMgr->getOwnId())
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::setPeerState() is Self";
std::cerr << std::endl;
#endif
tm->setPeerState(id, PQIPEER_IDLE, maxrate);
}
else if (online)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::setPeerState()";
std::cerr << " Peer is Online";
std::cerr << std::endl;
#endif
tm->setPeerState(id, PQIPEER_IDLE, maxrate);
}
else
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::setPeerState()";
std::cerr << " Peer is Offline";
std::cerr << std::endl;
#endif
tm->setPeerState(id, PQIPEER_NOT_ONLINE, maxrate);
}
return true;
}
bool ftController::FileCancel(std::string hash) bool ftController::FileCancel(std::string hash)
{ {
@ -825,47 +844,57 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
*/ */
void ftController::statusChange(const std::list<pqipeer> &plist) void ftController::statusChange(const std::list<pqipeer> &plist)
{ {
#if 0 /*** FIX ME !!!**************/
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
uint32_t rate = FT_CNTRL_STANDARD_RATE;
/* add online to all downloads */ /* add online to all downloads */
std::map<std::string, ftFileControl>::iterator it; std::map<std::string, ftFileControl>::iterator it;
std::list<pqipeer>::const_iterator pit; std::list<pqipeer>::const_iterator pit;
for(it = mDownloads.begin(); it != mDownloads.end(); it++) #ifdef CONTROL_DEBUG
{ std::cerr << "ftController::statusChange()";
for(pit = plist.begin(); pit != plist.end(); pit++) std::cerr << std::endl;
{
if (pit->actions | RS_PEER_CONNECTED)
{
((it->second).mTransfer)->setPeer(RS_FILE_PEER_ONLINE | RS_FILE_RATE_TRICKLE);
}
else if (pit->actions | RS_PEER_DISCONNECTED)
{
((it->second).mTransfer)->setPeer(RS_FILE_PEER_OFFLINE);
}
}
}
/* modify my list of peers */
for(pit = plist.begin(); pit != plist.end(); pit++)
{
if (pit->actions | RS_PEER_CONNECTED)
{
/* add in */
((it->second).mTransfer)->setPeer(RS_FILE_PEER_ONLINE | RS_FILE_RATE_TRICKLE);
}
else if (pit->actions | RS_PEER_DISCONNECTED)
{
((it->second).mTransfer)->setPeer(RS_FILE_PEER_OFFLINE);
}
}
#endif #endif
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::statusChange() Updating Hash:";
std::cerr << it->first;
std::cerr << std::endl;
#endif
for(pit = plist.begin(); pit != plist.end(); pit++)
{
#ifdef CONTROL_DEBUG
std::cerr << "Peer: " << pit->id;
#endif
if (pit->actions & RS_PEER_CONNECTED)
{
#ifdef CONTROL_DEBUG
std::cerr << " is Newly Connected!";
std::cerr << std::endl;
#endif
setPeerState(it->second.mTransfer, pit->id, rate, true);
}
else if (pit->actions & RS_PEER_DISCONNECTED)
{
#ifdef CONTROL_DEBUG
std::cerr << " is Just disconnected!";
std::cerr << std::endl;
#endif
setPeerState(it->second.mTransfer, pit->id, rate, false);
}
else
{
#ifdef CONTROL_DEBUG
std::cerr << " had something happen to it: ";
std::cerr << pit-> actions;
std::cerr << std::endl;
#endif
setPeerState(it->second.mTransfer, pit->id, rate, false);
}
}
}
} }
/* p3Config Interface */ /* p3Config Interface */
RsSerialiser *ftController::setupSerialiser() RsSerialiser *ftController::setupSerialiser()

View File

@ -150,6 +150,9 @@ virtual bool loadList(std::list<RsItem *> load);
void checkDownloadQueue(); void checkDownloadQueue();
bool completeFile(std::string hash); bool completeFile(std::string hash);
bool setPeerState(ftTransferModule *tm, std::string id,
uint32_t maxrate, bool online);
/* pointers to other components */ /* pointers to other components */
ftSearch *mSearch; ftSearch *mSearch;

View File

@ -7,7 +7,7 @@
#define FILE_DEBUG 1 #define FILE_DEBUG 1
#define CHUNK_MAX_AGE 30 #define CHUNK_MAX_AGE 20
/*********************************************************** /***********************************************************
@ -147,20 +147,19 @@ int ftFileCreator::initializeFileAttrs()
/* /*
* check if the file exists * check if the file exists
* cant use FileProviders verion because that opens readonly.
*/ */
if (ftFileProvider::initializeFileAttrs())
{
return 1;
}
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
if (fd) if (fd)
return 1; return 1;
/*
* check if the file exists
*/
{ {
std::cerr << "ftFileCreator::initializeFileAttrs() opening w+b"; std::cerr << "ftFileCreator::initializeFileAttrs() trying (r+b) ";
std::cerr << std::endl; std::cerr << std::endl;
} }
@ -168,14 +167,27 @@ int ftFileCreator::initializeFileAttrs()
* attempt to open file * attempt to open file
*/ */
fd = fopen(file_name.c_str(), "r+b");
if (!fd)
{
std::cerr << "ftFileCreator::initializeFileAttrs() Failed to open (r+b): ";
std::cerr << file_name << std::endl;
std::cerr << "ftFileCreator::initializeFileAttrs() opening w+b";
std::cerr << std::endl;
/* try opening for write */
fd = fopen(file_name.c_str(), "w+b"); fd = fopen(file_name.c_str(), "w+b");
if (!fd) if (!fd)
{ {
std::cerr << "ftFileCreator::initializeFileAttrs()"; std::cerr << "ftFileCreator::initializeFileAttrs()";
std::cerr << " Failed to open (w+b): "<< file_name << std::endl; std::cerr << " Failed to open (w+b): "<< file_name << std::endl;
return 0; return 0;
} }
}
/* /*
* if it opened, find it's length * if it opened, find it's length

View File

@ -64,8 +64,9 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t chunk_size, void *dat
/* /*
* FIXME: Warning of comparison between unsigned and signed int? * FIXME: Warning of comparison between unsigned and signed int?
*/ */
int data_size = chunk_size;
long base_loc = offset; uint32_t data_size = chunk_size;
uint64_t base_loc = offset;
if (base_loc + data_size > mSize) if (base_loc + data_size > mSize)
{ {
@ -138,13 +139,22 @@ int ftFileProvider::initializeFileAttrs()
* attempt to open file * attempt to open file
*/ */
fd = fopen(file_name.c_str(), "r+b"); fd = fopen(file_name.c_str(), "rb");
if (!fd) if (!fd)
{ {
std::cerr << "ftFileProvider::initializeFileAttrs() Failed to open (r+b): "; std::cerr << "ftFileProvider::initializeFileAttrs() Failed to open (r+b): ";
std::cerr << file_name << std::endl; std::cerr << file_name << std::endl;
return 0;
/* try opening read only */
fd = fopen(file_name.c_str(), "rb");
if (!fd)
{
std::cerr << "ftFileProvider::initializeFileAttrs() Failed to open (rb): ";
std::cerr << file_name << std::endl;
/* try opening read only */
return 0;
}
} }
/* /*

View File

@ -48,6 +48,7 @@
*/ */
const double FT_TM_MAX_PEER_RATE = 1024 * 1024; /* 1MB/s */ const double FT_TM_MAX_PEER_RATE = 1024 * 1024; /* 1MB/s */
const uint32_t FT_TM_MAX_RESETS = 5;
ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftController *c) ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftController *c)
:mFileCreator(fc), mMultiplexor(dm), mFtController(c), mFlag(0) :mFileCreator(fc), mMultiplexor(dm), mFtController(c), mFlag(0)
@ -111,6 +112,38 @@ bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
return true; return true;
} }
bool ftTransferModule::addFileSource(std::string peerId)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit;
mit = mFileSources.find(peerId);
if (mit == mFileSources.end())
{
/* add in new source */
peerInfo pInfo(peerId);
mFileSources.insert(std::pair<std::string,peerInfo>(peerId,pInfo));
mit = mFileSources.find(peerId);
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::addFileSource()";
std::cerr << " adding peer: " << peerId << " to sourceList";
std::cerr << std::endl;
#endif
}
else
{
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::addFileSource()";
std::cerr << " peer: " << peerId << " already there";
std::cerr << std::endl;
#endif
}
}
bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t maxRate) bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t maxRate)
{ {
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
@ -124,7 +157,17 @@ bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t m
std::map<std::string,peerInfo>::iterator mit; std::map<std::string,peerInfo>::iterator mit;
mit = mFileSources.find(peerId); mit = mFileSources.find(peerId);
if (mit == mFileSources.end()) return false; if (mit == mFileSources.end())
{
/* add in new source */
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::setPeerState()";
std::cerr << " adding new peer to sourceList";
std::cerr << std::endl;
#endif
return false;
}
(mit->second).state=state; (mit->second).state=state;
(mit->second).desiredRate=maxRate; (mit->second).desiredRate=maxRate;
@ -458,9 +501,25 @@ void ftTransferModule::adjustSpeed()
**/ **/
const uint32_t FT_TM_MINIMUM_CHUNK = 1024; /* ie 1Kb / sec */ const uint32_t FT_TM_MINIMUM_CHUNK = 1024; /* ie 1Kb / sec */
const uint32_t FT_TM_RESTART_DOWNLOAD = 60; /* 60 seconds */ const uint32_t FT_TM_RESTART_DOWNLOAD = 10; /* 10 seconds */
const uint32_t FT_TM_DOWNLOAD_TIMEOUT = 5; /* 5 seconds */ const uint32_t FT_TM_DOWNLOAD_TIMEOUT = 5; /* 5 seconds */
/* NOTEs on this function...
* 1) This is the critical function for deciding the rate at which ft takes place.
* 2) Some of the peers might not have the file... care must be taken avoid deadlock.
*
* Eg. A edge case which fails badly.
* Small 1K file (one chunk), with 3 sources (A,B,C). A doesn't have file.
* (a) request data from A. B & C pause cos no more data needed.
* (b) all timeout, chunk reset... then back to request again (a) and repeat.
* (c) all timeout x 5 and are disabled.... no transfer, while B&C had it all the time.
*
* To solve this we might need random waiting periods, so each peer can
* be tried.
*
*
*/
bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info) bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
{ {
/* how long has it been? */ /* how long has it been? */
@ -477,11 +536,31 @@ bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
return false; return false;
} }
if (ageReq > FT_TM_RESTART_DOWNLOAD) if (ageReq > FT_TM_RESTART_DOWNLOAD * (info.nResets + 1))
{ {
if (info.nResets > 1) /* 3rd timeout */
{
/* 90% chance of return false...
* will mean variations in which peer
* starts first. hopefully stop deadlocks.
*/
if (rand() % 10 != 0)
{
return false;
}
}
info.state = PQIPEER_DOWNLOADING; info.state = PQIPEER_DOWNLOADING;
info.recvTS = ts; /* reset to activate */ info.recvTS = ts; /* reset to activate */
info.nResets++;
ageRecv = 0; ageRecv = 0;
if (info.nResets >= FT_TM_MAX_RESETS)
{
/* for this file anyway */
info.state = PQIPEER_NOT_ONLINE;
return false;
}
} }
if (ageRecv > FT_TM_DOWNLOAD_TIMEOUT) if (ageRecv > FT_TM_DOWNLOAD_TIMEOUT)
@ -543,6 +622,7 @@ bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset,
time_t ts = time(NULL); time_t ts = time(NULL);
info.recvTS = ts; info.recvTS = ts;
info.nResets = 0;
info.state = PQIPEER_DOWNLOADING; info.state = PQIPEER_DOWNLOADING;
info.lastTransfers += chunk_size; info.lastTransfers += chunk_size;

View File

@ -45,42 +45,25 @@
#include "util/rsthreads.h" #include "util/rsthreads.h"
const int PQIPEER_INIT = 0x0000; const uint32_t PQIPEER_INIT = 0x0000;
const int PQIPEER_NOT_ONLINE = 0x0001; const uint32_t PQIPEER_NOT_ONLINE = 0x0001;
const int PQIPEER_DOWNLOADING = 0x0002; const uint32_t PQIPEER_DOWNLOADING = 0x0002;
const int PQIPEER_IDLE = 0x0004; const uint32_t PQIPEER_IDLE = 0x0004;
const int PQIPEER_SUSPEND = 0x0010; const uint32_t PQIPEER_SUSPEND = 0x0010;
const uint32_t PQIPEER_OFFLINE_CHECK = 120; /* check every 2 minutes */
const uint32_t PQIPEER_DOWNLOAD_TIMEOUT = 60; /* time it out, -> offline after 60 secs */
const uint32_t PQIPEER_DOWNLOAD_CHECK = 10; /* desired delta = 10 secs */
const uint32_t PQIPEER_DOWNLOAD_TOO_FAST = 8; /* 8 secs */
const uint32_t PQIPEER_DOWNLOAD_TOO_SLOW = 12; /* 12 secs */
const uint32_t PQIPEER_DOWNLOAD_MIN_DELTA = 5; /* 5 secs */
const uint32_t TRANSFER_START_MIN = 10000; /* 10000 byte min limit */
const uint32_t TRANSFER_START_MAX = 10000; /* 10000 byte max limit */
/*
class Request
{
public:
uint64_t offset;
uint32_t chunkSize;
};
*/
class peerInfo class peerInfo
{ {
public: public:
peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0), peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
offset(0),chunkSize(TRANSFER_START_MIN),receivedSize(0),lastTS(0), offset(0),chunkSize(0),receivedSize(0),lastTS(0),
recvTS(0), lastTransfers(0) recvTS(0), lastTransfers(0), nResets(0)
{ {
return; return;
} }
peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in): peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in):
peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0), peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0),
offset(0),chunkSize(TRANSFER_START_MIN),receivedSize(0),lastTS(0), offset(0),chunkSize(0),receivedSize(0),lastTS(0),
recvTS(0), lastTransfers(0) recvTS(0), lastTransfers(0), nResets(0)
{ {
return; return;
} }
@ -99,6 +82,7 @@ public:
time_t lastTS; /* last Request */ time_t lastTS; /* last Request */
time_t recvTS; /* last Recv */ time_t recvTS; /* last Recv */
uint32_t lastTransfers; /* data recvd in last second */ uint32_t lastTransfers; /* data recvd in last second */
uint32_t nResets; /* count to disable non-existant files */
}; };
class ftFileStatus class ftFileStatus
@ -135,6 +119,7 @@ public:
//interface to download controller //interface to download controller
bool setFileSources(std::list<std::string> peerIds); bool setFileSources(std::list<std::string> peerIds);
bool addFileSource(std::string peerId);
bool setPeerState(std::string peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE bool setPeerState(std::string peerId,uint32_t state,uint32_t maxRate); //state = ONLINE/OFFLINE
bool getFileSources(std::list<std::string> &peerIds); bool getFileSources(std::list<std::string> &peerIds);
bool getPeerState(std::string peerId,uint32_t &state,uint32_t &tfRate); bool getPeerState(std::string peerId,uint32_t &state,uint32_t &tfRate);

View File

@ -64,13 +64,19 @@ const uint32_t CONFIG_TYPE_FSERVER = 0x0003;
const uint32_t CONFIG_TYPE_MSGS = 0x0004; const uint32_t CONFIG_TYPE_MSGS = 0x0004;
const uint32_t CONFIG_TYPE_CACHE_OLDID = 0x0005; const uint32_t CONFIG_TYPE_CACHE_OLDID = 0x0005;
/* new FileTransfer */
const uint32_t CONFIG_TYPE_EXTRALIST = 0x0008;
const uint32_t CONFIG_TYPE_CONTROL = 0x0009;
/* 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_RANK_LINK = 0x0011;
const uint32_t CONFIG_TYPE_QBLOG = 0x0012; /* standard services */
const uint32_t CONFIG_TYPE_QBLOG = 0x0101;
const uint32_t CONFIG_TYPE_FORUMS = 0x0013; const uint32_t CONFIG_TYPE_FORUMS = 0x0102;
const uint32_t CONFIG_TYPE_CHANNELS = 0x0103;
const uint32_t CONFIG_TYPE_CHANNELS = 0x0014;
/* CACHE ID Must be at the END so that other configurations /* CACHE ID Must be at the END so that other configurations
* are loaded First (Cache Config --> Cache Loading) * are loaded First (Cache Config --> Cache Loading)

View File

@ -154,12 +154,8 @@ int RsServer::UpdateAllConfig()
void RsServer::ConfigFinalSave() void RsServer::ConfigFinalSave()
{ {
/* force saving of transfers */ /* force saving of transfers TODO */
#ifdef USE_OLD_FT
server->saveFileTransferStatus();
#else
//ftserver->saveFileTransferStatus(); //ftserver->saveFileTransferStatus();
#endif
mAuthMgr->FinalSaveCertificates(); mAuthMgr->FinalSaveCertificates();
mConfigMgr->completeConfiguration(); mConfigMgr->completeConfiguration();

View File

@ -27,10 +27,6 @@
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#ifdef USE_OLD_FT
#include "rsserver/p3files.h" // TMP FOR HACK!
#endif
#include "tcponudp/tou.h" #include "tcponudp/tou.h"
#include <sstream> #include <sstream>
@ -121,11 +117,7 @@ void RsServer::run()
/******************************** RUN SERVER *****************/ /******************************** RUN SERVER *****************/
lockRsCore(); lockRsCore();
#ifdef USE_OLD_FT
int moreToTick = server -> tick();
#else
int moreToTick = ftserver -> tick(); int moreToTick = ftserver -> tick();
#endif
#ifdef DEBUG_TICK #ifdef DEBUG_TICK
std::cerr << "RsServer::run() ftserver->tick(): moreToTick: " << moreToTick << std::endl; std::cerr << "RsServer::run() ftserver->tick(): moreToTick: " << moreToTick << std::endl;
@ -201,16 +193,6 @@ void RsServer::run()
// currently Dummy Functions. // currently Dummy Functions.
//std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl; //std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl;
#ifdef USE_OLD_FT
//
// TMP HACK.
p3Files *p3f = (p3Files *) rsFiles;
if (p3f)
{
p3f -> UpdateAllTransfers();
}
#endif
//std::cerr << "RsServer::run() "; //std::cerr << "RsServer::run() ";
//std::cerr << "UpdateRemotePeople()"<<std::endl; //std::cerr << "UpdateRemotePeople()"<<std::endl;
//UpdateRemotePeople(); //UpdateRemotePeople();
@ -258,12 +240,8 @@ void RsServer::run()
{ {
loop = 0; loop = 0;
/* force saving FileTransferStatus */ /* force saving FileTransferStatus TODO */
#ifdef USE_OLD_FT
ftserver->saveFileTransferStatus();
#else
//ftserver->saveFileTransferStatus(); //ftserver->saveFileTransferStatus();
#endif
/* see if we need to resave certs */ /* see if we need to resave certs */
mAuthMgr->CheckSaveCertificates(); mAuthMgr->CheckSaveCertificates();

View File

@ -28,13 +28,8 @@
//#include <getopt.h> //#include <getopt.h>
#include "dbase/cachestrapper.h" #include "dbase/cachestrapper.h"
#ifdef USE_OLD_FT
#include "server/ftfiler.h"
#include "server/filedexserver.h"
#else
#include "ft/ftserver.h" #include "ft/ftserver.h"
#include "ft/ftcontroller.h" #include "ft/ftcontroller.h"
#endif
/* global variable now points straight to /* global variable now points straight to
* ft/ code so variable defined here. * ft/ code so variable defined here.
@ -91,6 +86,8 @@ RsFiles *rsFiles = NULL;
#define RS_RELEASE 1 #define RS_RELEASE 1
****/ ****/
#define RS_RELEASE 1
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
#include "pqi/authxpgp.h" #include "pqi/authxpgp.h"
@ -590,26 +587,6 @@ int RsServer::StartupRetroShare(RsInit *config)
pqih = new pqisslpersongrp(none, flags); pqih = new pqisslpersongrp(none, flags);
//pqih = new pqipersongrpDummy(none, flags); //pqih = new pqipersongrpDummy(none, flags);
#ifdef USE_OLD_FT
CacheStrapper *mCacheStrapper = new CacheStrapper(mAuthMgr, mConnMgr);
ftfiler *mCacheTransfer = new ftfiler(mCacheStrapper);
// 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);
server->setFileCallback(ownId, mCacheStrapper, mCacheTransfer, &(getNotify()));
server->setEmergencySaveDir(emergencySaveDir); /* (after setFileCallback()) if saveDir invalid */
/*
* *** TMP NEW INTERFACE FOR FILES - until ftServer comes online ***
*/
rsFiles = new p3Files(server, this, mAuthMgr);
#else
/****** New Ft Server **** !!! */ /****** New Ft Server **** !!! */
ftserver = new ftServer(mAuthMgr, mConnMgr); ftserver = new ftServer(mAuthMgr, mConnMgr);
ftserver->setP3Interface(pqih); ftserver->setP3Interface(pqih);
@ -625,9 +602,8 @@ int RsServer::StartupRetroShare(RsInit *config)
/* This should be set by config ... there is no default */ /* This should be set by config ... there is no default */
//ftserver->setSharedDirectories(fileList); //ftserver->setSharedDirectories(fileList);
rsFiles = ftserver; rsFiles = ftserver;
#endif
mConfigMgr = new p3ConfigMgr(mAuthMgr, config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn"); mConfigMgr = new p3ConfigMgr(mAuthMgr, config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn");
mGeneralConfig = new p3GeneralConfig(); mGeneralConfig = new p3GeneralConfig();
@ -647,6 +623,10 @@ int RsServer::StartupRetroShare(RsInit *config)
std::string remotecachedir = config_dir + "/cache/remote"; std::string remotecachedir = config_dir + "/cache/remote";
std::string channelsdir = config_dir + "/channels"; std::string channelsdir = config_dir + "/channels";
#ifndef RS_RELEASE
mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */ mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */
mCacheStrapper, mCacheTransfer, mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
@ -654,7 +634,8 @@ int RsServer::StartupRetroShare(RsInit *config)
CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0)); CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0));
mCacheStrapper -> addCachePair(cp); /* end of declaration */ mCacheStrapper -> addCachePair(cp); /* end of declaration */
#ifndef RS_RELEASE
p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr); p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr);
pqih -> addService(gameLauncher); pqih -> addService(gameLauncher);
@ -690,8 +671,21 @@ int RsServer::StartupRetroShare(RsInit *config)
pqih -> addService(mChannels); /* This must be also ticked as a service */ pqih -> addService(mChannels); /* This must be also ticked as a service */
#else #else
//mQblog = NULL; /* In the release - so we can test it seperately from
//mForums = NULL; * rest of services...
*/
p3Channels *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);
pqih -> addService(mChannels); /* This must be also ticked as a service */
mRanking = NULL;
mQblog = NULL;
#endif #endif
/**************************************************************************/ /**************************************************************************/
@ -710,27 +704,23 @@ int RsServer::StartupRetroShare(RsInit *config)
/* must also add the controller as a Monitor... /* must also add the controller as a Monitor...
* a little hack to get it to work. * a little hack to get it to work.
*/ */
#ifdef USE_OLD_FT
#else
mConnMgr->addMonitor(((ftController *) mCacheTransfer)); mConnMgr->addMonitor(((ftController *) mCacheTransfer));
#endif
/**************************************************************************/ /**************************************************************************/
#ifdef USE_OLD_FT
mConfigMgr->addConfiguration("server.cfg", server);
#else
//mConfigMgr->addConfiguration("ftserver.cfg", ftserver); //mConfigMgr->addConfiguration("ftserver.cfg", ftserver);
#endif //
mConfigMgr->addConfiguration("peers.cfg", mConnMgr); mConfigMgr->addConfiguration("peers.cfg", mConnMgr);
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig); mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
mConfigMgr->addConfiguration("msgs.cfg", msgSrv); mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper); mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
#ifndef RS_RELEASE #ifndef RS_RELEASE
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
mConfigMgr->addConfiguration("forums.cfg", mForums); mConfigMgr->addConfiguration("forums.cfg", mForums);
mConfigMgr->addConfiguration("channels.cfg", mChannels); mConfigMgr->addConfiguration("channels.cfg", mChannels);
#else
mConfigMgr->addConfiguration("channels.cfg", mChannels);
#endif #endif
/**************************************************************************/ /**************************************************************************/
@ -845,11 +835,8 @@ int RsServer::StartupRetroShare(RsInit *config)
/* Start up Threads */ /* Start up Threads */
/**************************************************************************/ /**************************************************************************/
#ifdef USE_OLD_FT
server->StartupMonitor();
#else
ftserver->StartupThreads(); ftserver->StartupThreads();
#endif
mDhtMgr->start(); mDhtMgr->start();
// create loopback device, and add to pqisslgrp. // create loopback device, and add to pqisslgrp.
@ -868,7 +855,6 @@ int RsServer::StartupRetroShare(RsInit *config)
rsPeers = new p3Peers(mConnMgr, mAuthMgr); rsPeers = new p3Peers(mConnMgr, mAuthMgr);
rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv); rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv);
rsDisc = new p3Discovery(ad); rsDisc = new p3Discovery(ad);
rsRanks = new p3Rank(mRanking);
#ifndef RS_RELEASE #ifndef RS_RELEASE
@ -878,14 +864,17 @@ int RsServer::StartupRetroShare(RsInit *config)
rsChannels = mChannels; rsChannels = mChannels;
rsStatus = new p3Status(); rsStatus = new p3Status();
rsQblog = new p3Blog(mQblog); rsQblog = new p3Blog(mQblog);
rsRanks = new p3Rank(mRanking);
#else #else
rsGameLauncher = NULL; rsGameLauncher = NULL;
rsPhoto = NULL; rsPhoto = NULL;
rsForums = NULL; rsForums = NULL;
rsChannels = NULL; rsChannels = NULL;
rsChannels = mChannels;
rsStatus = NULL; rsStatus = NULL;
rsQblog = NULL; rsQblog = NULL;
rsRanks = NULL;
#endif #endif

View File

@ -284,20 +284,6 @@ bool p3Channels::channelSubscribe(std::string cId, bool subscribe)
std::cerr << cId; std::cerr << cId;
std::cerr << std::endl; std::cerr << std::endl;
if (subscribe)
{
std::string channeldir = mChannelsDir + "/" + cId;
/* create chanDir */
if (!RsDirUtil::checkCreateDirectory(channeldir))
{
std::cerr << "p3Channels::channelSubscribe()";
std::cerr << " Failed to create Channels Directory: ";
std::cerr << channeldir;
std::cerr << std::endl;
}
}
return subscribeToGroup(cId, subscribe); return subscribeToGroup(cId, subscribe);
} }
@ -316,6 +302,7 @@ bool p3Channels::locked_eventUpdateGroup(GroupInfo *info, bool isNew)
std::cerr << "p3Channels::locked_eventUpdateGroup() "; std::cerr << "p3Channels::locked_eventUpdateGroup() ";
std::cerr << grpId; std::cerr << grpId;
std::cerr << " flags:" << info->flags;
std::cerr << std::endl; std::cerr << std::endl;
if (isNew) if (isNew)
@ -328,6 +315,7 @@ bool p3Channels::locked_eventUpdateGroup(GroupInfo *info, bool isNew)
} }
if (info->flags & RS_DISTRIB_SUBSCRIBED) if (info->flags & RS_DISTRIB_SUBSCRIBED)
// || (info->flags & RS_DISTRIB_SUBSCRIBED))
{ {
std::string channeldir = mChannelsDir + "/" + grpId; std::string channeldir = mChannelsDir + "/" + grpId;
@ -458,6 +446,34 @@ bool p3Channels::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::stri
} }
void p3Channels::locked_notifyGroupChanged(GroupInfo &grp)
{
/* create directory if needed */
if (grp.flags & RS_DISTRIB_SUBSCRIBED)
{
std::string channeldir = mChannelsDir + "/" + grp.grpId;
/* create chanDir */
if (!RsDirUtil::checkCreateDirectory(channeldir))
{
std::cerr << "p3Channels::channelSubscribe()";
std::cerr << " Failed to create Channels Directory: ";
std::cerr << channeldir;
std::cerr << std::endl;
}
else
{
std::cerr << "p3Channels::channelSubscribe()";
std::cerr << " Created: ";
std::cerr << channeldir;
std::cerr << std::endl;
}
}
return p3GroupDistrib::locked_notifyGroupChanged(grp);
}
/****************************************/ /****************************************/

View File

@ -62,10 +62,12 @@ virtual bool channelSubscribe(std::string cId, bool subscribe);
/****************** Event Feedback (Overloaded form p3distrib) *************************/ /****************** Event Feedback (Overloaded form p3distrib) *************************/
/***************************************************************************************/ /***************************************************************************************/
protected:
virtual bool locked_eventUpdateGroup(GroupInfo *, bool isNew); virtual bool locked_eventUpdateGroup(GroupInfo *, bool isNew);
virtual bool locked_eventNewMsg(GroupInfo *, RsDistribMsg *, std::string); virtual bool locked_eventNewMsg(GroupInfo *, RsDistribMsg *, std::string);
virtual bool locked_eventDuplicateMsg(GroupInfo *, RsDistribMsg *, std::string); virtual bool locked_eventDuplicateMsg(GroupInfo *, RsDistribMsg *, std::string);
/****************************************/ /****************************************/
/********* Overloaded Functions *********/ /********* Overloaded Functions *********/
@ -75,6 +77,7 @@ virtual bool locked_checkDistribMsg(RsDistribMsg *msg);
virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info); virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info);
virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info); virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info);
virtual void locked_notifyGroupChanged(GroupInfo &info);
/****************************************/ /****************************************/

View File

@ -1299,16 +1299,7 @@ bool p3GroupDistrib::loadList(std::list<RsItem *> load)
std::string gid = newGrp -> grpId; std::string gid = newGrp -> grpId;
loadGroup(newGrp); loadGroup(newGrp);
/* flag as SUBSCRIBER */ subscribeToGroup(gid, true);
RsStackMutex stack(distribMtx); /******* STACK LOCKED MUTEX ***********/
std::map<std::string, GroupInfo>::iterator it;
it = mGroups.find(gid);
if (it != mGroups.end())
{
it->second.flags |= RS_DISTRIB_SUBSCRIBED;
}
} }
else if ((newKey = dynamic_cast<RsDistribGrpKey *>(*lit))) else if ((newKey = dynamic_cast<RsDistribGrpKey *>(*lit)))
{ {

View File

@ -347,6 +347,10 @@ virtual bool locked_choosePublishKey(GroupInfo &info);
//virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info); //virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info);
//virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info); //virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info);
protected:
/* root version of this function must be called */
virtual void locked_notifyGroupChanged(GroupInfo &info);
/***************************************************************************************/ /***************************************************************************************/
/***************************** Utility Functions ***************************************/ /***************************** Utility Functions ***************************************/
/***************************************************************************************/ /***************************************************************************************/
@ -366,10 +370,6 @@ void printGroups(std::ostream &out);
bool groupsChanged(std::list<std::string> &groupIds); bool groupsChanged(std::list<std::string> &groupIds);
protected:
void locked_notifyGroupChanged(GroupInfo &info);
/***************************************************************************************/ /***************************************************************************************/
/***************************************************************************************/ /***************************************************************************************/