mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-04 20:34:26 -04:00
merged upstream/master
This commit is contained in:
commit
cecd9a3368
136 changed files with 5050 additions and 2182 deletions
|
@ -1273,6 +1273,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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
|
||||
#include "rsitems/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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -328,6 +328,23 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
|||
mUpdateCounter = 0;
|
||||
}
|
||||
|
||||
void RsGxsNetService::getItemNames(std::map<uint8_t,std::string>& names) const
|
||||
{
|
||||
names.clear();
|
||||
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM ] = "Group Sync Request" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM ] = "Group Sync" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM ] = "Group Stats" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_GRP_ITEM ] = "Group Data" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM ] = "Encrypted data" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM ] = "Session Key" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM ] = "Message Sync" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM ] = "Message Sync Request" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_MSG_ITEM ] = "Message Data" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM ] = "Transaction" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM ] = "Publish key" ;
|
||||
}
|
||||
|
||||
RsGxsNetService::~RsGxsNetService()
|
||||
{
|
||||
RS_STACK_MUTEX(mNxsMutex) ;
|
||||
|
@ -1972,7 +1989,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 +3017,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
|
||||
|
|
|
@ -99,6 +99,7 @@ public:
|
|||
|
||||
virtual RsServiceInfo getServiceInfo() { return mServiceInfo; }
|
||||
|
||||
virtual void getItemNames(std::map<uint8_t,std::string>& names) const ;
|
||||
public:
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue