mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 06:02:41 -04:00
First shot of file sharing permissions. Compiles, but needs some testing/debugging.
- added type-safe flags in retroshare/rsflags.h. This should be used to make new flags types in order to prevent mixing flags up in function prototypes. - group handling is left to rsPeers. We'll move it to rsCircles later. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-FileSharingPermissions@5754 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
03d4936b12
commit
dc82cee700
27 changed files with 567 additions and 336 deletions
|
@ -92,11 +92,12 @@ bool CacheSource::loadLocalCache(const CacheData &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* control Caches available */
|
/* control Caches available */
|
||||||
bool CacheSource::refreshCache(const CacheData &data)
|
bool CacheSource::refreshCache(const CacheData &data,const std::list<std::string>& destination_peers)
|
||||||
{
|
{
|
||||||
lockData(); /* LOCK MUTEX */
|
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(cMutex); /* LOCK MUTEX */
|
||||||
|
|
||||||
if (data.cid.type == getCacheType())
|
if (data.cid.type == getCacheType())
|
||||||
{
|
{
|
||||||
int subid = 0;
|
int subid = 0;
|
||||||
|
@ -116,14 +117,45 @@ bool CacheSource::refreshCache(const CacheData &data)
|
||||||
caches[subid] = data;
|
caches[subid] = data;
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unlockData(); /* UNLOCK MUTEX */
|
if (mStrapper) /* allow testing without full feedback */
|
||||||
|
mStrapper->refreshCache(data,destination_peers);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
bool CacheSource::refreshCache(const CacheData &data)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(cMutex); /* LOCK MUTEX */
|
||||||
|
|
||||||
|
if (data.cid.type == getCacheType())
|
||||||
|
{
|
||||||
|
int subid = 0;
|
||||||
|
if (isMultiCache())
|
||||||
|
{
|
||||||
|
subid = data.cid.subid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Backup the old Caches */
|
||||||
|
CacheSet::const_iterator it;
|
||||||
|
if (caches.end() != (it = caches.find(subid)))
|
||||||
|
{
|
||||||
|
mOldCaches[it->second.hash] = it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* store new cache */
|
||||||
|
caches[subid] = data;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mStrapper) /* allow testing without full feedback */
|
if (mStrapper) /* allow testing without full feedback */
|
||||||
mStrapper->refreshCache(data);
|
mStrapper->refreshCache(data);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CacheSource::clearCache(CacheId id)
|
bool CacheSource::clearCache(CacheId id)
|
||||||
{
|
{
|
||||||
lockData(); /* LOCK MUTEX */
|
lockData(); /* LOCK MUTEX */
|
||||||
|
@ -567,6 +599,26 @@ void CacheStrapper::statusChange(const std::list<pqipeer> &plist)
|
||||||
|
|
||||||
/**************** from pqimonclient ********************/
|
/**************** from pqimonclient ********************/
|
||||||
|
|
||||||
|
void CacheStrapper::refreshCache(const CacheData &data,const std::list<std::string>& destination_peers)
|
||||||
|
{
|
||||||
|
/* we've received an update
|
||||||
|
* send to all online peers + self
|
||||||
|
*/
|
||||||
|
#ifdef CS_DEBUG
|
||||||
|
std::cerr << "CacheStrapper::refreshCache() : " << data << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
|
||||||
|
for(std::list<std::string>::const_iterator it = destination_peers.begin(); it != destination_peers.end(); ++it)
|
||||||
|
{
|
||||||
|
#ifdef CS_DEBUG
|
||||||
|
std::cerr << "CacheStrapper::refreshCache() Send To: " << *it << std::endl;
|
||||||
|
#endif
|
||||||
|
mCacheUpdates.push_back(std::make_pair(*it, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
}
|
||||||
|
|
||||||
void CacheStrapper::refreshCache(const CacheData &data)
|
void CacheStrapper::refreshCache(const CacheData &data)
|
||||||
{
|
{
|
||||||
|
@ -578,26 +630,12 @@ void CacheStrapper::refreshCache(const CacheData &data)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::list<std::string> ids;
|
std::list<std::string> ids;
|
||||||
std::list<std::string>::iterator it;
|
|
||||||
|
|
||||||
mLinkMgr->getOnlineList(ids);
|
mLinkMgr->getOnlineList(ids);
|
||||||
|
ids.push_back(mLinkMgr->getOwnId()) ;
|
||||||
|
|
||||||
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
|
refreshCache(data,ids) ;
|
||||||
for(it = ids.begin(); it != ids.end(); it++)
|
|
||||||
{
|
|
||||||
#ifdef CS_DEBUG
|
|
||||||
std::cerr << "CacheStrapper::refreshCache() Send To: " << *it << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mCacheUpdates.push_back(std::make_pair(*it, data));
|
|
||||||
}
|
|
||||||
|
|
||||||
mCacheUpdates.push_back(std::make_pair(mLinkMgr->getOwnId(), data));
|
|
||||||
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CacheStrapper::refreshCacheStore(const CacheData & /* data */ )
|
void CacheStrapper::refreshCacheStore(const CacheData & /* data */ )
|
||||||
{
|
{
|
||||||
/* indicate to save data */
|
/* indicate to save data */
|
||||||
|
|
|
@ -181,6 +181,7 @@ class CacheSource
|
||||||
virtual bool loadLocalCache(const CacheData &data);
|
virtual bool loadLocalCache(const CacheData &data);
|
||||||
|
|
||||||
/* control Caches available */
|
/* control Caches available */
|
||||||
|
bool refreshCache(const CacheData &data,const std::list<std::string>& destination_peers);
|
||||||
bool refreshCache(const CacheData &data);
|
bool refreshCache(const CacheData &data);
|
||||||
bool clearCache(CacheId id);
|
bool clearCache(CacheId id);
|
||||||
|
|
||||||
|
@ -394,11 +395,12 @@ virtual void statusChange(const std::list<pqipeer> &plist);
|
||||||
/* Feedback from CacheSources */
|
/* Feedback from CacheSources */
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* send data to peers online and selfe
|
* send data to peers online and self
|
||||||
* @param data
|
* @param data
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void refreshCache(const CacheData &data);
|
void refreshCache(const CacheData &data);
|
||||||
|
void refreshCache(const CacheData &data,const std::list<std::string>& destination_peers); // specify a particular list of destination peers (self not added!)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* forces config savelist
|
* forces config savelist
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
#include "retroshare/rsiface.h"
|
#include "retroshare/rsiface.h"
|
||||||
#include "retroshare/rsnotify.h"
|
#include "retroshare/rsnotify.h"
|
||||||
|
#include "retroshare/rspeers.h"
|
||||||
#include "util/folderiterator.h"
|
#include "util/folderiterator.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -266,7 +267,7 @@ FileIndexMonitor::~FileIndexMonitor()
|
||||||
/* Data cleanup - TODO */
|
/* Data cleanup - TODO */
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
|
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id)
|
||||||
{
|
{
|
||||||
results.clear();
|
results.clear();
|
||||||
std::list<FileEntry *> firesults;
|
std::list<FileEntry *> firesults;
|
||||||
|
@ -276,10 +277,10 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
|
||||||
fi.searchTerms(keywords, firesults);
|
fi.searchTerms(keywords, firesults);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterResults(firesults,results,flags) ;
|
return filterResults(firesults,results,flags,peer_id) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,uint32_t flags) const
|
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,uint32_t flags,const std::string& peer_id) const
|
||||||
{
|
{
|
||||||
results.clear();
|
results.clear();
|
||||||
std::list<FileEntry *> firesults;
|
std::list<FileEntry *> firesults;
|
||||||
|
@ -289,11 +290,15 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& resu
|
||||||
fi.searchBoolExp(exp, firesults);
|
fi.searchBoolExp(exp, firesults);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterResults(firesults,results,flags) ;
|
return filterResults(firesults,results,flags,peer_id) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const
|
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,TransferInfoFlags flags,const std::string& peer_id) const
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
if((flags & ~RS_FILE_HINTS_PERMISSION_MASK) > 0)
|
||||||
|
std::cerr << "(EE) ***** FileIndexMonitor:: Flags ERROR in filterResults!!" << std::endl;
|
||||||
|
#endif
|
||||||
/* translate/filter results */
|
/* translate/filter results */
|
||||||
|
|
||||||
for(std::list<FileEntry*>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
|
for(std::list<FileEntry*>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
|
||||||
|
@ -304,7 +309,9 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
|
||||||
std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags ;
|
std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (cdetails.type == DIR_TYPE_FILE && ( cdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0)
|
TransferInfoFlags permission_flags = rsPeers->computePeerPermissionFlags(peer_id,cdetails.flags,cdetails.parent_groups) ;
|
||||||
|
|
||||||
|
if (cdetails.type == DIR_TYPE_FILE && (( permission_flags & flags & RS_FILE_HINTS_PERMISSION_MASK) > 0 ))
|
||||||
{
|
{
|
||||||
cdetails.id = "Local";
|
cdetails.id = "Local";
|
||||||
results.push_back(cdetails);
|
results.push_back(cdetails);
|
||||||
|
@ -320,7 +327,7 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
|
||||||
return !results.empty() ;
|
return !results.empty() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t hint_flags, std::string &fullpath, uint64_t &size) const
|
bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t hint_flags, const std::string& peer_id,std::string &fullpath, uint64_t &size) const
|
||||||
{
|
{
|
||||||
std::list<FileEntry *> results;
|
std::list<FileEntry *> results;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
@ -340,12 +347,19 @@ bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t hint_flags, std::
|
||||||
FileEntry *fe = results.front();
|
FileEntry *fe = results.front();
|
||||||
DirEntry *de = fe->parent; /* all files must have a valid parent! */
|
DirEntry *de = fe->parent; /* all files must have a valid parent! */
|
||||||
|
|
||||||
uint32_t share_flags = locked_findShareFlags(fe) ;
|
std::list<std::string> parent_groups ;
|
||||||
|
FileStorageFlags share_flags ;
|
||||||
|
|
||||||
|
locked_findShareFlagsAndParentGroups(fe,share_flags,parent_groups) ;
|
||||||
|
|
||||||
|
// turn share flags into hint flags
|
||||||
|
|
||||||
|
uint32_t shflh = rsPeers->computePeerPermissionFlags(peer_id,share_flags,parent_groups) ;
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::findLocalFile: Filtering candidate " << fe->name << ", flags=" << share_flags << ", hint_flags=" << hint_flags << std::endl ;
|
std::cerr << "FileIndexMonitor::findLocalFile: Filtering candidate " << fe->name << ", flags=" << share_flags << ", hint_flags=" << hint_flags << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((share_flags & hint_flags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE)) > 0)
|
if(shflh & (hint_flags & RS_FILE_HINTS_PERMISSION_MASK))
|
||||||
{
|
{
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl;
|
std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl;
|
||||||
|
@ -423,7 +437,11 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
||||||
|
|
||||||
/* More error checking needed here! */
|
/* More error checking needed here! */
|
||||||
|
|
||||||
std::string name = data.name ; // this trick allows to load the complete file. Not the one being shared.
|
std::string name = data.name ;
|
||||||
|
|
||||||
|
name[name.length()-4] = 'r' ;// this trick allows to load the complete file. Not the one being shared.
|
||||||
|
name[name.length()-3] = 's' ;
|
||||||
|
name[name.length()-2] = 'f' ;
|
||||||
name[name.length()-1] = 'c' ;
|
name[name.length()-1] = 'c' ;
|
||||||
|
|
||||||
if ((ok = fi.loadIndex(data.path + '/' + name, "", data.size)))
|
if ((ok = fi.loadIndex(data.path + '/' + name, "", data.size)))
|
||||||
|
@ -445,17 +463,18 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
||||||
|
|
||||||
fi.updateMaxModTime() ;
|
fi.updateMaxModTime() ;
|
||||||
}
|
}
|
||||||
|
#ifdef REMOVED
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
return updateCache(data);
|
return updateCache(data);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileIndexMonitor::updateCache(const CacheData &data) /* we call this one */
|
bool FileIndexMonitor::updateCache(const CacheData &data,const std::list<std::string>& destination_peers) /* we call this one */
|
||||||
{
|
{
|
||||||
return refreshCache(data);
|
return refreshCache(data,destination_peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -986,45 +1005,80 @@ void FileIndexMonitor::locked_saveFileIndexes()
|
||||||
|
|
||||||
std::string path = getCacheDir();
|
std::string path = getCacheDir();
|
||||||
|
|
||||||
// Two files are saved: one with only browsable dirs, which will be shared by the cache system,
|
// Multiple files are saved: for every kind of peers, the set of browsable files will be different. A specific file is
|
||||||
// and one with the complete file collection.
|
// prepared for all situations, and shared by all peers having the same situation.
|
||||||
|
//
|
||||||
|
// A complete file collection is also saved, and serves as memory for the FileIndexMonitor system.
|
||||||
//
|
//
|
||||||
std::string tmpname_browsable;
|
|
||||||
rs_sprintf(tmpname_browsable, "fc-own-%ld.rsfb", time(NULL));
|
|
||||||
std::string fname_browsable = path + "/" + tmpname_browsable;
|
|
||||||
|
|
||||||
std::string tmpname_total;
|
|
||||||
rs_sprintf(tmpname_total, "fc-own-%ld.rsfc", time(NULL));
|
|
||||||
std::string fname_total = path + "/" + tmpname_total;
|
|
||||||
|
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::updateCycle() FileIndex modified ... updating";
|
std::cerr << "FileIndexMonitor::updateCycle() FileIndex modified ... updating" << std::endl;
|
||||||
std::cerr << std::endl;
|
|
||||||
std::cerr << "FileIndexMonitor::updateCycle() saving browsable file list to: " << fname_browsable << std::endl ;
|
|
||||||
std::cerr << "FileIndexMonitor::updateCycle() saving total file list to to: " << fname_total << std::endl ;
|
std::cerr << "FileIndexMonitor::updateCycle() saving total file list to to: " << fname_total << std::endl ;
|
||||||
|
std::cerr << "FileIndexMonitor::updateCycle() saving browsable file list to: " << fname_browsable << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
// Make for each peer the list of forbidden shared directories. Make a separate cache file for each different set.
|
||||||
|
// 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> online_ids ;
|
||||||
|
rsPeers->getOnlineList(online_ids);
|
||||||
|
|
||||||
std::string calchash;
|
std::map<std::set<std::string>, std::list<std::string> > peers_per_directory_combination ;
|
||||||
uint64_t size;
|
|
||||||
|
|
||||||
std::cerr << "About to save, with the following restrictions:" << std::endl ;
|
for(std::list<std::string>::const_iterator it(online_ids.begin());it!=online_ids.end();++it)
|
||||||
std::set<std::string> forbidden_dirs ;
|
|
||||||
for(std::map<std::string,SharedDirInfo>::const_iterator it(directoryMap.begin());it!=directoryMap.end();++it)
|
|
||||||
{
|
{
|
||||||
std::cerr << " dir=" << it->first << " : " ;
|
std::cerr << "About to save, with the following restrictions:" << std::endl ;
|
||||||
if((it->second.shareflags & RS_FILE_HINTS_BROWSABLE) == 0)
|
|
||||||
|
std::set<std::string> forbidden_dirs ;
|
||||||
|
for(std::map<std::string,SharedDirInfo>::const_iterator dit(directoryMap.begin());dit!=directoryMap.end();++dit)
|
||||||
|
{
|
||||||
|
std::cerr << " dir=" << dit->first << " : " ;
|
||||||
|
|
||||||
|
uint32_t permission_flags = rsPeers->computePeerPermissionFlags(*it,dit->second.shareflags,dit->second.parent_groups) ;
|
||||||
|
|
||||||
|
if(!(permission_flags & RS_FILE_HINTS_BROWSABLE))
|
||||||
{
|
{
|
||||||
std::cerr << "forbidden" << std::endl;
|
std::cerr << "forbidden" << std::endl;
|
||||||
forbidden_dirs.insert(it->first) ;
|
forbidden_dirs.insert(dit->first) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cerr << "autorized" << std::endl;
|
std::cerr << "autorized" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t sizetmp ;
|
peers_per_directory_combination[forbidden_dirs].push_back(*it) ;
|
||||||
|
}
|
||||||
|
std::string ownId = rsPeers->getOwnId() ;
|
||||||
|
peers_per_directory_combination[std::set<std::string>()].push_back(ownId) ; // add full configuration to self, i.e. no forbidden directories.
|
||||||
|
|
||||||
fi.saveIndex(fname_total, calchash, sizetmp,std::set<std::string>()); // save all files
|
int n=0 ;
|
||||||
fi.saveIndex(fname_browsable, calchash, size,forbidden_dirs); // save only browsable files
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
|
for(std::map<std::set<std::string>, std::list<std::string> >::const_iterator it(peers_per_directory_combination.begin());
|
||||||
|
it!=peers_per_directory_combination.end();++it,++n)
|
||||||
|
{
|
||||||
|
std::string tmpname_browsable;
|
||||||
|
|
||||||
|
if(it->first.empty())
|
||||||
|
rs_sprintf(tmpname_browsable, "fc-own-%ld.rsfc",now,n);
|
||||||
|
else
|
||||||
|
rs_sprintf(tmpname_browsable, "fc-own-%ld.%04d",now,n);
|
||||||
|
|
||||||
|
std::string fname_browsable = path + "/" + tmpname_browsable;
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "Sending file list: " << std::endl;
|
||||||
|
std::cerr << " filename : " << tmpname_browsable << std::endl;
|
||||||
|
std::cerr << " to peers : " << std::endl;
|
||||||
|
for(std::list<std::string>::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 ;
|
||||||
|
uint64_t size ;
|
||||||
|
|
||||||
|
fi.saveIndex(fname_browsable, hash, size,it->first); // save only browsable files
|
||||||
|
|
||||||
if(size > 0)
|
if(size > 0)
|
||||||
{
|
{
|
||||||
|
@ -1042,11 +1096,12 @@ void FileIndexMonitor::locked_saveFileIndexes()
|
||||||
data.cid.subid = 0;
|
data.cid.subid = 0;
|
||||||
data.path = path;
|
data.path = path;
|
||||||
data.name = tmpname_browsable;
|
data.name = tmpname_browsable;
|
||||||
data.hash = calchash;
|
data.hash = hash;
|
||||||
data.size = size;
|
data.size = size;
|
||||||
data.recvd = time(NULL);
|
data.recvd = time(NULL);
|
||||||
|
|
||||||
updateCache(data);
|
updateCache(data,it->second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
|
@ -1353,18 +1408,15 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
|
||||||
if(ref != NULL)
|
if(ref != NULL)
|
||||||
{
|
{
|
||||||
FileEntry *file = (FileEntry *) ref;
|
FileEntry *file = (FileEntry *) ref;
|
||||||
|
locked_findShareFlagsAndParentGroups(file,details.flags,details.parent_groups) ;
|
||||||
uint32_t share_flags = locked_findShareFlags(file) ;
|
|
||||||
|
|
||||||
details.flags |= (( (share_flags & RS_FILE_HINTS_BROWSABLE )>0)?DIR_FLAGS_BROWSABLE :0) ;
|
|
||||||
details.flags |= (( (share_flags & RS_FILE_HINTS_NETWORK_WIDE)>0)?DIR_FLAGS_NETWORK_WIDE:0) ;
|
|
||||||
}
|
}
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t FileIndexMonitor::locked_findShareFlags(FileEntry *file) const
|
void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list<std::string>& parent_groups) const
|
||||||
{
|
{
|
||||||
uint32_t flags = 0 ;
|
flags = 0 ;
|
||||||
|
static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ;
|
||||||
|
|
||||||
DirEntry *dir = dynamic_cast<DirEntry*>(file) ;
|
DirEntry *dir = dynamic_cast<DirEntry*>(file) ;
|
||||||
if(dir == NULL)
|
if(dir == NULL)
|
||||||
|
@ -1384,13 +1436,14 @@ uint32_t FileIndexMonitor::locked_findShareFlags(FileEntry *file) const
|
||||||
if(it == directoryMap.end())
|
if(it == directoryMap.end())
|
||||||
std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ;
|
std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ;
|
||||||
else
|
else
|
||||||
flags = it->second.shareflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE) ;
|
{
|
||||||
|
flags = it->second.shareflags & PERMISSION_MASK ;
|
||||||
|
parent_groups = it->second.parent_groups ;
|
||||||
|
}
|
||||||
#ifdef FIM_DEBUG2
|
#ifdef FIM_DEBUG2
|
||||||
std::cerr << "flags = " << flags << std::endl ;
|
std::cerr << "flags = " << flags << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,10 +111,12 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||||
virtual ~FileIndexMonitor();
|
virtual ~FileIndexMonitor();
|
||||||
|
|
||||||
/* external interface for filetransfer */
|
/* external interface for filetransfer */
|
||||||
bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const;
|
bool findLocalFile(std::string hash,uint32_t flags,const std::string& peer_id, std::string &fullpath, uint64_t &size) const;
|
||||||
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) ;
|
|
||||||
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,uint32_t flags) const ;
|
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id) ;
|
||||||
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const ;
|
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id) const ;
|
||||||
|
|
||||||
|
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,TransferInfoFlags flags,const std::string& peer_id) const ;
|
||||||
|
|
||||||
|
|
||||||
/* external interface for local access to files */
|
/* external interface for local access to files */
|
||||||
|
@ -124,7 +126,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||||
/* Interacting with CacheSource */
|
/* Interacting with CacheSource */
|
||||||
/* overloaded from CacheSource */
|
/* overloaded from CacheSource */
|
||||||
virtual bool loadLocalCache(const CacheData &data); /* called with stored data */
|
virtual bool loadLocalCache(const CacheData &data); /* called with stored data */
|
||||||
bool updateCache(const CacheData &data); /* we call when we have a new cache for others */
|
bool updateCache(const CacheData &data,const std::list<std::string>& dest_peers); /* we call when we have a new cache for others */
|
||||||
|
|
||||||
|
|
||||||
/* the FileIndexMonitor inner workings */
|
/* the FileIndexMonitor inner workings */
|
||||||
|
@ -169,7 +171,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||||
void locked_saveFileIndexes() ;
|
void locked_saveFileIndexes() ;
|
||||||
|
|
||||||
// Finds the share flags associated with this file entry.
|
// Finds the share flags associated with this file entry.
|
||||||
uint32_t locked_findShareFlags(FileEntry *fe) const ;
|
void locked_findShareFlagsAndParentGroups(FileEntry *fe,FileStorageFlags& shareflags,std::list<std::string>& parent_groups) const ;
|
||||||
|
|
||||||
std::string locked_findRealRoot(std::string base) const;
|
std::string locked_findRealRoot(std::string base) const;
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ virtual int print(std::string &out);
|
||||||
/* References for easy manipulation */
|
/* References for easy manipulation */
|
||||||
DirEntry *parent;
|
DirEntry *parent;
|
||||||
int row;
|
int row;
|
||||||
|
std::list<std::string> parent_groups ;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
|
|
|
@ -622,7 +622,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
||||||
|
|
||||||
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
|
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
|
||||||
|
|
||||||
if(_queue[pos]->mFlags & RS_FILE_HINTS_NETWORK_WIDE)
|
if(_queue[pos]->mFlags & RS_FILE_HINTS_ANONYMOUS_ROUTING)
|
||||||
mTurtle->monitorFileTunnels(_queue[pos]->mName,_queue[pos]->mHash,_queue[pos]->mSize) ;
|
mTurtle->monitorFileTunnels(_queue[pos]->mName,_queue[pos]->mHash,_queue[pos]->mSize) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,7 +631,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
||||||
_queue[pos]->mState = ftFileControl::QUEUED ;
|
_queue[pos]->mState = ftFileControl::QUEUED ;
|
||||||
_queue[pos]->mCreator->closeFile() ;
|
_queue[pos]->mCreator->closeFile() ;
|
||||||
|
|
||||||
if(_queue[pos]->mFlags & RS_FILE_HINTS_NETWORK_WIDE)
|
if(_queue[pos]->mFlags & RS_FILE_HINTS_ANONYMOUS_ROUTING)
|
||||||
mTurtle->stopMonitoringFileTunnels(_queue[pos]->mHash) ;
|
mTurtle->stopMonitoringFileTunnels(_queue[pos]->mHash) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -875,7 +875,7 @@ bool ftController::completeFile(std::string hash)
|
||||||
|
|
||||||
mDownloads.erase(it);
|
mDownloads.erase(it);
|
||||||
|
|
||||||
if(flags & RS_FILE_HINTS_NETWORK_WIDE)
|
if(flags & RS_FILE_HINTS_ANONYMOUS_ROUTING)
|
||||||
mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ;
|
mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ;
|
||||||
|
|
||||||
} /******* UNLOCKED ********/
|
} /******* UNLOCKED ********/
|
||||||
|
@ -1043,14 +1043,14 @@ bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
||||||
return true ;
|
return true ;
|
||||||
|
|
||||||
// check for file lists
|
// check for file lists
|
||||||
if (mSearch->search(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info))
|
if (mSearch->search(hash, DIR_FLAGS_PERMISSIONS_MASK | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info))
|
||||||
return true ;
|
return true ;
|
||||||
|
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftController::FileRequest(const std::string& fname, const std::string& hash,
|
bool ftController::FileRequest(const std::string& fname, const std::string& hash,
|
||||||
uint64_t size, const std::string& dest, uint32_t flags,
|
uint64_t size, const std::string& dest, TransferInfoFlags flags,
|
||||||
const std::list<std::string> &_srcIds)
|
const std::list<std::string> &_srcIds)
|
||||||
{
|
{
|
||||||
std::list<std::string> srcIds(_srcIds) ;
|
std::list<std::string> srcIds(_srcIds) ;
|
||||||
|
@ -1196,7 +1196,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||||
/* do a source search - for any extra sources */
|
/* do a source search - for any extra sources */
|
||||||
// add sources only in direct mode
|
// add sources only in direct mode
|
||||||
//
|
//
|
||||||
if((flags & RS_FILE_HINTS_BROWSABLE) && mSearch->search(hash, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
|
if(/* (flags & RS_FILE_HINTS_BROWSABLE) && */ mSearch->search(hash, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
|
||||||
{
|
{
|
||||||
/* do something with results */
|
/* do something with results */
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
|
@ -1242,7 +1242,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||||
|
|
||||||
// We check that flags are consistent.
|
// We check that flags are consistent.
|
||||||
|
|
||||||
if(flags & RS_FILE_HINTS_NETWORK_WIDE)
|
if(flags & RS_FILE_HINTS_ANONYMOUS_ROUTING)
|
||||||
mTurtle->monitorFileTunnels(fname,hash,size) ;
|
mTurtle->monitorFileTunnels(fname,hash,size) ;
|
||||||
|
|
||||||
bool assume_availability = flags & RS_FILE_HINTS_CACHE ; // assume availability for cache files
|
bool assume_availability = flags & RS_FILE_HINTS_CACHE ; // assume availability for cache files
|
||||||
|
@ -1623,7 +1623,7 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
||||||
/* extract details */
|
/* extract details */
|
||||||
info.hash = hash;
|
info.hash = hash;
|
||||||
info.fname = it->second->mName;
|
info.fname = it->second->mName;
|
||||||
info.flags = it->second->mFlags;
|
info.transfer_info_flags = it->second->mFlags ;
|
||||||
info.priority = SPEED_NORMAL ;
|
info.priority = SPEED_NORMAL ;
|
||||||
RsDirUtil::removeTopDir(it->second->mDestination, info.path); /* remove fname */
|
RsDirUtil::removeTopDir(it->second->mDestination, info.path); /* remove fname */
|
||||||
info.queue_position = it->second->mQueuePosition ;
|
info.queue_position = it->second->mQueuePosition ;
|
||||||
|
|
|
@ -129,7 +129,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
bool FileRequest(const std::string& fname, const std::string& hash,
|
bool FileRequest(const std::string& fname, const std::string& hash,
|
||||||
uint64_t size, const std::string& dest, uint32_t flags,
|
uint64_t size, const std::string& dest, TransferInfoFlags flags,
|
||||||
const std::list<std::string> &sourceIds);
|
const std::list<std::string> &sourceIds);
|
||||||
|
|
||||||
/// Do we already have this file, either in download or in file lists ?
|
/// Do we already have this file, either in download or in file lists ?
|
||||||
|
|
|
@ -142,7 +142,7 @@ bool ftDataMultiplex::FileDownloads(std::list<std::string> &hashs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ftDataMultiplex::FileDetails(const std::string &hash, uint32_t hintsflag, FileInfo &info)
|
bool ftDataMultiplex::FileDetails(const std::string &hash, TransferInfoFlags hintsflag, FileInfo &info)
|
||||||
{
|
{
|
||||||
#ifdef MPLEX_DEBUG
|
#ifdef MPLEX_DEBUG
|
||||||
std::cerr << "ftDataMultiplex::FileDetails(";
|
std::cerr << "ftDataMultiplex::FileDetails(";
|
||||||
|
@ -1316,11 +1316,11 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::
|
||||||
uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY ;
|
uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY ;
|
||||||
|
|
||||||
if(rsTurtle->isTurtlePeer(peerId))
|
if(rsTurtle->isTurtlePeer(peerId))
|
||||||
hintflags |= RS_FILE_HINTS_NETWORK_WIDE ;
|
hintflags |= RS_FILE_HINTS_ANONYMOUS_ROUTING ;
|
||||||
else
|
else
|
||||||
hintflags |= RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_CACHE ;
|
hintflags |= RS_FILE_HINTS_CACHE ;
|
||||||
|
|
||||||
if (mSearch->search(hash, hintflags, info))
|
if(mSearch->search(hash, hintflags,peerId, info))
|
||||||
{
|
{
|
||||||
|
|
||||||
/* setup a new provider */
|
/* setup a new provider */
|
||||||
|
|
|
@ -104,7 +104,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
||||||
/* get Details of File Transfers */
|
/* get Details of File Transfers */
|
||||||
bool FileUploads(std::list<std::string> &hashs);
|
bool FileUploads(std::list<std::string> &hashs);
|
||||||
bool FileDownloads(std::list<std::string> &hashs);
|
bool FileDownloads(std::list<std::string> &hashs);
|
||||||
bool FileDetails(const std::string &hash, uint32_t hintsflag, FileInfo &info);
|
bool FileDetails(const std::string &hash, TransferInfoFlags hintsflag, FileInfo &info);
|
||||||
|
|
||||||
void deleteUnusedServers() ;
|
void deleteUnusedServers() ;
|
||||||
void handlePendingCrcRequests() ;
|
void handlePendingCrcRequests() ;
|
||||||
|
|
|
@ -129,6 +129,11 @@ ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cached
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &info) const
|
bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &info) const
|
||||||
|
{
|
||||||
|
std::cerr << "(EE) ********* ftFiMonitor expects a peer id in search()!" << std::endl;
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, const std::string& peer_id,FileInfo &info) const
|
||||||
{
|
{
|
||||||
uint64_t fsize;
|
uint64_t fsize;
|
||||||
std::string path;
|
std::string path;
|
||||||
|
@ -144,7 +149,7 @@ bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &
|
||||||
//
|
//
|
||||||
uint32_t flags = hintflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE);
|
uint32_t flags = hintflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE);
|
||||||
|
|
||||||
if(findLocalFile(hash, flags, path, fsize))
|
if(findLocalFile(hash, flags,peer_id,path, fsize))
|
||||||
{
|
{
|
||||||
/* fill in details */
|
/* fill in details */
|
||||||
#ifdef DB_DEBUG
|
#ifdef DB_DEBUG
|
||||||
|
@ -288,6 +293,7 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
|
||||||
/* for each item, check it exists ....
|
/* for each item, check it exists ....
|
||||||
* - remove any that are dead (or flag?)
|
* - remove any that are dead (or flag?)
|
||||||
*/
|
*/
|
||||||
|
static const uint32_t PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ;
|
||||||
|
|
||||||
#ifdef DEBUG_ELIST
|
#ifdef DEBUG_ELIST
|
||||||
std::cerr << "ftFiMonitor::loadList()";
|
std::cerr << "ftFiMonitor::loadList()";
|
||||||
|
@ -341,7 +347,7 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
|
||||||
SharedDirInfo info ;
|
SharedDirInfo info ;
|
||||||
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
|
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
|
||||||
info.virtualname = fi->file.name;
|
info.virtualname = fi->file.name;
|
||||||
info.shareflags = fi->flags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE) ;
|
info.shareflags = fi->flags & PERMISSION_MASK ;
|
||||||
|
|
||||||
dirList.push_back(info) ;
|
dirList.push_back(info) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
||||||
|
|
||||||
/* overloaded search function */
|
/* overloaded search function */
|
||||||
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const;
|
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const;
|
||||||
|
virtual bool search(const std::string &hash, uint32_t hintflags, const std::string& peer_id, FileInfo &info) const;
|
||||||
|
|
||||||
/* overloaded set dirs enables config indication */
|
/* overloaded set dirs enables config indication */
|
||||||
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
||||||
|
|
|
@ -40,10 +40,14 @@ class ftSearch
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ftSearch() { return; }
|
ftSearch() { return; }
|
||||||
virtual ~ftSearch() { return; }
|
virtual ~ftSearch() { return; }
|
||||||
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const = 0;
|
virtual bool search(const std::string &hash, uint32_t hintflags,const std::string& peer_id, FileInfo &info) const
|
||||||
|
{
|
||||||
|
std::cerr << "Non overloaded search method called!!!" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,7 @@ bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
||||||
return mFtController->alreadyHaveFile(hash, info);
|
return mFtController->alreadyHaveFile(hash, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, uint32_t flags, const std::list<std::string>& srcIds)
|
bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferInfoFlags flags, const std::list<std::string>& srcIds)
|
||||||
{
|
{
|
||||||
std::string error_string ;
|
std::string error_string ;
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ bool ftServer::FileUploads(std::list<std::string> &hashs)
|
||||||
return mFtDataplex->FileUploads(hashs);
|
return mFtDataplex->FileUploads(hashs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftServer::FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info)
|
bool ftServer::FileDetails(const std::string &hash, TransferInfoFlags hintflags, FileInfo &info)
|
||||||
{
|
{
|
||||||
if (hintflags & RS_FILE_HINTS_DOWNLOAD)
|
if (hintflags & RS_FILE_HINTS_DOWNLOAD)
|
||||||
if(mFtController->FileDetails(hash, info))
|
if(mFtController->FileDetails(hash, info))
|
||||||
|
@ -429,7 +429,7 @@ bool ftServer::FileDetails(const std::string &hash, uint32_t hintflags, FileInfo
|
||||||
// file, we skip the call to fileDetails() for efficiency reasons.
|
// file, we skip the call to fileDetails() for efficiency reasons.
|
||||||
//
|
//
|
||||||
FileInfo info2 ;
|
FileInfo info2 ;
|
||||||
if( (!(info.flags & RS_FILE_HINTS_CACHE)) && mFtController->FileDetails(hash, info2))
|
if( (!(info.transfer_info_flags & RS_FILE_HINTS_CACHE)) && mFtController->FileDetails(hash, info2))
|
||||||
info.fname = info2.fname ;
|
info.fname = info2.fname ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
|
@ -447,17 +447,17 @@ bool ftServer::FileDetails(const std::string &hash, uint32_t hintflags, FileInfo
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
||||||
uint32_t period, uint32_t flags)
|
uint32_t period, TransferInfoFlags flags)
|
||||||
{
|
{
|
||||||
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
|
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftServer::ExtraFileRemove(std::string hash, uint32_t flags)
|
bool ftServer::ExtraFileRemove(std::string hash, TransferInfoFlags flags)
|
||||||
{
|
{
|
||||||
return mFtExtra->removeExtraFile(hash, flags);
|
return mFtExtra->removeExtraFile(hash, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags)
|
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferInfoFlags flags)
|
||||||
{
|
{
|
||||||
return mFtExtra->hashExtraFile(localpath, period, flags);
|
return mFtExtra->hashExtraFile(localpath, period, flags);
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,7 @@ int ftServer::RequestDirDetails(const std::string& uid, const std::string& path,
|
||||||
return mFiStore->RequestDirDetails(uid, path, details);
|
return mFiStore->RequestDirDetails(uid, path, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileStorageFlags flags)
|
||||||
{
|
{
|
||||||
#ifdef SERVER_DEBUG
|
#ifdef SERVER_DEBUG
|
||||||
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
|
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
|
||||||
|
@ -511,12 +511,12 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if(flags & DIR_FLAGS_LOCAL)
|
if(flags & RS_FILE_HINTS_LOCAL)
|
||||||
return mFiMon->RequestDirDetails(ref, details, flags);
|
return mFiMon->RequestDirDetails(ref, details, flags);
|
||||||
else
|
else
|
||||||
return mFiStore->RequestDirDetails(ref, details, flags);
|
return mFiStore->RequestDirDetails(ref, details, flags);
|
||||||
}
|
}
|
||||||
uint32_t ftServer::getType(void *ref, uint32_t flags)
|
uint32_t ftServer::getType(void *ref, TransferInfoFlags flags)
|
||||||
{
|
{
|
||||||
#ifdef SERVER_DEBUG
|
#ifdef SERVER_DEBUG
|
||||||
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
|
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
|
||||||
|
@ -530,7 +530,7 @@ uint32_t ftServer::getType(void *ref, uint32_t flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if(flags & DIR_FLAGS_LOCAL)
|
if(flags & RS_FILE_HINTS_LOCAL)
|
||||||
return mFiMon->getType(ref);
|
return mFiMon->getType(ref);
|
||||||
else
|
else
|
||||||
return mFiStore->getType(ref);
|
return mFiStore->getType(ref);
|
||||||
|
@ -541,6 +541,11 @@ uint32_t ftServer::getType(void *ref, uint32_t flags)
|
||||||
|
|
||||||
|
|
||||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
|
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
|
||||||
|
{
|
||||||
|
std::cerr << "(WW) ********* ftServer::SearchBoolExp:: called without peer id" << std::endl;
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id)
|
||||||
{
|
{
|
||||||
#ifdef SERVER_DEBUG
|
#ifdef SERVER_DEBUG
|
||||||
std::cerr << "ftServer::SearchKeywords()";
|
std::cerr << "ftServer::SearchKeywords()";
|
||||||
|
@ -553,16 +558,21 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetai
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if(flags & DIR_FLAGS_LOCAL)
|
if(flags & RS_FILE_HINTS_LOCAL)
|
||||||
return mFiMon->SearchKeywords(keywords, results,flags);
|
return mFiMon->SearchKeywords(keywords, results,flags,peer_id);
|
||||||
else
|
else
|
||||||
return mFiStore->SearchKeywords(keywords, results,flags);
|
return mFiStore->SearchKeywords(keywords, results,flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags)
|
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags)
|
||||||
{
|
{
|
||||||
if(flags & DIR_FLAGS_LOCAL)
|
std::cerr << "(WW) ********* ftServer::SearchBoolExp:: called without peer id" << std::endl;
|
||||||
return mFiMon->SearchBoolExp(exp,results,flags) ;
|
return 0 ;
|
||||||
|
}
|
||||||
|
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id)
|
||||||
|
{
|
||||||
|
if(flags & RS_FILE_HINTS_LOCAL)
|
||||||
|
return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ;
|
||||||
else
|
else
|
||||||
return mFiStore->searchBoolExp(exp, results);
|
return mFiStore->searchBoolExp(exp, results);
|
||||||
}
|
}
|
||||||
|
@ -731,7 +741,7 @@ bool ftServer::shareDownloadDirectory(bool share)
|
||||||
/* Share */
|
/* Share */
|
||||||
SharedDirInfo inf ;
|
SharedDirInfo inf ;
|
||||||
inf.filename = mFtController->getDownloadDirectory();
|
inf.filename = mFtController->getDownloadDirectory();
|
||||||
inf.shareflags = RS_FILE_HINTS_NETWORK_WIDE ;
|
inf.shareflags = DIR_FLAGS_NETWORK_WIDE_OTHERS ;
|
||||||
|
|
||||||
return addSharedDirectory(inf);
|
return addSharedDirectory(inf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ ftController *getController() const { return mFtController ; }
|
||||||
* Control of Downloads
|
* Control of Downloads
|
||||||
***/
|
***/
|
||||||
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info);
|
||||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, uint32_t flags, const std::list<std::string>& srcIds);
|
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferInfoFlags flags, const std::list<std::string>& srcIds);
|
||||||
virtual bool FileCancel(const std::string& hash);
|
virtual bool FileCancel(const std::string& hash);
|
||||||
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
virtual bool FileControl(const std::string& hash, uint32_t flags);
|
||||||
virtual bool FileClearCompleted();
|
virtual bool FileClearCompleted();
|
||||||
|
@ -154,7 +154,7 @@ virtual bool clearDownload(const std::string hash);
|
||||||
***/
|
***/
|
||||||
virtual bool FileDownloads(std::list<std::string> &hashs);
|
virtual bool FileDownloads(std::list<std::string> &hashs);
|
||||||
virtual bool FileUploads(std::list<std::string> &hashs);
|
virtual bool FileUploads(std::list<std::string> &hashs);
|
||||||
virtual bool FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info);
|
virtual bool FileDetails(const std::string &hash, TransferInfoFlags hintflags, FileInfo &info);
|
||||||
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
||||||
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
virtual bool FileUploadChunksDetails(const std::string& hash,const std::string& peer_id,CompressedChunkMap& map) ;
|
||||||
|
|
||||||
|
@ -162,25 +162,24 @@ virtual bool FileUploadChunksDetails(const std::string& hash,const std::string&
|
||||||
/***
|
/***
|
||||||
* Extra List Access
|
* Extra List Access
|
||||||
***/
|
***/
|
||||||
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferInfoFlags flags);
|
||||||
uint32_t period, uint32_t flags);
|
virtual bool ExtraFileRemove(std::string hash, TransferInfoFlags flags);
|
||||||
virtual bool ExtraFileRemove(std::string hash, uint32_t flags);
|
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferInfoFlags flags);
|
||||||
virtual bool ExtraFileHash(std::string localpath,
|
|
||||||
uint32_t period, uint32_t flags);
|
|
||||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||||
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath);
|
||||||
std::string destpath);
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Directory Listing / Search Interface
|
* Directory Listing / Search Interface
|
||||||
***/
|
***/
|
||||||
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details);
|
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details);
|
||||||
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
virtual int RequestDirDetails(void *ref, DirDetails &details, FileStorageFlags flags);
|
||||||
virtual uint32_t getType(void *ref,uint32_t flags) ;
|
virtual uint32_t getType(void *ref,TransferInfoFlags flags) ;
|
||||||
|
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags);
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags);
|
||||||
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id);
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags);
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags);
|
||||||
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id);
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions
|
* Utility Functions
|
||||||
|
|
|
@ -63,27 +63,29 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const uint32_t RS_FILE_HINTS_MASK = 0x00ffffff;
|
// Flags used when requesting info about transfers, mostly to filter out the result.
|
||||||
|
//
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_CACHE = 0x00000001;
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_EXTRA = 0x00000002;
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_LOCAL = 0x00000004;
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_REMOTE = 0x00000008;
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_DOWNLOAD = 0x00000010;
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_UPLOAD = 0x00000020;
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_NETWORK_WIDE = 0x00000080;// anonymously shared over network
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_BROWSABLE = 0x00000100;// browsable by friends
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_PERMISSION_MASK = 0x00000180;// OR of the last two flags. Used to filter out.
|
||||||
|
|
||||||
const uint32_t RS_FILE_HINTS_CACHE = 0x00000001;
|
// Flags used when requesting a transfer
|
||||||
const uint32_t RS_FILE_HINTS_EXTRA = 0x00000002;
|
//
|
||||||
const uint32_t RS_FILE_HINTS_LOCAL = 0x00000004;
|
const TransferInfoFlags RS_FILE_HINTS_ANONYMOUS_ROUTING = 0x00000040; // Use to ask turtle router to download the file.
|
||||||
const uint32_t RS_FILE_HINTS_REMOTE = 0x00000008;
|
const TransferInfoFlags RS_FILE_HINTS_ASSUME_AVAILABILITY = 0x00000200; // Assume full source availability. Used for cache files.
|
||||||
const uint32_t RS_FILE_HINTS_DOWNLOAD = 0x00000010;
|
const TransferInfoFlags RS_FILE_HINTS_MEDIA = 0x00001000;
|
||||||
const uint32_t RS_FILE_HINTS_UPLOAD = 0x00000020;
|
const TransferInfoFlags RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly.
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_SPEC_ONLY = 0x01000000;
|
||||||
|
const TransferInfoFlags RS_FILE_HINTS_NO_SEARCH = 0x02000000; // disable searching for potential direct sources.
|
||||||
|
|
||||||
const uint32_t RS_FILE_HINTS_NETWORK_WIDE = 0x00000080; // anonymously shared over network
|
// const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS
|
||||||
const uint32_t RS_FILE_HINTS_BROWSABLE = 0x00000100; // browsable by friends
|
// | RS_FILE_HINTS_NETWORK_WIDE_GROUPS | RS_FILE_HINTS_BROWSABLE_GROUPS ;
|
||||||
const uint32_t RS_FILE_HINTS_NETWORK_WIDE_OTHERS = 0x00000080; // anonymously shared over network
|
|
||||||
const uint32_t RS_FILE_HINTS_BROWSABLE_OTHERS = 0x00000100; // browsable by friends
|
|
||||||
const uint32_t RS_FILE_HINTS_ASSUME_AVAILABILITY = 0x00000200; // Assume full source availability. Used for cache files.
|
|
||||||
const uint32_t RS_FILE_HINTS_NETWORK_WIDE_GROUPS = 0x00000400; // anonymously shared over network
|
|
||||||
const uint32_t RS_FILE_HINTS_BROWSABLE_GROUPS = 0x00000800; // browsable by friends
|
|
||||||
const uint32_t RS_FILE_HINTS_MEDIA = 0x00001000;
|
|
||||||
const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly.
|
|
||||||
|
|
||||||
const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x01000000;
|
|
||||||
const uint32_t RS_FILE_HINTS_NO_SEARCH = 0x02000000;
|
|
||||||
|
|
||||||
/* Callback Codes */
|
/* Callback Codes */
|
||||||
|
|
||||||
|
@ -94,6 +96,7 @@ struct SharedDirInfo
|
||||||
std::string filename ;
|
std::string filename ;
|
||||||
std::string virtualname ;
|
std::string virtualname ;
|
||||||
uint32_t shareflags ; // RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE
|
uint32_t shareflags ; // RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE
|
||||||
|
std::list<std::string> parent_groups ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsFiles
|
class RsFiles
|
||||||
|
@ -113,7 +116,7 @@ class RsFiles
|
||||||
|
|
||||||
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info) = 0;
|
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info) = 0;
|
||||||
/// Returns false is we already have the file. Otherwise, initiates the dl and returns true.
|
/// Returns false is we already have the file. Otherwise, initiates the dl and returns true.
|
||||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, uint32_t flags, const std::list<std::string>& srcIds) = 0;
|
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferInfoFlags flags, const std::list<std::string>& srcIds) = 0;
|
||||||
virtual bool FileCancel(const std::string& hash) = 0;
|
virtual bool FileCancel(const std::string& hash) = 0;
|
||||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
||||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
|
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
|
||||||
|
@ -141,7 +144,7 @@ class RsFiles
|
||||||
***/
|
***/
|
||||||
virtual bool FileDownloads(std::list<std::string> &hashs) = 0;
|
virtual bool FileDownloads(std::list<std::string> &hashs) = 0;
|
||||||
virtual bool FileUploads(std::list<std::string> &hashs) = 0;
|
virtual bool FileUploads(std::list<std::string> &hashs) = 0;
|
||||||
virtual bool FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info) = 0;
|
virtual bool FileDetails(const std::string &hash, TransferInfoFlags hintflags, FileInfo &info) = 0;
|
||||||
|
|
||||||
/// Gives chunk details about the downloaded file with given hash.
|
/// Gives chunk details about the downloaded file with given hash.
|
||||||
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ;
|
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ;
|
||||||
|
@ -152,11 +155,9 @@ class RsFiles
|
||||||
/***
|
/***
|
||||||
* Extra List Access
|
* Extra List Access
|
||||||
***/
|
***/
|
||||||
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferInfoFlags flags) = 0;
|
||||||
uint32_t period, uint32_t flags) = 0;
|
virtual bool ExtraFileRemove(std::string hash, TransferInfoFlags flags) = 0;
|
||||||
virtual bool ExtraFileRemove(std::string hash, uint32_t flags) = 0;
|
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferInfoFlags flags) = 0;
|
||||||
virtual bool ExtraFileHash(std::string localpath,
|
|
||||||
uint32_t period, uint32_t flags) = 0;
|
|
||||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
|
||||||
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
||||||
std::string destpath) = 0;
|
std::string destpath) = 0;
|
||||||
|
@ -168,11 +169,13 @@ class RsFiles
|
||||||
*/
|
*/
|
||||||
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) = 0;
|
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) = 0;
|
||||||
|
|
||||||
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
|
virtual int RequestDirDetails(void *ref, DirDetails &details, FileStorageFlags flags) = 0;
|
||||||
virtual uint32_t getType(void *ref,uint32_t flags) = 0;
|
virtual uint32_t getType(void *ref,TransferInfoFlags flags) = 0;
|
||||||
|
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||||
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id) = 0;
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||||
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id) = 0;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions.
|
* Utility Functions.
|
||||||
|
|
29
libretroshare/src/retroshare/rsflags.h
Normal file
29
libretroshare/src/retroshare/rsflags.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
template<int n> class t_RsFlags32
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
t_RsFlags32() {}
|
||||||
|
|
||||||
|
t_RsFlags32(uint32_t N) : _bits(N) {}
|
||||||
|
operator uint32_t() const { return _bits ; }
|
||||||
|
|
||||||
|
t_RsFlags32<n> operator| (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits | f._bits) ; }
|
||||||
|
t_RsFlags32<n> operator^ (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits ^ f._bits) ; }
|
||||||
|
t_RsFlags32<n> operator& (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits & f._bits) ; }
|
||||||
|
|
||||||
|
t_RsFlags32<n> operator|=(const t_RsFlags32<n>& f) { _bits |= f._bits ; return *this ;}
|
||||||
|
t_RsFlags32<n> operator^=(const t_RsFlags32<n>& f) { _bits ^= f._bits ; return *this ;}
|
||||||
|
t_RsFlags32<n> operator&=(const t_RsFlags32<n>& f) { _bits &= f._bits ; return *this ;}
|
||||||
|
|
||||||
|
t_RsFlags32<n> operator~() const { return t_RsFlags32<n>(~_bits) ; }
|
||||||
|
private:
|
||||||
|
uint32_t _bits ;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TRANSFER_INFO_FLAGS_TAG 0x8133ea
|
||||||
|
#define FILE_STORAGE_FLAGS_TAG 0x184738
|
||||||
|
|
||||||
|
typedef t_RsFlags32<TRANSFER_INFO_FLAGS_TAG> TransferInfoFlags ;
|
||||||
|
typedef t_RsFlags32<FILE_STORAGE_FLAGS_TAG > FileStorageFlags ; // this makes it a uint32_t class incompatible with other flag class
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
#include <retroshare/rstypes.h>
|
||||||
|
#include <retroshare/rsfiles.h>
|
||||||
|
|
||||||
/* The Main Interface Class - for information about your Peers
|
/* The Main Interface Class - for information about your Peers
|
||||||
* A peer is another RS instance, means associated with an SSL certificate
|
* A peer is another RS instance, means associated with an SSL certificate
|
||||||
* A same GPG person can have multiple peer running with different SSL certs signed by the same GPG key
|
* A same GPG person can have multiple peer running with different SSL certs signed by the same GPG key
|
||||||
|
@ -211,87 +214,100 @@ class RsPeers
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsPeers() { return; }
|
RsPeers() { return; }
|
||||||
virtual ~RsPeers() { return; }
|
virtual ~RsPeers() { return; }
|
||||||
|
|
||||||
/* Updates ... */
|
/* Updates ... */
|
||||||
virtual bool FriendsChanged() = 0;
|
virtual bool FriendsChanged() = 0;
|
||||||
virtual bool OthersChanged() = 0;
|
virtual bool OthersChanged() = 0;
|
||||||
|
|
||||||
/* Peer Details (Net & Auth) */
|
/* Peer Details (Net & Auth) */
|
||||||
virtual std::string getOwnId() = 0;
|
virtual std::string getOwnId() = 0;
|
||||||
|
|
||||||
virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0;
|
virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0;
|
||||||
virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0;
|
virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0;
|
||||||
//virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0;
|
//virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0;
|
||||||
virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0;
|
virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0;
|
||||||
|
|
||||||
virtual bool isOnline(const std::string &ssl_id) = 0;
|
virtual bool isOnline(const std::string &ssl_id) = 0;
|
||||||
virtual bool isFriend(const std::string &ssl_id) = 0;
|
virtual bool isFriend(const std::string &ssl_id) = 0;
|
||||||
virtual bool isGPGAccepted(const std::string &gpg_id_is_friend) = 0; //
|
virtual bool isGPGAccepted(const std::string &gpg_id_is_friend) = 0; //
|
||||||
virtual std::string getPeerName(const std::string &ssl_or_gpg_id) = 0;
|
virtual std::string getPeerName(const std::string &ssl_or_gpg_id) = 0;
|
||||||
virtual std::string getGPGName(const std::string &gpg_id) = 0;
|
virtual std::string getGPGName(const std::string &gpg_id) = 0;
|
||||||
virtual bool getPeerDetails(const std::string &ssl_or_gpg_id, RsPeerDetails &d) = 0; //get Peer detail accept SSL and PGP certs
|
virtual bool getPeerDetails(const std::string &ssl_or_gpg_id, RsPeerDetails &d) = 0; //get Peer detail accept SSL and PGP certs
|
||||||
|
|
||||||
/* Using PGP Ids */
|
/* Using PGP Ids */
|
||||||
virtual std::string getGPGOwnId() = 0;
|
virtual std::string getGPGOwnId() = 0;
|
||||||
virtual std::string getGPGId(const std::string &sslid_or_gpgid) = 0; //return the gpg id of the given gpg or ssl id
|
virtual std::string getGPGId(const std::string &sslid_or_gpgid) = 0; //return the gpg id of the given gpg or ssl id
|
||||||
virtual bool isKeySupported(const std::string& gpg_ids) = 0;
|
virtual bool isKeySupported(const std::string& gpg_ids) = 0;
|
||||||
virtual bool getGPGAcceptedList(std::list<std::string> &gpg_ids) = 0;
|
virtual bool getGPGAcceptedList(std::list<std::string> &gpg_ids) = 0;
|
||||||
virtual bool getGPGSignedList(std::list<std::string> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key
|
virtual bool getGPGSignedList(std::list<std::string> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key
|
||||||
virtual bool getGPGValidList(std::list<std::string> &gpg_ids) = 0;
|
virtual bool getGPGValidList(std::list<std::string> &gpg_ids) = 0;
|
||||||
virtual bool getGPGAllList(std::list<std::string> &gpg_ids) = 0;
|
virtual bool getGPGAllList(std::list<std::string> &gpg_ids) = 0;
|
||||||
virtual bool getGPGDetails(const std::string &gpg_id, RsPeerDetails &d) = 0;
|
virtual bool getGPGDetails(const std::string &gpg_id, RsPeerDetails &d) = 0;
|
||||||
virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list<std::string> &ids) = 0;
|
virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list<std::string> &ids) = 0;
|
||||||
|
|
||||||
/* Add/Remove Friends */
|
/* Add/Remove Friends */
|
||||||
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id) = 0;
|
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id) = 0;
|
||||||
virtual bool removeFriend(const std::string &ssl_or_gpg_id) = 0;
|
virtual bool removeFriend(const std::string &ssl_or_gpg_id) = 0;
|
||||||
virtual bool removeFriendLocation(const std::string &sslId) = 0;
|
virtual bool removeFriendLocation(const std::string &sslId) = 0;
|
||||||
|
|
||||||
/* Network Stuff */
|
/* Network Stuff */
|
||||||
virtual bool connectAttempt(const std::string &ssl_id) = 0;
|
virtual bool connectAttempt(const std::string &ssl_id) = 0;
|
||||||
virtual bool setLocation(const std::string &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs
|
virtual bool setLocation(const std::string &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs
|
||||||
virtual bool setLocalAddress(const std::string &ssl_id, const std::string &addr, uint16_t port) = 0;
|
virtual bool setLocalAddress(const std::string &ssl_id, const std::string &addr, uint16_t port) = 0;
|
||||||
virtual bool setExtAddress( const std::string &ssl_id, const std::string &addr, uint16_t port) = 0;
|
virtual bool setExtAddress( const std::string &ssl_id, const std::string &addr, uint16_t port) = 0;
|
||||||
virtual bool setDynDNS(const std::string &id, const std::string &addr) = 0;
|
virtual bool setDynDNS(const std::string &id, const std::string &addr) = 0;
|
||||||
virtual bool setNetworkMode(const std::string &ssl_id, uint32_t netMode) = 0;
|
virtual bool setNetworkMode(const std::string &ssl_id, uint32_t netMode) = 0;
|
||||||
virtual bool setVisState(const std::string &ssl_id, uint32_t vis) = 0;
|
virtual bool setVisState(const std::string &ssl_id, uint32_t vis) = 0;
|
||||||
|
|
||||||
virtual void getIPServersList(std::list<std::string>& ip_servers) = 0;
|
virtual void getIPServersList(std::list<std::string>& ip_servers) = 0;
|
||||||
virtual void allowServerIPDetermination(bool) = 0;
|
virtual void allowServerIPDetermination(bool) = 0;
|
||||||
virtual void allowTunnelConnection(bool) = 0;
|
virtual void allowTunnelConnection(bool) = 0;
|
||||||
virtual bool getAllowServerIPDetermination() = 0 ;
|
virtual bool getAllowServerIPDetermination() = 0 ;
|
||||||
virtual bool getAllowTunnelConnection() = 0 ;
|
virtual bool getAllowTunnelConnection() = 0 ;
|
||||||
|
|
||||||
/* Auth Stuff */
|
/* Auth Stuff */
|
||||||
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format = false) = 0;
|
virtual std::string GetRetroshareInvite(const std::string& ssl_id,bool include_signatures,bool old_format = false) = 0;
|
||||||
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0 ;
|
virtual bool GetPGPBase64StringAndCheckSum(const std::string& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0 ;
|
||||||
virtual std::string GetRetroshareInvite(bool include_signatures,bool old_format = false) = 0;
|
virtual std::string GetRetroshareInvite(bool include_signatures,bool old_format = false) = 0;
|
||||||
virtual bool hasExportMinimal() = 0 ;
|
virtual bool hasExportMinimal() = 0 ;
|
||||||
|
|
||||||
// Add keys to the keyring
|
// Add keys to the keyring
|
||||||
virtual bool loadCertificateFromFile(const std::string &fname, std::string &ssl_id, std::string &gpg_id) = 0;
|
virtual bool loadCertificateFromFile(const std::string &fname, std::string &ssl_id, std::string &gpg_id) = 0;
|
||||||
virtual bool loadCertificateFromString(const std::string &cert, std::string &ssl_id, std::string &gpg_id) = 0;
|
virtual bool loadCertificateFromString(const std::string &cert, std::string &ssl_id, std::string &gpg_id) = 0;
|
||||||
|
|
||||||
// Gets the GPG details, but does not add the key to the keyring.
|
// Gets the GPG details, but does not add the key to the keyring.
|
||||||
virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,std::string& error_string) = 0;
|
virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,std::string& error_string) = 0;
|
||||||
|
|
||||||
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0;
|
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0;
|
||||||
virtual bool saveCertificateToFile(const std::string &id, const std::string &fname) = 0;
|
virtual bool saveCertificateToFile(const std::string &id, const std::string &fname) = 0;
|
||||||
virtual std::string saveCertificateToString(const std::string &id) = 0;
|
virtual std::string saveCertificateToString(const std::string &id) = 0;
|
||||||
|
|
||||||
virtual bool signGPGCertificate(const std::string &gpg_id) = 0;
|
virtual bool signGPGCertificate(const std::string &gpg_id) = 0;
|
||||||
virtual bool trustGPGCertificate(const std::string &gpg_id, uint32_t trustlvl) = 0;
|
virtual bool trustGPGCertificate(const std::string &gpg_id, uint32_t trustlvl) = 0;
|
||||||
|
|
||||||
/* Group Stuff */
|
/* Group Stuff */
|
||||||
virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
|
virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
|
||||||
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
||||||
virtual bool removeGroup(const std::string &groupId) = 0;
|
virtual bool removeGroup(const std::string &groupId) = 0;
|
||||||
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
|
||||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
|
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
|
||||||
// groupId == "" && assign == false -> remove from all groups
|
// groupId == "" && assign == false -> remove from all groups
|
||||||
virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign) = 0;
|
virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign) = 0;
|
||||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign) = 0;
|
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign) = 0;
|
||||||
|
|
||||||
|
/* Group sharing permission */
|
||||||
|
|
||||||
|
// Given
|
||||||
|
// - the peer id
|
||||||
|
// - the permission flags of a given hash, e.g. a combination of
|
||||||
|
// RS_DIR_FLAGS_NETWORK_WIDE_OTHERS, RS_DIR_FLAGS_NETWORK_WIDE_GROUPS, RS_DIR_FLAGS_BROWSABLE_OTHERS and RS_DIR_FLAGS_BROWSABLE_GROUPS
|
||||||
|
// - the parent groups of the file
|
||||||
|
//
|
||||||
|
// ... computes the sharing file permission hint flags set for this peer, that is a combination of
|
||||||
|
// RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE.
|
||||||
|
//
|
||||||
|
virtual TransferInfoFlags computePeerPermissionFlags(const std::string& peer_id,FileStorageFlags file_sharing_flags,const std::list<std::string>& file_parent_groups) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <retroshare/rsflags.h>
|
||||||
|
|
||||||
#define USE_NEW_CHUNK_CHECKING_CODE
|
#define USE_NEW_CHUNK_CHECKING_CODE
|
||||||
|
|
||||||
typedef std::string RsCertId;
|
typedef std::string RsCertId;
|
||||||
|
@ -94,54 +96,6 @@ enum DwlSpeed { SPEED_LOW = 0x00,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FileInfo
|
|
||||||
{
|
|
||||||
/* old BaseInfo Entries */
|
|
||||||
public:
|
|
||||||
|
|
||||||
FileInfo() :flags(0), mId(0) { return; }
|
|
||||||
RsCertId id; /* key for matching everything */
|
|
||||||
int flags; /* INFO_TAG above */
|
|
||||||
|
|
||||||
/* allow this to be tweaked by the GUI Model */
|
|
||||||
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
|
|
||||||
|
|
||||||
/* Old FileInfo Entries */
|
|
||||||
public:
|
|
||||||
|
|
||||||
static const int kRsFiStatusNone = 0;
|
|
||||||
static const int kRsFiStatusStall = 1;
|
|
||||||
static const int kRsFiStatusProgress = 2;
|
|
||||||
static const int kRsFiStatusDone = 2;
|
|
||||||
|
|
||||||
/* FileInfo(); */
|
|
||||||
|
|
||||||
int searchId; /* 0 if none */
|
|
||||||
std::string path;
|
|
||||||
std::string fname;
|
|
||||||
std::string hash;
|
|
||||||
std::string ext;
|
|
||||||
|
|
||||||
uint64_t size;
|
|
||||||
uint64_t avail; /* how much we have */
|
|
||||||
int status;
|
|
||||||
|
|
||||||
double rank;
|
|
||||||
int age;
|
|
||||||
uint32_t queue_position ;
|
|
||||||
|
|
||||||
/* Transfer Stuff */
|
|
||||||
uint64_t transfered;
|
|
||||||
double tfRate; /* in kbytes */
|
|
||||||
uint32_t downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
|
|
||||||
std::list<TransferInfo> peers;
|
|
||||||
|
|
||||||
DwlSpeed priority ;
|
|
||||||
time_t lastTS;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const FileInfo &info);
|
|
||||||
|
|
||||||
|
|
||||||
/* matched to the uPnP states */
|
/* matched to the uPnP states */
|
||||||
#define UPNP_STATE_UNINITIALISED 0
|
#define UPNP_STATE_UNINITIALISED 0
|
||||||
|
@ -248,16 +202,72 @@ class SearchRequest
|
||||||
* (TODO)
|
* (TODO)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DIR_FLAGS_LOCAL 0x1000
|
const FileStorageFlags DIR_FLAGS_PARENT = 0x0001;
|
||||||
#define DIR_FLAGS_REMOTE 0x2000
|
const FileStorageFlags DIR_FLAGS_DETAILS = 0x0002;
|
||||||
|
const FileStorageFlags DIR_FLAGS_CHILDREN = 0x0004;
|
||||||
|
|
||||||
|
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_OTHERS = 0x0080; // Flags for directory sharing permissions. The last
|
||||||
|
const FileStorageFlags DIR_FLAGS_BROWSABLE_OTHERS = 0x0100; // one should be the OR of the all four flags.
|
||||||
|
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_GROUPS = 0x0200;
|
||||||
|
const FileStorageFlags DIR_FLAGS_BROWSABLE_GROUPS = 0x0400;
|
||||||
|
const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK = DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_OTHERS
|
||||||
|
| DIR_FLAGS_NETWORK_WIDE_GROUPS | DIR_FLAGS_BROWSABLE_GROUPS ;
|
||||||
|
|
||||||
|
const FileStorageFlags DIR_FLAGS_LOCAL = 0x1000;
|
||||||
|
const FileStorageFlags DIR_FLAGS_REMOTE = 0x2000;
|
||||||
|
|
||||||
|
class FileInfo
|
||||||
|
{
|
||||||
|
/* old BaseInfo Entries */
|
||||||
|
public:
|
||||||
|
|
||||||
|
FileInfo() : mId(0) { return; }
|
||||||
|
RsCertId id; /* key for matching everything */
|
||||||
|
|
||||||
|
FileStorageFlags storage_permission_flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file.
|
||||||
|
TransferInfoFlags transfer_info_flags ; // various flags from RS_FILE_HINTS_*
|
||||||
|
|
||||||
|
/* allow this to be tweaked by the GUI Model */
|
||||||
|
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
|
||||||
|
|
||||||
|
/* Old FileInfo Entries */
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const int kRsFiStatusNone = 0;
|
||||||
|
static const int kRsFiStatusStall = 1;
|
||||||
|
static const int kRsFiStatusProgress = 2;
|
||||||
|
static const int kRsFiStatusDone = 2;
|
||||||
|
|
||||||
|
/* FileInfo(); */
|
||||||
|
|
||||||
|
int searchId; /* 0 if none */
|
||||||
|
std::string path;
|
||||||
|
std::string fname;
|
||||||
|
std::string hash;
|
||||||
|
std::string ext;
|
||||||
|
|
||||||
|
uint64_t size;
|
||||||
|
uint64_t avail; /* how much we have */
|
||||||
|
int status;
|
||||||
|
|
||||||
|
double rank;
|
||||||
|
int age;
|
||||||
|
uint32_t queue_position ;
|
||||||
|
|
||||||
|
/* Transfer Stuff */
|
||||||
|
uint64_t transfered;
|
||||||
|
double tfRate; /* in kbytes */
|
||||||
|
uint32_t downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
|
||||||
|
std::list<TransferInfo> peers;
|
||||||
|
|
||||||
|
DwlSpeed priority ;
|
||||||
|
time_t lastTS;
|
||||||
|
|
||||||
|
std::list<std::string> parent_groups ;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const FileInfo &info);
|
||||||
|
|
||||||
#define DIR_FLAGS_PARENT 0x0001
|
|
||||||
#define DIR_FLAGS_DETAILS 0x0002
|
|
||||||
#define DIR_FLAGS_CHILDREN 0x0004
|
|
||||||
#define DIR_FLAGS_NETWORK_WIDE_OTHERS 0x0008
|
|
||||||
#define DIR_FLAGS_BROWSABLE_OTHERS 0x0010
|
|
||||||
#define DIR_FLAGS_NETWORK_WIDE_GROUPS 0x0020
|
|
||||||
#define DIR_FLAGS_BROWSABLE_GROUPS 0x0040
|
|
||||||
|
|
||||||
class DirStub
|
class DirStub
|
||||||
{
|
{
|
||||||
|
@ -281,11 +291,11 @@ class DirDetails
|
||||||
std::string path;
|
std::string path;
|
||||||
uint64_t count;
|
uint64_t count;
|
||||||
uint32_t age;
|
uint32_t age;
|
||||||
uint32_t flags;
|
FileStorageFlags flags;
|
||||||
uint32_t min_age ; // minimum age of files in this subtree
|
uint32_t min_age ; // minimum age of files in this subtree
|
||||||
|
|
||||||
std::list<DirStub> children;
|
std::list<DirStub> children;
|
||||||
std::list<std::string> groups; // parent groups for the shared directory
|
std::list<std::string> parent_groups; // parent groups for the shared directory
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileDetail
|
class FileDetail
|
||||||
|
|
|
@ -1100,6 +1100,38 @@ bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<std
|
||||||
return mPeerMgr->assignPeersToGroup(groupId, peerIds, assign);
|
return mPeerMgr->assignPeersToGroup(groupId, peerIds, assign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TransferInfoFlags p3Peers::computePeerPermissionFlags(const std::string& peer_id,
|
||||||
|
FileStorageFlags share_flags,
|
||||||
|
const std::list<std::string>& directory_parent_groups)
|
||||||
|
{
|
||||||
|
// We should be able to do that in O(1), using groups based on packs of bits.
|
||||||
|
//
|
||||||
|
// But for now, because the implementation of groups is not totally decided yet, we revert to this
|
||||||
|
// very simple algorithm.
|
||||||
|
//
|
||||||
|
|
||||||
|
TransferInfoFlags final_flags = 0 ;
|
||||||
|
bool found = false ;
|
||||||
|
|
||||||
|
for(std::list<std::string>::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it)
|
||||||
|
{
|
||||||
|
RsGroupInfo info ;
|
||||||
|
if(!getGroupInfo(*it,info))
|
||||||
|
{
|
||||||
|
std::cerr << "(EE) p3Peers::computePeerPermissionFlags: no group named " << *it << ": cannot get info." << std::endl;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::list<std::string>::const_iterator it2(info.peerIds.begin());it2!=info.peerIds.end() && !found;++it2)
|
||||||
|
if(*it2 == peer_id)
|
||||||
|
found = true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool network_wide = (share_flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) || ( (share_flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) && found) ;
|
||||||
|
bool browsable = (share_flags & DIR_FLAGS_BROWSABLE_OTHERS) || ( (share_flags & DIR_FLAGS_BROWSABLE_GROUPS) && found) ;
|
||||||
|
|
||||||
|
return network_wide * RS_FILE_HINTS_NETWORK_WIDE + browsable * RS_FILE_HINTS_BROWSABLE ;
|
||||||
|
}
|
||||||
|
|
||||||
RsPeerDetails::RsPeerDetails()
|
RsPeerDetails::RsPeerDetails()
|
||||||
:isOnlyGPGdetail(false),
|
:isOnlyGPGdetail(false),
|
||||||
|
|
|
@ -121,6 +121,7 @@ virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
|
||||||
virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign);
|
virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign);
|
||||||
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign);
|
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign);
|
||||||
|
|
||||||
|
virtual TransferInfoFlags computePeerPermissionFlags(const std::string& peer_id,FileStorageFlags share_flags,const std::list<std::string>& parent_groups) ;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
p3LinkMgr *mLinkMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
|
@ -1840,7 +1840,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
found = (_sharing_strategy != SHARE_FRIENDS_ONLY || item->depth < 2) && performLocalHashSearch(item->file_hash,info) ;
|
found = (_sharing_strategy != SHARE_FRIENDS_ONLY || item->depth < 2) && performLocalHashSearch(item->file_hash,item->PeerId(),info) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -2092,7 +2092,7 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
||||||
std::cerr << "Performing rsFiles->search()" << std::endl ;
|
std::cerr << "Performing rsFiles->search()" << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
// now, search!
|
// now, search!
|
||||||
rsFiles->SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE);
|
rsFiles->SearchKeywords(words, initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId());
|
||||||
|
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << initialResults.size() << " matches found." << std::endl ;
|
std::cerr << initialResults.size() << " matches found." << std::endl ;
|
||||||
|
@ -2130,12 +2130,20 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
// now, search!
|
// now, search!
|
||||||
rsFiles->SearchBoolExp(exp,initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE);
|
rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId());
|
||||||
|
|
||||||
result.clear() ;
|
result.clear() ;
|
||||||
|
|
||||||
for(std::list<DirDetails>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
|
for(std::list<DirDetails>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
|
||||||
{
|
{
|
||||||
|
// retain only file type
|
||||||
|
if (it->type == DIR_TYPE_DIR)
|
||||||
|
{
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << " Skipping directory " << it->name << std::endl ;
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
TurtleFileInfo i ;
|
TurtleFileInfo i ;
|
||||||
i.hash = it->hash ;
|
i.hash = it->hash ;
|
||||||
i.size = it->count ;
|
i.size = it->count ;
|
||||||
|
@ -2276,9 +2284,25 @@ void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
|
||||||
/// Warning: this function should never be called while the turtle mutex is locked.
|
/// Warning: this function should never be called while the turtle mutex is locked.
|
||||||
/// Otherwize this is a possible source of cross-lock with the File mutex.
|
/// Otherwize this is a possible source of cross-lock with the File mutex.
|
||||||
//
|
//
|
||||||
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info)
|
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const std::string& peer_id,FileInfo& info)
|
||||||
{
|
{
|
||||||
return rsFiles->FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info);
|
bool res = rsFiles->FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info);
|
||||||
|
|
||||||
|
// The call to computeHashPeerClearance() return a combination of RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE
|
||||||
|
// This is an additional computation cost, but the way it's written here, it's only called when res is true.
|
||||||
|
//
|
||||||
|
res = res && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ;
|
||||||
|
|
||||||
|
std::cerr << "p3turtle: performing local hash search for hash " << hash << std::endl;
|
||||||
|
|
||||||
|
if(res)
|
||||||
|
{
|
||||||
|
std::cerr << "Found hash: " << std::endl;
|
||||||
|
std::cerr << " peer = " << peer_id << std::endl;
|
||||||
|
std::cerr << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string printFloatNumber(float num,bool friendly=false)
|
static std::string printFloatNumber(float num,bool friendly=false)
|
||||||
|
|
|
@ -213,7 +213,7 @@ class TurtleFileHashInfo
|
||||||
// p3Config | ConfigChanged() | used to load/save .cfg file for turtle variales.
|
// p3Config | ConfigChanged() | used to load/save .cfg file for turtle variales.
|
||||||
// -----------+------------------+------------------------------------------------------
|
// -----------+------------------+------------------------------------------------------
|
||||||
//
|
//
|
||||||
class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* public ftSearch */ public p3Config
|
class p3turtle: public p3Service, public RsTurtle, public p3Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3turtle(p3LinkMgr *lm,ftServer *m);
|
p3turtle(p3LinkMgr *lm,ftServer *m);
|
||||||
|
@ -371,8 +371,8 @@ class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* publ
|
||||||
/// Returns a search result upwards (possibly to the gui)
|
/// Returns a search result upwards (possibly to the gui)
|
||||||
void returnSearchResult(RsTurtleSearchResultItem *item) ;
|
void returnSearchResult(RsTurtleSearchResultItem *item) ;
|
||||||
|
|
||||||
/// Returns true if the file with given hash is hosted locally.
|
/// Returns true if the file with given hash is hosted locally, and accessible in anonymous mode the supplied peer.
|
||||||
virtual bool performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info) ;
|
virtual bool performLocalHashSearch(const TurtleFileHash& hash,const std::string& client_peer_id,FileInfo& info) ;
|
||||||
|
|
||||||
//--------------------------- Local variables --------------------------------//
|
//--------------------------- Local variables --------------------------------//
|
||||||
|
|
||||||
|
|
|
@ -339,9 +339,9 @@ void QuickStartWizard::updateFlags(bool b)
|
||||||
for(it = dirs.begin(); it != dirs.end(); it++,++row)
|
for(it = dirs.begin(); it != dirs.end(); it++,++row)
|
||||||
{
|
{
|
||||||
std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ;
|
std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ;
|
||||||
uint32_t current_flags = 0 ;
|
TransferInfoFlags current_flags = 0u ;
|
||||||
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,1)))->isChecked()? RS_FILE_HINTS_NETWORK_WIDE:0 ;
|
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,1)))->isChecked()? RS_FILE_HINTS_NETWORK_WIDE:(TransferInfoFlags)0u ;
|
||||||
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,2)))->isChecked()? RS_FILE_HINTS_BROWSABLE:0 ;
|
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,2)))->isChecked()? RS_FILE_HINTS_BROWSABLE:(TransferInfoFlags)0u ;
|
||||||
|
|
||||||
if( (*it).shareflags ^ current_flags )
|
if( (*it).shareflags ^ current_flags )
|
||||||
{
|
{
|
||||||
|
|
|
@ -204,12 +204,12 @@ int FlatStyle_RDM::columnCount(const QModelIndex &/*parent*/) const
|
||||||
}
|
}
|
||||||
QString RetroshareDirModel::getFlagsString(uint32_t flags)
|
QString RetroshareDirModel::getFlagsString(uint32_t flags)
|
||||||
{
|
{
|
||||||
char str[5] = "----" ;
|
char str[8] = "- - - -" ;
|
||||||
|
|
||||||
if(flags & DIR_FLAGS_BROWSABLE_GROUPS) str[0] = 'B' ;
|
if(flags & DIR_FLAGS_BROWSABLE_GROUPS) str[0] = 'B' ;
|
||||||
if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) str[1] = 'N' ;
|
if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) str[2] = 'N' ;
|
||||||
if(flags & DIR_FLAGS_BROWSABLE_OTHERS) str[2] = 'B' ;
|
if(flags & DIR_FLAGS_BROWSABLE_OTHERS) str[4] = 'B' ;
|
||||||
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) str[3] = 'N' ;
|
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) str[6] = 'N' ;
|
||||||
|
|
||||||
return QString(str) ;
|
return QString(str) ;
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
||||||
// return ind;
|
// return ind;
|
||||||
// }
|
// }
|
||||||
case 4:
|
case 4:
|
||||||
return getGroupsString(details.groups) ;
|
return getGroupsString(details.parent_groups) ;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return tr("FILE");
|
return tr("FILE");
|
||||||
|
@ -364,7 +364,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
||||||
case 3:
|
case 3:
|
||||||
return getFlagsString(details.flags);
|
return getFlagsString(details.flags);
|
||||||
case 4:
|
case 4:
|
||||||
return getGroupsString(details.groups) ;
|
return getGroupsString(details.parent_groups) ;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return tr("DIR");
|
return tr("DIR");
|
||||||
|
|
|
@ -614,7 +614,7 @@ void SearchDialog::advancedSearch(Expression* expression)
|
||||||
// The text "bool exp" should be replaced by an appropriate text describing the actual search.
|
// The text "bool exp" should be replaced by an appropriate text describing the actual search.
|
||||||
initSearchResult("bool exp",req_id, ui.FileTypeComboBox->currentIndex(), true) ;
|
initSearchResult("bool exp",req_id, ui.FileTypeComboBox->currentIndex(), true) ;
|
||||||
|
|
||||||
rsFiles -> SearchBoolExp(expression, results, DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
rsFiles -> SearchBoolExp(expression, results, DIR_FLAGS_REMOTE);// | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
||||||
|
|
||||||
/* abstraction to allow reusee of tree rendering code */
|
/* abstraction to allow reusee of tree rendering code */
|
||||||
resultsToTree(advSearchDialog->getSearchAsString(),req_id, results);
|
resultsToTree(advSearchDialog->getSearchAsString(),req_id, results);
|
||||||
|
@ -712,7 +712,7 @@ void SearchDialog::searchKeywords(const QString& keywords)
|
||||||
{
|
{
|
||||||
std::list<DirDetails> initialResults;
|
std::list<DirDetails> initialResults;
|
||||||
|
|
||||||
rsFiles->SearchBoolExp(&exprs, initialResults, DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE) ;
|
rsFiles->SearchBoolExp(&exprs, initialResults, DIR_FLAGS_LOCAL);// | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE) ;
|
||||||
|
|
||||||
/* which extensions do we use? */
|
/* which extensions do we use? */
|
||||||
DirDetails dd;
|
DirDetails dd;
|
||||||
|
|
|
@ -945,7 +945,7 @@ void TransfersDialog::insertTransfers()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fileInfo.flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers) {
|
if ((fileInfo.transfer_info_flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers) {
|
||||||
// if file transfer is a cache file index file, don't show it
|
// if file transfer is a cache file index file, don't show it
|
||||||
DLListModel->removeRow(row);
|
DLListModel->removeRow(row);
|
||||||
rowCount = DLListModel->rowCount();
|
rowCount = DLListModel->rowCount();
|
||||||
|
@ -971,7 +971,7 @@ void TransfersDialog::insertTransfers()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fileInfo.flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers) {
|
if ((fileInfo.transfer_info_flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers) {
|
||||||
//if file transfer is a cache file index file, don't show it
|
//if file transfer is a cache file index file, don't show it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -998,7 +998,7 @@ void TransfersDialog::insertTransfers()
|
||||||
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info))
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if((info.flags & RS_FILE_HINTS_CACHE) && showCacheTransfers)
|
if((info.transfer_info_flags & RS_FILE_HINTS_CACHE) && showCacheTransfers)
|
||||||
continue ;
|
continue ;
|
||||||
|
|
||||||
std::list<TransferInfo>::iterator pit;
|
std::list<TransferInfo>::iterator pit;
|
||||||
|
|
|
@ -48,10 +48,10 @@ GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,uint32_t flags)
|
||||||
|
|
||||||
setLayout(_layout) ;
|
setLayout(_layout) ;
|
||||||
|
|
||||||
_flags[0] = RS_FILE_HINTS_BROWSABLE_GROUPS ;
|
_flags[0] = DIR_FLAGS_BROWSABLE_GROUPS ;
|
||||||
_flags[1] = RS_FILE_HINTS_NETWORK_WIDE_GROUPS ;
|
_flags[1] = DIR_FLAGS_NETWORK_WIDE_GROUPS ;
|
||||||
_flags[2] = RS_FILE_HINTS_BROWSABLE_OTHERS ;
|
_flags[2] = DIR_FLAGS_BROWSABLE_OTHERS ;
|
||||||
_flags[3] = RS_FILE_HINTS_NETWORK_WIDE_OTHERS ;
|
_flags[3] = DIR_FLAGS_NETWORK_WIDE_OTHERS ;
|
||||||
|
|
||||||
for(int i=0;i<4;++i)
|
for(int i=0;i<4;++i)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue