mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-20 23:10:39 -04:00
added structures for generic turtle search and access functions in Gxs objects
This commit is contained in:
parent
b5c1b8210b
commit
7caf06b57d
31 changed files with 513 additions and 262 deletions
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsgxsitems.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include <iostream>
|
||||
|
@ -70,4 +72,58 @@ std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta)
|
|||
return out;
|
||||
}
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const TurtleGxsInfo& i)
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 2 ; // service_id
|
||||
s += i.group_id.SIZE_IN_BYTES ;
|
||||
s += GetTlvStringSize(i.name) ;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size,uint32_t& offset,TurtleGxsInfo& i)
|
||||
{
|
||||
uint32_t saved_offset = offset ;
|
||||
bool ok = true ;
|
||||
|
||||
ok &= getRawUInt16(data, size, &offset, &i.service_id); // service_id
|
||||
ok &= i.group_id.deserialise(data, size, offset); // group_id
|
||||
ok &= GetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // group name
|
||||
|
||||
if(!ok)
|
||||
offset = saved_offset ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_t& offset,const TurtleGxsInfo& i)
|
||||
{
|
||||
uint32_t saved_offset = offset ;
|
||||
bool ok = true ;
|
||||
|
||||
ok &= setRawUInt16(data, size, &offset, i.service_id); // service_id
|
||||
ok &= i.group_id.serialise(data, size, offset); // group_id
|
||||
ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // group name
|
||||
|
||||
if(!ok)
|
||||
offset = saved_offset ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleGxsInfo& i)
|
||||
{
|
||||
std::cerr << " [GXS Info ] " << n << " group_id=" << i.group_id << " service=" << std::hex << i.service_id << std::dec << ", name=" << i.name << std::endl;
|
||||
}
|
||||
|
||||
void RsTurtleGxsSearchResultGroupSummaryItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,result,"result") ;
|
||||
}
|
||||
void RsTurtleGxsSearchResultGroupDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::TlvMemBlock_proxy prox(encrypted_nxs_group_data,encrypted_nxs_group_data_len) ;
|
||||
RsTypeSerializer::serial_process(j,ctx,prox,"encrypted_nxs_data") ;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,82 @@ public:
|
|||
RsMsgMetaData meta;
|
||||
};
|
||||
|
||||
// We should make these items templates or generic classes so that each GXS service will handle them on its own.
|
||||
|
||||
static const uint8_t RS_PKT_SUBTYPE_GXS_SUBSTRING_SEARCH_ITEM = 0x20 ;
|
||||
static const uint8_t RS_PKT_SUBTYPE_GXS_GROUP_SEARCH_ITEM = 0x21 ;
|
||||
static const uint8_t RS_PKT_SUBTYPE_GXS_GROUP_SUMMARY_ITEM = 0x22 ;
|
||||
static const uint8_t RS_PKT_SUBTYPE_GXS_GROUP_DATA_ITEM = 0x23 ;
|
||||
|
||||
class RsGxsTurtleSubStringSearchItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsTurtleSubStringSearchItem(uint16_t service): RsItem(RS_PKT_VERSION_SERVICE,service,RS_PKT_SUBTYPE_GXS_SUBSTRING_SEARCH_ITEM) {}
|
||||
virtual ~RsGxsTurtleSubStringSearchItem() {}
|
||||
|
||||
std::string match_string ; // string to match
|
||||
|
||||
std::string GetKeywords() { return match_string; }
|
||||
void clear() { match_string.clear() ; }
|
||||
|
||||
protected:
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
class RsGxsTurtleGroupSearchItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsTurtleGroupSearchItem(uint16_t service): RsItem(RS_PKT_VERSION_SERVICE,service,RS_PKT_SUBTYPE_GXS_GROUP_SEARCH_ITEM) {}
|
||||
virtual ~RsGxsTurtleGroupSearchItem() {}
|
||||
|
||||
uint16_t service_id ; // searvice to search
|
||||
Sha1CheckSum hashed_group_id ; // the group ID is hashed in order to keep it private.
|
||||
|
||||
std::string GetKeywords() { return std::string("Group request for [hashed] ")+hashed_group_id.toStdString() ; }
|
||||
void clear() { hashed_group_id.clear() ; }
|
||||
|
||||
protected:
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
struct TurtleGxsInfo
|
||||
{
|
||||
uint16_t service_id ;
|
||||
RsGxsGroupId group_id ;
|
||||
RsGxsId author;
|
||||
std::string name ;
|
||||
std::string description ;
|
||||
time_t last_post ;
|
||||
uint32_t number_of_posts ;
|
||||
};
|
||||
|
||||
class RsTurtleGxsSearchResultGroupSummaryItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsTurtleGxsSearchResultGroupSummaryItem(uint16_t service) : RsItem(RS_PKT_VERSION_SERVICE,service,RS_PKT_SUBTYPE_GXS_GROUP_SUMMARY_ITEM){}
|
||||
virtual ~RsTurtleGxsSearchResultGroupSummaryItem() {}
|
||||
|
||||
std::list<TurtleGxsInfo> result ;
|
||||
|
||||
void clear() { result.clear() ; }
|
||||
protected:
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
class RsTurtleGxsSearchResultGroupDataItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsTurtleGxsSearchResultGroupDataItem(uint16_t service) : RsItem(RS_PKT_VERSION_SERVICE,service,RS_PKT_SUBTYPE_GXS_GROUP_DATA_ITEM){}
|
||||
virtual ~RsTurtleGxsSearchResultGroupDataItem() {}
|
||||
|
||||
unsigned char *encrypted_nxs_group_data; // data is encrypted with group ID. Only the requester, or anyone who already know the group id can decrypt.
|
||||
uint32_t encrypted_nxs_group_data_len ;
|
||||
|
||||
void clear() { free(encrypted_nxs_group_data); encrypted_nxs_group_data=NULL; encrypted_nxs_group_data_len=0; }
|
||||
protected:
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue