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 \ gxs/rsgxsnetservice.h \
retroshare/rsgxsflags.h \ retroshare/rsgxsflags.h \
retroshare/rsgxsifacetypes.h \ retroshare/rsgxsifacetypes.h \
retroshare/rsreputations.h \
gxs/rsgenexchange.h \ gxs/rsgenexchange.h \
gxs/rsnxsobserver.h \ gxs/rsnxsobserver.h \
gxs/rsgxsdata.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.... // For Other Services....
// It should be impossible for them to get a message which we don't have the identity. // 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. // Its a major error if we don't have the identity.

View File

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

View File

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

View File

@ -380,7 +380,13 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid, time_t ts)
* Opinion * 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 *******/ RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/

View File

@ -35,6 +35,7 @@
#include "serialiser/rsgxsreputationitems.h" #include "serialiser/rsgxsreputationitems.h"
#include "retroshare/rsidentity.h" #include "retroshare/rsidentity.h"
#include "retroshare/rsreputations.h"
#include "services/p3service.h" #include "services/p3service.h"
@ -80,14 +81,16 @@ int32_t CalculateReputation();
* *
*/ */
class p3GxsReputation: public p3Service, public p3Config /* , public pqiMonitor */ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /* , public pqiMonitor */
{ {
public: public:
p3GxsReputation(p3LinkMgr *lm); p3GxsReputation(p3LinkMgr *lm);
virtual RsServiceInfo getServiceInfo(); 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); virtual bool updateOpinion(const RsGxsId& gxsid, int opinion);
/***** overloaded from p3Service *****/ /***** overloaded from p3Service *****/

View File

@ -34,6 +34,7 @@
#include "gui/msgs/MessageComposer.h" #include "gui/msgs/MessageComposer.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsreputations.h>
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
#include <iostream> #include <iostream>
@ -676,13 +677,16 @@ void IdDialog::insertIdDetails(uint32_t token)
#endif #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) switch(data.mReputation.mOwnOpinion)
{ {
case RsIdentity::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ; case RsReputations::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ;
case RsIdentity::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ; case RsReputations::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ;
case RsIdentity::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ; case RsReputations::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ;
default: default:
std::cerr << "Unexpected value in own opinion: " << data.mReputation.mOwnOpinion << std::endl; 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()); RsGxsId id(ui->lineEdit_KeyId->text().toStdString());
RsIdentity::Opinion op ; RsReputations::Opinion op ;
switch(ui->ownOpinion_CB->currentIndex()) switch(ui->ownOpinion_CB->currentIndex())
{ {
case 0: op = RsIdentity::OPINION_NEGATIVE ; break ; case 0: op = RsReputations::OPINION_NEGATIVE ; break ;
case 1: op = RsIdentity::OPINION_NEUTRAL ; break ; case 1: op = RsReputations::OPINION_NEUTRAL ; break ;
case 2: op = RsIdentity::OPINION_POSITIVE ; break ; case 2: op = RsReputations::OPINION_POSITIVE ; break ;
default: default:
std::cerr << "Wrong value from opinion combobox. Bug??" << std::endl; std::cerr << "Wrong value from opinion combobox. Bug??" << std::endl;
} }
rsReputations->setOwnOpinion(id,op) ;
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << "IdDialog::modifyReputation() ID: " << id << " Mod: " << mod; std::cerr << "IdDialog::modifyReputation() ID: " << id << " Mod: " << mod;
std::cerr << std::endl; std::cerr << std::endl;
#endif #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; uint32_t token;
if (!rsIdentity->submitOpinion(token, id, false, op)) if (!rsIdentity->submitOpinion(token, id, false, op))
{ {
@ -724,15 +733,18 @@ void IdDialog::modifyReputation()
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
#endif
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << "IdDialog::modifyReputation() queuingRequest(), token: " << token; std::cerr << "IdDialog::modifyReputation() queuingRequest(), token: " << token;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
#ifdef SUSPENDED
// trigger refresh when finished. // trigger refresh when finished.
// basic / anstype are not needed. // basic / anstype are not needed.
mIdQueue->queueRequest(token, 0, 0, IDDIALOG_REFRESH); mIdQueue->queueRequest(token, 0, 0, IDDIALOG_REFRESH);
#endif
return; return;
} }