diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index 08f788218..609339edc 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 48778064f..e875f9fb4 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -2572,3 +2572,15 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp) return GxsSecurity::validateNxsGrp(newGrp, adminSign, keyMit->second) && latest; } + +bool 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)); + return true; +} diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index b495d7922..2e5143203 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -609,6 +609,15 @@ public: */ void setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, 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 + * @return true if set successfully + */ + bool setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff); + protected: /** Notifications **/ @@ -849,9 +858,15 @@ private: private: std::vector mGroupUpdates, mPeersGroupUpdate; - std::vector mGroupUpdatePublish; + struct CutOffEntry + { + uint32_t token; + RsGxsGroupId id; + uint32_t cutOff; + }; + }; #endif // RSGENEXCHANGE_H diff --git a/libretroshare/src/gxs/rsgxsdata.cc b/libretroshare/src/gxs/rsgxsdata.cc index 45f4db18f..a0a32a4a9 100644 --- a/libretroshare/src/gxs/rsgxsdata.cc +++ b/libretroshare/src/gxs/rsgxsdata.cc @@ -77,7 +77,7 @@ void RsGxsGrpMetaData::clear(){ mAuthenFlags = 0; mParentGrpId.clear(); mRecvTS = 0; - + mReputationCutOff = 0; } bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize) diff --git a/libretroshare/src/gxs/rsgxsdata.h b/libretroshare/src/gxs/rsgxsdata.h index 6fe905a9a..2419265e5 100644 --- a/libretroshare/src/gxs/rsgxsdata.h +++ b/libretroshare/src/gxs/rsgxsdata.h @@ -78,6 +78,7 @@ public: std::string mOriginator; std::string mInternalCircle; std::string mHash; + uint32_t mReputationCutOff; }; diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index a15336600..bb11e373c 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -1459,10 +1459,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 @@ -1521,19 +1525,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; @@ -1559,7 +1570,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..b232c96c0 100644 --- a/libretroshare/src/retroshare/rsgxsiface.h +++ b/libretroshare/src/retroshare/rsgxsiface.h @@ -184,6 +184,15 @@ 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 + * @return true if set successfully + */ + virtual bool 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..50125e536 100644 --- a/libretroshare/src/retroshare/rsgxsifacehelper.h +++ b/libretroshare/src/retroshare/rsgxsifacehelper.h @@ -238,6 +238,21 @@ 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 + * @return true if set successfully + */ + bool 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 a25cbee0c..eacbcc952 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1319,7 +1319,7 @@ int RsServer::StartupRetroShare() std::string currGxsDir = rsAccounts.PathAccountDirectory() + "/GXS_phase2"; #ifdef GXS_DEV_TESTNET // Different Directory for testing. - currGxsDir += "_TESTNET7"; + currGxsDir += "_TESTNET8"; #endif bool cleanUpGxsDir = false; diff --git a/libretroshare/src/util/retrodb.cc b/libretroshare/src/util/retrodb.cc index 967b1f98f..6fdbf9c8f 100644 --- a/libretroshare/src/util/retrodb.cc +++ b/libretroshare/src/util/retrodb.cc @@ -31,7 +31,7 @@ #include "retrodb.h" #include "rsdbbind.h" -//#define RETRODB_DEBUG +#define RETRODB_DEBUG #define ENABLE_ENCRYPTED_DB