diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index d6f0670f7..ac0bcdf53 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -289,6 +289,9 @@ public: virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0; virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0; + virtual void setDeleteBannedNodesThreshold(uint32_t days) =0; + virtual uint32_t deleteBannedNodesThreshold() =0; + virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname, const std::string &tag, RsRecognTagDetails &details) = 0; virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment, diff --git a/libretroshare/src/retroshare/rsreputations.h b/libretroshare/src/retroshare/rsreputations.h index 811806f4f..c8ff572db 100644 --- a/libretroshare/src/retroshare/rsreputations.h +++ b/libretroshare/src/retroshare/rsreputations.h @@ -74,6 +74,9 @@ public: virtual void setThresholdForRemotelyNegativeReputation(uint32_t thresh)=0; virtual void setThresholdForRemotelyPositiveReputation(uint32_t thresh)=0; + virtual void setRememberDeletedNodesThreshold(uint32_t days) =0; + virtual uint32_t rememberDeletedNodesThreshold() =0; + // This one is a proxy designed to allow fast checking of a GXS id. // it basically returns true if assessment is not ASSESSMENT_OK diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index 86d00d1f5..a026e8d0d 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -139,8 +139,8 @@ static const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ; // reputat static const uint32_t PGP_AUTO_BAN_THRESHOLD_DEFAULT = 2 ; // above this, auto ban any GXS id signed by this node static const uint32_t IDENTITY_FLAGS_UPDATE_DELAY = 100 ; // static const uint32_t BANNED_NODES_UPDATE_DELAY = 313 ; // update approx every 5 mins. Chosen to not be a multiple of IDENTITY_FLAGS_UPDATE_DELAY -static const uint32_t REPUTATION_INFO_KEEP_DELAY = 86400*35; // remove old reputation info 5 days after last usage limit, in case the ID would come back.. -static const uint32_t BANNED_NODES_INACTIVITY_KEEP = 86400*60; // remove all info about banned nodes after 2 months of inactivity +static const uint32_t REPUTATION_INFO_KEEP_DELAY_DEFAULT = 86400*35; // remove old reputation info 5 days after last usage limit, in case the ID would come back.. +static const uint32_t BANNED_NODES_INACTIVITY_KEEP_DEFAULT = 86400*60; // remove all info about banned nodes after 2 months of inactivity static const uint32_t REPUTATION_DEFAULT_MIN_VOTES_FOR_REMOTELY_POSITIVE = 1; // min difference in votes that makes friends opinion globally positive static const uint32_t REPUTATION_DEFAULT_MIN_VOTES_FOR_REMOTELY_NEGATIVE = 1; // min difference in votes that makes friends opinion globally negative @@ -257,6 +257,23 @@ bool p3GxsReputation::nodeAutoPositiveOpinionForContacts() return mAutoSetPositiveOptionToContacts ; } +void p3GxsReputation::setRememberDeletedNodesThreshold(uint32_t days) +{ + RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/ + + if(mMaxPreventReloadBannedIds != days/86400) + { + mMaxPreventReloadBannedIds = days/86400 ; + IndicateConfigChanged(); + } +} +uint32_t p3GxsReputation::rememberDeletedNodesThreshold() +{ + RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/ + + return mMaxPreventReloadBannedIds/86400; +} + int p3GxsReputation::status() { return 1; @@ -379,10 +396,10 @@ void p3GxsReputation::cleanup() // Delete slots that havn't been used for a while. The else below is here for debug display purposes, and not harmful since both conditions lead the same effect. - else if(it->second.mLastUsedTS + REPUTATION_INFO_KEEP_DELAY < now) + else if(it->second.mLastUsedTS + REPUTATION_INFO_KEEP_DELAY_DEFAULT < now) { #ifdef DEBUG_REPUTATION - std::cerr << " ID " << it->first << ": no request for reputation for more than " << REPUTATION_INFO_KEEP_DELAY/86400 << " days => deleting." << std::endl; + std::cerr << " ID " << it->first << ": no request for reputation for more than " << REPUTATION_INFO_KEEP_DELAY_DEFAULT/86400 << " days => deleting." << std::endl; #endif should_delete = true ; } @@ -410,7 +427,7 @@ void p3GxsReputation::cleanup() RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/ for(std::map::iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();) - if(it->second.last_activity_TS + BANNED_NODES_INACTIVITY_KEEP < now) + if(it->second.last_activity_TS + BANNED_NODES_INACTIVITY_KEEP_DEFAULT < now) { #ifdef DEBUG_REPUTATION std::cerr << " Removing all info about banned node " << it->first << " by lack of activity." << std::endl; @@ -1084,6 +1101,10 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list &savelist) kv.value = mAutoSetPositiveOptionToContacts?"YES":"NO"; vitem->tlvkvs.pairs.push_back(kv) ; + kv.key = "MAX_PREVENT_RELOAD_BANNED_IDS" ; + rs_sprintf(kv.value, "%d", mMaxPreventReloadBannedIds) ; + vitem->tlvkvs.pairs.push_back(kv) ; + savelist.push_back(vitem) ; return true; @@ -1170,6 +1191,15 @@ bool p3GxsReputation::loadList(std::list& loadList) std::cerr << "Setting AutoPositiveContacts to " << kit->value << std::endl ; mLastBannedNodesUpdate = 0 ; // force update } + if(kit->key == "MAX_PREVENT_RELOAD_BANNED_IDS" ) + { + int val ; + if (sscanf(kit->value.c_str(), "%d", &val) == 1) + { + mMaxPreventReloadBannedIds = val ; + std::cerr << "Setting mMaxPreventReloadBannedIds threshold to " << val << std::endl ; + } + } } delete (*it); diff --git a/libretroshare/src/services/p3gxsreputation.h b/libretroshare/src/services/p3gxsreputation.h index e6d4ac11d..e6b6c7f66 100644 --- a/libretroshare/src/services/p3gxsreputation.h +++ b/libretroshare/src/services/p3gxsreputation.h @@ -119,6 +119,9 @@ public: virtual void setNodeAutoPositiveOpinionForContacts(bool b) ; virtual bool nodeAutoPositiveOpinionForContacts() ; + virtual void setRememberDeletedNodesThreshold(uint32_t days) ; + virtual uint32_t rememberDeletedNodesThreshold() ; + uint32_t thresholdForRemotelyNegativeReputation(); uint32_t thresholdForRemotelyPositiveReputation(); void setThresholdForRemotelyNegativeReputation(uint32_t thresh); @@ -186,6 +189,7 @@ private: uint32_t mMinVotesForRemotelyPositive ; uint32_t mMinVotesForRemotelyNegative ; + uint32_t mMaxPreventReloadBannedIds ; bool mChanged ; // slow version of IndicateConfigChanged(); time_t mLastReputationConfigSaved ; diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 8ee7f51fb..323a49ae2 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -62,7 +62,8 @@ // unused keys are deleted according to some heuristic that should favor known keys, signed keys etc. -static const time_t MAX_KEEP_KEYS_BANNED = 2 * 86400 ; // get rid of banned ids after 1 days. That gives a chance to un-ban someone before he gets definitely kicked out +static const time_t MAX_KEEP_KEYS_BANNED_DEFAULT = 2 * 86400 ; // get rid of banned ids after 1 days. That gives a chance to un-ban someone before he gets definitely kicked out + static const time_t MAX_KEEP_KEYS_DEFAULT = 5 * 86400 ; // default for unsigned identities: 5 days static const time_t MAX_KEEP_KEYS_SIGNED = 8 * 86400 ; // signed identities by unknown key static const time_t MAX_KEEP_KEYS_SIGNED_KNOWN = 30 * 86400 ; // signed identities by known node keys @@ -164,6 +165,7 @@ p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *ne mLastKeyCleaningTime = time(NULL) - int(MAX_DELAY_BEFORE_CLEANING * 0.9) ; mLastConfigUpdate = 0 ; mOwnIdsLoaded = false ; + mMaxKeepKeysBanned = MAX_KEEP_KEYS_BANNED_DEFAULT; // Kick off Cache Testing, + Others. RsTickEvent::schedule_in(GXSID_EVENT_PGPHASH, PGPHASH_PERIOD); @@ -320,6 +322,22 @@ bool p3IdService::loadList(std::list& items) mContacts = lii->mContacts ; } + RsConfigKeyValueSet *vitem = dynamic_cast(*it); + + if(vitem) + for(std::list::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) + { + if(kit->key == "REMOVE_BANNED_IDENTITIES_DELAY") + { + int val ; + if (sscanf(kit->value.c_str(), "%d", &val) == 1) + { + mMaxKeepKeysBanned = val ; + std::cerr << "Setting mMaxKeepKeysBanned threshold to " << val << std::endl ; + } + }; + } + delete *it ; } @@ -327,6 +345,23 @@ bool p3IdService::loadList(std::list& items) return true ; } +void p3IdService::setDeleteBannedNodesThreshold(uint32_t days) +{ + RsStackMutex stack(mIdMtx); /****** LOCKED MUTEX *******/ + if(mMaxKeepKeysBanned != days*86400) + { + mMaxKeepKeysBanned = days*86400 ; + IndicateConfigChanged(); + } +} +uint32_t p3IdService::deleteBannedNodesThreshold() +{ + RsStackMutex stack(mIdMtx); /****** LOCKED MUTEX *******/ + + return mMaxKeepKeysBanned/86400; +} + + bool p3IdService::saveList(bool& cleanup,std::list& items) { #ifdef DEBUG_IDS @@ -343,13 +378,23 @@ bool p3IdService::saveList(bool& cleanup,std::list& items) item->mContacts = mContacts ; items.push_back(item) ; + + RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; + RsTlvKeyValue kv; + + kv.key = "REMOVE_BANNED_IDENTITIES_DELAY" ; + rs_sprintf(kv.value, "%d", mMaxKeepKeysBanned); + vitem->tlvkvs.pairs.push_back(kv) ; + + items.push_back(vitem) ; + return true ; } class IdCacheEntryCleaner { public: - IdCacheEntryCleaner(const std::map& last_usage_TSs) : mLastUsageTS(last_usage_TSs) {} + IdCacheEntryCleaner(const std::map& last_usage_TSs,uint32_t m) : mLastUsageTS(last_usage_TSs),mMaxKeepKeysBanned(m) {} bool processEntry(RsGxsIdCache& entry) { @@ -380,7 +425,7 @@ public: if(no_ts) max_keep_time = 0 ; else if(is_id_banned) - max_keep_time = MAX_KEEP_KEYS_BANNED ; + max_keep_time = mMaxKeepKeysBanned ; else if(is_known_id) max_keep_time = MAX_KEEP_KEYS_SIGNED_KNOWN ; else if(is_signed_id) @@ -403,6 +448,7 @@ public: std::list ids_to_delete ; const std::map& mLastUsageTS; + uint32_t mMaxKeepKeysBanned ; }; void p3IdService::cleanUnusedKeys() @@ -422,7 +468,7 @@ void p3IdService::cleanUnusedKeys() } // grab at most 10 identities to delete. No need to send too many requests to the token queue at once. - IdCacheEntryCleaner idcec(mKeysTS) ; + IdCacheEntryCleaner idcec(mKeysTS,mMaxKeepKeysBanned) ; mKeyCache.applyToAllCachedEntries(idcec,&IdCacheEntryCleaner::processEntry); diff --git a/libretroshare/src/services/p3idservice.h b/libretroshare/src/services/p3idservice.h index e9e6ed9d5..addff0d1b 100644 --- a/libretroshare/src/services/p3idservice.h +++ b/libretroshare/src/services/p3idservice.h @@ -266,6 +266,9 @@ public: virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group); virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group); + virtual void setDeleteBannedNodesThreshold(uint32_t days) ; + virtual uint32_t deleteBannedNodesThreshold() ; + virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname, const std::string &tag, RsRecognTagDetails &details); virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment, @@ -536,6 +539,7 @@ private: time_t mLastConfigUpdate ; bool mOwnIdsLoaded ; + uint32_t mMaxKeepKeysBanned ; }; #endif // P3_IDENTITY_SERVICE_HEADER diff --git a/retroshare-gui/src/gui/settings/PeoplePage.cpp b/retroshare-gui/src/gui/settings/PeoplePage.cpp index 9a52cdb35..66265f4de 100644 --- a/retroshare-gui/src/gui/settings/PeoplePage.cpp +++ b/retroshare-gui/src/gui/settings/PeoplePage.cpp @@ -22,6 +22,7 @@ #include "PeoplePage.h" #include "rsharesettings.h" #include "retroshare/rsreputations.h" +#include "retroshare/rsidentity.h" PeoplePage::PeoplePage(QWidget * parent, Qt::WindowFlags flags) : ConfigPage(parent, flags) @@ -44,6 +45,8 @@ bool PeoplePage::save(QString &/*errmsg*/) rsReputations->setThresholdForRemotelyPositiveReputation(ui.thresholdForPositive_SB->value()); rsReputations->setThresholdForRemotelyNegativeReputation(ui.thresholdForNegative_SB->value()); + rsReputations->setRememberDeletedNodesThreshold(ui.preventReloadingBannedIdentitiesFor_SB->value()); + rsIdentity->setDeleteBannedNodesThreshold(ui.deleteBannedIdentitiesAfter_SB->value()); return true; } @@ -58,4 +61,6 @@ void PeoplePage::load() ui.autoPositiveOpinion_CB->setChecked(auto_positive_contacts); ui.thresholdForPositive_SB->setValue(threshold_for_positive); ui.thresholdForNegative_SB->setValue(threshold_for_negative); + ui.deleteBannedIdentitiesAfter_SB->setValue(rsIdentity->deleteBannedNodesThreshold()); + ui.preventReloadingBannedIdentitiesFor_SB->setValue(rsReputations->rememberDeletedNodesThreshold()); } diff --git a/retroshare-gui/src/gui/settings/PeoplePage.ui b/retroshare-gui/src/gui/settings/PeoplePage.ui index 133634c0c..301b3a151 100644 --- a/retroshare-gui/src/gui/settings/PeoplePage.ui +++ b/retroshare-gui/src/gui/settings/PeoplePage.ui @@ -34,9 +34,15 @@ + + Qt::RightToLeft + Difference in votes to make friends globally negative: + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -67,9 +73,67 @@ + + Qt::RightToLeft + Difference in votes to make friends globally positive: + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::RightToLeft + + + Delete banned identities after: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::RightToLeft + + + Prevent re-loading previously banned identities for: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + days + + + 1 + + + 5 + + + + + + + days + + + 1 + + + 60 +