added some backend for reputation system

This commit is contained in:
csoler 2015-10-04 23:14:49 -04:00
parent c17dddb79c
commit 317e7ea5ab
7 changed files with 54 additions and 26 deletions

View File

@ -708,6 +708,7 @@ gxs {
gxs/rsgxsnetservice.h \
retroshare/rsgxsflags.h \
retroshare/rsgxsifacetypes.h \
retroshare/rsreputations.h \
gxs/rsgenexchange.h \
gxs/rsnxsobserver.h \
gxs/rsgxsdata.h \

View File

@ -215,12 +215,6 @@ public:
/********************************************************************************************/
/********************************************************************************************/
enum Opinion {
OPINION_NEGATIVE = -1,
OPINION_NEUTRAL = 0,
OPINION_POSITIVE = 1
};
// 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.

View File

@ -40,6 +40,7 @@ extern RsPluginHandler *rsPlugins ;
class p3Service ;
class RsServiceControl ;
class RsReputations ;
class RsTurtle ;
class RsDht ;
class RsDisc ;
@ -116,6 +117,7 @@ public:
RsUtil::inited_ptr<PgpAuxUtils> mPgpAuxUtils;
RsUtil::inited_ptr<RsGxsForums> mGxsForums;
RsUtil::inited_ptr<RsGxsChannels> mGxsChannels;
RsUtil::inited_ptr<RsReputations> mReputations;
};
class RsPlugin

View File

@ -819,6 +819,7 @@ bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
RsFiles *rsFiles = NULL;
RsTurtle *rsTurtle = NULL ;
RsReputations *rsReputations = NULL ;
#ifdef ENABLE_GROUTER
RsGRouter *rsGRouter = NULL ;
#endif
@ -847,6 +848,7 @@ RsGRouter *rsGRouter = NULL ;
#endif
#endif
#include "services/p3gxsreputation.h"
#include "services/p3serviceinfo.h"
#include "services/p3heartbeat.h"
#include "services/p3discovery2.h"
@ -1357,6 +1359,11 @@ int RsServer::StartupRetroShare()
mPosted->setNetworkExchangeService(posted_ns) ;
/**** Reputation system ****/
p3GxsReputation *mReputations = new p3GxsReputation(mLinkMgr) ;
rsReputations = mReputations ;
/**** Wiki GXS service ****/
@ -1490,7 +1497,7 @@ int RsServer::StartupRetroShare()
pqih -> addService(msgSrv,true);
pqih -> addService(chatSrv,true);
pqih -> addService(mStatusSrv,true);
pqih -> addService(mReputations,true);
// set interfaces for plugins
//
@ -1511,6 +1518,8 @@ int RsServer::StartupRetroShare()
interfaces.mPgpAuxUtils = pgpAuxUtils;
interfaces.mGxsForums = mGxsForums;
interfaces.mGxsChannels = mGxsChannels;
interfaces.mReputations = mReputations;
mPluginsManager->setInterfaces(interfaces);
// now add plugin objects inside the loop:
@ -1604,6 +1613,7 @@ int RsServer::StartupRetroShare()
mConfigMgr->addConfiguration("turtle.cfg", tr);
mConfigMgr->addConfiguration("banlist.cfg", mBanList);
mConfigMgr->addConfiguration("servicecontrol.cfg", serviceCtrl);
mConfigMgr->addConfiguration("reputations.cfg", mReputations);
#ifdef ENABLE_GROUTER
mConfigMgr->addConfiguration("grouter.cfg", gr);
#endif

View File

@ -380,7 +380,13 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid, time_t ts)
* Opinion
****/
bool p3GxsReputation::updateOpinion(const RsGxsId& gxsid, int opinion)
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::ReputationInfo& info)
{
std::cerr << __PRETTY_FUNCTION__ << ": not implemented yet!" << std::endl;
return true ;
}
bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::Opinion& opinion)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/

View File

@ -35,6 +35,7 @@
#include "serialiser/rsgxsreputationitems.h"
#include "retroshare/rsidentity.h"
#include "retroshare/rsreputations.h"
#include "services/p3service.h"
@ -80,13 +81,15 @@ int32_t CalculateReputation();
*
*/
class p3GxsReputation: public p3Service, public p3Config /* , public pqiMonitor */
class p3GxsReputation: public p3Service, public p3Config, public RsReputations /* , public pqiMonitor */
{
public:
p3GxsReputation(p3LinkMgr *lm);
virtual RsServiceInfo getServiceInfo();
/***** Interface for p3idservice *****/
/***** Interface for RsReputations *****/
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) ;
virtual bool updateOpinion(const RsGxsId& gxsid, int opinion);

View File

@ -34,6 +34,7 @@
#include "gui/msgs/MessageComposer.h"
#include <retroshare/rspeers.h>
#include <retroshare/rsreputations.h>
#include "retroshare/rsgxsflags.h"
#include "retroshare/rsmsgs.h"
#include <iostream>
@ -676,13 +677,16 @@ void IdDialog::insertIdDetails(uint32_t token)
#endif
ui->overallOpinion_TF->setText(QString::number(data.mReputation.mOverallScore));
RsReputations::ReputationInfo info ;
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ;
ui->overallOpinion_TF->setText(QString::number(info.mOverallReputationScore));
switch(data.mReputation.mOwnOpinion)
{
case RsIdentity::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ;
case RsIdentity::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ;
case RsIdentity::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ;
case RsReputations::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ;
case RsReputations::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ;
case RsReputations::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ;
default:
std::cerr << "Unexpected value in own opinion: " << data.mReputation.mOwnOpinion << std::endl;
}
@ -699,23 +703,28 @@ void IdDialog::modifyReputation()
RsGxsId id(ui->lineEdit_KeyId->text().toStdString());
RsIdentity::Opinion op ;
RsReputations::Opinion op ;
switch(ui->ownOpinion_CB->currentIndex())
{
case 0: op = RsIdentity::OPINION_NEGATIVE ; break ;
case 1: op = RsIdentity::OPINION_NEUTRAL ; break ;
case 2: op = RsIdentity::OPINION_POSITIVE ; break ;
case 0: op = RsReputations::OPINION_NEGATIVE ; break ;
case 1: op = RsReputations::OPINION_NEUTRAL ; break ;
case 2: op = RsReputations::OPINION_POSITIVE ; break ;
default:
std::cerr << "Wrong value from opinion combobox. Bug??" << std::endl;
}
rsReputations->setOwnOpinion(id,op) ;
#ifdef ID_DEBUG
std::cerr << "IdDialog::modifyReputation() ID: " << id << " Mod: " << mod;
std::cerr << std::endl;
#endif
#ifdef SUSPENDED
// Cyril: apparently the old reputation system was in used here. It's based on GXS data exchange, and probably not
// very efficient because of this.
uint32_t token;
if (!rsIdentity->submitOpinion(token, id, false, op))
{
@ -724,15 +733,18 @@ void IdDialog::modifyReputation()
std::cerr << std::endl;
#endif
}
#endif
#ifdef ID_DEBUG
std::cerr << "IdDialog::modifyReputation() queuingRequest(), token: " << token;
std::cerr << std::endl;
#endif
#ifdef SUSPENDED
// trigger refresh when finished.
// basic / anstype are not needed.
mIdQueue->queueRequest(token, 0, 0, IDDIALOG_REFRESH);
#endif
return;
}