mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -05:00
fixed a few bugs in hash-based syncing
This commit is contained in:
parent
384d001f3b
commit
88f85383df
@ -55,6 +55,16 @@ bool InternalFileHierarchyStorage::getIndexFromDirHash(const RsFileHash& hash,Di
|
|||||||
index = it->second;
|
index = it->second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool InternalFileHierarchyStorage::getIndexFromFileHash(const RsFileHash& hash,DirectoryStorage::EntryIndex& index) const
|
||||||
|
{
|
||||||
|
std::map<RsFileHash,DirectoryStorage::EntryIndex>::const_iterator it = mFileHashes.find(hash) ;
|
||||||
|
|
||||||
|
if(it == mFileHashes.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
index = it->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int InternalFileHierarchyStorage::parentRow(DirectoryStorage::EntryIndex e)
|
int InternalFileHierarchyStorage::parentRow(DirectoryStorage::EntryIndex e)
|
||||||
{
|
{
|
||||||
@ -344,6 +354,7 @@ bool InternalFileHierarchyStorage::updateDirEntry(const DirectoryStorage::EntryI
|
|||||||
d.subdirs.push_back(dir_index) ;
|
d.subdirs.push_back(dir_index) ;
|
||||||
|
|
||||||
((DirEntry*&)node)->dir_parent_path = d.dir_parent_path + "/" + dir_name ;
|
((DirEntry*&)node)->dir_parent_path = d.dir_parent_path + "/" + dir_name ;
|
||||||
|
((DirEntry*&)node)->dir_hash = subdirs_hash[i];
|
||||||
node->row = i ;
|
node->row = i ;
|
||||||
node->parent_index = indx ;
|
node->parent_index = indx ;
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,7 @@ public:
|
|||||||
|
|
||||||
bool getDirHashFromIndex(const DirectoryStorage::EntryIndex& index,RsFileHash& hash) const ;
|
bool getDirHashFromIndex(const DirectoryStorage::EntryIndex& index,RsFileHash& hash) const ;
|
||||||
bool getIndexFromDirHash(const RsFileHash& hash,DirectoryStorage::EntryIndex& index) const ;
|
bool getIndexFromDirHash(const RsFileHash& hash,DirectoryStorage::EntryIndex& index) const ;
|
||||||
|
bool getIndexFromFileHash(const RsFileHash& hash,DirectoryStorage::EntryIndex& index) const ;
|
||||||
|
|
||||||
// file/dir access and modification
|
// file/dir access and modification
|
||||||
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
|
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
|
||||||
|
@ -510,14 +510,6 @@ std::string LocalDirectoryStorage::locked_getVirtualPath(EntryIndex indx) const
|
|||||||
}
|
}
|
||||||
return it->second.virtualname + "/" + res;
|
return it->second.virtualname + "/" + res;
|
||||||
}
|
}
|
||||||
RsFileHash LocalDirectoryStorage::locked_getDirHashFromIndex(EntryIndex indx) const
|
|
||||||
{
|
|
||||||
// hash the full virtual path
|
|
||||||
|
|
||||||
std::string virtual_path = locked_getVirtualPath(indx) ;
|
|
||||||
|
|
||||||
return RsDirUtil::sha1sum((unsigned char*)virtual_path.c_str(),virtual_path.length()) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinaryData& bindata,const RsPeerId& client_id)
|
bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinaryData& bindata,const RsPeerId& client_id)
|
||||||
{
|
{
|
||||||
@ -541,7 +533,12 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||||||
for(uint32_t i=0;i<dir->subdirs.size();++i)
|
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)))
|
if(indx != 0 || (locked_getFileSharingPermissions(dir->subdirs[i],node_flags,node_groups) && (rsPeers->computePeerPermissionFlags(client_id,node_flags,node_groups) & RS_FILE_HINTS_BROWSABLE)))
|
||||||
{
|
{
|
||||||
RsFileHash hash = locked_getDirHashFromIndex(dir->subdirs[i]) ;
|
RsFileHash hash ;
|
||||||
|
if(!mFileHierarchy->getDirHashFromIndex(dir->subdirs[i],hash))
|
||||||
|
{
|
||||||
|
std::cerr << "(EE) Cannot get hash from subdir index " << dir->subdirs[i] << ". Weird bug." << std::endl ;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
allowed_subdirs.push_back(hash) ;
|
allowed_subdirs.push_back(hash) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,9 +722,9 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
|
|||||||
{
|
{
|
||||||
DirectoryStorage::EntryIndex file_index ;
|
DirectoryStorage::EntryIndex file_index ;
|
||||||
|
|
||||||
if(!getIndexFromDirHash(subfiles_hash[i],file_index))
|
if(!mFileHierarchy->getIndexFromFileHash(subfiles_hash[i],file_index))
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) Cannot optain file entry index for hash " << subfiles_hash[i] << ". This is very unexpected." << std::endl;
|
std::cerr << "(EE) Cannot obtain file entry index for hash " << subfiles_hash[i] << ". This is very unexpected." << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::cerr << " updating file entry " << subfiles_hash[i] << std::endl;
|
std::cerr << " updating file entry " << subfiles_hash[i] << std::endl;
|
||||||
|
@ -205,7 +205,6 @@ public:
|
|||||||
bool serialiseDirEntry(const EntryIndex& indx, RsTlvBinaryData& bindata, const RsPeerId &client_id) ;
|
bool serialiseDirEntry(const EntryIndex& indx, RsTlvBinaryData& bindata, const RsPeerId &client_id) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RsFileHash locked_getDirHashFromIndex(EntryIndex indx) const ;
|
|
||||||
std::string locked_getVirtualPath(EntryIndex indx) const ;
|
std::string locked_getVirtualPath(EntryIndex indx) const ;
|
||||||
std::string locked_getVirtualDirName(EntryIndex indx) const ;
|
std::string locked_getVirtualDirName(EntryIndex indx) const ;
|
||||||
|
|
||||||
|
@ -1003,7 +1003,7 @@ void p3FileDatabase::handleDirSyncResponse(RsFileListsSyncResponseItem *item)
|
|||||||
std::cerr << std::endl << " (EE) cannot find index from hash " << item->entry_hash << ". Dropping the response." << std::endl;
|
std::cerr << std::endl << " (EE) cannot find index from hash " << item->entry_hash << ". Dropping the response." << std::endl;
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
std::cerr << " entry index is " << entry_index ;
|
std::cerr << " entry index is " << entry_index << " " ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item->flags & RsFileListsItem::FLAGS_ENTRY_WAS_REMOVED)
|
if(item->flags & RsFileListsItem::FLAGS_ENTRY_WAS_REMOVED)
|
||||||
@ -1029,9 +1029,9 @@ void p3FileDatabase::handleDirSyncResponse(RsFileListsSyncResponseItem *item)
|
|||||||
std::cerr << "(EE) Cannot deserialise dir entry. ERROR. "<< std::endl;
|
std::cerr << "(EE) Cannot deserialise dir entry. ERROR. "<< std::endl;
|
||||||
|
|
||||||
std::cerr << " new content after update: " << std::endl;
|
std::cerr << " new content after update: " << std::endl;
|
||||||
#ifdef DEBUG_FILE_HIERARCHY
|
//#ifdef DEBUG_FILE_HIERARCHY
|
||||||
mRemoteDirectories[fi]->print();
|
mRemoteDirectories[fi]->print();
|
||||||
#endif
|
//#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1097,7 +1097,7 @@ void p3FileDatabase::locked_recursSweepRemoteDirectory(RemoteDirectoryStorage *r
|
|||||||
|
|
||||||
// Dont recurs into sub-directories, since we dont know yet were to go.
|
// Dont recurs into sub-directories, since we dont know yet were to go.
|
||||||
|
|
||||||
return ;
|
//return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(DirectoryStorage::DirIterator it(rds,e);it;++it)
|
for(DirectoryStorage::DirIterator it(rds,e);it;++it)
|
||||||
@ -1113,8 +1113,15 @@ p3FileDatabase::DirSyncRequestId p3FileDatabase::makeDirSyncReqId(const RsPeerId
|
|||||||
// that cannot be brute-forced or reverse-engineered, which explains the random bias.
|
// that cannot be brute-forced or reverse-engineered, which explains the random bias.
|
||||||
|
|
||||||
for(uint32_t i=0;i<RsPeerId::SIZE_IN_BYTES;++i)
|
for(uint32_t i=0;i<RsPeerId::SIZE_IN_BYTES;++i)
|
||||||
r += (0x3ff92892a94 * peer_id.toByteArray()[i] + r) ^ 0x39e83784378aafe3;
|
{
|
||||||
|
r ^= (0x011933ff92892a94 * e + peer_id.toByteArray()[i] * 0x1001fff92ee640f9) ;
|
||||||
|
r <<= 8 ;
|
||||||
|
r ^= 0xf392843890321808;
|
||||||
|
|
||||||
|
std::cerr << std::hex << "r=" << r << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "making request ID: peer_id=" << peer_id << ", e=" << e << ", random_bias=" << std::hex<< random_bias << " returning " << (r^random_bias) << std::dec << std::endl;
|
||||||
return r ^ random_bias;
|
return r ^ random_bias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user