Implementation of GxsId Opinion, and start of Reputation system.

- Removed old reputation system from p3idservice
 - Removed old Msg types as well (no longer needed)
 - Added real submitOpinion()
 - Modified serviceString to support Reputation System.
 - Added reputation information to both Cached Data, and Standard ID Data.
 - Added basics of new reputation system as alternative service. (not gxs).
 - Added Generic TLV types for maps.
 - Moved configuration files to their own directory .rs/config/
 - Finally, fixed up bits missed from the change to updateGroup!



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7131 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-02-19 11:08:37 +00:00
parent 9a4c696688
commit 1b2ed66814
33 changed files with 2046 additions and 916 deletions

View file

@ -25,6 +25,8 @@
#include "gxs/gxstokenqueue.h" #include "gxs/gxstokenqueue.h"
#define GXS_DEBUG 1
bool GxsTokenQueue::queueRequest(uint32_t token, uint32_t req_type) bool GxsTokenQueue::queueRequest(uint32_t token, uint32_t req_type)
{ {
RsStackMutex stack(mQueueMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mQueueMtx); /********** STACK LOCKED MTX ******/
@ -60,6 +62,12 @@ void GxsTokenQueue::checkRequests()
toload.push_back(*it); toload.push_back(*it);
it = mQueue.erase(it); it = mQueue.erase(it);
stuffToLoad = true; stuffToLoad = true;
#ifdef GXS_DEBUG
std::cerr << "GxsTokenQueue::checkRequests() token: " << token << " Complete";
std::cerr << std::endl;
#endif
it++;
} }
else if (status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED) else if (status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
{ {
@ -71,6 +79,10 @@ void GxsTokenQueue::checkRequests()
} }
else else
{ {
#ifdef GXS_DEBUG
std::cerr << "GxsTokenQueue::checkRequests() token: " << token << " is unfinished, status: " << status;
std::cerr << std::endl;
#endif
it++; it++;
} }
} }

View file

@ -410,6 +410,8 @@ HEADERS += serialiser/rsbaseserial.h \
serialiser/rstlvkeys.h \ serialiser/rstlvkeys.h \
serialiser/rstlvkvwide.h \ serialiser/rstlvkvwide.h \
serialiser/rstlvtypes.h \ serialiser/rstlvtypes.h \
serialiser/rstlvgenericmap.h \
serialiser/rstlvmaps.h \
serialiser/rstlvutil.h \ serialiser/rstlvutil.h \
serialiser/rstlvbanlist.h \ serialiser/rstlvbanlist.h \
serialiser/rsbanlistitems.h \ serialiser/rsbanlistitems.h \
@ -543,6 +545,7 @@ SOURCES += serialiser/rsbaseserial.cc \
serialiser/rstlvkeys.cc \ serialiser/rstlvkeys.cc \
serialiser/rstlvkvwide.cc \ serialiser/rstlvkvwide.cc \
serialiser/rstlvtypes.cc \ serialiser/rstlvtypes.cc \
serialiser/rstlvgenericmap.cc \
serialiser/rstlvutil.cc \ serialiser/rstlvutil.cc \
serialiser/rstlvbanlist.cc \ serialiser/rstlvbanlist.cc \
serialiser/rsbanlistitems.cc \ serialiser/rsbanlistitems.cc \
@ -683,10 +686,14 @@ gxs {
HEADERS += retroshare/rsidentity.h \ HEADERS += retroshare/rsidentity.h \
gxs/rsgixs.h \ gxs/rsgixs.h \
services/p3idservice.h \ services/p3idservice.h \
serialiser/rsgxsiditems.h serialiser/rsgxsiditems.h \
services/p3gxsreputation.h \
serialiser/rsgxsreputationitems.h \
SOURCES += services/p3idservice.cc \ SOURCES += services/p3idservice.cc \
serialiser/rsgxsiditems.cc \ serialiser/rsgxsiditems.cc \
services/p3gxsreputation.cc \
serialiser/rsgxsreputationitems.cc \
# GxsCircles Service # GxsCircles Service
HEADERS += services/p3gxscircles.h \ HEADERS += services/p3gxscircles.h \

View file

@ -162,6 +162,7 @@ void p3ConfigMgr::addConfiguration(std::string file, pqiConfig *conf)
{ {
filename += "/"; filename += "/";
} }
filename += "config/";
filename += file; filename += file;
conf->setFilename(filename); conf->setFilename(filename);

View file

@ -93,6 +93,8 @@ const uint32_t CONFIG_TYPE_QBLOG = 0x0101;
const uint32_t CONFIG_TYPE_FORUMS = 0x0102; const uint32_t CONFIG_TYPE_FORUMS = 0x0102;
const uint32_t CONFIG_TYPE_CHANNELS = 0x0103; const uint32_t CONFIG_TYPE_CHANNELS = 0x0103;
const uint32_t CONFIG_TYPE_GXS_REPUTATION = 0x0200;
/* CACHE ID Must be at the END so that other configurations /* CACHE ID Must be at the END so that other configurations

View file

@ -109,7 +109,7 @@ virtual bool subscribeToGroup(uint32_t &token, const RsGxsGroupId &groupId, bool
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group) = 0; virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group) = 0;
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post) = 0; virtual bool createPost(uint32_t &token, RsGxsChannelPost &post) = 0;
virtual bool updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsGxsChannelGroup &group) = 0; virtual bool updateGroup(uint32_t &token, RsGxsChannelGroup &group) = 0;
// File Interface // File Interface
virtual bool ExtraFileHash(const std::string &path, std::string filename) = 0; virtual bool ExtraFileHash(const std::string &path, std::string filename) = 0;

View file

@ -90,7 +90,7 @@ virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg) = 0;
* @param group group to be updated, groupId element must be set or will be rejected * @param group group to be updated, groupId element must be set or will be rejected
* @return false groupId not set, true if set and accepted (still check token for completion) * @return false groupId not set, true if set and accepted (still check token for completion)
*/ */
virtual bool updateGroup(uint32_t &token, RsGxsGroupUpdateMeta&, RsGxsForumGroup &group) = 0; virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0;
}; };

View file

@ -59,6 +59,20 @@ extern RsIdentity *rsIdentity;
std::string rsIdTypeToString(uint32_t idtype); std::string rsIdTypeToString(uint32_t idtype);
class GxsReputation
{
public:
GxsReputation();
bool updateIdScore(bool pgpLinked, bool pgpKnown);
bool update(); // checks ranges and calculates overall score.
int mOverallScore;
int mIdScore; // PGP, Known, etc.
int mOwnOpinion;
int mPeerOpinion;
};
class RsGxsIdGroup class RsGxsIdGroup
{ {
public: public:
@ -90,79 +104,11 @@ class RsGxsIdGroup
// Not Serialised - for GUI's benefit. // Not Serialised - for GUI's benefit.
bool mPgpKnown; bool mPgpKnown;
std::string mPgpId; std::string mPgpId;
}; GxsReputation mReputation;
class RsGxsIdOpinion
{
public:
RsMsgMetaData mMeta;
// In MsgMetaData.
//std::string mKeyId; (mGroupId)
//std::string mPeerId; (mAuthorId) ???
uint32_t mOpinion;
std::string mComment;
uint32_t mReputation;
/* these convert To/From uint32 to expected scale. */
int getOpinion();
int getReputation();
int setOpinion(int op);
int setReputation(int rep);
// NOT SERIALISED YET!
//int mRating;
//int mPeersRating;
};
// This will probably be dropped.
class RsGxsIdComment
{
public:
RsMsgMetaData mMeta;
std::string mComment;
}; };
std::ostream &operator<<(std::ostream &out, const RsGxsIdGroup &group); std::ostream &operator<<(std::ostream &out, const RsGxsIdGroup &group);
std::ostream &operator<<(std::ostream &out, const RsGxsIdOpinion &msg);
#if 0
class RsIdReputation
{
public:
std::string mKeyId;
int mYourRating;
int mPeersRating;
int mFofRating;
int mTotalRating;
std::string mComment;
};
class RsIdOpinion
{
public:
std::string mKeyId;
std::string mPeerId;
int mRating;
int mPeersRating;
std::string mComment;
};
#endif
// DATA TYPE FOR EXTERNAL INTERFACE. // DATA TYPE FOR EXTERNAL INTERFACE.
@ -203,7 +149,7 @@ class RsIdentityDetails
public: public:
RsIdentityDetails() RsIdentityDetails()
:mIsOwnId(false), mPgpLinked(false), mPgpKnown(false), :mIsOwnId(false), mPgpLinked(false), mPgpKnown(false),
mOpinion(0), mReputation(0) { return; } mReputation() { return; }
RsGxsId mId; RsGxsId mId;
@ -220,8 +166,7 @@ class RsIdentityDetails
std::list<RsRecognTag> mRecognTags; std::list<RsRecognTag> mRecognTags;
// reputation details. // reputation details.
double mOpinion; GxsReputation mReputation;
double mReputation;
}; };
@ -265,7 +210,8 @@ virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0; virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0;
// //
virtual bool submitOpinion(uint32_t& token, RsIdOpinion &opinion) = 0; virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
bool absOpinion, int score) = 0;
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params) = 0; virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params) = 0;
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0; virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
@ -281,7 +227,7 @@ virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
*/ */
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0; virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0; //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
}; };

View file

@ -98,7 +98,7 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0; virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0;
virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0; virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0;
virtual bool updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsPostedGroup &group) = 0; virtual bool updateGroup(uint32_t &token, RsPostedGroup &group) = 0;
}; };

View file

@ -131,7 +131,7 @@ virtual bool submitCollection(uint32_t &token, RsWikiCollection &collection) = 0
virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot) = 0; virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot) = 0;
virtual bool submitComment(uint32_t &token, RsWikiComment &comment) = 0; virtual bool submitComment(uint32_t &token, RsWikiComment &comment) = 0;
virtual bool updateCollection(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsWikiCollection &collection) = 0; virtual bool updateCollection(uint32_t &token, RsWikiCollection &collection) = 0;
}; };

View file

@ -181,6 +181,7 @@ bool RsAccountsDetail::checkPreferredId()
const std::string kPathPGPDirectory = "pgp"; const std::string kPathPGPDirectory = "pgp";
const std::string kPathKeyDirectory = "keys"; const std::string kPathKeyDirectory = "keys";
const std::string kPathConfigDirectory = "config";
const std::string kFilenamePreferredAccount = "default_cert.txt"; const std::string kFilenamePreferredAccount = "default_cert.txt";
const std::string kFilenameKey = "user_pk.pem"; const std::string kFilenameKey = "user_pk.pem";
@ -1110,6 +1111,9 @@ bool RsAccountsDetail::setupAccount(const std::string& accountdir)
std::string subdir1 = accountdir + "/"; std::string subdir1 = accountdir + "/";
subdir1 += kPathKeyDirectory; subdir1 += kPathKeyDirectory;
std::string subdir2 = accountdir + "/";
subdir2 += kPathConfigDirectory;
std::string subdir3 = accountdir + "/"; std::string subdir3 = accountdir + "/";
subdir3 += "cache"; subdir3 += "cache";
@ -1127,7 +1131,12 @@ bool RsAccountsDetail::setupAccount(const std::string& accountdir)
} }
if (!RsDirUtil::checkCreateDirectory(subdir1)) if (!RsDirUtil::checkCreateDirectory(subdir1))
{ {
std::cerr << "Cannot Create Config/Key Dir" << std::endl; std::cerr << "Cannot Create Key Directory" << std::endl;
return false ;
}
if (!RsDirUtil::checkCreateDirectory(subdir2))
{
std::cerr << "Cannot Create Config Directory" << std::endl;
return false ; return false ;
} }
if (!RsDirUtil::checkCreateDirectory(subdir3)) if (!RsDirUtil::checkCreateDirectory(subdir3))

View file

@ -107,3 +107,5 @@ const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
// GXS // GXS
// //
const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ; const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ;
// GXS Reputation.
const uint8_t QOS_PRIORITY_RS_GXSREPUTATION_ITEM = 2;

View file

@ -35,13 +35,16 @@
uint32_t RsGxsIdSerialiser::size(RsItem *item) uint32_t RsGxsIdSerialiser::size(RsItem *item)
{ {
RsGxsIdGroupItem* grp_item = NULL; RsGxsIdGroupItem* grp_item = NULL;
#if 0
RsGxsIdOpinionItem* op_item = NULL; RsGxsIdOpinionItem* op_item = NULL;
RsGxsIdCommentItem* com_item = NULL; RsGxsIdCommentItem* com_item = NULL;
#endif
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL) if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
{ {
return sizeGxsIdGroupItem(grp_item); return sizeGxsIdGroupItem(grp_item);
} }
#if 0
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL) else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
{ {
return sizeGxsIdOpinionItem(op_item); return sizeGxsIdOpinionItem(op_item);
@ -50,6 +53,7 @@ uint32_t RsGxsIdSerialiser::size(RsItem *item)
{ {
return sizeGxsIdCommentItem(com_item); return sizeGxsIdCommentItem(com_item);
} }
#endif
std::cerr << "RsGxsIdSerialiser::size() ERROR invalid item" << std::endl; std::cerr << "RsGxsIdSerialiser::size() ERROR invalid item" << std::endl;
return 0; return 0;
} }
@ -57,13 +61,16 @@ uint32_t RsGxsIdSerialiser::size(RsItem *item)
bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size) bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{ {
RsGxsIdGroupItem* grp_item = NULL; RsGxsIdGroupItem* grp_item = NULL;
#if 0
RsGxsIdOpinionItem* op_item = NULL; RsGxsIdOpinionItem* op_item = NULL;
RsGxsIdCommentItem* com_item = NULL; RsGxsIdCommentItem* com_item = NULL;
#endif
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL) if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
{ {
return serialiseGxsIdGroupItem(grp_item, data, size); return serialiseGxsIdGroupItem(grp_item, data, size);
} }
#if 0
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL) else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
{ {
return serialiseGxsIdOpinionItem(op_item, data, size); return serialiseGxsIdOpinionItem(op_item, data, size);
@ -72,6 +79,7 @@ bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{ {
return serialiseGxsIdCommentItem(com_item, data, size); return serialiseGxsIdCommentItem(com_item, data, size);
} }
#endif
std::cerr << "RsGxsIdSerialiser::serialise() ERROR invalid item" << std::endl; std::cerr << "RsGxsIdSerialiser::serialise() ERROR invalid item" << std::endl;
return false; return false;
} }
@ -94,12 +102,14 @@ RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM: case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM:
return deserialiseGxsIdGroupItem(data, size); return deserialiseGxsIdGroupItem(data, size);
break; break;
#if 0
case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM: case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM:
return deserialiseGxsIdOpinionItem(data, size); return deserialiseGxsIdOpinionItem(data, size);
break; break;
case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM: case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM:
return deserialiseGxsIdCommentItem(data, size); return deserialiseGxsIdCommentItem(data, size);
break; break;
#endif
default: default:
#ifdef GXSID_DEBUG #ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype"; std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype";
@ -287,6 +297,7 @@ RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint3
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/
#if 0
void RsGxsIdOpinionItem::clear() void RsGxsIdOpinionItem::clear()
{ {
@ -575,6 +586,7 @@ RsGxsIdCommentItem* RsGxsIdSerialiser::deserialiseGxsIdCommentItem(void *data, u
return item; return item;
} }
#endif
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/

View file

@ -55,6 +55,7 @@ public:
RsGxsIdGroup group; RsGxsIdGroup group;
}; };
#if 0
class RsGxsIdOpinionItem : public RsGxsMsgItem class RsGxsIdOpinionItem : public RsGxsMsgItem
{ {
public: public:
@ -79,6 +80,7 @@ public:
RsGxsIdComment comment; RsGxsIdComment comment;
}; };
#endif
class RsGxsIdSerialiser : public RsSerialType class RsGxsIdSerialiser : public RsSerialType
{ {
@ -99,6 +101,7 @@ public:
bool serialiseGxsIdGroupItem (RsGxsIdGroupItem *item, void *data, uint32_t *size); bool serialiseGxsIdGroupItem (RsGxsIdGroupItem *item, void *data, uint32_t *size);
RsGxsIdGroupItem * deserialiseGxsIdGroupItem(void *data, uint32_t *size); RsGxsIdGroupItem * deserialiseGxsIdGroupItem(void *data, uint32_t *size);
#if 0
uint32_t sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item); uint32_t sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item);
bool serialiseGxsIdOpinionItem (RsGxsIdOpinionItem *item, void *data, uint32_t *size); bool serialiseGxsIdOpinionItem (RsGxsIdOpinionItem *item, void *data, uint32_t *size);
RsGxsIdOpinionItem * deserialiseGxsIdOpinionItem(void *data, uint32_t *size); RsGxsIdOpinionItem * deserialiseGxsIdOpinionItem(void *data, uint32_t *size);
@ -106,6 +109,8 @@ public:
uint32_t sizeGxsIdCommentItem(RsGxsIdCommentItem *item); uint32_t sizeGxsIdCommentItem(RsGxsIdCommentItem *item);
bool serialiseGxsIdCommentItem (RsGxsIdCommentItem *item, void *data, uint32_t *size); bool serialiseGxsIdCommentItem (RsGxsIdCommentItem *item, void *data, uint32_t *size);
RsGxsIdCommentItem * deserialiseGxsIdCommentItem(void *data, uint32_t *size); RsGxsIdCommentItem * deserialiseGxsIdCommentItem(void *data, uint32_t *size);
#endif
}; };

View file

@ -0,0 +1,203 @@
/*
* libretroshare/src/serialiser: rsbanlist.cc
*
* RetroShare Serialiser.
*
* Copyright 2011 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".
*
*/
#include "serialiser/rsbaseserial.h"
#include "serialiser/rsbanlistitems.h"
#include "serialiser/rstlvbanlist.h"
/***
#define RSSERIAL_DEBUG 1
***/
#include <iostream>
/*************************************************************************/
RsBanListItem::~RsBanListItem()
{
return;
}
void RsBanListItem::clear()
{
peerList.TlvClear();
}
std::ostream &RsBanListItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsBanListItem", indent);
uint16_t int_Indent = indent + 2;
peerList.print(out, int_Indent);
printRsItemEnd(out, "RsBanListItem", indent);
return out;
}
uint32_t RsBanListSerialiser::sizeList(RsBanListItem *item)
{
uint32_t s = 8; /* header */
s += item->peerList.TlvSize();
return s;
}
/* serialise the data to the buffer */
bool RsBanListSerialiser::serialiseList(RsBanListItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeList(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDsdvSerialiser::serialiseRoute() Header: " << ok << std::endl;
std::cerr << "RsDsdvSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= item->peerList.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDsdvSerialiser::serialiseRoute() Size Error! " << std::endl;
#endif
}
return ok;
}
RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t tlvsize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_BANLIST != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_BANLIST_ITEM != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < tlvsize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = tlvsize;
bool ok = true;
/* ready to load */
RsBanListItem *item = new RsBanListItem();
item->clear();
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= item->peerList.GetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
uint32_t RsBanListSerialiser::size(RsItem *i)
{
RsBanListItem *dri;
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
{
return sizeList(dri);
}
return 0;
}
bool RsBanListSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
RsBanListItem *dri;
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
{
return serialiseList(dri, data, pktsize);
}
return false;
}
RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_BANLIST != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_BANLIST_ITEM:
return deserialiseList(data, pktsize);
break;
default:
return NULL;
break;
}
}
/*************************************************************************/

View file

@ -0,0 +1,163 @@
#ifndef RS_GXSREPUTATION_ITEMS_H
#define RS_GXSREPUTATION_ITEMS_H
/*
* libretroshare/src/serialiser: rsgxsreputationitems.h
*
* RetroShare Serialiser.
*
* 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".
*
*/
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#define RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM 0x01
#define RS_PKT_SUBTYPE_GXSREPUTATION_SET_ITEM 0x02
#define RS_PKT_SUBTYPE_GXSREPUTATION_UPDATE_ITEM 0x03
#define RS_PKT_SUBTYPE_GXSREPUTATION_REQUEST_ITEM 0x04
/**************************************************************************/
class RsGxsReputationConfigItem: public RsItem
{
public:
RsGxsReputationConfigItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
return;
}
virtual ~RsGxsReputationConfigItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::string mPeerId;
uint32_t mLatestUpdate; // timestamp they returned.
uint32_t mLastQuery; // when we sent out.
};
class RsGxsReputationSetItem: public RsItem
{
public:
RsGxsReputationSetItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
RS_PKT_SUBTYPE_GXSREPUTATION_SET_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
return;
}
virtual ~RsGxsReputationSetItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::string mGxsId;
uint32_t mOwnOpinion;
uint32_t mOwnOpinionTs;
uint32_t mReputation;
std::map<std::string, uint32_t> mOpinions; // RsPeerId -> Opinion.
};
class RsGxsReputationUpdateItem: public RsItem
{
public:
RsGxsReputationUpdateItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
RS_PKT_SUBTYPE_GXSREPUTATION_UPDATE_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
return;
}
virtual ~RsGxsReputationUpdateItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::map<std::string, uint32_t> mOpinions; // GxsId -> Opinion.
uint32_t mLatestUpdate;
};
class RsGxsReputationRequestItem: public RsItem
{
public:
RsGxsReputationRequestItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
RS_PKT_SUBTYPE_GXSREPUTATION_REQUEST_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
return;
}
virtual ~RsGxsReputationRequestItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
uint32_t mLastUpdate;
};
class RsGxsReputationSerialiser: public RsSerialType
{
public:
RsGxsReputationSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION)
{ return; }
virtual ~RsGxsReputationSerialiser()
{ return; }
virtual uint32_t size(RsItem *);
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
virtual RsItem * deserialise(void *data, uint32_t *size);
private:
virtual uint32_t sizeConfig(RsGxsReputationConfigItem *);
virtual bool serialiseConfig(RsGxsReputationConfigItem *item, void *data, uint32_t *size);
virtual RsGxsReputationConfigItem *deserialiseConfig(void *data, uint32_t *size);
virtual uint32_t sizeSet(RsGxsReputationSetItem *);
virtual bool serialiseSet(RsGxsReputationSetItem *item, void *data, uint32_t *size);
virtual RsGxsReputationSetItem *deserialiseSet(void *data, uint32_t *size);
virtual uint32_t sizeUpdate(RsGxsReputationUpdateItem *);
virtual bool serialiseUpdate(RsGxsReputationUpdateItem *item, void *data, uint32_t *size);
virtual RsGxsReputationUpdateItem *deserialiseUpdate(void *data, uint32_t *size);
virtual uint32_t sizeRequest(RsGxsReputationRequestItem *);
virtual bool serialiseRequest(RsGxsReputationRequestItem *item, void *data, uint32_t *size);
virtual RsGxsReputationRequestItem *deserialiseRequest(void *data, uint32_t *size);
};
/**************************************************************************/
#endif /* RS_GXSREPUTATION_ITEMS_H */

View file

@ -144,6 +144,7 @@ const uint16_t RS_SERVICE_GXSV2_TYPE_WIRE = 0xf315;
const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf316; const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf316;
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf317; const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf317;
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf318; const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf318;
const uint16_t RS_SERVICE_GXSV2_TYPE_REPUTATION = 0xf319;
const uint16_t RS_SERVICE_GXSV3_TYPE_GXSID = 0xf321; const uint16_t RS_SERVICE_GXSV3_TYPE_GXSID = 0xf321;
const uint16_t RS_SERVICE_GXSV3_TYPE_PHOTO = 0xf322; const uint16_t RS_SERVICE_GXSV3_TYPE_PHOTO = 0xf322;
@ -153,6 +154,7 @@ const uint16_t RS_SERVICE_GXSV3_TYPE_FORUMS = 0xf325;
const uint16_t RS_SERVICE_GXSV3_TYPE_POSTED = 0xf326; const uint16_t RS_SERVICE_GXSV3_TYPE_POSTED = 0xf326;
const uint16_t RS_SERVICE_GXSV3_TYPE_CHANNELS = 0xf327; const uint16_t RS_SERVICE_GXSV3_TYPE_CHANNELS = 0xf327;
const uint16_t RS_SERVICE_GXSV3_TYPE_GXSCIRCLE = 0xf328; const uint16_t RS_SERVICE_GXSV3_TYPE_GXSCIRCLE = 0xf328;
const uint16_t RS_SERVICE_GXSV3_TYPE_REPUTATION = 0xf329;
const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0xf331; const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0xf331;

View file

@ -116,6 +116,7 @@ const uint16_t TLV_TYPE_UINT32_AGE = 0x0032;
const uint16_t TLV_TYPE_UINT32_OFFSET = 0x0033; const uint16_t TLV_TYPE_UINT32_OFFSET = 0x0033;
const uint16_t TLV_TYPE_UINT32_SERID = 0x0034; const uint16_t TLV_TYPE_UINT32_SERID = 0x0034;
const uint16_t TLV_TYPE_UINT32_BW = 0x0035; const uint16_t TLV_TYPE_UINT32_BW = 0x0035;
const uint16_t TLV_TYPE_UINT32_PARAM = 0x0030;
const uint16_t TLV_TYPE_UINT64_SIZE = 0x0040; const uint16_t TLV_TYPE_UINT64_SIZE = 0x0040;
const uint16_t TLV_TYPE_UINT64_OFFSET = 0x0041; const uint16_t TLV_TYPE_UINT64_OFFSET = 0x0041;
@ -138,6 +139,7 @@ const uint16_t TLV_TYPE_STR_CERT_GPG = 0x005d;
const uint16_t TLV_TYPE_STR_PGPCERT = 0x005d; /* same as CERT_GPG */ const uint16_t TLV_TYPE_STR_PGPCERT = 0x005d; /* same as CERT_GPG */
const uint16_t TLV_TYPE_STR_CERT_SSL = 0x005e; const uint16_t TLV_TYPE_STR_CERT_SSL = 0x005e;
const uint16_t TLV_TYPE_STR_VERSION = 0x005f; const uint16_t TLV_TYPE_STR_VERSION = 0x005f;
const uint16_t TLV_TYPE_STR_PARAM = 0x0054; /* same as VALUE ---- TO FIX */

View file

@ -0,0 +1,375 @@
/*
* libretroshare/src/serialiser: rstlvgenericmap.cc
*
* RetroShare Serialiser.
*
* 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".
*
*/
#include "rstlvbase.h"
#include "rstlvtypes.h"
#include "rstlvgenericmap.h"
#include "rsbaseserial.h"
#include "util/rsprint.h"
#include <ostream>
#include <sstream>
#include <iomanip>
#include <iostream>
#define TLV_DEBUG 1
template<>
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
{
return GetTlvUInt32Size();
}
template<>
void RsTlvParamRef<uint32_t>::TlvClear()
{
mParam = 0;
}
template<>
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvUInt32(data, size, offset, TLV_TYPE_UINT32_PARAM, mParam);
}
template<>
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return GetTlvUInt32(data, size, offset, TLV_TYPE_UINT32_PARAM, &mParam);
}
template<>
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << mParam;
return out;
}
/***** std::string ****/
template<>
uint32_t RsTlvParamRef<std::string>::TlvSize()
{
return GetTlvStringSize(mParam);
}
template<>
void RsTlvParamRef<std::string>::TlvClear()
{
mParam.clear();
}
template<>
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvString(data, size, offset, TLV_TYPE_STR_PARAM, mParam);
}
template<>
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return GetTlvString(data, size, offset, TLV_TYPE_STR_PARAM, mParam);
}
template<>
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << mParam;
return out;
}
// declare likely combinations.
template class RsTlvParamRef<uint32_t>;
template class RsTlvParamRef<std::string>;
/*********************************** RsTlvGenericPairRef ***********************************/
template<class K, class V>
void RsTlvGenericPairRef<K, V>::TlvClear()
{
RsTlvParamRef<K> key(mKey);
RsTlvParamRef<V> value(mValue);
key.TlvClear();
value.TlvClear();
}
template<class K, class V>
uint32_t RsTlvGenericPairRef<K, V>::TlvSize()
{
uint32_t s = TLV_HEADER_SIZE; /* header */
RsTlvParamRef<K> key(mKey);
RsTlvParamRef<V> value(mValue);
s += key.TlvSize();
s += value.TlvSize();
return s;
}
template<class K, class V>
bool RsTlvGenericPairRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
/* start at data[offset] */
ok &= SetTlvBase(data, tlvend, offset, mPairType, tlvsize);
RsTlvParamRef<K> key(mKey);
RsTlvParamRef<V> value(mValue);
ok &= key.SetTlv(data, tlvend, offset);
ok &= value.SetTlv(data, tlvend, offset);
return ok;
}
template<class K, class V>
bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != mPairType) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
RsTlvParamRef<K> key(mKey);
RsTlvParamRef<V> value(mValue);
ok &= key.GetTlv(data, tlvend, offset);
ok &= value.GetTlv(data, tlvend, offset);
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvGenericPairRef::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
template<class K, class V>
std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t indent)
{
printBase(out, "RsTlvGenericPairRef", indent);
uint16_t int_Indent = indent + 2;
RsTlvParamRef<K> key(mKey);
RsTlvParamRef<V> value(mValue);
printIndent(out, int_Indent);
out << "Key:";
key.print(out, 0);
out << std::endl;
printIndent(out, int_Indent);
out << "Value:";
value.print(out, 0);
out << std::endl;
printEnd(out, "RsTlvGenericPairRef", indent);
return out;
}
// declare likely combinations.
//template<> class RsTlvGenericPairRef<uint32_t, uint32_t>;
//template<> class RsTlvGenericPairRef<uint32_t, std::string>;
//template<> class RsTlvGenericPairRef<std::string, uint32_t>;
//template<> class RsTlvGenericPairRef<std::string, std::string>;
/************************************ RsTlvGenericMapRef ***********************************/
template<class K, class V>
void RsTlvGenericMapRef<K, V>::TlvClear()
{
mRefMap.clear(); //empty list
}
template<class K, class V>
uint32_t RsTlvGenericMapRef<K, V>::TlvSize()
{
uint32_t s = TLV_HEADER_SIZE; /* header */
typename std::map<K, V>::iterator it;
for(it = mRefMap.begin(); it != mRefMap.end(); ++it)
{
RsTlvGenericPairRef<const K, V> pair(mPairType, it->first, it->second);
s += pair.TlvSize();
}
return s;
}
template<class K, class V>
bool RsTlvGenericMapRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
/* start at data[offset] */
ok &= SetTlvBase(data, tlvend, offset, mMapType, tlvsize);
typename std::map<K, V>::iterator it;
for(it = mRefMap.begin(); it != mRefMap.end(); ++it)
{
RsTlvGenericPairRef<const K, V> pair(mPairType, it->first, it->second);
ok &= pair.SetTlv(data, size, offset);
}
return ok;
}
template<class K, class V>
bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != mMapType) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
/* while there is TLV */
while((*offset) + 2 < tlvend)
{
/* get the next type */
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
if (tlvsubtype == mPairType)
{
K k;
V v;
RsTlvGenericPairRef<const K, V> pair(mPairType, k, v);
ok &= pair.GetTlv(data, size, offset);
if (ok)
{
mRefMap[k] = v;
}
}
else
{
ok &= SkipUnknownTlv(data, tlvend, offset);
ok = false;
}
if (!ok)
break;
}
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvGenericMapRef::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
template<class K, class V>
std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent)
{
printBase(out, "RsTlvGenericMapRef", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "MapType:" << mMapType << std::endl;
typename std::map<K, V>::iterator it;
for(it = mRefMap.begin(); it != mRefMap.end() ; ++it)
{
RsTlvGenericPairRef<const K, V> pair(mPairType, it->first, it->second);
pair.print(out, int_Indent);
}
printEnd(out, "RsTlvGenericMapRef", indent);
return out;
}
// declare likely combinations.
template class RsTlvGenericMapRef<uint32_t, uint32_t>;
template class RsTlvGenericMapRef<uint32_t, std::string>;
template class RsTlvGenericMapRef<std::string, uint32_t>;
template class RsTlvGenericMapRef<std::string, std::string>;

View file

@ -0,0 +1,100 @@
#ifndef RS_TLV_GENERIC_MAP_H
#define RS_TLV_GENERIC_MAP_H
/*
* libretroshare/src/serialiser: rstlvgenericmap.h
*
* RetroShare Serialiser.
*
* 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".
*
*/
#include "serialiser/rstlvtypes.h"
#include <map>
#include <stdlib.h>
#include <stdint.h>
/**** TLV *****
* Generic Parameters / Maps.
*/
template<class T>
class RsTlvParamRef: public RsTlvItem
{
public:
RsTlvParamRef(T &p): mParam(p) {}
virtual ~RsTlvParamRef() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
T &mParam;
};
/*********************************** RsTlvGenericPairRef ***********************************/
template<class K, class V>
class RsTlvGenericPairRef: public RsTlvItem
{
public:
RsTlvGenericPairRef(uint16_t pair_type, K &k, V &v)
:mPairType(pair_type), mKey(k), mValue(v) { return; }
virtual ~RsTlvGenericPairRef() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
uint16_t mPairType;
K &mKey;
V &mValue;
};
/************************************ RsTlvGenericMapRef ***********************************/
template<class K, class V>
class RsTlvGenericMapRef: public RsTlvItem
{
public:
RsTlvGenericMapRef(uint16_t map_type, uint16_t pair_type, std::map<K, V> &refmap)
:mMapType(map_type), mPairType(pair_type), mRefMap(refmap) { return; }
virtual ~RsTlvGenericMapRef() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
uint16_t mMapType;
uint16_t mPairType;
std::map<K, V> &mRefMap;
};
#endif

View file

@ -0,0 +1,41 @@
#ifndef RS_TLV_MAPS_H
#define RS_TLV_MAPS_H
/*
* libretroshare/src/serialiser: rstlvmaps.h
*
* RetroShare Serialiser.
*
* 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".
*
*/
#include "serialiser/rstlvgenericmaps.h"
class RsTlvOpinionMapRef: public RsTlvGenericMapRef<std::string, uint32_t>
{
public:
RsTlvOpinionMapRef(std::map<std::string, uint32_t> &refmap)
:RsTlvGenericMapRef(OPINION, STRING_INT_PAIR, refmap) { return; }
};
#endif

View file

@ -264,29 +264,6 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
}; };
class RsTlvIntStringMap: public RsTlvItem
{
public:
RsTlvIntStringMap() { return; }
virtual ~RsTlvIntStringMap() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
uint32_t mapType;
std::map<uint32_t, std::string> map;
};
class RsTlvServiceIdMap: public RsTlvIntStringMap
{
public:
RsTlvServiceIdMap();
};
class RsTlvImage: public RsTlvItem class RsTlvImage: public RsTlvItem
{ {
public: public:

View file

@ -805,18 +805,14 @@ bool p3GxsChannels::createGroup(uint32_t &token, RsGxsChannelGroup &group)
} }
bool p3GxsChannels::updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsGxsChannelGroup &group) bool p3GxsChannels::updateGroup(uint32_t &token, RsGxsChannelGroup &group)
{ {
std::cerr << "p3GxsChannels::updateGroup()" << std::endl; std::cerr << "p3GxsChannels::updateGroup()" << std::endl;
if(meta.getGroupId().empty())
return false;
RsGxsChannelGroupItem* grpItem = new RsGxsChannelGroupItem(); RsGxsChannelGroupItem* grpItem = new RsGxsChannelGroupItem();
grpItem->fromChannelGroup(group, true); grpItem->fromChannelGroup(group, true);
grpItem->meta.mGroupId = meta.getGroupId();
RsGenExchange::updateGroup(token, meta, grpItem); RsGenExchange::updateGroup(token, grpItem);
return true; return true;
} }

View file

@ -92,7 +92,7 @@ virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group); virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group);
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post); virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
virtual bool updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsGxsChannelGroup &group); virtual bool updateGroup(uint32_t &token, RsGxsChannelGroup &group);
// no tokens... should be cached. // no tokens... should be cached.
virtual bool setChannelAutoDownload(const RsGxsGroupId &groupId, bool enabled); virtual bool setChannelAutoDownload(const RsGxsGroupId &groupId, bool enabled);

View file

@ -215,19 +215,15 @@ bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group)
return true; return true;
} }
bool p3GxsForums::updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsGxsForumGroup &group) bool p3GxsForums::updateGroup(uint32_t &token, RsGxsForumGroup &group)
{ {
std::cerr << "p3GxsForums::updateGroup()" << std::endl; std::cerr << "p3GxsForums::updateGroup()" << std::endl;
if(meta.getGroupId().empty())
return false;
RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem(); RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem();
grpItem->mGroup = group; grpItem->mGroup = group;
grpItem->meta = group.mMeta; grpItem->meta = group.mMeta;
grpItem->meta.mGroupId = meta.getGroupId();
// RsGenExchange::updateGroup(token, meta, grpItem); RsGenExchange::updateGroup(token, grpItem);
return true; return true;
} }

View file

@ -80,7 +80,7 @@ virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg);
* @param group group to be updated, groupId element must be set or will be rejected * @param group group to be updated, groupId element must be set or will be rejected
* @return false groupId not set, true if set and accepted (still check token for completion) * @return false groupId not set, true if set and accepted (still check token for completion)
*/ */
virtual bool updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsGxsForumGroup &group); virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group);
private: private:

View file

@ -0,0 +1,658 @@
/*
* libretroshare/src/services p3gxsreputation.cc
*
* Gxs Reputation Service for RetroShare.
*
* Copyright 2011-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".
*
*/
#include "pqi/p3linkmgr.h"
#include "retroshare/rspeers.h"
#include "services/p3gxsreputation.h"
#include "serialiser/rsgxsreputationitems.h"
#include <sys/time.h>
#include <set>
/****
* #define DEBUG_REPUTATION 1
****/
/* DEFINE INTERFACE POINTER! */
//RsGxsReputation *rsGxsReputation = NULL;
const int kMaximumPeerAge = 180; // half a year.
const int kMaximumSetSize = 100;
/************ IMPLEMENTATION NOTES *********************************
*
* p3GxsReputation shares opinions / reputations with peers.
* This is closely linked to p3IdService, receiving info, updating
* reputations as needed.
*
* It is designed as separate service as the exchange of peer opinions
* is not well suited to Gxs Groups / Messages...
*
* Instead we can broadcast opinions to all peers.
*
* To avoid too much traffic, changes are transmitted rather than whole lists.
* Peer A Peer B
* last update ----------->
* <----------- modified opinions.
*
* This service will have to store a huge amount of data.
* need to workout how to reduce it.
*
* std::map<RsGxsId, Reputation> mReputations.
* std::multimap<time_t, RsGxsId> mUpdated.
*
* std::map<RsPeerId, ReputationConfig> mConfig;
*
* Updates from p3GxsReputation -> p3IdService.
*
*
* Updates from p3IdService -> p3GxsReputation.
*
*
*/
const int32_t REPUTATION_OFFSET = 100000;
const int32_t LOWER_LIMIT = -100;
const int32_t UPPER_LIMIT = 100;
int32_t ConvertFromSerialised(uint32_t value, bool limit)
{
int32_t converted = ((int32_t) value) - REPUTATION_OFFSET ;
if (limit)
{
if (converted < LOWER_LIMIT)
{
converted = LOWER_LIMIT;
}
if (converted > UPPER_LIMIT)
{
converted = UPPER_LIMIT;
}
}
return converted;
}
uint32_t ConvertToSerialised(int32_t value, bool limit)
{
if (limit)
{
if (value < LOWER_LIMIT)
{
value = LOWER_LIMIT;
}
if (value > UPPER_LIMIT)
{
value = UPPER_LIMIT;
}
}
value += REPUTATION_OFFSET;
if (value < 0)
{
value = 0;
}
return (uint32_t) value;
}
p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
:p3Service(RS_SERVICE_GXSV2_TYPE_REPUTATION), p3Config(CONFIG_TYPE_GXS_REPUTATION),
mReputationMtx("p3GxsReputation"), mLinkMgr(lm)
{
addSerialType(new RsGxsReputationSerialiser());
mRequestTime = 0;
mStoreTime = 0;
mReputationsUpdated = false;
}
int p3GxsReputation::tick()
{
processIncoming();
sendPackets();
return 0;
}
int p3GxsReputation::status()
{
return 1;
}
/***** Implementation ******/
bool p3GxsReputation::processIncoming()
{
/* for each packet - pass to specific handler */
RsItem *item = NULL;
while(NULL != (item = recvItem()))
{
#ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputation::processingIncoming() Received Item:";
std::cerr << std::endl;
item->print(std::cerr);
std::cerr << std::endl;
#endif
bool itemOk = true;
switch(item->PacketSubType())
{
default:
case RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM:
case RS_PKT_SUBTYPE_GXSREPUTATION_SET_ITEM:
std::cerr << "p3GxsReputation::processingIncoming() Unknown Item";
std::cerr << std::endl;
itemOk = false;
break;
case RS_PKT_SUBTYPE_GXSREPUTATION_REQUEST_ITEM:
{
RsGxsReputationRequestItem *requestItem =
dynamic_cast<RsGxsReputationRequestItem *>(item);
if (requestItem)
{
SendReputations(requestItem);
}
else
{
itemOk = false;
}
}
break;
case RS_PKT_SUBTYPE_GXSREPUTATION_UPDATE_ITEM:
{
RsGxsReputationUpdateItem *updateItem =
dynamic_cast<RsGxsReputationUpdateItem *>(item);
if (updateItem)
{
RecvReputations(updateItem);
}
else
{
itemOk = false;
}
}
break;
}
if (!itemOk)
{
std::cerr << "p3GxsReputation::processingIncoming() Error with Item";
std::cerr << std::endl;
}
/* clean up */
delete item;
}
return true ;
}
bool p3GxsReputation::SendReputations(RsGxsReputationRequestItem *request)
{
std::cerr << "p3GxsReputation::SendReputations()";
std::cerr << std::endl;
RsPeerId peerId = request->PeerId();
time_t last_update = request->mLastUpdate;
time_t now = time(NULL);
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
std::multimap<time_t, RsGxsId>::iterator tit;
tit = mUpdated.upper_bound(last_update); // could skip some - (fixed below).
int count = 0;
int totalcount = 0;
RsGxsReputationUpdateItem *pkt = new RsGxsReputationUpdateItem();
pkt->PeerId(peerId);
for(;tit != mUpdated.end(); tit++)
{
/* find */
std::map<RsGxsId, Reputation>::iterator rit;
rit = mReputations.find(tit->second);
if (rit == mReputations.end())
{
std::cerr << "p3GxsReputation::SendReputations() ERROR Missing Reputation";
std::cerr << std::endl;
// error.
continue;
}
if (rit->second.mOwnOpinionTs == 0)
{
std::cerr << "p3GxsReputation::SendReputations() ERROR OwnOpinionTS = 0";
std::cerr << std::endl;
// error.
continue;
}
pkt->mOpinions[rit->first] = ConvertToSerialised(rit->second.mOwnOpinion, true);
pkt->mLatestUpdate = rit->second.mOwnOpinionTs;
if (pkt->mLatestUpdate == (uint32_t) now)
{
// if we could possibly get another Update at this point (same second).
// then set Update back one second to ensure there are none missed.
pkt->mLatestUpdate--;
}
count++;
totalcount++;
if (count > kMaximumSetSize)
{
std::cerr << "p3GxsReputation::SendReputations() Sending Full Packet";
std::cerr << std::endl;
sendItem(pkt);
pkt = new RsGxsReputationUpdateItem();
pkt->PeerId(peerId);
count = 0;
}
}
if (!pkt->mOpinions.empty())
{
std::cerr << "p3GxsReputation::SendReputations() Sending Final Packet";
std::cerr << std::endl;
sendItem(pkt);
}
else
{
delete pkt;
}
std::cerr << "p3GxsReputation::SendReputations() Total Count: " << totalcount;
std::cerr << std::endl;
return true;
}
bool p3GxsReputation::RecvReputations(RsGxsReputationUpdateItem *item)
{
std::cerr << "p3GxsReputation::RecvReputations()";
std::cerr << std::endl;
RsPeerId peerid = item->PeerId();
std::map<std::string, uint32_t>::iterator it;
for(it = item->mOpinions.begin(); it != item->mOpinions.end(); it++)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
/* find matching Reputation */
std::map<RsGxsId, Reputation>::iterator rit;
rit = mReputations.find(it->first);
if (rit == mReputations.end())
{
mReputations[it->first] = Reputation(it->first);
rit = mReputations.find(it->first);
}
Reputation &reputation = rit->second;
reputation.mOpinions[peerid] = ConvertFromSerialised(it->second, true);
int previous = reputation.mReputation;
if (previous != reputation.CalculateReputation())
{
// updated from the network.
mUpdatedReputations.insert(it->first);
}
}
updateLatestUpdate(peerid, item->mLatestUpdate);
return true;
}
bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid, time_t ts)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
std::map<RsPeerId, ReputationConfig>::iterator it;
it = mConfig.find(peerid);
if (it != mConfig.end())
{
mConfig[peerid] = ReputationConfig(peerid);
}
it->second.mLatestUpdate = ts;
mReputationsUpdated = true;
// Switched to periodic save due to scale of data.
//IndicateConfigChanged();
return true;
}
/********************************************************************
* Opinion
****/
bool p3GxsReputation::updateOpinion(const RsGxsId& gxsid, int opinion)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
std::map<RsGxsId, Reputation>::iterator rit;
/* find matching Reputation */
rit = mReputations.find(gxsid);
if (rit == mReputations.end())
{
mReputations[gxsid] = Reputation(gxsid);
rit = mReputations.find(gxsid);
}
// we should remove previous entries from Updates...
Reputation &reputation = rit->second;
if (reputation.mOwnOpinionTs != 0)
{
if (reputation.mOwnOpinion == opinion)
{
// if opinion is accurate, don't update.
return false;
}
std::multimap<time_t, RsGxsId>::iterator uit, euit;
uit = mUpdated.lower_bound(reputation.mOwnOpinionTs);
euit = mUpdated.upper_bound(reputation.mOwnOpinionTs);
for(; uit != euit; uit++)
{
if (uit->second == gxsid)
{
mUpdated.erase(uit);
break;
}
}
}
time_t now = time(NULL);
reputation.mOwnOpinion = opinion;
reputation.mOwnOpinionTs = now;
reputation.CalculateReputation();
mUpdated.insert(std::make_pair(now, gxsid));
mUpdatedReputations.insert(gxsid);
mReputationsUpdated = true;
// Switched to periodic save due to scale of data.
//IndicateConfigChanged();
return true;
}
/********************************************************************
* Configuration.
****/
RsSerialiser *p3GxsReputation::setupSerialiser()
{
RsSerialiser *rss = new RsSerialiser ;
rss->addSerialType(new RsGxsReputationSerialiser());
return rss ;
}
bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
{
cleanup = true;
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
/* save */
std::map<RsPeerId, ReputationConfig>::iterator it;
for(it = mConfig.begin(); it != mConfig.end(); it++)
{
if (!rsPeers->isFriend(it->first))
{
// discard info from non-friends.
continue;
}
RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem();
item->mPeerId = it->first;
item->mLatestUpdate = it->second.mLatestUpdate;
item->mLastQuery = it->second.mLastQuery;
savelist.push_back(item);
}
int count = 0;
std::map<RsGxsId, Reputation>::iterator rit;
for(rit = mReputations.begin(); rit != mReputations.end(); rit++, count++)
{
RsGxsReputationSetItem *item = new RsGxsReputationSetItem();
item->mGxsId = rit->first;
item->mOwnOpinion = ConvertToSerialised(rit->second.mOwnOpinion, false);
item->mOwnOpinionTs = rit->second.mOwnOpinionTs;
item->mReputation = ConvertToSerialised(rit->second.mReputation, false);
std::map<RsPeerId, int32_t>::iterator oit;
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
{
// should be already limited.
item->mOpinions[oit->first] = ConvertToSerialised(oit->second, false);
}
savelist.push_back(item);
count++;
}
return true;
}
void p3GxsReputation::saveDone()
{
return;
}
bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
{
std::list<RsItem *>::iterator it;
std::set<std::string> peerSet;
for(it = loadList.begin(); it != loadList.end(); it++)
{
RsGxsReputationConfigItem *item = dynamic_cast<RsGxsReputationConfigItem *>(*it);
// Configurations are loaded first. (to establish peerSet).
if (item)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
ReputationConfig &config = mConfig[item->mPeerId];
config.mPeerId = item->mPeerId;
config.mLatestUpdate = item->mLatestUpdate;
config.mLastQuery = 0;
peerSet.insert(item->mPeerId);
}
RsGxsReputationSetItem *set = dynamic_cast<RsGxsReputationSetItem *>(*it);
if (set)
{
loadReputationSet(set, peerSet);
}
delete (*it);
}
return true;
}
bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std::set<std::string> &peerSet)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
std::map<RsGxsId, Reputation>::iterator rit;
/* find matching Reputation */
rit = mReputations.find(item->mGxsId);
if (rit != mReputations.end())
{
std::cerr << "ERROR";
std::cerr << std::endl;
}
Reputation &reputation = mReputations[item->mGxsId];
// install opinions.
std::map<std::string, uint32_t>::const_iterator oit;
for(oit = item->mOpinions.begin(); oit != item->mOpinions.end(); oit++)
{
// expensive ... but necessary.
if (peerSet.end() != peerSet.find(oit->first))
{
reputation.mOpinions[oit->first] = ConvertFromSerialised(oit->second, true);
}
}
reputation.mOwnOpinion = ConvertFromSerialised(item->mOwnOpinion, false);
reputation.mOwnOpinionTs = item->mOwnOpinionTs;
// if dropping entries has changed the score -> must update.
int previous = ConvertFromSerialised(item->mReputation, false);
if (previous != reputation.CalculateReputation())
{
mUpdatedReputations.insert(item->mGxsId);
}
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, item->mGxsId));
return true;
}
/********************************************************************
* Send Requests.
****/
const int kReputationRequestPeriod = 3600;
const int kReputationStoreWait = 180; // 3 minutes.
int p3GxsReputation::sendPackets()
{
time_t now = time(NULL);
time_t requestTime, storeTime;
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
requestTime = mRequestTime;
storeTime = mStoreTime;
}
if (now - requestTime > kReputationRequestPeriod)
{
sendReputationRequests();
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
#ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputation::sendPackets() Regular Broadcast";
std::cerr << std::endl;
#endif
mRequestTime = now;
mStoreTime = now + kReputationStoreWait;
}
if (now > storeTime)
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
#ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputation::sendPackets() Regular Broadcast";
std::cerr << std::endl;
#endif
// push it into the future.
// store time will be reset when requests are send.
mStoreTime = now + kReputationRequestPeriod;
if (mReputationsUpdated)
{
IndicateConfigChanged();
mReputationsUpdated = false;
}
}
return true ;
}
void p3GxsReputation::sendReputationRequests()
{
/* we ping our peers */
/* who is online? */
std::list<RsPeerId> idList;
mLinkMgr->getOnlineList(idList);
#ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputation::sendReputationRequests()";
std::cerr << std::endl;
#endif
/* prepare packets */
std::list<std::string>::iterator it;
for(it = idList.begin(); it != idList.end(); it++)
{
#ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputation::sendReputationRequest() To: " << *it;
std::cerr << std::endl;
#endif
sendReputationRequest(*it);
}
}
int p3GxsReputation::sendReputationRequest(RsPeerId peerid)
{
std::cerr << "p3GxsReputation::sendReputationRequest(" << peerid << ")";
std::cerr << std::endl;
/* */
RsGxsReputationRequestItem *requestItem =
new RsGxsReputationRequestItem();
requestItem->PeerId(peerid);
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
/* find the last timestamp we have */
std::map<RsPeerId, ReputationConfig>::iterator it;
it = mConfig.find(peerid);
if (it != mConfig.end())
{
requestItem->mLastUpdate = it->second.mLatestUpdate;
}
else
{
// get whole list.
requestItem->mLastUpdate = 0;
}
}
sendItem(requestItem);
return 1;
}

View file

@ -0,0 +1,155 @@
/*
* 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 <string>
#include <list>
#include <map>
#include <set>
#include "serialiser/rsgxsreputationitems.h"
#include "retroshare/rsidentity.h"
#include "services/p3service.h"
typedef std::string RsPeerId;
class p3LinkMgr;
class ReputationConfig
{
public:
ReputationConfig()
:mPeerId(), mLatestUpdate(0) { return; }
ReputationConfig(const RsPeerId& peerId)
:mPeerId(peerId), mLatestUpdate(0) { return; }
RsPeerId mPeerId;
time_t mLatestUpdate;
time_t mLastQuery;
};
class Reputation
{
public:
Reputation()
:mOwnOpinion(0) { return; }
Reputation(const RsGxsId& about)
:mGxsId(about), mOwnOpinion(0) { return; }
int32_t CalculateReputation();
RsGxsId mGxsId;
std::map<RsPeerId, int32_t> mOpinions;
int32_t mOwnOpinion;
time_t mOwnOpinionTs;
int32_t mReputation;
};
//!The p3GxsReputation service.
/**
*
*
*/
class p3GxsReputation: public p3Service, public p3Config /* , public pqiMonitor */
{
public:
p3GxsReputation(p3LinkMgr *lm);
/***** Interface for p3idservice *****/
virtual bool updateOpinion(const RsGxsId& gxsid, int opinion);
/***** overloaded from p3Service *****/
/*!
* This retrieves all chat msg items and also (important!)
* processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned
* (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status
* : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar
* @see NotifyBase
*/
virtual int tick();
virtual int status();
/*!
* Interface stuff.
*/
/*************** pqiMonitor callback ***********************/
//virtual void statusChange(const std::list<pqipeer> &plist);
/************* from p3Config *******************/
virtual RsSerialiser *setupSerialiser() ;
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
virtual void saveDone();
virtual bool loadList(std::list<RsItem*>& load) ;
private:
bool processIncoming();
bool SendReputations(RsGxsReputationRequestItem *request);
bool RecvReputations(RsGxsReputationUpdateItem *item);
bool updateLatestUpdate(RsPeerId peerid, time_t ts);
bool loadReputationSet(RsGxsReputationSetItem *item,
const std::set<std::string> &peerSet);
int sendPackets();
void sendReputationRequests();
int sendReputationRequest(RsPeerId peerid);
private:
RsMutex mReputationMtx;
time_t mRequestTime;
time_t mStoreTime;
bool mReputationsUpdated;
p3LinkMgr *mLinkMgr;
// Data for Reputation.
std::map<RsPeerId, ReputationConfig> mConfig;
std::map<RsGxsId, Reputation> mReputations;
std::multimap<time_t, RsGxsId> mUpdated;
// set of Reputations to send to p3IdService.
std::set<RsGxsId> mUpdatedReputations;
};
#endif //SERVICE_RSGXSREPUTATION_HEADER

File diff suppressed because it is too large Load diff

View file

@ -49,6 +49,39 @@
* *
*/ */
#if 0
class GxsReputation
{
public:
GxsReputation();
bool updateIdScore(bool pgpLinked, bool pgpKnown);
bool update(); // checks ranges and calculates overall score.
int mOverallScore;
int mIdScore; // PGP, Known, etc.
int mOwnOpinion;
int mPeerOpinion;
};
#endif
class OpinionRequest
{
public:
OpinionRequest(uint32_t token, RsGxsId id, bool absOpinion, int32_t score)
:mToken(token), mId(id), mAbsOpinion(absOpinion), mScore(score)
{ return; }
OpinionRequest()
:mToken(0), mId(), mAbsOpinion(false), mScore(0)
{ return; }
uint32_t mToken;
RsGxsId mId;
bool mAbsOpinion;
int32_t mScore;
};
// INTERNAL DATA TYPES. // INTERNAL DATA TYPES.
// Describes data stored in GroupServiceString. // Describes data stored in GroupServiceString.
@ -97,16 +130,16 @@ virtual std::string save() const;
}; };
class SSGxsIdScore: public SSBit class SSGxsIdReputation: public SSBit
{ {
public: public:
SSGxsIdScore() SSGxsIdReputation()
:score(0) { return; } :rep() { return; }
virtual bool load(const std::string &input); virtual bool load(const std::string &input);
virtual std::string save() const; virtual std::string save() const;
int score; GxsReputation rep;
}; };
class SSGxsIdCumulator: public SSBit class SSGxsIdCumulator: public SSBit
@ -141,7 +174,9 @@ virtual std::string save() const;
SSGxsIdRecognTags recogntags; SSGxsIdRecognTags recogntags;
// reputation score. // reputation score.
SSGxsIdScore score; SSGxsIdReputation score;
// These are depreciated (will load, but not save)
SSGxsIdCumulator opinion; SSGxsIdCumulator opinion;
SSGxsIdCumulator reputation; SSGxsIdCumulator reputation;
@ -173,16 +208,6 @@ void updateServiceString(std::string serviceString);
}; };
#if 0
class LruData
{
public:
RsGxsId key;
};
#endif
// Not sure exactly what should be inherited here? // Not sure exactly what should be inherited here?
// Chris - please correct as necessary. // Chris - please correct as necessary.
@ -208,12 +233,12 @@ static uint32_t idAuthenPolicy();
// These are exposed via RsIdentity. // These are exposed via RsIdentity.
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups); virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions); //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
// These are local - and not exposed via RsIdentity. // These are local - and not exposed via RsIdentity.
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group);
virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion); //virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
/**************** RsIdentity External Interface. /**************** RsIdentity External Interface.
* Notes: * Notes:
@ -232,7 +257,8 @@ virtual bool getOwnIds(std::list<RsGxsId> &ownIds);
// //
virtual bool submitOpinion(uint32_t& token, RsIdOpinion &opinion); virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
bool absOpinion, int score);
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params); virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params);
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group); virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group);
@ -369,6 +395,18 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
void loadRecognKeys(); void loadRecognKeys();
/************************************************************************
* opinion processing.
*
*/
bool opinion_handlerequest(uint32_t token);
/* MUTEX PROTECTED DATA */
std::map<uint32_t, OpinionRequest> mPendingOpinion;
/************************************************************************ /************************************************************************
* for getting identities that are not present * for getting identities that are not present
* *
@ -398,6 +436,7 @@ virtual void generateDummyData();
std::string genRandomId(int len = 20); std::string genRandomId(int len = 20);
#if 0
bool reputation_start(); bool reputation_start();
bool reputation_continue(); bool reputation_continue();
@ -410,9 +449,11 @@ std::string genRandomId(int len = 20);
bool background_processFullCalc(); bool background_processFullCalc();
bool background_cleanup(); bool background_cleanup();
#endif
RsMutex mIdMtx; RsMutex mIdMtx;
#if 0
/***** below here is locked *****/ /***** below here is locked *****/
bool mLastBgCheck; bool mLastBgCheck;
bool mBgProcessing; bool mBgProcessing;
@ -422,6 +463,7 @@ std::string genRandomId(int len = 20);
std::map<std::string, RsGroupMetaData> mBgGroupMap; std::map<std::string, RsGroupMetaData> mBgGroupMap;
std::list<std::string> mBgFullCalcGroups; std::list<std::string> mBgFullCalcGroups;
#endif
/************************************************************************ /************************************************************************
* Other Data that is protected by the Mutex. * Other Data that is protected by the Mutex.

View file

@ -219,19 +219,15 @@ bool p3Posted::createGroup(uint32_t &token, RsPostedGroup &group)
} }
bool p3Posted::updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsPostedGroup &group) bool p3Posted::updateGroup(uint32_t &token, RsPostedGroup &group)
{ {
std::cerr << "p3Posted::updateGroup()" << std::endl; std::cerr << "p3Posted::updateGroup()" << std::endl;
if(meta.getGroupId().empty())
return false;
RsGxsPostedGroupItem* grpItem = new RsGxsPostedGroupItem(); RsGxsPostedGroupItem* grpItem = new RsGxsPostedGroupItem();
grpItem->mGroup = group; grpItem->mGroup = group;
grpItem->meta = group.mMeta; grpItem->meta = group.mMeta;
grpItem->meta.mGroupId = meta.getGroupId();
RsGenExchange::updateGroup(token, meta, grpItem); RsGenExchange::updateGroup(token, grpItem);
return true; return true;
} }

View file

@ -68,7 +68,7 @@ virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &p
virtual bool createGroup(uint32_t &token, RsPostedGroup &group); virtual bool createGroup(uint32_t &token, RsPostedGroup &group);
virtual bool createPost(uint32_t &token, RsPostedPost &post); virtual bool createPost(uint32_t &token, RsPostedPost &post);
virtual bool updateGroup(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsPostedGroup &group); virtual bool updateGroup(uint32_t &token, RsPostedGroup &group);
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// WRAPPERS due to the separate Interface. // WRAPPERS due to the separate Interface.

View file

@ -299,19 +299,15 @@ bool p3Wiki::submitComment(uint32_t &token, RsWikiComment &comment)
return true; return true;
} }
bool p3Wiki::updateCollection(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsWikiCollection &group) bool p3Wiki::updateCollection(uint32_t &token, RsWikiCollection &group)
{ {
std::cerr << "p3Wiki::updateCollection()" << std::endl; std::cerr << "p3Wiki::updateCollection()" << std::endl;
if(meta.getGroupId().empty())
return false;
RsGxsWikiCollectionItem* grpItem = new RsGxsWikiCollectionItem(); RsGxsWikiCollectionItem* grpItem = new RsGxsWikiCollectionItem();
grpItem->collection = group; grpItem->collection = group;
grpItem->meta = group.mMeta; grpItem->meta = group.mMeta;
grpItem->meta.mGroupId = meta.getGroupId();
RsGenExchange::updateGroup(token, meta, grpItem); RsGenExchange::updateGroup(token, grpItem);
return true; return true;
} }

View file

@ -69,7 +69,7 @@ virtual bool submitCollection(uint32_t &token, RsWikiCollection &collection);
virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot); virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot);
virtual bool submitComment(uint32_t &token, RsWikiComment &comment); virtual bool submitComment(uint32_t &token, RsWikiComment &comment);
virtual bool updateCollection(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsWikiCollection &collection); virtual bool updateCollection(uint32_t &token, RsWikiCollection &collection);
private: private: