Merge branch 'master' into android

This commit is contained in:
Gio 2016-11-07 14:37:23 +01:00
commit 8ab3c7de26
84 changed files with 4132 additions and 1402 deletions

File diff suppressed because it is too large Load diff

View 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() ;
}
}

View file

@ -299,8 +299,7 @@ bool InternalFileHierarchyStorage::updateSubFilesList(const DirectoryStorage::En
std::cerr << "[directory storage] removing non existing file " << f.file_name << " at index " << d.subfiles[i] << std::endl;
#endif
delete mNodes[d.subfiles[i]] ;
mNodes[d.subfiles[i]] = NULL ;
deleteNode(d.subfiles[i]) ;
d.subfiles[i] = d.subfiles[d.subfiles.size()-1] ;
d.subfiles.pop_back();
@ -374,23 +373,29 @@ bool InternalFileHierarchyStorage::updateFile(const DirectoryStorage::EntryIndex
return true;
}
void InternalFileHierarchyStorage::deleteNode(uint32_t index)
{
if(mNodes[index] != NULL)
{
delete mNodes[index] ;
mFreeNodes.push_back(index) ;
mNodes[index] = NULL ;
}
}
DirectoryStorage::EntryIndex InternalFileHierarchyStorage::allocateNewIndex()
{
int found = -1;
for(uint32_t j=0;j<mNodes.size();++j)
if(mNodes[j] == NULL)
{
found = j;
break;
}
if(found < 0)
while(!mFreeNodes.empty())
{
mNodes.push_back(NULL) ;
return mNodes.size()-1 ;
uint32_t index = mFreeNodes.front();
mFreeNodes.pop_front();
if(mNodes[index] == NULL)
return DirectoryStorage::EntryIndex(index) ;
}
else
return found ;
mNodes.push_back(NULL) ;
return mNodes.size()-1 ;
}
bool InternalFileHierarchyStorage::updateDirEntry(const DirectoryStorage::EntryIndex& indx,const std::string& dir_name,time_t most_recent_time,time_t dir_modtime,const std::vector<RsFileHash>& subdirs_hash,const std::vector<FileEntry>& subfiles_array)
@ -534,8 +539,7 @@ bool InternalFileHierarchyStorage::updateDirEntry(const DirectoryStorage::EntryI
std::cerr << "(EE) Cannot delete node of index " << it->second << " because it is not a file. Inconsistency error!" << std::endl;
continue ;
}
delete mNodes[it->second] ;
mNodes[it->second] = NULL ;
deleteNode(it->second) ;
}
// now update row and parent index for all subnodes
@ -590,12 +594,12 @@ bool InternalFileHierarchyStorage::setTS(const DirectoryStorage::EntryIndex& ind
// Do a complete recursive sweep over sub-directories and files, and update the lst modf TS. This could be also performed by a cleanup method.
time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index)
time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index,bool& unfinished_files_present)
{
DirEntry& d(*static_cast<DirEntry*>(mNodes[dir_index])) ;
time_t largest_modf_time = d.dir_modtime ;
bool unfinished_files_present = false ;
unfinished_files_present = false ;
for(uint32_t i=0;i<d.subfiles.size();++i)
{
@ -608,7 +612,12 @@ time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectorySto
}
for(uint32_t i=0;i<d.subdirs.size();++i)
largest_modf_time = std::max(largest_modf_time,recursUpdateLastModfTime(d.subdirs[i])) ;
{
bool unfinished_files_below = false ;
largest_modf_time = std::max(largest_modf_time,recursUpdateLastModfTime(d.subdirs[i],unfinished_files_below)) ;
unfinished_files_present = unfinished_files_present || unfinished_files_below ;
}
// now if some files are not hashed in this directory, reduce the recurs time by 1, so that the TS wil be updated when all hashes are ready.
@ -673,18 +682,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
@ -749,6 +749,8 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co
std::vector<uint32_t> hits(mNodes.size(),0) ; // count hits of children. Should be 1 for all in the end. Otherwise there's an error.
hits[0] = 1 ; // because 0 is never the child of anyone
mFreeNodes.clear();
for(uint32_t i=0;i<mNodes.size();++i)
if(mNodes[i] != NULL && mNodes[i]->type() == FileStorageNode::TYPE_DIR)
{
@ -796,13 +798,15 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co
}
}
}
else if(mNodes[i] == NULL)
mFreeNodes.push_back(i) ;
for(uint32_t i=0;i<hits.size();++i)
if(hits[i] == 0 && mNodes[i] != NULL)
{
error_string += " - Orphean node!" ;
delete mNodes[i] ;
mNodes[i] = NULL ;
deleteNode(i) ;
}
return error_string.empty();;
@ -896,12 +900,9 @@ bool InternalFileHierarchyStorage::recursRemoveDirectory(DirectoryStorage::Entry
recursRemoveDirectory(d.subdirs[i]);
for(uint32_t i=0;i<d.subfiles.size();++i)
{
delete mNodes[d.subfiles[i]] ;
mNodes[d.subfiles[i]] = NULL ;
}
delete mNodes[dir] ;
mNodes[dir] = NULL ;
deleteNode(d.subfiles[i]);
deleteNode(dir) ;
mDirHashes.erase(hash) ;
@ -1014,6 +1015,8 @@ bool InternalFileHierarchyStorage::load(const std::string& fname)
uint32_t buffer_size = 0 ;
uint32_t buffer_offset = 0 ;
mFreeNodes.clear();
try
{
if(!FileListIO::loadEncryptedDataFromFile(fname,buffer,buffer_size) )

View file

@ -110,7 +110,7 @@ public:
// Do a complete recursive sweep over sub-directories and files, and update the lst modf TS. This could be also performed by a cleanup method.
time_t recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index);
time_t recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index, bool &unfinished_files_present);
// hash stuff
@ -122,6 +122,7 @@ public:
bool findSubDirectory(DirectoryStorage::EntryIndex e,const std::string& s) const ; // returns true when s is the name of a sub-directory in the given entry e
uint32_t mRoot ;
std::list<uint32_t > mFreeNodes ; // keeps a list of free nodes in order to make insert effcieint
std::vector<FileStorageNode*> mNodes;// uses pointers to keep information about valid/invalid objects.
void compress() ; // use empty space in the vector, mostly due to deleted entries. This is a complicated operation, mostly due to
@ -142,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
@ -159,6 +160,10 @@ private:
DirectoryStorage::EntryIndex allocateNewIndex();
// Deletes an existing entry in mNodes, and keeps record of the indices that get freed.
void deleteNode(DirectoryStorage::EntryIndex);
// Removes the given subdirectory from the parent node and all its pendign subdirs. Files are kept, and will go during the cleaning
// phase. That allows to keep file information when moving them around.

View file

@ -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) ;
@ -422,11 +446,13 @@ void LocalDirectoryStorage::updateTimeStamps()
std::cerr << "Updating recursive TS for local shared dirs..." << std::endl;
#endif
time_t last_modf_time = mFileHierarchy->recursUpdateLastModfTime(EntryIndex(0)) ;
bool unfinished_files_below ;
time_t last_modf_time = mFileHierarchy->recursUpdateLastModfTime(EntryIndex(0),unfinished_files_below) ;
mTSChanged = false ;
#ifdef DEBUG_LOCAL_DIRECTORY_STORAGE
std::cerr << "LocalDirectoryStorage: global last modf time is " << last_modf_time << " (which is " << time(NULL) - last_modf_time << " secs ago)" << std::endl;
std::cerr << "LocalDirectoryStorage: global last modf time is " << last_modf_time << " (which is " << time(NULL) - last_modf_time << " secs ago), unfinished files below=" << unfinished_files_below << std::endl;
#else
// remove unused variable warning
// variable is only used for debugging
@ -434,7 +460,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 ****/
@ -724,7 +758,9 @@ RemoteDirectoryStorage::RemoteDirectoryStorage(const RsPeerId& pid,const std::st
{
load(fname) ;
std::cerr << "Loaded remote directory for peer " << pid << std::endl;
mLastSweepTime = time(NULL) - (RSRandom::random_u32() % DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP) ;
std::cerr << "Loaded remote directory for peer " << pid << ", inited last sweep time to " << time(NULL) - mLastSweepTime << " secs ago." << std::endl;
#ifdef DEBUG_REMOTE_DIRECTORY_STORAGE
mFileHierarchy->print();
#endif

View file

@ -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)
@ -193,8 +194,15 @@ public:
*/
void checkSave() ;
/*!
* \brief lastSweepTime
* returns the last time a sweep has been done over the directory in order to check update TS.
* \return
*/
time_t& lastSweepTime() { return mLastSweepTime ; }
private:
time_t mLastSavedTime ;
time_t mLastSweepTime ;
bool mChanged ;
std::string mFileName;
};
@ -216,6 +224,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 +283,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 +292,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 ;

View file

@ -54,10 +54,10 @@ void LocalDirectoryUpdater::setEnabled(bool b)
if(mIsEnabled == b)
return ;
if(b)
start("fs dir updater") ;
else
if(!b)
shutdown();
else if(!isRunning())
start("fs dir updater") ;
mIsEnabled = b ;
}

View file

@ -28,7 +28,8 @@
static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 600 ; // 10 minutes
static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 minutes
static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. Buy we only update for real if something has changed.
static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed.
static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec.
static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time
static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files
@ -43,3 +44,8 @@ static const uint32_t MIN_INTERVAL_BETWEEN_REMOTE_DIRECTORY_SAVE = 23 ; //
static const uint32_t MAX_DIR_SYNC_RESPONSE_DATA_SIZE = 20000 ; // Maximum RsItem data size in bytes for serialised directory transmission
static const uint32_t DEFAULT_HASH_STORAGE_DURATION_DAYS = 30 ; // remember deleted/inaccessible files for 30 days
static const uint32_t NB_FRIEND_INDEX_BITS = 10 ; // Do not change this!
static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; // Do not change this!
static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. Depends on the two values just before. Dont change!
static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min

View file

@ -46,11 +46,6 @@ static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_LOCAL_DIRS_CHANGED = 0x0002 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_DIRS_CHANGED = 0x0004 ;
static const uint32_t NB_FRIEND_INDEX_BITS = 10 ;
static const uint32_t NB_ENTRY_INDEX_BITS = 22 ;
static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer.
static const uint32_t DELAY_BEFORE_DROP_REQUEST = 55 ; // every 55 secs, for debugging. Should be evey 10 minutes or so.
p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
: mServCtrl(mpeers), mFLSMtx("p3FileLists")
{
@ -209,7 +204,7 @@ int p3FileDatabase::tick()
for(uint32_t i=0;i<mRemoteDirectories.size();++i)
if(mRemoteDirectories[i] != NULL)
{
if(online_peers.find(mRemoteDirectories[i]->peerId()) != online_peers.end())
if(online_peers.find(mRemoteDirectories[i]->peerId()) != online_peers.end() && mRemoteDirectories[i]->lastSweepTime() + DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP < now)
{
#ifdef DEBUG_FILE_HIERARCHY
P3FILELISTS_DEBUG() << "Launching recurs sweep of friend directory " << mRemoteDirectories[i]->peerId() << ". Content currently is:" << std::endl;
@ -217,6 +212,7 @@ int p3FileDatabase::tick()
#endif
locked_recursSweepRemoteDirectory(mRemoteDirectories[i],mRemoteDirectories[i]->root(),0) ;
mRemoteDirectories[i]->lastSweepTime() = now ;
}
mRemoteDirectories[i]->checkSave() ;
@ -345,7 +341,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 +396,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) ;
@ -498,7 +493,6 @@ void p3FileDatabase::cleanup()
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " removing pending request " << std::hex << it->first << std::dec << " for peer " << it->second.peer_id << ", because peer is offline or request is too old." << std::endl;
#endif
std::map<DirSyncRequestId,DirSyncRequestData>::iterator tmp(it);
++tmp;
mPendingSyncRequests.erase(it) ;
@ -543,7 +537,7 @@ uint32_t p3FileDatabase::locked_getFriendIndex(const RsPeerId& pid)
mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ;
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << *it << ", with index " << friend_index << std::endl;
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << pid << ", with index " << it->second << std::endl;
#endif
}
@ -570,7 +564,7 @@ uint32_t p3FileDatabase::locked_getFriendIndex(const RsPeerId& pid)
mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ;
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << *it << ", with index " << friend_index << std::endl;
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << pid << ", with index " << it->second << std::endl;
#endif
}
@ -644,26 +638,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 +992,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;
}
@ -1457,25 +1454,23 @@ void p3FileDatabase::locked_recursSweepRemoteDirectory(RemoteDirectoryStorage *r
p3FileDatabase::DirSyncRequestId p3FileDatabase::makeDirSyncReqId(const RsPeerId& peer_id,const RsFileHash& hash)
{
static uint64_t random_bias = RSRandom::random_u64();
uint64_t r = 0 ;
uint8_t mem[RsPeerId::SIZE_IN_BYTES + RsFileHash::SIZE_IN_BYTES];
memcpy(mem,peer_id.toByteArray(),RsPeerId::SIZE_IN_BYTES) ;
memcpy(&mem[RsPeerId::SIZE_IN_BYTES],hash.toByteArray(),RsFileHash::SIZE_IN_BYTES) ;
RsFileHash tmp = RsDirUtil::sha1sum(mem,RsPeerId::SIZE_IN_BYTES + RsFileHash::SIZE_IN_BYTES) ;
// This is kind of arbitrary. The important thing is that the same ID needs to be generated every time for a given (peer_id,entry index) pair, in a way
// that cannot be brute-forced or reverse-engineered, which explains the random bias and the usage of the hash, that is itself random.
for(uint32_t i=0;i<RsPeerId::SIZE_IN_BYTES;++i)
{
r ^= (0x011933ff92892a94 + peer_id.toByteArray()[i] * 0x1001fff92ee640f9) ;
r <<= 8 ;
r += 0xf392843890321808;
}
for(uint32_t i=0;i<RsFileHash::SIZE_IN_BYTES;++i)
{
r ^= (0x011933ff92892a94 + hash.toByteArray()[i] * 0x1001fff92ee640f9) ;
r <<= 8 ;
r += 0xf392843890321808;
}
uint64_t r = random_bias ^ *((uint64_t*)tmp.toByteArray()) ;
return r ^ random_bias;
#ifdef DEBUG_P3FILELISTS
std::cerr << "Creating ID " << std::hex << r << std::dec << " from peer id " << peer_id << " and hash " << hash << std::endl;
#endif
return r ;
}
bool p3FileDatabase::locked_generateAndSendSyncRequest(RemoteDirectoryStorage *rds,const DirectoryStorage::EntryIndex& e)
@ -1525,7 +1520,7 @@ bool p3FileDatabase::locked_generateAndSendSyncRequest(RemoteDirectoryStorage *r
data.flags = item->flags;
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " Pushing req in pending list with peer id " << data.peer_id << std::endl;
P3FILELISTS_DEBUG() << " Pushing req " << std::hex << sync_req_id << std::dec << " in pending list with peer id " << data.peer_id << std::endl;
#endif
mPendingSyncRequests[sync_req_id] = data ;

View file

@ -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) ;

View file

@ -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;

View file

@ -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

View file

@ -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
};

View file

@ -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;

View file

@ -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;
};

View file

@ -294,7 +294,7 @@ mac {
OBJECTS_DIR = temp/obj
MOC_DIR = temp/moc
#DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW
DEFINES *= MINIUPNPC_VERSION=13
#DEFINES *= MINIUPNPC_VERSION=13
CONFIG += upnp_miniupnpc
CONFIG += c++11
@ -304,7 +304,7 @@ mac {
#CONFIG += zcnatassist
# Beautiful Hack to fix 64bit file access.
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs
#GPG_ERROR_DIR = ../../../../libgpg-error-1.7
#GPGME_DIR = ../../../../gpgme-1.1.8
@ -314,6 +314,7 @@ mac {
DEPENDPATH += . $$INC_DIR
INCLUDEPATH += . $$INC_DIR
INCLUDEPATH += ../../../.
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
LIBS += /usr/local/lib/libsqlcipher.a
@ -379,6 +380,8 @@ HEADERS += ft/ftchunkmap.h \
ft/fttransfermodule.h \
ft/ftturtlefiletransferitem.h
HEADERS += crypto/chacha20.h
HEADERS += directory_updater.h \
directory_list.h \
p3filelists.h
@ -537,6 +540,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 \

View file

@ -64,6 +64,10 @@ static const int PQISTREAM_PACKET_SLICING_PROBE_DELAY = 60; // send every 6
static uint8_t PACKET_SLICING_PROBE_BYTES[8] = { 0x02, 0xaa, 0xbb, 0xcc, 0x00, 0x00, 0x00, 0x08 } ;
/* Change to true to disable packet slicing and/or packet grouping, if needed */
#define DISABLE_PACKET_SLICING false
#define DISABLE_PACKET_GROUPING false
/* This removes the print statements (which hammer pqidebug) */
/***
#define RSITEM_DEBUG 1
@ -629,7 +633,7 @@ int pqistreamer::handleoutgoing_locked()
++k ;
}
}
while(mPkt_wpending_size < (uint32_t)maxbytes && mPkt_wpending_size < PQISTREAM_OPTIMAL_PACKET_SIZE ) ;
while(mPkt_wpending_size < (uint32_t)maxbytes && mPkt_wpending_size < PQISTREAM_OPTIMAL_PACKET_SIZE && !DISABLE_PACKET_GROUPING) ;
#ifdef DEBUG_PQISTREAMER
if(k > 1)
@ -787,7 +791,7 @@ start_packet_read:
if(!memcmp(block,PACKET_SLICING_PROBE_BYTES,8))
{
mAcceptsPacketSlicing = true ;
mAcceptsPacketSlicing = !DISABLE_PACKET_SLICING;
#ifdef DEBUG_PACKET_SLICING
std::cerr << "(II) Enabling packet slicing!" << std::endl;
#endif
@ -815,7 +819,7 @@ continue_packet:
#endif
is_partial_packet = true ;
mAcceptsPacketSlicing = true ; // this is needed
mAcceptsPacketSlicing = !DISABLE_PACKET_SLICING; // this is needed
}
else
extralen = getRsItemSize(block) - blen; // old style packet type

View file

@ -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 );// can be downloaded anonymously
const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends
const FileSearchFlags RS_FILE_HINTS_SEARCHABLE ( 0x00000200 );// can be searched anonymously
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;

View file

@ -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 );

View file

@ -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 ;
}

View file

@ -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() ;

View file

@ -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;

View file

@ -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 ;
};
/***********************************************************************************/

View file

@ -30,7 +30,17 @@
#include <iostream>
#include <time.h>
#ifdef __APPLE__
int __attribute__((weak)) pthread_setname_np(const char *__buf) ;
int RS_pthread_setname_np(pthread_t /*__target_thread*/, const char *__buf) {
return pthread_setname_np(__buf);
}
#else
int __attribute__((weak)) pthread_setname_np(pthread_t __target_thread, const char *__buf) ;
int RS_pthread_setname_np(pthread_t __target_thread, const char *__buf) {
return pthread_setname_np(__target_thread, __buf);
}
#endif
#ifdef RSMUTEX_DEBUG
#include <stdio.h>
@ -147,6 +157,11 @@ void RsTickingThread::fullstop()
void RsThread::start(const std::string &threadName)
{
if(isRunning())
{
std::cerr << "(EE) RsThread \"" << threadName << "\" is already running. Will not start twice!" << std::endl;
return ;
}
pthread_t tid;
void *data = (void *)this ;
@ -167,19 +182,21 @@ void RsThread::start(const std::string &threadName)
// set name
if(pthread_setname_np)
if(!threadName.empty())
{
// thread names are restricted to 16 characters including the terminating null byte
if(threadName.length() > 15)
{
{
if(!threadName.empty())
{
// thread names are restricted to 16 characters including the terminating null byte
if(threadName.length() > 15)
{
#ifdef DEBUG_THREADS
THREAD_DEBUG << "RsThread::start called with to long name '" << name << "' truncating..." << std::endl;
THREAD_DEBUG << "RsThread::start called with to long name '" << name << "' truncating..." << std::endl;
#endif
pthread_setname_np(mTid, threadName.substr(0, 15).c_str());
} else {
pthread_setname_np(mTid, threadName.c_str());
}
}
RS_pthread_setname_np(mTid, threadName.substr(0, 15).c_str());
} else {
RS_pthread_setname_np(mTid, threadName.c_str());
}
}
}
}
else
{