mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 00:49:41 -05:00
added load/save of banned files and handling of banned files information from friends
This commit is contained in:
parent
0b176a0fe5
commit
365464623a
@ -305,6 +305,15 @@ cleanup = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
|
||||
RsFileListsBannedHashesConfigItem *item = new RsFileListsBannedHashesConfigItem ;
|
||||
|
||||
item->primary_banned_files_list = mPrimaryBanList;
|
||||
sList.push_back(item) ;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
|
||||
|
||||
/* basic control parameters */
|
||||
@ -546,6 +555,14 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
||||
dirList.push_back(info) ;
|
||||
}
|
||||
|
||||
RsFileListsBannedHashesConfigItem *fb = dynamic_cast<RsFileListsBannedHashesConfigItem*>(*it) ;
|
||||
|
||||
if(fb)
|
||||
{
|
||||
mPrimaryBanList = fb->primary_banned_files_list ;
|
||||
mBannedFilesChanged = true;
|
||||
}
|
||||
|
||||
delete *it ;
|
||||
}
|
||||
|
||||
@ -1868,7 +1885,9 @@ bool p3FileDatabase::locked_generateAndSendSyncRequest(RemoteDirectoryStorage *r
|
||||
}
|
||||
|
||||
|
||||
// Unwanted content filtering system
|
||||
//=========================================================================================================================//
|
||||
// Unwanted content filtering system //
|
||||
//=========================================================================================================================//
|
||||
|
||||
bool p3FileDatabase::banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size)
|
||||
{
|
||||
@ -1943,13 +1962,13 @@ void p3FileDatabase::checkSendBannedFilesInfo()
|
||||
continue;
|
||||
}
|
||||
|
||||
if(it->second.mLastSent == 0) // has ban info already been sent? If not do it.
|
||||
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
|
||||
peers.erase(it->first); // friend has been handled -> remove from list
|
||||
++it;
|
||||
}
|
||||
|
||||
@ -2022,15 +2041,26 @@ void p3FileDatabase::locked_sendBanInfo(const RsPeerId& peer)
|
||||
sendItem(item);
|
||||
}
|
||||
|
||||
|
||||
void p3FileDatabase::handleBannedFilesInfo(RsFileListsBannedHashesItem *item)
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
|
||||
// 1 - localize the friend in the banned file map
|
||||
|
||||
PeerBannedFilesEntry& pbfe(mPeerBannedFiles[item->PeerId()]) ;
|
||||
|
||||
if(pbfe.mSessionId != item->session_id)
|
||||
pbfe.mBannedHashOfHash.clear();
|
||||
|
||||
pbfe.mSessionId = item->session_id ;
|
||||
|
||||
// 2 - replace/update the list, depending on the session_id
|
||||
|
||||
for(auto it(item->encrypted_hashes.begin());it!=item->encrypted_hashes.end();++it)
|
||||
pbfe.mBannedHashOfHash.insert(*it);
|
||||
|
||||
// 3 - tell the updater that the banned file list has changed
|
||||
#warning missing code here!
|
||||
|
||||
mBannedFilesChanged = true ;
|
||||
}
|
||||
|
||||
|
@ -261,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 has its place here
|
||||
// File filtering. Not explicitly related to shared files, but has its place here
|
||||
//
|
||||
|
||||
std::map<RsFileHash,BannedFileEntry> mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map<real hash, BannedFileEntry>
|
||||
|
@ -46,7 +46,16 @@ void RsFileListsBannedHashesItem::serial_process(RsGenericSerializer::SerializeJ
|
||||
RsTypeSerializer::serial_process(j,ctx,session_id ,"session_id") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,encrypted_hashes,"encrypted_hashes") ;
|
||||
}
|
||||
|
||||
void RsFileListsBannedHashesConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,primary_banned_files_list,"primary_banned_files_list") ;
|
||||
}
|
||||
template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,BannedFileEntry& entry,const std::string& /*name*/)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,entry.filename ,"entry.file_name") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx, entry.size ,"entry.size") ;
|
||||
RsTypeSerializer::serial_process<time_t> (j,ctx, entry.ban_time_stamp,"entry.ban_time_stamp") ;
|
||||
}
|
||||
RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_FILE_DATABASE)
|
||||
@ -54,9 +63,10 @@ RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: return new RsFileListsSyncRequestItem();
|
||||
case RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM: return new RsFileListsSyncResponseItem();
|
||||
case RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM: return new RsFileListsBannedHashesItem();
|
||||
case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: return new RsFileListsSyncRequestItem();
|
||||
case RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM: return new RsFileListsSyncResponseItem();
|
||||
case RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM: return new RsFileListsBannedHashesItem();
|
||||
case RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_CONFIG_ITEM: return new RsFileListsBannedHashesConfigItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
|
@ -33,11 +33,13 @@
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_CONFIG_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_CONFIG_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_CONFIG_ITEM = 0x05;
|
||||
|
||||
/*!
|
||||
* Base class for filelist sync items
|
||||
@ -114,6 +116,17 @@ public:
|
||||
std::set<RsFileHash> encrypted_hashes ;// hash of hash for each banned file.
|
||||
};
|
||||
|
||||
class RsFileListsBannedHashesConfigItem: public RsFileListsItem
|
||||
{
|
||||
public:
|
||||
RsFileListsBannedHashesConfigItem() : RsFileListsItem(RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_CONFIG_ITEM){}
|
||||
|
||||
virtual void clear() { primary_banned_files_list.clear(); }
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
std::map<RsFileHash,BannedFileEntry> primary_banned_files_list ;
|
||||
};
|
||||
|
||||
class RsFileListsSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user