Merged branch commits:

3068: added verification for file size computation (bug correction)

3069: set heartbeat values to intermediate values

3070: suppressed uninitialised memory read

3071: automatic removal of file lists from deleted peers, at restart (After
      double check that this does not alter exchange of file lists in any way)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3072 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-06-05 19:16:39 +00:00
parent 0470477bcc
commit 7b0757c4bc
9 changed files with 73 additions and 39 deletions

View file

@ -24,11 +24,12 @@
#include "dbase/fistore.h" #include "dbase/fistore.h"
#include "rsiface/rsexpr.h" #include "rsiface/rsexpr.h"
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
#include "pqi/p3connmgr.h"
FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft,
NotifyBase *cb_in, RsPeerId ownid, std::string cachedir) NotifyBase *cb_in,p3ConnectMgr *cnmgr, RsPeerId ownid, std::string cachedir)
:CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir), :CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir),
localId(ownid), localindex(NULL), cb(cb_in) localId(ownid), localindex(NULL), cb(cb_in),mConnMgr(cnmgr)
{ {
return; return;
} }
@ -79,47 +80,60 @@ int FileIndexStore::loadCache(const CacheData &data)
} }
/* load Cache */ /* load Cache */
FileIndex *finew = new FileIndex(data.pid); FileIndex *finew = new FileIndex(data.pid);
if (finew->loadIndex(data.path + '/' + data.name, data.hash, data.size)) if(mConnMgr->isFriend(data.pid))
{ {
// We discard file lists from non friends. This is the place to remove file lists of deleted friends
// from the cache. Doing this, the file list still shows in a session where we deleted a friend, but will be removed
// at next restart.
//
if (finew->loadIndex(data.path + '/' + data.name, data.hash, data.size))
{
#ifdef FIS_DEBUG2 #ifdef FIS_DEBUG2
std::cerr << "FileIndexStore::loadCache() Succeeded!" << std::endl; std::cerr << "FileIndexStore::loadCache() Succeeded!" << std::endl;
#endif #endif
/* set the name */ /* set the name */
finew->root->name = data.pname; finew->root->name = data.pname;
if (local)
{
localindex = finew;
}
else
{
indices[data.pid] = finew;
}
delete fiold;
/* store in tale */
locked_storeCacheEntry(data);
}
else
{
#ifdef FIS_DEBUG2
std::cerr << "FileIndexStore::loadCache() Failed!" << std::endl;
#endif
/* reinstall the old one! */
delete finew;
if (fiold)
{
if (local) if (local)
{ {
localindex = fiold; localindex = finew;
} }
else else
{ {
indices[data.pid] = fiold; indices[data.pid] = finew;
}
delete fiold;
/* store in tale */
locked_storeCacheEntry(data);
}
else
{
#ifdef FIS_DEBUG2
std::cerr << "FileIndexStore::loadCache() Failed!" << std::endl;
#endif
/* reinstall the old one! */
delete finew;
if (fiold)
{
if (local)
{
localindex = fiold;
}
else
{
indices[data.pid] = fiold;
}
} }
} }
} }
#ifdef FIS_DEBUG
else
std::cerr << "Discarding file list from deleted peer " << data.pid << std::endl ;
#endif
/* need to correct indices(row) for the roots of the FileIndex */ /* need to correct indices(row) for the roots of the FileIndex */
int i = 0; int i = 0;

View file

@ -34,6 +34,8 @@
* *
*/ */
class p3ConnectMgr ;
#include "dbase/findex.h" #include "dbase/findex.h"
#include "dbase/cachestrapper.h" #include "dbase/cachestrapper.h"
#include "rsiface/rsiface.h" #include "rsiface/rsiface.h"
@ -63,8 +65,7 @@ class FileIndexStore: public CacheStore
{ {
public: public:
FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in, FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,p3ConnectMgr *cmgr, RsPeerId ownid, std::string cachedir);
RsPeerId ownid, std::string cachedir);
virtual ~FileIndexStore(); virtual ~FileIndexStore();
/* virtual functions overloaded by cache implementor */ /* virtual functions overloaded by cache implementor */
@ -94,6 +95,7 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa
FileIndex *localindex; FileIndex *localindex;
NotifyBase *cb; NotifyBase *cb;
p3ConnectMgr *mConnMgr ;
}; };

View file

@ -30,9 +30,9 @@
//#define DB_DEBUG 1 //#define DB_DEBUG 1
ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in, ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,p3ConnectMgr *cnmgr,
RsPeerId ownid, std::string cachedir) RsPeerId ownid, std::string cachedir)
:FileIndexStore(cs, cft, cb_in, ownid, cachedir) :FileIndexStore(cs, cft, cb_in,cnmgr, ownid, cachedir)
{ {
return; return;
} }

View file

@ -33,6 +33,8 @@
* So they work in the ft world. * So they work in the ft world.
*/ */
class p3ConnectMgr ;
#include "ft/ftsearch.h" #include "ft/ftsearch.h"
#include "pqi/p3cfgmgr.h" #include "pqi/p3cfgmgr.h"
@ -45,6 +47,7 @@ class ftFiStore: public FileIndexStore, public ftSearch
{ {
public: public:
ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in, ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
p3ConnectMgr *,
RsPeerId ownid, std::string cachedir); RsPeerId ownid, std::string cachedir);
/* overloaded search function */ /* overloaded search function */

View file

@ -135,7 +135,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
/* Make Cache Source/Store */ /* Make Cache Source/Store */
mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb, ownId, remotecachedir); mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb,mConnMgr, ownId, remotecachedir);
mFiMon = new ftFiMonitor(mCacheStrapper,cb, localcachedir, ownId); mFiMon = new ftFiMonitor(mCacheStrapper,cb, localcachedir, ownId);
/* now add the set to the cachestrapper */ /* now add the set to the cachestrapper */

View file

@ -724,12 +724,22 @@ bool p3Config::backedUpFileSave(const std::string& cfg_fname, const std::string&
cfg_file = fopen(cfg_fname.c_str(), "wb"); cfg_file = fopen(cfg_fname.c_str(), "wb");
if(cfg_file == NULL) if(cfg_file == NULL)
{
std::cerr << "p3Config::backedUpFileSave() fopen failed for file:" << cfg_fname << std::endl; std::cerr << "p3Config::backedUpFileSave() fopen failed for file:" << cfg_fname << std::endl;
return false ;
}
} }
//determine file size //determine file size
fseek(cfg_file, 0L, SEEK_END); fseek(cfg_file, 0L, SEEK_END);
size_file = ftell(cfg_file); size_file = ftell(cfg_file);
if(size_file < 0) // ftell returns -1 when fails
{
fclose(cfg_file);
size_file = 0 ;
}
fseek(cfg_file, 0L, SEEK_SET); fseek(cfg_file, 0L, SEEK_SET);
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG

View file

@ -115,7 +115,7 @@ int pqiperson::tick()
//if lastHeartbeatReceived is 0, it might be not activated so don't do a net reset. //if lastHeartbeatReceived is 0, it might be not activated so don't do a net reset.
if (active && if (active &&
lastHeartbeatReceived != 0 && lastHeartbeatReceived != 0 &&
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 10) { (time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5) {
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::tick() No heartbeat from the peer, assume connection is dead."); pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::tick() No heartbeat from the peer, assume connection is dead.");
this->reset(); this->reset();
} }

View file

@ -41,7 +41,7 @@ static const int CONNECT_UNREACHABLE = 3;
static const int CONNECT_FIREWALLED = 4; static const int CONNECT_FIREWALLED = 4;
static const int CONNECT_FAILED = 5; static const int CONNECT_FAILED = 5;
static const int HEARTBEAT_REPEAT_TIME = 10; static const int HEARTBEAT_REPEAT_TIME = 5;
#include "pqi/pqistreamer.h" #include "pqi/pqistreamer.h"

View file

@ -1137,10 +1137,15 @@ int ensureExtension(std::string &name, std::string def_ext)
RsPeerDetails::RsPeerDetails() RsPeerDetails::RsPeerDetails()
:trustLvl(0), ownsign(false), state(0), netMode(0), :isOnlyGPGdetail(false),
lastConnect(0), connectPeriod(0) id(""),gpg_id(""),
name(""),email(""),location(""),
org(""),issuer(""),fpr(""),authcode(""),
trustLvl(0), validLvl(0),ownsign(false),
hasSignedMe(false),accept_connection(false),
state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),visState(0),
lastConnect(0),autoconnect(""),connectPeriod(0)
{ {
return;
} }
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail) std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail)