mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added logic to compute ban list from friend nodes and own opinions
This commit is contained in:
parent
af7556610a
commit
e5e566051b
@ -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<RsPeerId> online_friends ;
|
||||
rsPeers->getOnlineList(online_friends);
|
||||
|
||||
std::set<RsPeerId> 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
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,6 +65,13 @@ class RsFileListsSyncResponseItem ;
|
||||
|
||||
class HashStorage ;
|
||||
|
||||
struct PeerBannedFilesEntry
|
||||
{
|
||||
std::set<RsFileHash> 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<RsFileHash,BannedFileEntry> mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map<real hash, BannedFileEntry>
|
||||
std::map<RsPeerId,PeerBannedFilesEntry> mPeerBannedFiles ; // records of which files other peers ban, stored as H(H(f))
|
||||
std::set<RsFileHash> 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);
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><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></string>
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
|
||||
|
Loading…
Reference in New Issue
Block a user