added to parameters in options to fix the time banned ids are kept in list and prevented to re-download

This commit is contained in:
csoler 2017-01-12 20:39:49 +01:00
parent a7f0fff0f1
commit bd7f6aca99
8 changed files with 168 additions and 9 deletions

View file

@ -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,

View file

@ -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

View file

@ -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<RsPgpId,BannedNodeInfo>::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<RsItem*> &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<RsItem *>& 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);

View file

@ -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 ;

View file

@ -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<RsItem*>& items)
mContacts = lii->mContacts ;
}
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
if(vitem)
for(std::list<RsTlvKeyValue>::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<RsItem*>& 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<RsItem*>& items)
{
#ifdef DEBUG_IDS
@ -343,13 +378,23 @@ bool p3IdService::saveList(bool& cleanup,std::list<RsItem*>& 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<RsGxsId,p3IdService::keyTSInfo>& last_usage_TSs) : mLastUsageTS(last_usage_TSs) {}
IdCacheEntryCleaner(const std::map<RsGxsId,p3IdService::keyTSInfo>& 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<RsGxsId> ids_to_delete ;
const std::map<RsGxsId,p3IdService::keyTSInfo>& 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);

View file

@ -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