/* * libretroshare/src/services/p3gxsreputation.h * * Exchange list of Peers Reputations. * * Copyright 2014 by Robert Fernie. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License Version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Please report all bugs and problems to "retroshare@lunamutt.com". * */ #ifndef SERVICE_RSGXSREPUTATION_HEADER #define SERVICE_RSGXSREPUTATION_HEADER #include #include #include #include #include "serialiser/rsgxsreputationitems.h" #include "retroshare/rsidentity.h" #include "retroshare/rsreputations.h" #include "services/p3service.h" class p3LinkMgr; class ReputationConfig { public: ReputationConfig() :mPeerId(), mLatestUpdate(0), mLastQuery(0) { return; } ReputationConfig(const RsPeerId& peerId) :mPeerId(peerId), mLatestUpdate(0), mLastQuery(0) { return; } RsPeerId mPeerId; time_t mLatestUpdate; time_t mLastQuery; }; class Reputation { public: Reputation() :mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0), mReputation(RsReputations::OPINION_NEUTRAL) { } Reputation(const RsGxsId& about) :mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0), mReputation(RsReputations::OPINION_NEUTRAL) { } float CalculateReputation(uint32_t average_active_friends); std::map mOpinions; int32_t mOwnOpinion; time_t mOwnOpinionTs; float mReputation; }; //!The p3GxsReputation service. /** * * */ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /* , public pqiMonitor */ { public: p3GxsReputation(p3LinkMgr *lm); virtual RsServiceInfo getServiceInfo(); /***** Interface for RsReputations *****/ virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ; virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) ; virtual bool isIdentityOk(const RsGxsId& id) ; /***** overloaded from p3Service *****/ virtual int tick(); virtual int status(); /*! * Interface stuff. */ /************* from p3Config *******************/ virtual RsSerialiser *setupSerialiser() ; virtual bool saveList(bool& cleanup, std::list&) ; virtual void saveDone(); virtual bool loadList(std::list& load) ; private: bool processIncoming(); bool SendReputations(RsGxsReputationRequestItem *request); bool RecvReputations(RsGxsReputationUpdateItem *item); bool updateLatestUpdate(RsPeerId peerid, time_t ts); void updateActiveFriends() ; // internal update of data. Takes care of cleaning empty boxes. void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op); bool loadReputationSet(RsGxsReputationSetItem *item, const std::set &peerSet); int sendPackets(); void sendReputationRequests(); int sendReputationRequest(RsPeerId peerid); private: RsMutex mReputationMtx; time_t mLastActiveFriendsUpdate; time_t mRequestTime; time_t mStoreTime; bool mReputationsUpdated; uint32_t mAverageActiveFriends ; p3LinkMgr *mLinkMgr; // Data for Reputation. std::map mConfig; std::map mReputations; std::multimap mUpdated; // set of Reputations to send to p3IdService. std::set mUpdatedReputations; }; #endif //SERVICE_RSGXSREPUTATION_HEADER