mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
First shot of file sharing permissions. Compiles, but needs some testing/debugging.
- added type-safe flags in retroshare/rsflags.h. This should be used to make new flags types in order to prevent mixing flags up in function prototypes. - group handling is left to rsPeers. We'll move it to rsCircles later. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-FileSharingPermissions@5754 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
03d4936b12
commit
dc82cee700
27 changed files with 567 additions and 336 deletions
|
@ -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_HINTS_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_HINTS_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringFileTunnels(_queue[pos]->mHash) ;
|
||||
}
|
||||
}
|
||||
|
@ -875,7 +875,7 @@ bool ftController::completeFile(std::string hash)
|
|||
|
||||
mDownloads.erase(it);
|
||||
|
||||
if(flags & RS_FILE_HINTS_NETWORK_WIDE)
|
||||
if(flags & RS_FILE_HINTS_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ;
|
||||
|
||||
} /******* UNLOCKED ********/
|
||||
|
@ -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, DIR_FLAGS_PERMISSIONS_MASK | 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, TransferInfoFlags flags,
|
||||
const std::list<std::string> &_srcIds)
|
||||
{
|
||||
std::list<std::string> srcIds(_srcIds) ;
|
||||
|
@ -1196,7 +1196,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
|||
/* do a source search - for any extra sources */
|
||||
// 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,7 +1242,7 @@ 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_HINTS_ANONYMOUS_ROUTING)
|
||||
mTurtle->monitorFileTunnels(fname,hash,size) ;
|
||||
|
||||
bool assume_availability = flags & RS_FILE_HINTS_CACHE ; // assume availability for cache files
|
||||
|
@ -1623,7 +1623,7 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
|||
/* extract details */
|
||||
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 ;
|
||||
|
|
|
@ -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, TransferInfoFlags flags,
|
||||
const std::list<std::string> &sourceIds);
|
||||
|
||||
/// Do we already have this file, either in download or in file lists ?
|
||||
|
|
|
@ -142,7 +142,7 @@ bool ftDataMultiplex::FileDownloads(std::list<std::string> &hashs)
|
|||
}
|
||||
|
||||
|
||||
bool ftDataMultiplex::FileDetails(const std::string &hash, uint32_t hintsflag, FileInfo &info)
|
||||
bool ftDataMultiplex::FileDetails(const std::string &hash, TransferInfoFlags hintsflag, FileInfo &info)
|
||||
{
|
||||
#ifdef MPLEX_DEBUG
|
||||
std::cerr << "ftDataMultiplex::FileDetails(";
|
||||
|
@ -1316,11 +1316,11 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::
|
|||
uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY ;
|
||||
|
||||
if(rsTurtle->isTurtlePeer(peerId))
|
||||
hintflags |= RS_FILE_HINTS_NETWORK_WIDE ;
|
||||
hintflags |= RS_FILE_HINTS_ANONYMOUS_ROUTING ;
|
||||
else
|
||||
hintflags |= RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_CACHE ;
|
||||
hintflags |= RS_FILE_HINTS_CACHE ;
|
||||
|
||||
if (mSearch->search(hash, hintflags, info))
|
||||
if(mSearch->search(hash, hintflags,peerId, info))
|
||||
{
|
||||
|
||||
/* setup a new provider */
|
||||
|
|
|
@ -104,7 +104,7 @@ class ftDataMultiplex: public ftDataRecv, public RsQueueThread
|
|||
/* get Details of File Transfers */
|
||||
bool FileUploads(std::list<std::string> &hashs);
|
||||
bool FileDownloads(std::list<std::string> &hashs);
|
||||
bool FileDetails(const std::string &hash, uint32_t hintsflag, FileInfo &info);
|
||||
bool FileDetails(const std::string &hash, TransferInfoFlags hintsflag, FileInfo &info);
|
||||
|
||||
void deleteUnusedServers() ;
|
||||
void handlePendingCrcRequests() ;
|
||||
|
|
|
@ -129,6 +129,11 @@ ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cached
|
|||
}
|
||||
|
||||
bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &info) const
|
||||
{
|
||||
std::cerr << "(EE) ********* ftFiMonitor expects a peer id in search()!" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, const std::string& peer_id,FileInfo &info) const
|
||||
{
|
||||
uint64_t fsize;
|
||||
std::string path;
|
||||
|
@ -144,7 +149,7 @@ bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &
|
|||
//
|
||||
uint32_t flags = hintflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE);
|
||||
|
||||
if(findLocalFile(hash, flags, path, fsize))
|
||||
if(findLocalFile(hash, flags,peer_id,path, fsize))
|
||||
{
|
||||
/* fill in details */
|
||||
#ifdef DB_DEBUG
|
||||
|
@ -288,6 +293,7 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
|
|||
/* for each item, check it exists ....
|
||||
* - remove any that are dead (or flag?)
|
||||
*/
|
||||
static const uint32_t PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ;
|
||||
|
||||
#ifdef DEBUG_ELIST
|
||||
std::cerr << "ftFiMonitor::loadList()";
|
||||
|
@ -341,7 +347,7 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& 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.shareflags = fi->flags & PERMISSION_MASK ;
|
||||
|
||||
dirList.push_back(info) ;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
|||
|
||||
/* overloaded search function */
|
||||
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const;
|
||||
virtual bool search(const std::string &hash, uint32_t hintflags, const std::string& peer_id, FileInfo &info) const;
|
||||
|
||||
/* overloaded set dirs enables config indication */
|
||||
virtual void setSharedDirectories(const std::list<SharedDirInfo>& dirList);
|
||||
|
|
|
@ -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, uint32_t hintflags,const std::string& peer_id, FileInfo &info) const
|
||||
{
|
||||
std::cerr << "Non overloaded search method called!!!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ bool ftServer::alreadyHaveFile(const std::string& hash, FileInfo &info)
|
|||
return mFtController->alreadyHaveFile(hash, info);
|
||||
}
|
||||
|
||||
bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, uint32_t flags, const std::list<std::string>& srcIds)
|
||||
bool ftServer::FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferInfoFlags flags, const std::list<std::string>& srcIds)
|
||||
{
|
||||
std::string error_string ;
|
||||
|
||||
|
@ -415,7 +415,7 @@ bool ftServer::FileUploads(std::list<std::string> &hashs)
|
|||
return mFtDataplex->FileUploads(hashs);
|
||||
}
|
||||
|
||||
bool ftServer::FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info)
|
||||
bool ftServer::FileDetails(const std::string &hash, TransferInfoFlags hintflags, FileInfo &info)
|
||||
{
|
||||
if (hintflags & RS_FILE_HINTS_DOWNLOAD)
|
||||
if(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_HINTS_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, TransferInfoFlags flags)
|
||||
{
|
||||
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileRemove(std::string hash, uint32_t flags)
|
||||
bool ftServer::ExtraFileRemove(std::string hash, TransferInfoFlags flags)
|
||||
{
|
||||
return mFtExtra->removeExtraFile(hash, flags);
|
||||
}
|
||||
|
||||
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags)
|
||||
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferInfoFlags flags)
|
||||
{
|
||||
return mFtExtra->hashExtraFile(localpath, period, flags);
|
||||
}
|
||||
|
@ -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, FileStorageFlags 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, TransferInfoFlags 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);
|
||||
|
@ -541,6 +541,11 @@ uint32_t ftServer::getType(void *ref, uint32_t flags)
|
|||
|
||||
|
||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
|
||||
{
|
||||
std::cerr << "(WW) ********* ftServer::SearchBoolExp:: called without peer id" << std::endl;
|
||||
return 0 ;
|
||||
}
|
||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "ftServer::SearchKeywords()";
|
||||
|
@ -553,16 +558,21 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetai
|
|||
}
|
||||
|
||||
#endif
|
||||
if(flags & DIR_FLAGS_LOCAL)
|
||||
return mFiMon->SearchKeywords(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<DirDetails> &results,uint32_t flags)
|
||||
{
|
||||
if(flags & DIR_FLAGS_LOCAL)
|
||||
return mFiMon->SearchBoolExp(exp,results,flags) ;
|
||||
std::cerr << "(WW) ********* ftServer::SearchBoolExp:: called without peer id" << std::endl;
|
||||
return 0 ;
|
||||
}
|
||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
return mFiMon->SearchBoolExp(exp,results,flags,peer_id) ;
|
||||
else
|
||||
return mFiStore->searchBoolExp(exp, results);
|
||||
}
|
||||
|
@ -731,7 +741,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);
|
||||
}
|
||||
|
|
|
@ -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<std::string>& srcIds);
|
||||
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferInfoFlags flags, const std::list<std::string>& srcIds);
|
||||
virtual bool FileCancel(const std::string& hash);
|
||||
virtual bool 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<std::string> &hashs);
|
||||
virtual bool FileUploads(std::list<std::string> &hashs);
|
||||
virtual bool FileDetails(const std::string &hash, uint32_t hintflags, FileInfo &info);
|
||||
virtual bool FileDetails(const std::string &hash, TransferInfoFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) ;
|
||||
virtual bool 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, TransferInfoFlags flags);
|
||||
virtual bool ExtraFileRemove(std::string hash, TransferInfoFlags flags);
|
||||
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferInfoFlags 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, FileStorageFlags flags);
|
||||
virtual uint32_t getType(void *ref,TransferInfoFlags flags) ;
|
||||
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags);
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags);
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id);
|
||||
|
||||
/***
|
||||
* Utility Functions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue