From 15af443c31f703e2a94822208c3c88826d7cb5e4 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sun, 23 Feb 2014 00:08:11 +0000 Subject: [PATCH] Added reputation filtering to genexchange and reputation threshold setting function - NOTE: you will lose all data with this build, new db schema Checked into wrong repo folder on previous commit git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7147 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/gxs/rsdataservice.cc | 9 +++++- libretroshare/src/gxs/rsgds.h | 1 + libretroshare/src/gxs/rsgenexchange.cc | 11 +++++++ libretroshare/src/gxs/rsgenexchange.h | 8 +++++ libretroshare/src/gxs/rsgxsdata.cc | 1 + libretroshare/src/gxs/rsgxsdata.h | 1 + libretroshare/src/gxs/rsgxsnetservice.cc | 29 +++++++++++++------ libretroshare/src/retroshare/rsgxsiface.h | 8 +++++ .../src/retroshare/rsgxsifacehelper.h | 14 +++++++++ libretroshare/src/rsserver/rsinit.cc | 2 +- 10 files changed, 73 insertions(+), 11 deletions(-) diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index 8a1626323..6aa772308 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -70,6 +70,7 @@ #define KEY_MSG_COUNT std::string("msgCount") #define KEY_GRP_STATUS std::string("grpStatus") #define KEY_GRP_LAST_POST std::string("lastPost") +#define KEY_GRP_REP_CUTOFF std::string("rep_cutoff") // msg table columns @@ -117,6 +118,7 @@ #define COL_GRP_AUTHEN_FLAGS 20 #define COL_PARENT_GRP_ID 21 #define COL_GRP_RECV_TS 22 +#define COL_GRP_REP_CUTOFF 23 // msg col numbers @@ -143,6 +145,7 @@ const std::string RsGeneralDataService::GRP_META_SERV_STRING = KEY_NXS_SERV_STRING; const std::string RsGeneralDataService::GRP_META_STATUS = KEY_GRP_STATUS; const std::string RsGeneralDataService::GRP_META_SUBSCRIBE_FLAG = KEY_GRP_SUBCR_FLAG; +const std::string RsGeneralDataService::GRP_META_CUTOFF_LEVEL = KEY_GRP_REP_CUTOFF; const std::string RsGeneralDataService::MSG_META_SERV_STRING = KEY_NXS_SERV_STRING; const std::string RsGeneralDataService::MSG_META_STATUS = KEY_MSG_STATUS; @@ -175,7 +178,8 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d grpMetaColumns.push_back(KEY_GRP_LAST_POST); grpMetaColumns.push_back(KEY_ORIG_GRP_ID); grpMetaColumns.push_back(KEY_NXS_SERV_STRING); grpMetaColumns.push_back(KEY_GRP_SIGN_FLAGS); grpMetaColumns.push_back(KEY_GRP_CIRCLE_ID); grpMetaColumns.push_back(KEY_GRP_CIRCLE_TYPE); grpMetaColumns.push_back(KEY_GRP_INTERNAL_CIRCLE); grpMetaColumns.push_back(KEY_GRP_ORIGINATOR); - grpMetaColumns.push_back(KEY_GRP_AUTHEN_FLAGS); grpMetaColumns.push_back(KEY_PARENT_GRP_ID); grpMetaColumns.push_back(KEY_RECV_TS); + grpMetaColumns.push_back(KEY_GRP_AUTHEN_FLAGS); grpMetaColumns.push_back(KEY_PARENT_GRP_ID); grpMetaColumns.push_back(KEY_RECV_TS); + grpMetaColumns.push_back(KEY_GRP_REP_CUTOFF); // for retrieving actual grp data @@ -251,6 +255,7 @@ void RsDataService::initialise(){ KEY_NXS_HASH + " TEXT," + KEY_RECV_TS + " INT," + KEY_PARENT_GRP_ID + " TEXT," + + KEY_GRP_REP_CUTOFF + " INT," + KEY_SIGN_SET + " BLOB);"); mDb->execSQL("CREATE TRIGGER " + GRP_LAST_POST_UPDATE_TRIGGER + @@ -284,6 +289,7 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c) c.getString(COL_ORIG_GRP_ID, grpMeta->mOrigGrpId); c.getString(COL_GRP_SERV_STRING, grpMeta->mServiceString); c.getString(COL_HASH, grpMeta->mHash); + grpMeta->mReputationCutOff = c.getInt32(COL_GRP_REP_CUTOFF); grpMeta->mSignFlags = c.getInt32(COL_GRP_SIGN_FLAGS); grpMeta->mPublishTs = c.getInt32(COL_TIME_STAMP); @@ -622,6 +628,7 @@ int RsDataService::storeGroup(std::map &grp) cv.put(KEY_PARENT_GRP_ID, grpMetaPtr->mParentGrpId); cv.put(KEY_NXS_HASH, grpMetaPtr->mHash); cv.put(KEY_RECV_TS, (int32_t)grpMetaPtr->mRecvTS); + cv.put(KEY_GRP_REP_CUTOFF, (int32_t)grpMetaPtr->mReputationCutOff); if(! (grpMetaPtr->mAuthorId.empty()) ){ cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId); diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index c2ba4d8ac..5aada4d27 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -113,6 +113,7 @@ public: static const std::string GRP_META_SUBSCRIBE_FLAG; static const std::string GRP_META_STATUS; static const std::string GRP_META_SERV_STRING; + static const std::string GRP_META_CUTOFF_LEVEL; public: diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 4f7192eda..09b3b5c83 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -2559,3 +2559,14 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp) return GxsSecurity::validateNxsGrp(newGrp, adminSign, keyMit->second) && latest; } + +void RsGenExchange::setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff) +{ + RsStackMutex stack(mGenMtx); + token = mDataAccess->generatePublicToken(); + + GrpLocMetaData g; + g.grpId = grpId; + g.val.put(RsGeneralDataService::GRP_META_CUTOFF_LEVEL, (int32_t)CutOff); + mGrpLocMetaMap.insert(std::make_pair(token, g)); +} diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index f73d82f18..a420c544e 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -592,6 +592,14 @@ public: */ void setGroupServiceString(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString); + /*! + * + * @param token value set to be redeemed with acknowledgement + * @param grpId group id for cutoff value to be set + * @param CutOff The cut off value to set + */ + void setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff); + /*! * sets the msg status flag * @param token this is set to token value associated to this request diff --git a/libretroshare/src/gxs/rsgxsdata.cc b/libretroshare/src/gxs/rsgxsdata.cc index 45f4db18f..d867441b5 100644 --- a/libretroshare/src/gxs/rsgxsdata.cc +++ b/libretroshare/src/gxs/rsgxsdata.cc @@ -77,6 +77,7 @@ void RsGxsGrpMetaData::clear(){ mAuthenFlags = 0; mParentGrpId.clear(); mRecvTS = 0; + mReputationCutOff = 0; } diff --git a/libretroshare/src/gxs/rsgxsdata.h b/libretroshare/src/gxs/rsgxsdata.h index 6fe905a9a..8e5f1aa05 100644 --- a/libretroshare/src/gxs/rsgxsdata.h +++ b/libretroshare/src/gxs/rsgxsdata.h @@ -72,6 +72,7 @@ public: uint32_t mPop; // HOW DO WE DO THIS NOW. uint32_t mMsgCount; // ??? uint32_t mLastPost; // ??? + uint32_t mReputationCutOff; uint32_t mGroupStatus; uint32_t mRecvTS; diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index dce2b1337..ab27c9b75 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -1464,10 +1464,14 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr) RsNxsSyncMsgItem* item = msgItemL.front(); const std::string& grpId = item->grpId; -// std::map grpMetaMap; -// grpMetaMap[grpId] = NULL; -// mDataStore->retrieveGxsGrpMetaData(grpMetaMap); -// RsGxsGrpMetaData* grpMeta = grpMetaMap[grpId]; + std::map grpMetaMap; + grpMetaMap[grpId] = NULL; + mDataStore->retrieveGxsGrpMetaData(grpMetaMap); + RsGxsGrpMetaData* grpMeta = grpMetaMap[grpId]; + + int cutoff = 0; + if(grpMeta != NULL) + cutoff = grpMeta->mReputationCutOff; // // // you want to find out if you can receive it // // number polls essentially represent multiple @@ -1526,19 +1530,26 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr) if(msgIdSet.find(msgId) == msgIdSet.end()){ + // if reputation is in reputations cache then proceed + // or if there isn't an author (note as author requirement is + // enforced at service level, if no author is needed then reputation + // filtering is optional) bool noAuthor = syncItem->authorId.empty(); + + // grp meta must be present if author present + if(!noAuthor && grpMeta == NULL) + continue; + if(mReputations->haveReputation(syncItem->authorId) || noAuthor) { - - GixsReputation rep; - if(!noAuthor) // has author + if(!noAuthor) mReputations->getReputation(syncItem->authorId, rep); // if author is required for this message, it will simply get dropped // at genexchange side of things - if(rep.score > GIXS_CUT_OFF || noAuthor) + if(rep.score > grpMeta->mReputationCutOff || noAuthor) { RsNxsSyncMsgItem* msgItem = new RsNxsSyncMsgItem(mServType); msgItem->grpId = grpId; @@ -1564,7 +1575,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr) if(!toVet.empty()) { - MsgRespPending* mrp = new MsgRespPending(mReputations, tr->mTransaction->PeerId(), toVet); + MsgRespPending* mrp = new MsgRespPending(mReputations, tr->mTransaction->PeerId(), toVet, cutoff); mPendingResp.push_back(mrp); } diff --git a/libretroshare/src/retroshare/rsgxsiface.h b/libretroshare/src/retroshare/rsgxsiface.h index 9bb29b064..9a19d9b9d 100644 --- a/libretroshare/src/retroshare/rsgxsiface.h +++ b/libretroshare/src/retroshare/rsgxsiface.h @@ -184,6 +184,14 @@ public: * @return true if token is false otherwise */ virtual bool getGroupStatistic(const uint32_t& token, GxsGroupStatistic& stats) = 0; + + /*! + * + * @param token value set to be redeemed with acknowledgement + * @param grpId group id for cutoff value to be set + * @param CutOff The cut off value to set + */ + virtual void setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff) = 0; }; diff --git a/libretroshare/src/retroshare/rsgxsifacehelper.h b/libretroshare/src/retroshare/rsgxsifacehelper.h index 4b9ef2ede..20dede9e5 100644 --- a/libretroshare/src/retroshare/rsgxsifacehelper.h +++ b/libretroshare/src/retroshare/rsgxsifacehelper.h @@ -238,6 +238,20 @@ public: return mGxs->getGroupStatistic(token, stats); } + + /*! + * This determines the reputation threshold messages need to surpass in order + * for it to be accepted by local user from remote source + * NOTE: threshold only enforced if service require author signature + * @param token value set to be redeemed with acknowledgement + * @param grpId group id for cutoff value to be set + * @param CutOff The cut off value to set + */ + void setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff) + { + return mGxs->setGroupReputationCutOff(token, grpId, CutOff); + } + private: RsGxsIface* mGxs; diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index aaa44b746..b87a5398c 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1364,7 +1364,7 @@ int RsServer::StartupRetroShare() std::string currGxsDir = rsAccounts.PathAccountDirectory() + "/GXS_phase2"; #ifdef GXS_DEV_TESTNET // Different Directory for testing. - currGxsDir += "_TESTNET8"; + currGxsDir += "_TESTNET9"; #endif bool cleanUpGxsDir = false;