added two new options to people page for handlign reputations: change the ban limit from friend opinions, and allow to auto-set positive opinions to contacts

This commit is contained in:
csoler 2016-07-25 15:45:49 -04:00
parent efd503e7d4
commit 218977170c
5 changed files with 229 additions and 86 deletions

View File

@ -51,8 +51,15 @@ public:
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0; virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0;
virtual bool getReputationInfo(const RsGxsId& id,const RsPgpId& owner_id,ReputationInfo& info) =0 ; virtual bool getReputationInfo(const RsGxsId& id,const RsPgpId& owner_id,ReputationInfo& info) =0 ;
// parameters
virtual void setNodeAutoBanThreshold(uint32_t n) =0; virtual void setNodeAutoBanThreshold(uint32_t n) =0;
virtual uint32_t nodeAutoBanThreshold() =0; virtual uint32_t nodeAutoBanThreshold() =0;
virtual void setNodeAutoPositiveOpinionForContacts(bool b) =0;
virtual bool nodeAutoPositiveOpinionForContacts() =0;
virtual float nodeAutoBanIdentitiesLimit() =0;
virtual void setNodeAutoBanIdentitiesLimit(float f) =0;
// This one is a proxy designed to allow fast checking of a GXS id. // This one is a proxy designed to allow fast checking of a GXS id.
// it basically returns true if assessment is not ASSESSMENT_OK // it basically returns true if assessment is not ASSESSMENT_OK

View File

@ -134,7 +134,7 @@ static const int ACTIVE_FRIENDS_UPDATE_PERIOD = 600 ; // 10 minu
static const int ACTIVE_FRIENDS_ONLINE_DELAY = 86400*7 ; // 1 week. static const int ACTIVE_FRIENDS_ONLINE_DELAY = 86400*7 ; // 1 week.
static const int kReputationRequestPeriod = 600; // 10 mins static const int kReputationRequestPeriod = 600; // 10 mins
static const int kReputationStoreWait = 180; // 3 minutes. static const int kReputationStoreWait = 180; // 3 minutes.
static const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ; // reputation under which the peer gets killed static const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ; // reputation under which the peer gets killed. Warning there's a 1 shift with what's shown in GUI. Be careful.
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 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 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 BANNED_NODES_UPDATE_DELAY = 313 ; // update approx every 5 mins. Chosen to not be a multiple of IDENTITY_FLAGS_UPDATE_DELAY
@ -153,6 +153,9 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
mLastActiveFriendsUpdate = time(NULL) - 0.5*ACTIVE_FRIENDS_UPDATE_PERIOD; // avoids doing it too soon since the TS from rsIdentity needs to be loaded already mLastActiveFriendsUpdate = time(NULL) - 0.5*ACTIVE_FRIENDS_UPDATE_PERIOD; // avoids doing it too soon since the TS from rsIdentity needs to be loaded already
mAverageActiveFriends = 0 ; mAverageActiveFriends = 0 ;
mLastBannedNodesUpdate = 0 ; mLastBannedNodesUpdate = 0 ;
mAutoBanIdentitiesLimit = REPUTATION_ASSESSMENT_THRESHOLD_X1;
mAutoSetPositiveOptionToContacts = true; // default
} }
const std::string GXS_REPUTATION_APP_NAME = "gxsreputation"; const std::string GXS_REPUTATION_APP_NAME = "gxsreputation";
@ -232,6 +235,44 @@ uint32_t p3GxsReputation::nodeAutoBanThreshold()
return mPgpAutoBanThreshold ; return mPgpAutoBanThreshold ;
} }
void p3GxsReputation::setNodeAutoPositiveOpinionForContacts(bool b)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
if(b != mAutoSetPositiveOptionToContacts)
{
mLastBannedNodesUpdate = 0 ;
mAutoSetPositiveOptionToContacts = b ;
IndicateConfigChanged() ;
}
}
bool p3GxsReputation::nodeAutoPositiveOpinionForContacts()
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
return mAutoSetPositiveOptionToContacts ;
}
float p3GxsReputation::nodeAutoBanIdentitiesLimit()
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
return mAutoBanIdentitiesLimit - 1.0f;
}
void p3GxsReputation::setNodeAutoBanIdentitiesLimit(float f)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
if(f < -1.0 || f >= 0.0)
{
std::cerr << "(EE) Unexpected value for auto ban identities limit: " << f << std::endl;
return ;
}
if(f != mAutoBanIdentitiesLimit)
{
mLastBannedNodesUpdate = 0 ;
mAutoBanIdentitiesLimit = f+1.0 ;
IndicateConfigChanged() ;
}
}
int p3GxsReputation::status() int p3GxsReputation::status()
{ {
return 1; return 1;
@ -292,6 +333,8 @@ void p3GxsReputation::updateIdentityFlags()
to_update.push_back(rit->first) ; to_update.push_back(rit->first) ;
} }
std::list<RsGxsId> should_set_to_positive ;
for(std::list<RsGxsId>::const_iterator rit(to_update.begin());rit!=to_update.end();++rit) for(std::list<RsGxsId>::const_iterator rit(to_update.begin());rit!=to_update.end();++rit)
{ {
RsIdentityDetails details; RsIdentityDetails details;
@ -303,9 +346,10 @@ void p3GxsReputation::updateIdentityFlags()
#endif #endif
continue ; continue ;
} }
bool is_a_contact = rsIdentity->isARegularContact(*rit) ;
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/ RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(*rit) ; std::map<RsGxsId,Reputation>::iterator it = mReputations.find(*rit) ;
if(it == mReputations.end()) if(it == mReputations.end())
@ -322,6 +366,9 @@ void p3GxsReputation::updateIdentityFlags()
} }
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN ) it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_KNOWN ; if(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN ) it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_KNOWN ;
if(mAutoSetPositiveOptionToContacts && is_a_contact && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL)
should_set_to_positive.push_back(*rit) ;
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << " updated flags for " << *rit << " to " << std::hex << it->second.mIdentityFlags << std::dec << std::endl; std::cerr << " updated flags for " << *rit << " to " << std::hex << it->second.mIdentityFlags << std::dec << std::endl;
#endif #endif
@ -329,6 +376,10 @@ void p3GxsReputation::updateIdentityFlags()
it->second.updateReputation() ; it->second.updateReputation() ;
IndicateConfigChanged(); IndicateConfigChanged();
} }
}
for(std::list<RsGxsId>::const_iterator it(should_set_to_positive.begin());it!=should_set_to_positive.end();++it)
setOwnOpinion(*it,RsReputations::OPINION_POSITIVE) ;
} }
void p3GxsReputation::cleanup() void p3GxsReputation::cleanup()
@ -748,7 +799,7 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
#endif #endif
info.mAssessment = RsReputations::ASSESSMENT_BAD ; info.mAssessment = RsReputations::ASSESSMENT_BAD ;
} }
else if(info.mOverallReputationScore <= REPUTATION_ASSESSMENT_THRESHOLD_X1) else if(info.mOverallReputationScore <= mAutoBanIdentitiesLimit)
info.mAssessment = RsReputations::ASSESSMENT_BAD ; info.mAssessment = RsReputations::ASSESSMENT_BAD ;
else else
info.mAssessment = RsReputations::ASSESSMENT_OK ; info.mAssessment = RsReputations::ASSESSMENT_OK ;
@ -901,6 +952,14 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold); rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold);
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
kv.key = "AUTO_BAN_IDENTITIES_THRESHOLD" ;
rs_sprintf(kv.value, "%d", mAutoBanIdentitiesLimit);
vitem->tlvkvs.pairs.push_back(kv) ;
kv.key = "AUTO_POSITIVE_CONTACTS" ;
kv.value = mAutoSetPositiveOptionToContacts?"YES":"NO";
vitem->tlvkvs.pairs.push_back(kv) ;
savelist.push_back(vitem) ; savelist.push_back(vitem) ;
return true; return true;
@ -955,6 +1014,22 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
mLastBannedNodesUpdate = 0 ; // force update mLastBannedNodesUpdate = 0 ; // force update
} }
}; };
if(kit->key == "AUTO_BAN_IDENTITIES_THRESHOLD")
{
float val ;
if (sscanf(kit->value.c_str(), "%f", &val) == 1)
{
mAutoBanIdentitiesLimit = val ;
std::cerr << "Setting AutoBanIdentity threshold to " << val << std::endl ;
mLastBannedNodesUpdate = 0 ; // force update
}
};
if(kit->key == "AUTO_POSITIVE_CONTACTS")
{
mAutoSetPositiveOptionToContacts = (kit->value == "YES");
std::cerr << "Setting AutoPositiveContacts to " << kit->value << std::endl ;
mLastBannedNodesUpdate = 0 ; // force update
}
} }
delete (*it); delete (*it);

View File

@ -91,7 +91,7 @@ public:
class p3GxsReputation: public p3Service, public p3Config, public RsReputations /* , public pqiMonitor */ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /* , public pqiMonitor */
{ {
public: public:
p3GxsReputation(p3LinkMgr *lm); p3GxsReputation(p3LinkMgr *lm);
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
@ -102,6 +102,10 @@ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /
virtual void setNodeAutoBanThreshold(uint32_t n) ; virtual void setNodeAutoBanThreshold(uint32_t n) ;
virtual uint32_t nodeAutoBanThreshold() ; virtual uint32_t nodeAutoBanThreshold() ;
virtual void setNodeAutoPositiveOpinionForContacts(bool b) ;
virtual bool nodeAutoPositiveOpinionForContacts() ;
virtual float nodeAutoBanIdentitiesLimit() ;
virtual void setNodeAutoBanIdentitiesLimit(float f) ;
/***** overloaded from p3Service *****/ /***** overloaded from p3Service *****/
virtual int tick(); virtual int tick();
@ -138,7 +142,7 @@ private:
void debug_print() ; void debug_print() ;
void updateIdentityFlags(); void updateIdentityFlags();
private: private:
RsMutex mReputationMtx; RsMutex mReputationMtx;
time_t mLastActiveFriendsUpdate; time_t mLastActiveFriendsUpdate;
@ -148,6 +152,9 @@ private:
bool mReputationsUpdated; bool mReputationsUpdated;
uint32_t mAverageActiveFriends ; uint32_t mAverageActiveFriends ;
float mAutoBanIdentitiesLimit ;
bool mAutoSetPositiveOptionToContacts;
p3LinkMgr *mLinkMgr; p3LinkMgr *mLinkMgr;
// Data for Reputation. // Data for Reputation.

View File

@ -42,6 +42,13 @@ bool PeoplePage::save(QString &/*errmsg*/)
else else
rsReputations->setNodeAutoBanThreshold(ui.identityBanThreshold_SB->value()) ; rsReputations->setNodeAutoBanThreshold(ui.identityBanThreshold_SB->value()) ;
if(!ui.autoPositiveOpinion_CB->isChecked())
rsReputations->setNodeAutoPositiveOpinionForContacts(true) ;
else
rsReputations->setNodeAutoPositiveOpinionForContacts(false) ;
rsReputations->setNodeAutoBanIdentitiesLimit(ui.autoBanIdentitiesLimit_SB->value());
return true; return true;
} }
@ -49,7 +56,11 @@ bool PeoplePage::save(QString &/*errmsg*/)
void PeoplePage::load() void PeoplePage::load()
{ {
uint32_t ban_limit = rsReputations->nodeAutoBanThreshold() ; uint32_t ban_limit = rsReputations->nodeAutoBanThreshold() ;
bool auto_positive_contacts = rsReputations->nodeAutoPositiveOpinionForContacts() ;
float node_auto_ban_identities_limit = rsReputations->nodeAutoBanIdentitiesLimit();
ui.identityBan_CB->setChecked(ban_limit > 0) ; ui.identityBan_CB->setChecked(ban_limit > 0) ;
ui.identityBanThreshold_SB->setValue(ban_limit) ; ui.identityBanThreshold_SB->setValue(ban_limit) ;
ui.autoPositiveOpinion_CB->setChecked(auto_positive_contacts);
ui.autoBanIdentitiesLimit_SB->setValue(node_auto_ban_identities_limit);
} }

View File

@ -16,7 +16,7 @@
<property name="title"> <property name="title">
<string>Identities handling</string> <string>Identities handling</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
@ -61,6 +61,49 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="autoPositiveOpinion_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Anyone in your contact list will automatically have a positive opinion. This allows to automatically raise reputations of used nodes. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>automatically give &quot;Positive&quot; option to my contacts</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Friend options below which identities are banned:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="autoBanIdentitiesLimit_SB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The default value of -0.6 needs 3 to 4 friends to set a negative opinion in order for that identity to be banned at your own node. This is a pretty conservative value. If you want to more easily get rid of banned identities, set the value to e.g. -0.2&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>-0.010000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>-0.600000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>