mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-29 17:28:41 -04:00
finished implementing hash-based transactions. To be tested.
This commit is contained in:
parent
eaa8ad883a
commit
fafe684cc4
3 changed files with 110 additions and 42 deletions
|
@ -466,7 +466,7 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||
}
|
||||
|
||||
// compute list of allowed subdirs
|
||||
std::vector<EntryIndex> allowed_subdirs ;
|
||||
std::vector<RsFileHash> allowed_subdirs ;
|
||||
FileStorageFlags node_flags ;
|
||||
std::list<RsNodeGroupId> node_groups ;
|
||||
|
||||
|
@ -474,7 +474,16 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||
|
||||
for(uint32_t i=0;i<dir->subdirs.size();++i)
|
||||
if(indx != 0 || (locked_getFileSharingPermissions(dir->subdirs[i],node_flags,node_groups) && (rsPeers->computePeerPermissionFlags(client_id,node_flags,node_groups) & RS_FILE_HINTS_BROWSABLE)))
|
||||
allowed_subdirs.push_back(dir->subdirs[i]) ;
|
||||
{
|
||||
RsFileHash hash ;
|
||||
|
||||
if(!getHashFromIndex(dir->subdirs[i],hash))
|
||||
{
|
||||
std::cerr << "(EE) cannot get hash from index for subdir " << dir->subdirs[i] << " at position " << i << " in subdirs list. Weird." << std::endl;
|
||||
continue ;
|
||||
}
|
||||
allowed_subdirs.push_back(hash) ;
|
||||
}
|
||||
|
||||
unsigned char *section_data = NULL;
|
||||
uint32_t section_size = 0;
|
||||
|
@ -498,7 +507,7 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||
// serialise subdirs entry indexes
|
||||
|
||||
for(uint32_t i=0;i<allowed_subdirs.size();++i)
|
||||
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_ENTRY_INDEX ,(uint32_t)allowed_subdirs[i] )) return false ;
|
||||
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_ENTRY_INDEX ,allowed_subdirs[i] )) return false ;
|
||||
|
||||
// serialise directory subfiles, with info for each of them
|
||||
|
||||
|
@ -516,7 +525,6 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||
continue ;
|
||||
}
|
||||
|
||||
if(!FileListIO::writeField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_ENTRY_INDEX ,(uint32_t)dir->subfiles[i] )) return false ;
|
||||
if(!FileListIO::writeField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_FILE_NAME ,file->file_name )) return false ;
|
||||
if(!FileListIO::writeField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ,file->file_size )) return false ;
|
||||
if(!FileListIO::writeField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH,file->file_hash )) return false ;
|
||||
|
@ -594,14 +602,14 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
|
|||
|
||||
// serialise subdirs entry indexes
|
||||
|
||||
std::vector<EntryIndex> subdirs_array ;
|
||||
uint32_t subdir_index ;
|
||||
std::vector<RsFileHash> subdirs_hashes ;
|
||||
RsFileHash subdir_hash ;
|
||||
|
||||
for(uint32_t i=0;i<n_subdirs;++i)
|
||||
{
|
||||
if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_ENTRY_INDEX ,subdir_index)) return false ;
|
||||
if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_ENTRY_INDEX ,subdir_hash)) return false ;
|
||||
|
||||
subdirs_array.push_back(EntryIndex(subdir_index)) ;
|
||||
subdirs_hashes.push_back(subdir_hash) ;
|
||||
}
|
||||
|
||||
// deserialise directory subfiles, with info for each of them
|
||||
|
@ -622,13 +630,11 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
|
|||
|
||||
uint32_t file_section_offset = 0 ;
|
||||
|
||||
uint32_t entry_index ;
|
||||
std::string entry_name ;
|
||||
uint64_t entry_size ;
|
||||
RsFileHash entry_hash ;
|
||||
uint32_t entry_modtime ;
|
||||
|
||||
if(!FileListIO::readField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_ENTRY_INDEX ,entry_index )) return false ;
|
||||
if(!FileListIO::readField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_FILE_NAME ,entry_name )) return false ;
|
||||
if(!FileListIO::readField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ,entry_size )) return false ;
|
||||
if(!FileListIO::readField(file_section_data,file_section_size,file_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH,entry_hash )) return false ;
|
||||
|
@ -636,7 +642,6 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
|
|||
|
||||
free(file_section_data) ;
|
||||
|
||||
subfiles_array.push_back(entry_index) ;
|
||||
subfiles_name.push_back(entry_name) ;
|
||||
subfiles_size.push_back(entry_size) ;
|
||||
subfiles_hash.push_back(entry_hash) ;
|
||||
|
@ -647,20 +652,27 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
|
|||
|
||||
std::cerr << " updating dir entry..." << std::endl;
|
||||
|
||||
// first create the entries for each subdir and each subfile.
|
||||
if(!mFileHierarchy->updateDirEntry(indx,dir_name,most_recent_time,dir_modtime,subdirs_array,subfiles_array))
|
||||
// First create the entries for each subdir and each subfile, if needed.
|
||||
if(!mFileHierarchy->updateDirEntry(indx,dir_name,most_recent_time,dir_modtime,subdirs_hashes,subfiles_hash))
|
||||
{
|
||||
std::cerr << "(EE) Cannot update dir entry with index " << indx << ": entry does not exist." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// then update the subfiles
|
||||
for(uint32_t i=0;i<subfiles_array.size();++i)
|
||||
// Then update the subfiles
|
||||
for(uint32_t i=0;i<subfiles_hash.size();++i)
|
||||
{
|
||||
DirectoryStorage::EntryIndex file_index ;
|
||||
|
||||
if(!getIndexFromHash(subfiles_hash[i],file_index))
|
||||
{
|
||||
std::cerr << "(EE) Cannot optain file entry index for hash " << subfiles_hash[i] << ". This is very unexpected." << std::endl;
|
||||
continue;
|
||||
}
|
||||
std::cerr << " updating file entry " << subfiles_hash[i] << std::endl;
|
||||
|
||||
if(!mFileHierarchy->updateFile(subfiles_array[i],subfiles_hash[i],subfiles_name[i],subfiles_size[i],subfiles_modtime[i]))
|
||||
std::cerr << "(EE) Cannot update file with index " << subfiles_array[i] << ". This is very weird. Entry should have just been created and therefore should exist. Skipping." << std::endl;
|
||||
if(!mFileHierarchy->updateFile(file_index,subfiles_hash[i],subfiles_name[i],subfiles_size[i],subfiles_modtime[i]))
|
||||
std::cerr << "(EE) Cannot update file with index " << file_index <<" and hash " << subfiles_hash[i] << ". This is very weird. Entry should have just been created and therefore should exist. Skipping." << std::endl;
|
||||
}
|
||||
mChanged = true ;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue