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
This commit is contained in:
chrisparker126 2014-02-23 00:08:11 +00:00
parent 265bc65299
commit 15af443c31
10 changed files with 73 additions and 11 deletions

View File

@ -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;
@ -176,6 +179,7 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
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_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<RsNxsGrp *, RsGxsGrpMetaData *> &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);

View File

@ -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:

View File

@ -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));
}

View File

@ -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

View File

@ -77,6 +77,7 @@ void RsGxsGrpMetaData::clear(){
mAuthenFlags = 0;
mParentGrpId.clear();
mRecvTS = 0;
mReputationCutOff = 0;
}

View File

@ -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;

View File

@ -1464,10 +1464,14 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
RsNxsSyncMsgItem* item = msgItemL.front();
const std::string& grpId = item->grpId;
// std::map<std::string, RsGxsGrpMetaData*> grpMetaMap;
// grpMetaMap[grpId] = NULL;
// mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
// RsGxsGrpMetaData* grpMeta = grpMetaMap[grpId];
std::map<std::string, RsGxsGrpMetaData*> 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);
}

View File

@ -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;
};

View File

@ -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;

View File

@ -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;