merge of branch v0.6-idclean 7180

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7187 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2014-03-17 20:56:06 +00:00
parent 7815efb16f
commit 0f29d28b1b
397 changed files with 6503 additions and 5702 deletions

View file

@ -92,7 +92,7 @@ bool CacheSource::loadLocalCache(const RsCacheData &data)
}
/* control Caches available */
bool CacheSource::refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers)
bool CacheSource::refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers)
{
bool ret = false;
{
@ -122,9 +122,9 @@ bool CacheSource::refreshCache(const RsCacheData &data,const std::set<std::strin
if (mStrapper) /* allow testing without full feedback */
{
std::set<std::string> allowed_dest_peers ;
std::set<RsPeerId> allowed_dest_peers ;
for(std::set<std::string>::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it)
for(std::set<RsPeerId>::const_iterator it(destination_peers.begin());it!=destination_peers.end();++it)
if(isPeerAcceptedAsCacheReceiver(*it))
allowed_dest_peers.insert(*it) ;
@ -161,14 +161,14 @@ bool CacheSource::refreshCache(const RsCacheData &data)
}
// Strip down destination peers to eliminate peers that are not allowed to receive cache items.
std::list<std::string> ids;
std::list<RsPeerId> ids;
rsPeers->getOnlineList(ids);
if (mStrapper) /* allow testing without full feedback */
{
std::set<std::string> allowed_dest_peers ;
std::set<RsPeerId> allowed_dest_peers ;
for(std::list<std::string>::const_iterator it(ids.begin());it!=ids.end();++it)
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
if(isPeerAcceptedAsCacheReceiver(*it))
allowed_dest_peers.insert(*it) ;
@ -232,7 +232,7 @@ bool CacheSource::clearCache(CacheId id)
return ret;
}
bool CacheSource::cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData> &ids)
bool CacheSource::cachesAvailable(const RsPeerId& pid, std::map<CacheId, RsCacheData> &ids)
{
if(!isPeerAcceptedAsCacheReceiver(pid))
return false ;
@ -253,7 +253,7 @@ bool CacheSource::cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData
}
bool CacheSource::findCache(std::string hash, RsCacheData &data) const
bool CacheSource::findCache(const RsFileHash &hash, RsCacheData &data) const
{
lockData(); /* LOCK MUTEX */
@ -271,7 +271,7 @@ bool CacheSource::findCache(std::string hash, RsCacheData &data) const
if (!found)
{
std::map<std::string, RsCacheData>::const_iterator oit;
std::map<RsFileHash, RsCacheData>::const_iterator oit;
oit = mOldCaches.find(hash);
if (oit != mOldCaches.end())
{
@ -336,7 +336,7 @@ void CacheStore::listCaches(std::ostream &out)
lockData(); /* LOCK MUTEX */
/* can overwrite for more control! */
std::map<RsPeerId, CacheSet>::iterator pit;
std::map<RsPeerId, CacheSet>::iterator pit;
out << "CacheStore::listCaches() [" << getCacheType();
out << "] Total People: " << caches.size();
out << std::endl;
@ -377,7 +377,7 @@ bool CacheStore::locked_getStoredCache(RsCacheData &data)
return false;
}
std::map<RsPeerId, CacheSet>::iterator pit;
std::map<RsPeerId, CacheSet>::iterator pit;
if (caches.end() == (pit = caches.find(data.pid)))
{
return false;
@ -414,7 +414,7 @@ bool CacheStore::getAllStoredCaches(std::list<RsCacheData> &data)
{
lockData(); /* LOCK MUTEX */
std::map<RsPeerId, CacheSet>::iterator pit;
std::map<RsPeerId, CacheSet>::iterator pit;
for(pit = caches.begin(); pit != caches.end(); pit++)
{
CacheSet::iterator cit;
@ -547,7 +547,7 @@ int CacheStore::nameCache(RsCacheData &data)
std::cerr << "CacheStore::nameCache() for:" << data << std::endl;
#endif
data.name = data.hash;
data.name = data.hash.toStdString();
data.path = getCacheDir();
#ifdef CS_DEBUG
@ -585,7 +585,7 @@ int CacheStore::loadCache(const RsCacheData &data)
void CacheStore::locked_storeCacheEntry(const RsCacheData &data)
{
/* store what we loaded - overwriting if necessary */
std::map<RsPeerId, CacheSet>::iterator pit;
std::map<RsPeerId, CacheSet>::iterator pit;
if (caches.end() == (pit = caches.find(data.pid)))
{
/* add in a new CacheSet */
@ -658,7 +658,7 @@ void CacheStrapper::statusChange(const std::list<pqipeer> &plist)
/**************** from pqimonclient ********************/
void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers)
void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers)
{
/* we've received an update
* send to all online peers + self intersected with online peers.
@ -666,13 +666,13 @@ void CacheStrapper::refreshCache(const RsCacheData &data,const std::set<std::str
#ifdef CS_DEBUG
std::cerr << "CacheStrapper::refreshCache() : " << data << std::endl;
#endif
std::string ownid = mLinkMgr->getOwnId() ;
std::list<std::string> ids;
const RsPeerId& ownid = mLinkMgr->getOwnId() ;
std::list<RsPeerId> ids;
mLinkMgr->getOnlineList(ids);
ids.push_back(ownid) ;
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
for(std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
for(std::list<RsPeerId>::const_iterator it = ids.begin(); it != ids.end(); ++it)
if(destination_peers.find(*it) != destination_peers.end())
{
#ifdef CS_DEBUG
@ -741,28 +741,7 @@ void CacheStrapper::recvCacheResponse(RsCacheData &data, time_t /* ts */)
}
/* generate periodically or at a change */
#if 0
bool CacheStrapper::sendCacheQuery(std::list<RsPeerId> &id, time_t ts)
{
/* iterate through peers, and see who we haven't got an answer from recently */
std::map<RsPeerId, CacheTS>::iterator it;
for(it = status.begin(); it != status.end(); it++)
{
if ((ts - (it->second).query) > queryPeriod)
{
/* query this one */
id.push_back(it->first);
(it->second).query = ts;
}
}
return (id.size() > 0);
}
#endif
void CacheStrapper::handleCacheQuery(RsPeerId id, std::map<CacheId,RsCacheData> &hashs)
void CacheStrapper::handleCacheQuery(const RsPeerId& id, std::map<CacheId,RsCacheData> &hashs)
{
/* basic version just iterates through ....
* more complex could decide who gets what!
@ -816,7 +795,7 @@ void CacheStrapper::listPeerStatus(std::ostream & /* out */)
}
bool CacheStrapper::findCache(std::string hash, RsCacheData &data) const
bool CacheStrapper::findCache(const RsFileHash& hash, RsCacheData &data) const
{
/* can overwrite for more control! */
std::map<uint16_t, CachePair>::const_iterator it;
@ -875,7 +854,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
std::list<RsCacheData>::iterator cit;
std::list<RsCacheData> ownCaches;
std::list<RsCacheData> remoteCaches;
std::string ownId = mLinkMgr->getOwnId();
const RsPeerId& ownId = mLinkMgr->getOwnId();
std::map<uint16_t, CachePair>::iterator it;
for(it = caches.begin(); it != caches.end(); it++)
@ -899,7 +878,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
// Fixup lazy behaviour in clients...
// This ensures correct loading later.
// (used to be: rscc->pid = cit->pid;)
rscc->pid = ownId;
rscc->pid = ownId.toStdString();
//rscc->pname = cit->pname;
rscc->cachetypeid = cit->cid.type;
@ -926,7 +905,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
RsCacheConfig *rscc = new RsCacheConfig();
rscc->pid = cit->pid;
rscc->pid = cit->pid.toStdString();
//rscc->pname = cit->pname;
rscc->cachetypeid = cit->cid.type;
rscc->cachesubid = cit->cid.subid;
@ -955,7 +934,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
#endif
std::list<RsCacheData> ownCaches;
std::list<RsCacheData> remoteCaches;
std::string ownId = mLinkMgr->getOwnId();
const RsPeerId& ownId = mLinkMgr->getOwnId();
//peerConnectState ownState;
//mPeerMgr->getOwnNetStatus(ownState);
@ -977,7 +956,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
#endif
RsCacheData cd;
cd.pid = rscc->pid;
cd.pid = RsPeerId(rscc->pid) ;
#if 0
if(cd.pid == ownId)
@ -1073,7 +1052,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
std::list<std::string> cacheDirs;
std::list<std::string>::iterator dit;
#ifdef CS_DEBUG
std::list<std::string>::iterator fit;
std::set<std::string>::iterator fit;
#endif
std::map<uint16_t, CachePair>::iterator cit;
for(cit = caches.begin(); cit != caches.end(); cit++)
@ -1113,7 +1092,8 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
#ifdef CS_DEBUG
std::cerr << "CacheStrapper::loadList() Cleaning cache dir: <" << *dit << ">" << std::endl;
#endif
sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit));
sit = saveFiles.find(RsDirUtil::convertPathToUnix(*dit));
if (sit != saveFiles.end())
{
#ifdef CS_DEBUG
@ -1153,8 +1133,8 @@ bool CacheTransfer::RequestCache(RsCacheData &data, CacheStore *cbStore)
* - if duplicate hash -> Fail Transfer
*/
std::map<std::string, RsCacheData>::iterator dit;
std::map<std::string, CacheStore *>::iterator sit;
std::map<RsFileHash, RsCacheData>::iterator dit;
std::map<RsFileHash, CacheStore *>::iterator sit;
for(dit = cbData.begin(); dit != cbData.end(); dit++)
{
@ -1219,7 +1199,7 @@ bool CacheTransfer::RequestCache(RsCacheData &data, CacheStore *cbStore)
/* to be overloaded */
bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
bool CacheTransfer::RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size)
{
(void) id;
(void) path;
@ -1233,12 +1213,12 @@ bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string
#endif
/* just tell them we've completed! */
CompletedCache(hash);
CompletedCache(hash);
return true;
}
/* to be overloaded */
bool CacheTransfer::CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
bool CacheTransfer::CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash &hash, uint64_t size)
{
(void) id;
(void) path;
@ -1257,10 +1237,10 @@ bool CacheTransfer::CancelCacheFile(RsPeerId id, std::string path, std::string h
/* internal completion -> does cb */
bool CacheTransfer::CompletedCache(std::string hash)
bool CacheTransfer::CompletedCache(const RsFileHash& hash)
{
std::map<std::string, RsCacheData>::iterator dit;
std::map<std::string, CacheStore *>::iterator sit;
std::map<RsFileHash, RsCacheData>::iterator dit;
std::map<RsFileHash, CacheStore *>::iterator sit;
#ifdef CS_DEBUG
std::cerr << "CacheTransfer::CompletedCache(" << hash << ")";
@ -1296,13 +1276,13 @@ bool CacheTransfer::CompletedCache(std::string hash)
}
/* internal completion -> does cb */
bool CacheTransfer::FailedCache(std::string hash)
bool CacheTransfer::FailedCache(const RsFileHash& hash)
{
std::map<std::string, RsCacheData>::iterator dit;
std::map<std::string, CacheStore *>::iterator sit;
std::map<RsFileHash, RsCacheData>::iterator dit;
std::map<RsFileHash, CacheStore *>::iterator sit;
/* find in store.... */
sit = cbStores.find(hash);
sit = cbStores.find(hash);
dit = cbData.find(hash);
if ((sit == cbStores.end()) || (dit == cbData.end()))
@ -1321,7 +1301,7 @@ bool CacheTransfer::FailedCache(std::string hash)
}
bool CacheTransfer::FindCacheFile(std::string hash, std::string &path, uint64_t &size)
bool CacheTransfer::FindCacheFile(const RsFileHash &hash, std::string &path, uint64_t &size)
{
RsCacheData data;
if (strapper->findCache(hash, data))

View file

@ -60,11 +60,6 @@ class CacheSource; /* Interface for local File Index/Monitor */
class CacheStore; /* Interface for the actual Cache */
class CacheStrapper; /* Controlling Class */
/****
typedef uint32_t RsPeerId;
*****/
typedef std::string RsPeerId;
/******************************** CacheId ********************************/
/*!
@ -91,12 +86,12 @@ class RsCacheData
{
public:
RsPeerId pid; /// peer id
RsPeerId pid; /// peer id
/// REMOVED as a WASTE to look it up everywhere! std::string pname; /// peer name (can be used by cachestore)
CacheId cid; /// cache id
std::string path; /// file system path where physical cache data is located
std::string name;
std::string hash;
RsFileHash hash;
uint64_t size;
time_t recvd; /// received timestamp
};
@ -119,7 +114,7 @@ class CacheTransfer
/*!
* upload side of things .... searches through CacheStrapper.
*/
bool FindCacheFile(std::string hash, std::string &path, uint64_t &size);
bool FindCacheFile(const RsFileHash& hash, std::string &path, uint64_t &size);
/*!
* At the download side RequestCache() => overloaded RequestCacheFile()
@ -132,18 +127,18 @@ class CacheTransfer
/*!
* to be overloaded
*/
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
virtual bool RequestCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
virtual bool CancelCacheFile(const RsPeerId& id, std::string path, const RsFileHash& hash, uint64_t size);
bool CompletedCache(std::string hash); /* internal completion -> does cb */
bool FailedCache(std::string hash); /* internal completion -> does cb */
bool CompletedCache(const RsFileHash &hash); /* internal completion -> does cb */
bool FailedCache(const RsFileHash &hash); /* internal completion -> does cb */
private:
CacheStrapper *strapper;
std::map<std::string, RsCacheData> cbData;
std::map<std::string, CacheStore *> cbStores;
std::map<RsFileHash, RsCacheData> cbData;
std::map<RsFileHash, CacheStore *> cbStores;
};
@ -172,7 +167,7 @@ class CacheSource
* called to determine available cache for peer -
* default acceptable (returns all)
*/
virtual bool cachesAvailable(RsPeerId pid, std::map<CacheId, RsCacheData> &ids);
virtual bool cachesAvailable(const RsPeerId& pid, std::map<CacheId, RsCacheData> &ids);
/*!
* function called at startup to load from
@ -182,12 +177,12 @@ class CacheSource
virtual bool loadLocalCache(const RsCacheData &data);
/* control Caches available */
bool refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers);
bool refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers);
bool refreshCache(const RsCacheData &data);
bool clearCache(CacheId id);
/* controls if peer is an accepted receiver for cache items. Default is yes. To be overloaded. */
virtual bool isPeerAcceptedAsCacheReceiver(const std::string& /*peer_id*/) { return true ; }
virtual bool isPeerAcceptedAsCacheReceiver(const RsPeerId& /*peer_id*/) { return true ; }
/* get private data */
std::string getCacheDir() { return cacheDir; }
@ -198,7 +193,7 @@ class CacheSource
void listCaches(std::ostream &out);
/* search */
bool findCache(std::string hash, RsCacheData &data) const;
bool findCache(const RsFileHash& hash, RsCacheData &data) const;
protected:
@ -211,7 +206,7 @@ class CacheSource
void unlockData() const;
CacheSet caches; /// all local cache data stored here
std::map<std::string, RsCacheData> mOldCaches; /// replaced/cleared caches are pushed here (in case requested)
std::map<RsFileHash, RsCacheData> mOldCaches; /// replaced/cleared caches are pushed here (in case requested)
private:
@ -276,7 +271,7 @@ class CacheStore
/* virtual functions overloaded by cache implementor */
/* controls if peer is an accepted provider for cache items. Default is yes. To be overloaded. */
virtual bool isPeerAcceptedAsCacheProvider(const std::string& /*peer_id*/) { return true ; }
virtual bool isPeerAcceptedAsCacheProvider(const RsPeerId& /*peer_id*/) { return true ; }
/*!
* @param data cache data is stored here
@ -334,7 +329,7 @@ class CacheStore
std::string cacheDir;
mutable RsMutex cMutex;
std::map<RsPeerId, CacheSet> caches;
std::map<RsPeerId, CacheSet> caches;
};
@ -407,7 +402,7 @@ virtual void statusChange(const std::list<pqipeer> &plist);
*
*/
void refreshCache(const RsCacheData &data);
void refreshCache(const RsCacheData &data,const std::set<std::string>& destination_peers); // specify a particular list of destination peers (self not added!)
void refreshCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers); // specify a particular list of destination peers (self not added!)
/*!
* forces config savelist
@ -429,14 +424,14 @@ void addCachePair(CachePair pair);
/*** I/O (2) ***/
void recvCacheResponse(RsCacheData &data, time_t ts);
void handleCacheQuery(RsPeerId id, std::map<CacheId, RsCacheData> &data);
void handleCacheQuery(const RsPeerId& id, std::map<CacheId, RsCacheData> &data);
/*!
* search through CacheSources.
* @return false if cachedate mapping to hash not found
*/
bool findCache(std::string hash, RsCacheData &data) const;
bool findCache(const RsFileHash &hash, RsCacheData &data) const;
/* display */
void listCaches(std::ostream &out);
@ -472,7 +467,7 @@ virtual bool loadList(std::list<RsItem *>& load);
RsMutex csMtx; /* protect below */
std::list<std::pair<RsPeerId, RsCacheData> > mCacheUpdates;
std::list<std::pair<RsPeerId, RsCacheData> > mCacheUpdates;
};

View file

@ -33,6 +33,7 @@
#include "retroshare/rsiface.h"
#include "pqi/p3notify.h"
#include "retroshare/rspeers.h"
#include "retroshare/rstypes.h"
#include "util/folderiterator.h"
#include <errno.h>
@ -52,7 +53,7 @@
//#define FIM_DEBUG 1
// ***********/
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid,const std::string& config_dir)
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const RsPeerId& pid,const std::string& config_dir)
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid),
pendingDirs(false), pendingForceCacheWrite(false),
mForceCheck(false), mInCheck(false), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true)
@ -142,12 +143,6 @@ HashCache::HashCache(const std::string& path)
f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.modf_stamp)),&info.modf_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; }
f.getline(buff,max_line_size,'\n') ; info.hash = std::string(buff) ;
if(info.hash.length() != 40)
{
std::cerr << "Loaded hash is not a hash: " << info.hash << std::endl;
break ;
}
#ifdef FIM_DEBUG
std::cerr << " (" << name << ", " << info.size << ", " << info.time_stamp << ", " << info.modf_stamp << ", " << info.hash << std::endl ;
++n ;
@ -194,7 +189,7 @@ void HashCache::save()
#endif
}
bool HashCache::find(const std::string& full_path,uint64_t size,time_t time_stamp,std::string& hash)
bool HashCache::find(const std::string& full_path,uint64_t size,time_t time_stamp,RsFileHash& hash)
{
#ifdef FIM_DEBUG
std::cerr << "HashCache: looking for " << full_path << std::endl ;
@ -219,7 +214,7 @@ bool HashCache::find(const std::string& full_path,uint64_t size,time_t time_stam
return false ;
}
}
void HashCache::insert(const std::string& full_path,uint64_t size,time_t time_stamp,const std::string& hash)
void HashCache::insert(const std::string& full_path,uint64_t size,time_t time_stamp,const RsFileHash& hash)
{
HashCacheInfo info ;
info.size = size ;
@ -271,7 +266,7 @@ FileIndexMonitor::~FileIndexMonitor()
/* Data cleanup - TODO */
}
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id)
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
{
results.clear();
std::list<FileEntry *> firesults;
@ -284,7 +279,7 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
return filterResults(firesults,results,flags,peer_id) ;
}
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const std::string& peer_id) const
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const
{
results.clear();
std::list<FileEntry *> firesults;
@ -297,7 +292,7 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& resu
return filterResults(firesults,results,flags,peer_id) ;
}
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const std::string& peer_id) const
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const
{
#ifdef DEBUG
if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0)
@ -313,13 +308,13 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags << ", peer=" << peer_id ;
#endif
if(!peer_id.empty())
if(!peer_id.isNull())
{
FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(peer_id,cdetails.flags,cdetails.parent_groups) ;
if (cdetails.type == DIR_TYPE_FILE && ( permission_flags & flags ))
{
cdetails.id = "Local";
cdetails.id.clear() ;
results.push_back(cdetails);
#ifdef FIM_DEBUG
std::cerr << ": kept" << std::endl ;
@ -337,7 +332,7 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
return !results.empty() ;
}
bool FileIndexMonitor::findLocalFile(std::string hash,FileSearchFlags hint_flags, const std::string& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const
bool FileIndexMonitor::findLocalFile(const RsFileHash& hash,FileSearchFlags hint_flags, const RsPeerId& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const
{
std::list<FileEntry *> results;
bool ok = false;
@ -361,12 +356,12 @@ bool FileIndexMonitor::findLocalFile(std::string hash,FileSearchFlags hint_flags
// turn share flags into hint flags
FileSearchFlags shflh = peer_id.empty()?(RS_FILE_HINTS_BROWSABLE|RS_FILE_HINTS_NETWORK_WIDE):rsPeers->computePeerPermissionFlags(peer_id,storage_flags,parent_groups) ;
FileSearchFlags shflh = peer_id.isNull()?(RS_FILE_HINTS_BROWSABLE|RS_FILE_HINTS_NETWORK_WIDE):rsPeers->computePeerPermissionFlags(peer_id,storage_flags,parent_groups) ;
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::findLocalFile: Filtering candidate " << fe->name << ", flags=" << storage_flags << ", hint_flags=" << hint_flags << ", peer_id = " << peer_id << std::endl ;
#endif
if(peer_id.empty() || (shflh & hint_flags))
if(peer_id.isNull() || (shflh & hint_flags))
{
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl;
@ -451,14 +446,14 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s
std::string name = data.name ;
if ((ok = fi.loadIndex(data.path + '/' + name, "", data.size)))
if ((ok = fi.loadIndex(data.path + '/' + name, RsFileHash(), data.size)))
{
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::loadCache() Success!";
std::cerr << std::endl;
#endif
fi.root->row = 0;
fi.root->name = data.pid; // XXX Hack here - TODO
fi.root->name = data.pid.toStdString(); // XXX Hack here - TODO
std::string fname_browsable = data.path + '/' + name ;
struct stat64 buf;
@ -516,7 +511,7 @@ bool FileIndexMonitor::loadLocalCache(const RsCacheData &data) /* called with s
return false;
}
bool FileIndexMonitor::updateCache(const RsCacheData &data,const std::set<std::string>& destination_peers) /* we call this one */
bool FileIndexMonitor::updateCache(const RsCacheData &data,const std::set<RsPeerId>& destination_peers) /* we call this one */
{
return refreshCache(data,destination_peers);
}
@ -1107,18 +1102,18 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
// To figure out which sets are different, we index them by the set of forbidden indexes from the directory list.
// This is probably a bit costly, but we can't suppose that the number of shared directories is bounded.
//
std::list<std::string> all_friend_ids ;
std::list<RsPeerId> all_friend_ids ;
rsPeers->getFriendList(all_friend_ids);
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::updateCycle(): got list of all friends." << std::endl ;
for(std::list<std::string>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
for(std::list<RsPeerId>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
std::cerr << " " << *it << std::endl;
#endif
std::map<std::set<std::string>, std::set<std::string> > peers_per_directory_combination ;
std::map<std::set<std::string>, std::set<RsPeerId> > peers_per_directory_combination ;
for(std::list<std::string>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
for(std::list<RsPeerId>::const_iterator it(all_friend_ids.begin());it!=all_friend_ids.end();++it)
{
#ifdef FIM_DEBUG
std::cerr << "About to save, with the following restrictions:" << std::endl ;
@ -1153,14 +1148,14 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
peers_per_directory_combination[forbidden_dirs].insert(*it) ;
}
std::string ownId = rsPeers->getOwnId() ;
RsPeerId ownId = rsPeers->getOwnId() ;
peers_per_directory_combination[std::set<std::string>()].insert(ownId) ; // add full configuration to self, i.e. no forbidden directories.
int n=0 ;
time_t now = time(NULL) ;
time_t mod_time = 0 ;
for(std::map<std::set<std::string>, std::set<std::string> >::const_iterator it(peers_per_directory_combination.begin());
for(std::map<std::set<std::string>, std::set<RsPeerId> >::const_iterator it(peers_per_directory_combination.begin());
it!=peers_per_directory_combination.end();++it,++n)
{
std::string tmpname_browsable;
@ -1176,14 +1171,14 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
std::cerr << "Sending file list: " << std::endl;
std::cerr << " filename : " << tmpname_browsable << std::endl;
std::cerr << " to peers : " << std::endl;
for(std::set<std::string>::const_iterator itt(it->second.begin());itt!= it->second.end();++itt)
for(std::set<RsPeerId>::const_iterator itt(it->second.begin());itt!= it->second.end();++itt)
std::cerr << " " << *itt << std::endl;
std::cerr << " forbidden : " << std::endl;
for(std::set<std::string>::const_iterator itt(it->first.begin());itt!= it->first.end();++itt)
std::cerr << " " << *itt << std::endl;
#endif
std::string hash ;
RsFileHash hash ;
uint64_t size ;
#ifdef FIM_DEBUG
@ -1210,7 +1205,7 @@ time_t FileIndexMonitor::locked_saveFileIndexes(bool update_cache)
data.size = size;
data.recvd = time(NULL);
for(std::set<std::string>::const_iterator ff(it->second.begin());ff!=it->second.end();++ff)
for(std::set<RsPeerId>::const_iterator ff(it->second.begin());ff!=it->second.end();++ff)
_cache_items_per_peer[*ff] = data ;
data.cid.subid = 0;
@ -1261,7 +1256,7 @@ bool FileIndexMonitor::cachesAvailable(RsPeerId pid,std::map<CacheId, RsCacheDat
//
ids.clear() ;
std::map<RsPeerId,RsCacheData>::const_iterator it(_cache_items_per_peer.find(pid)) ;
std::string ownId = rsPeers->getOwnId() ;
RsPeerId ownId = rsPeers->getOwnId();
if(it != _cache_items_per_peer.end())
{
@ -1591,7 +1586,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, FileSear
details.ref = NULL;
details.type = DIR_TYPE_ROOT;
details.name = "root";
details.hash = "";
details.hash.clear() ;
details.path = "root";
details.age = 0;
details.flags.clear() ;

View file

@ -76,8 +76,8 @@ class HashCache
HashCache(const std::string& save_file_name) ;
void save() ;
void insert(const std::string& full_path,uint64_t size,time_t time_stamp,const std::string& hash) ;
bool find(const std::string& full_path,uint64_t size,time_t time_stamp,std::string& hash) ;
void insert(const std::string& full_path,uint64_t size,time_t time_stamp,const RsFileHash& hash) ;
bool find(const std::string& full_path,uint64_t size,time_t time_stamp,RsFileHash& hash) ;
void clean() ;
typedef struct
@ -85,7 +85,7 @@ class HashCache
uint64_t size ;
uint64_t time_stamp ;
uint64_t modf_stamp ;
std::string hash ;
RsFileHash hash ;
} HashCacheInfo ;
void setRememberHashFilesDuration(uint32_t days) { _max_cache_duration_days = days ; }
@ -94,7 +94,7 @@ class HashCache
bool empty() const { return _files.empty() ; }
private:
uint32_t _max_cache_duration_days ; // maximum duration of un-requested cache entries
std::map<std::string, HashCacheInfo> _files ;
std::map<std::string, HashCacheInfo> _files ;
std::string _path ;
bool _changed ;
};
@ -106,16 +106,16 @@ class HashCache
class FileIndexMonitor: public CacheSource, public RsThread
{
public:
FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid, const std::string& config_dir);
FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const RsPeerId& pid, const std::string& config_dir);
virtual ~FileIndexMonitor();
/* external interface for filetransfer */
bool findLocalFile(std::string hash,FileSearchFlags flags,const std::string& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const;
bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const;
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) ;
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) const ;
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) ;
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const std::string& peer_id) const ;
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
/* external interface for local access to files */
@ -125,7 +125,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
/* Interacting with CacheSource */
/* overloaded from CacheSource */
virtual bool loadLocalCache(const RsCacheData &data); /* called with stored data */
bool updateCache(const RsCacheData &data,const std::set<std::string>& dest_peers); /* we call when we have a new cache for others */
bool updateCache(const RsCacheData &data,const std::set<RsPeerId>& dest_peers); /* we call when we have a new cache for others */
/* the FileIndexMonitor inner workings */

View file

@ -500,7 +500,7 @@ int FileEntry::print(std::string &out)
else
out += "[MISSING PARENT]";
rs_sprintf_append(out, " %s [ s: %lld ] ==> [ %s ]\n", name.c_str(), size, hash.c_str());
rs_sprintf_append(out, " %s [ s: %lld ] ==> [ %s ]\n", name.c_str(), size, hash.toStdString().c_str());
return 1;
}
@ -524,7 +524,7 @@ int DirEntry::print(std::string &out)
return 1;
}
FileIndex::FileIndex(const std::string& pid)
FileIndex::FileIndex(const RsPeerId& pid)
{
root = new PersonEntry(pid);
registerEntry(root) ;
@ -754,7 +754,7 @@ int FileIndex::printFileIndex(std::string &out)
return 1;
}
int FileIndex::loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size)
int FileIndex::loadIndex(const std::string& filename, const RsFileHash& expectedHash, uint64_t size)
{
FILE *file = RsDirUtil::rs_fopen(filename.c_str(),"rb") ;
@ -783,7 +783,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
}
fclose(file) ;
std::string tmpout = RsDirUtil::sha1sum((unsigned char *)(compressed_data),size).toStdString() ;
RsFileHash tmpout = RsDirUtil::sha1sum((unsigned char *)(compressed_data),size);
// /* calculate hash */
// unsigned char sha_buf[SHA_DIGEST_LENGTH];
@ -799,7 +799,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
// rs_sprintf_append(tmpout, "%02x", (unsigned int) (sha_buf[i]));
// }
if (expectedHash != "" && expectedHash != tmpout)
if (!expectedHash.isNull() && expectedHash != tmpout)
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::loadIndex expected hash does not match" << std::endl;
@ -821,6 +821,11 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
}
std::string s((char *)uncompressed_data,uncompressed_data_size) ;
std::cerr << " file = " << filename << std::endl;
std::cerr << " uncompressed size = " << uncompressed_data_size << std::endl;
std::cerr << " compressed size = " << size << std::endl;
std::cerr << " hash = " << tmpout << std::endl;
delete[] compressed_data ;
free(uncompressed_data) ;
@ -857,7 +862,7 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte
/* finished parse, last dir is root */
case 1:
{
std::string pid = root -> id;
RsPeerId pid = root -> id;
FileIndex::unregisterEntry((void*)root) ;
delete root; /* to clean up old entries */
root = new PersonEntry(pid);
@ -991,9 +996,8 @@ error:
}
int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uint64_t &size,const std::set<std::string>& forbidden_dirs)
int FileIndex::saveIndex(const std::string& filename, RsFileHash &fileHash, uint64_t &size,const std::set<std::string>& forbidden_dirs)
{
unsigned char sha_buf[SHA_DIGEST_LENGTH];
std::string filenametmp = filename + ".tmp" ;
std::string s;
@ -1049,6 +1053,7 @@ int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uin
fileHash = RsDirUtil::sha1sum((unsigned char *)compressed_data,compressed_data_size).toStdString() ;
std::cerr << " file = " << filename << std::endl;
std::cerr << " old size = " << s.length() << std::endl;
std::cerr << " new size = " << compressed_data_size << std::endl;
std::cerr << " hash = " << fileHash << std::endl;
@ -1138,7 +1143,7 @@ void DirEntry::writeFileInfo(std::string& s)
{
rs_sprintf_append(s, "f%s%c%s%c%lld%c%ld%c%d%c%ld%c\n",
FixName((fit->second)->name).c_str(), FILE_CACHE_SEPARATOR_CHAR,
(fit->second)->hash.c_str(), FILE_CACHE_SEPARATOR_CHAR,
(fit->second)->hash.toStdString().c_str(), FILE_CACHE_SEPARATOR_CHAR,
(fit->second)->size, FILE_CACHE_SEPARATOR_CHAR,
(fit->second)->modtime, FILE_CACHE_SEPARATOR_CHAR,
(fit->second)->pop, FILE_CACHE_SEPARATOR_CHAR,
@ -1165,14 +1170,14 @@ int DirEntry::saveEntry(std::string &s)
}
int FileIndex::searchHash(const std::string& hash, std::list<FileEntry *> &results) const
int FileIndex::searchHash(const RsFileHash& hash, std::list<FileEntry *> &results) const
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::searchHash(" << hash << ")";
std::cerr << std::endl;
#endif
std::map<std::string,FileEntry*>::const_iterator it = _file_hashes.find(hash) ;
std::map<RsFileHash,FileEntry*>::const_iterator it = _file_hashes.find(hash) ;
if(it!=_file_hashes.end() && isValid((void*)it->second))
results.push_back(it->second) ;
@ -1394,7 +1399,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
}
FileEntry *file = static_cast<FileEntry *>(ref);
DirEntry *dir = (file->hash.empty())?static_cast<DirEntry *>(file):NULL ; // This is a hack to avoid doing a dynamic_cast
DirEntry *dir = (file->hash.isNull())?static_cast<DirEntry *>(file):NULL ; // This is a hack to avoid doing a dynamic_cast
details.children.clear() ;
time_t now = time(NULL) ;
@ -1433,7 +1438,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
details.type = DIR_TYPE_PERSON ;
else
details.type = DIR_TYPE_DIR;
details.hash = "";
details.hash.clear() ;
details.count = dir->subdirs.size() + dir->files.size();
details.min_age = now - dir->most_recent_time ;
}

View file

@ -91,7 +91,7 @@ virtual int print(std::string &out);
/* Data */
std::string name;
std::string hash;
RsFileHash hash;
uint64_t size; /* file size */
time_t modtime; /* modification time - most recent mod time for a sub entry for dirs */
int pop; /* popularity rating */
@ -174,7 +174,7 @@ class PersonEntry: public DirEntry
{
public:
/* cleanup */
PersonEntry(const std::string& pid) : id(pid) { return; }
PersonEntry(const RsPeerId& pid) : id(pid) { return; }
virtual ~PersonEntry() { return; }
DirEntry &operator=(DirEntry &src)
@ -186,7 +186,7 @@ DirEntry &operator=(DirEntry &src)
virtual uint32_t type() const { return DIR_TYPE_PERSON ; }
/* Data */
std::string id;
RsPeerId id;
/* Inherited members from FileEntry:
int size - count for dirs
@ -209,7 +209,7 @@ class Expression;
class FileIndex
{
public:
FileIndex(const std::string& pid);
FileIndex(const RsPeerId& pid);
~FileIndex();
/* control root entries */
@ -230,12 +230,12 @@ class FileIndex
int printFileIndex(std::ostream &out);
/* load/save to file */
int loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size);
int saveIndex(const std::string& filename, std::string &fileHash, uint64_t &size, const std::set<std::string>& forbidden_roots);
int loadIndex(const std::string& filename, const RsFileHash &expectedHash, uint64_t size);
int saveIndex(const std::string& filename, RsFileHash &fileHash, uint64_t &size, const std::set<std::string>& forbidden_roots);
/* search through this index */
int searchTerms(const std::list<std::string>& terms, std::list<FileEntry *> &results) const;
int searchHash(const std::string& hash, std::list<FileEntry *> &results) const;
int searchHash(const RsFileHash& hash, std::list<FileEntry *> &results) const;
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
/// Recursively compute the maximum modification time of children.
@ -262,7 +262,7 @@ class FileIndex
void updateHashIndex() ;
void recursUpdateHashIndex(DirEntry *) ;
std::map<std::string,FileEntry*> _file_hashes ;
std::map<RsFileHash,FileEntry*> _file_hashes ;
};

View file

@ -106,7 +106,7 @@ int FileIndexStore::loadCache(const RsCacheData &data)
*
* peername should not be used in dbase.
*/
finew->root->name = data.pid;
finew->root->name = data.pid.toStdString();
if (local)
{
@ -168,7 +168,7 @@ int FileIndexStore::loadCache(const RsCacheData &data)
/* Search Interface - For Directory Access */
int FileIndexStore::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails& details) const
int FileIndexStore::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails& details) const
{
lockData();
@ -263,7 +263,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, FileSearch
details.ref = NULL;
details.type = DIR_TYPE_ROOT;
details.name = "";
details.hash = "";
details.hash.clear() ;
details.path = "";
details.count = indices.size();
details.age = 0;
@ -288,7 +288,7 @@ uint32_t FileIndexStore::getType(void *ref) const
return b;
}
int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results) const
int FileIndexStore::SearchHash(const RsFileHash& hash, std::list<FileDetail> &results) const
{
lockData();
results.clear() ;
@ -382,7 +382,7 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Di
if(!FileIndex::extractData(*rit, dd))
continue ;
dd.id = "Local";
dd.id.clear() ;
results.push_back(dd);
}
@ -431,7 +431,7 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<DirDetails> &resul
{
DirDetails dd;
FileIndex::extractData(*rit, dd);
dd.id = "Local";
dd.id.clear() ;
results.push_back(dd);
}

View file

@ -73,7 +73,7 @@ virtual ~FileIndexStore();
virtual int loadCache(const RsCacheData &data); /* actual load, once data available */
/* Search Interface - For FileTransfer Lookup */
int SearchHash(std::string hash, std::list<FileDetail> &results) const;
int SearchHash(const RsFileHash &hash, std::list<FileDetail> &results) const;
/* Search Interface - For Search Interface */
int SearchKeywords(std::list<std::string> terms, std::list<DirDetails> &results,FileSearchFlags flags) const;
@ -83,7 +83,7 @@ virtual int loadCache(const RsCacheData &data); /* actual load, once data avai
/* Search Interface - For Directory Access */
int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) const;
int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details) const;
int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const;
uint32_t getType(void *ref) const ;

View file

@ -98,7 +98,7 @@ bool ExtExpression::eval(FileEntry *file){
}
bool HashExpression::eval(FileEntry *file){
return evalStr(file->hash);
return evalStr(file->hash.toStdString());
}
/*Check whether two strings are 'equal' to each other*/
@ -115,7 +115,7 @@ static bool StrEquals(const std::string & str1, const std::string & str2,
}
/*Check whether one string contains the other*/
static bool StrContains( std::string & str1, std::string & str2,
static bool StrContains( const std::string & str1, const std::string & str2,
bool IgnoreCase){
std::string::const_iterator iter ;
@ -131,7 +131,7 @@ static bool StrContains( std::string & str1, std::string & str2,
}
bool StringExpression :: evalStr ( std::string &str ){
bool StringExpression :: evalStr ( const std::string &str ){
std::list<std::string>::iterator iter;
switch (Op) {
case ContainsAllStrings: