Merge pull request #433 from csoler/v0.6-SqlCache

V0.6 sql cache
This commit is contained in:
Cyril Soler 2016-07-05 23:47:55 -04:00 committed by GitHub
commit 1c277ab81b
19 changed files with 359 additions and 226 deletions

View file

@ -87,8 +87,10 @@ bool UdpStack::getLocalAddress(struct sockaddr_in &local)
bool UdpStack::resetAddress(struct sockaddr_in &local) bool UdpStack::resetAddress(struct sockaddr_in &local)
{ {
std::cerr << "UdpStack::resetAddress(" << local << ")"; #ifdef DEBUG_UDP_RECV
std::cerr << "UdpStack::resetAddress(" << local << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
laddr = local; laddr = local;
return udpLayer->reset(local); return udpLayer->reset(local);

View file

@ -34,7 +34,6 @@
#include "pqi/p3historymgr.h" #include "pqi/p3historymgr.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
#include "retroshare/rsreputations.h"
#include "retroshare/rsidentity.h" #include "retroshare/rsidentity.h"
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#include "gxs/rsgixs.h" #include "gxs/rsgixs.h"
@ -139,7 +138,7 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
return false ; return false ;
} }
if(rsReputations->isIdentityBanned(cli->signature.keyId)) if(rsIdentity->isBanned(cli->signature.keyId))
{ {
std::cerr << "(WW) Received lobby msg/item from banned identity " << cli->signature.keyId << ". Dropping it." << std::endl; std::cerr << "(WW) Received lobby msg/item from banned identity " << cli->signature.keyId << ". Dropping it." << std::endl;
return false ; return false ;
@ -648,7 +647,7 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
#endif #endif
time_t now = time(NULL) ; time_t now = time(NULL) ;
if(rsReputations->isIdentityBanned(item->signature.keyId)) if(rsIdentity->isBanned(item->signature.keyId))
{ {
std::cerr << "(WW) Received lobby msg/item from banned identity " << item->signature.keyId << ". Dropping it." << std::endl; std::cerr << "(WW) Received lobby msg/item from banned identity " << item->signature.keyId << ". Dropping it." << std::endl;
return ; return ;

View file

@ -191,7 +191,6 @@
#include "turtle/p3turtle.h" #include "turtle/p3turtle.h"
#include "gxs/rsgixs.h" #include "gxs/rsgixs.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsreputations.h"
#include "p3grouter.h" #include "p3grouter.h"
#include "grouteritems.h" #include "grouteritems.h"
@ -1994,7 +1993,7 @@ bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item,uint32_t& er
{ {
try try
{ {
if(rsReputations->isIdentityBanned(item->signature.keyId)) if(rsIdentity->isBanned(item->signature.keyId))
{ {
std::cerr << "(WW) received global router message from banned identity " << item->signature.keyId << ". Rejecting the message." << std::endl; std::cerr << "(WW) received global router message from banned identity " << item->signature.keyId << ". Rejecting the message." << std::endl;
return false ; return false ;

View file

@ -27,6 +27,7 @@
/***** /*****
* #define RS_DATA_SERVICE_DEBUG 1 * #define RS_DATA_SERVICE_DEBUG 1
* #define RS_DATA_SERVICE_DEBUG_TIME 1 * #define RS_DATA_SERVICE_DEBUG_TIME 1
* #define RS_DATA_SERVICE_DEBUG_CACHE 1
****/ ****/
#include <fstream> #include <fstream>
@ -123,6 +124,7 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
: RsGeneralDataService(), mDbMutex("RsDataService"), mServiceDir(serviceDir), mDbName(dbName), mDbPath(mServiceDir + "/" + dbName), mServType(serviceType), mDb(NULL) : RsGeneralDataService(), mDbMutex("RsDataService"), mServiceDir(serviceDir), mDbName(dbName), mDbPath(mServiceDir + "/" + dbName), mServType(serviceType), mDb(NULL)
{ {
bool isNewDatabase = !RsDirUtil::fileExists(mDbPath); bool isNewDatabase = !RsDirUtil::fileExists(mDbPath);
mGrpMetaDataCache_ContainsAllDatabase = false ;
mDb = new RetroDb(mDbPath, RetroDb::OPEN_READWRITE_CREATE, key); mDb = new RetroDb(mDbPath, RetroDb::OPEN_READWRITE_CREATE, key);
@ -1231,6 +1233,9 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
if (c) if (c)
{ {
locked_retrieveMsgMeta(c, metaSet); locked_retrieveMsgMeta(c, metaSet);
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving (all) Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
#endif
} }
}else{ }else{
@ -1245,6 +1250,9 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
if (c) if (c)
{ {
locked_retrieveMsgMeta(c, metaSet); locked_retrieveMsgMeta(c, metaSet);
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
#endif
} }
} }
} }
@ -1296,11 +1304,21 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
int requestedGroups = grp.size(); int requestedGroups = grp.size();
#endif #endif
if(grp.empty()){ if(grp.empty())
{
if(mGrpMetaDataCache_ContainsAllDatabase) // grab all the stash from the cache, so as to avoid decryption costs.
{
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": RsDataService::retrieveGxsGrpMetaData() retrieving all from cache!" << std::endl;
#endif
for(std::map<RsGxsGroupId,RsGxsGrpMetaData>::const_iterator it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it)
grp[it->first] = new RsGxsGrpMetaData(it->second);
}
else
{
#ifdef RS_DATA_SERVICE_DEBUG #ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all"; std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all" << std::endl;
std::cerr << std::endl;
#endif #endif
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", "");
@ -1315,6 +1333,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
if(g) if(g)
{ {
grp[g->mGroupId] = g; grp[g->mGroupId] = g;
mGrpMetaDataCache[g->mGroupId] = *g ;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void *)this << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl;
#endif
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -1325,12 +1347,29 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
delete c; delete c;
} }
mGrpMetaDataCache_ContainsAllDatabase = true ;
}
}else }else
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin(); std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
for(; mit != grp.end(); ++mit) for(; mit != grp.end(); ++mit)
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData>::const_iterator itt = mGrpMetaDataCache.find(mit->first) ;
if(itt != mGrpMetaDataCache.end())
{
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first << " from cache!" << std::endl;
#endif
grp[mit->first] = new RsGxsGrpMetaData(itt->second) ;
}
else
{
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first ;
#endif
const RsGxsGroupId& grpId = mit->first; const RsGxsGroupId& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", "");
@ -1338,6 +1377,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
{ {
bool valid = c->moveToFirst(); bool valid = c->moveToFirst();
//#ifdef RS_DATA_SERVICE_DEBUG_CACHE
if(!valid)
std::cerr << " Empty query! GrpId " << grpId << " is not in database" << std::endl;
//#endif
while(valid) while(valid)
{ {
RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0); RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0);
@ -1345,6 +1388,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
if(g) if(g)
{ {
grp[g->mGroupId] = g; grp[g->mGroupId] = g;
mGrpMetaDataCache[g->mGroupId] = *g ;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << ". Got it. Updating cache." << std::endl;
#endif
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -1354,7 +1401,11 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
} }
delete c; delete c;
} }
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
else
std::cerr << ". not found!" << std::endl;
#endif
}
} }
} }
@ -1391,13 +1442,29 @@ int RsDataService::resetDataStore()
int RsDataService::updateGroupMetaData(GrpLocMetaData &meta) int RsDataService::updateGroupMetaData(GrpLocMetaData &meta)
{ {
RsStackMutex stack(mDbMutex); #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": Updating Grp Meta data: grpId = " << meta.grpId << std::endl;
#endif
RsStackMutex stack(mDbMutex);
RsGxsGroupId& grpId = meta.grpId; RsGxsGroupId& grpId = meta.grpId;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": erasing old entry from cache." << std::endl;
#endif
mGrpMetaDataCache_ContainsAllDatabase = false ;
mGrpMetaDataCache.erase(meta.grpId) ;
return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", meta.val) ? 1 : 0; return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", meta.val) ? 1 : 0;
} }
int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData) int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData)
{ {
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": Updating Msg Meta data: grpId = " << metaData.msgId.first << " msgId = " << metaData.msgId.second << std::endl;
#endif
RsStackMutex stack(mDbMutex); RsStackMutex stack(mDbMutex);
RsGxsGroupId& grpId = metaData.msgId.first; RsGxsGroupId& grpId = metaData.msgId.first;
RsGxsMessageId& msgId = metaData.msgId.second; RsGxsMessageId& msgId = metaData.msgId.second;

View file

@ -340,6 +340,13 @@ private:
uint16_t mServType; uint16_t mServType;
RetroDb* mDb; RetroDb* mDb;
// used to store metadata instead of reading it from the database.
// The boolean variable below is also used to force re-reading when
// the entre list of grp metadata is requested (which happens quite often)
std::map<RsGxsGroupId,RsGxsGrpMetaData> mGrpMetaDataCache ;
bool mGrpMetaDataCache_ContainsAllDatabase ;
}; };
#endif // RSDATASERVICE_H #endif // RSDATASERVICE_H

View file

@ -204,7 +204,6 @@
#include "rsgxsnetservice.h" #include "rsgxsnetservice.h"
#include "gxssecurity.h" #include "gxssecurity.h"
#include "retroshare/rsconfig.h" #include "retroshare/rsconfig.h"
#include "retroshare/rsreputations.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rsgxscircles.h" #include "retroshare/rsgxscircles.h"
#include "pgp/pgpauxutils.h" #include "pgp/pgpauxutils.h"
@ -2928,9 +2927,8 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
#endif #endif
continue; continue;
} }
// FIXTESTS global variable rsReputations not available in unittests!
if(rsReputations == 0){ std::cerr << "rsReputations==0, accepting all messages!" << std::endl; } if(rsIdentity && rsIdentity->isBanned(syncItem->authorId))
if(rsReputations && rsReputations->isIdentityBanned(syncItem->authorId))
{ {
#ifdef NXS_NET_DEBUG_1 #ifdef NXS_NET_DEBUG_1
GXSNETDEBUG_PG(item->PeerId(),grpId) << ", Identity " << syncItem->authorId << " is banned. Not requesting message!" << std::endl; GXSNETDEBUG_PG(item->PeerId(),grpId) << ", Identity " << syncItem->authorId << " is banned. Not requesting message!" << std::endl;
@ -3174,8 +3172,8 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
latestVersion = grpSyncItem->publishTs > metaIter->second->mPublishTs; latestVersion = grpSyncItem->publishTs > metaIter->second->mPublishTs;
} }
// FIXTESTS global variable rsReputations not available in unittests! // FIXTESTS global variable rsReputations not available in unittests!
if(rsReputations == 0){ std::cerr << "rsReputations==0, accepting all groups!" << std::endl; }
if(!grpSyncItem->authorId.isNull() && rsReputations && rsReputations->isIdentityBanned(grpSyncItem->authorId)) if(!grpSyncItem->authorId.isNull() && rsIdentity && rsIdentity->isBanned(grpSyncItem->authorId))
{ {
#ifdef NXS_NET_DEBUG_0 #ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grpId) << " Identity " << grpSyncItem->authorId << " is banned. Not syncing group." << std::endl; GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grpId) << " Identity " << grpSyncItem->authorId << " is banned. Not syncing group." << std::endl;

View file

@ -28,7 +28,6 @@
#include "rsgxsutil.h" #include "rsgxsutil.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsreputations.h"
#include "pqi/pqihash.h" #include "pqi/pqihash.h"
#include "gxs/rsgixs.h" #include "gxs/rsgixs.h"
@ -165,7 +164,7 @@ bool RsGxsIntegrityCheck::check()
std::cerr << "TimeStamping group authors' key ID " << grp->metaData->mAuthorId << " in group ID " << grp->grpId << std::endl; std::cerr << "TimeStamping group authors' key ID " << grp->metaData->mAuthorId << " in group ID " << grp->grpId << std::endl;
#endif #endif
if(rsReputations!=NULL && !rsReputations->isIdentityBanned(grp->metaData->mAuthorId)) if(rsIdentity!=NULL && !rsIdentity->isBanned(grp->metaData->mAuthorId))
used_gxs_ids.insert(grp->metaData->mAuthorId) ; used_gxs_ids.insert(grp->metaData->mAuthorId) ;
} }
} }
@ -247,7 +246,7 @@ bool RsGxsIntegrityCheck::check()
#ifdef GXSUTIL_DEBUG #ifdef GXSUTIL_DEBUG
std::cerr << "TimeStamping message authors' key ID " << msg->metaData->mAuthorId << " in message " << msg->msgId << ", group ID " << msg->grpId<< std::endl; std::cerr << "TimeStamping message authors' key ID " << msg->metaData->mAuthorId << " in message " << msg->msgId << ", group ID " << msg->grpId<< std::endl;
#endif #endif
if(rsReputations!=NULL && !rsReputations->isIdentityBanned(msg->metaData->mAuthorId)) if(rsIdentity!=NULL && !rsIdentity->isBanned(msg->metaData->mAuthorId))
used_gxs_ids.insert(msg->metaData->mAuthorId) ; used_gxs_ids.insert(msg->metaData->mAuthorId) ;
} }

View file

@ -221,46 +221,48 @@ public:
RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) { return; } RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) { return; }
virtual ~RsIdentity() { return; } virtual ~RsIdentity() { return; }
/********************************************************************************************/ /********************************************************************************************/
/********************************************************************************************/ /********************************************************************************************/
// For Other Services....
// It should be impossible for them to get a message which we don't have the identity.
// Its a major error if we don't have the identity.
// We cache all identities, and provide alternative (instantaneous) // For Other Services....
// functions to extract info, rather than the standard Token system. // It should be impossible for them to get a message which we don't have the identity.
// Its a major error if we don't have the identity.
//virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0; // We cache all identities, and provide alternative (instantaneous)
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0; // functions to extract info, rather than the standard Token system.
// Fills up list of all own ids. Returns false if ids are not yet loaded. //virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0; virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0;
virtual bool isOwnId(const RsGxsId& id) = 0;
// // Fills up list of all own ids. Returns false if ids are not yet loaded.
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id, virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0;
bool absOpinion, int score) = 0; virtual bool isOwnId(const RsGxsId& id) = 0;
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params) = 0;
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0; //
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0; virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
bool absOpinion, int score) = 0;
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params) = 0;
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname, virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
const std::string &tag, RsRecognTagDetails &details) = 0; virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 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,
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0;
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ; virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
virtual bool isARegularContact(const RsGxsId& id) = 0 ; virtual bool isARegularContact(const RsGxsId& id) = 0 ;
virtual bool isBanned(const RsGxsId& id) =0;
// Specific RsIdentity Functions.... virtual time_t getLastUsageTS(const RsGxsId &id) =0;
/* Specific Service Data */
/* We expose these initially for testing / GUI purposes. // Specific RsIdentity Functions....
/* Specific Service Data */
/* We expose these initially for testing / GUI purposes.
*/ */
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0; virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0; //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
}; };

View file

@ -50,14 +50,14 @@ 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,ReputationInfo& info) =0 ; virtual bool getReputationInfo(const RsGxsId& id,const RsPgpId& owner_id,ReputationInfo& info) =0 ;
virtual void setNodeAutoBanThreshold(uint32_t n) =0; virtual void setNodeAutoBanThreshold(uint32_t n) =0;
virtual uint32_t nodeAutoBanThreshold() =0; virtual uint32_t nodeAutoBanThreshold() =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
virtual bool isIdentityBanned(const RsGxsId& id) =0; virtual bool isIdentityBanned(const RsGxsId& id,const RsPgpId& owner_node) =0;
}; };
// To access reputations from anywhere // To access reputations from anywhere

View file

@ -116,13 +116,13 @@
* 10 | 1.0 | 0 | 0.25 | 1.0 * 10 | 1.0 | 0 | 0.25 | 1.0
* *
* To check: * To check:
* [ ] Opinions are saved/loaded accross restart * [X] Opinions are saved/loaded accross restart
* [ ] Opinions are transmitted to friends * [X] Opinions are transmitted to friends
* [ ] Opinions are transmitted to friends when updated * [X] Opinions are transmitted to friends when updated
* *
* To do: * To do:
* [ ] Add debug info * [X] Add debug info
* [ ] Test the whole thing * [X] Test the whole thing
* [X] Implement a system to allow not storing info when we don't have it * [X] Implement a system to allow not storing info when we don't have it
*/ */
@ -138,6 +138,7 @@ 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 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
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..
p3GxsReputation::p3GxsReputation(p3LinkMgr *lm) p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
:p3Service(), p3Config(), :p3Service(), p3Config(),
@ -149,7 +150,7 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
mRequestTime = 0; mRequestTime = 0;
mStoreTime = 0; mStoreTime = 0;
mReputationsUpdated = false; mReputationsUpdated = false;
mLastActiveFriendsUpdate = 0 ; 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 ;
} }
@ -333,11 +334,47 @@ void p3GxsReputation::updateIdentityFlags()
void p3GxsReputation::cleanup() void p3GxsReputation::cleanup()
{ {
// remove opinions from friends that havn't been seen online for more than the specified delay // remove opinions from friends that havn't been seen online for more than the specified delay
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputation::cleanup() " << std::endl;
#endif #endif
std::cerr << __PRETTY_FUNCTION__ << ": not implemented. TODO!" << std::endl; std::cerr << "p3GxsReputation::cleanup() " << std::endl;
// remove optionions about identities that do not exist anymore. That will in particular avoid asking p3idservice about deleted
// identities, which would cause an excess of hits to the database.
bool updated = false ;
time_t now = time(NULL) ;
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();)
if(it->second.mOpinions.empty() && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL)
{
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
++tmp ;
mReputations.erase(it) ;
it = tmp ;
#ifdef DEBUG_REPUTATION
std::cerr << " ID " << it->first << ": own is neutral and no opinions from friends => remove entry" << std::endl;
#endif
updated = true ;
}
else if(rsIdentity->getLastUsageTS(it->first) + REPUTATION_INFO_KEEP_DELAY < now)
{
#ifdef DEBUG_REPUTATION
std::cerr << " Identity " << it->first << " has a last usage TS of " << now - rsIdentity->getLastUsageTS(it->first) << " secs ago: deleting it." << std::endl;
#endif
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
++tmp ;
mReputations.erase(it) ;
it = tmp ;
updated = true ;
}
else
++it ;
if(updated)
IndicateConfigChanged() ;
} }
void p3GxsReputation::updateActiveFriends() void p3GxsReputation::updateActiveFriends()
@ -668,7 +705,7 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,time_t latest_update)
* Opinion * Opinion
****/ ****/
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::ReputationInfo& info) bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& owner_id, RsReputations::ReputationInfo& info)
{ {
if(gxsid.isNull()) if(gxsid.isNull())
return false ; return false ;
@ -678,25 +715,34 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::Rep
#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>::const_iterator it = mReputations.find(gxsid) ;
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ; if(it == mReputations.end())
info.mOverallReputationScore = rep.mReputation ;
info.mFriendAverage = rep.mFriendAverage ;
if( (rep.mIdentityFlags & REPUTATION_IDENTITY_FLAG_PGP_LINKED) && (mBannedPgpIds.find(rep.mOwnerNode) != mBannedPgpIds.end()))
{ {
info.mAssessment = RsReputations::ASSESSMENT_BAD ; info.mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
#ifdef DEBUG_REPUTATION info.mOverallReputationScore = RsReputations::REPUTATION_THRESHOLD_DEFAULT ;
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << rep.mOwnerNode << " is banned." << std::endl; info.mFriendAverage = REPUTATION_THRESHOLD_DEFAULT ;
#endif
return true;
} }
if(info.mOverallReputationScore > REPUTATION_ASSESSMENT_THRESHOLD_X1)
info.mAssessment = RsReputations::ASSESSMENT_OK ;
else else
info.mAssessment = RsReputations::ASSESSMENT_BAD ; {
const Reputation& rep(it->second) ;
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ;
info.mOverallReputationScore = rep.mReputation ;
info.mFriendAverage = rep.mFriendAverage ;
}
if(!owner_id.isNull() && (mBannedPgpIds.find(owner_id) != mBannedPgpIds.end()))
{
#ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned." << std::endl;
#endif
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
}
else if(info.mOverallReputationScore <= REPUTATION_ASSESSMENT_THRESHOLD_X1)
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
else
info.mAssessment = RsReputations::ASSESSMENT_OK ;
#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;
@ -705,12 +751,13 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::Rep
return true ; return true ;
} }
bool p3GxsReputation::isIdentityBanned(const RsGxsId &id) bool p3GxsReputation::isIdentityBanned(const RsGxsId &id,const RsPgpId& owner_node)
{ {
RsReputations::ReputationInfo info ; RsReputations::ReputationInfo info ;
getReputationInfo(id,info) ; if(!getReputationInfo(id,owner_node,info))
return false ;
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << "isIdentityBanned(): returning " << (info.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl; std::cerr << "isIdentityBanned(): returning " << (info.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl;
#endif #endif

View file

@ -97,8 +97,8 @@ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /
/***** Interface for RsReputations *****/ /***** Interface for RsReputations *****/
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ; virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) ; virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &owner_id, ReputationInfo& info) ;
virtual bool isIdentityBanned(const RsGxsId& id) ; virtual bool isIdentityBanned(const RsGxsId& id, const RsPgpId &owner_node) ;
virtual void setNodeAutoBanThreshold(uint32_t n) ; virtual void setNodeAutoBanThreshold(uint32_t n) ;
virtual uint32_t nodeAutoBanThreshold() ; virtual uint32_t nodeAutoBanThreshold() ;

View file

@ -258,16 +258,13 @@ time_t p3IdService::locked_getLastUsageTS(const RsGxsId& gxs_id)
std::map<RsGxsId,time_t>::const_iterator it = mKeysTS.find(gxs_id) ; std::map<RsGxsId,time_t>::const_iterator it = mKeysTS.find(gxs_id) ;
if(it == mKeysTS.end()) if(it == mKeysTS.end())
{ return 0 ;
slowIndicateConfigChanged() ;
return mKeysTS[gxs_id] = time(NULL) ;
}
else else
return it->second ; return it->second ;
} }
void p3IdService::timeStampKey(const RsGxsId& gxs_id) void p3IdService::timeStampKey(const RsGxsId& gxs_id)
{ {
if(rsReputations->isIdentityBanned(gxs_id)) if(isBanned(gxs_id))
{ {
std::cerr << "(II) p3IdService:timeStampKey(): refusing to time stamp key " << gxs_id << " because it is banned." << std::endl; std::cerr << "(II) p3IdService:timeStampKey(): refusing to time stamp key " << gxs_id << " because it is banned." << std::endl;
return; return;
@ -327,7 +324,7 @@ public:
time_t now = time(NULL); time_t now = time(NULL);
const RsGxsId& gxs_id = entry.details.mId ; const RsGxsId& gxs_id = entry.details.mId ;
bool is_id_banned = rsReputations->isIdentityBanned(gxs_id) ; bool is_id_banned = rsReputations->isIdentityBanned(gxs_id,entry.details.mPgpId) ;
bool is_own_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_IS_OWN_ID) ; bool is_own_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_IS_OWN_ID) ;
bool is_known_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN) ; bool is_known_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN) ;
bool is_signed_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED) ; bool is_signed_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED) ;
@ -345,7 +342,7 @@ public:
if(it == mLastUsageTS.end()) if(it == mLastUsageTS.end())
{ {
std::cerr << "No Ts for this ID" << std::endl; std::cerr << "No Ts for this ID => kept" << std::endl;
return true ; return true ;
} }
@ -413,10 +410,7 @@ void p3IdService::cleanUnusedKeys()
{ {
RS_STACK_MUTEX(mIdMtx) ; RS_STACK_MUTEX(mIdMtx) ;
std::map<RsGxsId,time_t>::iterator tmp = mKeysTS.find(*it) ; mKeysTS.erase(*it) ;
if(mKeysTS.end() != tmp)
mKeysTS.erase(tmp) ;
// mPublicKeyCache.erase(*it) ; no need to do it now. It's done in p3IdService::deleteGroup() // mPublicKeyCache.erase(*it) ; no need to do it now. It's done in p3IdService::deleteGroup()
} }
@ -509,7 +503,13 @@ bool p3IdService:: getNickname(const RsGxsId &id, std::string &nickname)
} }
#endif #endif
bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details) time_t p3IdService::getLastUsageTS(const RsGxsId &id)
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
return locked_getLastUsageTS(id) ;
}
bool p3IdService::getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
{ {
#ifdef DEBUG_IDS #ifdef DEBUG_IDS
std::cerr << "p3IdService::getIdDetails(" << id << ")"; std::cerr << "p3IdService::getIdDetails(" << id << ")";
@ -530,7 +530,7 @@ bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
if(details.mNickname.length() > RSID_MAXIMUM_NICKNAME_SIZE*4) if(details.mNickname.length() > RSID_MAXIMUM_NICKNAME_SIZE*4)
details.mNickname = "[too long a name]" ; details.mNickname = "[too long a name]" ;
rsReputations->getReputationInfo(id,details.mReputation) ; rsReputations->getReputationInfo(id,details.mPgpId,details.mReputation) ;
return true; return true;
} }
@ -542,6 +542,16 @@ bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
return false; return false;
} }
bool p3IdService::isBanned(const RsGxsId &id)
{
RsIdentityDetails det ;
getIdDetails(id,det) ;
#ifdef DEBUG_REPUTATION
std::cerr << "isIdentityBanned(): returning " << (det.mReputation.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl;
#endif
return det.mReputation.mAssessment == RsReputations::ASSESSMENT_BAD ;
}
bool p3IdService::isOwnId(const RsGxsId& id) bool p3IdService::isOwnId(const RsGxsId& id)
{ {

View file

@ -218,34 +218,34 @@ private:
class p3IdService: public RsGxsIdExchange, public RsIdentity, public GxsTokenQueue, public RsTickEvent, public p3Config class p3IdService: public RsGxsIdExchange, public RsIdentity, public GxsTokenQueue, public RsTickEvent, public p3Config
{ {
public: public:
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils); p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils);
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
static uint32_t idAuthenPolicy(); static uint32_t idAuthenPolicy();
virtual void service_tick(); // needed for background processing. virtual void service_tick(); // needed for background processing.
/*! /*!
* Design hack, id service must be constructed first as it * Design hack, id service must be constructed first as it
* is need for construction of subsequent net services * is need for construction of subsequent net services
*/ */
void setNes(RsNetworkExchangeService* nes); void setNes(RsNetworkExchangeService* nes);
/* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */ /* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */
/* Data Specific Interface */ /* Data Specific Interface */
// These are exposed via RsIdentity. // These are exposed via RsIdentity.
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups); virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions); //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
// These are local - and not exposed via RsIdentity. // These are local - and not exposed via RsIdentity.
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group);
virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
//virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion); //virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
/**************** RsIdentity External Interface. /**************** RsIdentity External Interface.
* Notes: * Notes:
@ -256,86 +256,88 @@ virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
* Also need to handle Cache updates / invalidation from internal changes. * Also need to handle Cache updates / invalidation from internal changes.
* *
*/ */
//virtual bool getNickname(const RsGxsId &id, std::string &nickname); //virtual bool getNickname(const RsGxsId &id, std::string &nickname);
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details); virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details);
// //
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id, virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
bool absOpinion, int score); bool absOpinion, int score);
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params); virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params);
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group); virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group);
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group); virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group);
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname, virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
const std::string &tag, RsRecognTagDetails &details); const std::string &tag, RsRecognTagDetails &details);
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment, virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
uint16_t tag_class, uint16_t tag_type, std::string &tag); uint16_t tag_class, uint16_t tag_type, std::string &tag);
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ; virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ;
virtual bool isARegularContact(const RsGxsId& id) ; virtual bool isARegularContact(const RsGxsId& id) ;
virtual bool isBanned(const RsGxsId& id) ;
/**************** RsGixs Implementation ***************/ virtual time_t getLastUsageTS(const RsGxsId &id) ;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds); /**************** RsGixs Implementation ***************/
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ; virtual bool getOwnIds(std::list<RsGxsId> &ownIds);
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
virtual bool isOwnId(const RsGxsId& key_id) ; //virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ;
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
virtual bool signData(const uint8_t *data,uint32_t data_size,const RsGxsId& signer_id,RsTlvKeySignature& signature,uint32_t& signing_error) ; virtual bool isOwnId(const RsGxsId& key_id) ;
virtual bool validateData(const uint8_t *data,uint32_t data_size,const RsTlvKeySignature& signature,bool force_load,uint32_t& signing_error) ;
virtual bool encryptData(const uint8_t *decrypted_data,uint32_t decrypted_data_size,uint8_t *& encrypted_data,uint32_t& encrypted_data_size,const RsGxsId& encryption_key_id,bool force_load,uint32_t& encryption_error) ; virtual bool signData(const uint8_t *data,uint32_t data_size,const RsGxsId& signer_id,RsTlvKeySignature& signature,uint32_t& signing_error) ;
virtual bool decryptData(const uint8_t *encrypted_data,uint32_t encrypted_data_size,uint8_t *& decrypted_data,uint32_t& decrypted_data_size,const RsGxsId& encryption_key_id,uint32_t& encryption_error) ; virtual bool validateData(const uint8_t *data,uint32_t data_size,const RsTlvKeySignature& signature,bool force_load,uint32_t& signing_error) ;
virtual bool haveKey(const RsGxsId &id); virtual bool encryptData(const uint8_t *decrypted_data,uint32_t decrypted_data_size,uint8_t *& encrypted_data,uint32_t& encrypted_data_size,const RsGxsId& encryption_key_id,bool force_load,uint32_t& encryption_error) ;
virtual bool havePrivateKey(const RsGxsId &id); virtual bool decryptData(const uint8_t *encrypted_data,uint32_t encrypted_data_size,uint8_t *& decrypted_data,uint32_t& decrypted_data_size,const RsGxsId& encryption_key_id,uint32_t& encryption_error) ;
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key); virtual bool haveKey(const RsGxsId &id);
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key); virtual bool havePrivateKey(const RsGxsId &id);
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers); virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key);
virtual bool requestPrivateKey(const RsGxsId &id); virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key);
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers);
virtual bool requestPrivateKey(const RsGxsId &id);
/**************** RsGixsReputation Implementation ****************/ /**************** RsGixsReputation Implementation ****************/
// get Reputation. // get Reputation.
virtual bool haveReputation(const RsGxsId &id); virtual bool haveReputation(const RsGxsId &id);
virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers); virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep); virtual bool getReputation(const RsGxsId &id, GixsReputation &rep);
protected: protected:
/** Notifications **/ /** Notifications **/
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes); virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
/** Overloaded to add PgpIdHash to Group Definition **/ /** Overloaded to add PgpIdHash to Group Definition **/
virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet); virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
// Overloaded from GxsTokenQueue for Request callbacks. // Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type); virtual void handleResponse(uint32_t token, uint32_t req_type);
// Overloaded from RsTickEvent. // Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel); virtual void handle_event(uint32_t event_type, const std::string &elabel);
//===================================================// //===================================================//
// p3Config methods // // p3Config methods //
//===================================================// //===================================================//
// Load/save the routing info, the pending items in transit, and the config variables. // Load/save the routing info, the pending items in transit, and the config variables.
// //
virtual bool loadList(std::list<RsItem*>& items) ; virtual bool loadList(std::list<RsItem*>& items) ;
virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ; virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ;
virtual RsSerialiser *setupSerialiser() ; virtual RsSerialiser *setupSerialiser() ;
private: private:
/************************************************************************ /************************************************************************
* This is the Cache for minimising calls to the DataStore. * This is the Cache for minimising calls to the DataStore.
* *
*/ */
@ -348,7 +350,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool cache_store(const RsGxsIdGroupItem *item); bool cache_store(const RsGxsIdGroupItem *item);
bool cache_update_if_cached(const RsGxsId &id, std::string serviceString); bool cache_update_if_cached(const RsGxsId &id, std::string serviceString);
bool isPendingNetworkRequest(const RsGxsId& gxsId); bool isPendingNetworkRequest(const RsGxsId& gxsId);
void requestIdsFromNet(); void requestIdsFromNet();
// Mutex protected. // Mutex protected.
@ -359,7 +361,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
// Switching to RsMemCache for Key Caching. // Switching to RsMemCache for Key Caching.
RsMemCache<RsGxsId, RsGxsIdCache> mKeyCache; RsMemCache<RsGxsId, RsGxsIdCache> mKeyCache;
/************************************************************************ /************************************************************************
* Refreshing own Ids. * Refreshing own Ids.
* *
*/ */
@ -368,7 +370,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
std::list<RsGxsId> mOwnIds; std::list<RsGxsId> mOwnIds;
/************************************************************************ /************************************************************************
* Test fns for Caching. * Test fns for Caching.
* *
*/ */
@ -376,7 +378,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool cachetest_getlist(); bool cachetest_getlist();
bool cachetest_handlerequest(uint32_t token); bool cachetest_handlerequest(uint32_t token);
/************************************************************************ /************************************************************************
* for processing background tasks that use the serviceString. * for processing background tasks that use the serviceString.
* - must be mutually exclusive to avoid clashes. * - must be mutually exclusive to avoid clashes.
*/ */
@ -386,7 +388,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool mBgSchedule_Active; bool mBgSchedule_Active;
uint32_t mBgSchedule_Mode; uint32_t mBgSchedule_Mode;
/************************************************************************ /************************************************************************
* pgphash processing. * pgphash processing.
* *
*/ */
@ -394,7 +396,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool pgphash_handlerequest(uint32_t token); bool pgphash_handlerequest(uint32_t token);
bool pgphash_process(); bool pgphash_process();
bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id, bool &error); bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id, bool &error);
void getPgpIdList(); void getPgpIdList();
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */ /* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
@ -402,7 +404,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
std::map<RsPgpId, PGPFingerprintType> mPgpFingerprintMap; std::map<RsPgpId, PGPFingerprintType> mPgpFingerprintMap;
std::list<RsGxsIdGroup> mGroupsToProcess; std::list<RsGxsIdGroup> mGroupsToProcess;
/************************************************************************ /************************************************************************
* recogn processing. * recogn processing.
* *
*/ */
@ -420,7 +422,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
void loadRecognKeys(); void loadRecognKeys();
/************************************************************************ /************************************************************************
* opinion processing. * opinion processing.
* *
*/ */
@ -448,24 +450,24 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
std::map<RsGxsId, RsGxsRecognSignerItem *> mRecognSignKeys; std::map<RsGxsId, RsGxsRecognSignerItem *> mRecognSignKeys;
std::map<RsGxsId, uint32_t> mRecognOldSignKeys; std::map<RsGxsId, uint32_t> mRecognOldSignKeys;
/************************************************************************ /************************************************************************
* Below is the background task for processing opinions => reputations * Below is the background task for processing opinions => reputations
* *
*/ */
virtual void generateDummyData(); virtual void generateDummyData();
void generateDummy_OwnIds(); void generateDummy_OwnIds();
void generateDummy_FriendPGP(); void generateDummy_FriendPGP();
void generateDummy_UnknownPGP(); void generateDummy_UnknownPGP();
void generateDummy_UnknownPseudo(); void generateDummy_UnknownPseudo();
void cleanUnusedKeys() ; void cleanUnusedKeys() ;
void slowIndicateConfigChanged() ; void slowIndicateConfigChanged() ;
virtual void timeStampKey(const RsGxsId& id) ; virtual void timeStampKey(const RsGxsId& id) ;
time_t locked_getLastUsageTS(const RsGxsId& gxs_id); time_t locked_getLastUsageTS(const RsGxsId& gxs_id);
std::string genRandomId(int len = 20); std::string genRandomId(int len = 20);
#if 0 #if 0
bool reputation_start(); bool reputation_start();
@ -478,7 +480,7 @@ std::string genRandomId(int len = 20);
bool background_processNewMessages(); bool background_processNewMessages();
bool background_FullCalcRequest(); bool background_FullCalcRequest();
bool background_processFullCalc(); bool background_processFullCalc();
bool background_cleanup(); bool background_cleanup();
#endif #endif
@ -488,40 +490,40 @@ std::string genRandomId(int len = 20);
/***** below here is locked *****/ /***** below here is locked *****/
bool mLastBgCheck; bool mLastBgCheck;
bool mBgProcessing; bool mBgProcessing;
uint32_t mBgToken; uint32_t mBgToken;
uint32_t mBgPhase; uint32_t mBgPhase;
std::map<RsGxsGroupId, RsGroupMetaData> mBgGroupMap; std::map<RsGxsGroupId, RsGroupMetaData> mBgGroupMap;
std::list<RsGxsGroupId> mBgFullCalcGroups; std::list<RsGxsGroupId> mBgFullCalcGroups;
#endif #endif
/************************************************************************ /************************************************************************
* Other Data that is protected by the Mutex. * Other Data that is protected by the Mutex.
*/ */
private: private:
std::map<uint32_t, std::set<RsGxsGroupId> > mIdsPendingCache; std::map<uint32_t, std::set<RsGxsGroupId> > mIdsPendingCache;
std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent; std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent;
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent; std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
std::map<RsGxsId,time_t> mKeysTS ; std::map<RsGxsId,time_t> mKeysTS ;
// keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only. // keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only.
std::set<RsGxsId> mContacts; std::set<RsGxsId> mContacts;
RsNetworkExchangeService* mNes; RsNetworkExchangeService* mNes;
/************************** /**************************
* AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.) * AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.)
* without depending directly on all these classes. * without depending directly on all these classes.
*/ */
PgpAuxUtils *mPgpUtils; PgpAuxUtils *mPgpUtils;
time_t mLastKeyCleaningTime ; time_t mLastKeyCleaningTime ;
time_t mLastConfigUpdate ; time_t mLastConfigUpdate ;
bool mOwnIdsLoaded ; bool mOwnIdsLoaded ;
}; };
#endif // P3_IDENTITY_SERVICE_HEADER #endif // P3_IDENTITY_SERVICE_HEADER

View file

@ -64,8 +64,8 @@ class rsUdpStack: public UdpStack, public pqiNetListener
/* from pqiNetListener */ /* from pqiNetListener */
virtual bool resetListener(const struct sockaddr_storage &local) virtual bool resetListener(const struct sockaddr_storage &local)
{ {
std::cerr << "rsUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")"; //std::cerr << "rsUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
std::cerr << std::endl; //std::cerr << std::endl;
if (local.ss_family != AF_INET) if (local.ss_family != AF_INET)
{ {
@ -90,16 +90,16 @@ class rsFixedUdpStack: public UdpStack, public pqiNetListener
:UdpStack(testmode, local) { return; } :UdpStack(testmode, local) { return; }
/* from pqiNetListener */ /* from pqiNetListener */
virtual bool resetListener(const struct sockaddr_storage &local) virtual bool resetListener(const struct sockaddr_storage & /* local */)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
getLocalAddress(addr); getLocalAddress(addr);
// The const_cast below is not so nice but without it, the compiler can't // The const_cast below is not so nice but without it, the compiler can't
// find the correct operator<<(). No idea why! // find the correct operator<<(). No idea why!
std::cerr << "rsFixedUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")"; //std::cerr << "rsFixedUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
std::cerr << " Resetting with original addr: " << const_cast<const struct sockaddr_in &>(addr); //std::cerr << " Resetting with original addr: " << const_cast<const struct sockaddr_in &>(addr);
std::cerr << std::endl; //std::cerr << std::endl;
return resetAddress(addr); return resetAddress(addr);
} }

View file

@ -26,7 +26,6 @@
#include "gui/common/UIStateHelper.h" #include "gui/common/UIStateHelper.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsreputations.h>
// Data Requests. // Data Requests.
#define IDDETAILSDIALOG_IDDETAILS 1 #define IDDETAILSDIALOG_IDDETAILS 1
@ -261,7 +260,7 @@ void IdDetailsDialog::insertIdDetails(uint32_t token)
#endif #endif
RsReputations::ReputationInfo info ; RsReputations::ReputationInfo info ;
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ; rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),data.mPgpId,info) ;
ui->neighborNodesOpinion_TF->setText(QString::number(info.mOverallReputationScore-1.0f)); ui->neighborNodesOpinion_TF->setText(QString::number(info.mOverallReputationScore-1.0f));

View file

@ -41,7 +41,6 @@
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsreputations.h>
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
#include <iostream> #include <iostream>
@ -1360,25 +1359,31 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item,
if (!item) if (!item)
item = new TreeWidgetItem(); item = new TreeWidgetItem();
RsReputations::ReputationInfo info ; RsIdentityDetails idd ;
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ; rsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId),idd) ;
item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE)); item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE));
item->setText(RSID_COL_KEYID, QString::fromStdString(data.mMeta.mGroupId.toStdString())); item->setText(RSID_COL_KEYID, QString::fromStdString(data.mMeta.mGroupId.toStdString()));
//time_t now = time(NULL) ; if(idd.mReputation.mAssessment == RsReputations::ASSESSMENT_BAD)
//item->setText(RSID_COL_LASTUSED, getHumanReadableDuration(now - data.mLastUsageTS)) ; {
item->setForeground(RSID_COL_NICKNAME,QBrush(Qt::red));
item->setForeground(RSID_COL_KEYID,QBrush(Qt::red));
item->setForeground(RSID_COL_IDTYPE,QBrush(Qt::red));
}
else
{
item->setForeground(RSID_COL_NICKNAME,QBrush(Qt::black));
item->setForeground(RSID_COL_KEYID,QBrush(Qt::black));
item->setForeground(RSID_COL_IDTYPE,QBrush(Qt::black));
}
item->setData(RSID_COL_KEYID, Qt::UserRole,QVariant(item_flags)) ; item->setData(RSID_COL_KEYID, Qt::UserRole,QVariant(item_flags)) ;
item->setTextAlignment(RSID_COL_VOTES, Qt::AlignRight); item->setTextAlignment(RSID_COL_VOTES, Qt::AlignRight);
item->setData(RSID_COL_VOTES,Qt::DisplayRole, QString::number(info.mOverallReputationScore - 1.0f,'f',3)); item->setData(RSID_COL_VOTES,Qt::DisplayRole, QString::number(idd.mReputation.mOverallReputationScore - 1.0f,'f',3));
if(isOwnId) if(isOwnId)
{ {
RsIdentityDetails idd ;
rsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId),idd) ;
QFont font = item->font(RSID_COL_NICKNAME) ; QFont font = item->font(RSID_COL_NICKNAME) ;
font.setBold(true) ; font.setBold(true) ;
@ -1740,12 +1745,12 @@ void IdDialog::insertIdDetails(uint32_t token)
#endif #endif
RsReputations::ReputationInfo info ; RsReputations::ReputationInfo info ;
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ; rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),data.mPgpId,info) ;
ui->neighborNodesOpinion_TF->setText(QString::number(info.mFriendAverage - 1.0f));
ui->overallOpinion_TF->setText(QString::number(info.mOverallReputationScore - 1.0f) +" ("+ ui->neighborNodesOpinion_TF->setText(QString::number(info.mFriendAverage - 1.0f));
((info.mAssessment == RsReputations::ASSESSMENT_OK)? tr("OK") : tr("Banned")) +")" ) ;
ui->overallOpinion_TF->setText(QString::number(info.mOverallReputationScore - 1.0f) +" ("+
((info.mAssessment == RsReputations::ASSESSMENT_OK)? tr("OK") : tr("Banned")) +")" ) ;
switch(info.mOwnOpinion) switch(info.mOwnOpinion)
{ {
@ -2021,10 +2026,10 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
#endif #endif
RsGxsId keyId((*it)->text(RSID_COL_KEYID).toStdString()); RsGxsId keyId((*it)->text(RSID_COL_KEYID).toStdString());
RsReputations::ReputationInfo info ; RsIdentityDetails det ;
rsReputations->getReputationInfo(keyId,info) ; rsIdentity->getIdDetails(keyId,det) ;
switch(info.mOwnOpinion) switch(det.mReputation.mOwnOpinion)
{ {
case RsReputations::OPINION_NEGATIVE: ++n_negative_reputations ; case RsReputations::OPINION_NEGATIVE: ++n_negative_reputations ;
break ; break ;

View file

@ -29,7 +29,6 @@
#include <math.h> #include <math.h>
#include "GxsIdDetails.h" #include "GxsIdDetails.h"
#include "retroshare-gui/RsAutoUpdatePage.h" #include "retroshare-gui/RsAutoUpdatePage.h"
#include "retroshare/rsreputations.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
@ -905,7 +904,7 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, QLi
QString GxsIdDetails::getName(const RsIdentityDetails &details) QString GxsIdDetails::getName(const RsIdentityDetails &details)
{ {
if(rsReputations->isIdentityBanned(details.mId)) if(rsIdentity->isBanned(details.mId))
return tr("[Banned]") ; return tr("[Banned]") ;
QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE); QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE);
@ -924,7 +923,7 @@ QString GxsIdDetails::getComment(const RsIdentityDetails &details)
QString comment; QString comment;
QString nickname ; QString nickname ;
bool banned = rsReputations->isIdentityBanned(details.mId) ; bool banned = rsIdentity->isBanned(details.mId) ;
if(details.mNickname.empty()) if(details.mNickname.empty())
nickname = tr("[Unknown]") ; nickname = tr("[Unknown]") ;
@ -963,7 +962,7 @@ void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList<QIcon> &icon
{ {
QPixmap pix ; QPixmap pix ;
if(rsReputations->isIdentityBanned(details.mId)) if(rsIdentity->isBanned(details.mId))
{ {
icons.clear() ; icons.clear() ;
icons.push_back(QIcon(IMAGE_BANNED)) ; icons.push_back(QIcon(IMAGE_BANNED)) ;

View file

@ -25,7 +25,6 @@
#include "GxsIdTreeWidgetItem.h" #include "GxsIdTreeWidgetItem.h"
#include "GxsIdDetails.h" #include "GxsIdDetails.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "retroshare/rsreputations.h"
#define BANNED_IMAGE ":/icons/yellow_biohazard64.png" #define BANNED_IMAGE ":/icons/yellow_biohazard64.png"
@ -117,14 +116,14 @@ void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column, bool retryWhenF
void GxsIdRSTreeWidgetItem::updateBannedState() void GxsIdRSTreeWidgetItem::updateBannedState()
{ {
if(mBannedState != rsReputations->isIdentityBanned(mId)) if(mBannedState != rsIdentity->isBanned(mId))
forceUpdate() ; forceUpdate() ;
} }
void GxsIdRSTreeWidgetItem::forceUpdate() void GxsIdRSTreeWidgetItem::forceUpdate()
{ {
mIdFound = false; mIdFound = false;
mBannedState = rsReputations->isIdentityBanned(mId) ; mBannedState = rsIdentity->isBanned(mId) ;
startProcess(); startProcess();
} }
@ -170,7 +169,7 @@ QVariant GxsIdRSTreeWidgetItem::data(int column, int role) const
if(mId.isNull()) if(mId.isNull())
return RSTreeWidgetItem::data(column, role); return RSTreeWidgetItem::data(column, role);
else if(rsReputations->isIdentityBanned(mId)) else if(rsIdentity->isBanned(mId))
pix = QImage(BANNED_IMAGE) ; pix = QImage(BANNED_IMAGE) ;
else if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG")) else if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG"))
pix = GxsIdDetails::makeDefaultIcon(mId); pix = GxsIdDetails::makeDefaultIcon(mId);

View file

@ -44,7 +44,6 @@
#include <retroshare/rsgxsforums.h> #include <retroshare/rsgxsforums.h>
#include <retroshare/rsgrouter.h> #include <retroshare/rsgrouter.h>
#include <retroshare/rsreputations.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
// These should be in retroshare/ folder. // These should be in retroshare/ folder.
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
@ -986,7 +985,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
// is flagged with a bad reputation // is flagged with a bad reputation
bool redacted = rsReputations->isIdentityBanned(msg.mMeta.mAuthorId) ; bool redacted = rsIdentity->isBanned(msg.mMeta.mAuthorId) ;
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_ALL || (redacted?(GxsIdDetails::ICON_TYPE_REDACTED):0)); GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_ALL || (redacted?(GxsIdDetails::ICON_TYPE_REDACTED):0));
item->moveToThread(ui->threadTreeWidget->thread()); item->moveToThread(ui->threadTreeWidget->thread());
@ -1409,7 +1408,7 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
return; return;
} }
bool redacted = rsReputations->isIdentityBanned(msg.mMeta.mAuthorId) ; bool redacted = rsIdentity->isBanned(msg.mMeta.mAuthorId) ;
mStateHelper->setActive(mTokenTypeMessageData, true); mStateHelper->setActive(mTokenTypeMessageData, true);