mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Third attempt at link rank system.
* Added Anonymous links, stored in configuration file. * Friends recommendations are also shared anonymously with peers. * Own recommendations are shared with friends. * TODO include ranking (+2 <-> -2) in score. * some bugfixes too. Added RandomId to p3service file. Improved forum interface. Added dummy forum system (not transmitted) for testing. Switched on new features as well. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@505 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2def35c6f2
commit
129c07a553
@ -64,6 +64,8 @@ const uint32_t CONFIG_TYPE_FSERVER = 0x0003;
|
||||
const uint32_t CONFIG_TYPE_MSGS = 0x0004;
|
||||
const uint32_t CONFIG_TYPE_CACHE = 0x0005;
|
||||
|
||||
const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011;
|
||||
|
||||
class p3ConfigMgr;
|
||||
class p3AuthMgr;
|
||||
|
||||
|
@ -37,6 +37,9 @@
|
||||
#define RS_FORUM_PRIVATE 0x0002 /* anyone with key can publish */
|
||||
#define RS_FORUM_ENCRYPTED 0x0004 /* need admin key */
|
||||
|
||||
#define RS_FORUM_MSG_AUTH 0x0010 /* you must sign messages */
|
||||
#define RS_FORUM_MSG_ANON 0x0020 /* you can send anonymous messages */
|
||||
|
||||
#define RS_FORUM_ADMIN 0x0100 /* anyone can publish */
|
||||
#define RS_FORUM_SUBSCRIBED 0x0200 /* anyone can publish */
|
||||
|
||||
@ -61,8 +64,11 @@ class ForumMsgInfo
|
||||
ForumMsgInfo() {}
|
||||
std::string forumId;
|
||||
std::string threadId;
|
||||
std::string parentId;
|
||||
std::string msgId;
|
||||
|
||||
std::string srcId; /* if Authenticated -> signed here */
|
||||
|
||||
unsigned int msgflags;
|
||||
|
||||
std::wstring title;
|
||||
@ -75,13 +81,15 @@ class ThreadInfoSummary
|
||||
{
|
||||
public:
|
||||
ThreadInfoSummary() {}
|
||||
|
||||
std::string forumId;
|
||||
std::string threadId;
|
||||
std::string parentId;
|
||||
std::string msgId;
|
||||
std::string srcId;
|
||||
|
||||
uint32_t msgflags;
|
||||
|
||||
std::wstring title;
|
||||
std::wstring msg;
|
||||
int count; /* file count */
|
||||
time_t ts;
|
||||
|
||||
@ -105,9 +113,12 @@ virtual ~RsForums() { return; }
|
||||
|
||||
virtual bool forumsChanged(std::list<std::string> &forumIds) = 0;
|
||||
|
||||
|
||||
virtual std::string createForum(std::wstring forumName, std::wstring forumDesc, uint32_t forumFlags) = 0;
|
||||
|
||||
virtual bool getForumList(std::list<ForumInfo> &forumList) = 0;
|
||||
virtual bool getForumThreadList(std::string fId, std::list<ThreadInfoSummary> &msgs) = 0;
|
||||
virtual bool getForumThreadMsgList(std::string fId, std::string tId, std::list<ThreadInfoSummary> &msgs) = 0;
|
||||
virtual bool getForumThreadMsgList(std::string fId, std::string pId, std::list<ThreadInfoSummary> &msgs) = 0;
|
||||
virtual bool getForumMessage(std::string fId, std::string mId, ForumMsgInfo &msg) = 0;
|
||||
|
||||
virtual bool ForumMessageSend(ForumMsgInfo &info) = 0;
|
||||
|
@ -40,6 +40,7 @@ class RsRankComment
|
||||
|
||||
std::string id;
|
||||
std::wstring comment;
|
||||
int32_t score;
|
||||
time_t timestamp;
|
||||
};
|
||||
|
||||
@ -85,8 +86,10 @@ virtual bool getRankings(uint32_t first, uint32_t count, std::list<std::string>
|
||||
virtual bool getRankDetails(std::string rid, RsRankDetails &details) = 0;
|
||||
|
||||
/* Add New Comment / Msg */
|
||||
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment) = 0;
|
||||
virtual bool updateComment(std::string rid, std::wstring comment) = 0;
|
||||
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score) = 0;
|
||||
virtual bool updateComment(std::string rid, std::wstring comment, int32_t score) = 0;
|
||||
|
||||
virtual std::string anonRankMsg(std::wstring link, std::wstring title) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -74,8 +74,6 @@
|
||||
#define RS_RELEASE 1
|
||||
****/
|
||||
|
||||
#define RS_RELEASE 1
|
||||
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
@ -590,6 +588,9 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
|
||||
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
|
||||
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
|
||||
#ifndef RS_RELEASE
|
||||
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -87,14 +87,18 @@ bool p3Rank::getRankDetails(std::string rid, RsRankDetails &details)
|
||||
|
||||
|
||||
/* Add New Comment / Msg */
|
||||
std::string p3Rank::newRankMsg(std::wstring link, std::wstring title, std::wstring comment)
|
||||
std::string p3Rank::newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score)
|
||||
{
|
||||
return mRank->newRankMsg(link, title, comment);
|
||||
return mRank->newRankMsg(link, title, comment, score);
|
||||
}
|
||||
|
||||
bool p3Rank::updateComment(std::string rid, std::wstring comment)
|
||||
bool p3Rank::updateComment(std::string rid, std::wstring comment, int32_t score)
|
||||
{
|
||||
return mRank->updateComment(rid, comment);
|
||||
return mRank->updateComment(rid, comment, score);
|
||||
}
|
||||
|
||||
std::string p3Rank::anonRankMsg(std::wstring link, std::wstring title)
|
||||
{
|
||||
return mRank->anonRankMsg(link, title);
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,9 @@ virtual bool getRankings(uint32_t first, uint32_t count, std::list<std::strin
|
||||
virtual bool getRankDetails(std::string rid, RsRankDetails &details);
|
||||
|
||||
/* Add New Comment / Msg */
|
||||
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment);
|
||||
virtual bool updateComment(std::string rid, std::wstring comment);
|
||||
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);
|
||||
virtual std::string anonRankMsg(std::wstring link, std::wstring title);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -51,6 +51,7 @@ std::ostream &RsRankMsg::print(std::ostream &out, uint16_t indent)
|
||||
printIndent(out, int_Indent);
|
||||
out << "timestamp: " << timestamp << std::endl;
|
||||
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
|
||||
std::string cnv_title(title.begin(), title.end());
|
||||
@ -60,6 +61,9 @@ std::ostream &RsRankMsg::print(std::ostream &out, uint16_t indent)
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "comment: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "score: " << score << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsRankMsg", indent);
|
||||
return out;
|
||||
}
|
||||
@ -73,6 +77,7 @@ void RsRankLinkMsg::clear()
|
||||
timestamp = 0;
|
||||
title.clear();
|
||||
comment.clear();
|
||||
score = 0;
|
||||
linktype = 0;
|
||||
link.clear();
|
||||
}
|
||||
@ -98,6 +103,9 @@ std::ostream &RsRankLinkMsg::print(std::ostream &out, uint16_t indent)
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "comment: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "score: " << score << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "linktype: " << linktype << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
@ -117,6 +125,7 @@ uint32_t RsRankSerialiser::sizeLink(RsRankLinkMsg *item)
|
||||
s += 4; /* timestamp */
|
||||
s += GetTlvWideStringSize(item->title);
|
||||
s += GetTlvWideStringSize(item->comment);
|
||||
s += 4; /* score */
|
||||
s += 4; /* linktype */
|
||||
s += GetTlvWideStringSize(item->link);
|
||||
|
||||
@ -158,6 +167,9 @@ bool RsRankSerialiser::serialiseLink(RsRankLinkMsg *item, void *data, uint32
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() Comment: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, *((uint32_t *) &(item->score)));
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->linktype);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() linktype: " << ok << std::endl;
|
||||
|
||||
@ -184,7 +196,7 @@ RsRankLinkMsg *RsRankSerialiser::deserialiseLink(void *data, uint32_t *pktsize)
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RANK != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RANK_LINK2 != getRsItemSubType(rstype)))
|
||||
(RS_PKT_SUBTYPE_RANK_LINK3 != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -210,6 +222,7 @@ RsRankLinkMsg *RsRankSerialiser::deserialiseLink(void *data, uint32_t *pktsize)
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->timestamp));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
ok &= getRawUInt32(data, rssize, &offset, (uint32_t *) &(item->score));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->linktype));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_LINK, item->link);
|
||||
|
||||
|
@ -33,8 +33,10 @@
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_OLD_LINK = 0x02; /* defunct - don't use! */
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_LINK2 = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_PHOTO = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_OLD_LINK2 = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_LINK3 = 0x04;
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_PHOTO = 0x05;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@ -54,6 +56,7 @@ virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
uint32_t timestamp;
|
||||
std::wstring title;
|
||||
std::wstring comment;
|
||||
int32_t score;
|
||||
};
|
||||
|
||||
|
||||
@ -65,7 +68,7 @@ class RsRankLinkMsg: public RsRankMsg
|
||||
{
|
||||
public:
|
||||
RsRankLinkMsg()
|
||||
:RsRankMsg(RS_PKT_SUBTYPE_RANK_LINK2) { return; }
|
||||
:RsRankMsg(RS_PKT_SUBTYPE_RANK_LINK3) { return; }
|
||||
virtual ~RsRankLinkMsg() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
@ -75,6 +78,7 @@ virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
uint32_t timestamp;
|
||||
std::wstring title;
|
||||
std::wstring comment;
|
||||
int32_t score;
|
||||
***************************/
|
||||
|
||||
/* Link specific Fields */
|
||||
|
@ -99,25 +99,117 @@ bool p3Forums::getForumList(std::list<ForumInfo> &forumList)
|
||||
|
||||
bool p3Forums::getForumThreadList(std::string fId, std::list<ThreadInfoSummary> &msgs)
|
||||
{
|
||||
std::map<std::string, ThreadInfoSummary>::iterator it;
|
||||
for(it = mForumMsgs.begin(); it != mForumMsgs.end(); it++)
|
||||
{
|
||||
if (((it->second).forumId == fId) && ((it->second).parentId == ""))
|
||||
{
|
||||
msgs.push_back(it->second);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::getForumThreadMsgList(std::string fId, std::string tId, std::list<ThreadInfoSummary> &msgs)
|
||||
bool p3Forums::getForumThreadMsgList(std::string fId, std::string pId, std::list<ThreadInfoSummary> &msgs)
|
||||
{
|
||||
std::map<std::string, ThreadInfoSummary>::iterator it;
|
||||
for(it = mForumMsgs.begin(); it != mForumMsgs.end(); it++)
|
||||
{
|
||||
if (((it->second).forumId == fId) && ((it->second).parentId == pId))
|
||||
{
|
||||
msgs.push_back(it->second);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::getForumMessage(std::string fId, std::string mId, ForumMsgInfo &msg)
|
||||
{
|
||||
std::map<std::string, ThreadInfoSummary>::iterator it;
|
||||
it = mForumMsgs.find(mId);
|
||||
if (it == mForumMsgs.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
msg.forumId = (it->second).forumId;
|
||||
msg.threadId = (it->second).threadId;
|
||||
msg.parentId = (it->second).parentId;
|
||||
msg.msgId = (it->second).msgId;
|
||||
|
||||
msg.title = (it->second).title;
|
||||
msg.msg = (it->second).msg;
|
||||
msg.ts = (it->second).ts;
|
||||
|
||||
msg.srcId = "SRC";
|
||||
msg.ts = (it->second).ts;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::ForumMessageSend(ForumMsgInfo &info)
|
||||
{
|
||||
|
||||
createForumMsg(info.forumId, info.parentId, info.title, info.msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::string p3Forums::createForum(std::wstring forumName, std::wstring forumDesc, uint32_t forumFlags)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
|
||||
ForumInfo fi;
|
||||
fi.lastPost = now;
|
||||
fi.pop = 1;
|
||||
|
||||
fi.forumId = generateRandomServiceId();
|
||||
fi.forumName = forumName;
|
||||
fi.forumDesc = forumDesc;
|
||||
fi.forumFlags = forumFlags;
|
||||
fi.forumFlags |= RS_FORUM_ADMIN;
|
||||
|
||||
mForums.push_back(fi);
|
||||
mForumsChanged = true;
|
||||
|
||||
return fi.forumId;
|
||||
}
|
||||
|
||||
std::string p3Forums::createForumMsg(std::string fId, std::string pId,
|
||||
std::wstring title, std::wstring msg)
|
||||
{
|
||||
ThreadInfoSummary tis;
|
||||
|
||||
tis.forumId = fId;
|
||||
tis.parentId = pId;
|
||||
|
||||
/* find the parent -> copy threadId */
|
||||
tis.msgId = generateRandomServiceId();
|
||||
|
||||
std::map<std::string, ThreadInfoSummary>::iterator it;
|
||||
it = mForumMsgs.find(pId);
|
||||
|
||||
if (it == mForumMsgs.end())
|
||||
{
|
||||
tis.parentId = "";
|
||||
tis.threadId = tis.msgId;
|
||||
}
|
||||
else
|
||||
{
|
||||
tis.threadId = (it->second).threadId;
|
||||
}
|
||||
|
||||
tis.title = title;
|
||||
tis.msg = msg;
|
||||
tis.ts = time(NULL);
|
||||
|
||||
mForumMsgs[tis.msgId] = tis;
|
||||
mForumsChanged = true;
|
||||
|
||||
return tis.msgId;
|
||||
}
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
||||
void p3Forums::loadDummyData()
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include "rsiface/rsforums.h"
|
||||
#include "services/p3service.h"
|
||||
|
||||
class p3Forums: public RsForums
|
||||
{
|
||||
@ -40,6 +41,8 @@ virtual ~p3Forums();
|
||||
|
||||
virtual bool forumsChanged(std::list<std::string> &forumIds);
|
||||
|
||||
virtual std::string createForum(std::wstring forumName, std::wstring forumDesc, uint32_t forumFlags);
|
||||
|
||||
virtual bool getForumList(std::list<ForumInfo> &forumList);
|
||||
virtual bool getForumThreadList(std::string fId, std::list<ThreadInfoSummary> &msgs);
|
||||
virtual bool getForumThreadMsgList(std::string fId, std::string tId, std::list<ThreadInfoSummary> &msgs);
|
||||
@ -51,8 +54,13 @@ virtual bool ForumMessageSend(ForumMsgInfo &info);
|
||||
|
||||
private:
|
||||
|
||||
std::string createForumMsg(std::string fid, std::string pid,
|
||||
std::wstring title, std::wstring msg);
|
||||
|
||||
void loadDummyData();
|
||||
std::list<ForumInfo> mForums;
|
||||
std::map<std::string, ThreadInfoSummary> mForumMsgs;
|
||||
|
||||
bool mForumsChanged;
|
||||
};
|
||||
|
||||
|
@ -52,6 +52,7 @@ p3Ranking::p3Ranking(p3ConnectMgr *connMgr,
|
||||
uint32_t storePeriod)
|
||||
:CacheSource(type, true, cs, sourcedir),
|
||||
CacheStore(type, true, cs, cft, storedir),
|
||||
p3Config(CONFIG_TYPE_RANK_LINK),
|
||||
mConnMgr(connMgr),
|
||||
mRepublish(false), mRepublishFriends(false), mRepublishFriendTS(0),
|
||||
mStorePeriod(storePeriod), mUpdated(true)
|
||||
@ -300,25 +301,68 @@ void p3Ranking::publishMsgs(bool own)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* iterate through all comments */
|
||||
for(cit = it->second.comments.begin();
|
||||
cit != it->second.comments.end(); cit++)
|
||||
/* if we have pushed it out already - don't bother */
|
||||
if (it->second.ownTag)
|
||||
{
|
||||
RsItem *item = cit->second;
|
||||
/* write to serialiser */
|
||||
if (item && (mConnMgr->isFriend(item->PeerId())))
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs() Storing Friend Item:";
|
||||
std::cerr << std::endl;
|
||||
item->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3Ranking::publishMsgs() (Friends) Skipping Own Item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
stream->SendItem(item);
|
||||
stream->tick(); /* Tick to write! */
|
||||
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* if we have some comments ... then a friend has recommended it
|
||||
* serialise a sanitized version.
|
||||
*/
|
||||
if (it->second.comments.size() > 0)
|
||||
{
|
||||
RsRankLinkMsg *origmsg = (it->second.comments.begin())->second;
|
||||
RsRankLinkMsg *msg = new RsRankLinkMsg();
|
||||
|
||||
/* copy anon data */
|
||||
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
msg->clear();
|
||||
msg->PeerId("");
|
||||
msg->pid = ""; /* Anon */
|
||||
msg->rid = origmsg->rid;
|
||||
msg->link = origmsg->link;
|
||||
msg->title = origmsg->title;
|
||||
msg->timestamp = origmsg->timestamp;
|
||||
msg->score = 0;
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs() (Friends) Storing (Anon) Item:";
|
||||
std::cerr << std::endl;
|
||||
msg->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
stream->SendItem(msg);
|
||||
stream->tick(); /* Tick to write! */
|
||||
|
||||
/* cleanup */
|
||||
delete msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* now we also add our anon messages to the friends list */
|
||||
if (!own)
|
||||
{
|
||||
std::list<RsRankLinkMsg *>::iterator ait;
|
||||
for(ait=mAnon.begin(); ait != mAnon.end(); ait++)
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs() (Friends) Adding Own Anon Item:";
|
||||
std::cerr << std::endl;
|
||||
(*ait)->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
stream->SendItem(*ait);
|
||||
stream->tick(); /* Tick to write! */
|
||||
}
|
||||
}
|
||||
|
||||
@ -389,12 +433,36 @@ void p3Ranking::addRankMsg(RsRankLinkMsg *msg)
|
||||
grp.rid = rid;
|
||||
grp.ownTag = false;
|
||||
|
||||
/******** LINK SPECIFIC ****/
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
|
||||
grp.link = msg->link;
|
||||
grp.title = msg->title;
|
||||
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
|
||||
mData[rid] = grp;
|
||||
it = mData.find(rid);
|
||||
|
||||
|
||||
if (id == "")
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::addRankMsg() New Anon Link: mUpdated = true";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
locked_reSortGroup(it->second);
|
||||
mUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**** If it is an anonymous Link (ie Friend of a Friend) Drop out now ***/
|
||||
if (id == "")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* check for old comment */
|
||||
@ -624,7 +692,7 @@ float p3Ranking::locked_calcRank(RankGroup &grp)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if ((count < 0) || (algScore < 0))
|
||||
if ((count <= 0) || (algScore <= 0))
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "Final score: 0";
|
||||
@ -695,12 +763,14 @@ void p3Ranking::sortAllMsgs()
|
||||
for(it = mData.begin(); it != mData.end(); it++)
|
||||
{
|
||||
(it->second).rank = locked_calcRank(it->second);
|
||||
if (it->second.rank > 0)
|
||||
if (it->second.rank < 0)
|
||||
{
|
||||
mRankings.insert(
|
||||
std::pair<float, std::string>
|
||||
(it->second.rank, it->first));
|
||||
it->second.rank = 0;
|
||||
}
|
||||
|
||||
mRankings.insert(
|
||||
std::pair<float, std::string>
|
||||
(it->second.rank, it->first));
|
||||
}
|
||||
}
|
||||
|
||||
@ -728,12 +798,17 @@ bool p3Ranking::getRankings(uint32_t first, uint32_t count, std::list<std::st
|
||||
{
|
||||
RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::getRankings() First: " << first << " Count: " << count;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t i = 0;
|
||||
std::multimap<float, std::string>::reverse_iterator rit;
|
||||
for(rit = mRankings.rbegin(); (i < first) && (rit != mRankings.rend()); rit++);
|
||||
for(rit = mRankings.rbegin(); (i < first) && (rit != mRankings.rend()); rit++, i++);
|
||||
|
||||
i = 0;
|
||||
for(; (i < count) && (rit != mRankings.rend()); rit++)
|
||||
for(; (i < count) && (rit != mRankings.rend()); rit++, i++)
|
||||
{
|
||||
rids.push_back(rit->second);
|
||||
}
|
||||
@ -754,12 +829,20 @@ bool p3Ranking::getRankDetails(std::string rid, RsRankDetails &details)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
|
||||
details.rid = it->first;
|
||||
details.link = (it->second).link;
|
||||
details.title = (it->second).title;
|
||||
details.rank = (it->second).rank;
|
||||
details.ownTag = (it->second).ownTag;
|
||||
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
|
||||
std::map<std::string, RsRankLinkMsg *>::iterator cit;
|
||||
for(cit = (it->second).comments.begin();
|
||||
cit != (it->second).comments.end(); cit++)
|
||||
@ -768,6 +851,7 @@ bool p3Ranking::getRankDetails(std::string rid, RsRankDetails &details)
|
||||
comm.id = (cit->second)->PeerId();
|
||||
comm.timestamp = (cit->second)->timestamp;
|
||||
comm.comment = (cit->second)->comment;
|
||||
comm.score = (cit->second)->score;
|
||||
|
||||
details.comments.push_back(comm);
|
||||
}
|
||||
@ -821,7 +905,10 @@ bool p3Ranking::updated()
|
||||
}
|
||||
|
||||
/***** NEW CONTENT *****/
|
||||
std::string p3Ranking::newRankMsg(std::wstring link, std::wstring title, std::wstring comment)
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
std::string p3Ranking::newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score)
|
||||
{
|
||||
/* generate an id */
|
||||
std::string rid = generateRandomLinkId();
|
||||
@ -840,16 +927,22 @@ std::string p3Ranking::newRankMsg(std::wstring link, std::wstring title, std::ws
|
||||
msg->title = title;
|
||||
msg->timestamp = now;
|
||||
msg->comment = comment;
|
||||
msg->score = score;
|
||||
|
||||
msg->linktype = RS_LINK_TYPE_WEB;
|
||||
msg->link = link;
|
||||
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
bool p3Ranking::updateComment(std::string rid, std::wstring comment)
|
||||
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
bool p3Ranking::updateComment(std::string rid, std::wstring comment, int32_t score)
|
||||
{
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
@ -883,6 +976,7 @@ bool p3Ranking::updateComment(std::string rid, std::wstring comment)
|
||||
msg->timestamp = now;
|
||||
msg->title = (it->second).title;
|
||||
msg->comment = comment;
|
||||
msg->score = score;
|
||||
|
||||
msg->linktype = RS_LINK_TYPE_WEB;
|
||||
msg->link = (it->second).link;
|
||||
@ -900,6 +994,54 @@ bool p3Ranking::updateComment(std::string rid, std::wstring comment)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
std::string p3Ranking::anonRankMsg(std::wstring link, std::wstring title)
|
||||
{
|
||||
/* generate an id */
|
||||
std::string rid = generateRandomLinkId();
|
||||
|
||||
RsRankLinkMsg *msg1 = new RsRankLinkMsg();
|
||||
RsRankLinkMsg *msg2 = new RsRankLinkMsg();
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
|
||||
msg1->PeerId("");
|
||||
msg1->pid = "";
|
||||
|
||||
msg2->PeerId("");
|
||||
msg2->pid = "";
|
||||
}
|
||||
|
||||
msg1->rid = rid;
|
||||
msg1->title = title;
|
||||
msg1->timestamp = now;
|
||||
msg1->comment.clear();
|
||||
msg1->score = 0;
|
||||
|
||||
msg1->linktype = RS_LINK_TYPE_WEB;
|
||||
msg1->link = link;
|
||||
|
||||
msg2->rid = rid;
|
||||
msg2->title = title;
|
||||
msg2->timestamp = now;
|
||||
msg2->comment.clear();
|
||||
msg2->score = 0;
|
||||
|
||||
msg2->linktype = RS_LINK_TYPE_WEB;
|
||||
msg2->link = link;
|
||||
|
||||
addRankMsg(msg1);
|
||||
addAnonToList(msg2);
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pqistreamer *createStreamer(std::string file, std::string src, bool reading)
|
||||
{
|
||||
|
||||
@ -953,6 +1095,9 @@ std::string generateRandomLinkId()
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/****************************** LINK SPECIFIC ****************************/
|
||||
/*************************************************************************/
|
||||
void p3Ranking::createDummyData()
|
||||
{
|
||||
RsRankLinkMsg *msg = new RsRankLinkMsg();
|
||||
@ -966,6 +1111,7 @@ void p3Ranking::createDummyData()
|
||||
msg->timestamp = now - 60 * 60 * 24 * 15;
|
||||
msg->link = L"http://www.retroshare.org";
|
||||
msg->comment = L"Retroshares Website";
|
||||
msg->score = 1;
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
@ -977,6 +1123,7 @@ void p3Ranking::createDummyData()
|
||||
msg->timestamp = now - 123;
|
||||
msg->link = L"http://www.lunamutt.org";
|
||||
msg->comment = L"Lunamutt's Website";
|
||||
msg->score = 1;
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
@ -990,6 +1137,7 @@ void p3Ranking::createDummyData()
|
||||
msg->comment = L"Lunamutt's Website (TWO) How Long can this comment be!\n";
|
||||
msg->comment += L"What happens to the second line?\n";
|
||||
msg->comment += L"And a 3rd!";
|
||||
msg->score = 1;
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
@ -1001,6 +1149,7 @@ void p3Ranking::createDummyData()
|
||||
msg->timestamp = now - 60 * 60 * 7;
|
||||
msg->link = L"http://www.lunamutt.org";
|
||||
msg->comment += L"A Short Comment";
|
||||
msg->score = 1;
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
@ -1015,6 +1164,7 @@ void p3Ranking::createDummyData()
|
||||
msg->timestamp = now - 60 * 60;
|
||||
msg->link = L"http://www.lunamutt.com";
|
||||
msg->comment = L"";
|
||||
msg->score = 1;
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
@ -1026,8 +1176,136 @@ void p3Ranking::createDummyData()
|
||||
msg->timestamp = now - 60 * 60 * 24 * 2;
|
||||
msg->link = L"http://www.lunamutt.com";
|
||||
msg->comment = L"";
|
||||
msg->score = 1;
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/****************************** CONFIGURATION HANDLING *********************/
|
||||
/***************************************************************************/
|
||||
|
||||
/**** Store Anon Links: OVERLOADED FROM p3Config ****/
|
||||
|
||||
RsSerialiser *p3Ranking::setupSerialiser()
|
||||
{
|
||||
RsSerialiser *rss = new RsSerialiser();
|
||||
|
||||
/* add in the types we need! */
|
||||
rss->addSerialType(new RsRankSerialiser());
|
||||
return rss;
|
||||
}
|
||||
|
||||
bool p3Ranking::addAnonToList(RsRankLinkMsg *msg)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
|
||||
mAnon.push_back(msg);
|
||||
mRepublishFriends = true;
|
||||
}
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE CONFIG CHANGED! *****/
|
||||
return true;
|
||||
}
|
||||
|
||||
std::list<RsItem *> p3Ranking::saveList(bool &cleanup)
|
||||
{
|
||||
std::list<RsItem *> saveData;
|
||||
|
||||
mRankMtx.lock(); /*********************** LOCK *******/
|
||||
|
||||
cleanup = false;
|
||||
|
||||
std::list<RsRankLinkMsg *>::iterator it;
|
||||
for(it = mAnon.begin(); it != mAnon.end(); it++)
|
||||
{
|
||||
saveData.push_back(*it);
|
||||
}
|
||||
|
||||
/* list completed! */
|
||||
return saveData;
|
||||
}
|
||||
|
||||
void p3Ranking::saveDone()
|
||||
{
|
||||
mRankMtx.unlock(); /*********************** UNLOCK *******/
|
||||
return;
|
||||
}
|
||||
|
||||
bool p3Ranking::loadList(std::list<RsItem *> load)
|
||||
{
|
||||
std::list<RsItem *>::iterator it;
|
||||
RsRankLinkMsg *msg;
|
||||
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cerr << "p3Ranking::loadList() Item Count: " << load.size();
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
time_t now = time(NULL);
|
||||
time_t min, max;
|
||||
|
||||
{ RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
min = now - mStorePeriod;
|
||||
max = now + RANK_MAX_FWD_OFFSET;
|
||||
|
||||
} /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(it = load.begin(); it != load.end(); it++)
|
||||
{
|
||||
/* switch on type */
|
||||
if (NULL != (msg = dynamic_cast<RsRankLinkMsg *>(*it)))
|
||||
{
|
||||
/* check date -> if old expire */
|
||||
if (((time_t) msg->timestamp < min) ||
|
||||
((time_t) msg->timestamp > max))
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadList() Outside TimeRange (deleting Own Anon):";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* if outside range -> remove */
|
||||
delete msg;
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadList() Anon TimeRange ok";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
msg->PeerId("");
|
||||
msg->pid = "";
|
||||
|
||||
RsRankLinkMsg *msg2 = new RsRankLinkMsg();
|
||||
msg2->clear();
|
||||
msg2->PeerId(msg->PeerId());
|
||||
msg2->pid = msg->pid;
|
||||
msg2->rid = msg->rid;
|
||||
msg2->title = msg->title;
|
||||
msg2->timestamp = msg->timestamp;
|
||||
msg2->comment.clear();
|
||||
msg2->score = 0;
|
||||
|
||||
msg2->linktype = msg->linktype;
|
||||
msg2->link = msg->link;
|
||||
|
||||
/* make a copy to add into standard map */
|
||||
addRankMsg(msg);
|
||||
|
||||
RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
|
||||
mAnon.push_back(msg2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* cleanup */
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "pqi/pqiservice.h"
|
||||
#include "pqi/pqistreamer.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
@ -61,7 +62,7 @@ class RankGroup
|
||||
};
|
||||
|
||||
|
||||
class p3Ranking: public CacheSource, public CacheStore
|
||||
class p3Ranking: public CacheSource, public CacheStore, public p3Config
|
||||
{
|
||||
public:
|
||||
|
||||
@ -100,8 +101,9 @@ virtual bool getRankings(uint32_t first, uint32_t count, std::list<std::strin
|
||||
virtual bool getRankDetails(std::string rid, RsRankDetails &details);
|
||||
|
||||
/* Add New Comment / Msg */
|
||||
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment);
|
||||
virtual bool updateComment(std::string rid, std::wstring comment);
|
||||
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);
|
||||
virtual std::string anonRankMsg(std::wstring link, std::wstring title);
|
||||
|
||||
|
||||
void tick();
|
||||
@ -116,6 +118,16 @@ void locked_reSortGroup(RankGroup &grp);
|
||||
void sortAllMsgs();
|
||||
pqistreamer *createStreamer(std::string file, std::string src, bool reading);
|
||||
|
||||
|
||||
/****************** 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();
|
||||
|
||||
private:
|
||||
|
||||
void createDummyData();
|
||||
@ -143,6 +155,12 @@ void createDummyData();
|
||||
uint32_t mViewPeriod;
|
||||
uint32_t mSortType;
|
||||
|
||||
/* Anonymous Link List */
|
||||
std::list<RsRankLinkMsg *> mAnon;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "services/p3service.h"
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#define SERV_DEBUG 1
|
||||
|
||||
@ -201,4 +203,31 @@ RsRawItem *p3Service::send()
|
||||
}
|
||||
|
||||
|
||||
std::string generateRandomServiceId()
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << std::hex;
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
/* 4 bytes per random number: 4 x 4 = 16 bytes */
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
out << std::setw(8) << std::setfill('0');
|
||||
uint32_t rint = random();
|
||||
out << rint;
|
||||
}
|
||||
#else
|
||||
srand(time(NULL));
|
||||
/* 2 bytes per random number: 8 x 2 = 16 bytes */
|
||||
for(int i = 0; i < 8; i++)
|
||||
{
|
||||
out << std::setw(4) << std::setfill('0');
|
||||
uint16_t rint = rand(); /* only gives 16 bits */
|
||||
out << rint;
|
||||
}
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,6 +48,9 @@
|
||||
* For both Cached and Messages.
|
||||
*/
|
||||
|
||||
std::string generateRandomServiceId();
|
||||
|
||||
|
||||
class p3Service: public pqiService
|
||||
{
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user