Implement GXS group base64 public data export

Link to GXS group is a concept that is useful for almost all GXS based
  services, gen exchange now provides method to facilitate the
  implementation of group links at service layer.
Move waitToken in token service interface.
This commit is contained in:
Gioacchino Mazzurco 2019-10-28 15:07:50 +01:00
parent a9510da61b
commit 6f3d842d30
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
5 changed files with 173 additions and 52 deletions

View file

@ -21,6 +21,7 @@
* *
*******************************************************************************/
#include <unistd.h>
#include <algorithm>
#include "pqi/pqihash.h"
#include "rsgenexchange.h"
@ -38,8 +39,7 @@
#include "rsgxsutil.h"
#include "rsserver/p3face.h"
#include "retroshare/rsevents.h"
#include <algorithm>
#include "util/radix64.h"
#define PUB_GRP_MASK 0x000f
#define RESTR_GRP_MASK 0x00f0
@ -3445,6 +3445,71 @@ bool RsGenExchange::localSearch( const std::string& matchString,
return mNetService->search(matchString, results);
}
bool RsGenExchange::exportGroupBase64(
std::string& radix, const RsGxsGroupId& groupId, std::string& errMsg )
{
constexpr auto fname = __PRETTY_FUNCTION__;
const auto failure = [&](const std::string& err)
{
errMsg = err;
RsErr() << fname << " " << err << std::endl;
return false;
};
if(groupId.isNull()) return failure("groupId cannot be null");
const std::list<RsGxsGroupId> groupIds({groupId});
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mDataAccess->requestGroupInfo(
token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds);
RsTokenService::GxsRequestStatus wtStatus = mDataAccess->waitToken(token);
if(wtStatus != RsTokenService::COMPLETE)
return failure( "waitToken(...) failed with: " +
std::to_string(wtStatus) );
uint8_t* buf = nullptr;
uint32_t size;
RsGxsGroupId grpId;
if(!getSerializedGroupData(token, grpId, buf, size))
return failure("failed retrieving GXS data");
Radix64::encode(buf, static_cast<int>(size), radix);
free(buf);
return true;
}
bool RsGenExchange::importGroupBase64(
const std::string& radix, RsGxsGroupId& groupId,
std::string& errMsg )
{
constexpr auto fname = __PRETTY_FUNCTION__;
const auto failure = [&](const std::string& err)
{
errMsg = err;
RsErr() << fname << " " << err << std::endl;
return false;
};
if(radix.empty()) return failure("radix is empty");
std::vector<uint8_t> mem = Radix64::decode(radix);
if(mem.empty()) return failure("radix seems corrupted");
// On success this also import the group as pending validation
if(!deserializeGroupData(
mem.data(), static_cast<uint32_t>(mem.size()),
reinterpret_cast<RsGxsGroupId*>(&groupId) ))
return failure("failed deserializing group");
return true;
}
RsGxsChanges::RsGxsChanges() :
RsEvent(RsEventType::GXS_CHANGES), mServiceType(RsServiceType::NONE),
mService(nullptr) {}
RsGxsIface::~RsGxsIface() = default;
RsGxsGroupSummary::~RsGxsGroupSummary() = default;

View file

@ -95,7 +95,8 @@ typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgItem*> > GxsMsgRelatedDa
class RsGixs;
class RsGenExchange : public RsNxsObserver, public RsTickingThread, public RsGxsIface
class RsGenExchange : public RsNxsObserver, public RsTickingThread,
public RsGxsIface
{
public:
@ -325,6 +326,19 @@ public:
bool localSearch( const std::string& matchString,
std::list<RsGxsGroupSummary>& results );
/// @see RsGxsIface
bool exportGroupBase64(
std::string& radix, const RsGxsGroupId& groupId,
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
) override;
/// @see RsGxsIface
bool importGroupBase64(
const std::string& radix,
RsGxsGroupId& groupId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
) override;
protected:
bool messagePublicationTest(const RsGxsMsgMetaData&) ;