mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-26 09:41:29 -05:00
basic infrastructure for banning unwanted file content
This commit is contained in:
parent
7bdc61e3e3
commit
50e03a539c
@ -1855,6 +1855,47 @@ bool p3FileDatabase::locked_generateAndSendSyncRequest(RemoteDirectoryStorage *r
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Unwanted content filtering system
|
||||||
|
|
||||||
|
bool p3FileDatabase::banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mFLSMtx) ;
|
||||||
|
BannedFileEntry& entry(mPrimaryBanList[real_file_hash]) ; // primary list (user controlled) of files banned from FT search and forwarding. map<real hash, BannedFileEntry>
|
||||||
|
|
||||||
|
entry.filename = filename ;
|
||||||
|
entry.size = file_size ;
|
||||||
|
entry.ban_time_stamp = time(NULL);
|
||||||
|
|
||||||
|
RsFileHash hash_of_hash ;
|
||||||
|
ftServer::encryptHash(real_file_hash,hash_of_hash) ;
|
||||||
|
|
||||||
|
mBannedFileList.insert(real_file_hash) ;
|
||||||
|
mBannedFileList.insert(hash_of_hash) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
IndicateConfigChanged();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool p3FileDatabase::unbanFile(const RsFileHash& real_file_hash)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mFLSMtx) ;
|
||||||
|
mPrimaryBanList.erase(real_file_hash) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
IndicateConfigChanged();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool p3FileDatabase::getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files)
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mFLSMtx) ;
|
||||||
|
banned_files = mPrimaryBanList;
|
||||||
|
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,6 +132,10 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
|
|||||||
void setMaxShareDepth(int i) ;
|
void setMaxShareDepth(int i) ;
|
||||||
int maxShareDepth() const ;
|
int maxShareDepth() const ;
|
||||||
|
|
||||||
|
bool banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) ;
|
||||||
|
bool unbanFile(const RsFileHash& real_file_hash);
|
||||||
|
bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) ;
|
||||||
|
|
||||||
// computes/gathers statistics about shared directories
|
// computes/gathers statistics about shared directories
|
||||||
|
|
||||||
int getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& stats);
|
int getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& stats);
|
||||||
@ -244,5 +248,11 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
|
|||||||
std::string mFileSharingDir ;
|
std::string mFileSharingDir ;
|
||||||
time_t mLastCleanupTime;
|
time_t mLastCleanupTime;
|
||||||
time_t mLastDataRecvTS ;
|
time_t mLastDataRecvTS ;
|
||||||
|
|
||||||
|
// file filtering. Not explicitly related to shared files, but
|
||||||
|
//
|
||||||
|
|
||||||
|
std::map<RsFileHash,BannedFileEntry> mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map<real hash, BannedFileEntry>
|
||||||
|
std::set<RsFileHash> mBannedFileList ; // list of banned hashes. This include original hashs and H(H(f)) when coming from friends.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,6 +41,10 @@ void RsFileListsSyncResponseItem::serial_process(RsGenericSerializer::SerializeJ
|
|||||||
RsTypeSerializer::serial_process<uint64_t> (j,ctx,request_id, "request_id") ;
|
RsTypeSerializer::serial_process<uint64_t> (j,ctx,request_id, "request_id") ;
|
||||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,directory_content_data, "directory_content_data") ;
|
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,directory_content_data, "directory_content_data") ;
|
||||||
}
|
}
|
||||||
|
void RsFileListsBannedHashesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,encrypted_hashes,"encrypted_hashes") ;
|
||||||
|
}
|
||||||
|
|
||||||
RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
|
RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||||
{
|
{
|
||||||
@ -51,6 +55,7 @@ RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
|
|||||||
{
|
{
|
||||||
case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: return new RsFileListsSyncRequestItem();
|
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_SYNC_RSP_ITEM: return new RsFileListsSyncResponseItem();
|
||||||
|
case RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM: return new RsFileListsBannedHashesItem();
|
||||||
default:
|
default:
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,10 @@
|
|||||||
|
|
||||||
#include "serialiser/rsserializer.h"
|
#include "serialiser/rsserializer.h"
|
||||||
|
|
||||||
// These items have "flag type" numbers, but this is not used.
|
|
||||||
|
|
||||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM = 0x01;
|
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_SYNC_RSP_ITEM = 0x02;
|
||||||
const uint8_t RS_PKT_SUBTYPE_FILELISTS_CONFIG_ITEM = 0x03;
|
const uint8_t RS_PKT_SUBTYPE_FILELISTS_CONFIG_ITEM = 0x03;
|
||||||
|
const uint8_t RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM = 0x04;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Base class for filelist sync items
|
* Base class for filelist sync items
|
||||||
@ -103,6 +102,17 @@ public:
|
|||||||
RsTlvBinaryData directory_content_data ; // encoded binary data. This allows to vary the encoding format, in a way that is transparent to the serialiser.
|
RsTlvBinaryData directory_content_data ; // encoded binary data. This allows to vary the encoding format, in a way that is transparent to the serialiser.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RsFileListsBannedHashesItem: public RsFileListsItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsFileListsBannedHashesItem() : RsFileListsItem(RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM){}
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||||
|
|
||||||
|
std::set<RsFileHash> encrypted_hashes ;// hash of hash for each banned file.
|
||||||
|
};
|
||||||
|
|
||||||
class RsFileListsSerialiser : public RsServiceSerializer
|
class RsFileListsSerialiser : public RsServiceSerializer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -1832,3 +1832,17 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Offensive content file filtering
|
||||||
|
|
||||||
|
int ftServer::banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size)
|
||||||
|
{
|
||||||
|
return mFileDatabase->banFile(real_file_hash,filename,file_size) ;
|
||||||
|
}
|
||||||
|
int ftServer::unbanFile(const RsFileHash& real_file_hash)
|
||||||
|
{
|
||||||
|
return mFileDatabase->unbanFile(real_file_hash) ;
|
||||||
|
}
|
||||||
|
bool ftServer::getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files)
|
||||||
|
{
|
||||||
|
return mFileDatabase->getPrimaryBannedFilesList(banned_files) ;
|
||||||
|
}
|
||||||
|
@ -192,6 +192,10 @@ public:
|
|||||||
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
||||||
virtual int getSharedDirStatistics(const RsPeerId& pid, SharedDirStats& stats) ;
|
virtual int getSharedDirStatistics(const RsPeerId& pid, SharedDirStats& stats) ;
|
||||||
|
|
||||||
|
virtual int banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) ;
|
||||||
|
virtual int unbanFile(const RsFileHash& real_file_hash);
|
||||||
|
virtual bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) ;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions
|
* Utility Functions
|
||||||
***/
|
***/
|
||||||
@ -237,6 +241,8 @@ public:
|
|||||||
virtual bool ignoreDuplicates() ;
|
virtual bool ignoreDuplicates() ;
|
||||||
virtual void setIgnoreDuplicates(bool ignore) ;
|
virtual void setIgnoreDuplicates(bool ignore) ;
|
||||||
|
|
||||||
|
static bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash);
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/*************** Data Transfer Interface ***********************/
|
/*************** Data Transfer Interface ***********************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
@ -282,7 +288,6 @@ protected:
|
|||||||
// fnds out what is the real hash of encrypted hash hash
|
// fnds out what is the real hash of encrypted hash hash
|
||||||
bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash);
|
bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash);
|
||||||
bool findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash);
|
bool findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash);
|
||||||
bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash);
|
|
||||||
|
|
||||||
bool checkUploadLimit(const RsPeerId& pid,const RsFileHash& hash);
|
bool checkUploadLimit(const RsPeerId& pid,const RsFileHash& hash);
|
||||||
private:
|
private:
|
||||||
|
@ -162,6 +162,13 @@ public:
|
|||||||
uint64_t mTotalSize ;
|
uint64_t mTotalSize ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BannedFileEntry
|
||||||
|
{
|
||||||
|
uint64_t size ;
|
||||||
|
std::string filename ;
|
||||||
|
time_t ban_time_stamp;
|
||||||
|
};
|
||||||
|
|
||||||
class RsFiles
|
class RsFiles
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -261,6 +268,10 @@ public:
|
|||||||
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0;
|
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0;
|
||||||
virtual int getSharedDirStatistics(const RsPeerId& pid, SharedDirStats& stats) =0;
|
virtual int getSharedDirStatistics(const RsPeerId& pid, SharedDirStats& stats) =0;
|
||||||
|
|
||||||
|
virtual int banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) =0;
|
||||||
|
virtual int unbanFile(const RsFileHash& real_file_hash)=0;
|
||||||
|
virtual bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) =0;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions.
|
* Utility Functions.
|
||||||
***/
|
***/
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
#define IMAGE_COLLVIEW ":/images/library_view.png"
|
#define IMAGE_COLLVIEW ":/images/library_view.png"
|
||||||
#define IMAGE_COLLOPEN ":/images/library.png"
|
#define IMAGE_COLLOPEN ":/images/library.png"
|
||||||
#define IMAGE_COPYLINK ":/images/copyrslink.png"
|
#define IMAGE_COPYLINK ":/images/copyrslink.png"
|
||||||
|
#define IMAGE_BANFILE ":/icons/biohazard_red.png"
|
||||||
|
|
||||||
/* Key for UI Preferences */
|
/* Key for UI Preferences */
|
||||||
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
|
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
|
||||||
@ -327,6 +328,7 @@ void SearchDialog::searchResultWidgetCustomPopupMenu( QPoint /*point*/ )
|
|||||||
QMenu contextMnu(this) ;
|
QMenu contextMnu(this) ;
|
||||||
|
|
||||||
contextMnu.addAction(QIcon(IMAGE_START), tr("Download"), this, SLOT(download())) ;
|
contextMnu.addAction(QIcon(IMAGE_START), tr("Download"), this, SLOT(download())) ;
|
||||||
|
contextMnu.addAction(QIcon(IMAGE_BANFILE), tr("Mark as bad"), this, SLOT(ban())) ;
|
||||||
contextMnu.addSeparator();//--------------------------------------
|
contextMnu.addSeparator();//--------------------------------------
|
||||||
|
|
||||||
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyResultLink())) ;
|
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyResultLink())) ;
|
||||||
@ -406,22 +408,44 @@ void SearchDialog::download()
|
|||||||
std::cout << "isuing file request from search dialog: -"
|
std::cout << "isuing file request from search dialog: -"
|
||||||
<< (item->text(SR_NAME_COL)).toStdString()
|
<< (item->text(SR_NAME_COL)).toStdString()
|
||||||
<< "-" << hash << "-" << (item->text(SR_SIZE_COL)).toULongLong() << "-ids=" ;
|
<< "-" << hash << "-" << (item->text(SR_SIZE_COL)).toULongLong() << "-ids=" ;
|
||||||
for(std::list<RsPeerId>::const_iterator it(srcIds.begin()); it!=srcIds.end(); ++it) {
|
for(std::list<RsPeerId>::const_iterator it(srcIds.begin()); it!=srcIds.end(); ++it)
|
||||||
std::cout << *it << "-" << std::endl;
|
std::cout << *it << "-" << std::endl;
|
||||||
}//for(std::list<RsPeerId>::const_iterator
|
|
||||||
//QColor foreground = QColor(0, 128, 0); // green
|
|
||||||
QColor foreground = textColorDownloading();
|
QColor foreground = textColorDownloading();
|
||||||
QBrush brush(foreground);
|
QBrush brush(foreground);
|
||||||
for (int i = 0; i < item->columnCount(); ++i)
|
for (int i = 0; i < item->columnCount(); ++i)
|
||||||
{
|
|
||||||
item->setForeground(i, brush);
|
item->setForeground(i, brush);
|
||||||
}
|
}
|
||||||
}//if(!rsFiles -> FileRequest(
|
}
|
||||||
}//if (item->text(SR_HASH_COL).isEmpty())
|
}
|
||||||
}//for (int i = 0
|
if (attemptDownloadLocal)
|
||||||
if (attemptDownloadLocal) {
|
|
||||||
QMessageBox::information(this, tr("Download Notice"), tr("Skipping Local Files")) ;
|
QMessageBox::information(this, tr("Download Notice"), tr("Skipping Local Files")) ;
|
||||||
}//if (attemptDownloadLocal)
|
}
|
||||||
|
|
||||||
|
void SearchDialog::ban()
|
||||||
|
{
|
||||||
|
/* should also be able to handle multi-selection */
|
||||||
|
|
||||||
|
QList<QTreeWidgetItem*> itemsForDownload = ui.searchResultWidget->selectedItems() ;
|
||||||
|
int numdls = itemsForDownload.size() ;
|
||||||
|
QTreeWidgetItem * item ;
|
||||||
|
|
||||||
|
for (int i = 0; i < numdls; ++i)
|
||||||
|
{
|
||||||
|
item = itemsForDownload.at(i) ;
|
||||||
|
// call the download
|
||||||
|
// *
|
||||||
|
if(!item->text(SR_HASH_COL).isEmpty())
|
||||||
|
{
|
||||||
|
std::cerr << "SearchDialog::download() Calling File Ban" << std::endl ;
|
||||||
|
|
||||||
|
RsFileHash hash( item->text(SR_HASH_COL).toStdString()) ;
|
||||||
|
|
||||||
|
rsFiles -> banFile( hash, (item->text(SR_NAME_COL)).toUtf8().constData() , (item->text(SR_SIZE_COL)).toULongLong());
|
||||||
|
|
||||||
|
ui.searchResultWidget->takeItem(item) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchDialog::collCreate()
|
void SearchDialog::collCreate()
|
||||||
|
@ -75,6 +75,7 @@ private slots:
|
|||||||
void searchSummaryWidgetCustomPopupMenu( QPoint point );
|
void searchSummaryWidgetCustomPopupMenu( QPoint point );
|
||||||
|
|
||||||
void download();
|
void download();
|
||||||
|
void ban();
|
||||||
|
|
||||||
void collCreate();
|
void collCreate();
|
||||||
void collModif();
|
void collModif();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user