mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
efd503e7d4
commit
218977170c
@ -51,9 +51,16 @@ public:
|
||||
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0;
|
||||
virtual bool getReputationInfo(const RsGxsId& id,const RsPgpId& owner_id,ReputationInfo& info) =0 ;
|
||||
|
||||
// parameters
|
||||
|
||||
virtual void setNodeAutoBanThreshold(uint32_t n) =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.
|
||||
// it basically returns true if assessment is not ASSESSMENT_OK
|
||||
|
||||
|
@ -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 kReputationRequestPeriod = 600; // 10 mins
|
||||
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 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
|
||||
@ -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
|
||||
mAverageActiveFriends = 0 ;
|
||||
mLastBannedNodesUpdate = 0 ;
|
||||
|
||||
mAutoBanIdentitiesLimit = REPUTATION_ASSESSMENT_THRESHOLD_X1;
|
||||
mAutoSetPositiveOptionToContacts = true; // default
|
||||
}
|
||||
|
||||
const std::string GXS_REPUTATION_APP_NAME = "gxsreputation";
|
||||
@ -232,6 +235,44 @@ uint32_t p3GxsReputation::nodeAutoBanThreshold()
|
||||
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()
|
||||
{
|
||||
return 1;
|
||||
@ -292,6 +333,8 @@ void p3GxsReputation::updateIdentityFlags()
|
||||
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)
|
||||
{
|
||||
RsIdentityDetails details;
|
||||
@ -303,32 +346,40 @@ void p3GxsReputation::updateIdentityFlags()
|
||||
#endif
|
||||
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())
|
||||
{
|
||||
std::cerr << " Weird situation: item " << *rit << " has been deleted from the list??" << std::endl;
|
||||
continue ;
|
||||
}
|
||||
it->second.mIdentityFlags = 0 ;
|
||||
|
||||
if(it == mReputations.end())
|
||||
{
|
||||
std::cerr << " Weird situation: item " << *rit << " has been deleted from the list??" << std::endl;
|
||||
continue ;
|
||||
}
|
||||
it->second.mIdentityFlags = 0 ;
|
||||
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)
|
||||
{
|
||||
it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_LINKED ;
|
||||
it->second.mOwnerNode = details.mPgpId ;
|
||||
}
|
||||
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN ) it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_KNOWN ;
|
||||
|
||||
if(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)
|
||||
{
|
||||
it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_LINKED ;
|
||||
it->second.mOwnerNode = details.mPgpId ;
|
||||
}
|
||||
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
|
||||
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
|
||||
|
||||
it->second.updateReputation() ;
|
||||
IndicateConfigChanged();
|
||||
it->second.updateReputation() ;
|
||||
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()
|
||||
@ -748,7 +799,7 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
|
||||
#endif
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
}
|
||||
else if(info.mOverallReputationScore <= REPUTATION_ASSESSMENT_THRESHOLD_X1)
|
||||
else if(info.mOverallReputationScore <= mAutoBanIdentitiesLimit)
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
else
|
||||
info.mAssessment = RsReputations::ASSESSMENT_OK ;
|
||||
@ -901,7 +952,15 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
||||
rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold);
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
savelist.push_back(vitem) ;
|
||||
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) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -955,7 +1014,23 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
|
||||
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);
|
||||
}
|
||||
|
@ -91,76 +91,83 @@ public:
|
||||
|
||||
class p3GxsReputation: public p3Service, public p3Config, public RsReputations /* , public pqiMonitor */
|
||||
{
|
||||
public:
|
||||
p3GxsReputation(p3LinkMgr *lm);
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
public:
|
||||
p3GxsReputation(p3LinkMgr *lm);
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
/***** Interface for RsReputations *****/
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &owner_id, ReputationInfo& info) ;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id, const RsPgpId &owner_node) ;
|
||||
|
||||
virtual void setNodeAutoBanThreshold(uint32_t n) ;
|
||||
virtual uint32_t nodeAutoBanThreshold() ;
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
/***** Interface for RsReputations *****/
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &owner_id, ReputationInfo& info) ;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id, const RsPgpId &owner_node) ;
|
||||
|
||||
/*!
|
||||
* Interface stuff.
|
||||
*/
|
||||
virtual void setNodeAutoBanThreshold(uint32_t n) ;
|
||||
virtual uint32_t nodeAutoBanThreshold() ;
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) ;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() ;
|
||||
virtual float nodeAutoBanIdentitiesLimit() ;
|
||||
virtual void setNodeAutoBanIdentitiesLimit(float f) ;
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
/*!
|
||||
* Interface stuff.
|
||||
*/
|
||||
|
||||
/************* from p3Config *******************/
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
|
||||
virtual void saveDone();
|
||||
virtual bool loadList(std::list<RsItem*>& load) ;
|
||||
|
||||
/************* from p3Config *******************/
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
|
||||
virtual void saveDone();
|
||||
virtual bool loadList(std::list<RsItem*>& load) ;
|
||||
|
||||
private:
|
||||
|
||||
bool processIncoming();
|
||||
bool processIncoming();
|
||||
|
||||
bool SendReputations(RsGxsReputationRequestItem *request);
|
||||
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
||||
bool updateLatestUpdate(RsPeerId peerid, time_t latest_update);
|
||||
void updateActiveFriends() ;
|
||||
void updateBannedNodesList();
|
||||
|
||||
// internal update of data. Takes care of cleaning empty boxes.
|
||||
void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op);
|
||||
bool loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet);
|
||||
bool SendReputations(RsGxsReputationRequestItem *request);
|
||||
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
||||
bool updateLatestUpdate(RsPeerId peerid, time_t latest_update);
|
||||
void updateActiveFriends() ;
|
||||
void updateBannedNodesList();
|
||||
|
||||
int sendPackets();
|
||||
void cleanup();
|
||||
void sendReputationRequests();
|
||||
int sendReputationRequest(RsPeerId peerid);
|
||||
void debug_print() ;
|
||||
void updateIdentityFlags();
|
||||
// internal update of data. Takes care of cleaning empty boxes.
|
||||
void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op);
|
||||
bool loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet);
|
||||
|
||||
private:
|
||||
RsMutex mReputationMtx;
|
||||
int sendPackets();
|
||||
void cleanup();
|
||||
void sendReputationRequests();
|
||||
int sendReputationRequest(RsPeerId peerid);
|
||||
void debug_print() ;
|
||||
void updateIdentityFlags();
|
||||
|
||||
time_t mLastActiveFriendsUpdate;
|
||||
time_t mRequestTime;
|
||||
time_t mStoreTime;
|
||||
time_t mLastBannedNodesUpdate ;
|
||||
bool mReputationsUpdated;
|
||||
uint32_t mAverageActiveFriends ;
|
||||
private:
|
||||
RsMutex mReputationMtx;
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
time_t mLastActiveFriendsUpdate;
|
||||
time_t mRequestTime;
|
||||
time_t mStoreTime;
|
||||
time_t mLastBannedNodesUpdate ;
|
||||
bool mReputationsUpdated;
|
||||
uint32_t mAverageActiveFriends ;
|
||||
|
||||
// Data for Reputation.
|
||||
std::map<RsPeerId, ReputationConfig> mConfig;
|
||||
std::map<RsGxsId, Reputation> mReputations;
|
||||
std::multimap<time_t, RsGxsId> mUpdated;
|
||||
float mAutoBanIdentitiesLimit ;
|
||||
bool mAutoSetPositiveOptionToContacts;
|
||||
|
||||
// set of Reputations to send to p3IdService.
|
||||
std::set<RsGxsId> mUpdatedReputations;
|
||||
|
||||
// PGP Ids auto-banned. This is updated regularly.
|
||||
std::set<RsPgpId> mBannedPgpIds ;
|
||||
uint32_t mPgpAutoBanThreshold ;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
// Data for Reputation.
|
||||
std::map<RsPeerId, ReputationConfig> mConfig;
|
||||
std::map<RsGxsId, Reputation> mReputations;
|
||||
std::multimap<time_t, RsGxsId> mUpdated;
|
||||
|
||||
// set of Reputations to send to p3IdService.
|
||||
std::set<RsGxsId> mUpdatedReputations;
|
||||
|
||||
// PGP Ids auto-banned. This is updated regularly.
|
||||
std::set<RsPgpId> mBannedPgpIds ;
|
||||
uint32_t mPgpAutoBanThreshold ;
|
||||
};
|
||||
|
||||
#endif //SERVICE_RSGXSREPUTATION_HEADER
|
||||
|
@ -37,19 +37,30 @@ PeoplePage::~PeoplePage()
|
||||
/** Saves the changes on this page */
|
||||
bool PeoplePage::save(QString &/*errmsg*/)
|
||||
{
|
||||
if(!ui.identityBan_CB->isChecked())
|
||||
rsReputations->setNodeAutoBanThreshold(0) ;
|
||||
else
|
||||
rsReputations->setNodeAutoBanThreshold(ui.identityBanThreshold_SB->value()) ;
|
||||
if(!ui.identityBan_CB->isChecked())
|
||||
rsReputations->setNodeAutoBanThreshold(0) ;
|
||||
else
|
||||
rsReputations->setNodeAutoBanThreshold(ui.identityBanThreshold_SB->value()) ;
|
||||
|
||||
return true;
|
||||
if(!ui.autoPositiveOpinion_CB->isChecked())
|
||||
rsReputations->setNodeAutoPositiveOpinionForContacts(true) ;
|
||||
else
|
||||
rsReputations->setNodeAutoPositiveOpinionForContacts(false) ;
|
||||
|
||||
rsReputations->setNodeAutoBanIdentitiesLimit(ui.autoBanIdentitiesLimit_SB->value());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Loads the settings for this page */
|
||||
void PeoplePage::load()
|
||||
{
|
||||
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.identityBanThreshold_SB->setValue(ban_limit) ;
|
||||
ui.autoPositiveOpinion_CB->setChecked(auto_positive_contacts);
|
||||
ui.autoBanIdentitiesLimit_SB->setValue(node_auto_ban_identities_limit);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
<property name="title">
|
||||
<string>Identities handling</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
@ -61,6 +61,49 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="autoPositiveOpinion_CB">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Anyone in your contact list will automatically have a positive opinion. This allows to automatically raise reputations of used nodes. </p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>automatically give "Positive" 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><html><head/><body><p>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</p></body></html></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>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user