mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Added reputation filtering to genexchange and reputation threshold setting function
- NOTE: you will lose all data with this build, new db schema git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@7141 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7ca3ed78ae
commit
be58dd292a
@ -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<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);
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<GroupUpdate> mGroupUpdates, mPeersGroupUpdate;
|
||||
|
||||
std::vector<GroupUpdatePublish> mGroupUpdatePublish;
|
||||
|
||||
struct CutOffEntry
|
||||
{
|
||||
uint32_t token;
|
||||
RsGxsGroupId id;
|
||||
uint32_t cutOff;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // RSGENEXCHANGE_H
|
||||
|
@ -77,7 +77,7 @@ void RsGxsGrpMetaData::clear(){
|
||||
mAuthenFlags = 0;
|
||||
mParentGrpId.clear();
|
||||
mRecvTS = 0;
|
||||
|
||||
mReputationCutOff = 0;
|
||||
}
|
||||
|
||||
bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize)
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
std::string mOriginator;
|
||||
std::string mInternalCircle;
|
||||
std::string mHash;
|
||||
uint32_t mReputationCutOff;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1459,10 +1459,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
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "retrodb.h"
|
||||
#include "rsdbbind.h"
|
||||
|
||||
//#define RETRODB_DEBUG
|
||||
#define RETRODB_DEBUG
|
||||
#define ENABLE_ENCRYPTED_DB
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user