Got GxsId service compiling and linking.

- Added entries in rsinit.cc
	- Added serialiser functions.
	- Tweaked some datatypes.
	- Fixed up duplicate headers.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5736 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-10-28 23:13:15 +00:00
parent df1a3297e0
commit cddeaeea81
8 changed files with 630 additions and 15 deletions

View File

@ -638,8 +638,8 @@ HEADERS += retroshare/rsgame.h \
services/p3idservice.h \
serialiser/rsgxsiditems.h
SOURCES += services/p3idservice.cc
# serialiser/rsgxsiditems.cc \
SOURCES += services/p3idservice.cc \
serialiser/rsgxsiditems.cc \
# Wiki Service
HEADERS += retroshare/rswiki.h \

View File

@ -92,7 +92,11 @@ class RsGxsIdOpinion
//std::string mKeyId; (mGroupId)
//std::string mPeerId; (mAuthorId) ???
int mOpinion;
uint32_t mOpinion;
// NOT SERIALISED YET!
double mReputation;
//int mRating;
//int mPeersRating;

View File

@ -1,5 +1,5 @@
#ifndef RETROSHARE_IDENTITY_GUI_INTERFACE_H
#define RETROSHARE_IDENTITY_GUI_INTERFACE_H
#ifndef RETROSHARE_IDENTITY_GUI_VEG_INTERFACE_H
#define RETROSHARE_IDENTITY_GUI_VEG_INTERFACE_H
/*
* libretroshare/src/retroshare: rsidentity.h

View File

@ -1827,7 +1827,8 @@ RsTurtle *rsTurtle = NULL ;
#include "services/p3posted.h"
#include "services/p3wikiserviceVEG.h"
#include "services/p3wireVEG.h"
#include "services/p3idserviceVEG.h"
//#include "services/p3idserviceVEG.h"
#include "services/p3idservice.h"
#include "services/p3forumsVEG.h"
#endif
@ -2293,12 +2294,29 @@ int RsServer::StartupRetroShare()
RsNxsNetMgr* nxsMgr = new RsNxsNetMgrImpl(mLinkMgr);
/**** Identity service ****/
p3IdService *mGxsIdService = NULL;
RsGeneralDataService* gxsid_ds = new RsDataService("./" + mLinkMgr->getOwnId() + "/", "gxsid_db",
RS_SERVICE_GXSV1_TYPE_GXSID, NULL);
gxsid_ds->resetDataStore();
// init gxs services
mGxsIdService = new p3IdService(gxsid_ds, NULL);
// create GXS photo service
RsGxsNetService* gxsid_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_GXSID, gxsid_ds, nxsMgr, mGxsIdService);
/**** Photo service ****/
p3PhotoServiceV2 *mPhotoV2 = NULL;
RsGeneralDataService* photo_ds = new RsDataService("./" + mLinkMgr->getOwnId() + "/", "photoV2_db",
RS_SERVICE_GXSV1_TYPE_PHOTO, NULL);
@ -2334,15 +2352,18 @@ int RsServer::StartupRetroShare()
/*** start up GXS core runner ***/
GxsCoreServer* mGxsCore = new GxsCoreServer();
mGxsCore->addService(mGxsIdService);
mGxsCore->addService(mPhotoV2);
mGxsCore->addService(mPosted);
// cores ready start up GXS net servers
createThread(*photo_ns);
createThread(*posted_ns);
createThread(*gxsid_ns);
// now add to p3service
pqih->addService(photo_ns);
pqih->addService(gxsid_ns);
pqih->addService(posted_ns);
// start up gxs core server

View File

@ -0,0 +1,578 @@
/*
* libretroshare/src/serialiser: rsgxsiditems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 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 <iostream>
#include "rsgxsiditems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define GXSID_DEBUG 1
uint32_t RsGxsIdSerialiser::size(RsItem *item)
{
RsGxsIdGroupItem* grp_item = NULL;
RsGxsIdOpinionItem* op_item = NULL;
RsGxsIdCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
{
return sizeGxsIdGroupItem(grp_item);
}
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
{
return sizeGxsIdOpinionItem(op_item);
}
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
{
return sizeGxsIdCommentItem(com_item);
}
return NULL;
}
bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsIdGroupItem* grp_item = NULL;
RsGxsIdOpinionItem* op_item = NULL;
RsGxsIdCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
{
return serialiseGxsIdGroupItem(grp_item, data, size);
}
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
{
return serialiseGxsIdGroupItem(grp_item, data, size);
return sizeGxsIdOpinionItem(op_item);
}
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
{
return serialiseGxsIdCommentItem(com_item, data, size);
}
return false;
}
RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM:
return deserialiseGxsIdGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM:
return deserialiseGxsIdOpinionItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM:
return deserialiseGxsIdCommentItem(data, size);
break;
default:
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsIdGroupItem::clear()
{
group.mGpgIdHash.clear();
group.mIdType = 0;
// Others that aren't serialised. - but should be cleared anyway
group.mGpgIdKnown = false;
group.mGpgId.clear();
group.mGpgName.clear();
group.mGpgEmail.clear();
}
std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "IdType: " << group.mIdType << std::endl;
printIndent(out, int_Indent);
out << "GpgIdHash: " << group.mGpgIdHash << std::endl;
printRsItemEnd(out ,"RsGxsIdGroupItem", indent);
return out;
}
uint32_t RsGxsIdSerialiser::sizeGxsIdGroupItem(RsGxsIdGroupItem *item)
{
const RsGxsIdGroup& group = item->group;
uint32_t s = 8; // header
s += 4; // mIdType.
s += GetTlvStringSize(group.mGpgIdHash);
return s;
}
bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsIdGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsIdGroupItem */
ok &= setRawUInt32(data, tlvsize, &offset, item->group.mIdType);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mGpgIdHash);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, rssize, &offset, &(item->group.mIdType));
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mGpgIdHash);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsIdOpinionItem::clear()
{
opinion.mOpinion = 0;
// Others that aren't serialised. - but should be cleared anyway
opinion.mReputation = 0;
}
std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdOpinionItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Opinion: " << opinion.mOpinion << std::endl;
printRsItemEnd(out ,"RsGxsIdOpinionItem", indent);
return out;
}
uint32_t RsGxsIdSerialiser::sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item)
{
const RsGxsIdOpinion& opinion = item->opinion;
uint32_t s = 8; // header
s += 4; // mOpinion.
return s;
}
bool RsGxsIdSerialiser::serialiseGxsIdOpinionItem(RsGxsIdOpinionItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsIdOpinionItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsIdOpinionItem */
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialiseGxsIdOpinionItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdOpinionItem* item = new RsGxsIdOpinionItem();
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion));
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsIdCommentItem::clear()
{
comment.mComment.clear();
}
std::ostream& RsGxsIdCommentItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdCommentItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Comment: " << comment.mComment << std::endl;
printRsItemEnd(out ,"RsGxsIdCommentItem", indent);
return out;
}
uint32_t RsGxsIdSerialiser::sizeGxsIdCommentItem(RsGxsIdCommentItem *item)
{
const RsGxsIdComment& comment = item->comment;
uint32_t s = 8; // header
s += 4; // mIdType.
s += GetTlvStringSize(comment.mComment);
return s;
}
bool RsGxsIdSerialiser::serialiseGxsIdCommentItem(RsGxsIdCommentItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsIdCommentItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsIdCommentItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment.mComment);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdCommentItem* RsGxsIdSerialiser::deserialiseGxsIdCommentItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdCommentItem* item = new RsGxsIdCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->comment.mComment);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View File

@ -57,19 +57,23 @@ p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *ne
}
int p3IdService::internal_tick()
void p3IdService::service_tick()
{
std::cerr << "p3IdService::internal_tick()";
std::cerr << "p3IdService::service_tick()";
std::cerr << std::endl;
// Disable for now.
// background_tick();
cache_tick();
//cache_tick();
return 0;
return;
}
void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
receiveChanges(changes);
}
/********************************************************************************/
/******************* RsIdentity Interface ***************************************/

View File

@ -102,12 +102,14 @@ class LruData
// Not sure exactly what should be inherited here?
// Chris - please correct as necessary.
class p3IdService: public RsGxsIdExchange, public RsIdentity
class p3IdService:
public RsGxsIdExchange,
public RsIdentity
{
public:
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
virtual int internal_tick(); // needed for background processing.
virtual void service_tick(); // needed for background processing.
/* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */
@ -155,6 +157,12 @@ virtual int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key);
// get Reputation.
virtual bool getReputation(const RsGxsId &id, const GixsReputation &rep);
protected:
/** Notifications **/
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
private:
/************************************************************************

View File

@ -23,8 +23,8 @@
*
*/
#ifndef P3_IDENTITY_SERVICE_HEADER
#define P3_IDENTITY_SERVICE_HEADER
#ifndef P3_IDENTITY_SERVICE_VEG_HEADER
#define P3_IDENTITY_SERVICE_VEG_HEADER
#include "services/p3service.h"
#include "services/p3gxsserviceVEG.h"