Merge pull request #442 from csoler/v0.6-ContactList

V0.6 contact list
This commit is contained in:
Cyril Soler 2016-07-25 16:07:53 -04:00 committed by GitHub
commit da8a520f3b
13 changed files with 238 additions and 156 deletions

View File

@ -1862,15 +1862,6 @@ bool p3GRouter::locked_getLocallyRegisteredClientFromServiceId(const GRouterServ
return true ;
}
void p3GRouter::addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id)
{
RS_STACK_MUTEX(grMtx) ;
#ifdef GROUTER_DEBUG
grouter_debug() << "Received new routing clue for key " << mid << " from peer " << peer_id << std::endl;
#endif
_routing_matrix.addTrackingInfo(mid,peer_id) ;
_changed = true ;
}
void p3GRouter::addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id)
{
RS_STACK_MUTEX(grMtx) ;
@ -2357,13 +2348,6 @@ bool p3GRouter::getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& infos)
return true ;
}
bool p3GRouter::getTrackingInfo(const RsGxsMessageId &mid, RsPeerId &provider_id)
{
RS_STACK_MUTEX(grMtx) ;
return _routing_matrix.getTrackingInfo(mid,provider_id) ;
}
// Dump everything
//
void p3GRouter::debugDump()

View File

@ -130,7 +130,6 @@ public:
//===================================================//
virtual void addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id) ;
virtual void addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id) ;
//===================================================//
// Client/server request services //
@ -168,7 +167,6 @@ public:
// - Cache state (memory size, etc)
//
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& info) ;
virtual bool getTrackingInfo(const RsGxsMessageId& mid, RsPeerId& provider_id) ;
//===================================================//
// Derived from p3Service //

View File

@ -2011,10 +2011,7 @@ void RsGenExchange::publishMsgs()
// FIXTESTS global variable rsPeers not available in unittests!
if(rsPeers)
{
mRoutingClues[msg->metaData->mAuthorId].insert(rsPeers->getOwnId()) ;
mTrackingClues.push_back(std::make_pair(msg->msgId,rsPeers->getOwnId())) ;
}
computeHash(msg->msg, msg->metaData->mHash);
mDataAccess->addMsgData(msg);
@ -2159,11 +2156,6 @@ void RsGenExchange::processRoutingClues()
rsGRouter->addRoutingClue(GRouterKeyId(it->first),(*it2) ) ;
mRoutingClues.clear() ;
for(std::list<std::pair<RsGxsMessageId,RsPeerId> >::const_iterator it = mTrackingClues.begin();it!=mTrackingClues.end();++it)
rsGRouter->addTrackingInfo((*it).first,(*it).second) ;
mTrackingClues.clear() ;
}
void RsGenExchange::processGroupDelete()
@ -2732,9 +2724,6 @@ void RsGenExchange::processRecvdMessages()
if(!msg->metaData->mAuthorId.isNull())
mRoutingClues[msg->metaData->mAuthorId].insert(msg->PeerId()) ;
if(grpMeta->mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES)
mTrackingClues.push_back(std::make_pair(msg->msgId,msg->PeerId())) ;
}
if(validateReturn == VALIDATE_FAIL)

View File

@ -103,9 +103,6 @@ public:
//===================================================//
virtual void addRoutingClue(const GRouterKeyId& destination, const RsPeerId& source) =0;
virtual void addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id) =0;
virtual bool getTrackingInfo(const RsGxsMessageId& mid, RsPeerId& provider_id) =0;
};
// To access the GRouter from anywhere

View File

@ -33,7 +33,7 @@ namespace GXS_SERV {
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG = 0x00000100;
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_REQUIRED = 0x00000200;
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN = 0x00000400;
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES = 0x00000800;
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES = 0x00000800; // not used anymore
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN = 0x00001000;
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_MASK = 0x000000ff;

View File

@ -51,8 +51,15 @@ 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

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 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
@ -151,8 +151,12 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
mStoreTime = 0;
mReputationsUpdated = false;
mLastActiveFriendsUpdate = time(NULL) - 0.5*ACTIVE_FRIENDS_UPDATE_PERIOD; // avoids doing it too soon since the TS from rsIdentity needs to be loaded already
mLastIdentityFlagsUpdate = time(NULL) - 3;
mAverageActiveFriends = 0 ;
mLastBannedNodesUpdate = 0 ;
mAutoBanIdentitiesLimit = REPUTATION_ASSESSMENT_THRESHOLD_X1;
mAutoSetPositiveOptionToContacts = true; // default
}
const std::string GXS_REPUTATION_APP_NAME = "gxsreputation";
@ -186,22 +190,18 @@ int p3GxsReputation::tick()
mLastActiveFriendsUpdate = now ;
}
static time_t last_identity_flags_update = 0 ;
// no more than once per 5 second chunk.
if(now > IDENTITY_FLAGS_UPDATE_DELAY+last_identity_flags_update)
if(now > IDENTITY_FLAGS_UPDATE_DELAY+mLastIdentityFlagsUpdate)
{
last_identity_flags_update = now ;
updateIdentityFlags() ;
mLastIdentityFlagsUpdate = now ;
}
if(now > BANNED_NODES_UPDATE_DELAY+mLastBannedNodesUpdate) // 613 is not a multiple of 100, to avoid piling up work
{
mLastBannedNodesUpdate = now ;
updateIdentityFlags() ; // needed before updateBannedNodesList!
updateBannedNodesList();
mLastBannedNodesUpdate = now ;
}
#ifdef DEBUG_REPUTATION
@ -232,6 +232,44 @@ uint32_t p3GxsReputation::nodeAutoBanThreshold()
return mPgpAutoBanThreshold ;
}
void p3GxsReputation::setNodeAutoPositiveOpinionForContacts(bool b)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
if(b != mAutoSetPositiveOptionToContacts)
{
mLastIdentityFlagsUpdate = 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 +330,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,9 +343,10 @@ void p3GxsReputation::updateIdentityFlags()
#endif
continue ;
}
bool is_a_contact = rsIdentity->isARegularContact(*rit) ;
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(*rit) ;
if(it == mReputations.end())
@ -322,6 +363,9 @@ void p3GxsReputation::updateIdentityFlags()
}
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;
#endif
@ -331,6 +375,10 @@ void p3GxsReputation::updateIdentityFlags()
}
}
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()
{
// remove opinions from friends that havn't been seen online for more than the specified delay
@ -748,7 +796,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,6 +949,14 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold);
vitem->tlvkvs.pairs.push_back(kv) ;
kv.key = "AUTO_BAN_IDENTITIES_THRESHOLD" ;
rs_sprintf(kv.value, "%f", 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,6 +1011,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);

View File

@ -102,6 +102,10 @@ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /
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();
@ -145,9 +149,13 @@ private:
time_t mRequestTime;
time_t mStoreTime;
time_t mLastBannedNodesUpdate ;
time_t mLastIdentityFlagsUpdate ;
bool mReputationsUpdated;
uint32_t mAverageActiveFriends ;
float mAutoBanIdentitiesLimit ;
bool mAutoSetPositiveOptionToContacts;
p3LinkMgr *mLinkMgr;
// Data for Reputation.

View File

@ -301,8 +301,6 @@ void GxsGroupDialog::setupDefaults()
ui.commentsValueLabel->setText(tr("Allowed"));
}
}
ui.antiSpam_trackMessages->setChecked((bool)(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_TRACK));
if( (mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP) && (mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP_KNOWN))
ui.antiSpam_perms_CB->setCurrentIndex(2) ;
else if(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP)
@ -656,9 +654,6 @@ uint32_t GxsGroupDialog::getGroupSignFlags()
break ;
}
if (ui.antiSpam_trackMessages->isChecked())
signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES;
return signFlags;
}
@ -680,8 +675,6 @@ void GxsGroupDialog::setGroupSignFlags(uint32_t signFlags)
if (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN)
ui.personal_ifnopub->setChecked(true);
ui.antiSpam_trackMessages ->setChecked((bool)(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) );
if( (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN) && (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG))
ui.antiSpam_perms_CB->setCurrentIndex(2) ;
else if(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG)

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>860</width>
<height>775</height>
<width>1237</width>
<height>790</height>
</rect>
</property>
<property name="windowTitle">
@ -582,16 +582,6 @@
</item>
</widget>
</item>
<item>
<widget class="QRadioButton" name="antiSpam_trackMessages">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;This feature allows Retroshare to locally keep a record of who forwarded each message to you, for the last 10 days. Although useless if alone (and already available whatsoever) this information can be used by a group of teamed-up friends to easily locate a source of spams. To be used with care, since it significantly decreases the anonymity of message posts.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Keep track of posts</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">

View File

@ -577,17 +577,6 @@ void GxsForumThreadWidget::changedThread()
mThreadId = RsGxsMessageId(item->data(COLUMN_THREAD_DATA, ROLE_THREAD_MSGID).toString().toStdString());
}
// Show info about who passed on this message.
if(mForumGroup.mMeta.mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES)
{
RsPeerId providerId ;
std::string msgId = item->data(COLUMN_THREAD_DATA, ROLE_THREAD_MSGID).toString().toStdString();
RsGxsMessageId mid(msgId) ;
if(rsGRouter->getTrackingInfo(mid,providerId) && !providerId.isNull() )
item->setToolTip(COLUMN_THREAD_TITLE,tr("This message was obtained from %1").arg(QString::fromUtf8(rsPeers->getPeerName(providerId).c_str())));
}
if (mFillThread) {
return;
}

View File

@ -42,6 +42,13 @@ bool PeoplePage::save(QString &/*errmsg*/)
else
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;
}
@ -49,7 +56,11 @@ bool PeoplePage::save(QString &/*errmsg*/)
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);
}

View File

@ -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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Anyone in your contact list will automatically have a positive opinion if not set. 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; opinion 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 average opinion 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>
</widget>
</item>