diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 13a3dc370..5b3247f75 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1415,8 +1415,8 @@ void p3FileDatabase::tickRecv() { switch(item->PacketSubType()) { - case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: handleDirSyncRequest( dynamic_cast(item) ) ; - break ; + case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: handleDirSyncRequest( dynamic_cast(item) ) ; break ; + case RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM : handleBannedFilesInfo( dynamic_cast(item) ) ; break ; case RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM: { RsFileListsSyncResponseItem *sitem = dynamic_cast(item); @@ -1969,9 +1969,10 @@ void p3FileDatabase::checkSendBannedFilesInfo() // Add all H(H(f)) from friends - for(auto it(mPeerBannedFiles.begin());it!=mPeerBannedFiles.end();++it) - for(auto it2(it->second.mBannedHashOfHash.begin());it2!=it->second.mBannedHashOfHash.end();++it2) - mBannedFileList.insert(*it2); + if(mTrustFriendNodesForBannedFiles) + for(auto it(mPeerBannedFiles.begin());it!=mPeerBannedFiles.end();++it) + for(auto it2(it->second.mBannedHashOfHash.begin());it2!=it->second.mBannedHashOfHash.end();++it2) + mBannedFileList.insert(*it2); // Add H(f) and H(H(f)) from our primary list @@ -1989,10 +1990,47 @@ void p3FileDatabase::checkSendBannedFilesInfo() } } - void p3FileDatabase::locked_sendBanInfo(const RsPeerId& peer) { -#warning TODO: add code to send ban info to friends + RsFileListsBannedHashesItem *item = NULL; + uint32_t session_id = RSRandom::random_u32(); + + for(auto it(mPrimaryBanList.begin());it!=mPrimaryBanList.end();++it) + { + RsFileHash hash_of_hash ; + + ftServer::encryptHash(it->first,hash_of_hash) ; + + if(!item) + { + RsFileListsBannedHashesItem *item = new RsFileListsBannedHashesItem ; + + item->PeerId(peer); + item->session_id = session_id ; + } + + item->encrypted_hashes.insert(hash_of_hash) ; + + if(item->encrypted_hashes.size() >= 200) + { + sendItem(item); + item = NULL ; + } + } + + if(item) + sendItem(item); } +void p3FileDatabase::handleBannedFilesInfo(RsFileListsBannedHashesItem *item) +{ + RS_STACK_MUTEX(mFLSMtx) ; + + // 1 - localize the friend in the banned file map + + // 2 - replace/update the list, depending on the session_id + + // 3 - tell the updater that the banned file list has changed +#warning missing code here! +} diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 243c7ee78..336208910 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -62,13 +62,14 @@ class LocalDirectoryStorage ; class RsFileListsSyncRequestItem ; class RsFileListsSyncResponseItem ; +class RsFileListsBannedHashesItem ; class HashStorage ; struct PeerBannedFilesEntry { std::set mBannedHashOfHash; - uint32_t mRecordNumber ; // used for when a friend sends multiple packets in separate items. + uint32_t mSessionId ; // used for when a friend sends multiple packets in separate items. time_t mLastSent; }; @@ -260,7 +261,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub time_t mLastCleanupTime; time_t mLastDataRecvTS ; - // file filtering. Not explicitly related to shared files, but + // file filtering. Not explicitly related to shared files, but has its place here // std::map mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map @@ -270,5 +271,6 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub bool mBannedFilesChanged; void locked_sendBanInfo(const RsPeerId& pid); + void handleBannedFilesInfo(RsFileListsBannedHashesItem *item); }; diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index a0e1eb695..e39ffc275 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -43,6 +43,7 @@ void RsFileListsSyncResponseItem::serial_process(RsGenericSerializer::SerializeJ } void RsFileListsBannedHashesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { + RsTypeSerializer::serial_process(j,ctx,session_id ,"session_id") ; RsTypeSerializer::serial_process(j,ctx,encrypted_hashes,"encrypted_hashes") ; } diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 20ea2f649..3b9074ca7 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -110,6 +110,7 @@ public: virtual void clear() { encrypted_hashes.clear(); } virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + uint32_t session_id ; // used to allow to send in multiple parts. std::set encrypted_hashes ;// hash of hash for each banned file. };