diff --git a/libbitdht/src/bitdht/bdnode.cc b/libbitdht/src/bitdht/bdnode.cc index 5d4a73456..9958cf040 100644 --- a/libbitdht/src/bitdht/bdnode.cc +++ b/libbitdht/src/bitdht/bdnode.cc @@ -66,7 +66,7 @@ //#define DISABLE_BAD_PEER_FILTER 1 -//#define USE_HISTORY 1 +#define USE_HISTORY 1 #define HISTORY_PERIOD 60 @@ -806,10 +806,10 @@ void bdNode::msgout_ping(bdId *id, bdToken *transId) // THIS IS CRASHING HISTORY. // LIKELY ID is not always valid! // Either PotentialPeers or Out-Of-Date Peers. - //registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_PING); + registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_PING); - bdId dupId(*id); - registerOutgoingMsg(&dupId, transId, BITDHT_MSG_TYPE_PING); + //bdId dupId(*id); + //registerOutgoingMsg(&dupId, transId, BITDHT_MSG_TYPE_PING); /* create string */ char msg[10240]; diff --git a/libretroshare/src/dbase/cachestrapper.cc b/libretroshare/src/dbase/cachestrapper.cc index 9540bec3a..48d0cc110 100644 --- a/libretroshare/src/dbase/cachestrapper.cc +++ b/libretroshare/src/dbase/cachestrapper.cc @@ -92,38 +92,70 @@ bool CacheSource::loadLocalCache(const CacheData &data) } /* control Caches available */ -bool CacheSource::refreshCache(const CacheData &data) +bool CacheSource::refreshCache(const CacheData &data,const std::list& destination_peers) { - lockData(); /* LOCK MUTEX */ - bool ret = false; - if (data.cid.type == getCacheType()) { - int subid = 0; - if (isMultiCache()) - { - subid = data.cid.subid; - } + RsStackMutex mtx(cMutex); /* LOCK MUTEX */ - /* Backup the old Caches */ - CacheSet::const_iterator it; - if (caches.end() != (it = caches.find(subid))) + if (data.cid.type == getCacheType()) { - mOldCaches[it->second.hash] = it->second; - } + int subid = 0; + if (isMultiCache()) + { + subid = data.cid.subid; + } - /* store new cache */ - caches[subid] = data; - ret = true; + /* 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; + } } - 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 */ mStrapper->refreshCache(data); + return ret; -} - +} bool CacheSource::clearCache(CacheId id) { lockData(); /* LOCK MUTEX */ @@ -567,6 +599,26 @@ void CacheStrapper::statusChange(const std::list &plist) /**************** from pqimonclient ********************/ +void CacheStrapper::refreshCache(const CacheData &data,const std::list& 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::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) { @@ -578,26 +630,12 @@ void CacheStrapper::refreshCache(const CacheData &data) #endif std::list ids; - std::list::iterator it; - mLinkMgr->getOnlineList(ids); + ids.push_back(mLinkMgr->getOwnId()) ; - RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/ - 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! *****/ + refreshCache(data,ids) ; } - void CacheStrapper::refreshCacheStore(const CacheData & /* data */ ) { /* indicate to save data */ diff --git a/libretroshare/src/dbase/cachestrapper.h b/libretroshare/src/dbase/cachestrapper.h index d8a769b3b..1553f4ce0 100644 --- a/libretroshare/src/dbase/cachestrapper.h +++ b/libretroshare/src/dbase/cachestrapper.h @@ -181,7 +181,8 @@ class CacheSource virtual bool loadLocalCache(const CacheData &data); /* control Caches available */ - bool refreshCache(const CacheData &data); + bool refreshCache(const CacheData &data,const std::list& destination_peers); + bool refreshCache(const CacheData &data); bool clearCache(CacheId id); /* get private data */ @@ -394,11 +395,12 @@ virtual void statusChange(const std::list &plist); /* Feedback from CacheSources */ /*! - * send data to peers online and selfe + * send data to peers online and self * @param data * */ void refreshCache(const CacheData &data); +void refreshCache(const CacheData &data,const std::list& destination_peers); // specify a particular list of destination peers (self not added!) /*! * forces config savelist diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index 9b81c9652..a7f02a699 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -30,6 +30,7 @@ #include "serialiser/rsserviceids.h" #include "retroshare/rsiface.h" #include "retroshare/rsnotify.h" +#include "retroshare/rspeers.h" #include "util/folderiterator.h" #include @@ -266,7 +267,7 @@ FileIndexMonitor::~FileIndexMonitor() /* Data cleanup - TODO */ } -int FileIndexMonitor::SearchKeywords(std::list keywords, std::list &results,uint32_t flags) +int FileIndexMonitor::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) { results.clear(); std::list firesults; @@ -276,10 +277,10 @@ int FileIndexMonitor::SearchKeywords(std::list keywords, std::list< fi.searchTerms(keywords, firesults); } - return filterResults(firesults,results,flags) ; + return filterResults(firesults,results,flags,peer_id) ; } -int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list& results,uint32_t flags) const +int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list& results,FileSearchFlags flags,const std::string& peer_id) const { results.clear(); std::list firesults; @@ -289,38 +290,50 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list& resu fi.searchBoolExp(exp, firesults); } - return filterResults(firesults,results,flags) ; + return filterResults(firesults,results,flags,peer_id) ; } -int FileIndexMonitor::filterResults(std::list& firesults,std::list& results,uint32_t flags) const +int FileIndexMonitor::filterResults(std::list& firesults,std::list& results,FileSearchFlags 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 */ for(std::list::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit) { DirDetails cdetails ; - RequestDirDetails (*rit,cdetails,0); + RequestDirDetails (*rit,cdetails,FileSearchFlags(0u)); #ifdef FIM_DEBUG - std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags ; + std::cerr << "Filtering candidate " << (*rit)->name << ", flags=" << cdetails.flags << ", peer=" << peer_id ; #endif - if (cdetails.type == DIR_TYPE_FILE && ( cdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0) + if(!peer_id.empty()) { - cdetails.id = "Local"; - results.push_back(cdetails); + FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(peer_id,cdetails.flags,cdetails.parent_groups) ; + + if (cdetails.type == DIR_TYPE_FILE && ( permission_flags & flags )) + { + cdetails.id = "Local"; + results.push_back(cdetails); #ifdef FIM_DEBUG - std::cerr << ": kept" << std::endl ; + std::cerr << ": kept" << std::endl ; +#endif + } +#ifdef FIM_DEBUG + else + std::cerr << ": discarded" << std::endl ; #endif } -#ifdef FIM_DEBUG else - std::cerr << ": discarded" << std::endl ; -#endif + results.push_back(cdetails); } + 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,FileSearchFlags hint_flags, const std::string& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list& parent_groups) const { std::list results; bool ok = false; @@ -340,12 +353,16 @@ bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t hint_flags, std:: FileEntry *fe = results.front(); DirEntry *de = fe->parent; /* all files must have a valid parent! */ - uint32_t share_flags = locked_findShareFlags(fe) ; + locked_findShareFlagsAndParentGroups(fe,storage_flags,parent_groups) ; + + // turn share flags into hint flags + + FileSearchFlags shflh = peer_id.empty()?(RS_FILE_HINTS_BROWSABLE|RS_FILE_HINTS_NETWORK_WIDE):rsPeers->computePeerPermissionFlags(peer_id,storage_flags,parent_groups) ; #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=" << storage_flags << ", hint_flags=" << hint_flags << ", peer_id = " << peer_id << std::endl ; #endif - if((share_flags & hint_flags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE)) > 0) + if(peer_id.empty() || (shflh & hint_flags)) { #ifdef FIM_DEBUG std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl; @@ -423,7 +440,11 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto /* 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' ; if ((ok = fi.loadIndex(data.path + '/' + name, "", data.size))) @@ -445,17 +466,18 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto fi.updateMaxModTime() ; } - +#ifdef REMOVED if (ok) { return updateCache(data); } +#endif return false; } -bool FileIndexMonitor::updateCache(const CacheData &data) /* we call this one */ +bool FileIndexMonitor::updateCache(const CacheData &data,const std::list& destination_peers) /* we call this one */ { - return refreshCache(data); + return refreshCache(data,destination_peers); } @@ -514,13 +536,13 @@ void FileIndexMonitor::run() updateCycle(); #ifdef FIM_DEBUG - { - RsStackMutex mtx(fiMutex) ; - std::cerr <<"*********** FileIndex **************" << std::endl ; - fi.printFileIndex(std::cerr) ; - std::cerr <<"************** END *****************" << std::endl ; - std::cerr << std::endl ; - } +// { +// RsStackMutex mtx(fiMutex) ; +// std::cerr <<"*********** FileIndex **************" << std::endl ; +// fi.printFileIndex(std::cerr) ; +// std::cerr <<"************** END *****************" << std::endl ; +// std::cerr << std::endl ; +// } #endif } } @@ -801,7 +823,7 @@ void FileIndexMonitor::updateCycle() #ifdef FIM_DEBUG /* print out the new directory structure */ - fi.printFileIndex(std::cerr); +// fi.printFileIndex(std::cerr); #endif /* now if we have changed things -> restore file/hash it/and * tell the CacheSource @@ -986,67 +1008,107 @@ void FileIndexMonitor::locked_saveFileIndexes() std::string path = getCacheDir(); - // Two files are saved: one with only browsable dirs, which will be shared by the cache system, - // and one with the complete file collection. + // Multiple files are saved: for every kind of peers, the set of browsable files will be different. A specific file is + // 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 - std::cerr << "FileIndexMonitor::updateCycle() FileIndex modified ... updating"; - 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() FileIndex modified ... updating" << std::endl; #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 online_ids ; + rsPeers->getOnlineList(online_ids); - std::string calchash; - uint64_t size; + std::map, std::list > peers_per_directory_combination ; - std::cerr << "About to save, with the following restrictions:" << std::endl ; - std::set forbidden_dirs ; - for(std::map::const_iterator it(directoryMap.begin());it!=directoryMap.end();++it) + for(std::list::const_iterator it(online_ids.begin());it!=online_ids.end();++it) { - std::cerr << " dir=" << it->first << " : " ; - if((it->second.shareflags & RS_FILE_HINTS_BROWSABLE) == 0) + std::cerr << "About to save, with the following restrictions:" << std::endl ; + std::cerr << "Peer : " << *it << std::endl; + + std::set forbidden_dirs ; + for(std::map::const_iterator dit(directoryMap.begin());dit!=directoryMap.end();++dit) { - std::cerr << "forbidden" << std::endl; - forbidden_dirs.insert(it->first) ; - } - else - std::cerr << "autorized" << std::endl; - } - - uint64_t sizetmp ; - - fi.saveIndex(fname_total, calchash, sizetmp,std::set()); // save all files - fi.saveIndex(fname_browsable, calchash, size,forbidden_dirs); // save only browsable files - - if(size > 0) - { #ifdef FIM_DEBUG - std::cerr << "FileIndexMonitor::updateCycle() saved with hash:" << calchash; - std::cerr << std::endl; + std::cerr << " dir=" << dit->first << ", " ; + std::cerr << "parent groups: " ; + for(std::list::const_iterator mit(dit->second.parent_groups.begin());mit!=dit->second.parent_groups.end();++mit) + std::cerr << (*mit) << ", " ; + std::cerr << std::endl;; #endif - /* should clean up the previous cache.... */ + FileSearchFlags permission_flags = rsPeers->computePeerPermissionFlags(*it,dit->second.shareflags,dit->second.parent_groups) ; - /* flag as new info */ - CacheData data; - data.pid = fi.root->id; - data.cid.type = getCacheType(); - data.cid.subid = 0; - data.path = path; - data.name = tmpname_browsable; - data.hash = calchash; - data.size = size; - data.recvd = time(NULL); + if(!(permission_flags & RS_FILE_HINTS_BROWSABLE)) + { + std::cerr << "forbidden" << std::endl; + forbidden_dirs.insert(dit->first) ; + } + else + std::cerr << "autorized" << std::endl; + } - updateCache(data); + peers_per_directory_combination[forbidden_dirs].push_back(*it) ; + } + std::string ownId = rsPeers->getOwnId() ; + peers_per_directory_combination[std::set()].push_back(ownId) ; // add full configuration to self, i.e. no forbidden directories. + + int n=0 ; + time_t now = time(NULL) ; + + for(std::map, std::list >::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::const_iterator itt(it->second.begin());itt!= it->second.end();++itt) + std::cerr << " " << *itt << std::endl; + std::cerr << " forbidden : " << std::endl; + for(std::set::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) + { +#ifdef FIM_DEBUG + std::cerr << "FileIndexMonitor::updateCycle() saved with hash:" << hash << std::endl; +#endif + + /* should clean up the previous cache.... */ + + /* flag as new info */ + CacheData data; + data.pid = fi.root->id; + data.cid.type = getCacheType(); + data.cid.subid = 0; + data.path = path; + data.name = tmpname_browsable; + data.hash = hash; + data.size = size; + data.recvd = time(NULL); + + updateCache(data,it->second); + } } #ifdef FIM_DEBUG @@ -1073,6 +1135,7 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir) { std::cerr << "** Updating to " << (*it).shareflags << "!!" << std::endl ; (*it).shareflags = dir.shareflags ; + (*it).parent_groups = dir.parent_groups ; break ; } } @@ -1084,6 +1147,7 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir) { std::cerr << "** Updating from " << it->second.shareflags << "!!" << std::endl ; (*it).second.shareflags = dir.shareflags ; + (*it).second.parent_groups = dir.parent_groups ; fimods = true ; break ; } @@ -1295,7 +1359,7 @@ uint32_t FileIndexMonitor::getType(void *ref) const return fi.getType(ref) ; } -int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const +int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const { /* remove unused parameter warnings */ (void) flags; @@ -1335,7 +1399,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t details.hash = ""; details.path = "root"; details.age = 0; - details.flags = 0; + details.flags.clear() ; details.min_age = 0 ; return true ; @@ -1353,18 +1417,15 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t if(ref != NULL) { FileEntry *file = (FileEntry *) ref; - - 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) ; + locked_findShareFlagsAndParentGroups(file,details.flags,details.parent_groups) ; } return true ; } -uint32_t FileIndexMonitor::locked_findShareFlags(FileEntry *file) const +void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list& parent_groups) const { - uint32_t flags = 0 ; + flags.clear() ; + 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(file) ; if(dir == NULL) @@ -1384,13 +1445,16 @@ uint32_t FileIndexMonitor::locked_findShareFlags(FileEntry *file) const if(it == directoryMap.end()) std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ; else - flags = it->second.shareflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE) ; + { + flags = it->second.shareflags ; + flags &= PERMISSION_MASK ; + flags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // Disabling this flag for now, because it has inconsistent effects. + parent_groups = it->second.parent_groups ; + } #ifdef FIM_DEBUG2 std::cerr << "flags = " << flags << std::endl ; #endif } - - return flags ; } diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index 29c69059f..cfcd99be7 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -111,10 +111,12 @@ class FileIndexMonitor: public CacheSource, public RsThread virtual ~FileIndexMonitor(); /* external interface for filetransfer */ - bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const; - int SearchKeywords(std::list keywords, std::list &results,uint32_t flags) ; - int SearchBoolExp(Expression *exp, std::list &results,uint32_t flags) const ; - int filterResults(std::list& firesults,std::list& results,uint32_t flags) const ; + bool findLocalFile(std::string hash,FileSearchFlags flags,const std::string& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list& parent_groups) const; + + int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) ; + int SearchBoolExp(Expression *exp, std::list &results,FileSearchFlags flags,const std::string& peer_id) const ; + + int filterResults(std::list& firesults,std::list& results,FileSearchFlags flags,const std::string& peer_id) const ; /* external interface for local access to files */ @@ -124,7 +126,7 @@ class FileIndexMonitor: public CacheSource, public RsThread /* Interacting with CacheSource */ /* overloaded from CacheSource */ 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& dest_peers); /* we call when we have a new cache for others */ /* the FileIndexMonitor inner workings */ @@ -134,7 +136,7 @@ class FileIndexMonitor: public CacheSource, public RsThread void updateCycle(); // Interface for browsing dir hirarchy - int RequestDirDetails(void*, DirDetails&, uint32_t) const ; + int RequestDirDetails(void*, DirDetails&, FileSearchFlags) const ; uint32_t getType(void*) const ; int RequestDirDetails(const std::string& path, DirDetails &details) const ; @@ -169,7 +171,7 @@ class FileIndexMonitor: public CacheSource, public RsThread void locked_saveFileIndexes() ; // 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& parent_groups) const ; std::string locked_findRealRoot(std::string base) const; diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index 695c7c818..78f70270e 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -1346,7 +1346,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details) details.ref = file; details.hash = file->hash; details.age = now - file->modtime; - details.flags = 0;//file->pop; + details.flags.clear() ; /* find parent pointer, and row */ details.parent = file->parent ; diff --git a/libretroshare/src/dbase/findex.h b/libretroshare/src/dbase/findex.h index 5e2f32980..18d54c56e 100644 --- a/libretroshare/src/dbase/findex.h +++ b/libretroshare/src/dbase/findex.h @@ -101,6 +101,7 @@ virtual int print(std::string &out); /* References for easy manipulation */ DirEntry *parent; int row; + std::list parent_groups ; }; /****************************************************************************************** diff --git a/libretroshare/src/dbase/fistore.cc b/libretroshare/src/dbase/fistore.cc index 4302db617..481067d08 100644 --- a/libretroshare/src/dbase/fistore.cc +++ b/libretroshare/src/dbase/fistore.cc @@ -23,6 +23,7 @@ #include "dbase/fistore.h" #include "retroshare/rsexpr.h" +#include "retroshare/rsfiles.h" #include "serialiser/rsserviceids.h" #include "pqi/p3peermgr.h" @@ -200,7 +201,7 @@ int FileIndexStore::RequestDirDetails(const std::string& uid, const std::string& #endif } -int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const +int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const { /* remove unused parameter warnings */ (void) flags; @@ -258,7 +259,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f details.path = ""; details.count = indices.size(); details.age = 0; - details.flags = 0; + details.flags.clear() ; details.min_age = 0; unlockData(); @@ -329,7 +330,7 @@ int FileIndexStore::SearchHash(std::string hash, std::list &results) } -int FileIndexStore::SearchKeywords(std::list keywords, std::list &results,uint32_t flags) const +int FileIndexStore::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) const { lockData(); std::map::const_iterator pit; @@ -341,7 +342,7 @@ int FileIndexStore::SearchKeywords(std::list keywords, std::list keywords, std::list &results) const; /* Search Interface - For Search Interface */ - int SearchKeywords(std::list terms, std::list &results,uint32_t flags) const; + int SearchKeywords(std::list terms, std::list &results,FileSearchFlags flags) const; /* Search Interface - for Adv Search Interface */ int searchBoolExp(Expression * exp, std::list &results) const; @@ -83,7 +83,7 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa /* Search Interface - For Directory Access */ int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) const; - int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const; + int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) const; uint32_t getType(void *ref) const ; private: diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index f769f0776..82d930df4 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -83,7 +83,7 @@ ftFileControl::ftFileControl() ftFileControl::ftFileControl(std::string fname, std::string tmppath, std::string dest, - uint64_t size, std::string hash, uint32_t flags, + uint64_t size, std::string hash, TransferRequestFlags flags, ftFileCreator *fc, ftTransferModule *tm) :mName(fname), mCurrentPath(tmppath), mDestination(dest), mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash), @@ -127,7 +127,7 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun if(it != mDownloads.end()) { it->second->mCreator->getChunkMap(info) ; - info.flags = it->second->mFlags ; + //info.flags = it->second->mFlags ; return true ; } @@ -143,7 +143,7 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun info.file_size = it->second->mSize ; info.strategy = mDefaultChunkStrategy ; info.chunk_size = ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ; - info.flags = it->second->mFlags ; + //info.flags = it->second->mFlags ; uint32_t nb_chunks = it->second->mSize/ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ; if(it->second->mSize % ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE != 0) ++nb_chunks ; @@ -327,7 +327,7 @@ void ftController::cleanCacheDownloads() RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ for(std::map::iterator it(mDownloads.begin());it!=mDownloads.end();++it) - if (((it->second)->mFlags & RS_FILE_HINTS_CACHE) && it->second->mState != ftFileControl::DOWNLOADING) + if (((it->second)->mFlags & RS_FILE_REQ_CACHE) && it->second->mState != ftFileControl::DOWNLOADING) // check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER { #ifdef CONTROL_DEBUG @@ -429,7 +429,7 @@ void ftController::checkDownloadQueue() for(uint32_t p=0;p<_queue.size();++p) { if(p < _min_prioritized_transfers) - if(_queue[p]->mFlags & RS_FILE_HINTS_CACHE) // cache file. add to potential move list + if(_queue[p]->mFlags & RS_FILE_REQ_CACHE) // cache file. add to potential move list to_move_before.push_back(p) ; else ++user_transfers ; // count one more user file in the prioritized range. @@ -438,7 +438,7 @@ void ftController::checkDownloadQueue() if(to_move_after.size() + user_transfers >= _min_prioritized_transfers) // we caught enough transfers to move back to the top of the queue. break ; - if(!(_queue[p]->mFlags & RS_FILE_HINTS_CACHE)) // non cache file. add to potential move list + if(!(_queue[p]->mFlags & RS_FILE_REQ_CACHE)) // non cache file. add to potential move list to_move_after.push_back(p) ; } } @@ -471,7 +471,7 @@ void ftController::locked_addToQueue(ftFileControl* ftfc,int add_strategy) // This is costly, so only use this in case we really need it. // uint32_t pos =0; - while(pos < _queue.size() && (pos < _min_prioritized_transfers || (_queue[pos]->mFlags & RS_FILE_HINTS_CACHE)>0) ) + while(pos < _queue.size() && (pos < _min_prioritized_transfers || (_queue[pos]->mFlags & RS_FILE_REQ_CACHE)>0) ) ++pos ; _queue.push_back(NULL) ; @@ -622,7 +622,7 @@ void ftController::locked_checkQueueElement(uint32_t pos) _queue[pos]->mState = ftFileControl::DOWNLOADING ; - if(_queue[pos]->mFlags & RS_FILE_HINTS_NETWORK_WIDE) + if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING) 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]->mCreator->closeFile() ; - if(_queue[pos]->mFlags & RS_FILE_HINTS_NETWORK_WIDE) + if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING) mTurtle->stopMonitoringFileTunnels(_queue[pos]->mHash) ; } } @@ -766,8 +766,8 @@ bool ftController::completeFile(std::string hash) uint64_t size = 0; uint32_t state = 0; uint32_t period = 0; - uint32_t flags = 0; - uint32_t extraflags = 0; + TransferRequestFlags flags ; + TransferRequestFlags extraflags ; uint32_t completeCount = 0; { @@ -855,7 +855,7 @@ bool ftController::completeFile(std::string hash) size = fc->mSize; state = fc->mState; period = 30 * 24 * 3600; /* 30 days */ - extraflags = 0; + extraflags.clear() ; #ifdef CONTROL_DEBUG std::cerr << "CompleteFile(): size = " << size << std::endl ; @@ -866,7 +866,7 @@ bool ftController::completeFile(std::string hash) locked_queueRemove(it->second->mQueuePosition) ; /* switch map */ - if (!(fc->mFlags & RS_FILE_HINTS_CACHE)) /* clean up completed cache files automatically */ + if (!(fc->mFlags & RS_FILE_REQ_CACHE)) /* clean up completed cache files automatically */ { mCompleted[fc->mHash] = fc; completeCount = mCompleted.size(); @@ -875,7 +875,7 @@ bool ftController::completeFile(std::string hash) mDownloads.erase(it); - if(flags & RS_FILE_HINTS_NETWORK_WIDE) + if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ; } /******* UNLOCKED ********/ @@ -887,13 +887,13 @@ bool ftController::completeFile(std::string hash) /* If it has a callback - do it now */ - if(flags & ( RS_FILE_HINTS_CACHE | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_MEDIA)) + if(flags & ( RS_FILE_REQ_CACHE | RS_FILE_REQ_EXTRA))// | RS_FILE_HINTS_MEDIA)) { #ifdef CONTROL_DEBUG - std::cerr << "ftController::completeFile() doing Callback, callbackflags:" << (flags & ( RS_FILE_HINTS_CACHE | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_MEDIA)) ; + std::cerr << "ftController::completeFile() doing Callback, callbackflags:" << (flags & ( RS_FILE_HINTS_CACHE | RS_FILE_HINTS_EXTRA ));//| RS_FILE_HINTS_MEDIA)) ; std::cerr << std::endl; #endif - if(flags & RS_FILE_HINTS_CACHE) + if(flags & RS_FILE_REQ_CACHE) { /* callback */ if (state == ftFileControl::COMPLETED) @@ -915,7 +915,7 @@ bool ftController::completeFile(std::string hash) } } - if(flags & RS_FILE_HINTS_EXTRA) + if(flags & RS_FILE_REQ_EXTRA) { #ifdef CONTROL_DEBUG std::cerr << "ftController::completeFile() adding to ExtraList"; @@ -925,13 +925,13 @@ bool ftController::completeFile(std::string hash) mExtraList->addExtraFile(path, hash, size, period, extraflags); } - if(flags & RS_FILE_HINTS_MEDIA) - { -#ifdef CONTROL_DEBUG - std::cerr << "ftController::completeFile() NULL MEDIA callback"; - std::cerr << std::endl; -#endif - } +// if(flags & RS_FILE_HINTS_MEDIA) +// { +//#ifdef CONTROL_DEBUG +// std::cerr << "ftController::completeFile() NULL MEDIA callback"; +// std::cerr << std::endl; +//#endif +// } } else { @@ -942,7 +942,7 @@ bool ftController::completeFile(std::string hash) } /* Notify GUI */ - if ((flags & RS_FILE_HINTS_CACHE) == 0) { + if ((flags & RS_FILE_REQ_CACHE) == 0) { pqiNotify *notify = getPqiNotify(); if (notify) { notify->AddPopupMessage(RS_POPUP_DOWNLOAD, hash, name, ""); @@ -994,7 +994,7 @@ bool ftController::handleAPendingRequest() std::cerr << "Requesting pending hash " << req.mHash << std::endl ; #endif - FileRequest(req.mName, req.mHash, req.mSize, req.mDest, req.mFlags, req.mSrcIds); + FileRequest(req.mName, req.mHash, req.mSize, req.mDest, TransferRequestFlags(req.mFlags), req.mSrcIds); { // See whether there is a pendign chunk map recorded for this hash. @@ -1043,14 +1043,14 @@ bool ftController::alreadyHaveFile(const std::string& hash, FileInfo &info) return true ; // 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, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info)) return true ; return false ; } 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, TransferRequestFlags flags, const std::list &_srcIds) { std::list srcIds(_srcIds) ; @@ -1129,7 +1129,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has #endif uint32_t rate = 0; - if (flags & RS_FILE_HINTS_BACKGROUND) + if (flags & RS_FILE_REQ_BACKGROUND) rate = FT_CNTRL_SLOW_RATE; else rate = FT_CNTRL_STANDARD_RATE; @@ -1191,12 +1191,12 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has } } /******* UNLOCKED ********/ - if(!(flags & RS_FILE_HINTS_NO_SEARCH)) + if(!(flags & RS_FILE_REQ_NO_SEARCH)) { /* do a source search - for any extra sources */ // 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 */ #ifdef CONTROL_DEBUG @@ -1242,10 +1242,10 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has // We check that flags are consistent. - if(flags & RS_FILE_HINTS_NETWORK_WIDE) + if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) mTurtle->monitorFileTunnels(fname,hash,size) ; - bool assume_availability = flags & RS_FILE_HINTS_CACHE ; // assume availability for cache files + bool assume_availability = flags & RS_FILE_REQ_CACHE ; // assume availability for cache files ftFileCreator *fc = new ftFileCreator(savepath, size, hash,assume_availability); ftTransferModule *tm = new ftTransferModule(fc, mDataplex,this); @@ -1623,7 +1623,7 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info) /* extract details */ info.hash = hash; info.fname = it->second->mName; - info.flags = it->second->mFlags; + info.transfer_info_flags = it->second->mFlags ; info.priority = SPEED_NORMAL ; RsDirUtil::removeTopDir(it->second->mDestination, info.path); /* remove fname */ info.queue_position = it->second->mQueuePosition ; @@ -1859,7 +1859,7 @@ bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string h return false ; } - FileRequest(hash, hash, size, path, RS_FILE_HINTS_CACHE | RS_FILE_HINTS_NO_SEARCH, ids); + FileRequest(hash, hash, size, path, RS_FILE_REQ_CACHE | RS_FILE_REQ_NO_SEARCH, ids); return true; } @@ -1959,7 +1959,7 @@ bool ftController::saveList(bool &cleanup, std::list& saveData) /* ignore cache files. As this is small files, better download them again from scratch at restart.*/ - if (fit->second->mFlags & RS_FILE_HINTS_CACHE) + if (fit->second->mFlags & RS_FILE_REQ_CACHE) { #ifdef CONTROL_DEBUG std::cerr << "ftcontroller::saveList(): Not saving (callback) file entry " << fit->second->mName << ", " << fit->second->mHash << ", " << fit->second->mSize << std::endl ; @@ -1983,7 +1983,7 @@ bool ftController::saveList(bool &cleanup, std::list& saveData) rft->file.hash = fit->second->mHash; rft->file.filesize = fit->second->mSize; RsDirUtil::removeTopDir(fit->second->mDestination, rft->file.path); /* remove fname */ - rft->flags = fit->second->mFlags; + rft->flags = fit->second->mFlags.toUInt32(); rft->state = fit->second->mState; fit->second->mTransfer->getFileSources(rft->allPeerIds.ids); @@ -2032,7 +2032,7 @@ bool ftController::saveList(bool &cleanup, std::list& saveData) rft->file.hash = pit->mHash; rft->file.filesize = pit->mSize; RsDirUtil::removeTopDir(pit->mDest, rft->file.path); /* remove fname */ - rft->flags = pit->mFlags; + rft->flags = pit->mFlags.toUInt32(); rft->allPeerIds.ids = pit->mSrcIds; } @@ -2093,7 +2093,7 @@ bool ftController::loadList(std::list& load) #ifdef CONTROL_DEBUG std::cerr << "ftController::loadList(): requesting " << rsft->file.name << ", " << rsft->file.hash << ", " << rsft->file.filesize << std::endl ; #endif - FileRequest(rsft->file.name, rsft->file.hash, rsft->file.filesize, rsft->file.path, rsft->flags, rsft->allPeerIds.ids); + FileRequest(rsft->file.name, rsft->file.hash, rsft->file.filesize, rsft->file.path, TransferRequestFlags(rsft->flags), rsft->allPeerIds.ids); { RsStackMutex mtx(ctrlMutex) ; diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index e8e05e334..a3098259c 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -73,7 +73,7 @@ class ftFileControl ftFileControl(); ftFileControl(std::string fname, std::string tmppath, std::string dest, - uint64_t size, std::string hash, uint32_t flags, + uint64_t size, std::string hash, TransferRequestFlags flags, ftFileCreator *fc, ftTransferModule *tm); std::string mName; @@ -84,7 +84,7 @@ class ftFileControl uint32_t mState; std::string mHash; uint64_t mSize; - uint32_t mFlags; + TransferRequestFlags mFlags; time_t mCreateTime; uint32_t mQueuePriority ; uint32_t mQueuePosition ; @@ -94,7 +94,7 @@ class ftPendingRequest { public: ftPendingRequest(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, TransferRequestFlags flags, const std::list &srcIds) : mName(fname), mHash(hash), mSize(size), mDest(dest), mFlags(flags),mSrcIds(srcIds) { return; } @@ -105,7 +105,7 @@ class ftPendingRequest std::string mHash; uint64_t mSize; std::string mDest; - uint32_t mFlags; + TransferRequestFlags mFlags; std::list mSrcIds; }; @@ -129,7 +129,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu /***************************************************************/ 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, TransferRequestFlags flags, const std::list &sourceIds); /// Do we already have this file, either in download or in file lists ? diff --git a/libretroshare/src/ft/ftdatamultiplex.cc b/libretroshare/src/ft/ftdatamultiplex.cc index ccf1c8a9d..de5fc71f5 100644 --- a/libretroshare/src/ft/ftdatamultiplex.cc +++ b/libretroshare/src/ft/ftdatamultiplex.cc @@ -142,7 +142,7 @@ bool ftDataMultiplex::FileDownloads(std::list &hashs) } -bool ftDataMultiplex::FileDetails(const std::string &hash, uint32_t hintsflag, FileInfo &info) +bool ftDataMultiplex::FileDetails(const std::string &hash, FileSearchFlags hintsflag, FileInfo &info) { #ifdef MPLEX_DEBUG std::cerr << "ftDataMultiplex::FileDetails("; @@ -1309,18 +1309,19 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std:: * the network wide and browsable flags are needed, otherwise results get filtered. * For tunnel creation, the check of browsable/network wide flag is already done, so * if we get a file download packet here, the source is already allowed to download it. + * That is why we don't call the search function with a peer id. * */ FileInfo info; - uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY ; + FileSearchFlags hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY ; if(rsTurtle->isTurtlePeer(peerId)) hintflags |= RS_FILE_HINTS_NETWORK_WIDE ; 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, info)) { /* setup a new provider */ diff --git a/libretroshare/src/ft/ftdatamultiplex.h b/libretroshare/src/ft/ftdatamultiplex.h index facaa6565..8c804c478 100644 --- a/libretroshare/src/ft/ftdatamultiplex.h +++ b/libretroshare/src/ft/ftdatamultiplex.h @@ -104,7 +104,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread /* get Details of File Transfers */ bool FileUploads(std::list &hashs); bool FileDownloads(std::list &hashs); - bool FileDetails(const std::string &hash, uint32_t hintsflag, FileInfo &info); + bool FileDetails(const std::string &hash, FileSearchFlags hintsflag, FileInfo &info); void deleteUnusedServers() ; void handlePendingCrcRequests() ; diff --git a/libretroshare/src/ft/ftdbase.cc b/libretroshare/src/ft/ftdbase.cc index 56a4ee464..2c62b78f4 100644 --- a/libretroshare/src/ft/ftdbase.cc +++ b/libretroshare/src/ft/ftdbase.cc @@ -37,7 +37,7 @@ ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,p3 return; } -bool ftFiStore::search(const std::string &hash, uint32_t hintflags, FileInfo &info) const +bool ftFiStore::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const { /* could use hintflags to specify which bits of fileinfo to use additionally. eg. hintflags & FT_SEARCH_PEER_ID, then only return matching peers + hash. @@ -128,11 +128,12 @@ ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cached return; } -bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &info) const +bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const +{ + return search(hash,hintflags,"",info) ; +} +bool ftFiMonitor::search(const std::string &hash, FileSearchFlags hintflags, const std::string& peer_id,FileInfo &info) const { - uint64_t fsize; - std::string path; - #ifdef DB_DEBUG std::cerr << "ftFiMonitor::search(" << hash << "," << hintflags; std::cerr << ")"; @@ -142,9 +143,10 @@ bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo & // Setup search flags according to hintflags. Originally flags was 0. I (cyril) don't know // why we don't just pass hintflags there, so I tried to keep the idea. // - uint32_t flags = hintflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE); + FileSearchFlags flags = hintflags ; + flags &= (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE); - if(findLocalFile(hash, flags, path, fsize)) + if(findLocalFile(hash, flags,peer_id,info.path, info.size,info.storage_permission_flags,info.parent_groups)) { /* fill in details */ #ifdef DB_DEBUG @@ -153,10 +155,7 @@ bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo & std::cerr << " = " << hash << "," << fsize; std::cerr << std::endl; #endif - - info.size = fsize; - info.fname = RsDirUtil::getTopDir(path); - info.path = path; + info.fname = RsDirUtil::getTopDir(info.path); return true; } @@ -241,7 +240,8 @@ bool ftFiMonitor::saveList(bool &cleanup, std::list& sList) RsFileConfigItem *fi = new RsFileConfigItem(); fi->file.path = (*it).filename ; fi->file.name = (*it).virtualname ; - fi->flags = (*it).shareflags ; + fi->flags = (*it).shareflags.toUInt32() ; + fi->parent_groups = (*it).parent_groups ; sList.push_back(fi); } @@ -288,6 +288,7 @@ bool ftFiMonitor::loadList(std::list& load) /* for each item, check it exists .... * - remove any that are dead (or flag?) */ + static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ; #ifdef DEBUG_ELIST std::cerr << "ftFiMonitor::loadList()"; @@ -341,7 +342,10 @@ bool ftFiMonitor::loadList(std::list& load) SharedDirInfo info ; info.filename = RsDirUtil::convertPathToUnix(fi->file.path); info.virtualname = fi->file.name; - info.shareflags = fi->flags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE) ; + info.parent_groups = fi->parent_groups; + info.shareflags = FileStorageFlags(fi->flags) ; + info.shareflags &= PERMISSION_MASK ; + info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons dirList.push_back(info) ; } @@ -353,6 +357,11 @@ bool ftFiMonitor::loadList(std::list& load) void ftFiMonitor::updateShareFlags(const SharedDirInfo& info) { + std::cerr << "Updating share flags:" << std::endl; + std::cerr << " Directory : " << info.filename << std::endl; + std::cerr << " Virtual : " << info.virtualname << std::endl; + std::cerr << " Flags : " << info.shareflags << std::endl; + FileIndexMonitor::updateShareFlags(info); /* flag for config */ @@ -376,7 +385,7 @@ ftCacheStrapper::ftCacheStrapper(p3LinkMgr *lm) } /* overloaded search function */ -bool ftCacheStrapper::search(const std::string &hash, uint32_t hintflags, FileInfo &info) const +bool ftCacheStrapper::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const { /* remove unused parameter warnings */ (void) hintflags; diff --git a/libretroshare/src/ft/ftdbase.h b/libretroshare/src/ft/ftdbase.h index 33e4f2d75..3d187817b 100644 --- a/libretroshare/src/ft/ftdbase.h +++ b/libretroshare/src/ft/ftdbase.h @@ -52,7 +52,7 @@ class ftFiStore: public FileIndexStore, public ftSearch RsPeerId ownid, std::string cachedir); /* overloaded search function */ -virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const; +virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const; }; class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config @@ -61,7 +61,8 @@ class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid,const std::string& config_dir); /* overloaded search function */ - virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const; + virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const; + virtual bool search(const std::string &hash, FileSearchFlags hintflags, const std::string& peer_id, FileInfo &info) const; /* overloaded set dirs enables config indication */ virtual void setSharedDirectories(const std::list& dirList); @@ -93,7 +94,7 @@ class ftCacheStrapper: public CacheStrapper, public ftSearch ftCacheStrapper(p3LinkMgr *cm); /* overloaded search function */ -virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const; +virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const; }; diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index 7eb1d81e7..93e353f5c 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -146,7 +146,7 @@ void ftExtraList::hashAFile() **/ bool ftExtraList::addExtraFile(std::string path, std::string hash, - uint64_t size, uint32_t period, uint32_t flags) + uint64_t size, uint32_t period, TransferRequestFlags flags) { #ifdef DEBUG_ELIST std::cerr << "ftExtraList::addExtraFile() path: " << path; @@ -177,7 +177,7 @@ bool ftExtraList::addExtraFile(std::string path, std::string hash, return true; } -bool ftExtraList::removeExtraFile(std::string hash, uint32_t flags) +bool ftExtraList::removeExtraFile(std::string hash, TransferRequestFlags flags) { /* remove unused parameter warnings */ (void) flags; @@ -273,12 +273,12 @@ bool ftExtraList::cleanupOldFiles() } -bool ftExtraList::cleanupEntry(std::string /*path*/, uint32_t flags) +bool ftExtraList::cleanupEntry(std::string /*path*/, TransferRequestFlags flags) { - if (flags & RS_FILE_CONFIG_CLEANUP_DELETE) - { - /* Delete the file? - not yet! */ - } +// if (flags & RS_FILE_CONFIG_CLEANUP_DELETE) +// { +// /* Delete the file? - not yet! */ +// } return true; } @@ -287,7 +287,7 @@ bool ftExtraList::cleanupEntry(std::string /*path*/, uint32_t flags) * file is removed after period. **/ -bool ftExtraList::hashExtraFile(std::string path, uint32_t period, uint32_t flags) +bool ftExtraList::hashExtraFile(std::string path, uint32_t period, TransferRequestFlags flags) { #ifdef DEBUG_ELIST std::cerr << "ftExtraList::hashExtraFile() path: " << path; @@ -326,14 +326,14 @@ bool ftExtraList::hashExtraFileDone(std::string path, FileInfo &info) } hash = it->second; } - return search(hash, 0, info); + return search(hash, FileSearchFlags(0), info); } /*** * Search Function - used by File Transfer * **/ -bool ftExtraList::search(const std::string &hash, uint32_t /*hintflags*/, FileInfo &info) const +bool ftExtraList::search(const std::string &hash, FileSearchFlags /*hintflags*/, FileInfo &info) const { #ifdef DEBUG_ELIST @@ -396,7 +396,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list& sList) fi->file.hash = (it->second).info.hash; fi->file.filesize = (it->second).info.size; fi->file.age = (it->second).info.age; - fi->flags = (it->second).flags; + fi->flags = (it->second).flags.toUInt32(); sList.push_back(fi); } @@ -444,7 +444,7 @@ bool ftExtraList::loadList(std::list& load) if (ts > (time_t)fi->file.age) { /* to old */ - cleanupEntry(fi->file.path, fi->flags); + cleanupEntry(fi->file.path, TransferRequestFlags(fi->flags)); delete (*it); continue ; } @@ -461,7 +461,7 @@ bool ftExtraList::loadList(std::list& load) details.info.hash = fi->file.hash; details.info.size = fi->file.filesize; details.info.age = fi->file.age; /* time that we remove it. */ - details.flags = fi->flags; + details.flags = TransferRequestFlags(fi->flags); /* stick it in the available queue */ mFiles[details.info.hash] = details; diff --git a/libretroshare/src/ft/ftextralist.h b/libretroshare/src/ft/ftextralist.h index afdc3e685..c34c90399 100644 --- a/libretroshare/src/ft/ftextralist.h +++ b/libretroshare/src/ft/ftextralist.h @@ -65,38 +65,38 @@ class FileDetails { public: - FileDetails() -{ - return; -} + FileDetails() + { + return; + } - FileDetails(std::string path, uint32_t p, uint32_t f) -{ - info.path = path; - period = p; - flags = f; -} - - FileDetails(FileInfo &i, uint32_t p, uint32_t f) -{ - info = i; - period = p; - flags = f; -} + FileDetails(std::string path, uint32_t p, TransferRequestFlags f) + { + info.path = path; + period = p; + flags = f; + } - FileInfo info; + FileDetails(FileInfo &i, uint32_t p, TransferRequestFlags f) + { + info = i; + period = p; + flags = f; + } + + FileInfo info; #if 0 /*** WHAT IS NEEDED ***/ - std::list sources; - std::string path; - std::string fname; - std::string hash; - uint64_t size; + std::list sources; + std::string path; + std::string fname; + std::string hash; + uint64_t size; #endif - uint32_t start; - uint32_t period; - uint32_t flags; + uint32_t start; + uint32_t period; + TransferRequestFlags flags; }; const uint32_t FT_DETAILS_CLEANUP = 0x0100; /* remove when it expires */ @@ -118,9 +118,9 @@ class ftExtraList: public RsThread, public p3Config, public ftSearch **/ bool addExtraFile(std::string path, std::string hash, - uint64_t size, uint32_t period, uint32_t flags); + uint64_t size, uint32_t period, TransferRequestFlags flags); -bool removeExtraFile(std::string hash, uint32_t flags); +bool removeExtraFile(std::string hash, TransferRequestFlags flags); bool moveExtraFile(std::string fname, std::string hash, uint64_t size, std::string destpath); @@ -130,7 +130,7 @@ bool moveExtraFile(std::string fname, std::string hash, uint64_t size, * file is removed after period. **/ -bool hashExtraFile(std::string path, uint32_t period, uint32_t flags); +bool hashExtraFile(std::string path, uint32_t period, TransferRequestFlags flags); bool hashExtraFileDone(std::string path, FileInfo &info); /*** @@ -138,7 +138,7 @@ bool hashExtraFileDone(std::string path, FileInfo &info); * implementation of ftSearch. * **/ -virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const; +virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const; /*** * Thread Main Loop @@ -159,7 +159,7 @@ virtual bool loadList(std::list& load); /* Worker Functions */ void hashAFile(); bool cleanupOldFiles(); -bool cleanupEntry(std::string path, uint32_t flags); +bool cleanupEntry(std::string path, TransferRequestFlags flags); mutable RsMutex extMutex; diff --git a/libretroshare/src/ft/ftfilesearch.cc b/libretroshare/src/ft/ftfilesearch.cc index e57af87f3..e868ab6ca 100644 --- a/libretroshare/src/ft/ftfilesearch.cc +++ b/libretroshare/src/ft/ftfilesearch.cc @@ -39,9 +39,9 @@ ftFileSearch::ftFileSearch() } } -bool ftFileSearch::addSearchMode(ftSearch *search, uint32_t hintflags) +bool ftFileSearch::addSearchMode(ftSearch *search, FileSearchFlags hintflags) { - hintflags &= 0x00ffffff; + hintflags &= FileSearchFlags(0x000000ff); #ifdef DEBUG_SEARCH std::cerr << "ftFileSearch::addSearchMode() : " << hintflags; @@ -51,7 +51,7 @@ bool ftFileSearch::addSearchMode(ftSearch *search, uint32_t hintflags) uint32_t i; for (i = 0; i < MAX_SEARCHS; i++) { - uint32_t hints = hintflags >> i; + uint32_t hints = hintflags.toUInt32() >> i; if (hints & 0x0001) { /* has the flag */ @@ -75,7 +75,7 @@ bool ftFileSearch::addSearchMode(ftSearch *search, uint32_t hintflags) return false; } -bool ftFileSearch::search(const std::string &hash, uint32_t hintflags, FileInfo &info) const +bool ftFileSearch::search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const { uint32_t hints, i; @@ -87,7 +87,7 @@ bool ftFileSearch::search(const std::string &hash, uint32_t hintflags, FileInfo for (i = 0; i < MAX_SEARCHS; i++) { - hints = hintflags >> i; + hints = hintflags.toUInt32() >> i; if (hints & 0x0001) { /* has the flag */ @@ -140,7 +140,7 @@ bool ftFileSearch::search(const std::string &hash, uint32_t hintflags, FileInfo */ for (i = 0; i < MAX_SEARCHS; i++) { - hints = hintflags >> i; + hints = hintflags.toUInt32() >> i; if (hints & 0x0001) { continue; @@ -180,7 +180,7 @@ bool ftFileSearch::search(const std::string &hash, uint32_t hintflags, FileInfo } -bool ftSearchDummy::search(std::string /*hash*/, uint32_t hintflags, FileInfo &/*info*/) const +bool ftSearchDummy::search(std::string /*hash*/, FileSearchFlags hintflags, FileInfo &/*info*/) const { /* remove unused parameter warnings */ (void) hintflags; diff --git a/libretroshare/src/ft/ftfilesearch.h b/libretroshare/src/ft/ftfilesearch.h index eaf5db2cd..1f3426d85 100644 --- a/libretroshare/src/ft/ftfilesearch.h +++ b/libretroshare/src/ft/ftfilesearch.h @@ -44,8 +44,8 @@ class ftFileSearch: public ftSearch ftFileSearch(); -bool addSearchMode(ftSearch *search, uint32_t hintflags); -virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const; +bool addSearchMode(ftSearch *search, FileSearchFlags hintflags); +virtual bool search(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) const; private: diff --git a/libretroshare/src/ft/ftsearch.h b/libretroshare/src/ft/ftsearch.h index 670d78630..67bf965e5 100644 --- a/libretroshare/src/ft/ftsearch.h +++ b/libretroshare/src/ft/ftsearch.h @@ -40,10 +40,14 @@ class ftSearch { public: - - ftSearch() { return; } -virtual ~ftSearch() { return; } -virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const = 0; + ftSearch() { return; } + virtual ~ftSearch() { return; } + virtual bool search(const std::string &hash, FileSearchFlags 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, FileSearchFlags hintflags, FileInfo &info) const = 0; }; @@ -54,7 +58,7 @@ class ftSearchDummy: public ftSearch ftSearchDummy() { return; } virtual ~ftSearchDummy() { return; } -virtual bool search(std::string hash, uint32_t hintflags, FileInfo &info) const; +virtual bool search(std::string hash, FileSearchFlags hintflags, FileInfo &info) const; }; #endif diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 207fcbb60..ce935e081 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -270,7 +270,7 @@ bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &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& srcIds) +bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds) { std::string error_string ; @@ -415,7 +415,7 @@ bool ftServer::FileUploads(std::list &hashs) return mFtDataplex->FileUploads(hashs); } -bool ftServer::FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info) +bool ftServer::FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) { if (hintflags & RS_FILE_HINTS_DOWNLOAD) 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. // FileInfo info2 ; - if( (!(info.flags & RS_FILE_HINTS_CACHE)) && mFtController->FileDetails(hash, info2)) + if( (!(info.transfer_info_flags & RS_FILE_REQ_CACHE)) && mFtController->FileDetails(hash, info2)) info.fname = info2.fname ; 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, - uint32_t period, uint32_t flags) + uint32_t period, TransferRequestFlags flags) { return mFtExtra->addExtraFile(fname, hash, size, period, flags); } -bool ftServer::ExtraFileRemove(std::string hash, uint32_t flags) +bool ftServer::ExtraFileRemove(std::string hash, TransferRequestFlags 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, TransferRequestFlags 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); } -int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) +int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) { #ifdef SERVER_DEBUG std::cerr << "ftServer::RequestDirDetails(ref:" << ref; @@ -511,12 +511,12 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) } #endif - if(flags & DIR_FLAGS_LOCAL) + if(flags & RS_FILE_HINTS_LOCAL) return mFiMon->RequestDirDetails(ref, details, flags); else return mFiStore->RequestDirDetails(ref, details, flags); } -uint32_t ftServer::getType(void *ref, uint32_t flags) +uint32_t ftServer::getType(void *ref, FileSearchFlags flags) { #ifdef SERVER_DEBUG std::cerr << "ftServer::RequestDirDetails(ref:" << ref; @@ -530,7 +530,7 @@ uint32_t ftServer::getType(void *ref, uint32_t flags) } #endif - if(flags & DIR_FLAGS_LOCAL) + if(flags & RS_FILE_HINTS_LOCAL) return mFiMon->getType(ref); else return mFiStore->getType(ref); @@ -540,7 +540,15 @@ uint32_t ftServer::getType(void *ref, uint32_t flags) /***************************************************************/ -int ftServer::SearchKeywords(std::list keywords, std::list &results,uint32_t flags) +int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) +{ + if(flags & RS_FILE_HINTS_LOCAL) + return mFiMon->SearchKeywords(keywords, results,flags,""); + else + return mFiStore->SearchKeywords(keywords, results,flags); + return 0 ; +} +int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) { #ifdef SERVER_DEBUG std::cerr << "ftServer::SearchKeywords()"; @@ -553,16 +561,24 @@ int ftServer::SearchKeywords(std::list keywords, std::listSearchKeywords(keywords, results,flags); + if(flags & RS_FILE_HINTS_LOCAL) + return mFiMon->SearchKeywords(keywords, results,flags,peer_id); else return mFiStore->SearchKeywords(keywords, results,flags); } -int ftServer::SearchBoolExp(Expression * exp, std::list &results,uint32_t flags) +int ftServer::SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags) { - if(flags & DIR_FLAGS_LOCAL) - return mFiMon->SearchBoolExp(exp,results,flags) ; + if(flags & RS_FILE_HINTS_LOCAL) + return mFiMon->SearchBoolExp(exp,results,flags,"") ; + else + return mFiStore->searchBoolExp(exp, results); + return 0 ; +} +int ftServer::SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const std::string& peer_id) +{ + if(flags & RS_FILE_HINTS_LOCAL) + return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ; else return mFiStore->searchBoolExp(exp, results); } @@ -731,7 +747,7 @@ bool ftServer::shareDownloadDirectory(bool share) /* Share */ SharedDirInfo inf ; inf.filename = mFtController->getDownloadDirectory(); - inf.shareflags = RS_FILE_HINTS_NETWORK_WIDE ; + inf.shareflags = DIR_FLAGS_NETWORK_WIDE_OTHERS ; return addSharedDirectory(inf); } diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index ec0e16ff3..63201c0f5 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -125,7 +125,7 @@ ftController *getController() const { return mFtController ; } * Control of Downloads ***/ 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& srcIds); +virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds); virtual bool FileCancel(const std::string& hash); virtual bool FileControl(const std::string& hash, uint32_t flags); virtual bool FileClearCompleted(); @@ -154,7 +154,7 @@ virtual bool clearDownload(const std::string hash); ***/ virtual bool FileDownloads(std::list &hashs); virtual bool FileUploads(std::list &hashs); -virtual bool FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info); +virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info); virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ; 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 ***/ -virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, - uint32_t period, uint32_t flags); -virtual bool ExtraFileRemove(std::string hash, uint32_t flags); -virtual bool ExtraFileHash(std::string localpath, - uint32_t period, uint32_t flags); +virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags); +virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags); +virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags); virtual bool ExtraFileStatus(std::string localpath, FileInfo &info); -virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, - std::string destpath); +virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath); /*** * Directory Listing / Search Interface ***/ virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details); -virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags); -virtual uint32_t getType(void *ref,uint32_t flags) ; +virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags); +virtual uint32_t getType(void *ref,FileSearchFlags flags) ; -virtual int SearchKeywords(std::list keywords, std::list &results,uint32_t flags); -virtual int SearchBoolExp(Expression * exp, std::list &results,uint32_t flags); +virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags); +virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id); +virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags); +virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const std::string& peer_id); /*** * Utility Functions diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index f4c5dea50..d6df22baf 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -63,23 +63,32 @@ 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 FileSearchFlags RS_FILE_HINTS_CACHE ( 0x00000001 ); +const FileSearchFlags RS_FILE_HINTS_EXTRA ( 0x00000002 ); +const FileSearchFlags RS_FILE_HINTS_LOCAL ( 0x00000004 ); +const FileSearchFlags RS_FILE_HINTS_REMOTE ( 0x00000008 ); +const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 ); +const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 ); +const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 ); -const uint32_t RS_FILE_HINTS_CACHE = 0x00000001; -const uint32_t RS_FILE_HINTS_EXTRA = 0x00000002; -const uint32_t RS_FILE_HINTS_LOCAL = 0x00000004; -const uint32_t RS_FILE_HINTS_REMOTE = 0x00000008; -const uint32_t RS_FILE_HINTS_DOWNLOAD = 0x00000010; -const uint32_t RS_FILE_HINTS_UPLOAD = 0x00000020; +const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network +const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends +const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out. -const uint32_t RS_FILE_HINTS_NETWORK_WIDE = 0x00000080; // anonymously shared over network -const uint32_t RS_FILE_HINTS_BROWSABLE = 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_MEDIA = 0x00001000; -const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly. +// Flags used when requesting a transfer +// +const TransferRequestFlags RS_FILE_REQ_ANONYMOUS_ROUTING ( 0x00000040 ); // Use to ask turtle router to download the file. +const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files. +const TransferRequestFlags RS_FILE_REQ_CACHE ( 0x00000400 ); // Assume full source availability. Used for cache files. +const TransferRequestFlags RS_FILE_REQ_EXTRA ( 0x00000800 ); +const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 ); +const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly. +const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // disable searching for potential direct sources. -const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x01000000; -const uint32_t RS_FILE_HINTS_NO_SEARCH = 0x02000000; +// const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS +// | RS_FILE_HINTS_NETWORK_WIDE_GROUPS | RS_FILE_HINTS_BROWSABLE_GROUPS ; /* Callback Codes */ @@ -89,7 +98,8 @@ struct SharedDirInfo { std::string filename ; std::string virtualname ; - uint32_t shareflags ; // RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE + FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ... + std::list parent_groups ; }; class RsFiles @@ -109,7 +119,7 @@ class RsFiles 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. - virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, uint32_t flags, const std::list& srcIds) = 0; + virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds) = 0; virtual bool FileCancel(const std::string& hash) = 0; virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0; virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0; @@ -137,7 +147,7 @@ class RsFiles ***/ virtual bool FileDownloads(std::list &hashs) = 0; virtual bool FileUploads(std::list &hashs) = 0; - virtual bool FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info) = 0; + virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) = 0; /// Gives chunk details about the downloaded file with given hash. virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ; @@ -148,11 +158,9 @@ class RsFiles /*** * Extra List Access ***/ - virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, - uint32_t period, uint32_t flags) = 0; - virtual bool ExtraFileRemove(std::string hash, uint32_t flags) = 0; - virtual bool ExtraFileHash(std::string localpath, - uint32_t period, uint32_t flags) = 0; + virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags) = 0; + virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags) = 0; + virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) = 0; virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0; virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, std::string destpath) = 0; @@ -163,12 +171,13 @@ class RsFiles * Directory Listing / Search Interface */ virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) = 0; + virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) = 0; + virtual uint32_t getType(void *ref,FileSearchFlags flags) = 0; - virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0; - virtual uint32_t getType(void *ref,uint32_t flags) = 0; - - virtual int SearchKeywords(std::list keywords, std::list &results,uint32_t flags) = 0; - virtual int SearchBoolExp(Expression * exp, std::list &results,uint32_t flags) = 0; + virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) = 0; + virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const std::string& peer_id) = 0; + virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags) = 0; + virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const std::string& peer_id) = 0; /*** * Utility Functions. diff --git a/libretroshare/src/retroshare/rsflags.h b/libretroshare/src/retroshare/rsflags.h new file mode 100644 index 000000000..d221cf891 --- /dev/null +++ b/libretroshare/src/retroshare/rsflags.h @@ -0,0 +1,64 @@ +#pragma once + +#include + +// This class provides a representation for flags that can be combined with bitwise +// operations. However, because the class is templated with an id, it's not possible to +// mixup flags belonging to different classes. This avoids many bugs due to confusion of flags types +// that occur when all flags are uint32_t values. +// +// To use this class, define an ID that is different than other flags classes, and do a typedef: +// +// #define TRANSFER_INFO_FLAGS_TAG 0x8133ea +// typedef t_RsFlags32 TransferInfoFlags ; +// +// Implementation details: +// - we cannot have at the same time a implicit contructor from uint32_t and a bool operator, otherwise c++ +// mixes up operators and transforms flags into booleans before combining them further. +// +// So I decided to have: +// - an explicit constructor from uint32_t +// - an implicit bool operator, that allows test like if(flags & FLAGS_VALUE) +// +template class t_RsFlags32 +{ + public: + inline t_RsFlags32() { _bits=0; } + inline explicit t_RsFlags32(uint32_t N) : _bits(N) {} // allows initialization from a set of uint32_t + + inline t_RsFlags32 operator| (const t_RsFlags32& f) const { return t_RsFlags32(_bits | f._bits) ; } + inline t_RsFlags32 operator^ (const t_RsFlags32& f) const { return t_RsFlags32(_bits ^ f._bits) ; } + + inline bool operator!=(const t_RsFlags32& f) const { return _bits != f._bits ; } + inline bool operator& (const t_RsFlags32& f) const { return (_bits & f._bits)>0 ; } + + inline t_RsFlags32 operator|=(const t_RsFlags32& f) { _bits |= f._bits ; return *this ;} + inline t_RsFlags32 operator^=(const t_RsFlags32& f) { _bits ^= f._bits ; return *this ;} + inline t_RsFlags32 operator&=(const t_RsFlags32& f) { _bits &= f._bits ; return *this ;} + + inline t_RsFlags32 operator~() const { return t_RsFlags32(~_bits) ; } + + //inline explicit operator bool() const { return _bits>0; } + inline uint32_t toUInt32() const { return _bits ; } + + void clear() { _bits = 0 ; } + + friend std::ostream& operator<<(std::ostream& o,const t_RsFlags32& f) // friendly print with 0 and I + { + for(int i=31;i>=0;--i) { o << ( (f._bits&(1< FilePermissionFlags ; +typedef t_RsFlags32 TransferRequestFlags ; +typedef t_RsFlags32 FileStorageFlags ; // this makes it a uint32_t class incompatible with other flag class +typedef t_RsFlags32 FileSearchFlags ; // this makes it a uint32_t class incompatible with other flag class + diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 06b8eea8e..8e1e4202f 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -30,6 +30,9 @@ #include #include +#include +#include + /* The Main Interface Class - for information about your Peers * 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 @@ -210,88 +213,101 @@ class RsPeers { public: - RsPeers() { return; } -virtual ~RsPeers() { return; } + RsPeers() { return; } + virtual ~RsPeers() { return; } - /* Updates ... */ -virtual bool FriendsChanged() = 0; -virtual bool OthersChanged() = 0; + /* Updates ... */ + virtual bool FriendsChanged() = 0; + virtual bool OthersChanged() = 0; - /* Peer Details (Net & Auth) */ -virtual std::string getOwnId() = 0; + /* Peer Details (Net & Auth) */ + virtual std::string getOwnId() = 0; -virtual bool getOnlineList(std::list &ssl_ids) = 0; -virtual bool getFriendList(std::list &ssl_ids) = 0; -//virtual bool getOthersList(std::list &ssl_ids) = 0; -virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0; + virtual bool getOnlineList(std::list &ssl_ids) = 0; + virtual bool getFriendList(std::list &ssl_ids) = 0; + //virtual bool getOthersList(std::list &ssl_ids) = 0; + virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0; -virtual bool isOnline(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 std::string getPeerName(const std::string &ssl_or_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 isOnline(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 std::string getPeerName(const std::string &ssl_or_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 /* Using PGP Ids */ -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 bool isKeySupported(const std::string& gpg_ids) = 0; -virtual bool getGPGAcceptedList(std::list &gpg_ids) = 0; -virtual bool getGPGSignedList(std::list &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 &gpg_ids) = 0; -virtual bool getGPGAllList(std::list &gpg_ids) = 0; -virtual bool getGPGDetails(const std::string &gpg_id, RsPeerDetails &d) = 0; -virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list &ids) = 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 bool isKeySupported(const std::string& gpg_ids) = 0; + virtual bool getGPGAcceptedList(std::list &gpg_ids) = 0; + virtual bool getGPGSignedList(std::list &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 &gpg_ids) = 0; + virtual bool getGPGAllList(std::list &gpg_ids) = 0; + virtual bool getGPGDetails(const std::string &gpg_id, RsPeerDetails &d) = 0; + virtual bool getAssociatedSSLIds(const std::string &gpg_id, std::list &ids) = 0; - /* Add/Remove Friends */ -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 removeFriendLocation(const std::string &sslId) = 0; + /* Add/Remove Friends */ + 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 removeFriendLocation(const std::string &sslId) = 0; - /* Network Stuff */ -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 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 setDynDNS(const std::string &id, const std::string &addr) = 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; + /* Network Stuff */ + 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 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 setDynDNS(const std::string &id, const std::string &addr) = 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 void getIPServersList(std::list& ip_servers) = 0; -virtual void allowServerIPDetermination(bool) = 0; -virtual void allowTunnelConnection(bool) = 0; -virtual bool getAllowServerIPDetermination() = 0 ; -virtual bool getAllowTunnelConnection() = 0 ; + virtual void getIPServersList(std::list& ip_servers) = 0; + virtual void allowServerIPDetermination(bool) = 0; + virtual void allowTunnelConnection(bool) = 0; + virtual bool getAllowServerIPDetermination() = 0 ; + virtual bool getAllowTunnelConnection() = 0 ; - /* Auth Stuff */ -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 std::string GetRetroshareInvite(bool include_signatures,bool old_format = false) = 0; -virtual bool hasExportMinimal() = 0 ; + /* Auth Stuff */ + 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 std::string GetRetroshareInvite(bool include_signatures,bool old_format = false) = 0; + virtual bool hasExportMinimal() = 0 ; -// Add keys to the keyring -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; + // Add keys to the keyring + 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; -// 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; + // 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 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 std::string saveCertificateToString(const std::string &id) = 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 std::string saveCertificateToString(const std::string &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 signGPGCertificate(const std::string &gpg_id) = 0; + virtual bool trustGPGCertificate(const std::string &gpg_id, uint32_t trustlvl) = 0; - /* Group Stuff */ -virtual bool addGroup(RsGroupInfo &groupInfo) = 0; -virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0; -virtual bool removeGroup(const std::string &groupId) = 0; -virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; -virtual bool getGroupInfoList(std::list &groupInfoList) = 0; -// groupId == "" && assign == false -> remove from all groups -virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign) = 0; -virtual bool assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign) = 0; + /* Group Stuff */ + virtual bool addGroup(RsGroupInfo &groupInfo) = 0; + virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0; + virtual bool removeGroup(const std::string &groupId) = 0; + virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; + virtual bool getGroupInfoList(std::list &groupInfoList) = 0; + // groupId == "" && assign == false -> remove from all groups + virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign) = 0; + virtual bool assignPeersToGroup(const std::string &groupId, const std::list &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 FileSearchFlags computePeerPermissionFlags(const std::string& peer_id,FileStorageFlags file_sharing_flags,const std::list& file_parent_groups) = 0; }; diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index f038ede89..b3a40dc3f 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -34,6 +34,8 @@ #include #include +#include + #define USE_NEW_CHUNK_CHECKING_CODE 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 peers; - - DwlSpeed priority ; - time_t lastTS; -}; - -std::ostream &operator<<(std::ostream &out, const FileInfo &info); - /* matched to the uPnP states */ #define UPNP_STATE_UNINITIALISED 0 @@ -248,14 +202,72 @@ class SearchRequest * (TODO) */ -#define DIR_FLAGS_LOCAL 0x1000 -#define DIR_FLAGS_REMOTE 0x2000 +const FileStorageFlags DIR_FLAGS_PARENT ( 0x0001 ); +const FileStorageFlags DIR_FLAGS_DETAILS ( 0x0002 ); // apparently unused +const FileStorageFlags DIR_FLAGS_CHILDREN ( 0x0004 ); // apparently unused + +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. + TransferRequestFlags 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 peers; + + DwlSpeed priority ; + time_t lastTS; + + std::list 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 0x0008 -#define DIR_FLAGS_BROWSABLE 0x0010 class DirStub { @@ -279,22 +291,23 @@ class DirDetails std::string path; uint64_t count; uint32_t age; - uint32_t flags; + FileStorageFlags flags; uint32_t min_age ; // minimum age of files in this subtree std::list children; + std::list parent_groups; // parent groups for the shared directory }; class FileDetail { public: - std::string id; - std::string name; - std::string hash; - std::string path; - uint64_t size; - uint32_t age; - uint32_t rank; + std::string id; + std::string name; + std::string hash; + std::string path; + uint64_t size; + uint32_t age; + uint32_t rank; }; class CompressedChunkMap ; @@ -314,7 +327,6 @@ class FileChunksInfo uint64_t file_size ; // real size of the file uint32_t chunk_size ; // size of chunks - uint32_t flags ; uint32_t strategy ; // dl state of chunks. Only the last chunk may have size < chunk_size diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index e8984fb9c..2256aa35b 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1100,6 +1100,43 @@ bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::listassignPeersToGroup(groupId, peerIds, assign); } +FileSearchFlags p3Peers::computePeerPermissionFlags(const std::string& peer_ssl_id, + FileStorageFlags share_flags, + const std::list& 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. + // + + bool found = false ; + std::string pgp_id = getGPGId(peer_ssl_id) ; + + for(std::list::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::const_iterator it2(info.peerIds.begin());it2!=info.peerIds.end() && !found;++it2) + if(*it2 == pgp_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) ; + + FileSearchFlags final_flags ; + + if(network_wide) final_flags |= RS_FILE_HINTS_NETWORK_WIDE ; + if(browsable ) final_flags |= RS_FILE_HINTS_BROWSABLE ; + + return final_flags ; +} RsPeerDetails::RsPeerDetails() :isOnlyGPGdetail(false), diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 68dfd6d81..1fcb6babe 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -121,6 +121,7 @@ virtual bool getGroupInfoList(std::list &groupInfoList); virtual bool assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign); virtual bool assignPeersToGroup(const std::string &groupId, const std::list &peerIds, bool assign); +virtual FileSearchFlags computePeerPermissionFlags(const std::string& peer_id,FileStorageFlags share_flags,const std::list& parent_groups) ; private: p3LinkMgr *mLinkMgr; diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index f572c93b0..067ba2ee6 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -170,20 +170,24 @@ void RsFileConfigItem::clear() file.TlvClear(); flags = 0; + parent_groups.clear() ; } std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent) { - printRsItemBase(out, "RsFileConfigItem", indent); + printRsItemBase(out, "RsFileConfigItem", indent); uint16_t int_Indent = indent + 2; file.print(out, int_Indent); - printIndent(out, int_Indent); - out << "flags: " << flags << std::endl; + printIndent(out, int_Indent); out << "flags: " << flags << std::endl; + printIndent(out, int_Indent); out << "groups:" ; - printRsItemEnd(out, "RsFileConfigItem", indent); - return out; + for(std::list::const_iterator it(parent_groups.begin());it!=parent_groups.end();++it) + out << (*it) << " " ; + out << std::endl; + printRsItemEnd(out, "RsFileConfigItem", indent); + return out; } /*************************************************************************/ @@ -348,7 +352,10 @@ uint32_t RsFileConfigSerialiser::sizeFileItem(RsFileConfigItem *item) { uint32_t s = 8; /* header */ s += item->file.TlvSize(); - s += 4; + s += 4; // flags + + for(std::list::const_iterator it(item->parent_groups.begin());it!=item->parent_groups.end();++it) // parent groups + s += GetTlvStringSize(*it); return s; } @@ -377,9 +384,11 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void /* add mandatory parts first */ ok &= item->file.SetTlv(data, tlvsize, &offset); - ok &= setRawUInt32(data, tlvsize, &offset, item->flags); + for(std::list::const_iterator it(item->parent_groups.begin());ok && it!=item->parent_groups.end();++it) // parent groups + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, *it); + if (offset != tlvsize) { ok = false; @@ -427,6 +436,15 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32 ok &= item->file.GetTlv(data, rssize, &offset); ok &= getRawUInt32(data, rssize, &offset, &(item->flags)); + while(offset < rssize) + { + std::string tmp ; + if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp)) + item->parent_groups.push_back(tmp) ; + else + break ; + } + if (offset != rssize) { /* error */ diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index 71d5cfff9..9d4642110 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -300,6 +300,7 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0); RsTlvFileItem file; uint32_t flags; + std::list parent_groups ; }; /**************************************************************************/ diff --git a/libretroshare/src/services/p3channels.cc b/libretroshare/src/services/p3channels.cc index 867e691d2..331816e88 100644 --- a/libretroshare/src/services/p3channels.cc +++ b/libretroshare/src/services/p3channels.cc @@ -475,8 +475,7 @@ bool p3Channels::channelExtraFileHash(const std::string &path, const std::string // reverse string buff for correct file name fname.append(fnameBuff.rbegin(), fnameBuff.rend()); - - uint32_t flags = RS_FILE_HINTS_NETWORK_WIDE; + TransferRequestFlags flags = RS_FILE_REQ_ANONYMOUS_ROUTING; // then hash file and get file info too @@ -490,14 +489,15 @@ bool p3Channels::channelExtraFileHash(const std::string &path, const std::string } -bool p3Channels::channelExtraFileRemove(const std::string &hash, const std::string &chId){ - - uint32_t flags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_EXTRA; +bool p3Channels::channelExtraFileRemove(const std::string &hash, const std::string &chId) +{ + TransferRequestFlags tflags = RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA; + FileSearchFlags sflags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_EXTRA; /* remove copy from channels directory */ FileInfo fInfo; - mRsFiles->FileDetails(hash, flags, fInfo); + mRsFiles->FileDetails(hash, sflags, fInfo); std::string chPath = mChannelsDir + "/" + chId + "/" + fInfo.fname; if(remove(chPath.c_str()) == 0){ @@ -509,8 +509,7 @@ bool p3Channels::channelExtraFileRemove(const std::string &hash, const std::stri << chPath.c_str() << std::endl; } - return mRsFiles->ExtraFileRemove(hash, flags); - + return mRsFiles->ExtraFileRemove(hash, tflags); } @@ -835,7 +834,7 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, con std::string channelname = grpId; std::string localpath; - uint32_t flags; + TransferRequestFlags flags; // send to download directory if file is private // We also add explicit sources only if the channel is private. Otherwise we DL in network wide mode @@ -846,14 +845,14 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, con if(chanPrivate) { localpath = mChannelsDir; - flags = RS_FILE_HINTS_BACKGROUND | RS_FILE_HINTS_EXTRA; + flags = RS_FILE_REQ_BACKGROUND | RS_FILE_REQ_EXTRA; srcIds.push_back(id); } else { localpath = ""; // forces dl to default directory - flags = RS_FILE_HINTS_BACKGROUND | RS_FILE_HINTS_NETWORK_WIDE; + flags = RS_FILE_REQ_BACKGROUND | RS_FILE_REQ_ANONYMOUS_ROUTING; } /* download it ... and flag for ExtraList diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 34145014a..fec25a705 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1840,7 +1840,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) #ifdef P3TURTLE_DEBUG std::cerr << " Request not from us. Performing local search" << std::endl ; #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::listsearch()" << std::endl ; #endif // 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 std::cerr << initialResults.size() << " matches found." << std::endl ; @@ -2130,12 +2130,20 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::listSearchBoolExp(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() ; for(std::list::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 ; i.hash = it->hash ; i.size = it->count ; @@ -2276,9 +2284,31 @@ void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item) /// 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. // -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); + +#ifdef P3TURTLE_DEBUG + std::cerr << "p3turtle: performing local hash search for hash " << hash << std::endl; + + if(res) + { + std::cerr << "Found hash: " << std::endl; + std::cerr << " hash = " << hash << std::endl; + std::cerr << " peer = " << peer_id << std::endl; + std::cerr << " flags = " << info.storage_permission_flags << std::endl; + std::cerr << " local = " << 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) << std::endl; + std::cerr << " groups= " ; for(std::list::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) std::cerr << (*it) << ", " ; std::cerr << std::endl; + std::cerr << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl; + } +#endif + + // 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)) ; + + return res ; } static std::string printFloatNumber(float num,bool friendly=false) diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index 7a7c1eb1c..8c7203f51 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -213,7 +213,7 @@ class TurtleFileHashInfo // 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: 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) void returnSearchResult(RsTurtleSearchResultItem *item) ; - /// Returns true if the file with given hash is hosted locally. - virtual bool performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info) ; + /// 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,const std::string& client_peer_id,FileInfo& info) ; //--------------------------- Local variables --------------------------------// diff --git a/retroshare-gui/src/gui/FileTransferInfoWidget.cpp b/retroshare-gui/src/gui/FileTransferInfoWidget.cpp index 8a48d3591..09a7e91aa 100644 --- a/retroshare-gui/src/gui/FileTransferInfoWidget.cpp +++ b/retroshare-gui/src/gui/FileTransferInfoWidget.cpp @@ -261,8 +261,8 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info y += text_height ; painter->drawText(20,y,tr("Chunk strategy") + ":") ; painter->drawText(tab_size,y,(info.strategy==FileChunksInfo::CHUNK_STRATEGY_RANDOM)?"Random":"Streaming") ; y += block_sep ; y += text_height ; painter->drawText(20,y,tr("Transfer type") + ":") ; - if(info.flags & RS_FILE_HINTS_NETWORK_WIDE) painter->drawText(tab_size,y,tr("Anonymous F2F")) ; - if(info.flags & RS_FILE_HINTS_ASSUME_AVAILABILITY) painter->drawText(tab_size,y,tr("Direct friend transfer / Availability assumed")) ; + if(nfo.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) painter->drawText(tab_size,y,tr("Anonymous F2F")) ; + if(nfo.transfer_info_flags & RS_FILE_REQ_ASSUME_AVAILABILITY) painter->drawText(tab_size,y,tr("Direct friend transfer / Availability assumed")) ; y += text_height ; y += block_sep ; diff --git a/retroshare-gui/src/gui/QuickStartWizard.cpp b/retroshare-gui/src/gui/QuickStartWizard.cpp index c6af76d7f..22e8a0e30 100644 --- a/retroshare-gui/src/gui/QuickStartWizard.cpp +++ b/retroshare-gui/src/gui/QuickStartWizard.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "settings/rsharesettings.h" @@ -211,7 +212,7 @@ void QuickStartWizard::on_pushButtonSharesAdd_clicked() { SharedDirInfo sdi ; sdi.filename = dir ; - sdi.shareflags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE ; + sdi.shareflags = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS ; rsFiles->addSharedDirectory(sdi); @@ -307,8 +308,8 @@ void QuickStartWizard::loadShare() QCheckBox *cb1 = new QCheckBox ; QCheckBox *cb2 = new QCheckBox ; - cb1->setChecked( (*it).shareflags & RS_FILE_HINTS_NETWORK_WIDE ) ; - cb2->setChecked( (*it).shareflags & RS_FILE_HINTS_BROWSABLE ) ; + cb1->setChecked( (*it).shareflags & DIR_FLAGS_NETWORK_WIDE_OTHERS ) ; + cb2->setChecked( (*it).shareflags & DIR_FLAGS_BROWSABLE_OTHERS ) ; cb1->setToolTip(QString("If checked, the share is anonymously shared to anybody.")) ; cb2->setToolTip(QString("If checked, the share is browsable by your friends.")) ; @@ -339,11 +340,11 @@ void QuickStartWizard::updateFlags(bool b) for(it = dirs.begin(); it != dirs.end(); it++,++row) { std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ; - uint32_t current_flags = 0 ; - current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,1)))->isChecked()? RS_FILE_HINTS_NETWORK_WIDE:0 ; - current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,2)))->isChecked()? RS_FILE_HINTS_BROWSABLE:0 ; + FileStorageFlags current_flags(0u) ; + current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,1)))->isChecked()? DIR_FLAGS_NETWORK_WIDE_OTHERS:(FileStorageFlags)0u ; + current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,2)))->isChecked()? DIR_FLAGS_BROWSABLE_OTHERS :(FileStorageFlags)0u ; - if( (*it).shareflags ^ current_flags ) + if( ((*it).shareflags ^ current_flags).toUInt32() ) { (*it).shareflags = current_flags ; rsFiles->updateShareFlags(*it) ; // modifies the flags diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 201c16f5f..fea55e593 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -91,11 +91,7 @@ bool TreeStyle_RDM::hasChildren(const QModelIndex &parent) const void *ref = parent.internalPointer(); DirDetails details; - uint32_t flags = DIR_FLAGS_CHILDREN; - if (RemoteMode) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) { @@ -152,11 +148,7 @@ int TreeStyle_RDM::rowCount(const QModelIndex &parent) const void *ref = (parent.isValid())? parent.internalPointer() : NULL ; DirDetails details; - uint32_t flags = DIR_FLAGS_CHILDREN; - if (RemoteMode) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) { @@ -202,16 +194,28 @@ int FlatStyle_RDM::columnCount(const QModelIndex &/*parent*/) const { return 5; } -QString RetroshareDirModel::getFlagsString(uint32_t flags) +QString RetroshareDirModel::getFlagsString(FileStorageFlags flags) { - switch(flags & (DIR_FLAGS_NETWORK_WIDE|DIR_FLAGS_BROWSABLE)) + char str[11] = "- - -" ; + + if(flags & DIR_FLAGS_BROWSABLE_GROUPS) str[0] = 'B' ; + //if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) str[3] = 'N' ; + if(flags & DIR_FLAGS_BROWSABLE_OTHERS) str[3] = 'B' ; + if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) str[6] = 'N' ; + + return QString(str) ; +} +QString RetroshareDirModel::getGroupsString(const std::list& groups) +{ + QString groups_str ; + + for(std::list::const_iterator it(groups.begin());it!=groups.end();) { - case DIR_FLAGS_NETWORK_WIDE: return tr("Anonymous") ; - case DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE: return tr("Anonymous and browsable by friends") ; - case DIR_FLAGS_BROWSABLE: return tr("Only browsable by friends") ; - default: - return QString() ; + groups_str += QString::fromStdString(*it) ; + if(++it != groups.end()) + groups_str += ", " ; } + return groups_str ; } QString RetroshareDirModel::getAgeIndicatorString(const DirDetails &details) const @@ -320,13 +324,16 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const return misc::userFriendlyDuration(details.age); case 3: return getFlagsString(details.flags); +// case 4: +// { +// QString ind(""); +// if (ageIndicator != IND_ALWAYS) +// ind = getAgeIndicatorString(details); +// return ind; +// } case 4: - { - QString ind(""); - if (ageIndicator != IND_ALWAYS) - ind = getAgeIndicatorString(details); - return ind; - } + return getGroupsString(details.parent_groups) ; + default: return tr("FILE"); } @@ -348,6 +355,9 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const return misc::userFriendlyDuration(details.min_age); case 3: return getFlagsString(details.flags); + case 4: + return getGroupsString(details.parent_groups) ; + default: return tr("DIR"); } @@ -359,7 +369,7 @@ QString FlatStyle_RDM::computeDirectoryPath(const DirDetails& details) const { QString dir ; DirDetails det(details) ; - uint32_t flags = (RemoteMode)?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if(!requestDirDetails(det.parent,det,flags)) return QString(); @@ -500,11 +510,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const int coln = index.column(); DirDetails details; - uint32_t flags = DIR_FLAGS_DETAILS; - if (RemoteMode) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) return QVariant(); @@ -564,12 +570,8 @@ void RetroshareDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) c for (it = details.children.begin(); it != details.children.end(); it++) { void *ref = it->ref; DirDetails childDetails; - uint32_t flags; - if (RemoteMode) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (requestDirDetails(ref, childDetails, flags) && ret == tr("")) getAgeIndicatorRec(childDetails, ret); @@ -612,7 +614,10 @@ QVariant TreeStyle_RDM::headerData(int section, Qt::Orientation orientation, int else return tr("Share Type"); case 4: - return tr("What's new"); + if (RemoteMode) + return tr("What's new"); + else + return tr("Groups"); } return QString("Column %1").arg(section); } @@ -683,11 +688,7 @@ QModelIndex TreeStyle_RDM::index(int row, int column, const QModelIndex & parent ********/ DirDetails details; - uint32_t flags = DIR_FLAGS_CHILDREN; - if (RemoteMode) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) { @@ -766,7 +767,7 @@ QModelIndex TreeStyle_RDM::parent( const QModelIndex & index ) const void *ref = index.internalPointer(); DirDetails details; - uint32_t flags = (RemoteMode)?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) { @@ -817,11 +818,7 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const void *ref = index.internalPointer(); DirDetails details; - uint32_t flags = DIR_FLAGS_DETAILS; - if (RemoteMode) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) return Qt::ItemIsSelectable; // Error. @@ -871,7 +868,7 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const #endif } -bool RetroshareDirModel::requestDirDetails(void *ref,DirDetails& details,uint32_t flags) const +bool RetroshareDirModel::requestDirDetails(void *ref,DirDetails& details,FileSearchFlags flags) const { // We should use a cache instead of calling RsFiles::RequestDirDetails(), which is very costly // due to some pointer checking crap. @@ -929,7 +926,7 @@ void RetroshareDirModel::downloadSelected(const QModelIndexList &list) std::list srcIds; srcIds.push_back(details.id); rsFiles -> FileRequest(details.name, details.hash, - details.count, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds); + details.count, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds); } /* if it is a dir, copy all files included*/ else if (details.type == DIR_TYPE_DIR) @@ -950,7 +947,7 @@ void RetroshareDirModel::downloadDirectory(const DirDetails & dirDetails, int pr QString cleanPath = QDir::cleanPath(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()) + "/" + QString::fromUtf8(dirDetails.path.substr(prefixLen).c_str())); srcIds.push_back(dirDetails.id); - rsFiles->FileRequest(dirDetails.name, dirDetails.hash, dirDetails.count, cleanPath.toUtf8().constData(), RS_FILE_HINTS_NETWORK_WIDE, srcIds); + rsFiles->FileRequest(dirDetails.name, dirDetails.hash, dirDetails.count, cleanPath.toUtf8().constData(), RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds); } else if (dirDetails.type & DIR_TYPE_DIR) { @@ -965,7 +962,7 @@ void RetroshareDirModel::downloadDirectory(const DirDetails & dirDetails, int pr if (!it->ref) continue; DirDetails subDirDetails; - uint32_t flags = DIR_FLAGS_CHILDREN | DIR_FLAGS_REMOTE; + FileSearchFlags flags = RS_FILE_HINTS_REMOTE ; if (!requestDirDetails(it->ref, subDirDetails, flags)) continue; @@ -987,20 +984,10 @@ void RetroshareDirModel::getDirDetailsFromSelect (const QModelIndexList &list, s void *ref = it -> internalPointer(); DirDetails details; - uint32_t flags = DIR_FLAGS_DETAILS; - if (RemoteMode) - { - flags |= DIR_FLAGS_REMOTE; - } - else - { - flags |= DIR_FLAGS_LOCAL; - } + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) - { continue; - } dirVec.push_back(details); } @@ -1035,12 +1022,7 @@ void RetroshareDirModel::getFileInfoFromIndexList(const QModelIndexList& list, s void *ref = it -> internalPointer(); DirDetails details; - uint32_t flags = DIR_FLAGS_DETAILS; - - if (RemoteMode) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) continue; @@ -1136,10 +1118,8 @@ void RetroshareDirModel::getFilePaths(const QModelIndexList &list, std::list internalPointer(); DirDetails details; - uint32_t flags = DIR_FLAGS_DETAILS; - flags |= DIR_FLAGS_LOCAL; - if (!requestDirDetails(ref, details, flags)) + if (!requestDirDetails(ref, details, RS_FILE_HINTS_LOCAL)) { #ifdef RDM_DEBUG std::cerr << "getFilePaths() Bad Request" << std::endl; @@ -1193,15 +1173,7 @@ QMimeData * RetroshareDirModel::mimeData ( const QModelIndexList & indexes ) con void *ref = it -> internalPointer(); DirDetails details; - uint32_t flags = DIR_FLAGS_DETAILS; - if (RemoteMode) - { - flags |= DIR_FLAGS_REMOTE; - } - else - { - flags |= DIR_FLAGS_LOCAL; - } + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; if (!requestDirDetails(ref, details, flags)) { @@ -1278,7 +1250,7 @@ int RetroshareDirModel::getType ( const QModelIndex & index ) const //if (RemoteMode) // only local files can be opened // return ; - uint32_t flags = RemoteMode?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL; + FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; return rsFiles->getType(index.internalPointer(),flags); } @@ -1327,10 +1299,9 @@ void FlatStyle_RDM::updateRefs() std::cerr << "FlatStyle_RDM::postMods(): poped ref " << ref << std::endl; #endif _ref_stack.pop_back() ; - uint32_t flags = DIR_FLAGS_DETAILS; DirDetails details ; - if (requestDirDetails(ref, details, flags)) + if (requestDirDetails(ref, details, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_REMOTE)) { if(details.type == DIR_TYPE_FILE) // only push files, not directories nor persons. _ref_entries.push_back(std::pair(ref,computeDirectoryPath(details))); diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index 80f66448d..600005913 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -26,6 +26,7 @@ #include #include #include +#include class DirDetails; @@ -65,7 +66,7 @@ class RetroshareDirModel : public QAbstractItemModel void getFilePaths(const QModelIndexList &list, std::list &fullpaths); void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; } - bool requestDirDetails(void *ref,DirDetails& details,uint32_t flags) const; + bool requestDirDetails(void *ref,DirDetails& details,FileSearchFlags flags) const; void update() ; public: @@ -79,7 +80,8 @@ class RetroshareDirModel : public QAbstractItemModel void treeStyle(); void downloadDirectory(const DirDetails & details, int prefixLen); - static QString getFlagsString(uint32_t) ; + static QString getFlagsString(FileStorageFlags f) ; + static QString getGroupsString(const std::list&) ; QString getAgeIndicatorString(const DirDetails &) const; void getAgeIndicatorRec(DirDetails &details, QString &ret) const; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index d6b7335f0..401fa4c08 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -973,7 +973,7 @@ static void processList(const QStringList &list, const QString &textSingular, co srcIds.push_back((*it).peerId) ; } - if (rsFiles->FileRequest(link.name().toUtf8().constData(), link.hash().toStdString(), link.size(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) { + if (rsFiles->FileRequest(link.name().toUtf8().constData(), link.hash().toStdString(), link.size(), "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds)) { fileAdded.append(link.name()); } else { fileExist.append(link.name()); diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index 27346873f..f3d4cbf59 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -353,7 +353,7 @@ void SearchDialog::download() std::string hash = item->text(SR_HASH_COL).toStdString(); getSourceFriendsForHash(hash,srcIds) ; - if(!rsFiles -> FileRequest((item->text(SR_NAME_COL)).toUtf8().constData(), hash, (item->text(SR_SIZE_COL)).toULongLong(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) + if(!rsFiles -> FileRequest((item->text(SR_NAME_COL)).toUtf8().constData(), hash, (item->text(SR_SIZE_COL)).toULongLong(), "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds)) attemptDownloadLocal = true ; else { @@ -384,7 +384,7 @@ void SearchDialog::downloadDirectory(const QTreeWidgetItem *item, const QString rsFiles->FileRequest(item->text(SR_NAME_COL).toUtf8().constData(), hash, item->text(SR_SIZE_COL).toULongLong(), - cleanPath.toUtf8().constData(),RS_FILE_HINTS_NETWORK_WIDE, srcIds); + cleanPath.toUtf8().constData(),RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds); std::cout << "SearchDialog::downloadDirectory(): "\ "issuing file request from search dialog: -" @@ -607,7 +607,7 @@ void SearchDialog::advancedSearch(Expression* expression) // The text "bool exp" should be replaced by an appropriate text describing the actual search. 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, RS_FILE_HINTS_REMOTE);// | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE); /* abstraction to allow reusee of tree rendering code */ resultsToTree(advSearchDialog->getSearchAsString(),req_id, results); @@ -689,7 +689,7 @@ void SearchDialog::searchKeywords(const QString& keywords) { std::list initialResults; - rsFiles->SearchBoolExp(&exprs, initialResults, DIR_FLAGS_REMOTE) ; + rsFiles->SearchBoolExp(&exprs, initialResults, RS_FILE_HINTS_REMOTE) ; /* which extensions do we use? */ DirDetails dd; @@ -705,7 +705,7 @@ void SearchDialog::searchKeywords(const QString& keywords) { std::list initialResults; - rsFiles->SearchBoolExp(&exprs, initialResults, DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE) ; + rsFiles->SearchBoolExp(&exprs, initialResults, RS_FILE_HINTS_LOCAL);// | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE) ; /* which extensions do we use? */ DirDetails dd; @@ -859,7 +859,7 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons /* go through all children directories/files for a recursive call */ for (std::list::const_iterator it(dir.children.begin()); it != dir.children.end(); it ++) { DirDetails details; - rsFiles->RequestDirDetails(it->ref, details, 0); + rsFiles->RequestDirDetails(it->ref, details, FileSearchFlags(0u)); insertDirectory(txt, searchId, details, child); } } diff --git a/retroshare-gui/src/gui/ShareDialog.cpp b/retroshare-gui/src/gui/ShareDialog.cpp index ce21ee877..67062c7b9 100644 --- a/retroshare-gui/src/gui/ShareDialog.cpp +++ b/retroshare-gui/src/gui/ShareDialog.cpp @@ -21,11 +21,19 @@ #include "ShareDialog.h" #include +#include #include #include #include +#include +#include #include +#include +#include + +#include +#include /** Default constructor */ ShareDialog::ShareDialog(std::string filename, QWidget *parent, Qt::WFlags flags) @@ -43,16 +51,43 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent, Qt::WFlags flags ui.okButton->setEnabled(false); - if (filename.empty()) { - ui.networkwideCheckBox->setChecked(true); - } else { - /* edit exisiting share */ + QVBoxLayout *vbox = new QVBoxLayout() ; + + QHBoxLayout *hb2 = new QHBoxLayout() ; + hb2->addWidget(new QLabel(tr("Share flags and groups: "))) ; + + groupflagsbox = new GroupFlagsWidget(ui.shareflags_GB) ; + groupflagsbox->setFlags(DIR_FLAGS_NETWORK_WIDE_OTHERS) ; // default value + + messageBox = new QTextEdit(ui.shareflags_GB) ; + messageBox->setReadOnly(true) ; + messageBox->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred)) ; + + hb2->addWidget(groupflagsbox) ; + + vbox->addLayout(hb2) ; + vbox->addWidget(messageBox) ; + + QHBoxLayout *hbox = new QHBoxLayout() ; + groupselectionbox = new GroupSelectionBox(ui.shareflags_GB); + hbox->addLayout(vbox) ; + hbox->addWidget(groupselectionbox) ; + + ui.shareflags_GB->setLayout(hbox) ; + updateInfoMessage() ; + + connect(groupselectionbox,SIGNAL(itemSelectionChanged()),this,SLOT(updateInfoMessage())) ; + connect(groupflagsbox,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateInfoMessage())) ; + + if (!filename.empty()) + { std::list dirs; rsFiles->getSharedDirectories(dirs); std::list::const_iterator it; for (it = dirs.begin(); it != dirs.end(); it++) { - if (it->filename == filename) { + if (it->filename == filename) + { /* fill dialog */ ui.okButton->setEnabled(true); @@ -61,14 +96,20 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent, Qt::WFlags flags ui.browseButton->setDisabled(true); ui.virtualpath_lineEdit->setText(QString::fromUtf8(it->virtualname.c_str())); - ui.browsableCheckBox->setChecked(it->shareflags & RS_FILE_HINTS_BROWSABLE); - ui.networkwideCheckBox->setChecked(it->shareflags & RS_FILE_HINTS_NETWORK_WIDE); + groupflagsbox->setFlags(it->shareflags) ; + groupselectionbox->setSelectedGroups(it->parent_groups) ; + break; } } } } +void ShareDialog::updateInfoMessage() +{ + messageBox->setText(GroupFlagsWidget::groupInfoString(groupflagsbox->flags(),groupselectionbox->selectedGroups())) ; +} + void ShareDialog::browseDirectory() { /* select a dir*/ @@ -88,20 +129,16 @@ void ShareDialog::addDirectory() SharedDirInfo sdi ; sdi.filename = ui.localpath_lineEdit->text().toUtf8().constData(); sdi.virtualname = ui.virtualpath_lineEdit->text().toUtf8().constData(); + sdi.shareflags = groupflagsbox->flags() ; + sdi.parent_groups = groupselectionbox->selectedGroups() ; - sdi.shareflags = 0; - - if (ui.browsableCheckBox->isChecked()) { - sdi.shareflags |= RS_FILE_HINTS_BROWSABLE ; - } - if (ui.networkwideCheckBox->isChecked()) { - sdi.shareflags |= RS_FILE_HINTS_NETWORK_WIDE; - } - - if (ui.localpath_lineEdit->isEnabled()) { + if (ui.localpath_lineEdit->isEnabled()) + { /* add new share */ rsFiles->addSharedDirectory(sdi); - } else { + } + else + { /* edit exisiting share */ bool found = false; @@ -115,13 +152,15 @@ void ShareDialog::addDirectory() if (it->virtualname != sdi.virtualname) { /* virtual name changed, remove shared directory and add it again */ + rsFiles->removeSharedDirectory(it->filename); rsFiles->addSharedDirectory(sdi); break; } - if (it->shareflags ^ sdi.shareflags) { + if (it->shareflags != sdi.shareflags || it->parent_groups != sdi.parent_groups) { /* modifies the flags */ it->shareflags = sdi.shareflags; + it->parent_groups = sdi.parent_groups; rsFiles->updateShareFlags(*it); break; } diff --git a/retroshare-gui/src/gui/ShareDialog.h b/retroshare-gui/src/gui/ShareDialog.h index 349684728..e03b81ed9 100644 --- a/retroshare-gui/src/gui/ShareDialog.h +++ b/retroshare-gui/src/gui/ShareDialog.h @@ -26,22 +26,30 @@ #include "ui_ShareDialog.h" +class GroupFlagsWidget ; +class GroupSelectionBox ; +class QTextEdit ; + class ShareDialog : public QDialog { - Q_OBJECT + Q_OBJECT -public: - /** Default constructor */ - ShareDialog( std::string filename, QWidget *parent = 0, Qt::WFlags flags = 0); - /** Default destructor */ + public: + /** Default constructor */ + ShareDialog( std::string filename, QWidget *parent = 0, Qt::WFlags flags = 0); -private slots: - void browseDirectory(); - void addDirectory(); + private slots: + void browseDirectory(); + void addDirectory(); + void updateInfoMessage() ; -private: - /** Qt Designer generated object */ - Ui::ShareDialog ui; + private: + /** Qt Designer generated object */ + Ui::ShareDialog ui; + + GroupSelectionBox *groupselectionbox ; + GroupFlagsWidget *groupflagsbox ; + QTextEdit *messageBox ; }; #endif diff --git a/retroshare-gui/src/gui/ShareDialog.ui b/retroshare-gui/src/gui/ShareDialog.ui index e4d04c5c4..8b84eedc0 100644 --- a/retroshare-gui/src/gui/ShareDialog.ui +++ b/retroshare-gui/src/gui/ShareDialog.ui @@ -35,6 +35,9 @@ 1 + groupBox + frame_2 + groupBox @@ -45,17 +48,14 @@ QFrame::Raised - - - 6 - - + + Share Folder - - + + @@ -108,101 +108,87 @@ - - - - Share Flags - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Browseable by Friends - - - Browsable - - - - - - - Anonymous shared Network Wide - - - Network Wide - - - - - - - - - - - 0 - 0 - - - - - 200 - 200 - - - - OK - - - - 16 - 16 - - - - false - - - true - - + + + + + + Share Flags + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - - Qt::Horizontal - - - - 191 - 20 - - - - - - - - Cancel - - + + + + + + + 0 + 0 + + + + + 200 + 200 + + + + OK + + + + 16 + 16 + + + + false + + + true + + + + + + + Cancel + + + + + + + Qt::Horizontal + + + + 191 + 20 + + + + + diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index ee62e0f85..8e5734571 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -27,10 +27,12 @@ #include #include +#include #include "ShareManager.h" #include "ShareDialog.h" #include "settings/rsharesettings.h" +#include /* Images for context menu icons */ #define IMAGE_CANCEL ":/images/delete.png" @@ -38,9 +40,8 @@ #define COLUMN_PATH 0 #define COLUMN_VIRTUALNAME 1 -#define COLUMN_NETWORKWIDE 2 -#define COLUMN_BROWSABLE 3 -#define COLUMN_COUNT 3 +#define COLUMN_SHARE_FLAGS 2 +#define COLUMN_GROUPS 3 ShareManager *ShareManager::_instance = NULL ; @@ -73,15 +74,12 @@ ShareManager::ShareManager() QHeaderView* header = ui.shareddirList->horizontalHeader(); header->setResizeMode( COLUMN_PATH, QHeaderView::Stretch); - header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::Fixed); - header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::Fixed); + //header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::Fixed); + //header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::Fixed); header->setHighlightSections(false); - ui.shareddirList->setRangeSelected(QTableWidgetSelectionRange(0, 0, 0, COLUMN_COUNT), true); - setAcceptDrops(true); - setAttribute(Qt::WA_DeleteOnClose, true); } @@ -124,79 +122,35 @@ void ShareManager::load() /* set new row count */ listWidget->setRowCount(dirs.size()); - connect(this,SIGNAL(itemClicked(QTableWidgetItem*)),this,SLOT(updateFlags(QTableWidgetItem*))) ; - -#ifndef USE_COMBOBOX - QString ToolTips [2] = { tr("If checked, the share is anonymously shared to anybody."), - tr("If checked, the share is browsable by your friends.") }; - int Flags [2] = { RS_FILE_HINTS_NETWORK_WIDE, RS_FILE_HINTS_BROWSABLE }; -#endif - int row=0 ; for(it = dirs.begin(); it != dirs.end(); it++,++row) { listWidget->setItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8((*it).filename.c_str()))); listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8((*it).virtualname.c_str()))); -#ifdef USE_COMBOBOX - QComboBox *cb = new QComboBox ; - cb->addItem(QString("Network Wide")) ; - cb->addItem(QString("Browsable")) ; - cb->addItem(QString("Universal")) ; + GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,(*it).shareflags); - cb->setToolTip(QString("Decide here whether this directory is\n* Network Wide: \tanonymously shared over the network (including your friends)\n* Browsable: \tbrowsable by your friends\n* Universal: \t\tboth")) ; + listWidget->setRowHeight(row, 32); + listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget); - // TODO - // - set combobox current value depending on what rsFiles reports. - // - use a signal mapper to get the correct row that contains the combo box sending the signal: - // mapper = new SignalMapper(this) ; - // - // for(all cb) - // { - // signalMapper->setMapping(cb,...) - // } - // - int index = 0 ; - index += ((*it).shareflags & RS_FILE_HINTS_NETWORK_WIDE) > 0 ; - index += (((*it).shareflags & RS_FILE_HINTS_BROWSABLE) > 0) * 2 ; - listWidget->setCellWidget(row,1,cb); + QString group_string ; + int n=0; + for(std::list::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n) + { + if(n>0) + group_string += ", " ; - if(index < 1 || index > 3) - std::cerr << "******* ERROR IN FILE SHARING FLAGS. Flags = " << (*it).shareflags << " ***********" << std::endl ; - else - index-- ; + group_string += QString::fromStdString(*it2) ; + } - cb->setCurrentIndex(index) ; -#else - int col; - for (col = 0; col <= 1; col++) { - QModelIndex index = listWidget->model()->index(row, col + COLUMN_NETWORKWIDE, QModelIndex()); - QWidget* widget = dynamic_cast(listWidget->indexWidget(index)); - QCheckBox* cb = NULL; - if (widget) { - cb = dynamic_cast(widget->children().front()); - } - if (cb == NULL) { - QWidget* widget = new QWidget; + listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem(group_string)) ; + listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ; - cb = new QCheckBox(widget); - cb->setToolTip(ToolTips [col]); - - QHBoxLayout* layout = new QHBoxLayout(widget); - layout->addWidget(cb, 0, Qt::AlignCenter); - layout->setSpacing(0); - layout->setContentsMargins(10, 0, 0, 0); // to be centered - widget->setLayout(layout); - - listWidget->setCellWidget(row, col + COLUMN_NETWORKWIDE, widget); - - QObject::connect(cb, SIGNAL(toggled(bool)), this, SLOT(updateFlags(bool))) ; - } - cb->setChecked((*it).shareflags & Flags [col]); - } -#endif + connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ; } + listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132) ; + //ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory())); listWidget->update(); /* update display */ @@ -225,12 +179,12 @@ void ShareManager::showYourself() } } -void ShareManager::updateFlags(bool b) +void ShareManager::updateFlags() { if(isLoading) return ; - std::cerr << "Updating flags (b=" << b << ") !!!" << std::endl ; + std::cerr << "Updating flags" << std::endl; std::list::iterator it; std::list dirs; @@ -239,17 +193,15 @@ void ShareManager::updateFlags(bool b) int row=0 ; for(it = dirs.begin(); it != dirs.end(); it++,++row) { - std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ; - uint32_t current_flags = 0 ; - current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_NETWORKWIDE)->children().front()))->isChecked()? RS_FILE_HINTS_NETWORK_WIDE:0 ; - current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_BROWSABLE)->children().front()))->isChecked()? RS_FILE_HINTS_BROWSABLE:0 ; + //std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ; + FileStorageFlags current_flags = (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ; - if( (*it).shareflags ^ current_flags ) + if( (*it).shareflags != current_flags ) { (*it).shareflags = current_flags ; rsFiles->updateShareFlags(*it) ; // modifies the flags - std::cout << "Updating share flags for directory " << (*it).filename << std::endl ; + std::cout << "Updating share flags for directory " << (*it).filename << " to " << current_flags << std::endl ; } } } @@ -357,7 +309,7 @@ void ShareManager::dropEvent(QDropEvent *event) sdi.filename = localpath.toUtf8().constData(); sdi.virtualname.clear(); - sdi.shareflags = 0; + sdi.shareflags.clear() ; /* add new share */ rsFiles->addSharedDirectory(sdi); diff --git a/retroshare-gui/src/gui/ShareManager.h b/retroshare-gui/src/gui/ShareManager.h index 4af7b1edb..0dc9d8c6e 100644 --- a/retroshare-gui/src/gui/ShareManager.h +++ b/retroshare-gui/src/gui/ShareManager.h @@ -59,7 +59,7 @@ private slots: void showShareDialog(); void editShareDirectory(); void removeShareDirectory(); - void updateFlags(bool); + void updateFlags(); private: static ShareManager *_instance; diff --git a/retroshare-gui/src/gui/ShareManager.ui b/retroshare-gui/src/gui/ShareManager.ui index 3ad187968..bb9b948ab 100644 --- a/retroshare-gui/src/gui/ShareManager.ui +++ b/retroshare-gui/src/gui/ShareManager.ui @@ -81,14 +81,23 @@ p, li { white-space: pre-wrap; } QAbstractItemView::NoEditTriggers + + true + QAbstractItemView::SingleSelection QAbstractItemView::SelectRows + + false + + + true + - 100 + 128 false @@ -108,7 +117,7 @@ p, li { white-space: pre-wrap; } - Network Wide + Share flags @@ -116,7 +125,7 @@ p, li { white-space: pre-wrap; } - Browsable + Parent groups diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index 87d1b7f6e..2d995e478 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -157,17 +157,12 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent) /* Set header resize modes and initial section sizes */ QHeaderView * l_header = ui.localDirTreeView->header () ; -// l_header->setResizeMode (0, QHeaderView::Interactive); -// l_header->setResizeMode (1, QHeaderView::Fixed); -// l_header->setResizeMode (2, QHeaderView::Interactive); -// l_header->setResizeMode (3, QHeaderView::Interactive); -// l_header->setResizeMode (4, QHeaderView::Interactive); l_header->resizeSection ( 0, 490 ); l_header->resizeSection ( 1, 70 ); l_header->resizeSection ( 2, 100 ); l_header->resizeSection ( 3, 100 ); -// l_header->resizeSection ( 4, 100 ); + l_header->resizeSection ( 4, 100 ); l_header->setStretchLastSection(false); // l_header->setHighlightSections(false); @@ -210,7 +205,7 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent) // Hide columns after loading the settings ui.remoteDirTreeView->setColumnHidden(3,false) ; ui.remoteDirTreeView->setColumnHidden(4,true) ; - ui.localDirTreeView->setColumnHidden(4,true) ; + ui.localDirTreeView->setColumnHidden(4,false) ; /* Hide platform specific features */ #ifdef Q_WS_WIN @@ -468,11 +463,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote) const DirStub& dirStub = *cit; DirDetails details; - uint32_t flags = DIR_FLAGS_DETAILS; - if (remote) - flags |= DIR_FLAGS_REMOTE; - else - flags |= DIR_FLAGS_LOCAL; + FileSearchFlags flags = remote?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL ; // do not recursive copy sub dirs. if (!rsFiles->RequestDirDetails(dirStub.ref, details, flags) || details.type != DIR_TYPE_FILE) diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index d9f9aed45..a8dea4ea4 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -945,7 +945,7 @@ void TransfersDialog::insertTransfers() continue; } - if ((fileInfo.flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers) { + if ((fileInfo.transfer_info_flags & RS_FILE_REQ_CACHE) && !showCacheTransfers) { // if file transfer is a cache file index file, don't show it DLListModel->removeRow(row); rowCount = DLListModel->rowCount(); @@ -971,7 +971,7 @@ void TransfersDialog::insertTransfers() continue; } - if ((fileInfo.flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers) { + if ((fileInfo.transfer_info_flags & RS_FILE_REQ_CACHE) && !showCacheTransfers) { //if file transfer is a cache file index file, don't show it continue; } @@ -998,7 +998,7 @@ void TransfersDialog::insertTransfers() if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info)) continue; - if((info.flags & RS_FILE_HINTS_CACHE) && showCacheTransfers) + if((info.transfer_info_flags & RS_FILE_REQ_CACHE) && showCacheTransfers) continue ; std::list::iterator pit; diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp new file mode 100644 index 000000000..999f67842 --- /dev/null +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp @@ -0,0 +1,174 @@ +#include +#include +#include "GroupFlagsWidget.h" +#include + +#define FLAGS_GROUP_NETWORK_WIDE_ICON ":images/anonymous_128_green.png" +#define FLAGS_GROUP_BROWSABLE_ICON ":images/browsable_128_green.png" +#define FLAGS_GROUP_UNCHECKED ":images/blank_128_green.png" +#define FLAGS_OTHER_NETWORK_WIDE_ICON ":images/anonymous_128_blue.png" +#define FLAGS_OTHER_BROWSABLE_ICON ":images/browsable_128_blue.png" +#define FLAGS_OTHER_UNCHECKED ":images/blank_128_blue.png" + +#define INDEX_GROUP_BROWSABLE 0 +#define INDEX_GROUP_NETWORK_W 1 +#define INDEX_OTHER_BROWSABLE 2 +#define INDEX_OTHER_NETWORK_W 3 +#define INDEX_GROUP_UNCHECKED 4 +#define INDEX_OTHER_UNCHECKED 5 + +QString GroupFlagsWidget::_tooltips_on[4] = { + QObject::tr("Directory is browsable for friends from parent groups"), + QObject::tr("Directory is accessible by anonymous tunnels from friends from parent groups"), + QObject::tr("Directory is browsable for any friend"), + QObject::tr("Directory is accessible by anonymous tunnels from any friend") +}; +QString GroupFlagsWidget::_tooltips_off[4] = { + QObject::tr(""), + QObject::tr(""), + QObject::tr(""), + QObject::tr("") +}; + +GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags) + : QWidget(parent) +{ + _layout = new QHBoxLayout(this) ; + + setMinimumSize(128,32) ; + setMaximumSize(128,32) ; + setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); + + _icons[INDEX_GROUP_BROWSABLE] = new QIcon(FLAGS_GROUP_BROWSABLE_ICON) ; + _icons[INDEX_GROUP_NETWORK_W] = new QIcon(FLAGS_GROUP_NETWORK_WIDE_ICON) ; + _icons[INDEX_OTHER_BROWSABLE] = new QIcon(FLAGS_OTHER_BROWSABLE_ICON) ; + _icons[INDEX_OTHER_NETWORK_W] = new QIcon(FLAGS_OTHER_NETWORK_WIDE_ICON) ; + _icons[INDEX_GROUP_UNCHECKED] = new QIcon(FLAGS_GROUP_UNCHECKED) ; + _icons[INDEX_OTHER_UNCHECKED] = new QIcon(FLAGS_OTHER_UNCHECKED) ; + + setLayout(_layout) ; + + _flags[0] = DIR_FLAGS_BROWSABLE_GROUPS ; + _flags[1] = DIR_FLAGS_NETWORK_WIDE_GROUPS ; + _flags[2] = DIR_FLAGS_BROWSABLE_OTHERS ; + _flags[3] = DIR_FLAGS_NETWORK_WIDE_OTHERS ; + + for(int i=0;i<4;++i) + { + _buttons[i] = new QPushButton(this) ; + _buttons[i]->setCheckable(true) ; + _buttons[i]->setChecked(flags & _flags[i]) ; + _buttons[i]->setIconSize(QSize(32,32)); + update_button_state(_buttons[i]->isChecked(),i) ; + _layout->addWidget(_buttons[i]) ; + } + _buttons[INDEX_GROUP_NETWORK_W]->setHidden(true); + + connect(_buttons[INDEX_GROUP_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_GN_button(bool))) ; + connect(_buttons[INDEX_OTHER_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_ON_button(bool))) ; + connect(_buttons[INDEX_GROUP_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_GB_button(bool))) ; + connect(_buttons[INDEX_OTHER_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_OB_button(bool))) ; + + _layout->setSpacing(0); + _layout->setContentsMargins(0, 0, 0, 0); + + _layout->update() ; +} + +void GroupFlagsWidget::updated() +{ + emit flagsChanged(flags()) ; +} + +FileStorageFlags GroupFlagsWidget::flags() const +{ + FileStorageFlags flags ; + + for(int i=0;i<4;++i) + if(_buttons[i]->isChecked()) flags |= _flags[i] ; + + flags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; + return flags ; +} + +void GroupFlagsWidget::setFlags(FileStorageFlags flags) +{ + for(int i=0;i<4;++i) + { + _buttons[i]->setChecked(flags & _flags[i]) ; + update_button_state(_buttons[i]->isChecked(),i) ; + } +} + +void GroupFlagsWidget::update_button_state(bool b,int button_id) +{ + if(b) + { + _buttons[button_id]->setIcon(*_icons[button_id]) ; + _buttons[button_id]->setToolTip(_tooltips_on[button_id]) ; + } + else if(button_id == INDEX_GROUP_NETWORK_W || button_id == INDEX_GROUP_BROWSABLE) + { + _buttons[button_id]->setIcon(*_icons[INDEX_GROUP_UNCHECKED]) ; + _buttons[button_id]->setToolTip(_tooltips_off[button_id]) ; + } + else + { + _buttons[button_id]->setIcon(*_icons[INDEX_OTHER_UNCHECKED]) ; + _buttons[button_id]->setToolTip(_tooltips_off[button_id]) ; + } +} + +QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags,const std::list& groups) +{ + // makes a string that explains how files are shared / visible. + + QString res ; + QString groups_string ; + + for(std::list::const_iterator it(groups.begin());it!=groups.end();++it) + { + if(it != groups.begin()) + groups_string += ", " ; + groups_string += QString::fromStdString(*it) ; + } + + if(flags & DIR_FLAGS_BROWSABLE_OTHERS) + res += tr("All your friends can browse this directory\n") ; + else if(flags & DIR_FLAGS_BROWSABLE_GROUPS) + if(!groups.empty()) + res += tr("Only friends in groups ") + groups_string + tr(" can browse this directory\n") ; + else + res += tr("No one can browse this directory\n") ; + else + res += tr("No one can browse this directory\n") ; + + if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) + res += tr("All your friends can relay anonymous tunnels to this directory") ; + else if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) + res += tr("Only friends in groups ") + groups_string + tr(" can relay anonymous tunnels to this directory") ; + else + res += tr("No one can anonymously access this directory.") ; + + //if(flags.toUInt32() == 0) + // res += tr("No friends can access nor see this directory.") ; + + return res ; +} + +void GroupFlagsWidget::update_GN_button(bool b) { update_button_state(b,INDEX_GROUP_NETWORK_W) ; updated() ; } +void GroupFlagsWidget::update_GB_button(bool b) { update_button_state(b,INDEX_GROUP_BROWSABLE) ; updated() ; } +void GroupFlagsWidget::update_ON_button(bool b) { update_button_state(b,INDEX_OTHER_NETWORK_W) ; updated() ; } +void GroupFlagsWidget::update_OB_button(bool b) { update_button_state(b,INDEX_OTHER_BROWSABLE) ; updated() ; } + +GroupFlagsWidget::~GroupFlagsWidget() +{ + for(int i=0;i<4;++i) + { + delete _buttons[i] ; + delete _icons[i] ; + } + delete _icons[INDEX_GROUP_UNCHECKED] ; + delete _icons[INDEX_OTHER_UNCHECKED] ; +} + diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.h b/retroshare-gui/src/gui/common/GroupFlagsWidget.h new file mode 100644 index 000000000..1aa288833 --- /dev/null +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include + +class GroupFlagsWidget: public QWidget +{ + Q_OBJECT + + public: + GroupFlagsWidget(QWidget *parent,FileStorageFlags flags = FileStorageFlags(0u)) ; + virtual ~GroupFlagsWidget() ; + + FileStorageFlags flags() const ; + void setFlags(FileStorageFlags flags) ; + + static QString groupInfoString(FileStorageFlags flags,const std::list& groups) ; + public slots: + void updated() ; + + protected slots: + void update_GN_button(bool) ; + void update_GB_button(bool) ; + void update_ON_button(bool) ; + void update_OB_button(bool) ; + + signals: + void flagsChanged(FileStorageFlags) const ; + + private: + void update_button_state(bool b,int id) ; + + QPushButton *_buttons[4] ; + + QLayout *_layout ; + QIcon *_icons[6] ; + FileStorageFlags _flags[4] ; + + static QString _tooltips_on[4] ; + static QString _tooltips_off[4] ; +}; diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp new file mode 100644 index 000000000..4f01bd065 --- /dev/null +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp @@ -0,0 +1,43 @@ +#include +#include "GroupSelectionBox.h" + +GroupSelectionBox::GroupSelectionBox(QWidget *parent) + : QListWidget(parent) +{ + setSelectionMode(QAbstractItemView::ExtendedSelection) ; + + // Fill with available groups + + std::list lst ; + rsPeers->getGroupInfoList(lst) ; + + for(std::list::const_iterator it(lst.begin());it!=lst.end();++it) + addItem(QString::fromStdString(it->id)) ; + + for(int i=0;isetBackgroundColor(QColor(183,236,181)) ; +} + +std::list GroupSelectionBox::selectedGroups() const +{ + QList selected_items = selectedItems() ; + std::list out ; + + for(QList::const_iterator it(selected_items.begin());it!=selected_items.end();++it) + { + out.push_back((*it)->text().toStdString()) ; + std::cerr << "Addign selected item " << out.back() << std::endl; + } + + return out ; +} + +void GroupSelectionBox::setSelectedGroups(const std::list& group_ids) +{ + for(std::list::const_iterator it(group_ids.begin());it!=group_ids.end();++it) + { + QList lst = findItems(QString::fromStdString(*it),Qt::MatchExactly) ; + + setCurrentItem(*lst.begin(),QItemSelectionModel::Select) ; + } +} diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.h b/retroshare-gui/src/gui/common/GroupSelectionBox.h new file mode 100644 index 000000000..48deeee98 --- /dev/null +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.h @@ -0,0 +1,11 @@ +#include + +class GroupSelectionBox: public QListWidget +{ + public: + GroupSelectionBox(QWidget *parent) ; + + std::list selectedGroups() const ; + + void setSelectedGroups(const std::list& selected_group_ids) ; +}; diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index 93dd506e9..f62ebca63 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -217,7 +217,7 @@ void RsCollectionDialog::download() if(!QDir(QApplication::applicationDirPath()).mkpath(cleanPath)) QMessageBox::warning(NULL,QObject::tr("Unable to make path"),QObject::tr("Unable to make path:")+"
"+cleanPath) ; - rsFiles->FileRequest(dlinfo.name.toUtf8().constData(), dlinfo.hash.toUtf8().constData(), dlinfo.size, cleanPath.toUtf8().constData(), RS_FILE_HINTS_NETWORK_WIDE, std::list()); + rsFiles->FileRequest(dlinfo.name.toUtf8().constData(), dlinfo.hash.toUtf8().constData(), dlinfo.size, cleanPath.toUtf8().constData(), RS_FILE_REQ_ANONYMOUS_ROUTING, std::list()); } else std::cerr<<"Skipping file : " << dlinfo.name.toStdString() << std::endl; diff --git a/retroshare-gui/src/gui/common/RsCollectionFile.cpp b/retroshare-gui/src/gui/common/RsCollectionFile.cpp index 0ad18928e..ec5aaa6e6 100644 --- a/retroshare-gui/src/gui/common/RsCollectionFile.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionFile.cpp @@ -110,7 +110,7 @@ void RsCollectionFile::recursAddElements(QDomDocument& doc,const DirDetails& det continue; DirDetails subDirDetails; - uint32_t flags = DIR_FLAGS_CHILDREN | DIR_FLAGS_LOCAL; + FileSearchFlags flags = RS_FILE_HINTS_LOCAL; if (!rsFiles->RequestDirDetails(it->ref, subDirDetails, flags)) continue; diff --git a/retroshare-gui/src/gui/feeds/AttachFileItem.cpp b/retroshare-gui/src/gui/feeds/AttachFileItem.cpp index 26792913a..706efa960 100644 --- a/retroshare-gui/src/gui/feeds/AttachFileItem.cpp +++ b/retroshare-gui/src/gui/feeds/AttachFileItem.cpp @@ -100,7 +100,7 @@ AttachFileItem::AttachFileItem(const QString& path) mType = AFI_TYPE_ATTACH; /* ask for Files to hash/prepare it for us */ - if ((!rsFiles) || (!rsFiles->ExtraFileHash(path.toUtf8().constData(), AFI_DEFAULT_PERIOD, 0))) + if ((!rsFiles) || (!rsFiles->ExtraFileHash(path.toUtf8().constData(), AFI_DEFAULT_PERIOD, TransferRequestFlags(0u)))) { mMode = AFI_STATE_ERROR; } @@ -123,7 +123,7 @@ void AttachFileItem::Setup() if (mMode == AFI_STATE_REMOTE) { FileInfo fi; - uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY; + FileSearchFlags hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY; /* look up path */ if (rsFiles->FileDetails(mFileHash, hintflags, fi)) @@ -194,7 +194,7 @@ void AttachFileItem::updateItemStatic() if (mPath == "") { FileInfo fi; - uint32_t hintflags = RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_LOCAL + FileSearchFlags hintflags = RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY; /* look up path */ @@ -350,7 +350,7 @@ void AttachFileItem::updateItem() } else { - uint32_t hintflags = 0; + FileSearchFlags hintflags(0u); switch(mMode) { case AFI_STATE_REMOTE: diff --git a/retroshare-gui/src/gui/feeds/SubFileItem.cpp b/retroshare-gui/src/gui/feeds/SubFileItem.cpp index 9fbfa8943..c43603163 100644 --- a/retroshare-gui/src/gui/feeds/SubFileItem.cpp +++ b/retroshare-gui/src/gui/feeds/SubFileItem.cpp @@ -182,7 +182,7 @@ void SubFileItem::updateItemStatic() if (mPath == "") { FileInfo fi; - uint32_t hintflags = RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE; + FileSearchFlags hintflags = RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE; /* look up path */ if (!rsFiles->FileDetails(mFileHash, hintflags, fi)) @@ -364,7 +364,7 @@ void SubFileItem::updateItem() } else { - uint32_t hintflags = 0; + FileSearchFlags hintflags(0u) ; switch(mMode) { case SFI_STATE_REMOTE: @@ -544,7 +544,7 @@ void SubFileItem::cancel() if (((mType == SFI_TYPE_ATTACH) || (mType == SFI_TYPE_CHANNEL)) && (mFlag & SFI_FLAG_CREATE)) { hide(); - rsFiles->ExtraFileRemove(FileHash(), RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_EXTRA); + rsFiles->ExtraFileRemove(FileHash(), RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA); mPath = ""; } else @@ -559,7 +559,7 @@ void SubFileItem::cancel() void SubFileItem::play() { FileInfo info; - uint32_t flags = RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE; + FileSearchFlags flags = RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE; if (!rsFiles->FileDetails( mFileHash, flags, info)) @@ -612,7 +612,7 @@ void SubFileItem::download() if (mSrcId != "") sources.push_back(mSrcId); - rsFiles->FileRequest(mFileName, mFileHash, mFileSize, "", RS_FILE_HINTS_NETWORK_WIDE, sources); + rsFiles->FileRequest(mFileName, mFileHash, mFileSize, "", RS_FILE_REQ_ANONYMOUS_ROUTING, sources); downloadButton->setEnabled(false); diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index ccc0c561a..faca7a215 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -1,5 +1,11 @@ + images/anonymous_128_green.png + images/anonymous_128_blue.png + images/browsable_128_green.png + images/browsable_128_blue.png + images/blank_128_green.png + images/blank_128_blue.png images/splash.png images/help/addafriend.png images/help/addfriendkey.png diff --git a/retroshare-gui/src/gui/images/anonymous_128_blue.png b/retroshare-gui/src/gui/images/anonymous_128_blue.png new file mode 100644 index 000000000..5a67f5ce7 Binary files /dev/null and b/retroshare-gui/src/gui/images/anonymous_128_blue.png differ diff --git a/retroshare-gui/src/gui/images/anonymous_128_green.png b/retroshare-gui/src/gui/images/anonymous_128_green.png new file mode 100644 index 000000000..acf437a6b Binary files /dev/null and b/retroshare-gui/src/gui/images/anonymous_128_green.png differ diff --git a/retroshare-gui/src/gui/images/blank_128_blue.png b/retroshare-gui/src/gui/images/blank_128_blue.png new file mode 100644 index 000000000..22c5a5af9 Binary files /dev/null and b/retroshare-gui/src/gui/images/blank_128_blue.png differ diff --git a/retroshare-gui/src/gui/images/blank_128_green.png b/retroshare-gui/src/gui/images/blank_128_green.png new file mode 100644 index 000000000..def539368 Binary files /dev/null and b/retroshare-gui/src/gui/images/blank_128_green.png differ diff --git a/retroshare-gui/src/gui/images/browsable_128_blue.png b/retroshare-gui/src/gui/images/browsable_128_blue.png new file mode 100644 index 000000000..41812ec55 Binary files /dev/null and b/retroshare-gui/src/gui/images/browsable_128_blue.png differ diff --git a/retroshare-gui/src/gui/images/browsable_128_green.png b/retroshare-gui/src/gui/images/browsable_128_green.png new file mode 100644 index 000000000..79820230e Binary files /dev/null and b/retroshare-gui/src/gui/images/browsable_128_green.png differ diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index 082e6f413..ae140be75 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -323,7 +323,7 @@ void MessageWidget::getcurrentrecommended() const FileInfo& fi(it->second) ; std::cout << "Requesting file " << fi.fname << ", size=" << fi.size << ", hash=" << fi.hash << std::endl ; - if (rsFiles->FileRequest(fi.fname, fi.hash, fi.size, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds) == false) { + if (rsFiles->FileRequest(fi.fname, fi.hash, fi.size, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds) == false) { QMessageBox mb(QObject::tr("File Request canceled"), QObject::tr("The following has not been added to your download list, because you already have it:\n ") + QString::fromUtf8(fi.fname.c_str()), QMessageBox::Critical, QMessageBox::Ok, 0, 0); mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png"))); mb.exec(); @@ -347,7 +347,7 @@ void MessageWidget::getallrecommended() std::cerr << "MessageWidget::getallrecommended() Calling File Request" << std::endl; std::list srcIds; srcIds.push_back(msgInfo.srcId); - rsFiles->FileRequest(it->fname, it->hash, it->size, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds); + rsFiles->FileRequest(it->fname, it->hash, it->size, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds); } } diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 6ea71301b..469d816ff 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -357,6 +357,8 @@ HEADERS += rshare.h \ gui/common/rwindow.h \ gui/common/html.h \ gui/common/AvatarDefs.h \ + gui/common/GroupFlagsWidget.h \ + gui/common/GroupSelectionBox.h \ gui/common/StatusDefs.h \ gui/common/TagDefs.h \ gui/common/GroupDefs.h \ @@ -619,6 +621,8 @@ SOURCES += main.cpp \ gui/common/rwindow.cpp \ gui/common/html.cpp \ gui/common/AvatarDefs.cpp \ + gui/common/GroupFlagsWidget.cpp \ + gui/common/GroupSelectionBox.cpp \ gui/common/StatusDefs.cpp \ gui/common/TagDefs.cpp \ gui/common/GroupDefs.cpp \