mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #557 from mr-alice/v0.6-FTEncryption
V0.6 ft encryption
This commit is contained in:
commit
8c1a6537b4
1241
libretroshare/src/crypto/chacha20.cpp
Normal file
1241
libretroshare/src/crypto/chacha20.cpp
Normal file
File diff suppressed because it is too large
Load Diff
116
libretroshare/src/crypto/chacha20.h
Normal file
116
libretroshare/src/crypto/chacha20.h
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* RetroShare C++ File sharing default variables
|
||||
*
|
||||
* crypto/chacha20.h
|
||||
*
|
||||
* Copyright 2016 by Mr.Alice
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare.project@gmail.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace librs
|
||||
{
|
||||
namespace crypto
|
||||
{
|
||||
/*!
|
||||
* \brief chacha20_encrypt
|
||||
* Performs in place encryption/decryption of the supplied data, using chacha20, using the supplied key and nonce.
|
||||
*
|
||||
* \param key secret encryption key. *Should never* be re-used.
|
||||
* \param block_counter any integer. 0 is fine.
|
||||
* \param nonce acts as an initialzation vector. /!\ it is extremely important to make sure that this nounce *is* everytime different. Using a purely random value is fine.
|
||||
* \param data data that gets encrypted/decrypted in place
|
||||
* \param size size of the data.
|
||||
*/
|
||||
void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size) ;
|
||||
|
||||
/*!
|
||||
* \brief poly1305_tag
|
||||
* Computes an authentication tag for the supplied data, using the given secret key.
|
||||
* \param key secret key. *Should not* be used multiple times.
|
||||
* \param message message to generate a tag for
|
||||
* \param size size of the message
|
||||
* \param tag place where the tag is stored.
|
||||
*/
|
||||
|
||||
void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]);
|
||||
|
||||
/*!
|
||||
* \brief AEAD_chacha20_poly1305
|
||||
* Provides in-place authenticated encryption using the AEAD construction as described in RFC7539.
|
||||
* The data is first encrypted in place then 16-padded and concatenated to its size, than concatenated to the
|
||||
* 16-padded AAD (additional authenticated data) and its size, authenticated using poly1305.
|
||||
*
|
||||
* \param key key that is used to derive a one time secret key for poly1305 and that is also used to encrypt the data
|
||||
* \param nonce nonce. *Should be unique* in order to make the chacha20 stream cipher unique.
|
||||
* \param data data that is encrypted/decrypted in place.
|
||||
* \param size size of the data
|
||||
* \param aad additional authenticated data. Can be used to authenticate the nonce.
|
||||
* \param aad_size
|
||||
* \param tag generated poly1305 tag.
|
||||
* \param encrypt true to encrypt, false to decrypt and check the tag.
|
||||
* \return
|
||||
* always true for encryption.
|
||||
* authentication result for decryption. data is *always* xored to the cipher stream whatever the authentication result is.
|
||||
*/
|
||||
bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt_or_decrypt) ;
|
||||
|
||||
/*!
|
||||
* \brief AEAD_chacha20_sha256
|
||||
* Provides authenticated encryption using a simple construction that associates chacha20 encryption with HMAC authentication using
|
||||
* the same 32 bytes key. The authenticated tag is the 16 first bytes of the sha256 HMAC.
|
||||
*
|
||||
* \param key encryption/authentication key
|
||||
* \param nonce nonce. *Should be unique* in order to make chacha20 stream cipher unique.
|
||||
* \param data data that is encrypted/decrypted in place
|
||||
* \param data_size size of data to encrypt/authenticate
|
||||
* \param aad additional authenticated data. Can be used to authenticate the nonce.
|
||||
* \param aad_size
|
||||
* \param tag 16 bytes authentication tag result
|
||||
* \param encrypt true to encrypt, false to decrypt and check the tag.
|
||||
* \return
|
||||
* always true for encryption.
|
||||
* authentication result for decryption. data is *always* xored to the cipher stream whatever the authentication result is.
|
||||
*/
|
||||
bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt_or_decrypt) ;
|
||||
|
||||
/*!
|
||||
* \brief constant_time_memcmp
|
||||
* Provides a constant time comparison of two memory chunks. Calls CRYPTO_memcmp.
|
||||
*
|
||||
* \param m1 memory block 1
|
||||
* \param m2 memory block 2
|
||||
* \param size common size of m1 and m2
|
||||
* \return
|
||||
* false if the two chunks are different
|
||||
* true if the two chunks are identical
|
||||
*/
|
||||
bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t size) ;
|
||||
|
||||
/*!
|
||||
* \brief perform_tests
|
||||
* Tests all methods in this class, using the tests supplied in RFC7539
|
||||
* \return
|
||||
* true is all tests pass
|
||||
*/
|
||||
|
||||
bool perform_tests() ;
|
||||
}
|
||||
}
|
@ -677,18 +677,9 @@ DirectoryStorage::EntryIndex InternalFileHierarchyStorage::getSubDirIndex(Direct
|
||||
return static_cast<DirEntry*>(mNodes[parent_index])->subdirs[dir_tab_index];
|
||||
}
|
||||
|
||||
bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results)
|
||||
bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,DirectoryStorage::EntryIndex& result)
|
||||
{
|
||||
DirectoryStorage::EntryIndex indx ;
|
||||
|
||||
if(getIndexFromFileHash(hash,indx))
|
||||
{
|
||||
results.clear();
|
||||
results.push_back(indx) ;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return getIndexFromFileHash(hash,result);
|
||||
}
|
||||
|
||||
class DirectoryStorageExprFileEntry: public RsRegularExpression::ExpFileEntry
|
||||
|
@ -143,7 +143,7 @@ public:
|
||||
|
||||
// search. SearchHash is logarithmic. The other two are linear.
|
||||
|
||||
bool searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results);
|
||||
bool searchHash(const RsFileHash& hash, DirectoryStorage::EntryIndex &result);
|
||||
int searchBoolExp(RsRegularExpression::Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
||||
int searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const ; // does a logical OR between items of the list of terms
|
||||
|
||||
|
@ -168,12 +168,6 @@ bool DirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash
|
||||
return mFileHierarchy->updateHash(index,hash);
|
||||
}
|
||||
|
||||
int DirectoryStorage::searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const
|
||||
{
|
||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||
return mFileHierarchy->searchHash(hash,results);
|
||||
}
|
||||
|
||||
bool DirectoryStorage::load(const std::string& local_file_name)
|
||||
{
|
||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||
@ -295,6 +289,36 @@ bool DirectoryStorage::getIndexFromDirHash(const RsFileHash& hash,EntryIndex& in
|
||||
/* Local Directory Storage */
|
||||
/******************************************************************************************************************/
|
||||
|
||||
RsFileHash LocalDirectoryStorage::makeEncryptedHash(const RsFileHash& hash)
|
||||
{
|
||||
return RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES);
|
||||
}
|
||||
bool LocalDirectoryStorage::locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const
|
||||
{
|
||||
std::map<RsFileHash,RsFileHash>::const_iterator it = mEncryptedHashes.find(hash) ;
|
||||
|
||||
if(it == mEncryptedHashes.end())
|
||||
return false ;
|
||||
|
||||
real_hash = it->second ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
int LocalDirectoryStorage::searchHash(const RsFileHash& hash, RsFileHash& real_hash, EntryIndex& result) const
|
||||
{
|
||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||
|
||||
if(locked_findRealHash(hash,real_hash) && mFileHierarchy->searchHash(real_hash,result))
|
||||
return true ;
|
||||
|
||||
if(mFileHierarchy->searchHash(hash,result))
|
||||
{
|
||||
real_hash.clear();
|
||||
return true ;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
void LocalDirectoryStorage::setSharedDirectoryList(const std::list<SharedDirInfo>& lst)
|
||||
{
|
||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||
@ -434,7 +458,15 @@ void LocalDirectoryStorage::updateTimeStamps()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
bool LocalDirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash)
|
||||
{
|
||||
{
|
||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||
|
||||
mEncryptedHashes[makeEncryptedHash(hash)] = hash ;
|
||||
}
|
||||
return mFileHierarchy->updateHash(index,hash);
|
||||
}
|
||||
std::string LocalDirectoryStorage::locked_findRealRootFromVirtualFilename(const std::string& virtual_rootdir) const
|
||||
{
|
||||
/**** MUST ALREADY BE LOCKED ****/
|
||||
|
@ -53,7 +53,6 @@ class DirectoryStorage
|
||||
|
||||
virtual int searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const ;
|
||||
virtual int searchBoolExp(RsRegularExpression::Expression * exp, std::list<EntryIndex> &results) const ;
|
||||
virtual int searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const ;
|
||||
|
||||
// gets/sets the various time stamps:
|
||||
//
|
||||
@ -140,7 +139,9 @@ class DirectoryStorage
|
||||
// Updates relevant information for the file at the given index.
|
||||
|
||||
bool updateFile(const EntryIndex& index,const RsFileHash& hash, const std::string& fname, uint64_t size, time_t modf_time) ;
|
||||
bool updateHash(const EntryIndex& index,const RsFileHash& hash);
|
||||
|
||||
// This is derived in LocalDirectoryStorage in order to also store H(H(F))
|
||||
virtual bool updateHash(const EntryIndex& index,const RsFileHash& hash);
|
||||
|
||||
// Returns the hash of the directory at the given index and reverse. This hash is set as random the first time it is used (when updating directories). It will be
|
||||
// used by the sync system to designate the directory without referring to index (index could be used to figure out the existance of hidden directories)
|
||||
@ -216,6 +217,20 @@ public:
|
||||
void updateShareFlags(const SharedDirInfo& info) ;
|
||||
bool convertSharedFilePath(const std::string& path_with_virtual_name,std::string& fullpath) ;
|
||||
|
||||
virtual bool updateHash(const EntryIndex& index,const RsFileHash& hash);
|
||||
/*!
|
||||
* \brief searchHash
|
||||
* Looks into local database of shared files for the given hash. Also looks for files such that the hash of the hash
|
||||
* matches the given hash, and returns the real hash.
|
||||
* \param hash hash to look for
|
||||
* \param real_hash hash such that H(real_hash) = hash, or null hash if not found.
|
||||
* \param results Entry index of the file that is found
|
||||
* \return
|
||||
* true is a file is found
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual int searchHash(const RsFileHash& hash, RsFileHash &real_hash, EntryIndex &results) const ;
|
||||
|
||||
/*!
|
||||
* \brief updateTimeStamps
|
||||
* Checks recursive TS and update the if needed.
|
||||
@ -261,6 +276,8 @@ public:
|
||||
bool serialiseDirEntry(const EntryIndex& indx, RsTlvBinaryData& bindata, const RsPeerId &client_id) ;
|
||||
|
||||
private:
|
||||
static RsFileHash makeEncryptedHash(const RsFileHash& hash);
|
||||
bool locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const;
|
||||
std::string locked_getVirtualPath(EntryIndex indx) const ;
|
||||
std::string locked_getVirtualDirName(EntryIndex indx) const ;
|
||||
|
||||
@ -268,6 +285,7 @@ private:
|
||||
std::string locked_findRealRootFromVirtualFilename(const std::string& virtual_rootdir) const;
|
||||
|
||||
std::map<std::string,SharedDirInfo> mLocalDirs ; // map is better for search. it->first=it->second.filename
|
||||
std::map<RsFileHash,RsFileHash> mEncryptedHashes; // map such that hash(it->second) = it->first
|
||||
std::string mFileName;
|
||||
|
||||
bool mTSChanged ;
|
||||
|
@ -345,7 +345,7 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& 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 ;
|
||||
static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_PERMISSIONS_MASK;
|
||||
|
||||
#ifdef DEBUG_FILE_HIERARCHY
|
||||
P3FILELISTS_DEBUG() << "Load list" << std::endl;
|
||||
@ -400,7 +400,6 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
||||
info.virtualname = fi->file.name;
|
||||
info.shareflags = FileStorageFlags(fi->flags) ;
|
||||
info.shareflags &= PERMISSION_MASK ;
|
||||
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons
|
||||
|
||||
for(std::set<RsNodeGroupId>::const_iterator itt(fi->parent_groups.ids.begin());itt!=fi->parent_groups.ids.end();++itt)
|
||||
info.parent_groups.push_back(*itt) ;
|
||||
@ -644,26 +643,25 @@ void p3FileDatabase::requestDirUpdate(void *ref)
|
||||
bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result,
|
||||
FileSearchFlags flags ) const
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx);
|
||||
if (ref == NULL)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
{
|
||||
if(row != 0)
|
||||
return false ;
|
||||
|
||||
result = NULL;
|
||||
convertEntryIndexToPointer(0,0,result);
|
||||
|
||||
if (ref == NULL)
|
||||
{
|
||||
if(flags & RS_FILE_HINTS_LOCAL)
|
||||
{
|
||||
if(row != 0) return false;
|
||||
|
||||
convertEntryIndexToPointer(0,0,result);
|
||||
return true;
|
||||
}
|
||||
else if((uint32_t)row < mRemoteDirectories.size())
|
||||
{
|
||||
convertEntryIndexToPointer(mRemoteDirectories[row]->root(), row+1, result);
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
else if((uint32_t)row < mRemoteDirectories.size())
|
||||
{
|
||||
convertEntryIndexToPointer(mRemoteDirectories[row]->root(),row+1,result);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t fi;
|
||||
DirectoryStorage::EntryIndex e ;
|
||||
@ -999,16 +997,20 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F
|
||||
|
||||
if(hintflags & RS_FILE_HINTS_LOCAL)
|
||||
{
|
||||
std::list<EntryIndex> res;
|
||||
mLocalSharedDirs->searchHash(hash,res) ;
|
||||
RsFileHash real_hash ;
|
||||
EntryIndex indx;
|
||||
|
||||
if(res.empty())
|
||||
if(!mLocalSharedDirs->searchHash(hash,real_hash,indx))
|
||||
return false;
|
||||
|
||||
EntryIndex indx = *res.begin() ; // no need to report duplicates
|
||||
|
||||
mLocalSharedDirs->getFileInfo(indx,info) ;
|
||||
|
||||
if(!real_hash.isNull())
|
||||
{
|
||||
info.hash = real_hash ;
|
||||
info.transfer_info_flags |= RS_FILE_REQ_ENCRYPTED ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ ftFileControl::ftFileControl(std::string fname,
|
||||
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
||||
mSize(size), mFlags(flags), mCreateTime(0), mQueuePriority(0), mQueuePosition(0)
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId)
|
||||
@ -113,7 +113,8 @@ ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t f
|
||||
{
|
||||
_max_active_downloads = 5 ; // default queue size
|
||||
_min_prioritized_transfers = 3 ;
|
||||
/* TODO */
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE;
|
||||
/* TODO */
|
||||
cnt = 0 ;
|
||||
}
|
||||
|
||||
@ -580,7 +581,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
||||
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
|
||||
|
||||
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->monitorTunnels(_queue[pos]->mHash,mFtServer,true) ;
|
||||
mFtServer->activateTunnels(_queue[pos]->mHash,mDefaultEncryptionPolicy,_queue[pos]->mFlags,true);
|
||||
}
|
||||
|
||||
if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED && _queue[pos]->mState != ftFileControl::PAUSED)
|
||||
@ -589,8 +590,8 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
||||
_queue[pos]->mCreator->closeFile() ;
|
||||
|
||||
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringTunnels(_queue[pos]->mHash) ;
|
||||
}
|
||||
mFtServer->activateTunnels(_queue[pos]->mHash,mDefaultEncryptionPolicy,_queue[pos]->mFlags,false);
|
||||
}
|
||||
}
|
||||
|
||||
bool ftController::FlagFileComplete(const RsFileHash& hash)
|
||||
@ -833,7 +834,7 @@ bool ftController::completeFile(const RsFileHash& hash)
|
||||
mDownloads.erase(it);
|
||||
|
||||
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->stopMonitoringTunnels(hash_to_suppress) ;
|
||||
mFtServer->activateTunnels(hash_to_suppress,mDefaultEncryptionPolicy,flags,false);
|
||||
|
||||
} // UNLOCK: RS_STACK_MUTEX(ctrlMutex);
|
||||
|
||||
@ -976,6 +977,21 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
|
||||
if(alreadyHaveFile(hash, info))
|
||||
return false ;
|
||||
|
||||
// the strategy for requesting encryption is the following:
|
||||
//
|
||||
// if policy is STRICT
|
||||
// - disable clear, enforce encryption
|
||||
// else
|
||||
// - if not specified, use clear
|
||||
//
|
||||
if(mDefaultEncryptionPolicy == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)
|
||||
{
|
||||
flags |= RS_FILE_REQ_ENCRYPTED ;
|
||||
flags &= ~RS_FILE_REQ_UNENCRYPTED ;
|
||||
}
|
||||
else if(!(flags & ( RS_FILE_REQ_ENCRYPTED | RS_FILE_REQ_UNENCRYPTED )))
|
||||
flags |= RS_FILE_REQ_UNENCRYPTED ;
|
||||
|
||||
if(size == 0) // we treat this special case because
|
||||
{
|
||||
/* if no destpath - send to download directory */
|
||||
@ -1172,7 +1188,7 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
|
||||
// We check that flags are consistent.
|
||||
|
||||
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
mTurtle->monitorTunnels(hash,mFtServer,true) ;
|
||||
mFtServer->activateTunnels(hash,mDefaultEncryptionPolicy,flags,true);
|
||||
|
||||
bool assume_availability = false;
|
||||
|
||||
@ -1273,7 +1289,7 @@ bool ftController::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::Chunk
|
||||
|
||||
bool ftController::FileCancel(const RsFileHash& hash)
|
||||
{
|
||||
rsTurtle->stopMonitoringTunnels(hash) ;
|
||||
mFtServer->activateTunnels(hash,mDefaultEncryptionPolicy,TransferRequestFlags(0),false);
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::FileCancel" << std::endl;
|
||||
@ -1597,7 +1613,7 @@ bool ftController::FileDetails(const RsFileHash &hash, FileInfo &info)
|
||||
info.queue_position = it->second->mQueuePosition ;
|
||||
|
||||
if(it->second->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
|
||||
info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ; // file being downloaded anonymously are always anonymously available.
|
||||
info.storage_permission_flags |= DIR_FLAGS_ANONYMOUS_DOWNLOAD ; // file being downloaded anonymously are always anonymously available.
|
||||
|
||||
/* get list of sources from transferModule */
|
||||
std::list<RsPeerId> peerIds;
|
||||
@ -1811,6 +1827,7 @@ const std::string download_dir_ss("DOWN_DIR");
|
||||
const std::string partial_dir_ss("PART_DIR");
|
||||
const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY");
|
||||
const std::string free_space_limit_ss("FREE_SPACE_LIMIT");
|
||||
const std::string default_encryption_policy_ss("DEFAULT_ENCRYPTION_POLICY");
|
||||
|
||||
|
||||
/* p3Config Interface */
|
||||
@ -1858,6 +1875,8 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
break ;
|
||||
}
|
||||
|
||||
configMap[default_encryption_policy_ss] = (mDefaultEncryptionPolicy==RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE)?"PERMISSIVE":"STRICT" ;
|
||||
|
||||
rs_sprintf(s, "%lu", RsDiscSpace::freeSpaceLimit());
|
||||
configMap[free_space_limit_ss] = s ;
|
||||
|
||||
@ -2100,7 +2119,26 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
|
||||
setPartialsDirectory(mit->second);
|
||||
}
|
||||
|
||||
if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss)))
|
||||
if (configMap.end() != (mit = configMap.find(default_encryption_policy_ss)))
|
||||
{
|
||||
if(mit->second == "STRICT")
|
||||
{
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT ;
|
||||
std::cerr << "Note: loading default value for encryption policy: STRICT" << std::endl;
|
||||
}
|
||||
else if(mit->second == "PERMISSIVE")
|
||||
{
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ;
|
||||
std::cerr << "Note: loading default value for encryption policy: PERMISSIVE" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) encryption policy not recognized: \"" << mit->second << "\"" << std::endl;
|
||||
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ;
|
||||
}
|
||||
}
|
||||
|
||||
if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss)))
|
||||
{
|
||||
if(mit->second == "STREAMING")
|
||||
{
|
||||
@ -2133,7 +2171,18 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ftController::setFreeDiskSpaceLimit(uint32_t size_in_mb)
|
||||
void ftController::setDefaultEncryptionPolicy(uint32_t p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
mDefaultEncryptionPolicy = p ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
uint32_t ftController::defaultEncryptionPolicy()
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
return mDefaultEncryptionPolicy ;
|
||||
}
|
||||
void ftController::setFreeDiskSpaceLimit(uint32_t size_in_mb)
|
||||
{
|
||||
RsDiscSpace::setFreeSpaceLimit(size_in_mb) ;
|
||||
|
||||
|
@ -140,9 +140,11 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
|
||||
|
||||
bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s);
|
||||
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
|
||||
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
||||
void setDefaultEncryptionPolicy(uint32_t s);
|
||||
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
||||
uint32_t freeDiskSpaceLimit() const ;
|
||||
void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
uint32_t defaultEncryptionPolicy();
|
||||
|
||||
bool FileCancel(const RsFileHash& hash);
|
||||
bool FileControl(const RsFileHash& hash, uint32_t flags);
|
||||
@ -237,6 +239,7 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
|
||||
ftServer *mFtServer ;
|
||||
p3ServiceControl *mServiceCtrl;
|
||||
uint32_t mFtServiceId;
|
||||
uint32_t mDefaultEncryptionPolicy ;
|
||||
|
||||
uint32_t cnt ;
|
||||
RsMutex ctrlMutex;
|
||||
|
@ -350,9 +350,10 @@ bool ftExtraList::search(const RsFileHash &hash, FileSearchFlags /*hintflags*
|
||||
|
||||
// Now setup the file storage flags so that the client can know how to handle permissions
|
||||
//
|
||||
info.storage_permission_flags = DIR_FLAGS_BROWSABLE_OTHERS ;
|
||||
#warning make sure this is right
|
||||
info.storage_permission_flags = FileStorageFlags(0) ;//DIR_FLAGS_BROWSABLE_OTHERS ;
|
||||
|
||||
if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ;
|
||||
if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) info.storage_permission_flags |= DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -135,7 +135,8 @@ public:
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||
virtual uint32_t freeDiskSpaceLimit() const ;
|
||||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
|
||||
|
||||
virtual void setDefaultEncryptionPolicy(uint32_t policy) ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
|
||||
virtual uint32_t defaultEncryptionPolicy() ;
|
||||
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
@ -156,6 +157,7 @@ public:
|
||||
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info);
|
||||
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) ;
|
||||
virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
|
||||
virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) ;
|
||||
|
||||
|
||||
/***
|
||||
@ -200,7 +202,7 @@ public:
|
||||
virtual std::string getPartialsDirectory();
|
||||
|
||||
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs);
|
||||
virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs);
|
||||
virtual bool setSharedDirectories(const std::list<SharedDirInfo> &dirs);
|
||||
virtual bool addSharedDirectory(const SharedDirInfo& dir);
|
||||
virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist !
|
||||
virtual bool removeSharedDirectory(std::string dir);
|
||||
@ -217,6 +219,8 @@ public:
|
||||
/*************** Data Transfer Interface ***********************/
|
||||
/***************************************************************/
|
||||
public:
|
||||
virtual bool activateTunnels(const RsFileHash& hash,uint32_t default_encryption_policy,TransferRequestFlags flags,bool onoff);
|
||||
|
||||
virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
|
||||
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
|
||||
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
|
||||
@ -224,6 +228,11 @@ public:
|
||||
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) ;
|
||||
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
|
||||
|
||||
static void deriveEncryptionKey(const RsFileHash& hash, uint8_t *key);
|
||||
|
||||
bool encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item);
|
||||
bool decryptItem(RsTurtleGenericDataItem *encrypted_item, const RsFileHash& hash, RsTurtleGenericTunnelItem *&decrypted_item);
|
||||
|
||||
/*************** Internal Transfer Fns *************************/
|
||||
virtual int tick();
|
||||
|
||||
@ -237,6 +246,22 @@ protected:
|
||||
int handleIncoming() ;
|
||||
bool handleCacheData() ;
|
||||
|
||||
/*!
|
||||
* \brief sendTurtleItem
|
||||
* Sends the given item into a turtle tunnel, possibly encrypting it if the type of tunnel requires it, which is known from the hash itself.
|
||||
* \param peerId Peer id to send to (this is a virtual peer id from turtle service)
|
||||
* \param hash hash of the file. If the item needs to be encrypted
|
||||
* \param item item to send.
|
||||
* \return
|
||||
* true if everything goes right
|
||||
*/
|
||||
bool sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item);
|
||||
|
||||
// fnds out what is the real hash of encrypted hash hash
|
||||
bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash);
|
||||
bool findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash);
|
||||
bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash);
|
||||
|
||||
private:
|
||||
|
||||
/**** INTERNAL FUNCTIONS ***/
|
||||
@ -261,6 +286,9 @@ private:
|
||||
std::string mConfigPath;
|
||||
std::string mDownloadPath;
|
||||
std::string mPartialsPath;
|
||||
|
||||
std::map<RsFileHash,RsFileHash> mEncryptedHashes ; // This map is such that sha1(it->second) = it->first
|
||||
std::map<RsPeerId,RsFileHash> mEncryptedPeerIds ; // This map holds the hash to be used with each peer id
|
||||
};
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <serialiser/itempriorities.h>
|
||||
#include <ft/ftturtlefiletransferitem.h>
|
||||
|
||||
uint32_t RsTurtleFileRequestItem::serial_size()
|
||||
uint32_t RsTurtleFileRequestItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -42,7 +42,7 @@ uint32_t RsTurtleFileRequestItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileDataItem::serial_size()
|
||||
uint32_t RsTurtleFileDataItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -55,7 +55,7 @@ uint32_t RsTurtleFileDataItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileMapRequestItem::serial_size()
|
||||
uint32_t RsTurtleFileMapRequestItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -66,7 +66,7 @@ uint32_t RsTurtleFileMapRequestItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileMapItem::serial_size()
|
||||
uint32_t RsTurtleFileMapItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -80,7 +80,7 @@ uint32_t RsTurtleFileMapItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleChunkCrcItem::serial_size()
|
||||
uint32_t RsTurtleChunkCrcItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -91,7 +91,7 @@ uint32_t RsTurtleChunkCrcItem::serial_size()
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsTurtleChunkCrcRequestItem::serial_size()
|
||||
uint32_t RsTurtleChunkCrcRequestItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -101,7 +101,7 @@ uint32_t RsTurtleChunkCrcRequestItem::serial_size()
|
||||
|
||||
return s ;
|
||||
}
|
||||
bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -134,7 +134,7 @@ bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -171,7 +171,7 @@ bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
@ -206,7 +206,7 @@ bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
@ -345,7 +345,7 @@ RsTurtleChunkCrcRequestItem::RsTurtleChunkCrcRequestItem(void *data,uint32_t pkt
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
bool RsTurtleFileRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleFileRequestItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -459,7 +459,7 @@ RsTurtleFileDataItem::RsTurtleFileDataItem(void *data,uint32_t pktsize)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
@ -44,8 +44,8 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
};
|
||||
|
||||
class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem
|
||||
@ -64,8 +64,8 @@ class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
};
|
||||
|
||||
class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem
|
||||
@ -78,8 +78,8 @@ class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
};
|
||||
|
||||
class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
|
||||
@ -96,8 +96,8 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
};
|
||||
|
||||
class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
@ -113,8 +113,8 @@ class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
};
|
||||
|
||||
class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem
|
||||
@ -130,6 +130,6 @@ class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem
|
||||
Sha1CheckSum check_sum ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
};
|
||||
|
@ -381,6 +381,8 @@ HEADERS += ft/ftchunkmap.h \
|
||||
ft/fttransfermodule.h \
|
||||
ft/ftturtlefiletransferitem.h
|
||||
|
||||
HEADERS += crypto/chacha20.h
|
||||
|
||||
HEADERS += directory_updater.h \
|
||||
directory_list.h \
|
||||
p3filelists.h
|
||||
@ -539,6 +541,8 @@ SOURCES += ft/ftchunkmap.cc \
|
||||
ft/fttransfermodule.cc \
|
||||
ft/ftturtlefiletransferitem.cc
|
||||
|
||||
SOURCES += crypto/chacha20.cpp
|
||||
|
||||
SOURCES += chat/distantchat.cc \
|
||||
chat/p3chatservice.cc \
|
||||
chat/distributedchat.cc \
|
||||
|
@ -43,6 +43,9 @@ const uint32_t RS_FILE_CTRL_PAUSE = 0x00000100;
|
||||
const uint32_t RS_FILE_CTRL_START = 0x00000200;
|
||||
const uint32_t RS_FILE_CTRL_FORCE_CHECK = 0x00000400;
|
||||
|
||||
const uint32_t RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT = 0x00000001 ;
|
||||
const uint32_t RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE = 0x00000002 ;
|
||||
|
||||
const uint32_t RS_FILE_RATE_TRICKLE = 0x00000001;
|
||||
const uint32_t RS_FILE_RATE_SLOW = 0x00000002;
|
||||
const uint32_t RS_FILE_RATE_STANDARD = 0x00000003;
|
||||
@ -63,29 +66,32 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000;
|
||||
|
||||
// Flags used when requesting info about transfers, mostly to filter out the result.
|
||||
//
|
||||
const FileSearchFlags RS_FILE_HINTS_CACHE_deprecated ( 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 FileSearchFlags RS_FILE_HINTS_CACHE_deprecated ( 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 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 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_SEARCHABLE ( 0x00000200 );// browsable by friends
|
||||
const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000380 );// OR of the last tree flags. Used to filter out.
|
||||
|
||||
// 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_ENCRYPTED ( 0x00000080 ); // Asks for end-to-end encryption of file at the level of ftServer
|
||||
const TransferRequestFlags RS_FILE_REQ_UNENCRYPTED ( 0x00000100 ); // Asks for no end-to-end encryption of file at the level of ftServer
|
||||
const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files.
|
||||
const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Assume full source availability. Used for cache files.
|
||||
const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Old stuff used for cache files. Not used anymore.
|
||||
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_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_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS
|
||||
// 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 */
|
||||
@ -96,7 +102,7 @@ struct SharedDirInfo
|
||||
{
|
||||
std::string filename ;
|
||||
std::string virtualname ;
|
||||
FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ...
|
||||
FileStorageFlags shareflags ; // combnation of DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_BROWSABLE | ...
|
||||
std::list<RsNodeGroupId> parent_groups ;
|
||||
};
|
||||
|
||||
@ -141,6 +147,8 @@ class RsFiles
|
||||
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) =0;
|
||||
virtual bool FileControl(const RsFileHash& hash, uint32_t flags) = 0;
|
||||
virtual bool FileClearCompleted() = 0;
|
||||
virtual void setDefaultEncryptionPolicy(uint32_t policy)=0 ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
|
||||
virtual uint32_t defaultEncryptionPolicy()=0 ;
|
||||
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
@ -159,6 +167,7 @@ class RsFiles
|
||||
virtual void FileDownloads(std::list<RsFileHash> &hashs) = 0;
|
||||
virtual bool FileUploads(std::list<RsFileHash> &hashs) = 0;
|
||||
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) = 0;
|
||||
virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) =0;
|
||||
|
||||
/// Gives chunk details about the downloaded file with given hash.
|
||||
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) = 0 ;
|
||||
@ -209,8 +218,9 @@ class RsFiles
|
||||
virtual std::string getDownloadDirectory() = 0;
|
||||
virtual std::string getPartialsDirectory() = 0;
|
||||
|
||||
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs) = 0;
|
||||
virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0;
|
||||
virtual bool getSharedDirectories(std::list<SharedDirInfo>& dirs) = 0;
|
||||
virtual bool setSharedDirectories(const std::list<SharedDirInfo>& dirs) = 0;
|
||||
virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0;
|
||||
virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist !
|
||||
virtual bool removeSharedDirectory(std::string dir) = 0;
|
||||
|
||||
|
@ -155,12 +155,13 @@ 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_ANONYMOUS_DOWNLOAD ( 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 ( 0x0400 );
|
||||
const FileStorageFlags DIR_FLAGS_ANONYMOUS_SEARCH ( 0x0800 );
|
||||
const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_ANONYMOUS_DOWNLOAD | /*DIR_FLAGS_BROWSABLE_OTHERS
|
||||
DIR_FLAGS_NETWORK_WIDE_GROUPS*/ DIR_FLAGS_BROWSABLE | DIR_FLAGS_ANONYMOUS_SEARCH);
|
||||
|
||||
const FileStorageFlags DIR_FLAGS_LOCAL ( 0x1000 );
|
||||
const FileStorageFlags DIR_FLAGS_REMOTE ( 0x2000 );
|
||||
|
@ -1359,7 +1359,7 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
|
||||
// very simple algorithm.
|
||||
//
|
||||
|
||||
bool found = false ;
|
||||
bool found = directory_parent_groups.empty() ; // by default, empty list means browsable by everyone.
|
||||
RsPgpId pgp_id = getGPGId(peer_ssl_id) ;
|
||||
|
||||
for(std::list<RsNodeGroupId>::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it)
|
||||
@ -1378,13 +1378,15 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_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) ;
|
||||
bool network_wide = (share_flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) ;//|| ( (share_flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) && found) ;
|
||||
bool browsable = (share_flags & DIR_FLAGS_BROWSABLE) && found ;
|
||||
bool searchable = (share_flags & DIR_FLAGS_ANONYMOUS_SEARCH) ;
|
||||
|
||||
FileSearchFlags final_flags ;
|
||||
|
||||
if(network_wide) final_flags |= RS_FILE_HINTS_NETWORK_WIDE ;
|
||||
if(browsable ) final_flags |= RS_FILE_HINTS_BROWSABLE ;
|
||||
if(searchable ) final_flags |= RS_FILE_HINTS_SEARCHABLE ;
|
||||
|
||||
return final_flags ;
|
||||
}
|
||||
|
@ -1729,7 +1729,7 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
||||
std::cerr << "Performing rsFiles->search()" << std::endl ;
|
||||
#endif
|
||||
// now, search!
|
||||
rsFiles->SearchKeywords(words, initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId());
|
||||
rsFiles->SearchKeywords(words, initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId());
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << initialResults.size() << " matches found." << std::endl ;
|
||||
@ -1767,7 +1767,7 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
||||
return ;
|
||||
|
||||
// now, search!
|
||||
rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId());
|
||||
rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId());
|
||||
|
||||
result.clear() ;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
// ---------------------------------- Packet sizes -----------------------------------//
|
||||
//
|
||||
|
||||
uint32_t RsTurtleStringSearchRequestItem::serial_size()
|
||||
uint32_t RsTurtleStringSearchRequestItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -27,7 +27,7 @@ uint32_t RsTurtleStringSearchRequestItem::serial_size()
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsTurtleRegExpSearchRequestItem::serial_size()
|
||||
uint32_t RsTurtleRegExpSearchRequestItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -48,7 +48,7 @@ uint32_t RsTurtleRegExpSearchRequestItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleSearchResultItem::serial_size()
|
||||
uint32_t RsTurtleSearchResultItem::serial_size()const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -67,7 +67,7 @@ uint32_t RsTurtleSearchResultItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleOpenTunnelItem::serial_size()
|
||||
uint32_t RsTurtleOpenTunnelItem::serial_size()const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -80,7 +80,7 @@ uint32_t RsTurtleOpenTunnelItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleTunnelOkItem::serial_size()
|
||||
uint32_t RsTurtleTunnelOkItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -91,7 +91,7 @@ uint32_t RsTurtleTunnelOkItem::serial_size()
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleGenericDataItem::serial_size()
|
||||
uint32_t RsTurtleGenericDataItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
@ -159,7 +159,7 @@ RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size)
|
||||
|
||||
}
|
||||
|
||||
bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -193,7 +193,7 @@ bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -313,7 +313,7 @@ RsTurtleRegExpSearchRequestItem::RsTurtleRegExpSearchRequestItem(void *data,uint
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -398,7 +398,7 @@ RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -464,7 +464,7 @@ RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
@ -572,7 +572,7 @@ RsTurtleGenericDataItem::RsTurtleGenericDataItem(void *data,uint32_t pktsize)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize)
|
||||
bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
@ -35,8 +35,8 @@ class RsTurtleItem: public RsItem
|
||||
public:
|
||||
RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {}
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor
|
||||
virtual bool serialize(void *data,uint32_t& size) const = 0 ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor
|
||||
|
||||
virtual void clear() {}
|
||||
};
|
||||
@ -63,8 +63,8 @@ class RsTurtleSearchResultItem: public RsTurtleItem
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
};
|
||||
|
||||
class RsTurtleSearchRequestItem: public RsTurtleItem
|
||||
@ -92,8 +92,8 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
};
|
||||
|
||||
class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
|
||||
@ -109,8 +109,8 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
};
|
||||
|
||||
/***********************************************************************************/
|
||||
@ -131,8 +131,8 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
};
|
||||
|
||||
class RsTurtleTunnelOkItem: public RsTurtleItem
|
||||
@ -147,8 +147,8 @@ class RsTurtleTunnelOkItem: public RsTurtleItem
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
};
|
||||
|
||||
/***********************************************************************************/
|
||||
@ -208,8 +208,8 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
};
|
||||
|
||||
/***********************************************************************************/
|
||||
|
@ -1387,7 +1387,12 @@ QString TransfersDialog::getPeerName(const RsPeerId& id) const
|
||||
// connect mgr). In such a case their id can suitably hold for a name.
|
||||
//
|
||||
if(res == "")
|
||||
{
|
||||
if(rsFiles->isEncryptedSource(id))
|
||||
return tr("Anonymous end-to-end encrypted tunnel 0x")+QString::fromStdString(id.toStdString()).left(8) ;
|
||||
else
|
||||
return tr("Anonymous tunnel 0x")+QString::fromStdString(id.toStdString()).left(8) ;
|
||||
}
|
||||
else
|
||||
return res ;
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ void QuickStartWizard::on_pushButtonSharesAdd_clicked()
|
||||
{
|
||||
SharedDirInfo sdi ;
|
||||
sdi.filename = dir ;
|
||||
sdi.shareflags = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS ;
|
||||
sdi.shareflags = DIR_FLAGS_BROWSABLE | DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
|
||||
|
||||
rsFiles->addSharedDirectory(sdi);
|
||||
|
||||
@ -331,8 +331,8 @@ void QuickStartWizard::loadShare()
|
||||
QCheckBox *cb1 = new QCheckBox ;
|
||||
QCheckBox *cb2 = new QCheckBox ;
|
||||
|
||||
cb1->setChecked( (*it).shareflags & DIR_FLAGS_NETWORK_WIDE_OTHERS ) ;
|
||||
cb2->setChecked( (*it).shareflags & DIR_FLAGS_BROWSABLE_OTHERS ) ;
|
||||
cb1->setChecked( (*it).shareflags & DIR_FLAGS_ANONYMOUS_DOWNLOAD ) ;
|
||||
cb2->setChecked( (*it).shareflags & DIR_FLAGS_BROWSABLE ) ;
|
||||
|
||||
cb1->setToolTip(tr("If checked, the share is anonymously shared to anybody.")) ;
|
||||
cb2->setToolTip(tr("If checked, the share is browsable by your friends.")) ;
|
||||
@ -364,8 +364,8 @@ void QuickStartWizard::updateFlags(bool b)
|
||||
{
|
||||
std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ;
|
||||
FileStorageFlags current_flags(0u) ;
|
||||
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,1)))->isChecked()? DIR_FLAGS_NETWORK_WIDE_OTHERS:(FileStorageFlags)0u ;
|
||||
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,2)))->isChecked()? DIR_FLAGS_BROWSABLE_OTHERS :(FileStorageFlags)0u ;
|
||||
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,1)))->isChecked()? DIR_FLAGS_ANONYMOUS_DOWNLOAD:(FileStorageFlags)0u ;
|
||||
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,2)))->isChecked()? DIR_FLAGS_BROWSABLE :(FileStorageFlags)0u ;
|
||||
|
||||
if( ((*it).shareflags ^ current_flags).toUInt32() )
|
||||
{
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <gui/common/RsUrlHandler.h>
|
||||
#include <gui/common/FilesDefs.h>
|
||||
#include <gui/common/GroupDefs.h>
|
||||
#include <gui/gxs/GxsIdDetails.h>
|
||||
#include "RemoteDirModel.h"
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
@ -216,16 +217,21 @@ QString RetroshareDirModel::getFlagsString(FileStorageFlags flags)
|
||||
{
|
||||
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' ;
|
||||
if(flags & DIR_FLAGS_BROWSABLE) str[0] = 'B' ;
|
||||
if(flags & DIR_FLAGS_ANONYMOUS_SEARCH) str[3] = 'S' ;
|
||||
if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) str[6] = 'N' ;
|
||||
|
||||
return QString(str) ;
|
||||
}
|
||||
QString RetroshareDirModel::getGroupsString(const std::list<RsNodeGroupId>& group_ids)
|
||||
QString RetroshareDirModel::getGroupsString(FileStorageFlags flags,const std::list<RsNodeGroupId>& group_ids)
|
||||
{
|
||||
QString groups_str ;
|
||||
if(!(flags & DIR_FLAGS_BROWSABLE))
|
||||
return QString();
|
||||
|
||||
if(group_ids.empty())
|
||||
return tr("[All friend nodes]") ;
|
||||
|
||||
QString groups_str = tr("Only ");
|
||||
RsGroupInfo group_info ;
|
||||
|
||||
for(std::list<RsNodeGroupId>::const_iterator it(group_ids.begin());it!=group_ids.end();)
|
||||
@ -271,8 +277,55 @@ QString RetroshareDirModel::getAgeIndicatorString(const DirDetails &details) con
|
||||
return ret;
|
||||
}
|
||||
|
||||
const QIcon& RetroshareDirModel::getFlagsIcon(FileStorageFlags flags)
|
||||
{
|
||||
static QIcon *static_icons[8] = {NULL};
|
||||
|
||||
int n=0;
|
||||
if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) n += 1 ;
|
||||
if(flags & DIR_FLAGS_ANONYMOUS_SEARCH ) n += 2 ;
|
||||
if(flags & DIR_FLAGS_BROWSABLE ) n += 4 ;
|
||||
n-= 1;
|
||||
|
||||
if(static_icons[n] == NULL)
|
||||
{
|
||||
QList<QIcon> icons ;
|
||||
|
||||
if(flags & DIR_FLAGS_ANONYMOUS_SEARCH)
|
||||
icons.push_back(QIcon(":icons/search_red_128.png")) ;
|
||||
else
|
||||
icons.push_back(QIcon(":icons/void_128.png")) ;
|
||||
|
||||
if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD)
|
||||
icons.push_back(QIcon(":icons/anonymous_blue_128.png")) ;
|
||||
else
|
||||
icons.push_back(QIcon(":icons/void_128.png")) ;
|
||||
|
||||
if(flags & DIR_FLAGS_BROWSABLE)
|
||||
icons.push_back(QIcon(":icons/browsable_green_128.png")) ;
|
||||
else
|
||||
icons.push_back(QIcon(":icons/void_128.png")) ;
|
||||
|
||||
QPixmap pix ;
|
||||
GxsIdDetails::GenerateCombinedPixmap(pix, icons, 128);
|
||||
|
||||
static_icons[n] = new QIcon(pix);
|
||||
|
||||
std::cerr << "Generated icon for flags " << std::hex << flags << std::endl;
|
||||
}
|
||||
return *static_icons[n] ;
|
||||
}
|
||||
|
||||
QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) const
|
||||
{
|
||||
if(coln == 3)
|
||||
{
|
||||
if(details.type == DIR_TYPE_PERSON) return QVariant() ;
|
||||
|
||||
return getFlagsIcon(details.flags) ;
|
||||
}
|
||||
|
||||
|
||||
if(coln > 0)
|
||||
return QVariant() ;
|
||||
|
||||
@ -352,16 +405,9 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
||||
case 2:
|
||||
return misc::userFriendlyDuration(details.min_age);
|
||||
case 3:
|
||||
return getFlagsString(details.flags);
|
||||
// case 4:
|
||||
// {
|
||||
// QString ind("");
|
||||
// if (ageIndicator != IND_ALWAYS)
|
||||
// ind = getAgeIndicatorString(details);
|
||||
// return ind;
|
||||
// }
|
||||
return QVariant();
|
||||
case 4:
|
||||
return getGroupsString(details.parent_groups) ;
|
||||
return getGroupsString(details.flags,details.parent_groups) ;
|
||||
|
||||
default:
|
||||
return tr("FILE");
|
||||
@ -383,9 +429,9 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
||||
case 2:
|
||||
return misc::userFriendlyDuration(details.min_age);
|
||||
case 3:
|
||||
return getFlagsString(details.flags);
|
||||
return QVariant();
|
||||
case 4:
|
||||
return getGroupsString(details.parent_groups) ;
|
||||
return getGroupsString(details.flags,details.parent_groups) ;
|
||||
|
||||
default:
|
||||
return tr("DIR");
|
||||
@ -663,12 +709,12 @@ QVariant TreeStyle_RDM::headerData(int section, Qt::Orientation orientation, int
|
||||
if (RemoteMode)
|
||||
return tr("Friend");
|
||||
else
|
||||
return tr("Share Flags");
|
||||
return tr("Access");
|
||||
case 4:
|
||||
if (RemoteMode)
|
||||
return tr("What's new");
|
||||
else
|
||||
return tr("Groups");
|
||||
return tr("Visibility");
|
||||
}
|
||||
return QString("Column %1").arg(section);
|
||||
}
|
||||
|
@ -94,9 +94,10 @@ class RetroshareDirModel : public QAbstractItemModel
|
||||
void treeStyle();
|
||||
void downloadDirectory(const DirDetails & details, int prefixLen);
|
||||
static QString getFlagsString(FileStorageFlags f) ;
|
||||
static QString getGroupsString(const std::list<RsNodeGroupId> &) ;
|
||||
static QString getGroupsString(FileStorageFlags flags, const std::list<RsNodeGroupId> &) ;
|
||||
QString getAgeIndicatorString(const DirDetails &) const;
|
||||
// void getAgeIndicatorRec(const DirDetails &details, QString &ret) const;
|
||||
static const QIcon& getFlagsIcon(FileStorageFlags flags) ;
|
||||
|
||||
virtual QVariant displayRole(const DirDetails&,int) const = 0 ;
|
||||
virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const =0;
|
||||
|
@ -57,7 +57,7 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent)
|
||||
hb2->addWidget(new QLabel(tr("Share flags and groups:")+" ")) ;
|
||||
|
||||
groupflagsbox = new GroupFlagsWidget(ui.shareflags_GB) ;
|
||||
groupflagsbox->setFlags(DIR_FLAGS_NETWORK_WIDE_OTHERS) ; // default value
|
||||
groupflagsbox->setFlags(DIR_FLAGS_ANONYMOUS_DOWNLOAD) ; // default value
|
||||
|
||||
messageBox = new QTextEdit(ui.shareflags_GB) ;
|
||||
messageBox->setReadOnly(true) ;
|
||||
|
@ -34,7 +34,8 @@
|
||||
#include "ShareManager.h"
|
||||
#include "ShareDialog.h"
|
||||
#include "settings/rsharesettings.h"
|
||||
#include <gui/common/GroupFlagsWidget.h>
|
||||
#include "gui/common/GroupFlagsWidget.h"
|
||||
#include "gui/common/GroupSelectionBox.h"
|
||||
#include "gui/common/GroupDefs.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "util/QtVersion.h"
|
||||
@ -61,33 +62,83 @@ ShareManager::ShareManager()
|
||||
ui.headerFrame->setHeaderText(tr("Share Manager"));
|
||||
|
||||
isLoading = false;
|
||||
load();
|
||||
|
||||
Settings->loadWidgetInformation(this);
|
||||
|
||||
connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( showShareDialog() ) );
|
||||
connect(ui.editButton, SIGNAL(clicked( bool ) ), this , SLOT( editShareDirectory() ) );
|
||||
connect(ui.removeButton, SIGNAL(clicked( bool ) ), this , SLOT( removeShareDirectory() ) );
|
||||
connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( addShare() ) );
|
||||
connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(applyAndClose()));
|
||||
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
|
||||
|
||||
connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCostumPopupMenu(QPoint)));
|
||||
connect(ui.shareddirList, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(shareddirListCurrentCellChanged(int,int,int,int)));
|
||||
connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCustomPopupMenu(QPoint)));
|
||||
connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int)));
|
||||
connect(ui.shareddirList, SIGNAL(cellChanged(int,int)), this, SLOT(handleCellChange(int,int)));
|
||||
|
||||
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(updateGroups()));
|
||||
|
||||
ui.editButton->setEnabled(false);
|
||||
ui.removeButton->setEnabled(false);
|
||||
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload()));
|
||||
|
||||
QHeaderView* header = ui.shareddirList->horizontalHeader();
|
||||
QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch);
|
||||
|
||||
//header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::Fixed);
|
||||
//header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::Fixed);
|
||||
|
||||
header->setHighlightSections(false);
|
||||
|
||||
setAcceptDrops(true);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
void ShareManager::handleCellChange(int row,int column)
|
||||
{
|
||||
if(isLoading)
|
||||
return ;
|
||||
|
||||
if(column == COLUMN_VIRTUALNAME)
|
||||
{
|
||||
// check if the thing already exists
|
||||
|
||||
for(uint32_t i=0;i<mDirInfos.size();++i)
|
||||
if(i != (uint32_t)row && (mDirInfos[row].virtualname == std::string(ui.shareddirList->item(i,COLUMN_VIRTUALNAME)->text().toUtf8())))
|
||||
{
|
||||
ui.shareddirList->item(row,COLUMN_VIRTUALNAME)->setText(QString::fromUtf8(mDirInfos[row].virtualname.c_str())) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
mDirInfos[row].virtualname = std::string(ui.shareddirList->item(row,COLUMN_VIRTUALNAME)->text().toUtf8()) ;
|
||||
}
|
||||
}
|
||||
|
||||
void ShareManager::editShareDirectory()
|
||||
{
|
||||
QTableWidget *listWidget = ui.shareddirList;
|
||||
int row = listWidget -> currentRow();
|
||||
|
||||
doubleClickedCell(row,COLUMN_PATH) ;
|
||||
}
|
||||
|
||||
void ShareManager::doubleClickedCell(int row,int column)
|
||||
{
|
||||
if(column == COLUMN_PATH)
|
||||
{
|
||||
QString dirname = QFileDialog::getExistingDirectory(NULL,tr("Choose directory"),QString(),QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly);
|
||||
|
||||
if(!dirname.isNull())
|
||||
{
|
||||
std::string new_name( dirname.toUtf8() );
|
||||
|
||||
for(uint32_t i=0;i<mDirInfos.size();++i)
|
||||
if(mDirInfos[row].filename == new_name)
|
||||
return ;
|
||||
|
||||
mDirInfos[row].filename = new_name ;
|
||||
load();
|
||||
}
|
||||
}
|
||||
else if(column == COLUMN_GROUPS)
|
||||
{
|
||||
std::list<RsNodeGroupId> selected_groups = GroupSelectionDialog::selectGroups(mDirInfos[row].parent_groups) ;
|
||||
|
||||
mDirInfos[row].parent_groups = selected_groups ;
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
ShareManager::~ShareManager()
|
||||
@ -97,15 +148,25 @@ ShareManager::~ShareManager()
|
||||
Settings->saveWidgetInformation(this);
|
||||
}
|
||||
|
||||
void ShareManager::cancel()
|
||||
{
|
||||
close();
|
||||
}
|
||||
void ShareManager::applyAndClose()
|
||||
{
|
||||
// std::cerr << "ShareManager:::close(): updating!" << std::endl;
|
||||
// This is the only place where we change things.
|
||||
|
||||
std::list<SharedDirInfo> infos ;
|
||||
|
||||
for(uint32_t i=0;i<mDirInfos.size();++i)
|
||||
infos.push_back(mDirInfos[i]) ;
|
||||
|
||||
rsFiles->setSharedDirectories(infos) ;
|
||||
|
||||
updateFlags() ;
|
||||
close() ;
|
||||
}
|
||||
|
||||
void ShareManager::shareddirListCostumPopupMenu( QPoint /*point*/ )
|
||||
void ShareManager::shareddirListCustomPopupMenu( QPoint /*point*/ )
|
||||
{
|
||||
QMenu contextMnu( this );
|
||||
|
||||
@ -121,6 +182,19 @@ void ShareManager::shareddirListCostumPopupMenu( QPoint /*point*/ )
|
||||
contextMnu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ShareManager::reload()
|
||||
{
|
||||
std::list<SharedDirInfo> dirs ;
|
||||
rsFiles->getSharedDirectories(dirs) ;
|
||||
|
||||
mDirInfos.clear();
|
||||
|
||||
for(std::list<SharedDirInfo>::const_iterator it(dirs.begin());it!=dirs.end();++it)
|
||||
mDirInfos.push_back(*it) ;
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
/** Loads the settings for this page */
|
||||
void ShareManager::load()
|
||||
{
|
||||
@ -128,44 +202,46 @@ void ShareManager::load()
|
||||
return ;
|
||||
|
||||
isLoading = true;
|
||||
// std::cerr << "ShareManager:: In load !!!!!" << std::endl ;
|
||||
|
||||
std::list<SharedDirInfo>::const_iterator it;
|
||||
std::list<SharedDirInfo> dirs;
|
||||
rsFiles->getSharedDirectories(dirs);
|
||||
|
||||
/* get a link to the table */
|
||||
QTableWidget *listWidget = ui.shareddirList;
|
||||
|
||||
/* set new row count */
|
||||
listWidget->setRowCount(dirs.size());
|
||||
listWidget->setRowCount(mDirInfos.size());
|
||||
|
||||
int row=0 ;
|
||||
for(it = dirs.begin(); it != dirs.end(); ++it,++row)
|
||||
for(uint32_t row=0;row<mDirInfos.size();++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())));
|
||||
listWidget->setItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].filename.c_str())));
|
||||
listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].virtualname.c_str())));
|
||||
|
||||
GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,(*it).shareflags);
|
||||
GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,mDirInfos[row].shareflags);
|
||||
|
||||
listWidget->setRowHeight(row, 32 * QFontMetricsF(font()).height()/14.0);
|
||||
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
|
||||
listWidget->setRowHeight(row, 32 * QFontMetricsF(font()).height()/14.0);
|
||||
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
|
||||
|
||||
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ;
|
||||
listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ;
|
||||
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ;
|
||||
listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ;
|
||||
|
||||
//connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;
|
||||
connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;
|
||||
|
||||
listWidget->item(row,COLUMN_PATH)->setToolTip(tr("Double click to change shared directory path")) ;
|
||||
listWidget->item(row,COLUMN_GROUPS)->setToolTip(tr("Double click to select which groups of friends can see the files")) ;
|
||||
listWidget->item(row,COLUMN_VIRTUALNAME)->setToolTip(tr("Double click to change the name that friends will see")) ;
|
||||
|
||||
listWidget->item(row,COLUMN_GROUPS)->setText(getGroupString(mDirInfos[row].parent_groups));
|
||||
|
||||
QFont font = listWidget->item(row,COLUMN_GROUPS)->font();
|
||||
font.setBold(mDirInfos[row].shareflags & DIR_FLAGS_BROWSABLE) ;
|
||||
listWidget->item(row,COLUMN_GROUPS)->setTextColor( (mDirInfos[row].shareflags & DIR_FLAGS_BROWSABLE)? (Qt::black):(Qt::lightGray)) ;
|
||||
listWidget->item(row,COLUMN_GROUPS)->setFont(font);
|
||||
}
|
||||
|
||||
listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ;
|
||||
|
||||
//ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory()));
|
||||
listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ;
|
||||
|
||||
listWidget->update(); /* update display */
|
||||
update();
|
||||
|
||||
isLoading = false ;
|
||||
updateGroups();
|
||||
}
|
||||
|
||||
void ShareManager::showYourself()
|
||||
@ -173,6 +249,7 @@ void ShareManager::showYourself()
|
||||
if(_instance == NULL)
|
||||
_instance = new ShareManager() ;
|
||||
|
||||
_instance->reload() ;
|
||||
_instance->show() ;
|
||||
_instance->activateWindow();
|
||||
}
|
||||
@ -184,109 +261,39 @@ void ShareManager::showYourself()
|
||||
}
|
||||
|
||||
if (update_local) {
|
||||
_instance->load();
|
||||
_instance->reload();
|
||||
}
|
||||
}
|
||||
|
||||
void ShareManager::updateFlags()
|
||||
{
|
||||
if(isLoading)
|
||||
return ;
|
||||
|
||||
isLoading = true ; // stops GUI update. Otherwise each call to rsFiles->updateShareFlags() modifies the GUI that we count on to check
|
||||
// what has changed => fail!
|
||||
|
||||
// std::cerr << "Updating flags" << std::endl;
|
||||
|
||||
std::list<SharedDirInfo>::iterator it;
|
||||
std::list<SharedDirInfo> dirs;
|
||||
rsFiles->getSharedDirectories(dirs);
|
||||
|
||||
std::map<QString, FileStorageFlags> mapped_flags ;
|
||||
|
||||
for(int row=0;row<ui.shareddirList->rowCount();++row)
|
||||
{
|
||||
QString dirpath = ui.shareddirList->item(row,COLUMN_PATH)->text() ;
|
||||
FileStorageFlags flags = (dynamic_cast<GroupFlagsWidget*>(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ;
|
||||
|
||||
mapped_flags[dirpath] = flags ;
|
||||
|
||||
// std::cerr << "Getting new flags " << flags << " for path " << dirpath.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
for(std::list<SharedDirInfo>::iterator it(dirs.begin());it!=dirs.end();++it)
|
||||
{
|
||||
FileStorageFlags newf = mapped_flags[QString::fromUtf8((*it).filename.c_str())] ;
|
||||
|
||||
if( (*it).shareflags != newf )
|
||||
{
|
||||
(*it).shareflags = newf ;
|
||||
rsFiles->updateShareFlags(*it) ; // modifies the flags
|
||||
|
||||
// std::cerr << "Updating flags to " << newf << " for dir " << (*it).filename << std::endl ;
|
||||
}
|
||||
}
|
||||
|
||||
isLoading = false ; // re-enable GUI load
|
||||
load() ; // update the GUI.
|
||||
}
|
||||
|
||||
void ShareManager::updateGroups()
|
||||
{
|
||||
if(isLoading)
|
||||
return ;
|
||||
|
||||
// std::cerr << "Updating groups" << std::endl;
|
||||
|
||||
std::list<SharedDirInfo>::iterator it;
|
||||
std::list<SharedDirInfo> dirs;
|
||||
rsFiles->getSharedDirectories(dirs);
|
||||
|
||||
int row=0 ;
|
||||
for(it = dirs.begin(); it != dirs.end(); ++it,++row)
|
||||
for(int row=0;row<ui.shareddirList->rowCount();++row)
|
||||
{
|
||||
QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_GROUPS);
|
||||
|
||||
QString group_string;
|
||||
int n = 0;
|
||||
for (std::list<RsNodeGroupId>::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n)
|
||||
{
|
||||
if (n>0)
|
||||
group_string += ", " ;
|
||||
|
||||
RsGroupInfo groupInfo;
|
||||
rsPeers->getGroupInfo(*it2, groupInfo);
|
||||
group_string += GroupDefs::name(groupInfo);
|
||||
}
|
||||
|
||||
item->setText(group_string);
|
||||
FileStorageFlags flags = (dynamic_cast<GroupFlagsWidget*>(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ;
|
||||
mDirInfos[row].shareflags = flags ;
|
||||
}
|
||||
load() ; // update the GUI.
|
||||
}
|
||||
|
||||
void ShareManager::editShareDirectory()
|
||||
QString ShareManager::getGroupString(const std::list<RsNodeGroupId>& groups)
|
||||
{
|
||||
/* id current dir */
|
||||
int row = ui.shareddirList->currentRow();
|
||||
QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_PATH);
|
||||
if(groups.empty())
|
||||
return tr("[All friend nodes]") ;
|
||||
|
||||
if (item) {
|
||||
std::string filename = item->text().toUtf8().constData();
|
||||
int n = 0;
|
||||
QString group_string ;
|
||||
|
||||
std::list<SharedDirInfo> dirs;
|
||||
rsFiles->getSharedDirectories(dirs);
|
||||
for (std::list<RsNodeGroupId>::const_iterator it(groups.begin());it!=groups.end();++it,++n)
|
||||
{
|
||||
if (n>0)
|
||||
group_string += ", " ;
|
||||
|
||||
std::list<SharedDirInfo>::const_iterator it;
|
||||
for (it = dirs.begin(); it != dirs.end(); ++it) {
|
||||
if (it->filename == filename) {
|
||||
/* file name found, show dialog */
|
||||
ShareDialog sharedlg (it->filename, this);
|
||||
sharedlg.setWindowTitle(tr("Edit Shared Folder"));
|
||||
sharedlg.exec();
|
||||
load();
|
||||
break;
|
||||
}
|
||||
}
|
||||
RsGroupInfo groupInfo;
|
||||
rsPeers->getGroupInfo(*it, groupInfo);
|
||||
group_string += GroupDefs::name(groupInfo);
|
||||
}
|
||||
|
||||
return group_string ;
|
||||
}
|
||||
|
||||
void ShareManager::removeShareDirectory()
|
||||
@ -301,7 +308,10 @@ void ShareManager::removeShareDirectory()
|
||||
{
|
||||
if ((QMessageBox::question(this, tr("Warning!"),tr("Do you really want to stop sharing this directory ?"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes)
|
||||
{
|
||||
rsFiles->removeSharedDirectory( qdir->text().toUtf8().constData());
|
||||
for(uint32_t i=row;i+1<mDirInfos.size();++i)
|
||||
mDirInfos[i] = mDirInfos[i+1] ;
|
||||
|
||||
mDirInfos.pop_back() ;
|
||||
load();
|
||||
}
|
||||
}
|
||||
@ -315,6 +325,30 @@ void ShareManager::showEvent(QShowEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void ShareManager::addShare()
|
||||
{
|
||||
QString fname = QFileDialog::getExistingDirectory(NULL,tr("Choose a directory to share"),QString(),QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly);
|
||||
|
||||
if(fname.isNull())
|
||||
return;
|
||||
|
||||
std::string dir_name ( fname.toUtf8() );
|
||||
|
||||
// check that the directory does not already exist
|
||||
|
||||
for(uint32_t i=0;i<mDirInfos.size();++i)
|
||||
if(mDirInfos[i].filename == dir_name)
|
||||
return ;
|
||||
|
||||
mDirInfos.push_back(SharedDirInfo());
|
||||
mDirInfos.back().filename = dir_name ;
|
||||
mDirInfos.back().virtualname = std::string();
|
||||
mDirInfos.back().shareflags = DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_ANONYMOUS_SEARCH;
|
||||
mDirInfos.back().parent_groups.clear();
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
void ShareManager::showShareDialog()
|
||||
{
|
||||
ShareDialog sharedlg ("", this);
|
||||
@ -327,14 +361,6 @@ void ShareManager::shareddirListCurrentCellChanged(int currentRow, int currentCo
|
||||
Q_UNUSED(currentColumn);
|
||||
Q_UNUSED(previousRow);
|
||||
Q_UNUSED(previousColumn);
|
||||
|
||||
if (currentRow >= 0) {
|
||||
ui.editButton->setEnabled(true);
|
||||
ui.removeButton->setEnabled(true);
|
||||
} else {
|
||||
ui.editButton->setEnabled(false);
|
||||
ui.removeButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ShareManager::dragEnterEvent(QDragEnterEvent *event)
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QDialog>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include "ui_ShareManager.h"
|
||||
|
||||
class ShareManager : public QDialog
|
||||
@ -54,15 +55,20 @@ protected:
|
||||
private slots:
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void shareddirListCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
|
||||
void shareddirListCostumPopupMenu( QPoint point );
|
||||
void shareddirListCustomPopupMenu( QPoint point );
|
||||
void addShare();
|
||||
void doubleClickedCell(int,int);
|
||||
void handleCellChange(int row,int column);
|
||||
void editShareDirectory();
|
||||
|
||||
void showShareDialog();
|
||||
void editShareDirectory();
|
||||
void removeShareDirectory();
|
||||
void updateFlags();
|
||||
void updateGroups();
|
||||
void applyAndClose() ;
|
||||
void applyAndClose() ;
|
||||
void cancel() ;
|
||||
void reload() ;
|
||||
|
||||
static QString getGroupString(const std::list<RsNodeGroupId>& groups);
|
||||
private:
|
||||
static ShareManager *_instance;
|
||||
bool isLoading;
|
||||
@ -72,6 +78,8 @@ private:
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::ShareManager ui;
|
||||
|
||||
std::vector<SharedDirInfo> mDirInfos ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>741</width>
|
||||
<width>1210</width>
|
||||
<height>334</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -18,7 +18,16 @@
|
||||
<normaloff>:/images/logo/logo_16.png</normaloff>:/images/logo/logo_16.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
@ -49,7 +58,7 @@
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="1" column="0" colspan="6">
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Shared Folder Manager</string>
|
||||
@ -64,7 +73,7 @@
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
<set>QAbstractItemView::DoubleClicked</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
@ -92,17 +101,17 @@
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Directory</string>
|
||||
<string>Shared directory</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Virtual Folder</string>
|
||||
<string>Visible name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Share flags</string>
|
||||
<string>Access</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string comment="If activated, the share is anonymously accessible to anybody"/>
|
||||
@ -110,7 +119,7 @@
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Groups</string>
|
||||
<string>Visibility</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string comment="If checked, the share is browsable by your friends"/>
|
||||
@ -139,7 +148,7 @@
|
||||
<string>Add a Share Directory</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
<string>Add new</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
@ -149,35 +158,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Stop sharing selected Directory</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<item row="2" column="1">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -190,24 +171,14 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="closeButton">
|
||||
<property name="text">
|
||||
<string>Apply and close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="editButton">
|
||||
<property name="toolTip">
|
||||
<string>Edit selected Shared Directory</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="5">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="StyledLabel" name="labelInstructions">
|
||||
<property name="palette">
|
||||
<palette>
|
||||
@ -290,6 +261,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -25,8 +25,10 @@
|
||||
#include <QTreeView>
|
||||
#include <QClipboard>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QProcess>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "SharedFilesDialog.h"
|
||||
#include "settings/AddFileAssociationDialog.h"
|
||||
@ -114,6 +116,36 @@ private:
|
||||
RetroshareDirModel *m_dirModel;
|
||||
};
|
||||
|
||||
// This class allows to draw the item in the share flags column using an appropriate size
|
||||
|
||||
class ShareFlagsItemDelegate: public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
ShareFlagsItemDelegate() {}
|
||||
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
Q_ASSERT(index.isValid());
|
||||
|
||||
QStyleOptionViewItemV4 opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
// disable default icon
|
||||
opt.icon = QIcon();
|
||||
// draw default item
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
|
||||
|
||||
const QRect r = option.rect;
|
||||
|
||||
// get pixmap
|
||||
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
|
||||
QPixmap pix = icon.pixmap(r.size());
|
||||
|
||||
// draw pixmap at center of item
|
||||
const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2);
|
||||
painter->drawPixmap(r.topLeft() + p, pix);
|
||||
}
|
||||
};
|
||||
|
||||
/** Constructor */
|
||||
SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareDirModel *_flat_model,QWidget *parent)
|
||||
: RsAutoUpdatePage(1000,parent),model(NULL)
|
||||
@ -220,7 +252,9 @@ LocalSharedFilesDialog::LocalSharedFilesDialog(QWidget *parent)
|
||||
editshareAct = new QAction(QIcon(IMAGE_EDITSHARE), tr("Edit Share Permissions"), this) ;
|
||||
connect(editshareAct, SIGNAL(triggered()), this, SLOT(editSharePermissions())) ;
|
||||
|
||||
ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES)) ;
|
||||
ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES)) ;
|
||||
|
||||
ui.dirTreeView->setItemDelegateForColumn(COLUMN_FRIEND,new ShareFlagsItemDelegate()) ;
|
||||
}
|
||||
|
||||
RemoteSharedFilesDialog::RemoteSharedFilesDialog(QWidget *parent)
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>737</width>
|
||||
<width>1156</width>
|
||||
<height>402</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -86,7 +86,7 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="addShares_PB">
|
||||
<property name="text">
|
||||
<string>Add Share</string>
|
||||
<string>Configure shared directories</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
|
@ -3,31 +3,26 @@
|
||||
#include "GroupFlagsWidget.h"
|
||||
#include <retroshare/rsfiles.h>
|
||||
|
||||
#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 FLAGS_ANONYMOUS_SEARCH_ON ":icons/search_red_128.png"
|
||||
#define FLAGS_ANONYMOUS_SEARCH_OFF ":icons/blank_red_128.png"
|
||||
#define FLAGS_BROWSABLE_ON ":icons/browsable_green_128.png"
|
||||
#define FLAGS_BROWSABLE_OFF ":icons/blank_green_128.png"
|
||||
#define FLAGS_ANONYMOUS_DL_ON ":icons/anonymous_blue_128.png"
|
||||
#define FLAGS_ANONYMOUS_DL_OFF ":icons/blank_blue_128.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
|
||||
#define INDEX_ANON_SEARCH 0
|
||||
#define INDEX_ANON_DL 1
|
||||
#define INDEX_BROWSABLE 2
|
||||
|
||||
/*QString GroupFlagsWidget::_tooltips_on[4] = {
|
||||
QObject::tr("Directory is browsable for friends from groups"),
|
||||
QObject::tr("Directory is accessible by anonymous tunnels from friends from groups"),
|
||||
QObject::tr("Directory is browsable for any friend"),
|
||||
QObject::tr("Directory is accessible by anonymous tunnels from any friend")
|
||||
QObject::tr("Directory is visible to friends"),
|
||||
QObject::tr("Directory can be search anonymously"),
|
||||
QObject::tr("Directory is accessible by anonymous tunnels")
|
||||
};
|
||||
QString GroupFlagsWidget::_tooltips_off[4] = {
|
||||
QObject::tr("Directory is NOT browsable for friends from groups"),
|
||||
QObject::tr("Directory is NOT accessible by anonymous tunnels from friends from groups"),
|
||||
QObject::tr("Directory is NOT browsable for any friend"),
|
||||
QObject::tr("Directory is NOT accessible by anonymous tunnels from any friend")
|
||||
QObject::tr("Directory is not visible to friends"),
|
||||
QObject::tr("Directory cannot be searched anonymously"),
|
||||
QObject::tr("Directory is NOT accessible by anonymous tunnels")
|
||||
};
|
||||
*/
|
||||
GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags)
|
||||
@ -39,35 +34,33 @@ GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags)
|
||||
setMaximumSize(128 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0) ;
|
||||
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) ;
|
||||
_icons[2*INDEX_BROWSABLE+0] = new QIcon(FLAGS_BROWSABLE_OFF) ;
|
||||
_icons[2*INDEX_BROWSABLE+1] = new QIcon(FLAGS_BROWSABLE_ON) ;
|
||||
_icons[2*INDEX_ANON_SEARCH+0] = new QIcon(FLAGS_ANONYMOUS_SEARCH_OFF) ;
|
||||
_icons[2*INDEX_ANON_SEARCH+1] = new QIcon(FLAGS_ANONYMOUS_SEARCH_ON) ;
|
||||
_icons[2*INDEX_ANON_DL+0] = new QIcon(FLAGS_ANONYMOUS_DL_OFF) ;
|
||||
_icons[2*INDEX_ANON_DL+1] = new QIcon(FLAGS_ANONYMOUS_DL_ON) ;
|
||||
|
||||
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 ;
|
||||
_flags[INDEX_BROWSABLE ] = DIR_FLAGS_BROWSABLE ;
|
||||
_flags[INDEX_ANON_SEARCH] = DIR_FLAGS_ANONYMOUS_SEARCH ;
|
||||
_flags[INDEX_ANON_DL ] = DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
|
||||
|
||||
for(int i=0;i<4;++i)
|
||||
for(int i=0;i<3;++i)
|
||||
{
|
||||
_buttons[i] = new QPushButton(this) ;
|
||||
_buttons[i]->setCheckable(true) ;
|
||||
_buttons[i]->setChecked(flags & _flags[i]) ;
|
||||
_buttons[i]->setIconSize(QSize(32 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0));
|
||||
|
||||
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))) ;
|
||||
connect(_buttons[INDEX_ANON_DL ],SIGNAL(toggled(bool)),this,SLOT(update_DL_button(bool))) ;
|
||||
connect(_buttons[INDEX_ANON_SEARCH],SIGNAL(toggled(bool)),this,SLOT(update_SR_button(bool))) ;
|
||||
connect(_buttons[INDEX_BROWSABLE ],SIGNAL(toggled(bool)),this,SLOT(update_BR_button(bool))) ;
|
||||
|
||||
_layout->setSpacing(0);
|
||||
_layout->setContentsMargins(0, 0, 0, 0);
|
||||
@ -84,16 +77,15 @@ FileStorageFlags GroupFlagsWidget::flags() const
|
||||
{
|
||||
FileStorageFlags flags ;
|
||||
|
||||
for(int i=0;i<4;++i)
|
||||
for(int i=0;i<3;++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)
|
||||
for(int i=0;i<3;++i)
|
||||
{
|
||||
_buttons[i]->setChecked(flags & _flags[i]) ;
|
||||
update_button_state(_buttons[i]->isChecked(),i) ;
|
||||
@ -104,41 +96,28 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id)
|
||||
{
|
||||
QString tip_on, tip_off;
|
||||
switch (button_id) {
|
||||
case 0:
|
||||
tip_on = tr("Directory is browsable for friends from groups");
|
||||
tip_off = tr("Directory is NOT browsable for friends from groups");
|
||||
case INDEX_BROWSABLE:
|
||||
tip_on = tr("Directory content is visible to friend nodes (see list at right)");
|
||||
tip_off = tr("Directory content is NOT visible to friend nodes");
|
||||
break;
|
||||
case 1:
|
||||
tip_on = tr("Directory is accessible by anonymous tunnels from friends from groups");
|
||||
tip_off = tr("Directory is NOT accessible by anonymous tunnels from friends from groups");
|
||||
case INDEX_ANON_SEARCH:
|
||||
tip_on = tr("Directory can be searched anonymously");
|
||||
tip_off = tr("Directory cannot be searched anonymously");
|
||||
break;
|
||||
case 2:
|
||||
tip_on = tr("Directory is browsable for any friend");
|
||||
tip_off = tr("Directory is NOT browsable for any friend");
|
||||
break;
|
||||
case 3:
|
||||
tip_on = tr("Directory is accessible by anonymous tunnels from any friend");
|
||||
tip_off = tr("Directory is NOT accessible by anonymous tunnels from any friend");
|
||||
case INDEX_ANON_DL:
|
||||
if(_buttons[INDEX_ANON_SEARCH]->isChecked())
|
||||
tip_on = tr("Files can be accessed using anonymous tunnels");
|
||||
else
|
||||
tip_on = tr("Files can be accessed using anonymous & end-to-end encrypted tunnels");
|
||||
|
||||
tip_off = tr("Files cannot be downloaded anonymously");
|
||||
break;
|
||||
default:
|
||||
tip_on = "";
|
||||
tip_off = "";
|
||||
}
|
||||
if(b)
|
||||
{
|
||||
_buttons[button_id]->setIcon(*_icons[button_id]) ;
|
||||
_buttons[button_id]->setToolTip(tip_on) ;
|
||||
}
|
||||
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(tip_off) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
_buttons[button_id]->setIcon(*_icons[INDEX_OTHER_UNCHECKED]) ;
|
||||
_buttons[button_id]->setToolTip(tip_off) ;
|
||||
}
|
||||
_buttons[button_id]->setIcon(*_icons[2*button_id+(int)b]) ;
|
||||
_buttons[button_id]->setToolTip(b?tip_on:tip_off) ;
|
||||
}
|
||||
|
||||
QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QString>& groupNames)
|
||||
@ -155,42 +134,39 @@ QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QS
|
||||
groups_string += *it ;
|
||||
}
|
||||
|
||||
if(flags & DIR_FLAGS_BROWSABLE_OTHERS)
|
||||
res += tr("All friend nodes can browse this directory") + "\n" ;
|
||||
else if(flags & DIR_FLAGS_BROWSABLE_GROUPS)
|
||||
if(!groupNames.empty())
|
||||
res += tr("Only friend nodes in groups %1 can browse this directory").arg(groups_string) + "\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_BROWSABLE)
|
||||
{
|
||||
if(groupNames.empty())
|
||||
res += tr("All friend nodes can see this directory") + "\n" ;
|
||||
else
|
||||
res += tr("Only visible to friend nodes in groups: %1").arg(groups_string) + "\n" ;
|
||||
}
|
||||
else
|
||||
res += tr("Not visible to friend nodes") + "\n" ;
|
||||
|
||||
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS)
|
||||
res += tr("All friend nodes can relay anonymous tunnels to this directory") ;
|
||||
else if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS)
|
||||
res += tr("Only friend nodes 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.") ;
|
||||
if((flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && !(flags & DIR_FLAGS_ANONYMOUS_SEARCH))
|
||||
res += tr("Files can be downloaded (but not searched) anonymously") ;
|
||||
else if((flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && (flags & DIR_FLAGS_ANONYMOUS_SEARCH))
|
||||
res += tr("Files can be downloaded and searched anonymously") ;
|
||||
else if(!(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && (flags & DIR_FLAGS_ANONYMOUS_SEARCH))
|
||||
res += tr("Files can be searched (but not downloaded) anonymously") ;
|
||||
else
|
||||
res += tr("No one can anonymously access/search these files.") ;
|
||||
|
||||
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() ; }
|
||||
void GroupFlagsWidget::update_DL_button(bool b) { update_button_state(b,INDEX_ANON_DL ) ; updated() ; }
|
||||
void GroupFlagsWidget::update_SR_button(bool b) { update_button_state(b,INDEX_ANON_SEARCH) ; updated() ; }
|
||||
void GroupFlagsWidget::update_BR_button(bool b) { update_button_state(b,INDEX_BROWSABLE ) ; updated() ; }
|
||||
|
||||
GroupFlagsWidget::~GroupFlagsWidget()
|
||||
{
|
||||
for(int i=0;i<4;++i)
|
||||
for(int i=0;i<3;++i)
|
||||
{
|
||||
delete _buttons[i] ;
|
||||
delete _icons[i] ;
|
||||
}
|
||||
delete _icons[INDEX_GROUP_UNCHECKED] ;
|
||||
delete _icons[INDEX_OTHER_UNCHECKED] ;
|
||||
delete _icons[2*i+0] ;
|
||||
delete _icons[2*i+1] ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,9 @@ class GroupFlagsWidget: public QWidget
|
||||
void updated() ;
|
||||
|
||||
protected slots:
|
||||
void update_GN_button(bool) ;
|
||||
void update_GB_button(bool) ;
|
||||
void update_ON_button(bool) ;
|
||||
void update_OB_button(bool) ;
|
||||
void update_DL_button(bool) ;
|
||||
void update_SR_button(bool) ;
|
||||
void update_BR_button(bool) ;
|
||||
|
||||
signals:
|
||||
void flagsChanged(FileStorageFlags) const ;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <QLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include "GroupSelectionBox.h"
|
||||
#include "GroupDefs.h"
|
||||
@ -17,7 +19,6 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent)
|
||||
// Fill with available groups
|
||||
fillGroups();
|
||||
}
|
||||
|
||||
void GroupSelectionBox::fillGroups()
|
||||
{
|
||||
std::list<RsNodeGroupId> selectedIds;
|
||||
@ -78,3 +79,39 @@ void GroupSelectionBox::selectedGroupNames(QList<QString> &groupNames) const
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::list<RsNodeGroupId> GroupSelectionDialog::selectGroups(const std::list<RsNodeGroupId>& default_groups)
|
||||
{
|
||||
GroupSelectionDialog gsd(NULL) ;
|
||||
|
||||
gsd.mBox->setSelectedGroupIds(default_groups) ;
|
||||
|
||||
gsd.exec();
|
||||
|
||||
std::list<RsNodeGroupId> selected_groups ;
|
||||
gsd.mBox->selectedGroupIds(selected_groups);
|
||||
|
||||
return selected_groups ;
|
||||
}
|
||||
|
||||
GroupSelectionDialog::~GroupSelectionDialog()
|
||||
{
|
||||
delete mBox ;
|
||||
}
|
||||
GroupSelectionDialog::GroupSelectionDialog(QWidget *parent)
|
||||
{
|
||||
mBox = new GroupSelectionBox(this) ;
|
||||
|
||||
QLayout *l = new QVBoxLayout ;
|
||||
setLayout(l) ;
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
l->addWidget(mBox) ;
|
||||
l->addWidget(buttonBox) ;
|
||||
l->update() ;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <QListWidget>
|
||||
#include <QDialog>
|
||||
#include <retroshare/rsids.h>
|
||||
|
||||
class GroupSelectionBox: public QListWidget
|
||||
@ -8,6 +9,8 @@ class GroupSelectionBox: public QListWidget
|
||||
public:
|
||||
GroupSelectionBox(QWidget *parent);
|
||||
|
||||
static void selectGroups(const std::list<RsNodeGroupId>& default_groups) ;
|
||||
|
||||
void selectedGroupIds(std::list<RsNodeGroupId> &groupIds) const;
|
||||
void selectedGroupNames(QList<QString> &groupNames) const;
|
||||
|
||||
@ -16,3 +19,17 @@ public:
|
||||
private slots:
|
||||
void fillGroups();
|
||||
};
|
||||
|
||||
class GroupSelectionDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GroupSelectionDialog(QWidget *parent) ;
|
||||
virtual ~GroupSelectionDialog() ;
|
||||
|
||||
static std::list<RsNodeGroupId> selectGroups(const std::list<RsNodeGroupId>& default_groups) ;
|
||||
|
||||
private:
|
||||
GroupSelectionBox *mBox ;
|
||||
};
|
||||
|
@ -25,15 +25,16 @@
|
||||
<file>icons/settings/sound.svg</file>
|
||||
<file>icons/settings/webinterface.svg</file>
|
||||
<file>icons/add_user_256.png</file>
|
||||
<file>icons/anonymous_blue_128.png</file>
|
||||
<file>icons/anonymous_green_128.png</file>
|
||||
<file>icons/aol.png</file>
|
||||
<file>icons/avatar_128.png</file>
|
||||
<file>icons/avatar_grey_128.png</file>
|
||||
<file>icons/blank_blue_128.png</file>
|
||||
<file>icons/blank_red_128.png</file>
|
||||
<file>icons/void_128.png</file>
|
||||
<file>icons/blank_green_128.png</file>
|
||||
<file>icons/browsable_blue_128.png</file>
|
||||
<file>icons/blank_blue_128.png</file>
|
||||
<file>icons/browsable_green_128.png</file>
|
||||
<file>icons/search_red_128.png</file>
|
||||
<file>icons/anonymous_blue_128.png</file>
|
||||
<file>icons/bullet_blue_128.png</file>
|
||||
<file>icons/bullet_green_128.png</file>
|
||||
<file>icons/bullet_grey_128.png</file>
|
||||
|
BIN
retroshare-gui/src/gui/icons/blank_red_128.png
Normal file
BIN
retroshare-gui/src/gui/icons/blank_red_128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
@ -3,7 +3,7 @@
|
||||
echo '<RCC>'
|
||||
echo '\t<qresource prefix="/">'
|
||||
|
||||
for i in `ls *.png`; do
|
||||
for i in `ls *.png */*png */*svg`; do
|
||||
echo '\t\t<file>icons/'$i'</file>'
|
||||
done
|
||||
|
||||
|
BIN
retroshare-gui/src/gui/icons/search_red_128.png
Normal file
BIN
retroshare-gui/src/gui/icons/search_red_128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
BIN
retroshare-gui/src/gui/icons/void_128.png
Normal file
BIN
retroshare-gui/src/gui/icons/void_128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
@ -32,24 +32,31 @@
|
||||
TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags)
|
||||
: ConfigPage(parent, flags)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
ui._queueSize_SB->setValue(rsFiles->getQueueSize()) ;
|
||||
ui._queueSize_SB->setValue(rsFiles->getQueueSize()) ;
|
||||
|
||||
switch(rsFiles->defaultChunkStrategy())
|
||||
{
|
||||
case FileChunksInfo::CHUNK_STRATEGY_STREAMING: ui._defaultStrategy_CB->setCurrentIndex(0) ; break ;
|
||||
case FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE: ui._defaultStrategy_CB->setCurrentIndex(1) ; break ;
|
||||
case FileChunksInfo::CHUNK_STRATEGY_RANDOM: ui._defaultStrategy_CB->setCurrentIndex(2) ; break ;
|
||||
}
|
||||
switch(rsFiles->defaultChunkStrategy())
|
||||
{
|
||||
case FileChunksInfo::CHUNK_STRATEGY_STREAMING: ui._defaultStrategy_CB->setCurrentIndex(0) ; break ;
|
||||
case FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE: ui._defaultStrategy_CB->setCurrentIndex(1) ; break ;
|
||||
case FileChunksInfo::CHUNK_STRATEGY_RANDOM: ui._defaultStrategy_CB->setCurrentIndex(2) ; break ;
|
||||
}
|
||||
|
||||
ui._diskSpaceLimit_SB->setValue(rsFiles->freeDiskSpaceLimit()) ;
|
||||
switch(rsFiles->defaultEncryptionPolicy())
|
||||
{
|
||||
case RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE: ui._e2e_encryption_CB->setCurrentIndex(0) ; break ;
|
||||
case RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT : ui._e2e_encryption_CB->setCurrentIndex(1) ; break ;
|
||||
}
|
||||
|
||||
QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
|
||||
QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(int))) ;
|
||||
QObject::connect(ui._diskSpaceLimit_SB,SIGNAL(valueChanged(int)),this,SLOT(updateDiskSizeLimit(int))) ;
|
||||
QObject::connect(ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) );
|
||||
ui._diskSpaceLimit_SB->setValue(rsFiles->freeDiskSpaceLimit()) ;
|
||||
|
||||
QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
|
||||
QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(int))) ;
|
||||
QObject::connect(ui._e2e_encryption_CB,SIGNAL(activated(int)),this,SLOT(updateEncryptionPolicy(int))) ;
|
||||
QObject::connect(ui._diskSpaceLimit_SB,SIGNAL(valueChanged(int)),this,SLOT(updateDiskSizeLimit(int))) ;
|
||||
QObject::connect(ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) );
|
||||
|
||||
ui._max_tr_up_per_sec_SB->setValue(rsTurtle->getMaxTRForwardRate()) ;
|
||||
}
|
||||
@ -57,6 +64,19 @@ void TransferPage::updateMaxTRUpRate(int b)
|
||||
{
|
||||
rsTurtle->setMaxTRForwardRate(b) ;
|
||||
}
|
||||
|
||||
void TransferPage::updateEncryptionPolicy(int b)
|
||||
{
|
||||
switch(b)
|
||||
{
|
||||
case 1: rsFiles->setDefaultEncryptionPolicy(RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT) ;
|
||||
break ;
|
||||
default:
|
||||
case 0: rsFiles->setDefaultEncryptionPolicy(RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE) ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
void TransferPage::updateDefaultStrategy(int i)
|
||||
{
|
||||
switch(i)
|
||||
|
@ -49,6 +49,7 @@ class TransferPage: public ConfigPage
|
||||
void updateDefaultStrategy(int) ;
|
||||
void updateDiskSizeLimit(int) ;
|
||||
void updateMaxTRUpRate(int);
|
||||
void updateEncryptionPolicy(int);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>700</width>
|
||||
<height>356</height>
|
||||
<width>741</width>
|
||||
<height>372</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@ -49,6 +49,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>End-to-end encryption:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@ -135,6 +142,23 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="_e2e_encryption_CB">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Anonymous tunnels can be end-o-end encrypted. In order to maintain backward compatibility, this can be made optional (choosing &quot;Accepted&quot;), but in the end, all Retroshare nodes will be switched to &quot;Enforced&quot;, meaning that all anonymous transfers will be end-to-end encrypted.</p></body></html></string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Accepted</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Enforced</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
12
tests/unittests/libretroshare/crypto/chacha20_test.cc
Normal file
12
tests/unittests/libretroshare/crypto/chacha20_test.cc
Normal file
@ -0,0 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// from libretroshare
|
||||
|
||||
#include "crypto/chacha20.h"
|
||||
|
||||
TEST(libretroshare_crypto, ChaCha20)
|
||||
{
|
||||
std::cerr << "Testing Chacha20" << std::endl;
|
||||
|
||||
EXPECT_TRUE(librs::crypto::perform_tests()) ;
|
||||
}
|
@ -272,6 +272,10 @@ INCLUDEPATH += ../librssimulator/
|
||||
|
||||
SOURCES += unittests.cc \
|
||||
|
||||
################################## Crypto ##################################
|
||||
|
||||
SOURCES += libretroshare/crypto/chacha20_test.cc
|
||||
|
||||
################################ Serialiser ################################
|
||||
HEADERS += libretroshare/serialiser/support.h \
|
||||
libretroshare/serialiser/rstlvutil.h \
|
||||
|
Loading…
Reference in New Issue
Block a user