Merge branch 'master' into merge_alpha_master

This commit is contained in:
Gioacchino Mazzurco 2017-04-18 21:30:25 +02:00
commit 4455bfa92d
110 changed files with 2395 additions and 629 deletions

View file

@ -459,8 +459,12 @@ bool GxsSecurity::validateNxsMsg(const RsNxsMsg& msg, const RsTlvKeySignature& s
msgMeta.signSet.TlvClear();
RsGxsMessageId msgId = msgMeta.mMsgId, origMsgId = msgMeta.mOrigMsgId;
msgMeta.mOrigMsgId.clear();
if(msgMeta.mOrigMsgId == msgMeta.mMsgId) // message is not versionned, then the signature was made with mOrigMsgId==NULL
msgMeta.mOrigMsgId.clear();
msgMeta.mMsgId.clear();
int signOk = 0 ;
{

View file

@ -1270,6 +1270,58 @@ bool RsGenExchange::getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMa
return ok;
}
bool RsGenExchange::getSerializedGroupData(const uint32_t &token, RsGxsGroupId& id,unsigned char *& data,uint32_t& size)
{
RS_STACK_MUTEX(mGenMtx) ;
std::list<RsNxsGrp*> nxsGrps;
if(!mDataAccess->getGroupData(token, nxsGrps))
return false ;
if(nxsGrps.size() != 1)
{
std::cerr << "(EE) getSerializedGroupData() got multiple groups in single request. This is unexpected." << std::endl;
for(std::list<RsNxsGrp*>::const_iterator it(nxsGrps.begin());it!=nxsGrps.end();++it)
delete *it ;
return false ;
}
RsNxsGrp *nxs_grp = *(nxsGrps.begin());
size = nxs_grp->serial_size() ;
id = nxs_grp->metaData->mGroupId ;
if(size > 1024*1024 || NULL==(data = (unsigned char *)rs_malloc(size)))
{
std::cerr << "(EE) getSerializedGroupData() cannot allocate mem chunk of size " << size << ". Too big, or no room." << std::endl;
delete nxs_grp ;
return false ;
}
return nxs_grp->serialise(data,size) ;
}
bool RsGenExchange::deserializeGroupData(unsigned char *data,uint32_t size)
{
RS_STACK_MUTEX(mGenMtx) ;
RsItem *item = RsNxsSerialiser(mServType).deserialise(data, &size);
RsNxsGrp *nxs_grp = dynamic_cast<RsNxsGrp*>(item) ;
if(item == NULL)
{
std::cerr << "(EE) RsGenExchange::deserializeGroupData(): cannot deserialise this data. Something's wrong." << std::endl;
delete item ;
return false ;
}
mReceivedGrps.push_back( GxsPendingItem<RsNxsGrp*, RsGxsGroupId>(nxs_grp, nxs_grp->grpId,time(NULL)) );
return true ;
}
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem)
{
@ -2135,7 +2187,9 @@ void RsGenExchange::publishMsgs()
if(createOk && validSize)
{
// empty orig msg id means this is the original
// msg
// msg.
// (csoler) Why are we doing this???
if(msg->metaData->mOrigMsgId.isNull())
{
msg->metaData->mOrigMsgId = msg->metaData->mMsgId;

View file

@ -288,6 +288,20 @@ protected:
*/
bool getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem*>& grpItem);
/*!
* \brief getSerializedGroupData
* Retrieves the complete group data serialized into a chunk of memory. This can be useful to
* transfer a full group from one machine to another.
*
* \param token token previously obtained from cache request
* \param data memory chunk allocated (using malloc)
* \param size size of the memory chunk.
* \return
*/
bool getSerializedGroupData(const uint32_t &token, RsGxsGroupId &id, unsigned char *& data, uint32_t& size);
bool deserializeGroupData(unsigned char *data, uint32_t size);
template<class GrpType>
bool getGroupDataT(const uint32_t &token, std::vector<GrpType*>& grpItem)
{

View file

@ -34,8 +34,8 @@
#include "serialiser/rstlvkeys.h"
#include "serialiser/rsgxsitems.h"
class RsGroupMetaData;
class RsMsgMetaData;
struct RsGroupMetaData;
struct RsMsgMetaData;
static const uint32_t RS_GXS_GRP_META_DATA_VERSION_ID_0001 = 0x0000 ; // change this, and keep old values if the content changes
static const uint32_t RS_GXS_GRP_META_DATA_VERSION_ID_0002 = 0xaf01 ; // current API
@ -56,22 +56,22 @@ public:
void clear();
void operator =(const RsGroupMetaData& rMeta);
//Sort data in same order than serialiser and deserializer
//Sort data in same order than serialiser and deserializer
RsGxsGroupId mGroupId;
RsGxsGroupId mOrigGrpId;
RsGxsGroupId mParentGrpId;
RsGxsGroupId mParentGrpId;
std::string mGroupName;
uint32_t mGroupFlags; // GXS_SERV::FLAG_PRIVACY_RESTRICTED | GXS_SERV::FLAG_PRIVACY_PRIVATE | GXS_SERV::FLAG_PRIVACY_PUBLIC
uint32_t mPublishTs;
uint32_t mCircleType;
uint32_t mAuthenFlags;
uint32_t mCircleType;
uint32_t mAuthenFlags;
RsGxsId mAuthorId;
std::string mServiceString;
std::string mServiceString;
RsGxsCircleId mCircleId;
RsTlvKeySignatureSet signSet;
RsTlvSecurityKeySet keys;
uint32_t mSignFlags;
uint32_t mSignFlags;
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
@ -103,9 +103,9 @@ public:
void clear();
void operator =(const RsMsgMetaData& rMeta);
static int refcount;
//Sort data in same order than serialiser and deserializer
static int refcount;
//Sort data in same order than serialiser and deserializer
RsGxsGroupId mGroupId;
RsGxsMessageId mMsgId;
RsGxsMessageId mThreadId;
@ -121,7 +121,7 @@ public:
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
// normally READ / UNREAD flags. LOCAL Data.
std::string mServiceString;
std::string mServiceString;
uint32_t mMsgStatus;
uint32_t mMsgSize;
time_t mChildTs;

View file

@ -75,6 +75,12 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const
gir->mGroupIds = groupIds;
req = gir;
}
else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA)
{
GroupSerializedDataReq* gir = new GroupSerializedDataReq();
gir->mGroupIds = groupIds;
req = gir;
}
if(req == NULL)
{
@ -103,34 +109,25 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const
uint32_t reqType = opts.mReqType;
if(reqType & GXS_REQUEST_TYPE_GROUP_META)
{
GroupMetaReq* gmr = new GroupMetaReq();
req = gmr;
}
req = new GroupMetaReq();
else if(reqType & GXS_REQUEST_TYPE_GROUP_DATA)
{
GroupDataReq* gdr = new GroupDataReq();
req = gdr;
}
req = new GroupDataReq();
else if(reqType & GXS_REQUEST_TYPE_GROUP_IDS)
{
GroupIdReq* gir = new GroupIdReq();
req = gir;
}
if(req == NULL)
req = new GroupIdReq();
else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA)
req = new GroupSerializedDataReq();
else
{
std::cerr << "RsGxsDataAccess::requestGroupInfo() request type not recognised, type "
<< reqType << std::endl;
return false;
}else
{
generateToken(token);
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl;
#endif
}
generateToken(token);
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl;
#endif
setReq(req, token, ansType, opts);
storeRequest(req);
@ -430,7 +427,16 @@ bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>&
else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE)
{
GroupDataReq* gmreq = dynamic_cast<GroupDataReq*>(req);
if(gmreq)
GroupSerializedDataReq* gsreq = dynamic_cast<GroupSerializedDataReq*>(req);
if(gsreq)
{
grpData.swap(gsreq->mGroupData);
gsreq->mGroupData.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
}
else if(gmreq)
{
grpData.swap(gmreq->mGroupData);
gmreq->mGroupData.clear();
@ -804,6 +810,7 @@ void RsGxsDataAccess::processRequests()
MsgIdReq* mir;
MsgRelatedInfoReq* mri;
GroupStatisticRequest* gsr;
GroupSerializedDataReq* grr;
ServiceStatisticRequest* ssr;
#ifdef DATA_DEBUG
@ -851,6 +858,11 @@ void RsGxsDataAccess::processRequests()
{
ok = getServiceStatistic(ssr);
}
else if((grr = dynamic_cast<GroupSerializedDataReq*>(req)) != NULL)
{
ok = getGroupSerializedData(grr);
}
else
{
std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: "
@ -929,7 +941,30 @@ bool RsGxsDataAccess::getServiceStatistic(const uint32_t &token, GxsServiceStati
return true;
}
bool RsGxsDataAccess::getGroupSerializedData(GroupSerializedDataReq* req)
{
std::map<RsGxsGroupId, RsNxsGrp*> grpData;
std::list<RsGxsGroupId> grpIdsOut;
getGroupList(req->mGroupIds, req->Options, grpIdsOut);
if(grpIdsOut.empty())
return true;
for(std::list<RsGxsGroupId>::iterator lit = grpIdsOut.begin();lit != grpIdsOut.end();++lit)
grpData[*lit] = NULL;
bool ok = mDataStore->retrieveNxsGrps(grpData, true, true);
req->mGroupData.clear();
std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit = grpData.begin();
for(; mit != grpData.end(); ++mit)
req->mGroupData.push_back(mit->second) ;
return ok;
}
bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
{
std::map<RsGxsGroupId, RsNxsGrp*> grpData;

View file

@ -418,6 +418,13 @@ private:
*/
bool getGroupStatistic(GroupStatisticRequest* req);
/*!
*
* Attempts to retrieve group data in serialized format
* @param req Request object to satisfy
*/
bool getGroupSerializedData(GroupSerializedDataReq* req);
/*!
*
* Attempts to service statistic

View file

@ -1972,7 +1972,7 @@ void RsGxsNetService::updateServerSyncTS()
#endif
// I keep the creation, but the data is not used yet.
#warning disabled this, but do we need it?
#warning csoler 2016-12-12: Disabled this, but do we need it?
// RsGxsServerMsgUpdate& msui(mServerMsgUpdateMap[grpId]) ;
// (cyril) I'm removing this, because the msgUpdateTS is updated when new messages are received by calling locked_stampMsgServerUpdateTS().
@ -3000,7 +3000,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
}
// FIXTESTS global variable rsReputations not available in unittests!
#warning Update the code below to correctly send/recv dependign on reputation
#warning csoler 2016-12-23: Update the code below to correctly send/recv dependign on reputation
if(!grpSyncItem->authorId.isNull() && mReputations->overallReputationLevel(grpSyncItem->authorId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
{
#ifdef NXS_NET_DEBUG_0

View file

@ -45,7 +45,7 @@ bool AuthorPending::getAuthorRep(GixsReputation& rep, const RsGxsId& authorId, c
rep.id = authorId ;
rep.reputation_level = mRep->overallReputationLevel(authorId);
#warning can it happen that reputations do not have the info yet?
#warning csoler 2017-01-10: Can it happen that reputations do not have the info yet?
return true ;
#ifdef TO_BE_REMOVED
{

View file

@ -61,6 +61,12 @@ public:
std::list<RsGxsGroupId> mGroupIds;
std::list<RsGxsGroupId> mGroupIdResult;
};
class GroupSerializedDataReq : public GxsRequest
{
public:
std::list<RsGxsGroupId> mGroupIds;
std::list<RsNxsGrp*> mGroupData;
};
class GroupDataReq : public GxsRequest
{