mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-04 04:14:24 -04:00
changed RsGenExchange strategy to use a threshold on reputation when validating posts
This commit is contained in:
parent
e60ac99994
commit
b009c1135f
5 changed files with 75 additions and 60 deletions
|
@ -60,7 +60,7 @@ static const uint32_t INDEX_AUTHEN_ADMIN = 0x00000040; // admin key
|
||||||
|
|
||||||
#define GXS_MASK "GXS_MASK_HACK"
|
#define GXS_MASK "GXS_MASK_HACK"
|
||||||
|
|
||||||
//#define GEN_EXCH_DEBUG 1
|
#define GEN_EXCH_DEBUG 1
|
||||||
|
|
||||||
#define MSG_CLEANUP_PERIOD 60*5 // 5 minutes
|
#define MSG_CLEANUP_PERIOD 60*5 // 5 minutes
|
||||||
#define INTEGRITY_CHECK_PERIOD 60*30 // 30 minutes
|
#define INTEGRITY_CHECK_PERIOD 60*30 // 30 minutes
|
||||||
|
@ -899,7 +899,10 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
|
||||||
idValidate = false;
|
idValidate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(idValidate && (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG))
|
// now check reputation of the message author
|
||||||
|
float reputation_threshold = (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG)? RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM: RsReputations::REPUTATION_THRESHOLD_DEFAULT ;
|
||||||
|
|
||||||
|
if(idValidate)
|
||||||
{
|
{
|
||||||
// get key data and check that the key is actually PGP-linked. If not, reject the post.
|
// get key data and check that the key is actually PGP-linked. If not, reject the post.
|
||||||
|
|
||||||
|
@ -908,18 +911,18 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
|
||||||
if(!mGixs->getIdDetails(metaData.mAuthorId,details))
|
if(!mGixs->getIdDetails(metaData.mAuthorId,details))
|
||||||
{
|
{
|
||||||
// the key cannot ke reached, although it's in cache. Weird situation.
|
// the key cannot ke reached, although it's in cache. Weird situation.
|
||||||
idValidate = false;
|
|
||||||
std::cerr << "RsGenExchange::validateMsg(): cannot get key data for ID=" << metaData.mAuthorId << ", although it's supposed to be already in cache. Cannot validate." << std::endl;
|
std::cerr << "RsGenExchange::validateMsg(): cannot get key data for ID=" << metaData.mAuthorId << ", although it's supposed to be already in cache. Cannot validate." << std::endl;
|
||||||
idValidate = false ;
|
idValidate = false ;
|
||||||
}
|
}
|
||||||
|
else if(details.mReputation.mOverallReputationScore < reputation_threshold)
|
||||||
if(!details.mPgpLinked)
|
|
||||||
{
|
{
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "RsGenExchange::validateMsg(): message from " << metaData.mAuthorId << ", rejected because key is not PGP linked and the group requires it." << std::endl;
|
std::cerr << "RsGenExchange::validateMsg(): message from " << metaData.mAuthorId << ", rejected because reputation score (" << details.mReputation.mOverallReputationScore <<") is below the accepted threshold (" << reputation_threshold << ")" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
idValidate = false ;
|
idValidate = false ;
|
||||||
}
|
}
|
||||||
|
std::cerr << "RsGenExchange::validateMsg(): message from " << metaData.mAuthorId << ", accepted. Reputation score (" << details.mReputation.mOverallReputationScore <<") is above accepted threshold (" << reputation_threshold << ")" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
class RsReputations
|
class RsReputations
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static const float REPUTATION_THRESHOLD_ANTI_SPAM = 1.2f ;
|
||||||
|
static const float REPUTATION_THRESHOLD_DEFAULT = 1.0f ;
|
||||||
|
|
||||||
// This is the interface file for the reputation system
|
// This is the interface file for the reputation system
|
||||||
//
|
//
|
||||||
enum Opinion { OPINION_NEGATIVE = 0, OPINION_NEUTRAL = 1, OPINION_POSITIVE = 2 } ;
|
enum Opinion { OPINION_NEGATIVE = 0, OPINION_NEUTRAL = 1, OPINION_POSITIVE = 2 } ;
|
||||||
|
|
|
@ -151,6 +151,7 @@ uint32_t RsGxsReputationSetItem::serial_size() const
|
||||||
s += mGxsId.serial_size() ;
|
s += mGxsId.serial_size() ;
|
||||||
s += 4 ; // mOwnOpinion
|
s += 4 ; // mOwnOpinion
|
||||||
s += 4 ; // mOwnOpinionTS
|
s += 4 ; // mOwnOpinionTS
|
||||||
|
s += 4 ; // mIdentityFlags
|
||||||
|
|
||||||
s += 4 ; // mOpinions.size()
|
s += 4 ; // mOpinions.size()
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@ int p3GxsReputation::tick()
|
||||||
|
|
||||||
// no more than once per 5 second chunk.
|
// no more than once per 5 second chunk.
|
||||||
|
|
||||||
if(now > 5+last_identity_flags_update)
|
if(now > 100+last_identity_flags_update)
|
||||||
{
|
{
|
||||||
last_identity_flags_update = now ;
|
last_identity_flags_update = now ;
|
||||||
|
|
||||||
|
@ -214,6 +214,10 @@ int p3GxsReputation::status()
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3GxsReputation::updateIdentityFlags()
|
void p3GxsReputation::updateIdentityFlags()
|
||||||
|
{
|
||||||
|
std::list<RsGxsId> to_update ;
|
||||||
|
|
||||||
|
// we need to gather the list to be used in a non locked frame
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||||
|
|
||||||
|
@ -221,22 +225,37 @@ void p3GxsReputation::updateIdentityFlags()
|
||||||
|
|
||||||
for( std::map<RsGxsId, Reputation>::iterator rit = mReputations.begin();rit!=mReputations.end();++rit)
|
for( std::map<RsGxsId, Reputation>::iterator rit = mReputations.begin();rit!=mReputations.end();++rit)
|
||||||
if(rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE)
|
if(rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE)
|
||||||
|
to_update.push_back(rit->first) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::list<RsGxsId>::const_iterator rit(to_update.begin());rit!=to_update.end();++rit)
|
||||||
{
|
{
|
||||||
RsIdentityDetails details;
|
RsIdentityDetails details;
|
||||||
|
|
||||||
if(!rsIdentity->getIdDetails(rit->first,details))
|
if(!rsIdentity->getIdDetails(*rit,details))
|
||||||
{
|
{
|
||||||
std::cerr << " cannot obtain info for " << rit->first << ". Will do it later." << std::endl;
|
std::cerr << " cannot obtain info for " << *rit << ". Will do it later." << std::endl;
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
|
|
||||||
rit->second.mIdentityFlags = 0 ;
|
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||||
|
|
||||||
if(details.mPgpLinked) rit->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_LINKED ;
|
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(*rit) ;
|
||||||
if(details.mPgpKnown ) rit->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_KNOWN ;
|
|
||||||
|
|
||||||
std::cerr << " updated flags for " << rit->first << " to " << std::hex << rit->second.mIdentityFlags << std::dec << std::endl;
|
if(it == mReputations.end())
|
||||||
break ;
|
{
|
||||||
|
std::cerr << " Weird situation: item " << *rit << " has been deleted from the list??" << std::endl;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
it->second.mIdentityFlags = 0 ;
|
||||||
|
|
||||||
|
if(details.mPgpLinked) it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_LINKED ;
|
||||||
|
if(details.mPgpKnown ) it->second.mIdentityFlags |= REPUTATION_IDENTITY_FLAG_PGP_KNOWN ;
|
||||||
|
|
||||||
|
std::cerr << " updated flags for " << *rit << " to " << std::hex << it->second.mIdentityFlags << std::dec << std::endl;
|
||||||
|
|
||||||
|
it->second.updateReputation() ;
|
||||||
|
IndicateConfigChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +540,7 @@ void p3GxsReputation::locked_updateOpinion(const RsPeerId& from,const RsGxsId& a
|
||||||
#ifdef DEBUG_REPUTATION
|
#ifdef DEBUG_REPUTATION
|
||||||
std::cerr << " reputation changed. re-calculating." << std::endl;
|
std::cerr << " reputation changed. re-calculating." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
reputation.updateReputation(mAverageActiveFriends) ;
|
reputation.updateReputation() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(updated)
|
if(updated)
|
||||||
|
@ -576,29 +595,19 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,time_t latest_update)
|
||||||
|
|
||||||
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::ReputationInfo& info)
|
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::ReputationInfo& info)
|
||||||
{
|
{
|
||||||
|
if(gxsid.isNull())
|
||||||
|
return false ;
|
||||||
|
|
||||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||||
|
|
||||||
#ifdef DEBUG_REPUTATION
|
#ifdef DEBUG_REPUTATION
|
||||||
std::cerr << "getReputationInfo() for " << gxsid << std::endl;
|
std::cerr << "getReputationInfo() for " << gxsid << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
Reputation& rep(mReputations[gxsid]) ;
|
||||||
|
|
||||||
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(gxsid);
|
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ;
|
||||||
|
info.mOverallReputationScore = rep.mReputation ;
|
||||||
if (it == mReputations.end())
|
info.mFriendAverage = rep.mFriendAverage ;
|
||||||
{
|
|
||||||
info.mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
|
|
||||||
info.mFriendAverage = RsReputations::OPINION_NEUTRAL ;
|
|
||||||
info.mOverallReputationScore = float(RsReputations::OPINION_NEUTRAL) ;
|
|
||||||
info.mAssessment = RsReputations::ASSESSMENT_OK ;
|
|
||||||
#ifdef DEBUG_REPUTATION
|
|
||||||
std::cerr << " no information present. Returning default. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
info.mOwnOpinion = RsReputations::Opinion(it->second.mOwnOpinion) ;
|
|
||||||
info.mOverallReputationScore = it->second.mReputation ;
|
|
||||||
info.mFriendAverage = it->second.mFriendAverage ;
|
|
||||||
|
|
||||||
if(info.mOverallReputationScore > REPUTATION_ASSESSMENT_THRESHOLD_X1)
|
if(info.mOverallReputationScore > REPUTATION_ASSESSMENT_THRESHOLD_X1)
|
||||||
info.mAssessment = RsReputations::ASSESSMENT_OK ;
|
info.mAssessment = RsReputations::ASSESSMENT_OK ;
|
||||||
|
@ -608,7 +617,6 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::Rep
|
||||||
#ifdef DEBUG_REPUTATION
|
#ifdef DEBUG_REPUTATION
|
||||||
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
|
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
@ -675,7 +683,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
reputation.mOwnOpinion = opinion;
|
reputation.mOwnOpinion = opinion;
|
||||||
reputation.mOwnOpinionTs = now;
|
reputation.mOwnOpinionTs = now;
|
||||||
reputation.updateReputation(mAverageActiveFriends);
|
reputation.updateReputation();
|
||||||
|
|
||||||
mUpdated.insert(std::make_pair(now, gxsid));
|
mUpdated.insert(std::make_pair(now, gxsid));
|
||||||
mUpdatedReputations.insert(gxsid);
|
mUpdatedReputations.insert(gxsid);
|
||||||
|
@ -825,7 +833,7 @@ bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std:
|
||||||
//float old_reputation = reputation.mReputation ;
|
//float old_reputation = reputation.mReputation ;
|
||||||
//mUpdatedReputations.insert(gxsId) ;
|
//mUpdatedReputations.insert(gxsId) ;
|
||||||
|
|
||||||
reputation.updateReputation(mAverageActiveFriends) ;
|
reputation.updateReputation() ;
|
||||||
|
|
||||||
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
||||||
return true;
|
return true;
|
||||||
|
@ -934,7 +942,7 @@ int p3GxsReputation::sendReputationRequest(RsPeerId peerid)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reputation::updateReputation(uint32_t average_active_friends)
|
void Reputation::updateReputation()
|
||||||
{
|
{
|
||||||
// the calculation of reputation makes the whole thing
|
// the calculation of reputation makes the whole thing
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,12 @@ class Reputation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Reputation()
|
Reputation()
|
||||||
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0), mReputation(RsReputations::OPINION_NEUTRAL),mIdentityFlags(REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE) { }
|
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0),mFriendAverage(1.0f), mReputation(RsReputations::OPINION_NEUTRAL),mIdentityFlags(REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE){ }
|
||||||
|
|
||||||
Reputation(const RsGxsId& about)
|
Reputation(const RsGxsId& about)
|
||||||
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0), mReputation(RsReputations::OPINION_NEUTRAL),mIdentityFlags(REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE) { }
|
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0),mFriendAverage(1.0f), mReputation(RsReputations::OPINION_NEUTRAL),mIdentityFlags(REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE){ }
|
||||||
|
|
||||||
void updateReputation(uint32_t average_active_friends);
|
void updateReputation();
|
||||||
|
|
||||||
std::map<RsPeerId, RsReputations::Opinion> mOpinions;
|
std::map<RsPeerId, RsReputations::Opinion> mOpinions;
|
||||||
int32_t mOwnOpinion;
|
int32_t mOwnOpinion;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue