From e5e566051b37bd0804fc100019f757a0837bb0ca Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 19 Aug 2018 21:11:17 +0200 Subject: [PATCH] added logic to compute ban list from friend nodes and own opinions --- libretroshare/src/file_sharing/p3filelists.cc | 71 +++++++++++++++++++ libretroshare/src/file_sharing/p3filelists.h | 13 ++++ .../src/gui/FileTransfer/BannedFilesDialog.ui | 2 +- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index e6cbdb2b5..13a3dc370 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1922,6 +1922,77 @@ void p3FileDatabase::setTrustFriendNodesForBannedFiles(bool b) mTrustFriendNodesForBannedFiles = b; } +void p3FileDatabase::checkSendBannedFilesInfo() +{ + RS_STACK_MUTEX(mFLSMtx) ; + + // 1 - compare records to list of online friends, send own info of not already + + std::list online_friends ; + rsPeers->getOnlineList(online_friends); + + std::set peers ; + for(auto it(online_friends.begin());it!=online_friends.end();++it) // convert to std::set for efficient search + peers.insert(*it) ; + + for(auto it(mPeerBannedFiles.begin());it!=mPeerBannedFiles.end();) + { + if(peers.find(it->first) == peers.end()) // friend not online, remove his record + { + it = mPeerBannedFiles.erase(it) ; + continue; + } + + if(it->second.mLastSent == 0) // has ban info already been sent? If not do it. + { + locked_sendBanInfo(it->first); + it->second.mLastSent = time(NULL); + } + + peers.erase(it->first); // friend has been handled -> remove from list + ++it; + } + + // 2 - add a new record for friends not already in the record map + + for(auto it(peers.begin());it!=peers.end();++it) + { + locked_sendBanInfo(*it); + mPeerBannedFiles[*it].mLastSent = time(NULL); + } + + // 3 - update list of banned hashes if it has changed somehow + + if(mBannedFilesChanged) + { + mBannedFileList.clear(); + + // 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); + + // Add H(f) and H(H(f)) from our primary list + + for(auto it(mPrimaryBanList.begin());it!=mPrimaryBanList.end();++it) + { + mBannedFileList.insert(it->first) ; + + RsFileHash hash_of_hash ; + ftServer::encryptHash(it->first,hash_of_hash) ; + + mBannedFileList.insert(hash_of_hash) ; + } + + mBannedFilesChanged = false ; + } +} +void p3FileDatabase::locked_sendBanInfo(const RsPeerId& peer) +{ +#warning TODO: add code to send ban info to friends +} + diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 40aac7d87..243c7ee78 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -65,6 +65,13 @@ class RsFileListsSyncResponseItem ; class HashStorage ; +struct PeerBannedFilesEntry +{ + std::set mBannedHashOfHash; + uint32_t mRecordNumber ; // used for when a friend sends multiple packets in separate items. + time_t mLastSent; +}; + class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, public RsSharedFileService { public: @@ -174,6 +181,8 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub void tickRecv(); void tickSend(); + void checkSendBannedFilesInfo(); + private: p3ServiceControl *mServCtrl ; RsPeerId mOwnId ; @@ -255,7 +264,11 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub // std::map mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map + std::map mPeerBannedFiles ; // records of which files other peers ban, stored as H(H(f)) std::set mBannedFileList ; // list of banned hashes. This include original hashs and H(H(f)) when coming from friends. bool mTrustFriendNodesForBannedFiles ; + bool mBannedFilesChanged; + + void locked_sendBanInfo(const RsPeerId& pid); }; diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui index 435168023..ff7deec7f 100644 --- a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui @@ -14,7 +14,7 @@ - <html><head/><body><p>The list below contains files you have chosen to ban from your local network. You will not forward search results for these files nor forward data from these files to your friends. This list is securely shared with your friends, unless they uncheck option &quot;Trust my friends for banning unwanted content&quot;.</p></body></html> + <html><head/><body><p>The list below contains files you have chosen to ban from your local network. You will not forward search results and data from these files to your friends. This list is securely shared with your friends, unless they uncheck option &quot;Trust my friends for banning unwanted content&quot;.</p></body></html> Qt::AlignJustify|Qt::AlignVCenter