2012-05-01 16:52:07 -04:00
|
|
|
#ifndef RSNXSITEMS_H
|
|
|
|
#define RSNXSITEMS_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rsnxssitems.h
|
|
|
|
*
|
|
|
|
* RetroShare Serialiser.
|
|
|
|
*
|
|
|
|
* Copyright 2012 Christopher Evi-Parker, 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 <map>
|
|
|
|
|
|
|
|
#include "serialiser/rsserviceids.h"
|
|
|
|
#include "serialiser/rsserial.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
|
|
|
#include "serialiser/rstlvtypes.h"
|
|
|
|
#include "serialiser/rstlvkeys.h"
|
|
|
|
|
|
|
|
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_SYNC_GRP = 0x0001;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_SYNC_GRP_LIST = 0x0002;
|
2012-05-05 15:55:24 -04:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_GRPS_RESP = 0x0004;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG = 0x0008;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG_LIST = 0x0010;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_MSG_RESP = 0x0020;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_SEARCH_REQ = 0x0040;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_SEARCH_RESP = 0x0080;
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Base class for Network exchange service
|
2012-05-05 15:55:24 -04:00
|
|
|
* Main purpose is for rtti based routing used in the
|
|
|
|
* serialisation and deserialisation of NXS packets
|
2012-05-01 16:52:07 -04:00
|
|
|
*
|
|
|
|
* Service type is set by plugin service
|
|
|
|
*/
|
|
|
|
class RsNxs : public RsItem
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
RsNxs(uint16_t servtype, uint8_t subtype)
|
|
|
|
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype) { return; }
|
2012-05-05 15:55:24 -04:00
|
|
|
|
|
|
|
virtual void clear() { }
|
|
|
|
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) { return out; }
|
2012-05-01 16:52:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Use to request grp list from peer
|
|
|
|
* Server may advise client peer to use sync file
|
|
|
|
* while serving his request. This results
|
|
|
|
*/
|
2012-05-05 15:55:24 -04:00
|
|
|
class RsSyncGrp : public RsNxs {
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static const uint8_t FLAG_USE_SYNC_HASH;
|
|
|
|
|
|
|
|
RsSyncGrp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_GRP) { return;}
|
|
|
|
|
|
|
|
uint8_t flag; // advises whether to use sync hash
|
|
|
|
uint32_t syncAge; // how far back to sync data
|
|
|
|
std::string syncHash; // use to determine if changes that have occured since last hash
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Use to send to peer list of grps
|
|
|
|
* held by server peer
|
|
|
|
*/
|
|
|
|
class RsSyncGrpList : public RsNxs
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2012-05-05 15:55:24 -04:00
|
|
|
RsSyncGrpList(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_GRP_LIST) { return ; }
|
2012-05-01 16:52:07 -04:00
|
|
|
|
2012-05-03 17:49:55 -04:00
|
|
|
static const uint8_t FLAG_REQUEST;
|
|
|
|
static const uint8_t FLAG_RESPONSE;
|
2012-05-01 16:52:07 -04:00
|
|
|
|
2012-05-03 17:49:55 -04:00
|
|
|
uint8_t flag; // request or response
|
2012-05-01 16:52:07 -04:00
|
|
|
|
2012-05-03 17:49:55 -04:00
|
|
|
/// groups held by sending peer
|
|
|
|
std::map<std::string, std::list<uint32_t> > grps; // grpId/ n version pair
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Contains serialised group items
|
|
|
|
* Each item corresponds to a group which needs to be
|
|
|
|
* deserialised
|
|
|
|
*/
|
|
|
|
class RsGrpResp : public RsNxs
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
RsGrpResp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_GRPS_RESP) { return; }
|
|
|
|
|
|
|
|
std::list<RsTlvBinaryData> grps; /// each entry corresponds to a group item
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Use to request list of msg held by peer
|
|
|
|
* for a given group
|
|
|
|
*/
|
|
|
|
class RsSyncGrpMsg : public RsNxs
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-05-05 15:55:24 -04:00
|
|
|
static const uint8_t FLAG_USE_SYNC_HASH;
|
|
|
|
|
|
|
|
RsSyncGrpMsg(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_MSG) {return; }
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
std::string grpId;
|
2012-05-05 15:55:24 -04:00
|
|
|
uint8_t flag;
|
2012-05-03 17:49:55 -04:00
|
|
|
uint32_t syncAge;
|
2012-05-05 15:55:24 -04:00
|
|
|
std::string syncHash;
|
2012-05-01 16:52:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Use to send list msgs for a group held by
|
|
|
|
* a peer
|
|
|
|
*/
|
|
|
|
class RsSyncGrpMsgList : public RsNxs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-05-03 17:49:55 -04:00
|
|
|
static const uint8_t FLAG_RESPONSE;
|
|
|
|
static const uint8_t FLAG_REQUEST;
|
|
|
|
|
2012-05-01 16:52:07 -04:00
|
|
|
RsSyncGrpMsgList(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_MSG_LIST) { return; }
|
|
|
|
|
2012-05-05 15:55:24 -04:00
|
|
|
uint8_t flag; // response/req
|
2012-05-01 16:52:07 -04:00
|
|
|
std::string grpId;
|
|
|
|
std::map<std::string, std::list<uint32_t> > msgs; // msg/versions pairs
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Used to respond to a RsGrpMsgsReq
|
|
|
|
* with message items satisfying request
|
|
|
|
*/
|
|
|
|
class RsGrpMsgResp : public RsNxs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
RsGrpMsgResp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_MSG_RESP) { return; }
|
|
|
|
|
|
|
|
std::list<RsTlvBinaryData> msgs; // each entry corresponds to a message item
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Used to request a search of user data
|
|
|
|
*/
|
|
|
|
class RsNxsSearchReq : public RsNxs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-05-05 15:55:24 -04:00
|
|
|
RsNxsSearchReq(uint16_t servtype): RsNxs(servtype, RS_PKT_SUBTYPE_SEARCH_REQ), searchTerm(servtype) { return; }
|
2012-05-01 16:52:07 -04:00
|
|
|
uint16_t token;
|
|
|
|
RsTlvBinaryData searchTerm; // service aware of item class
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Used to respond to a RsGrpSearchReq
|
|
|
|
* with grpId/MsgIds that satisfy search request
|
|
|
|
*/
|
|
|
|
class RsNxsSearchResp : public RsNxs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
RsNxsSearchResp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SEARCH_RESP) { return; }
|
|
|
|
|
|
|
|
uint16_t token; // search token to be redeemed
|
|
|
|
std::list<RsTlvBinaryData> msgs; // msgs with search terms present
|
|
|
|
std::list<RsTlvBinaryData> grps; // grps with search terms present
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RsNxsSerialiser : public RsSerialType
|
|
|
|
{
|
|
|
|
|
|
|
|
RsNxsSerialiser(uint16_t servtype) :
|
2012-05-05 15:55:24 -04:00
|
|
|
RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) { return; }
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
virtual ~RsNxsSerialiser() { return; }
|
|
|
|
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual uint32_t size(RsItem *item);
|
2012-05-01 16:52:07 -04:00
|
|
|
virtual bool serialise(RsItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsItem* deserialise(void *data, uint32_t *size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
/* for RS_PKT_SUBTYPE_SYNC_GRP */
|
|
|
|
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual uint32_t sizeSyncGrp(RsSyncGrp* item);
|
2012-05-01 16:52:07 -04:00
|
|
|
virtual bool serialiseSyncGrp(RsSyncGrp *item, void *data, uint32_t *size);
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual RsSyncGrp* deserialSyncGrp(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
/* for RS_PKT_SUBTYPE_SYNC_GRP_LIST */
|
|
|
|
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual uint32_t sizeSyncGrpList(RsSyncGrpList* item);
|
2012-05-01 16:52:07 -04:00
|
|
|
virtual bool serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint32_t *size);
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual RsSyncGrpList* deserialSyncGrpList(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
/* for RS_PKT_SUBTYPE_GRPS_RESP */
|
|
|
|
|
|
|
|
virtual uint32_t sizeGrpResp(RsGrpResp* item);
|
|
|
|
virtual bool serialiseGrpResp(RsGrpResp *item, void *data, uint32_t *size);
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual RsGrpResp* deserialGrpResp(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
/* for RS_PKT_SUBTYPE_SYNC_MSG */
|
|
|
|
|
|
|
|
virtual uint32_t sizeSyncGrpMsg(RsSyncGrpMsg* item);
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual bool serialiseSyncGrpMsg(RsSyncGrpMsg *item, void *data, uint32_t *size);
|
|
|
|
virtual RsSyncGrpMsg* deserialSyncGrpMsg(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
/* RS_PKT_SUBTYPE_SYNC_MSG_LIST */
|
|
|
|
|
2012-05-05 15:55:24 -04:00
|
|
|
virtual uint32_t sizeSyncGrpMsgList(RsSyncGrpMsgList* item);
|
2012-05-01 16:52:07 -04:00
|
|
|
virtual bool serialiseSynGrpMsgList(RsSyncGrpMsgList* item, void *data, uint32_t* size);
|
2012-05-05 15:55:24 -04:00
|
|
|
virtual RsSyncGrpMsgList* deserialSyncGrpMsgList(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* RS_PKT_SUBTYPE_MSG_RESP */
|
|
|
|
|
|
|
|
virtual uint32_t sizeGrpMsgResp(RsGrpMsgResp* item);
|
|
|
|
virtual bool serialiseGrpMsgResp(RsGrpMsgResp* item, void* data, uint32_t* size);
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual RsGrpMsgResp* deserialGrpMsgResp(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
/* RS_PKT_SUBTYPE_SEARCH_REQ */
|
|
|
|
|
|
|
|
virtual uint32_t sizeNxsSearchReq(RsNxsSearchReq* item);
|
|
|
|
virtual bool serialiseNxsSearchReq(RsNxsSearchReq* item, void* data, uint32_t* size);
|
2012-05-05 15:55:24 -04:00
|
|
|
virtual RsNxsSearchReq* deserialNxsSearchReq(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
|
|
|
/* RS_PKT_SUBTYPE_SEARCH_RESP */
|
|
|
|
|
|
|
|
virtual uint32_t sizeNxsSearchResp(RsNxsSearchResp *item);
|
|
|
|
virtual bool serialiseNxsSearchResp(RsNxsSearchResp *item, void *data, uint32_t *size);
|
2012-05-03 17:49:55 -04:00
|
|
|
virtual RsNxsSearchResp* deserialNxsSearchResp(void *data, uint32_t *size);
|
2012-05-01 16:52:07 -04:00
|
|
|
|
2012-05-05 15:55:24 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
const uint16_t SERVICE_TYPE;
|
2012-05-01 16:52:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RSNXSITEMS_H
|