2008-02-03 01:29:02 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services: p3ranking.h
|
|
|
|
*
|
|
|
|
* 3P/PQI network interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2007-2008 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 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 P3_GENERIC_RANKING_HEADER
|
|
|
|
#define P3_GENERIC_RANKING_HEADER
|
|
|
|
|
|
|
|
#include "dbase/cachestrapper.h"
|
|
|
|
#include "pqi/pqiservice.h"
|
2009-05-12 17:55:50 -04:00
|
|
|
#include "pqi/pqistore.h"
|
2008-03-31 10:06:59 -04:00
|
|
|
#include "pqi/p3connmgr.h"
|
2008-04-15 12:35:46 -04:00
|
|
|
#include "pqi/p3cfgmgr.h"
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
#include "serialiser/rsserial.h"
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsrank.h"
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A Generic Ranking system.
|
|
|
|
* Each User provides one cache...
|
|
|
|
*
|
|
|
|
* can be overloaded for specific types
|
|
|
|
* (links, shares, photos etc)
|
2008-02-05 08:45:04 -05:00
|
|
|
*
|
|
|
|
* This is not generic yet!!!
|
2008-02-03 01:29:02 -05:00
|
|
|
*/
|
|
|
|
|
2008-02-05 08:45:04 -05:00
|
|
|
class RsRankMsg;
|
|
|
|
class RsRankLinkMsg;
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
class RankGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
std::string rid; /* Random Id */
|
|
|
|
std::wstring link;
|
|
|
|
std::wstring title;
|
|
|
|
float rank;
|
|
|
|
bool ownTag;
|
2008-02-05 08:45:04 -05:00
|
|
|
std::map<std::string, RsRankLinkMsg *> comments;
|
2008-02-03 01:29:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-15 12:35:46 -04:00
|
|
|
class p3Ranking: public CacheSource, public CacheStore, public p3Config
|
2008-02-03 01:29:02 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-03-31 10:06:59 -04:00
|
|
|
p3Ranking(p3ConnectMgr *connMgr,
|
|
|
|
uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
2008-02-03 01:29:02 -05:00
|
|
|
std::string sourcedir, std::string storedir,
|
|
|
|
uint32_t storePeriod);
|
|
|
|
|
|
|
|
/******************************* CACHE SOURCE / STORE Interface *********************/
|
|
|
|
|
|
|
|
/* overloaded functions from Cache Source */
|
|
|
|
virtual bool loadLocalCache(const CacheData &data);
|
|
|
|
|
|
|
|
/* overloaded functions from Cache Store */
|
|
|
|
virtual int loadCache(const CacheData &data);
|
|
|
|
|
|
|
|
/******************************* CACHE SOURCE / STORE Interface *********************/
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/************* Extern Interface *******/
|
|
|
|
|
2008-03-17 09:51:04 -04:00
|
|
|
/* changed */
|
|
|
|
virtual bool updated();
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* Set Sort Methods */
|
|
|
|
virtual bool setSortPeriod(uint32_t period);
|
|
|
|
virtual bool setSortMethod(uint32_t type);
|
|
|
|
virtual bool clearPeerFilter();
|
|
|
|
virtual bool setPeerFilter(std::list<std::string> peers);
|
|
|
|
|
|
|
|
/* get Ids */
|
|
|
|
virtual uint32_t getRankingsCount();
|
|
|
|
virtual float getMaxRank();
|
|
|
|
virtual bool getRankings(uint32_t first, uint32_t count, std::list<std::string> &rids);
|
|
|
|
virtual bool getRankDetails(std::string rid, RsRankDetails &details);
|
|
|
|
|
|
|
|
/* Add New Comment / Msg */
|
2008-04-15 12:35:46 -04:00
|
|
|
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score);
|
|
|
|
virtual bool updateComment(std::string rid, std::wstring comment, int32_t score);
|
2008-05-13 11:41:40 -04:00
|
|
|
virtual std::string anonRankMsg(std::string rid, std::wstring link, std::wstring title);
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
void tick();
|
|
|
|
|
|
|
|
void loadRankFile(std::string filename, std::string src);
|
2008-02-05 08:45:04 -05:00
|
|
|
void addRankMsg(RsRankLinkMsg *msg);
|
2008-03-31 10:06:59 -04:00
|
|
|
void publishMsgs(bool own);
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
float locked_calcRank(RankGroup &grp); /* returns 0->100 */
|
2008-02-07 11:18:34 -05:00
|
|
|
void locked_reSortGroup(RankGroup &grp);
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
void sortAllMsgs();
|
2009-05-12 17:55:50 -04:00
|
|
|
pqistore *createStore(std::string file, std::string src, bool reading);
|
2008-02-03 01:29:02 -05:00
|
|
|
|
2008-04-15 12:35:46 -04:00
|
|
|
|
|
|
|
/****************** p3Config STUFF *******************/
|
|
|
|
protected:
|
|
|
|
bool addAnonToList(RsRankLinkMsg *msg);
|
|
|
|
|
|
|
|
virtual RsSerialiser *setupSerialiser();
|
|
|
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
|
|
|
virtual bool loadList(std::list<RsItem *> load);
|
|
|
|
virtual void saveDone();
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
private:
|
|
|
|
|
|
|
|
void createDummyData();
|
|
|
|
|
2008-03-31 10:06:59 -04:00
|
|
|
p3ConnectMgr *mConnMgr;
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
RsMutex mRankMtx;
|
|
|
|
|
|
|
|
/***** below here is locked *****/
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
bool mRepublish;
|
2008-03-31 10:06:59 -04:00
|
|
|
bool mRepublishFriends;
|
|
|
|
time_t mRepublishFriendTS;
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
uint32_t mStorePeriod;
|
|
|
|
|
|
|
|
std::string mOwnId;
|
2008-03-17 09:51:04 -04:00
|
|
|
bool mUpdated;
|
2008-06-19 17:34:13 -04:00
|
|
|
bool mRepost;
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
std::map<std::string, RankGroup> mData;
|
|
|
|
std::multimap<float, std::string> mRankings;
|
|
|
|
|
|
|
|
/* Filter/Sort params */
|
|
|
|
std::list<std::string> mPeerFilter;
|
|
|
|
uint32_t mViewPeriod;
|
|
|
|
uint32_t mSortType;
|
|
|
|
|
2008-04-15 12:35:46 -04:00
|
|
|
/* Anonymous Link List */
|
|
|
|
std::list<RsRankLinkMsg *> mAnon;
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2008-04-15 12:35:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
|