From 50e03a539c76c1278dc19c280cb5ffa3b2929e6d Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 16 Aug 2018 18:49:36 +0200 Subject: [PATCH 01/14] basic infrastructure for banning unwanted file content --- libretroshare/src/file_sharing/p3filelists.cc | 41 +++++++++++++++++ libretroshare/src/file_sharing/p3filelists.h | 10 +++++ .../src/file_sharing/rsfilelistitems.cc | 19 +++++--- .../src/file_sharing/rsfilelistitems.h | 20 ++++++--- libretroshare/src/ft/ftserver.cc | 18 +++++++- libretroshare/src/ft/ftserver.h | 7 ++- libretroshare/src/retroshare/rsfiles.h | 11 +++++ .../src/gui/FileTransfer/SearchDialog.cpp | 44 ++++++++++++++----- .../src/gui/FileTransfer/SearchDialog.h | 1 + 9 files changed, 146 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 7448ffd0d..7e7be3632 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -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 + + 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& banned_files) +{ + RS_STACK_MUTEX(mFLSMtx) ; + banned_files = mPrimaryBanList; + + return true ; +} + + diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 44e5ec4b4..87297094d 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -132,6 +132,10 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub void setMaxShareDepth(int i) ; 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& banned_files) ; + // computes/gathers statistics about shared directories int getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& stats); @@ -244,5 +248,11 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub std::string mFileSharingDir ; time_t mLastCleanupTime; time_t mLastDataRecvTS ; + + // file filtering. Not explicitly related to shared files, but + // + + std::map mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map + std::set mBannedFileList ; // list of banned hashes. This include original hashs and H(H(f)) when coming from friends. }; diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index 49aa4edff..a0e1eb695 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -34,12 +34,16 @@ void RsFileListsSyncRequestItem::serial_process(RsGenericSerializer::SerializeJo } void RsFileListsSyncResponseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; - RsTypeSerializer::serial_process (j,ctx,checksum,"checksum") ; - RsTypeSerializer::serial_process (j,ctx,flags ,"flags") ; + RsTypeSerializer::serial_process (j,ctx,entry_hash, "entry_hash") ; + RsTypeSerializer::serial_process (j,ctx,checksum, "checksum") ; + RsTypeSerializer::serial_process (j,ctx,flags, "flags") ; RsTypeSerializer::serial_process (j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ; - RsTypeSerializer::serial_process (j,ctx,request_id,"request_id") ; - RsTypeSerializer::serial_process(j,ctx,directory_content_data,"directory_content_data") ; + RsTypeSerializer::serial_process (j,ctx,request_id, "request_id") ; + RsTypeSerializer::serial_process(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 @@ -49,8 +53,9 @@ 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_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(); default: return NULL ; } diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 337bde15f..68a7d2d8c 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -34,11 +34,10 @@ #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_RSP_ITEM = 0x02; -const uint8_t RS_PKT_SUBTYPE_FILELISTS_CONFIG_ITEM = 0x03; +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; /*! * 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. }; +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 encrypted_hashes ;// hash of hash for each banned file. +}; + class RsFileListsSerialiser : public RsServiceSerializer { public: diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 276446d1f..90ba9beac 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1825,10 +1825,24 @@ int ftServer::handleIncoming() bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr) { /* add all the subbits to config mgr */ - cfgmgr->addConfiguration("ft_database.cfg", mFileDatabase); - cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra); + cfgmgr->addConfiguration("ft_database.cfg" , mFileDatabase); + cfgmgr->addConfiguration("ft_extra.cfg" , mFtExtra ); cfgmgr->addConfiguration("ft_transfers.cfg", mFtController); 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& banned_files) +{ + return mFileDatabase->getPrimaryBannedFilesList(banned_files) ; +} diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 57920cc02..7e9ccde6a 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -192,6 +192,10 @@ public: virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id); 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& banned_files) ; + /*** * Utility Functions ***/ @@ -237,6 +241,8 @@ public: virtual bool ignoreDuplicates() ; virtual void setIgnoreDuplicates(bool ignore) ; + static bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash); + /***************************************************************/ /*************** Data Transfer Interface ***********************/ /***************************************************************/ @@ -282,7 +288,6 @@ protected: // fnds out what is the real hash of encrypted hash hash bool findRealHash(const RsFileHash& hash, RsFileHash& real_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); private: diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 520dd22bf..0af2708d6 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -162,6 +162,13 @@ public: uint64_t mTotalSize ; }; +struct BannedFileEntry +{ + uint64_t size ; + std::string filename ; + time_t ban_time_stamp; +}; + class RsFiles { public: @@ -261,6 +268,10 @@ public: virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) = 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& banned_files) =0; + /*** * Utility Functions. ***/ diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index be61a1dcc..e844f9866 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -54,6 +54,7 @@ #define IMAGE_COLLVIEW ":/images/library_view.png" #define IMAGE_COLLOPEN ":/images/library.png" #define IMAGE_COPYLINK ":/images/copyrslink.png" +#define IMAGE_BANFILE ":/icons/biohazard_red.png" /* Key for UI Preferences */ #define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch" @@ -327,6 +328,7 @@ void SearchDialog::searchResultWidgetCustomPopupMenu( QPoint /*point*/ ) QMenu contextMnu(this) ; 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.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: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << hash << "-" << (item->text(SR_SIZE_COL)).toULongLong() << "-ids=" ; - for(std::list::const_iterator it(srcIds.begin()); it!=srcIds.end(); ++it) { + for(std::list::const_iterator it(srcIds.begin()); it!=srcIds.end(); ++it) std::cout << *it << "-" << std::endl; - }//for(std::list::const_iterator - //QColor foreground = QColor(0, 128, 0); // green + QColor foreground = textColorDownloading(); QBrush brush(foreground); for (int i = 0; i < item->columnCount(); ++i) - { 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")) ; - }//if (attemptDownloadLocal) +} + +void SearchDialog::ban() +{ + /* should also be able to handle multi-selection */ + + QList 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() diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h index 57846692c..968b0e725 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h @@ -75,6 +75,7 @@ private slots: void searchSummaryWidgetCustomPopupMenu( QPoint point ); void download(); + void ban(); void collCreate(); void collModif(); From e17c4d0e40b4e3df766e82f444b5999dd7df0e46 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 16 Aug 2018 22:22:47 +0200 Subject: [PATCH 02/14] added a dialog to edit banned files --- .../src/file_sharing/rsfilelistitems.h | 2 +- .../gui/FileTransfer/BannedFilesDialog.cpp | 36 ++++++++++++++ .../src/gui/FileTransfer/BannedFilesDialog.h | 46 ++++++++++++++++++ .../src/gui/FileTransfer/BannedFilesDialog.ui | 48 +++++++++++++++++++ .../src/gui/FileTransfer/SearchDialog.cpp | 10 +++- .../src/gui/FileTransfer/SearchDialog.h | 1 + .../src/gui/FileTransfer/SearchDialog.ui | 18 +++++++ .../src/gui/FileTransfer/TransfersDialog.h | 6 +-- retroshare-gui/src/retroshare-gui.pro | 3 ++ 9 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp create mode 100644 retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h create mode 100644 retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 68a7d2d8c..20ea2f649 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -107,7 +107,7 @@ class RsFileListsBannedHashesItem: public RsFileListsItem public: RsFileListsBannedHashesItem() : RsFileListsItem(RS_PKT_SUBTYPE_FILELISTS_BANNED_HASHES_ITEM){} - virtual void clear(); + virtual void clear() { encrypted_hashes.clear(); } virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); std::set encrypted_hashes ;// hash of hash for each banned file. diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp new file mode 100644 index 000000000..49981410c --- /dev/null +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* + * retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp * + * * + * Copyright 2018 by Retroshare Team * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + *******************************************************************************/ + +#include "retroshare/rsfiles.h" + +#include "BannedFilesDialog.h" + +BannedFilesDialog::BannedFilesDialog(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); +} + +BannedFilesDialog::~BannedFilesDialog() {} + +void BannedFilesDialog::unbanFile() +{ +#warning Code missing here +} diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h new file mode 100644 index 000000000..a76efb7b9 --- /dev/null +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h * + * * + * Copyright 2018 by Retroshare Team * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + *******************************************************************************/ + +#pragma once + +#include "RsAutoUpdatePage.h" +#include "ui_BannedFilesDialog.h" + +class BannedFilesDialog: public QDialog +{ + Q_OBJECT + +public: + /** Default Constructor */ + BannedFilesDialog(QWidget *parent = 0); + /** Default Destructor */ + ~BannedFilesDialog(); + +private slots: + void unbanFile(); + + /** management of the adv search dialog object when switching search modes */ + //void hideEvent(QHideEvent * event); + +private: + /** Qt Designer generated object */ + Ui::BannedFilesDialog ui; +}; + diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui new file mode 100644 index 000000000..1b3833f58 --- /dev/null +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui @@ -0,0 +1,48 @@ + + + BannedFilesDialog + + + + 0 + 0 + 923 + 810 + + + + + + + true + + + + Filename + + + + + Hash + + + + + Size + + + + + Banned since... + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index e844f9866..f017529b1 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -26,6 +26,7 @@ #include "rshare.h" #include "SearchDialog.h" +#include "gui/FileTransfer/BannedFilesDialog.h" #include "gui/RSHumanReadableDelegate.h" #include "gui/RetroShareLink.h" #include "retroshare-gui/RsAutoUpdatePage.h" @@ -118,6 +119,7 @@ SearchDialog::SearchDialog(QWidget *parent) connect( ui.searchResultWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchResultWidgetCustomPopupMenu( QPoint ) ) ); connect( ui.searchSummaryWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchSummaryWidgetCustomPopupMenu( QPoint ) ) ); + connect( ui.showBannedFiles_TB, SIGNAL( clicked() ), this, SLOT( openBannedFiles() ) ); connect( ui.lineEdit, SIGNAL( returnPressed ( void ) ), this, SLOT( searchKeywords( void ) ) ); connect( ui.lineEdit, SIGNAL( textChanged ( const QString& ) ), this, SLOT( checkText( const QString& ) ) ); @@ -443,11 +445,17 @@ void SearchDialog::ban() rsFiles -> banFile( hash, (item->text(SR_NAME_COL)).toUtf8().constData() , (item->text(SR_SIZE_COL)).toULongLong()); - ui.searchResultWidget->takeItem(item) ; + ui.searchResultWidget->takeTopLevelItem(ui.searchResultWidget->indexOfTopLevelItem(item)) ; } } } +void SearchDialog::openBannedFiles() +{ + BannedFilesDialog d ; + d.exec(); +} + void SearchDialog::collCreate() { std::vector dirVec; diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h index 968b0e725..001ae3903 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h @@ -87,6 +87,7 @@ private slots: void recommendtofriends(); void checkText(const QString&); + void openBannedFiles(); void copyResultLink(); void copySearchLink(); void openFolderSearch(); diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.ui b/retroshare-gui/src/gui/FileTransfer/SearchDialog.ui index b3df60f05..47e221bf5 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.ui +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.ui @@ -170,6 +170,23 @@ + + + + + 0 + 0 + + + + + + + + :/icons/biohazard_red.png:/icons/biohazard_red.png + + + @@ -450,6 +467,7 @@ + diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h index 51bc205d3..f98a96daa 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h @@ -55,7 +55,8 @@ public: /* Fixed numbers for load and save the last page */ SearchTab = 0, /** Network page. */ LocalSharedFilesTab = 1, /** Network new graph. */ - RemoteSharedFilesTab = 2 /** Old group chat page. */ + RemoteSharedFilesTab = 2, /** Old group chat page. */ + DownloadTab = 3 }; @@ -108,9 +109,6 @@ private slots: void expandAllUL(); void collapseAllUL(); -// void rootdecorated(); -// void rootisnotdecorated(); - void pauseFileTransfer(); void resumeFileTransfer(); void dlOpenFolder(); diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index d973e5de8..b5b17d159 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -365,6 +365,7 @@ HEADERS += rshare.h \ gui/FileTransfer/DLListDelegate.h \ gui/FileTransfer/ULListDelegate.h \ gui/FileTransfer/TransfersDialog.h \ + gui/FileTransfer/BannedFilesDialog.h \ gui/statistics/TurtleRouterDialog.h \ gui/statistics/TurtleRouterStatistics.h \ gui/statistics/dhtgraph.h \ @@ -597,6 +598,7 @@ FORMS += gui/StartDialog.ui \ gui/FileTransfer/DetailsDialog.ui \ gui/FileTransfer/SearchDialog.ui \ gui/FileTransfer/SharedFilesDialog.ui \ + gui/FileTransfer/BannedFilesDialog.ui \ gui/MainWindow.ui \ gui/NetworkView.ui \ gui/MessengerWindow.ui \ @@ -743,6 +745,7 @@ SOURCES += main.cpp \ gui/FileTransfer/xprogressbar.cpp \ gui/FileTransfer/DetailsDialog.cpp \ gui/FileTransfer/TransferUserNotify.cpp \ + gui/FileTransfer/BannedFilesDialog.cpp \ gui/MainPage.cpp \ gui/HelpDialog.cpp \ gui/LogoBar.cpp \ From a7ee85495db4a266eedbd6384ffd999bdf25820e Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 16 Aug 2018 23:18:29 +0200 Subject: [PATCH 03/14] added fill routine for banned files list --- .../gui/FileTransfer/BannedFilesDialog.cpp | 41 +++++++++++++++++++ .../src/gui/FileTransfer/BannedFilesDialog.h | 3 ++ 2 files changed, 44 insertions(+) diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp index 49981410c..bda425ab3 100644 --- a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp @@ -18,14 +18,25 @@ * * *******************************************************************************/ +#include + #include "retroshare/rsfiles.h" #include "BannedFilesDialog.h" +#define COLUMN_FILE_NAME 0 +#define COLUMN_FILE_HASH 1 +#define COLUMN_FILE_SIZE 2 +#define COLUMN_FILE_TIME 3 + BannedFilesDialog::BannedFilesDialog(QWidget *parent) : QDialog(parent) { ui.setupUi(this); + + fillFilesList() ; + + connect(ui.bannedFiles_TW, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(bannedFilesContextMenu(QPoint))); } BannedFilesDialog::~BannedFilesDialog() {} @@ -34,3 +45,33 @@ void BannedFilesDialog::unbanFile() { #warning Code missing here } + +void BannedFilesDialog::bannedFilesContextMenu() +{ + QMenu menu(this); + + QAction *action = menu.addAction(QIcon(":/images/FeedAdd.png"), tr("Remove"), this, SLOT(unbanFile())); + + menu.exec(QCursor::pos()); +} + +void BannedFilesDialog::fillFilesList() +{ + std::map banned_files ; + + rsFiles->getPrimaryBannedFilesList(banned_files); + int row=0; + + for(auto it(banned_files.begin());it!=banned_files.end();++it) + { + ui.bannedFiles_TW->setItem(row, COLUMN_FILE_NAME, new QTableWidgetItem(QIcon(),QString::fromUtf8(it->second.filename.c_str()),0)); + ui.bannedFiles_TW->setItem(row, COLUMN_FILE_HASH, new QTableWidgetItem(QIcon(),QString::fromStdString(it->first.toStdString()),0)); + ui.bannedFiles_TW->setItem(row, COLUMN_FILE_SIZE, new QTableWidgetItem(QIcon(),QString::number(it->second.size),0)); + ui.bannedFiles_TW->setItem(row, COLUMN_FILE_TIME, new QTableWidgetItem(QIcon(),QString::number(it->second.ban_time_stamp),0)); + + row++; + + // ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_ID, QString::fromStdString(id)); + // ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_TYPE, dest_type); + } +} diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h index a76efb7b9..4dfe95adc 100644 --- a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h @@ -38,8 +38,11 @@ private slots: /** management of the adv search dialog object when switching search modes */ //void hideEvent(QHideEvent * event); + void bannedFilesContextMenu(); private: + void fillFilesList(); + /** Qt Designer generated object */ Ui::BannedFilesDialog ui; }; From a2804a70ec0b6e4b97e7d9fc682096fba6eff276 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 19 Aug 2018 15:09:43 +0200 Subject: [PATCH 04/14] added context menu and removal feature for banned files --- .../gui/FileTransfer/BannedFilesDialog.cpp | 23 ++++++++++----- .../src/gui/FileTransfer/BannedFilesDialog.h | 2 +- .../src/gui/FileTransfer/BannedFilesDialog.ui | 29 +++++++++++++++---- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp index bda425ab3..5be060b09 100644 --- a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.cpp @@ -19,6 +19,7 @@ *******************************************************************************/ #include +#include #include "retroshare/rsfiles.h" @@ -43,14 +44,21 @@ BannedFilesDialog::~BannedFilesDialog() {} void BannedFilesDialog::unbanFile() { -#warning Code missing here + int row = ui.bannedFiles_TW->currentRow(); + + QTableWidgetItem *item = ui.bannedFiles_TW->item(row, COLUMN_FILE_HASH); + + RsFileHash hash(item->data(Qt::UserRole).toString().toStdString()) ; + rsFiles->unbanFile(hash) ; + + fillFilesList(); } -void BannedFilesDialog::bannedFilesContextMenu() +void BannedFilesDialog::bannedFilesContextMenu(QPoint) { QMenu menu(this); - QAction *action = menu.addAction(QIcon(":/images/FeedAdd.png"), tr("Remove"), this, SLOT(unbanFile())); + menu.addAction(QIcon(":/images/FeedAdd.png"), tr("Remove"), this, SLOT(unbanFile())); menu.exec(QCursor::pos()); } @@ -62,16 +70,17 @@ void BannedFilesDialog::fillFilesList() rsFiles->getPrimaryBannedFilesList(banned_files); int row=0; + ui.bannedFiles_TW->setRowCount(banned_files.size()) ; + for(auto it(banned_files.begin());it!=banned_files.end();++it) { ui.bannedFiles_TW->setItem(row, COLUMN_FILE_NAME, new QTableWidgetItem(QIcon(),QString::fromUtf8(it->second.filename.c_str()),0)); ui.bannedFiles_TW->setItem(row, COLUMN_FILE_HASH, new QTableWidgetItem(QIcon(),QString::fromStdString(it->first.toStdString()),0)); ui.bannedFiles_TW->setItem(row, COLUMN_FILE_SIZE, new QTableWidgetItem(QIcon(),QString::number(it->second.size),0)); - ui.bannedFiles_TW->setItem(row, COLUMN_FILE_TIME, new QTableWidgetItem(QIcon(),QString::number(it->second.ban_time_stamp),0)); + ui.bannedFiles_TW->setItem(row, COLUMN_FILE_TIME, new QTableWidgetItem(QIcon(),QDateTime::fromTime_t(it->second.ban_time_stamp).toString(),0)); + + ui.bannedFiles_TW->item(row, COLUMN_FILE_HASH)->setData(Qt::UserRole, QString::fromStdString(it->first.toStdString())); row++; - - // ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_ID, QString::fromStdString(id)); - // ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_TYPE, dest_type); } } diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h index 4dfe95adc..cdcb4f6ee 100644 --- a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.h @@ -38,7 +38,7 @@ private slots: /** management of the adv search dialog object when switching search modes */ //void hideEvent(QHideEvent * event); - void bannedFilesContextMenu(); + void bannedFilesContextMenu(QPoint); private: void fillFilesList(); diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui index 1b3833f58..435168023 100644 --- a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui +++ b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui @@ -10,12 +10,34 @@ 810 - + + + + + <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> + + + Qt::AlignJustify|Qt::AlignVCenter + + + true + + + + + Qt::CustomContextMenu + + + true + true + + false + Filename @@ -40,9 +62,6 @@ - - - - + From af7556610a96d0b30b2550d2841800544e77d00e Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 19 Aug 2018 15:52:35 +0200 Subject: [PATCH 05/14] added option whether to trust friend nodes for banned files --- .../src/file_sharing/file_sharing_defaults.h | 24 +++++++++-------- libretroshare/src/file_sharing/p3filelists.cc | 26 +++++++++++++++++++ libretroshare/src/file_sharing/p3filelists.h | 3 +++ .../src/gui/settings/TransferPage.ui | 7 +++++ 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index 09bf937d5..77bdbb3ff 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -29,16 +29,17 @@ static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 se static const uint32_t DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR = 60*24*86400 ; // delete non empty remoe directories after 60 days of inactivity static const uint32_t DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR = 5*24*86400 ; // delete empty remote directories after 5 days of inactivity -static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time -static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files -static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch -static const std::string FOLLOW_SYMLINKS_SS = "FOLLOW_SYMLINKS"; // dereference symbolic links, or just ignore them. -static const std::string IGNORE_DUPLICATES = "IGNORE_DUPLICATES"; // do not index files that are referenced multiple times because of links -static const std::string WATCH_HASH_SALT_SS = "WATCH_HASH_SALT"; // Salt that is used to hash directory names -static const std::string IGNORED_PREFIXES_SS = "IGNORED_PREFIXES"; // ignore file prefixes -static const std::string IGNORED_SUFFIXES_SS = "IGNORED_SUFFIXES"; // ignore file suffixes -static const std::string IGNORE_LIST_FLAGS_SS = "IGNORED_FLAGS"; // ignore file flags -static const std::string MAX_SHARE_DEPTH = "MAX_SHARE_DEPTH"; // maximum depth of shared directories +static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time +static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files +static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch +static const std::string TRUST_FRIEND_NODES_FOR_BANNED_FILES_SS = "TRUST_FRIEND_NODES_FOR_BANNED_FILES"; // should we trust friends for banned files or not +static const std::string FOLLOW_SYMLINKS_SS = "FOLLOW_SYMLINKS"; // dereference symbolic links, or just ignore them. +static const std::string IGNORE_DUPLICATES = "IGNORE_DUPLICATES"; // do not index files that are referenced multiple times because of links +static const std::string WATCH_HASH_SALT_SS = "WATCH_HASH_SALT"; // Salt that is used to hash directory names +static const std::string IGNORED_PREFIXES_SS = "IGNORED_PREFIXES"; // ignore file prefixes +static const std::string IGNORED_SUFFIXES_SS = "IGNORED_SUFFIXES"; // ignore file suffixes +static const std::string IGNORE_LIST_FLAGS_SS = "IGNORED_FLAGS"; // ignore file flags +static const std::string MAX_SHARE_DEPTH = "MAX_SHARE_DEPTH"; // maximum depth of shared directories static const std::string FILE_SHARING_DIR_NAME = "file_sharing" ; // hard-coded directory name to store friend file lists, hash cache, etc. static const std::string HASH_CACHE_FILE_NAME = "hash_cache.bin" ; // hard-coded directory name to store encrypted hash cache. @@ -61,6 +62,7 @@ static const uint64_t ENTRY_INDEX_BIT_MASK_64BITS = 0x0000000 static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min -static const bool FOLLOW_SYMLINKS_DEFAULT = true; +static const bool FOLLOW_SYMLINKS_DEFAULT = true; +static const bool TRUST_FRIEND_NODES_FOR_BANNED_FILES_DEFAULT = true; static const uint32_t FL_BASE_TMP_SECTION_SIZE = 4096 ; diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 7e7be3632..e6cbdb2b5 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -72,6 +72,7 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers) mLastRemoteDirSweepTS = 0 ; mLastCleanupTime = 0 ; mLastDataRecvTS = 0 ; + mTrustFriendNodesForBannedFiles = TRUST_FRIEND_NODES_FOR_BANNED_FILES_DEFAULT; // This is for the transmission of data @@ -369,6 +370,14 @@ cleanup = true; { RsTlvKeyValue kv; + kv.key = TRUST_FRIEND_NODES_FOR_BANNED_FILES_SS; + kv.value = trustFriendNodesForBannedFiles()?"YES":"NO" ; + + rskv->tlvkvs.pairs.push_back(kv); + } + { + RsTlvKeyValue kv; + kv.key = WATCH_HASH_SALT_SS; kv.value = mLocalDirWatcher->hashSalt().toStdString(); @@ -462,6 +471,10 @@ bool p3FileDatabase::loadList(std::list& load) { setWatchEnabled(kit->value == "YES") ; } + else if(kit->key == TRUST_FRIEND_NODES_FOR_BANNED_FILES_SS) + { + setTrustFriendNodesForBannedFiles(kit->value == "YES") ; + } else if(kit->key == WATCH_HASH_SALT_SS) { std::cerr << "Initing directory watcher with saved secret salt..." << std::endl; @@ -1895,6 +1908,19 @@ bool p3FileDatabase::getPrimaryBannedFilesList(std::map& banned_files) ; + bool trustFriendNodesForBannedFiles() const ; + void setTrustFriendNodesForBannedFiles(bool b) ; // computes/gathers statistics about shared directories @@ -254,5 +256,6 @@ 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::set mBannedFileList ; // list of banned hashes. This include original hashs and H(H(f)) when coming from friends. + bool mTrustFriendNodesForBannedFiles ; }; diff --git a/retroshare-gui/src/gui/settings/TransferPage.ui b/retroshare-gui/src/gui/settings/TransferPage.ui index 529a6e260..2f6dd0dae 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.ui +++ b/retroshare-gui/src/gui/settings/TransferPage.ui @@ -447,6 +447,13 @@ + + + + Trust friend nodes with banned files + + + From e5e566051b37bd0804fc100019f757a0837bb0ca Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 19 Aug 2018 21:11:17 +0200 Subject: [PATCH 06/14] 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 From 0b176a0fe59cd0a47416764175e4203588c98977 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 20 Aug 2018 23:30:05 +0200 Subject: [PATCH 07/14] added sending of banned file info --- libretroshare/src/file_sharing/p3filelists.cc | 52 ++++++++++++++++--- libretroshare/src/file_sharing/p3filelists.h | 6 ++- .../src/file_sharing/rsfilelistitems.cc | 1 + .../src/file_sharing/rsfilelistitems.h | 1 + 4 files changed, 51 insertions(+), 9 deletions(-) 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. }; From 365464623a6bea9ca7bc307af62625d415e35b3e Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 21 Aug 2018 11:20:02 +0200 Subject: [PATCH 08/14] added load/save of banned files and handling of banned files information from friends --- libretroshare/src/file_sharing/p3filelists.cc | 40 ++++++++++++++++--- libretroshare/src/file_sharing/p3filelists.h | 2 +- .../src/file_sharing/rsfilelistitems.cc | 18 +++++++-- .../src/file_sharing/rsfilelistitems.h | 21 ++++++++-- 4 files changed, 67 insertions(+), 14 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 5b3247f75..cc9f6cfc3 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -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& load) dirList.push_back(info) ; } + RsFileListsBannedHashesConfigItem *fb = dynamic_cast(*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 ; } + diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 336208910..65ed7b6ef 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -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 mPrimaryBanList ; // primary list (user controlled) of files banned from FT search and forwarding. map diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index e39ffc275..c443d1f3a 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -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(j,ctx, entry.size ,"entry.size") ; + RsTypeSerializer::serial_process (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 ; } diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 3b9074ca7..a8c84e18b 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -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 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 primary_banned_files_list ; +}; + class RsFileListsSerialiser : public RsServiceSerializer { public: From 3055897425839643990e7b05c2a087e005d5314d Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 22 Aug 2018 21:57:56 +0200 Subject: [PATCH 09/14] added filter in p3turtle against banned hashes in tunnel requests and search results --- libretroshare/src/file_sharing/p3filelists.cc | 11 +++++++ libretroshare/src/file_sharing/p3filelists.h | 1 + libretroshare/src/ft/ftserver.cc | 5 +++ libretroshare/src/ft/ftserver.h | 1 + libretroshare/src/retroshare/rsfiles.h | 1 + libretroshare/src/turtle/p3turtle.cc | 31 +++++++++++++++++++ 6 files changed, 50 insertions(+) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index cc9f6cfc3..e1ddd059c 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1919,6 +1919,17 @@ bool p3FileDatabase::unbanFile(const RsFileHash& real_file_hash) IndicateConfigChanged(); return true; } + +bool p3FileDatabase::isFileBanned(const RsFileHash& hash) +{ + RS_STACK_MUTEX(mFLSMtx) ; + + RsFileHash hash_of_hash ; + ftServer::encryptHash(hash,hash_of_hash) ; + + return mBannedFileList.find(hash) != mBannedFileList.end() || mBannedFileList.find(hash_of_hash) != mBannedFileList.end() ; +} + bool p3FileDatabase::getPrimaryBannedFilesList(std::map& banned_files) { RS_STACK_MUTEX(mFLSMtx) ; diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 65ed7b6ef..c58c9989a 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -142,6 +142,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub bool banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) ; bool unbanFile(const RsFileHash& real_file_hash); + bool isFileBanned(const RsFileHash& hash) ; bool getPrimaryBannedFilesList(std::map& banned_files) ; bool trustFriendNodesForBannedFiles() const ; void setTrustFriendNodesForBannedFiles(bool b) ; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 90ba9beac..d517a0114 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1846,3 +1846,8 @@ bool ftServer::getPrimaryBannedFilesList(std::map& b { return mFileDatabase->getPrimaryBannedFilesList(banned_files) ; } + +bool ftServer::isHashBanned(const RsFileHash& hash) +{ + return mFileDatabase->isFileBanned(hash); +} diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 7e9ccde6a..8e420092f 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -195,6 +195,7 @@ public: 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& banned_files) ; + virtual bool isHashBanned(const RsFileHash& hash); /*** * Utility Functions diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 0af2708d6..918f1ab2f 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -271,6 +271,7 @@ public: 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& banned_files) =0; + virtual bool isHashBanned(const RsFileHash& hash) =0; /*** * Utility Functions. diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index fcb77b134..36b4383a9 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1109,6 +1109,27 @@ void p3turtle::performLocalSearch_files(RsTurtleFileSearchRequestItem *item,uint void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item) { + // Filter out banned hashes from the result. + + RsTurtleFTSearchResultItem *ftsr_tmp = dynamic_cast(item) ; + + if(ftsr_tmp != NULL) + { + for(auto it(ftsr_tmp->result.begin());it!=ftsr_tmp->result.end();) + if( rsFiles->isHashBanned((*it).hash) ) + { + std::cerr << "(II) filtering out banned hash " << (*it).hash << " from turtle result " << std::hex << item->request_id << std::dec << std::endl; + it = ftsr_tmp->result.erase(it); + } + else + ++it; + + if(ftsr_tmp->result.empty()) + return ; + } + + // Then handle the result + std::list > results_to_notify_off_mutex ; { @@ -1525,6 +1546,16 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) item->print(std::cerr,0) ; #endif + // check first if the hash is in the ban list. If so, drop the request. + + if(rsFiles->isHashBanned(item->file_hash)) + { +#ifdef P3TURTLE_DEBUG + std::cerr << "(II) Rejecting tunnel request to ban hash " << item->file_hash << std::endl; +#endif + return ; + } + #ifdef TUNNEL_STATISTICS if(TS_request_bounces.find(item->request_id) != TS_request_bounces.end()) TS_request_bounces[item->request_id].push_back(time(NULL)) ; From c14d89890144e167daac2b8ce4587de84468ebda Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 25 Aug 2018 18:44:29 +0200 Subject: [PATCH 10/14] added some debug info to file control system and fixes a problem with sending TS --- .../src/file_sharing/file_sharing_defaults.h | 8 +- libretroshare/src/file_sharing/p3filelists.cc | 81 ++++++++++++++++--- libretroshare/src/file_sharing/p3filelists.h | 1 + libretroshare/src/gxs/rsgxsnettunnel.cc | 2 +- libretroshare/src/retroshare/rsfiles.h | 2 + libretroshare/src/turtle/p3turtle.cc | 2 - 6 files changed, 78 insertions(+), 18 deletions(-) diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index 77bdbb3ff..6633e348f 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -21,10 +21,10 @@ ******************************************************************************/ #pragma once -static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 600 ; // 10 minutes -static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 minutes -static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed. -static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec. +static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 600 ; // 10 minutes +static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 minutes +static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed. +static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec. static const uint32_t DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR = 60*24*86400 ; // delete non empty remoe directories after 60 days of inactivity static const uint32_t DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR = 5*24*86400 ; // delete empty remote directories after 5 days of inactivity diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index e1ddd059c..5e0d2cffc 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -37,6 +37,7 @@ #define P3FILELISTS_ERROR() std::cerr << "***ERROR***" << " : FILE_LISTS : " << __FUNCTION__ << " : " //#define DEBUG_P3FILELISTS 1 +#define DEBUG_CONTENT_FILTERING 1 static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ; @@ -73,6 +74,7 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers) mLastCleanupTime = 0 ; mLastDataRecvTS = 0 ; mTrustFriendNodesForBannedFiles = TRUST_FRIEND_NODES_FOR_BANNED_FILES_DEFAULT; + mLastPrimaryBanListChangeTimeStamp = 0; // This is for the transmission of data @@ -561,6 +563,7 @@ bool p3FileDatabase::loadList(std::list& load) { mPrimaryBanList = fb->primary_banned_files_list ; mBannedFilesChanged = true; + mLastPrimaryBanListChangeTimeStamp = time(NULL); } delete *it ; @@ -1891,19 +1894,27 @@ bool p3FileDatabase::locked_generateAndSendSyncRequest(RemoteDirectoryStorage *r bool p3FileDatabase::banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) { +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " setting file \"" << filename << "\" size=" << file_size << " hash=" << real_file_hash << " as banned." << std::endl; +#endif { RS_STACK_MUTEX(mFLSMtx) ; BannedFileEntry& entry(mPrimaryBanList[real_file_hash]) ; // primary list (user controlled) of files banned from FT search and forwarding. map - entry.filename = filename ; - entry.size = file_size ; - entry.ban_time_stamp = time(NULL); + if(entry.ban_time_stamp == 0) + { + 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) ; + RsFileHash hash_of_hash ; + ftServer::encryptHash(real_file_hash,hash_of_hash) ; - mBannedFileList.insert(real_file_hash) ; - mBannedFileList.insert(hash_of_hash) ; + mBannedFileList.insert(real_file_hash) ; + mBannedFileList.insert(hash_of_hash) ; + + mLastPrimaryBanListChangeTimeStamp = time(NULL); + } } IndicateConfigChanged(); @@ -1911,9 +1922,13 @@ bool p3FileDatabase::banFile(const RsFileHash& real_file_hash, const std::string } bool p3FileDatabase::unbanFile(const RsFileHash& real_file_hash) { +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " unbanning file with hash " << real_file_hash << std::endl; +#endif { RS_STACK_MUTEX(mFLSMtx) ; mPrimaryBanList.erase(real_file_hash) ; + mLastPrimaryBanListChangeTimeStamp = time(NULL); } IndicateConfigChanged(); @@ -1927,7 +1942,12 @@ bool p3FileDatabase::isFileBanned(const RsFileHash& hash) RsFileHash hash_of_hash ; ftServer::encryptHash(hash,hash_of_hash) ; - return mBannedFileList.find(hash) != mBannedFileList.end() || mBannedFileList.find(hash_of_hash) != mBannedFileList.end() ; + bool res = mBannedFileList.find(hash) != mBannedFileList.end() || mBannedFileList.find(hash_of_hash) != mBannedFileList.end() ; + +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " is file banned(" << hash << "): " << (res?"YES":"NO") << std::endl; +#endif + return res ; } bool p3FileDatabase::getPrimaryBannedFilesList(std::map& banned_files) @@ -1943,10 +1963,14 @@ bool p3FileDatabase::trustFriendNodesForBannedFiles() const RS_STACK_MUTEX(mFLSMtx) ; return mTrustFriendNodesForBannedFiles; } + void p3FileDatabase::setTrustFriendNodesForBannedFiles(bool b) { if(b != mTrustFriendNodesForBannedFiles) + { IndicateConfigChanged(); + mBannedFilesChanged = true; + } RS_STACK_MUTEX(mFLSMtx) ; mTrustFriendNodesForBannedFiles = b; @@ -1958,6 +1982,11 @@ void p3FileDatabase::checkSendBannedFilesInfo() // 1 - compare records to list of online friends, send own info of not already +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " Checking banned file list: " << std::endl; +#endif + + time_t now = time(NULL); std::list online_friends ; rsPeers->getOnlineList(online_friends); @@ -1970,13 +1999,19 @@ void p3FileDatabase::checkSendBannedFilesInfo() if(peers.find(it->first) == peers.end()) // friend not online, remove his record { it = mPeerBannedFiles.erase(it) ; +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " Peer " << it->first << " is offline: removign record." << std::endl; +#endif continue; } - if(it->second.mLastSent == 0) // has ban info already been sent? If not do it. + if(it->second.mLastSent < mLastPrimaryBanListChangeTimeStamp) // has ban info already been sent? If not do it. { +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " Peer " << it->first << " is online and hasn't been sent since last change: sending..." << std::endl; +#endif locked_sendBanInfo(it->first); - it->second.mLastSent = time(NULL); + it->second.mLastSent = now; } peers.erase(it->first); // friend has been handled -> remove from list @@ -1988,7 +2023,10 @@ void p3FileDatabase::checkSendBannedFilesInfo() for(auto it(peers.begin());it!=peers.end();++it) { locked_sendBanInfo(*it); - mPeerBannedFiles[*it].mLastSent = time(NULL); + mPeerBannedFiles[*it].mLastSent = now; +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " Peer " << *it << " is online and hasn't been sent info at all: sending..." << std::endl; +#endif } // 3 - update list of banned hashes if it has changed somehow @@ -1997,13 +2035,22 @@ void p3FileDatabase::checkSendBannedFilesInfo() { mBannedFileList.clear(); +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " Creating banned file list: " << std::endl; +#endif // Add all H(H(f)) from friends 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); +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " from " << it->first << ": H(H(f)) = " << *it2 << std::endl; +#endif + } + // Add H(f) and H(H(f)) from our primary list for(auto it(mPrimaryBanList.begin());it!=mPrimaryBanList.end();++it) @@ -2014,6 +2061,10 @@ void p3FileDatabase::checkSendBannedFilesInfo() ftServer::encryptHash(it->first,hash_of_hash) ; mBannedFileList.insert(hash_of_hash) ; + +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " primary: H(f) = " << it->first << ": H(H(f)) = " << hash_of_hash << std::endl; +#endif } mBannedFilesChanged = false ; @@ -2056,6 +2107,9 @@ void p3FileDatabase::handleBannedFilesInfo(RsFileListsBannedHashesItem *item) { RS_STACK_MUTEX(mFLSMtx) ; +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " received banned files info from peer " << item->PeerId() << ", session id = " << std::hex << item->session_id << std::dec << ": " << item->encrypted_hashes.size() << " files:" << std::endl; +#endif // 1 - localize the friend in the banned file map PeerBannedFilesEntry& pbfe(mPeerBannedFiles[item->PeerId()]) ; @@ -2068,7 +2122,12 @@ void p3FileDatabase::handleBannedFilesInfo(RsFileListsBannedHashesItem *item) // 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); +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " added H(H(f)) = " << *it << std::endl; +#endif + } // 3 - tell the updater that the banned file list has changed diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index c58c9989a..0c9424c2f 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -270,6 +270,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub std::set mBannedFileList ; // list of banned hashes. This include original hashs and H(H(f)) when coming from friends. bool mTrustFriendNodesForBannedFiles ; bool mBannedFilesChanged; + time_t mLastPrimaryBanListChangeTimeStamp; void locked_sendBanInfo(const RsPeerId& pid); void handleBannedFilesInfo(RsFileListsBannedHashesItem *item); diff --git a/libretroshare/src/gxs/rsgxsnettunnel.cc b/libretroshare/src/gxs/rsgxsnettunnel.cc index bbe10694b..026ba822b 100644 --- a/libretroshare/src/gxs/rsgxsnettunnel.cc +++ b/libretroshare/src/gxs/rsgxsnettunnel.cc @@ -30,7 +30,7 @@ #include "gxs/rsnxs.h" #include "rsgxsnettunnel.h" -#define DEBUG_RSGXSNETTUNNEL 1 +// #define DEBUG_RSGXSNETTUNNEL 1 #define GXS_NET_TUNNEL_NOT_IMPLEMENTED() { std::cerr << __PRETTY_FUNCTION__ << ": not yet implemented." << std::endl; } #define GXS_NET_TUNNEL_DEBUG() std::cerr << time(NULL) << " : GXS_NET_TUNNEL: " << __FUNCTION__ << " : " diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 918f1ab2f..e516bea27 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -164,6 +164,8 @@ public: struct BannedFileEntry { + BannedFileEntry() : size(0),filename(""),ban_time_stamp(0) {} + uint64_t size ; std::string filename ; time_t ban_time_stamp; diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 36b4383a9..112363ea9 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1550,9 +1550,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) if(rsFiles->isHashBanned(item->file_hash)) { -#ifdef P3TURTLE_DEBUG std::cerr << "(II) Rejecting tunnel request to ban hash " << item->file_hash << std::endl; -#endif return ; } From b5eabf7af7ae7c97df188dcb53665ecf4560c3d4 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 25 Aug 2018 20:18:54 +0200 Subject: [PATCH 11/14] improved banned files UI and fixed deadlock --- libretroshare/src/file_sharing/p3filelists.cc | 20 +++++++++++++------ .../src/gui/FileTransfer/BannedFilesDialog.ui | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 5e0d2cffc..87f03f05a 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -185,15 +185,19 @@ int p3FileDatabase::tick() if(last_print_time + 20 < now) { - RS_STACK_MUTEX(mFLSMtx) ; + { + RS_STACK_MUTEX(mFLSMtx) ; #ifdef DEBUG_FILE_HIERARCHY - mLocalSharedDirs->print(); + mLocalSharedDirs->print(); #endif - last_print_time = now ; + last_print_time = now ; + } #warning mr-alice 2016-08-19: "This should be removed, but it's necessary atm for updating the GUI" RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + + checkSendBannedFilesInfo(); } if(mUpdateFlags) @@ -1939,13 +1943,17 @@ bool p3FileDatabase::isFileBanned(const RsFileHash& hash) { RS_STACK_MUTEX(mFLSMtx) ; + if(mBannedFileList.empty()) // quick exit + return false ; + RsFileHash hash_of_hash ; ftServer::encryptHash(hash,hash_of_hash) ; bool res = mBannedFileList.find(hash) != mBannedFileList.end() || mBannedFileList.find(hash_of_hash) != mBannedFileList.end() ; #ifdef DEBUG_CONTENT_FILTERING - P3FILELISTS_DEBUG() << " is file banned(" << hash << "): " << (res?"YES":"NO") << std::endl; + if(res) + P3FILELISTS_DEBUG() << " is file banned(" << hash << "): " << (res?"YES":"NO") << std::endl; #endif return res ; } @@ -2014,7 +2022,7 @@ void p3FileDatabase::checkSendBannedFilesInfo() it->second.mLastSent = now; } - peers.erase(it->first); // friend has been handled -> remove from list + peers.erase(it->first); // friend has been handled -> remove from list ++it; } @@ -2084,7 +2092,7 @@ void p3FileDatabase::locked_sendBanInfo(const RsPeerId& peer) if(!item) { - RsFileListsBannedHashesItem *item = new RsFileListsBannedHashesItem ; + item = new RsFileListsBannedHashesItem ; item->PeerId(peer); item->session_id = session_id ; diff --git a/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui b/retroshare-gui/src/gui/FileTransfer/BannedFilesDialog.ui index ff7deec7f..78d81df79 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 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> + <html><head/><body><p><span style=" font-weight:600;">Collaborative file control</span>: the list below contains files you choose to ban from your <span style=" font-weight:600;">local</span> network: you will not forward search results nor 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;. This feature cannot globally hide a file unless a signficant proportion of users in the same network decide to ban it.</p></body></html> Qt::AlignJustify|Qt::AlignVCenter From 2fab33d37f73f160c10e04e3eaa7014d106f7a27 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 25 Aug 2018 20:52:06 +0200 Subject: [PATCH 12/14] fixed a few bugs in ban file list management --- libretroshare/src/file_sharing/p3filelists.cc | 25 +++++++++++++------ libretroshare/src/file_sharing/p3filelists.h | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 87f03f05a..156490e18 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -566,7 +566,7 @@ bool p3FileDatabase::loadList(std::list& load) if(fb) { mPrimaryBanList = fb->primary_banned_files_list ; - mBannedFilesChanged = true; + mBannedFileListNeedsUpdate = true; mLastPrimaryBanListChangeTimeStamp = time(NULL); } @@ -1918,6 +1918,7 @@ bool p3FileDatabase::banFile(const RsFileHash& real_file_hash, const std::string mBannedFileList.insert(hash_of_hash) ; mLastPrimaryBanListChangeTimeStamp = time(NULL); + mBannedFileListNeedsUpdate = true ; } } @@ -1933,6 +1934,7 @@ bool p3FileDatabase::unbanFile(const RsFileHash& real_file_hash) RS_STACK_MUTEX(mFLSMtx) ; mPrimaryBanList.erase(real_file_hash) ; mLastPrimaryBanListChangeTimeStamp = time(NULL); + mBannedFileListNeedsUpdate = true ; } IndicateConfigChanged(); @@ -1977,7 +1979,7 @@ void p3FileDatabase::setTrustFriendNodesForBannedFiles(bool b) if(b != mTrustFriendNodesForBannedFiles) { IndicateConfigChanged(); - mBannedFilesChanged = true; + mBannedFileListNeedsUpdate = true; } RS_STACK_MUTEX(mFLSMtx) ; @@ -1991,7 +1993,7 @@ void p3FileDatabase::checkSendBannedFilesInfo() // 1 - compare records to list of online friends, send own info of not already #ifdef DEBUG_CONTENT_FILTERING - P3FILELISTS_DEBUG() << " Checking banned file list: " << std::endl; + P3FILELISTS_DEBUG() << " Checking banned files information: " << std::endl; #endif time_t now = time(NULL); @@ -2039,12 +2041,12 @@ void p3FileDatabase::checkSendBannedFilesInfo() // 3 - update list of banned hashes if it has changed somehow - if(mBannedFilesChanged) + if(mBannedFileListNeedsUpdate) { mBannedFileList.clear(); #ifdef DEBUG_CONTENT_FILTERING - P3FILELISTS_DEBUG() << " Creating banned file list: " << std::endl; + P3FILELISTS_DEBUG() << " Creating local banned file list: " << std::endl; #endif // Add all H(H(f)) from friends @@ -2075,15 +2077,22 @@ void p3FileDatabase::checkSendBannedFilesInfo() #endif } - mBannedFilesChanged = false ; + mBannedFileListNeedsUpdate = false ; } + +#ifdef DEBUG_CONTENT_FILTERING + P3FILELISTS_DEBUG() << " Final list of locally banned hashes contains: " << mBannedFileList.size() << " elements." << std::endl; +#endif } void p3FileDatabase::locked_sendBanInfo(const RsPeerId& peer) { - RsFileListsBannedHashesItem *item = NULL; + RsFileListsBannedHashesItem *item = new RsFileListsBannedHashesItem ; uint32_t session_id = RSRandom::random_u32(); + item->session_id = session_id ; + item->PeerId(peer); + for(auto it(mPrimaryBanList.begin());it!=mPrimaryBanList.end();++it) { RsFileHash hash_of_hash ; @@ -2139,6 +2148,6 @@ void p3FileDatabase::handleBannedFilesInfo(RsFileListsBannedHashesItem *item) // 3 - tell the updater that the banned file list has changed - mBannedFilesChanged = true ; + mBannedFileListNeedsUpdate = true ; } diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 0c9424c2f..a8ac377ea 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -269,7 +269,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub 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; + bool mBannedFileListNeedsUpdate; time_t mLastPrimaryBanListChangeTimeStamp; void locked_sendBanInfo(const RsPeerId& pid); From b09eb57e947ebffefbba3757dedbbdfce6474cf3 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 28 Aug 2018 23:16:35 +0200 Subject: [PATCH 13/14] fixed small bug in deletion of banned file --- retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index f017529b1..1c0ae3256 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -445,6 +445,9 @@ void SearchDialog::ban() rsFiles -> banFile( hash, (item->text(SR_NAME_COL)).toUtf8().constData() , (item->text(SR_SIZE_COL)).toULongLong()); + while(item->parent() != NULL) + item = item->parent(); + ui.searchResultWidget->takeTopLevelItem(ui.searchResultWidget->indexOfTopLevelItem(item)) ; } } From 65304a301a5b10bdcc53f1f97e3862664a804931 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 28 Aug 2018 23:57:16 +0200 Subject: [PATCH 14/14] added last relay (a.k.a which direct friend) of search results in sources column --- libresapi/src/api/FileSearchHandler.cpp | 2 +- libresapi/src/api/FileSearchHandler.h | 2 +- libretroshare/src/pqi/p3notify.cc | 2 +- libretroshare/src/pqi/p3notify.h | 2 +- libretroshare/src/retroshare/rsnotify.h | 2 +- retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp | 7 ++++--- retroshare-gui/src/gui/notifyqt.cpp | 4 ++-- retroshare-gui/src/gui/notifyqt.h | 2 +- retroshare-nogui/src/notifytxt.cc | 2 +- retroshare-nogui/src/notifytxt.h | 2 +- 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libresapi/src/api/FileSearchHandler.cpp b/libresapi/src/api/FileSearchHandler.cpp index 73e7848f0..c768b1112 100644 --- a/libresapi/src/api/FileSearchHandler.cpp +++ b/libresapi/src/api/FileSearchHandler.cpp @@ -50,7 +50,7 @@ FileSearchHandler::~FileSearchHandler() mStateTokenServer->discardToken(mSearchesStateToken); } -void FileSearchHandler::notifyTurtleSearchResult(uint32_t search_id, const std::list& files) +void FileSearchHandler::notifyTurtleSearchResult(const RsPeerId& pid,uint32_t search_id, const std::list& files) { RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** std::map::iterator mit = mSearches.find(search_id); diff --git a/libresapi/src/api/FileSearchHandler.h b/libresapi/src/api/FileSearchHandler.h index d4b3c31cf..66b79209c 100644 --- a/libresapi/src/api/FileSearchHandler.h +++ b/libresapi/src/api/FileSearchHandler.h @@ -37,7 +37,7 @@ public: virtual ~FileSearchHandler(); // from NotifyClient - virtual void notifyTurtleSearchResult(uint32_t search_id, const std::list& files); + virtual void notifyTurtleSearchResult(const RsPeerId &pid, uint32_t search_id, const std::list& files); private: void handleWildcard(Request& req, Response& resp); void handleCreateSearch(Request& req, Response& resp); diff --git a/libretroshare/src/pqi/p3notify.cc b/libretroshare/src/pqi/p3notify.cc index 8616a0957..2ffd3c5cd 100644 --- a/libretroshare/src/pqi/p3notify.cc +++ b/libretroshare/src/pqi/p3notify.cc @@ -225,7 +225,7 @@ void p3Notify::notifyChatCleared (const ChatId& chat_id) void p3Notify::notifyChatLobbyTimeShift (int time_shift) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatLobbyTimeShift(time_shift) ; } void p3Notify::notifyCustomState (const std::string& peer_id , const std::string& status_string ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyCustomState (peer_id,status_string) ; } void p3Notify::notifyHashingInfo (uint32_t type , const std::string& fileinfo ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHashingInfo (type,fileinfo) ; } -void p3Notify::notifyTurtleSearchResult (uint32_t search_id , const std::list& files ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(search_id,files) ; } +void p3Notify::notifyTurtleSearchResult (const RsPeerId& pid , uint32_t search_id , const std::list& files ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(pid,search_id,files) ; } #warning MISSING CODE HERE //void p3Notify::notifyTurtleSearchResult (uint32_t search_id , const std::list& groups ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(search_id,groups) ; } void p3Notify::notifyPeerHasNewAvatar (std::string peer_id ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerHasNewAvatar(peer_id) ; } diff --git a/libretroshare/src/pqi/p3notify.h b/libretroshare/src/pqi/p3notify.h index 7cc66d826..d288091c3 100644 --- a/libretroshare/src/pqi/p3notify.h +++ b/libretroshare/src/pqi/p3notify.h @@ -101,7 +101,7 @@ class p3Notify: public RsNotify void notifyChatLobbyTimeShift (int /* time_shift*/) ; void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) ; void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) ; - void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list& /* files */) ; + void notifyTurtleSearchResult (const RsPeerId &pid, uint32_t /* search_id */, const std::list& /* files */) ; #warning MISSING CODE HERE // void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list& /* groups */) ; void notifyPeerHasNewAvatar (std::string /* peer_id */) ; diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index a418cb958..cf7777e9e 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -222,7 +222,7 @@ public: virtual void notifyChatLobbyTimeShift (int /* time_shift*/) {} virtual void notifyCustomState (const std::string& /* peer_id */, const std::string& /* status_string */) {} virtual void notifyHashingInfo (uint32_t /* type */, const std::string& /* fileinfo */) {} - virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list& /* files */) {} + virtual void notifyTurtleSearchResult (const RsPeerId& /* pid */, uint32_t /* search_id */, const std::list& /* files */) {} #warning MISSING CODE HERE // virtual void notifyTurtleSearchResult (uint32_t /* search_id */, const std::list& /* groups */) {} virtual void notifyPeerHasNewAvatar (std::string /* peer_id */) {} diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index 1c0ae3256..20e5157da 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -977,9 +977,7 @@ void SearchDialog::processResultQueue() while(!searchResultsQueue.empty() && nb_treated_elements++ < 250) { qulonglong search_id = searchResultsQueue.back().first ; - FileDetail file = searchResultsQueue.back().second ; - - searchResultsQueue.pop_back() ; + FileDetail& file = searchResultsQueue.back().second ; #ifdef DEBUG std::cout << "Updating file detail:" << std::endl ; @@ -989,6 +987,8 @@ void SearchDialog::processResultQueue() #endif insertFile(search_id,file); + + searchResultsQueue.pop_back() ; } ui.searchResultWidget->setSortingEnabled(true); if(!searchResultsQueue.empty()) @@ -1323,6 +1323,7 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s modifiedResult =QString::number(friendSource) + "/" + QString::number(anonymousSource); float fltRes = friendSource + (float)anonymousSource/1000; item->setText(SR_SOURCES_COL,modifiedResult); + item->setToolTip(SR_SOURCES_COL, tr("Obtained via ")+QString::fromStdString(rsPeers->getPeerName(file.id)) ); item->setData(SR_SOURCES_COL, ROLE_SORT, fltRes); item->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight ); item->setText(SR_SEARCH_ID_COL, sid_hexa); diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index da8dac48d..fa7bb4c82 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -568,7 +568,7 @@ void NotifyQt::notifyTurtleSearchResult(uint32_t search_id,const std::list& files) +void NotifyQt::notifyTurtleSearchResult(const RsPeerId& pid,uint32_t search_id,const std::list& files) { { QMutexLocker m(&_mutex) ; @@ -588,7 +588,7 @@ void NotifyQt::notifyTurtleSearchResult(uint32_t search_id,const std::list& found_files); + virtual void notifyTurtleSearchResult(const RsPeerId &pid, uint32_t search_id, const std::list& found_files); virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list& found_groups); virtual void notifyPeerHasNewAvatar(std::string peer_id) ; virtual void notifyOwnAvatarChanged() ; diff --git a/retroshare-nogui/src/notifytxt.cc b/retroshare-nogui/src/notifytxt.cc index 18212b17e..d6d4741c4 100644 --- a/retroshare-nogui/src/notifytxt.cc +++ b/retroshare-nogui/src/notifytxt.cc @@ -219,7 +219,7 @@ void NotifyTxt::displayTransfers() /******************* Turtle Search Interface **********/ -void NotifyTxt::notifyTurtleSearchResult(uint32_t search_id,const std::list& found_files) +void NotifyTxt::notifyTurtleSearchResult(const RsPeerId &pid, uint32_t search_id, const std::list& found_files) { // std::cerr << "NotifyTxt::notifyTurtleSearchResult() " << found_files.size(); // std::cerr << " new results for Id: " << search_id; diff --git a/retroshare-nogui/src/notifytxt.h b/retroshare-nogui/src/notifytxt.h index 508bfd7fd..17dcbc409 100644 --- a/retroshare-nogui/src/notifytxt.h +++ b/retroshare-nogui/src/notifytxt.h @@ -44,7 +44,7 @@ class NotifyTxt: public NotifyClient virtual bool askForPassword(const std::string& title, const std::string& question, bool prev_is_bad, std::string& password,bool& cancel); virtual bool askForPluginConfirmation(const std::string& plugin_file, const std::string& plugin_hash,bool first_time); - virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list& found_files); + virtual void notifyTurtleSearchResult(const RsPeerId& pid,uint32_t search_id,const std::list& found_files); /* interface for handling SearchResults */ void getSearchIds(std::list &searchIds);