removed old unused serialization code

This commit is contained in:
csoler 2017-05-02 22:34:45 +02:00
parent 861dc165f7
commit 4bee52c406
15 changed files with 0 additions and 6310 deletions

View File

@ -67,81 +67,11 @@ void RsGRouterTransactionChunkItem::serial_process(RsGenericSerializer::Serializ
std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl;
}
#ifdef TO_REMOVE
RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionChunkItem(void *data, uint32_t tlvsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
if(tlvsize < rssize)
{
std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl;
return NULL ;
}
RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem() ;
/* add mandatory parts first */
ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id);
ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_start);
ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_size);
ok &= getRawUInt32(data, tlvsize, &offset, &item->total_size);
if(item->chunk_size > rssize || offset > rssize - item->chunk_size) // better than if(item->chunk_size + offset > rssize)
{
std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl;
delete item;
return NULL ;
}
if( NULL == (item->chunk_data = (uint8_t*)rs_malloc(item->chunk_size)))
{
delete item;
return NULL ;
}
memcpy(item->chunk_data,&((uint8_t*)data)[offset],item->chunk_size) ;
offset += item->chunk_size ;
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
void RsGRouterTransactionAcknItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,propagation_id,"propagation_id") ;
}
#ifdef TO_REMOVE
RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionAcknItem(void *data, uint32_t tlvsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGRouterTransactionAcknItem *item = new RsGRouterTransactionAcknItem() ;
/* add mandatory parts first */
ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id);
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,routing_id,"routing_id") ;
@ -174,76 +104,6 @@ void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob
}
}
#ifdef TO_REMOVE
RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *data, uint32_t pktsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
if(pktsize < rssize)
{
std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl;
return NULL ;
}
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ;
ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
ok &= item->destination_key.deserialise(data, pktsize, offset) ;
ok &= getRawUInt32(data, pktsize, &offset, &item->service_id);
ok &= getRawUInt32(data, pktsize, &offset, &item->data_size);
if(item->data_size > 0) // This happens when the item data has been deleted from the cache
{
if(item->data_size > rssize || offset > rssize - item->data_size) // better than if(item->data_size + offset > rssize)
{
std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl;
delete item;
return NULL ;
}
if( NULL == (item->data_bytes = (uint8_t*)rs_malloc(item->data_size)))
{
delete item;
return NULL ;
}
memcpy(item->data_bytes,&((uint8_t*)data)[offset],item->data_size) ;
offset += item->data_size ;
}
else
item->data_bytes = NULL ;
ok &= item->signature.GetTlv(data, pktsize, &offset) ;
ok &= getRawUInt32(data, pktsize, &offset, &item->duplication_factor);
// make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more.
if(item->duplication_factor < 1)
{
item->duplication_factor = 1 ;
std::cerr << "(II) correcting GRouter item duplication factor from 0 to 1, to ensure backward compat." << std::endl;
}
if(item->duplication_factor > GROUTER_MAX_DUPLICATION_FACTOR)
{
std::cerr << "(WW) correcting GRouter item duplication factor of " << item->duplication_factor << ". This is very unexpected." << std::endl;
item->duplication_factor = GROUTER_MAX_DUPLICATION_FACTOR ;
}
ok &= getRawUInt32(data, pktsize, &offset, &item->flags);
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t> (j,ctx,routing_id,"routing_id") ;
@ -258,33 +118,6 @@ void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJo
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ;
}
#ifdef TO_REMOVE
RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedReceiptItem(void *data, uint32_t pktsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem() ;
ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
ok &= getRawUInt32(data, pktsize, &offset, &item->flags);
ok &= item->destination_key.deserialise(data, pktsize, offset);
ok &= getRawUInt32(data, pktsize, &offset, &item->service_id);
ok &= item->data_hash.deserialise(data, pktsize, offset);
ok &= item->signature.GetTlv(data, pktsize, &offset); // signature
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
@ -352,99 +185,11 @@ void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob
}
}
#ifdef TO_REMOVE
RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *data, uint32_t pktsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ;
RsPeerId peer_id ;
ok &= peer_id.deserialise(data, pktsize, offset) ;
item->PeerId(peer_id) ;
ok &= getRawUInt32(data, pktsize, &offset, &item->data_status);
ok &= getRawUInt32(data, pktsize, &offset, &item->tunnel_status);
ok &= getRawTimeT(data, pktsize, &offset, item->received_time_TS);
ok &= getRawTimeT(data, pktsize, &offset, item->last_sent_TS);
ok &= getRawTimeT(data, pktsize, &offset, item->last_tunnel_request_TS);
ok &= getRawUInt32(data, pktsize, &offset, &item->sending_attempts);
ok &= getRawUInt32(data, pktsize, &offset, &item->client_id);
ok &= item->item_hash.deserialise(data, pktsize, offset) ;
ok &= item->tunnel_hash.deserialise(data, pktsize, offset) ;
ok &= getRawUInt32(data, pktsize, &offset, &item->routing_flags) ;
ok &= item->incoming_routes.GetTlv(data,pktsize,&offset) ;
item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ;
if(item->data_item != NULL)
offset += item->data_item->serial_size() ;
else
ok = false ;
// Receipt item is optional.
if (offset < pktsize)
{ //
item->receipt_item = deserialise_RsGRouterSignedReceiptItem(&((uint8_t*)data)[offset],pktsize - offset);
if (item->receipt_item != NULL)
offset += item->receipt_item->serial_size();
else //
ok = false;
}
else //
item->receipt_item = NULL;
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
void RsGRouterMatrixFriendListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ;
}
#ifdef TO_REMOVE
RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(void *data, uint32_t pktsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGRouterMatrixFriendListItem *item = new RsGRouterMatrixFriendListItem() ;
uint32_t nb_friends = 0 ;
ok &= getRawUInt32(data, pktsize, &offset, &nb_friends); // file hash
item->reverse_friend_indices.resize(nb_friends) ;
for(uint32_t i=0;ok && i<nb_friends;++i)
ok &= item->reverse_friend_indices[i].deserialise(data, pktsize, offset) ;
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ;
@ -452,30 +197,6 @@ void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob
RsTypeSerializer::serial_process<time_t>(j,ctx,time_stamp,"time_stamp") ;
}
#ifdef TO_REMOVE
RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackItem(void *data, uint32_t pktsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGRouterMatrixTrackItem *item = new RsGRouterMatrixTrackItem() ;
ok &= item->provider_id.deserialise(data, pktsize, offset) ;
ok &= item->message_id.deserialise(data,pktsize,offset) ;
ok &= getRawTimeT(data, pktsize, &offset, item->time_stamp) ;
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
void RsGRouterMatrixCluesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ;
@ -489,44 +210,6 @@ template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJ
RsTypeSerializer::serial_process<time_t> (j,ctx,s.time_stamp,name+":time_stamp") ;
}
#ifdef TO_REMOVE
RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *data, uint32_t pktsize) const
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem() ;
ok &= item->destination_key.deserialise(data,pktsize,offset) ;
uint32_t nb_clues = 0 ;
ok &= getRawUInt32(data, pktsize, &offset, &nb_clues);
item->clues.clear() ;
for(uint32_t j=0;j<nb_clues;++j)
{
RoutingMatrixHitEntry HitE ;
ok &= getRawUInt32(data, pktsize, &offset, &HitE.friend_id);
ok &= getRawUFloat32(data, pktsize, &offset, HitE.weight);
ok &= getRawTimeT(data, pktsize, &offset, HitE.time_stamp);
item->clues.push_back(HitE) ;
}
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
#endif
RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
{
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ;
@ -565,508 +248,3 @@ RsGRouterSignedReceiptItem *RsGRouterSignedReceiptItem::duplicate() const
return item ;
}
#ifdef TO_REMOVE
uint32_t RsGRouterGenericDataItem::serial_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += 4 ; // data_size
s += 4 ; // service id
s += data_size ; // data
s += signature.TlvSize() ; // signature
s += 4 ; // duplication_factor
s += 4 ; // flags
return s ;
}
uint32_t RsGRouterGenericDataItem::signed_data_size() const
{
uint32_t s = 0 ; // no header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += 4 ; // data_size
s += 4 ; // service id
s += data_size ; // data
return s ;
}
uint32_t RsGRouterSignedReceiptItem::serial_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += data_hash.serial_size() ;
s += 4 ; // state
s += 4 ; // service_id
s += signature.TlvSize() ; // signature
return s ;
}
uint32_t RsGRouterSignedReceiptItem::signed_data_size() const
{
uint32_t s = 0 ; // no header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += data_hash.serial_size() ;
s += 4 ; // service_id
s += 4 ; // state
return s ;
}
uint32_t RsGRouterTransactionChunkItem::serial_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += 4 ; // chunk_start
s += 4 ; // chunk_size
s += 4 ; // total_size
s += chunk_size ; // data
return s;
}
uint32_t RsGRouterTransactionAcknItem::serial_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
return s;
}
bool RsGRouterTransactionChunkItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, propagation_id);
ok &= setRawUInt32(data, tlvsize, &offset, chunk_start);
ok &= setRawUInt32(data, tlvsize, &offset, chunk_size);
ok &= setRawUInt32(data, tlvsize, &offset, total_size);
memcpy(&((uint8_t*)data)[offset],chunk_data,chunk_size) ;
offset += chunk_size ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= destination_key.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
offset += data_size ;
ok &= signature.SetTlv(data, tlvsize, &offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, duplication_factor) ;
ok &= setRawUInt32(data, tlvsize, &offset, flags) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterTransactionAcknItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, propagation_id);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterGenericDataItem::serialise_signed_data(void *data,uint32_t size) const
{
bool ok = true;
uint32_t offset = 0;
uint32_t tlvsize = signed_data_size() ;
if(tlvsize > size)
{
ok = false;
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl;
}
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= destination_key.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
offset += data_size ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterSignedReceiptItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= setRawUInt32(data, tlvsize, &offset, flags);
ok &= destination_key.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
ok &= data_hash.serialise(data,tlvsize,offset) ;
ok &= signature.SetTlv(data,tlvsize,&offset) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterSignedReceiptItem::serialise_signed_data(void *data,uint32_t size) const
{
bool ok = true;
uint32_t offset=0;
uint32_t tlvsize = signed_data_size() ;
if(tlvsize > size)
{
ok = false;
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl;
}
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= setRawUInt32(data, tlvsize, &offset, flags);
ok &= destination_key.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
ok &= data_hash.serialise(data,tlvsize,offset) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl;
}
return ok;
}
/* serialise the data to the buffer */
uint32_t RsGRouterMatrixCluesItem::serial_size() const
{
uint32_t s = 8 ; // header
s += destination_key.serial_size() ; // Key size
s += 4 ; // list<RoutingMatrixHitEntry>::size()
s += (4+4+8) * clues.size() ;
return s ;
}
uint32_t RsGRouterMatrixFriendListItem::serial_size() const
{
uint32_t s = 8 ; // header
s += 4 ; // reverse_friend_indices.size()
s += RsPeerId::SIZE_IN_BYTES * reverse_friend_indices.size() ; // sha1 for published_key
return s ;
}
uint32_t RsGRouterMatrixTrackItem::serial_size() const
{
uint32_t s = 8 ; // header
s += 8 ; // time_stamp
s += RsPeerId::SIZE_IN_BYTES; // provider_id
s += RsMessageId::SIZE_IN_BYTES; // message_id
return s ;
}
uint32_t RsGRouterRoutingInfoItem::serial_size() const
{
uint32_t s = 8 ; // header
s += PeerId().serial_size() ;
s += 4 ; // data status_flags
s += 4 ; // tunnel status_flags
s += 8 ; // received_time
s += 8 ; // last_sent_TS
s += 8 ; // last_TR_TS
s += 4 ; // sending attempts
s += sizeof(GRouterServiceId) ; // service_id
s += tunnel_hash.serial_size() ;
s += item_hash.serial_size() ;
s += 4 ; // routing_flags
s += incoming_routes.TlvSize() ; // incoming_routes
s += data_item->serial_size(); // data_item
if(receipt_item != NULL)
s += receipt_item->serial_size(); // receipt_item
return s ;
}
bool RsGRouterMatrixFriendListItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, reverse_friend_indices.size());
for(uint32_t i=0;ok && i<reverse_friend_indices.size();++i)
ok &= reverse_friend_indices[i].serialise(data,tlvsize,offset) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterMatrixFriendListItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterMatrixCluesItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= destination_key.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, clues.size());
for(std::list<RoutingMatrixHitEntry>::const_iterator it2(clues.begin());it2!=clues.end();++it2)
{
ok &= setRawUInt32(data, tlvsize, &offset, (*it2).friend_id) ;
ok &= setRawUFloat32(data, tlvsize, &offset, (*it2).weight) ;
ok &= setRawTimeT(data, tlvsize, &offset, (*it2).time_stamp) ;
}
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterMatrixCluesItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterMatrixTrackItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= provider_id.serialise(data, tlvsize, offset) ;
ok &= message_id.serialise(data,tlvsize,offset) ;
ok &= setRawTimeT(data, tlvsize, &offset, time_stamp) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterMatrixTrackItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool FriendTrialRecord::deserialise(void *data,uint32_t& offset,uint32_t size)
{
bool ok = true ;
ok &= friend_id.deserialise(data, size, offset) ;
ok &= getRawTimeT(data, size, &offset, time_stamp) ;
ok &= getRawUFloat32(data, size, &offset, probability) ;
ok &= getRawUInt32(data, size, &offset, &nb_friends) ;
return ok ;
}
bool FriendTrialRecord::serialise(void *data,uint32_t& offset,uint32_t size) const
{
bool ok = true ;
ok &= friend_id.serialise(data, size, offset) ;
ok &= setRawTimeT(data, size, &offset, time_stamp) ;
ok &= setRawUFloat32(data, size, &offset, probability) ;
ok &= setRawUInt32(data, size, &offset, nb_friends) ;
return ok ;
}
bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= PeerId().serialise(data, tlvsize, offset) ; // we keep this.
ok &= setRawUInt32(data, tlvsize, &offset, data_status) ;
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_status) ;
ok &= setRawTimeT(data, tlvsize, &offset, received_time_TS) ;
ok &= setRawTimeT(data, tlvsize, &offset, last_sent_TS) ;
ok &= setRawTimeT(data, tlvsize, &offset, last_tunnel_request_TS) ;
ok &= setRawUInt32(data, tlvsize, &offset, sending_attempts) ;
ok &= setRawUInt32(data, tlvsize, &offset, client_id) ;
ok &= item_hash.serialise(data, tlvsize, offset) ;
ok &= tunnel_hash.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, routing_flags) ;
ok &= incoming_routes.SetTlv(data,tlvsize,&offset) ;
uint32_t ns = size - offset ;
ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ;
offset += data_item->serial_size() ;
if(receipt_item != NULL)
{
uint32_t ns = size - offset ;
ok &= receipt_item->serialise( &((uint8_t*)data)[offset], ns) ;
offset += receipt_item->serial_size() ;
}
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterRoutingInfoItem::serialisedata() size error! " << std::endl;
}
return ok;
}
// -----------------------------------------------------------------------------------//
// ------------------------------------- IO --------------------------------------- //
// -----------------------------------------------------------------------------------//
//
std::ostream& RsGRouterSignedReceiptItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterReceiptItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " Mid: " << std::hex << routing_id << std::dec << std::endl ;
o << " State: " << flags << std::endl ;
o << " Dest: " << destination_key << std::endl ;
o << " Sign: " << signature.keyId << std::endl ;
return o ;
}
std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterGenericDataItem:" << std::endl ;
o << " Direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " Routing ID: " << std::hex << routing_id << std::dec << "\"" << std::endl ;
o << " Key: " << destination_key.toStdString() << std::endl ;
o << " Data size: " << data_size << std::endl ;
o << " Data hash: " << RsDirUtil::sha1sum(data_bytes,data_size) << std::endl ;
o << " signature key: " << signature.keyId << std::endl;
o << " duplication fac:" << duplication_factor << std::endl;
o << " flags: " << flags << std::endl;
return o ;
}
std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterRoutingInfoItem:" << std::endl ;
o << " direct origin: "<< PeerId() << std::endl ;
o << " data status: "<< std::hex<< data_status << std::dec << std::endl ;
o << " tunnel status: "<< tunnel_status << std::endl ;
o << " recv time: "<< received_time_TS << std::endl ;
o << " Last sent: "<< last_sent_TS << std::endl ;
o << " Sending attempts:"<< sending_attempts << std::endl ;
o << " destination key: "<< data_item->destination_key << std::endl ;
o << " Client id: "<< client_id << std::endl ;
o << " item hash: "<< item_hash << std::endl ;
o << " tunnel hash: "<< tunnel_hash << std::endl ;
o << " Data size: "<< data_item->data_size << std::endl ;
o << " Signed receipt: "<< (void*)receipt_item << std::endl ;
return o ;
}
std::ostream& RsGRouterMatrixTrackItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterMatrixTrackItem:" << std::endl ;
o << " provider_id: " << provider_id << std::endl;
o << " message_id: " << message_id << std::endl;
o << " time_stamp: " << time_stamp << std::endl;
return o ;
}
std::ostream& RsGRouterMatrixCluesItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterMatrixCluesItem:" << std::endl ;
o << " destination k: " << destination_key.toStdString() << std::endl;
o << " routing clues: " << clues.size() << std::endl;
for(std::list<RoutingMatrixHitEntry>::const_iterator it(clues.begin());it!=clues.end();++it)
o << " " << (*it).friend_id << " " << (*it).time_stamp << " " << (*it).weight << std::endl;
return o ;
}
std::ostream& RsGRouterTransactionChunkItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterTransactionChunkItem:" << std::endl ;
o << " total_size: " << total_size << std::endl;
o << " chunk_size: " << chunk_size << std::endl;
o << " chunk_start: " << chunk_start << std::endl;
return o ;
}
std::ostream& RsGRouterTransactionAcknItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterTransactionAcknItem:" << std::endl ;
o << " routing id: " << propagation_id << std::endl;
return o ;
}
std::ostream& RsGRouterMatrixFriendListItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterMatrixCluesItem:" << std::endl ;
o << " friends: " << reverse_friend_indices.size() << std::endl;
return o ;
}
#endif

View File

@ -2205,26 +2205,6 @@ Sha1CheckSum p3GRouter::makeTunnelHash(const RsGxsId& destination,const GRouterS
return RsDirUtil::sha1sum(bytes,20) ;
}
#ifdef TO_REMOVE
bool p3GRouter::locked_getGxsOwnIdAndClientIdFromHash(const TurtleFileHash& sum,RsGxsId& gxs_id,GRouterServiceId& client_id)
{
assert( gxs_id.SIZE_IN_BYTES == 16) ;
assert(Sha1CheckSum::SIZE_IN_BYTES == 20) ;
//gxs_id = RsGxsId(sum.toByteArray());// takes the first 16 bytes
//client_id = sum.toByteArray()[19] + (sum.toByteArray()[18] << 8) ;
std::map<Sha1CheckSum, GRouterPublishedKeyInfo>::const_iterator it = _owned_key_ids.find(sum);
if(it == _owned_key_ids.end())
return false ;
gxs_id = it->second.authentication_key ;
client_id = it->second.service_id ;
return true ;
}
#endif
bool p3GRouter::loadList(std::list<RsItem*>& items)
{
{

View File

@ -52,152 +52,11 @@ RsItem *RsGxsTunnelSerialiser::create_item(uint16_t service,uint8_t item_subtype
}
}
#ifdef TO_REMOVE
std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << " Signature Key ID: " << signature.keyId << std::endl ;
out << " Public Key ID: " << gxs_key.keyId << std::endl ;
printRsItemEnd(out, "RsGxsTunnelMsgItem", indent);
return out;
}
std::ostream& RsGxsTunnelDataItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsTunnelDataItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ;
out << " service id : " << std::hex << service_id << std::dec << std::endl ;
out << " flags : " << std::hex << flags << std::dec << std::endl ;
out << " size : " << data_size << std::endl ;
out << " data : " << RsUtil::BinToHex(data,std::min(50u,data_size)) << ((data_size>50u)?"...":"") << std::endl ;
printRsItemEnd(out, "RsGxsTunnelDataItem", indent);
return out;
}
std::ostream& RsGxsTunnelDataAckItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsTunnelDataItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ;
printRsItemEnd(out, "RsGxsTunnelDataAckItem", indent);
return out;
}
std::ostream& RsGxsTunnelStatusItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsTunnelDataItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << " flags : " << std::hex << status << std::dec << std::endl ;
printRsItemEnd(out, "RsGxsTunnelStatusItem", indent);
return out;
}
/*************************************************************************/
#endif
RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem()
{
BN_free(public_key) ;
}
#ifdef TO_REMOVE
/*************************************************************************/
RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize)
{
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
#ifdef GXS_TUNNEL_ITEM_DEBUG
std::cerr << "deserializing packet..."<< std::endl ;
#endif
// look what we have...
if (*pktsize < rssize) /* check size */
{
std::cerr << "GxsTunnel deserialisation: not enough size: pktsize=" << *pktsize << ", rssize=" << rssize << std::endl ;
return NULL; /* not enough data */
}
/* set the packet length */
*pktsize = rssize;
/* ready to load */
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_GXS_TUNNEL != getRsItemService(rstype)))
{
#ifdef GXS_TUNNEL_ITEM_DEBUG
std::cerr << "GxsTunnel deserialisation: wrong type !" << std::endl ;
#endif
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY: return deserialise_RsGxsTunnelDHPublicKeyItem(data,*pktsize) ;
case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA: return deserialise_RsGxsTunnelDataItem (data,*pktsize) ;
case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK: return deserialise_RsGxsTunnelDataAckItem (data,*pktsize) ;
case RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS: return deserialise_RsGxsTunnelStatusItem (data,*pktsize) ;
default:
std::cerr << "Unknown packet type in chat!" << std::endl ;
return NULL ;
}
}
/*************************************************************************/
uint32_t RsGxsTunnelDHPublicKeyItem::serial_size()
{
uint32_t s = 8 ; // header
s += 4 ; // BN size
s += BN_num_bytes(public_key) ; // public_key
s += signature.TlvSize() ; // signature
s += gxs_key.TlvSize() ; // gxs_key
return s ;
}
uint32_t RsGxsTunnelDataItem::serial_size()
{
uint32_t s = 8 ; // header
s += 8 ; // counter
s += 4 ; // flags
s += 4 ; // service id
s += 4 ; // data_size
s += data_size; // data
return s ;
}
uint32_t RsGxsTunnelDataAckItem::serial_size()
{
uint32_t s = 8 ; // header
s += 8 ; // counter
return s ;
}
uint32_t RsGxsTunnelStatusItem::serial_size()
{
uint32_t s = 8 ; // header
s += 4 ; // flags
return s ;
}
/*************************************************************************/
#endif
void RsGxsTunnelDHPublicKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,public_key,"public_key") ;
@ -243,88 +102,11 @@ template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM
std::cerr << "[BIGNUM] : " << name << std::endl;
}
#ifdef TO_REMOVE
bool RsGxsTunnelDHPublicKeyItem::serialise(void *data,uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
/* skip the header */
offset += 8;
uint32_t s = BN_num_bytes(public_key) ;
ok &= setRawUInt32(data, tlvsize, &offset, s);
BN_bn2bin(public_key,&((unsigned char *)data)[offset]) ;
offset += s ;
ok &= signature.SetTlv(data, tlvsize, &offset);
ok &= gxs_key.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsTunnelDHPublicKeyItem::serialiseItem() Size Error! offset=" << offset << ", tlvsize=" << tlvsize << std::endl;
}
return ok ;
}
#endif
void RsGxsTunnelStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,status,"status") ;
}
#ifdef TO_REMOVE
bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef GXS_TUNNEL_ITEM_DEBUG
std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, status);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl;
}
#ifdef GXS_TUNNEL_ITEM_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
#endif
return ok;
}
#endif
void RsGxsTunnelDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,unique_item_counter,"unique_item_counter") ;
@ -339,247 +121,6 @@ void RsGxsTunnelDataAckItem::serial_process(RsGenericSerializer::SerializeJob j,
RsTypeSerializer::serial_process<uint64_t>(j,ctx,unique_item_counter,"unique_item_counter") ;
}
#ifdef TO_REMOVE
bool RsGxsTunnelDataItem::serialise(void *dt, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(dt, tlvsize, PacketId(), tlvsize);
#ifdef GXS_TUNNEL_ITEM_DEBUG
std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt64(dt, tlvsize, &offset, unique_item_counter);
ok &= setRawUInt32(dt, tlvsize, &offset, flags);
ok &= setRawUInt32(dt, tlvsize, &offset, service_id);
ok &= setRawUInt32(dt, tlvsize, &offset, data_size);
if(offset + data_size <= tlvsize)
{
memcpy(&((uint8_t*)dt)[offset],data,data_size) ;
offset += data_size ;
}
else
ok = false ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl;
}
return ok;
}
bool RsGxsTunnelDataAckItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef GXS_TUNNEL_ITEM_DEBUG
std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, unique_item_counter);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl;
}
return ok;
}
/*************************************************************************/
RsGxsTunnelDHPublicKeyItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDHPublicKeyItem(void *data,uint32_t /*size*/)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsTunnelDHPublicKeyItem *item = new RsGxsTunnelDHPublicKeyItem() ;
uint32_t s=0 ;
/* get mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &s);
if(s > rssize || rssize - s < offset)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
item->public_key = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ;
offset += s ;
ok &= item->signature.GetTlv(data, rssize, &offset) ;
ok &= item->gxs_key.GetTlv(data, rssize, &offset) ;
if (offset != rssize)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
if (!ok)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
return item ;
}
RsGxsTunnelDataItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataItem(void *dat,uint32_t size)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(dat);
bool ok = true ;
if(rssize > size)
{
std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ;
return NULL ;
}
RsGxsTunnelDataItem *item = new RsGxsTunnelDataItem();
/* get mandatory parts first */
ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter);
ok &= getRawUInt32(dat, rssize, &offset, &item->flags);
ok &= getRawUInt32(dat, rssize, &offset, &item->service_id);
ok &= getRawUInt32(dat, rssize, &offset, &item->data_size);
if(item->data_size > rssize || rssize < offset + item->data_size)
{
std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
item->data = (unsigned char*)rs_malloc(item->data_size) ;
if(item->data == NULL)
{
delete item ;
return NULL ;
}
memcpy(item->data,&((uint8_t*)dat)[offset],item->data_size) ;
offset += item->data_size ;
if (offset != rssize)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
if (!ok)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
return item ;
}
RsGxsTunnelDataAckItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataAckItem(void *dat,uint32_t /* size */)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(dat);
bool ok = true ;
RsGxsTunnelDataAckItem *item = new RsGxsTunnelDataAckItem();
/* get mandatory parts first */
ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter);
if (offset != rssize)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
if (!ok)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
return item ;
}
RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(void *dat, uint32_t size)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(dat);
bool ok = true ;
if(rssize > size)
{
std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ;
return NULL ;
}
RsGxsTunnelStatusItem *item = new RsGxsTunnelStatusItem();
/* get mandatory parts first */
ok &= getRawUInt32(dat, rssize, &offset, &item->status);
if (offset != rssize)
{
std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
if (!ok)
{
std::cerr << "RsGxsTunnelStatusItem::() Unknown error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
return item ;
}
#endif

View File

@ -2294,44 +2294,6 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
continue;
}
#ifdef TO_REMOVE
RsPeerGroupItem_deprecated *gitem = dynamic_cast<RsPeerGroupItem_deprecated *>(*it) ;
if (gitem)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::loadList() Peer group item:" << std::endl;
gitem->print(std::cerr, 10);
std::cerr << std::endl;
#endif
RsGroupInfo ginfo ;
ginfo.flag = gitem->flag ;
ginfo.name = gitem->name ;
ginfo.peerIds = gitem->pgpList.ids ;
do { ginfo.id = RsNodeGroupId::random(); } while(groupList.find(ginfo.id) != groupList.end()) ;
// Ensure backward compatibility when loading the group in old format. The id must matchthe standard default id.
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FRIENDS )) ginfo.id = RS_GROUP_ID_FRIENDS ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_COWORKERS)) ginfo.id = RS_GROUP_ID_COWORKERS ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAMILY )) ginfo.id = RS_GROUP_ID_FAMILY ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ;
if(!ginfo.id.isNull())
{
groupList[ginfo.id] = ginfo ;
std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl;
}
else
std::cerr << "(EE) no group corresponding to old format group with ID=\"" << gitem->id << "\"" << std::endl;
continue;
}
#endif
RsNodeGroupItem *gitem2 = dynamic_cast<RsNodeGroupItem*>(*it) ;

View File

@ -57,143 +57,5 @@ void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsG
RsTypeSerializer::serial_process<uint32_t>(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ;
}
#ifdef TO_REMOVE
/* serialise the data to the buffer */
bool RsBwCtrlSerialiser::serialiseAllowed(RsBwCtrlAllowedItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeAllowed(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Header: " << ok << std::endl;
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, item->allowedBw);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size Error! " << std::endl;
#endif
}
return ok;
}
RsBwCtrlAllowedItem *RsBwCtrlSerialiser::deserialiseAllowed(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t tlvsize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < tlvsize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = tlvsize;
bool ok = true;
/* ready to load */
RsBwCtrlAllowedItem *item = new RsBwCtrlAllowedItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= GetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, &(item->allowedBw));
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
uint32_t RsBwCtrlSerialiser::size(RsItem *i)
{
RsBwCtrlAllowedItem *dri;
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
{
return sizeAllowed(dri);
}
return 0;
}
bool RsBwCtrlSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
RsBwCtrlAllowedItem *dri;
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
{
return serialiseAllowed(dri, data, pktsize);
}
return false;
}
RsItem *RsBwCtrlSerialiser::deserialise(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM:
return deserialiseAllowed(data, pktsize);
break;
default:
return NULL;
break;
}
}
/*************************************************************************/
#endif

View File

@ -140,30 +140,6 @@ class RsPeerBandwidthLimitsItem : public RsItem
std::map<RsPgpId,PeerBandwidthLimits> peers ;
};
#ifdef TO_REMOVE
class RsPeerGroupItem_deprecated : public RsItem
{
public:
RsPeerGroupItem_deprecated();
virtual ~RsPeerGroupItem_deprecated();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
/* set data from RsGroupInfo to RsPeerGroupItem */
void set(RsGroupInfo &groupInfo);
/* get data from RsGroupInfo to RsPeerGroupItem */
void get(RsGroupInfo &groupInfo);
/* Mandatory */
std::string id;
std::string name;
uint32_t flag;
RsTlvPgpIdSet pgpList;
};
#endif
class RsNodeGroupItem: public RsItem
{
public:
@ -216,51 +192,6 @@ class RsPeerConfigSerialiser: public RsConfigSerializer
/**************************************************************************/
#ifdef TO_REMOVE
class RsCacheConfig: public RsItem
{
public:
RsCacheConfig()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_CACHE_CONFIG,
RS_PKT_SUBTYPE_DEFAULT)
{ return; }
virtual ~RsCacheConfig();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPeerId pid; /* Mandatory */
uint16_t cachetypeid; /* Mandatory */
uint16_t cachesubid; /* Mandatory */
std::string path; /* Mandatory */
std::string name; /* Mandatory */
RsFileHash hash; /* Mandatory */
uint64_t size; /* Mandatory */
uint32_t recvd; /* Mandatory */
};
class RsCacheConfigSerialiser: public RsSerialType
{
public:
RsCacheConfigSerialiser()
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_CACHE_CONFIG)
{ return; }
virtual ~RsCacheConfigSerialiser();
virtual uint32_t size(RsItem *);
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
virtual RsItem * deserialise(void *data, uint32_t *size);
};
#endif
/**************************************************************************/
class RsFileTransfer: public RsItem
{
public:
@ -306,26 +237,6 @@ class RsFileTransfer: public RsItem
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
#ifdef TO_REMOVE
/* Used by ft / extralist / configdirs / anyone who wants a basic file */
class RsFileConfigItem_deprecated: public RsItem
{
public:
RsFileConfigItem_deprecated()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_FILE_CONFIG,
RS_PKT_SUBTYPE_FILE_ITEM_deprecated)
{}
virtual ~RsFileConfigItem_deprecated() {}
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsTlvFileItem file;
uint32_t flags;
std::list<std::string> parent_groups ;
};
#endif
class RsFileConfigItem: public RsItem
{
public:

View File

@ -46,403 +46,14 @@ RsItem *RsGxsCommentSerialiser::create_item(uint16_t service_id,uint8_t item_sub
}
}
#ifdef TO_REMOVE
uint32_t RsGxsCommentSerialiser::size(RsItem *item)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::size()" << std::endl;
#endif
RsGxsCommentItem* com_item = NULL;
RsGxsVoteItem* vote_item = NULL;
if((com_item = dynamic_cast<RsGxsCommentItem*>(item)) != NULL)
{
return sizeGxsCommentItem(com_item);
}
else if((vote_item = dynamic_cast<RsGxsVoteItem*>(item)) != NULL)
{
return sizeGxsVoteItem(vote_item);
}
std::cerr << "RsGxsCommentSerialiser::size() ERROR invalid item" << std::endl;
return 0;
}
bool RsGxsCommentSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::serialise()" << std::endl;
#endif
RsGxsCommentItem* com_item = NULL;
RsGxsVoteItem* vote_item = NULL;
if((com_item = dynamic_cast<RsGxsCommentItem*>(item)) != NULL)
{
return serialiseGxsCommentItem(com_item, data, size);
}
else if((vote_item = dynamic_cast<RsGxsVoteItem*>(item)) != NULL)
{
return serialiseGxsVoteItem(vote_item, data, size);
}
std::cerr << "RsGxsCommentSerialiser::serialise() ERROR invalid item" << std::endl;
return false;
}
RsItem* RsGxsCommentSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(getRsItemService(PacketId()) != getRsItemService(rstype)))
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialise() ERROR Wrong Type" << std::endl;
#endif
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM:
return deserialiseGxsCommentItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM:
return deserialiseGxsVoteItem(data, size);
break;
default:
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsCommentItem::clear()
{
mMsg.mComment.clear();
}
std::ostream& RsGxsCommentItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsCommentItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Comment: " << mMsg.mComment << std::endl;
printRsItemEnd(out ,"RsGxsCommentItem", indent);
return out;
}
uint32_t RsGxsCommentSerialiser::sizeGxsCommentItem(RsGxsCommentItem *item)
{
const RsGxsComment& msg = item->mMsg;
uint32_t s = 8; // header
s += GetTlvStringSize(msg.mComment); // mMsg.
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::sizeGxsCommentItem() is: " << s << std::endl;
msg.print(std::cerr);
#endif
return s;
}
#endif
void RsGxsCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,1,mMsg.mComment,"mMsg.mComment") ;
}
#ifdef TO_REMOVE
bool RsGxsCommentSerialiser::serialiseGxsCommentItem(RsGxsCommentItem *item, void *data, uint32_t *size)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsCommentItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() Failed size too small" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsCommentItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mComment);
if(offset != tlvsize)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSCOMMENT_DEBUG
if (!ok)
{
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsCommentItem* RsGxsCommentSerialiser::deserialiseGxsCommentItem(void *data, uint32_t *size)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(getRsItemService(PacketId()) != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsCommentItem* item = new RsGxsCommentItem(getRsItemService(PacketId()));
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mComment);
if (offset != rssize)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsVoteItem::clear()
{
mMsg.mVoteType = 0;
}
std::ostream& RsGxsVoteItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsVoteItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "VoteType: " << mMsg.mVoteType << std::endl;
printRsItemEnd(out ,"RsGxsVoteItem", indent);
return out;
}
uint32_t RsGxsCommentSerialiser::sizeGxsVoteItem(RsGxsVoteItem */*item*/)
{
uint32_t s = 8; // header
s += 4; // vote flags.
return s;
}
#endif
void RsGxsVoteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mMsg.mVoteType,"mMsg.mVoteType") ;
}
#ifdef TO_REMOVE
bool RsGxsCommentSerialiser::serialiseGxsVoteItem(RsGxsVoteItem *item, void *data, uint32_t *size)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsVoteItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsVoteItem */
ok &= setRawUInt32(data, tlvsize, &offset, item->mMsg.mVoteType);
if(offset != tlvsize)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSCOMMENT_DEBUG
if (!ok)
{
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsVoteItem* RsGxsCommentSerialiser::deserialiseGxsVoteItem(void *data, uint32_t *size)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(getRsItemService(PacketId()) != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsVoteItem* item = new RsGxsVoteItem(getRsItemService(PacketId()));
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, rssize, &offset, &(item->mMsg.mVoteType));
if (offset != rssize)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSCOMMENT_DEBUG
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif

View File

@ -60,172 +60,12 @@ void RsGxsIdGroupItem::clear()
mRecognTags.clear();
mImage.TlvClear();
}
#ifdef TO_REMOVE
RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)))
return NULL; /* wrong type */
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM: return deserialise_GxsIdGroupItem(data, size);
case RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM: return deserialise_GxsIdLocalInfoItem(data, size);
#if 0
case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM: return deserialise_GxsIdOpinionItem(data, size);
case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM: return deserialise_GxsIdCommentItem(data, size);
#endif
default:
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
bool RsGxsIdItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset)
{
tlvsize = serial_size() ;
offset = 0;
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize))
{
std::cerr << "RsItem::serialise_header(): ERROR. Not enough size!" << std::endl;
return false ;
}
offset += 8;
return true ;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
uint32_t RsGxsIdLocalInfoItem::serial_size()
{
uint32_t s = 8 ; // header
s += 4 ; // number of items
s += mTimeStamps.size() * (RsGxsId::SIZE_IN_BYTES + 8) ;
s += 4 ; // number of contacts
s += mContacts.size() * RsGxsId::SIZE_IN_BYTES ;
return s;
}
std::ostream& RsGxsIdLocalInfoItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdLocalInfoItem", indent);
// convert from binary to hex.
for(std::map<RsGxsId,time_t>::const_iterator it(mTimeStamps.begin());it!=mTimeStamps.end();++it)
out << it->first << " : " << it->second << std::endl;
printRsItemEnd(out ,"RsGxsIdLocalInfoItem", indent);
return out;
}
std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "MetaData: " << meta << std::endl;
printIndent(out, int_Indent);
out << "PgpIdHash: " << mPgpIdHash << std::endl;
printIndent(out, int_Indent);
std::string signhex;
// convert from binary to hex.
for(unsigned int i = 0; i < mPgpIdSign.length(); i++)
{
rs_sprintf_append(signhex, "%02x", (uint32_t) ((uint8_t) mPgpIdSign[i]));
}
out << "PgpIdSign: " << signhex << std::endl;
printIndent(out, int_Indent);
out << "RecognTags:" << std::endl;
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags);
set.print(out, int_Indent + 2);
printRsItemEnd(out ,"RsGxsIdGroupItem", indent);
return out;
}
uint32_t RsGxsIdGroupItem::serial_size()
{
uint32_t s = 8; // header
s += Sha1CheckSum::SIZE_IN_BYTES;
s += GetTlvStringSize(mPgpIdSign);
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags);
s += set.TlvSize();
s += mImage.TlvSize() ;
return s;
}
#endif
void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ;
RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ;
}
#ifdef TO_REMOVE
bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= setRawUInt32(data, tlvsize, &offset, mTimeStamps.size()) ;
for(std::map<RsGxsId,time_t>::const_iterator it = mTimeStamps.begin();it!=mTimeStamps.end();++it)
{
ok &= it->first.serialise(data,tlvsize,offset) ;
ok &= setRawTimeT(data,tlvsize,&offset,it->second) ;
}
ok &= setRawUInt32(data, tlvsize, &offset, mContacts.size()) ;
for(std::set<RsGxsId>::const_iterator it(mContacts.begin());it!=mContacts.end();++it)
ok &= (*it).serialise(data,tlvsize,offset) ;
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
#endif
void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,mPgpIdHash,"mPgpIdHash") ;
@ -243,43 +83,6 @@ void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
}
#ifdef TO_REMOVE
bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* GxsIdGroupItem */
ok &= mPgpIdHash.serialise(data, tlvsize, offset);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, mPgpIdSign);
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags);
ok &= set.SetTlv(data, tlvsize, &offset);
ok &= mImage.SetTlv(data,tlvsize,&offset) ;
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
#endif
bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
{
clear();
@ -320,422 +123,3 @@ bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
return true ;
}
#ifdef TO_REMOVE
RsGxsIdGroupItem* RsGxsIdSerialiser::deserialise_GxsIdGroupItem(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
/* skip the header */
offset += 8;
ok &= item->mPgpIdHash.deserialise(data, rssize, offset);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->mPgpIdSign);
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->mRecognTags);
ok &= set.GetTlv(data, rssize, &offset);
// image is optional,so that we can continue reading old items.
if(offset < rssize)
ok &= item->mImage.GetTlv(data,rssize,&offset) ;
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsIdLocalInfoItem *RsGxsIdSerialiser::deserialise_GxsIdLocalInfoItem(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdLocalInfoItem* item = new RsGxsIdLocalInfoItem();
/* skip the header */
offset += 8;
uint32_t n=0 ;
ok &= getRawUInt32(data, rssize, &offset, &n) ;
for(uint32_t i=0;ok && i<n;++i)
{
RsGxsId gxsid ;
time_t TS ;
ok &= gxsid.deserialise(data,rssize,offset) ;
ok &= getRawTimeT(data,rssize,&offset,TS) ;
item->mTimeStamps[gxsid] = TS ;
}
if (offset < rssize) // backward compatibility, making that section optional.
{
ok &= getRawUInt32(data, rssize, &offset, &n) ;
RsGxsId gxsid ;
for(uint32_t i=0;ok && i<n;++i)
{
ok &= gxsid.deserialise(data,rssize,offset) ;
item->mContacts.insert(gxsid) ;
}
}
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
#endif
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#if 0
void RsGxsIdOpinionItem::clear()
{
opinion.mOpinion = 0;
opinion.mReputation = 0;
opinion.mComment = "";
}
std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdOpinionItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Opinion: " << opinion.mOpinion << std::endl;
printIndent(out, int_Indent);
out << "Reputation: " << opinion.mReputation << std::endl;
printIndent(out, int_Indent);
out << "Comment: " << opinion.mComment << std::endl;
printRsItemEnd(out ,"RsGxsIdOpinionItem", indent);
return out;
}
uint32_t RsGxsIdOpinionItem::serial_size()
{
const RsGxsIdOpinion& opinion = item->opinion;
uint32_t s = 8; // header
s += 4; // mOpinion.
s += 4; // mReputation.
s += GetTlvStringSize(opinion.mComment);
return s;
}
bool RsGxsIdOpinionItem::serialise(void *data, uint32_t *size)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* GxsIdOpinionItem */
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion);
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mReputation);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialise_GxsIdOpinionItem(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdOpinionItem* item = new RsGxsIdOpinionItem();
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion));
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mReputation));
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsIdCommentItem::clear()
{
comment.mComment.clear();
}
std::ostream& RsGxsIdCommentItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsIdCommentItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Comment: " << comment.mComment << std::endl;
printRsItemEnd(out ,"RsGxsIdCommentItem", indent);
return out;
}
uint32_t RsGxsIdCommentItem::serial_size()
{
const RsGxsIdComment& comment = item->comment;
uint32_t s = 8; // header
s += GetTlvStringSize(comment.mComment);
return s;
}
bool RsGxsIdCommentItem::serialise(void *data, uint32_t *size)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* GxsIdCommentItem */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsIdCommentItem* RsGxsIdSerialiser::deserialise_GxsIdCommentItem(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsIdCommentItem* item = new RsGxsIdCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
#endif

View File

@ -63,65 +63,6 @@ void RsGxsRecognReqItem::clear()
sign.TlvClear();
}
#ifdef TO_REMOVE
RsGxsRecognReqItem::~RsGxsRecognReqItem()
{
return;
}
std::ostream &RsGxsRecognReqItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsRecognReqItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "issued_at: " << issued_at << std::endl;
printIndent(out, int_Indent);
out << "period: " << period << std::endl;
printIndent(out, int_Indent);
out << "tag_class: " << tag_class << std::endl;
printIndent(out, int_Indent);
out << "tag_type: " << tag_type << std::endl;
printIndent(out, int_Indent);
out << "identity: " << identity << std::endl;
printIndent(out, int_Indent);
out << "nickname: " << nickname << std::endl;
printIndent(out, int_Indent);
out << "comment: " << comment << std::endl;
printIndent(out, int_Indent);
out << "signature: " << std::endl;
sign.print(out, int_Indent + 2);
printRsItemEnd(out, "RsGxsRecognReqItem", indent);
return out;
}
uint32_t RsGxsRecognSerialiser::sizeReq(RsGxsRecognReqItem *item)
{
uint32_t s = 8; /* header */
s += 4; // issued_at;
s += 4; // period;
s += 2; // tag_class;
s += 2; // tag_type;
s += item->identity.serial_size();
s += GetTlvStringSize(item->nickname);
s += GetTlvStringSize(item->comment);
s += item->sign.TlvSize();
return s;
}
#endif
void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,issued_at ,"issued_at") ;
@ -134,122 +75,6 @@ void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
}
#ifdef TO_REMOVE
/* serialise the data to the buffer */
bool RsGxsRecognSerialiser::serialiseReq(RsGxsRecognReqItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeReq(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsRecognSerialiser::serialiseReq() Header: " << ok << std::endl;
std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, item->issued_at);
ok &= setRawUInt32(data, tlvsize, &offset, item->period);
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class);
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type);
ok &= item->identity.serialise(data, tlvsize, offset);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment);
ok &= item->sign.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size Error! " << std::endl;
#endif
}
return ok;
}
RsGxsRecognReqItem *RsGxsRecognSerialiser::deserialiseReq(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t tlvsize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RECOGN_REQ != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < tlvsize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = tlvsize;
bool ok = true;
/* ready to load */
RsGxsRecognReqItem *item = new RsGxsRecognReqItem();
item->clear();
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= getRawUInt32(data, tlvsize, &offset, &(item->issued_at));
ok &= getRawUInt32(data, tlvsize, &offset, &(item->period));
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class));
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type));
ok &= item->identity.serialise(data, tlvsize, offset);
ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname);
ok &= GetTlvString(data, tlvsize, &offset, 1, item->comment);
ok &= item->sign.GetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
RsGxsRecognTagItem::~RsGxsRecognTagItem()
{
return;
}
#endif
void RsGxsRecognTagItem::clear()
{
valid_from = 0;
@ -264,56 +89,6 @@ void RsGxsRecognTagItem::clear()
sign.TlvClear();
}
#ifdef TO_REMOVE
std::ostream &RsGxsRecognTagItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsRecognTagItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "valid_from: " << valid_from << std::endl;
printIndent(out, int_Indent);
out << "valid_to: " << valid_to << std::endl;
printIndent(out, int_Indent);
out << "tag_class: " << tag_class << std::endl;
printIndent(out, int_Indent);
out << "tag_type: " << tag_type << std::endl;
printIndent(out, int_Indent);
out << "identity: " << identity << std::endl;
printIndent(out, int_Indent);
out << "nickname: " << nickname << std::endl;
printIndent(out, int_Indent);
out << "signature: " << std::endl;
sign.print(out, int_Indent + 2);
printRsItemEnd(out, "RsGxsRecognTagItem", indent);
return out;
}
uint32_t RsGxsRecognSerialiser::sizeTag(RsGxsRecognTagItem *item)
{
uint32_t s = 8; /* header */
s += 4; // valid_from;
s += 4; // valid_to;
s += 2; // tag_class;
s += 2; // tag_type;
s += item->identity.serial_size();
s += GetTlvStringSize(item->nickname);
s += item->sign.TlvSize();
return s;
}
#endif
void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,valid_from ,"valid_from") ;
@ -325,122 +100,6 @@ void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
}
#ifdef TO_REMOVE
/* serialise the data to the buffer */
bool RsGxsRecognSerialiser::serialiseTag(RsGxsRecognTagItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeTag(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsRecognSerialiser::serialiseTag() Header: " << ok << std::endl;
std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, item->valid_from);
ok &= setRawUInt32(data, tlvsize, &offset, item->valid_to);
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class);
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type);
ok &= item->identity.serialise(data, tlvsize, offset);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname);
ok &= item->sign.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size Error! " << std::endl;
#endif
}
return ok;
}
RsGxsRecognTagItem *RsGxsRecognSerialiser::deserialiseTag(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t tlvsize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RECOGN_TAG != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < tlvsize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = tlvsize;
bool ok = true;
/* ready to load */
RsGxsRecognTagItem *item = new RsGxsRecognTagItem();
item->clear();
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_from));
ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_to));
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class));
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type));
ok &= item->identity.deserialise(data, tlvsize, offset);
ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname);
ok &= item->sign.GetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
RsGxsRecognSignerItem::~RsGxsRecognSignerItem()
{
return;
}
#endif
void RsGxsRecognSignerItem::clear()
{
signing_classes.TlvClear();
@ -448,43 +107,6 @@ void RsGxsRecognSignerItem::clear()
sign.TlvClear();
}
#ifdef TO_REMOVE
std::ostream &RsGxsRecognSignerItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsRecognSignerItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "signing_classes: " << std::endl;
signing_classes.print(out, int_Indent + 2);
printIndent(out, int_Indent);
out << "key: " << std::endl;
key.print(out, int_Indent + 2);
printIndent(out, int_Indent);
out << "signature: " << std::endl;
sign.print(out, int_Indent + 2);
printRsItemEnd(out, "RsGxsRecognSignerItem", indent);
return out;
}
uint32_t RsGxsRecognSerialiser::sizeSigner(RsGxsRecognSignerItem *item)
{
uint32_t s = 8; /* header */
s += item->signing_classes.TlvSize();
s += item->key.TlvSize();
s += item->sign.TlvSize();
return s;
}
#endif
void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signing_classes ,"signing_classes") ;
@ -492,175 +114,5 @@ void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,R
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
}
#ifdef TO_REMOVE
/* serialise the data to the buffer */
bool RsGxsRecognSerialiser::serialiseSigner(RsGxsRecognSignerItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeSigner(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Header: " << ok << std::endl;
std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= item->signing_classes.SetTlv(data, tlvsize, &offset);
ok &= item->key.SetTlv(data, tlvsize, &offset);
ok &= item->sign.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size Error! " << std::endl;
#endif
}
return ok;
}
RsGxsRecognSignerItem *RsGxsRecognSerialiser::deserialiseSigner(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t tlvsize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RECOGN_SIGNER != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < tlvsize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = tlvsize;
bool ok = true;
/* ready to load */
RsGxsRecognSignerItem *item = new RsGxsRecognSignerItem();
item->clear();
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= item->signing_classes.GetTlv(data, tlvsize, &offset);
ok &= item->key.GetTlv(data, tlvsize, &offset);
ok &= item->sign.GetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
uint32_t RsGxsRecognSerialiser::size(RsItem *i)
{
RsGxsRecognReqItem *rqi;
RsGxsRecognTagItem *rti;
RsGxsRecognSignerItem *rsi;
if (NULL != (rqi = dynamic_cast<RsGxsRecognReqItem *>(i)))
{
return sizeReq(rqi);
}
if (NULL != (rti = dynamic_cast<RsGxsRecognTagItem *>(i)))
{
return sizeTag(rti);
}
if (NULL != (rsi = dynamic_cast<RsGxsRecognSignerItem *>(i)))
{
return sizeSigner(rsi);
}
return 0;
}
bool RsGxsRecognSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
RsGxsRecognReqItem *rri;
RsGxsRecognTagItem *rti;
RsGxsRecognSignerItem *rsi;
if (NULL != (rri = dynamic_cast<RsGxsRecognReqItem *>(i)))
{
return serialiseReq(rri, data, pktsize);
}
if (NULL != (rti = dynamic_cast<RsGxsRecognTagItem *>(i)))
{
return serialiseTag(rti, data, pktsize);
}
if (NULL != (rsi = dynamic_cast<RsGxsRecognSignerItem *>(i)))
{
return serialiseSigner(rsi, data, pktsize);
}
return false;
}
RsItem *RsGxsRecognSerialiser::deserialise(void *data, uint32_t *pktsize)
{
if (*pktsize < getRsPktBaseSize())
return NULL ;
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_RECOGN_REQ:
return deserialiseReq(data, pktsize);
break;
case RS_PKT_SUBTYPE_RECOGN_TAG:
return deserialiseTag(data, pktsize);
break;
case RS_PKT_SUBTYPE_RECOGN_SIGNER:
return deserialiseSigner(data, pktsize);
break;
default:
return NULL;
break;
}
}
/*************************************************************************/
#endif

View File

@ -88,525 +88,6 @@ void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJo
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUpdate,"mLastUpdate") ;
}
#ifdef TO_REMOVE
// re-defined here, in order to avoid cross-includes
#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationConfigItem", indent);
out << "mPeerId: " << mPeerId << std::endl;
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
printRsItemEnd(out, "RsReputationConfigItem", indent);
return out;
}
std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationSetItem", indent);
out << "GxsId: " << mGxsId << std::endl;
out << "Owner: " << mOwnerNodeId << std::endl;
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
out << "Opinions from neighbors: " << std::endl;
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
out << " " << it->first << ": " << it->second << std::endl;
printRsItemEnd(out, "RsReputationSetItem", indent);
return out;
}
std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationUpdateItem", indent);
out << "from: " << PeerId() << std::endl;
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
out << " " << it->first << ": " << it->second << std::endl;
printRsItemEnd(out, "RsReputationUpdateItem", indent);
return out;
}
std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationRequestItem", indent);
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
printRsItemEnd(out, "RsReputationRequestItem", indent);
return out;
}
std::ostream& RsGxsReputationBannedNodeSetItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationBannedNodeSetItem", indent);
out << "last update: " << time(NULL) - mLastActivityTS << " secs ago." << std::endl;
out << "PGP id: " << mPgpId << std::endl;
out << "Known ids: " << mKnownIdentities.ids.size() << std::endl;
printRsItemEnd(out, "RsReputationRequestItem", indent);
return out;
}
/*************************************************************************/
uint32_t RsGxsReputationConfigItem::serial_size() const
{
uint32_t s = 8; /* header */
s += mPeerId.serial_size() ; // PeerId
s += 4 ; // mLatestUpdate
s += 4 ; // mLastQuery
return s ;
}
uint32_t RsGxsReputationSetItem::serial_size() const
{
uint32_t s = 8; /* header */
s += mGxsId.serial_size() ;
s += 4 ; // mOwnOpinion
s += 4 ; // mOwnOpinionTS
s += 4 ; // mIdentityFlags
s += 4 ; // mLastUsedTS
s += mOwnerNodeId.serial_size() ;
s += 4 ; // mOpinions.size()
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
return s ;
}
uint32_t RsGxsReputationBannedNodeSetItem::serial_size() const
{
uint32_t s = 8; /* header */
s += RsPgpId::serial_size() ; // mPgpId
s += 4 ; // mLastActivityTS;
s += mKnownIdentities.TlvSize(); // mKnownIdentities
return s ;
}
uint32_t RsGxsReputationUpdateItem::serial_size() const
{
uint32_t s = 8; /* header */
s += 4 ; // mLatestUpdate
s += 4 ; // mOpinions.size();
s += (RsGxsId::serial_size() + 4) * mOpinions.size() ;
return s ;
}
uint32_t RsGxsReputationRequestItem::serial_size() const
{
uint32_t s = 8; /* header */
s += 4 ; // mLastUpdate
return s;
}
/*************************************************************************/
bool RsGxsReputationConfigItem::serialise(void *data, uint32_t& pktsize) const
{
uint32_t tlvsize ;
uint32_t offset=0;
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
bool ok = true;
ok &= mPeerId.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
ok &= setRawUInt32(data, tlvsize, &offset, mLastQuery);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsReputationConfigItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
{
uint32_t tlvsize ;
uint32_t offset=0;
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
bool ok = true;
ok &= mGxsId.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion);
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS);
ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ;
ok &= setRawUInt32(data, tlvsize, &offset, mLastUsedTS) ;
ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
{
ok &= it->first.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, it->second) ;
}
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGxsReputationBannedNodeSetItem::serialise(void *data, uint32_t& pktsize) const
{
uint32_t tlvsize ;
uint32_t offset=0;
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
bool ok = true;
ok &= mPgpId.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mLastActivityTS);
ok &= mKnownIdentities.SetTlv(data, tlvsize, &offset) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
{
uint32_t tlvsize ;
uint32_t offset=0;
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
bool ok = true;
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());ok && it!=mOpinions.end();++it)
{
ok &= it->first.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, it->second) ;
}
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsReputationUpdateItem::serialisedata() size error! " << std::endl;
}
return ok;
}
/* serialise the data to the buffer */
bool RsGxsReputationRequestItem::serialise(void *data, uint32_t& pktsize) const
{
uint32_t tlvsize ;
uint32_t offset=0;
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
bool ok = true;
ok &= setRawUInt32(data, tlvsize, &offset, mLastUpdate);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsReputationRequestItem::serialisedata() size error! " << std::endl;
}
return ok;
}
/*************************************************************************/
RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfigItem(void *data,uint32_t size)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem() ;
/* add mandatory parts first */
ok &= item->mPeerId.deserialise(data, size, offset) ;
ok &= getRawUInt32(data, size, &offset, &item->mLatestUpdate);
ok &= getRawUInt32(data, size, &offset, &item->mLastQuery);
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem() ;
/* add mandatory parts first */
ok &= item->mPgpId.deserialise(data, size, offset) ;
ok &= getRawUInt32(data, size, &offset, &item->mLastActivityTS);
ok &= item->mKnownIdentities.GetTlv(data,size,&offset) ;
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated(void *data,uint32_t tlvsize)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ;
/* add mandatory parts first */
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
item->mOwnerNodeId.clear(); // clears up, for backward compat.
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
uint32_t S ;
ok &= getRawUInt32(data, tlvsize, &offset, &S);
for(uint32_t i = 0; ok && (i < S); ++i)
{
RsPeerId pid ;
uint32_t op ;
ok &= pid.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &op);
if(ok)
item->mOpinions[pid] = op ;
}
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
RsGxsReputationSetItem_deprecated3 *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated3(void *data,uint32_t tlvsize)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationSetItem_deprecated3 *item = new RsGxsReputationSetItem_deprecated3() ;
/* add mandatory parts first */
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
uint32_t S ;
ok &= getRawUInt32(data, tlvsize, &offset, &S);
for(uint32_t i = 0; ok && (i < S); ++i)
{
RsPeerId pid ;
uint32_t op ;
ok &= pid.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &op);
if(ok)
item->mOpinions[pid] = op ;
}
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(void *data,uint32_t tlvsize)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ;
/* add mandatory parts first */
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUsedTS);
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
uint32_t S ;
ok &= getRawUInt32(data, tlvsize, &offset, &S);
for(uint32_t i = 0; ok && (i < S); ++i)
{
RsPeerId pid ;
uint32_t op ;
ok &= pid.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &op);
if(ok)
item->mOpinions[pid] = op ;
}
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdateItem(void *data,uint32_t tlvsize)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationUpdateItem *item = new RsGxsReputationUpdateItem() ;
/* add mandatory parts first */
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
uint32_t S ;
ok &= getRawUInt32(data, tlvsize, &offset, &S) ;
for(uint32_t i=0;ok && i<S;++i)
{
RsGxsId gid ;
uint32_t op ;
ok &= gid.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &op);
if(ok)
item->mOpinions[gid] = op ;
}
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
RsGxsReputationRequestItem *RsGxsReputationSerialiser::deserialiseReputationRequestItem(void *data,uint32_t tlvsize)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationRequestItem *item = new RsGxsReputationRequestItem() ;
/* add mandatory parts first */
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUpdate);
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
return NULL ;
}
return item;
}
/*************************************************************************/
RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_REPUTATION != getRsItemService(rstype)))
{
std::cerr << "RsReputationSerialiser::deserialise(): wrong item type " << std::hex << rstype << std::dec << std::endl;
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize);
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3: return deserialiseReputationSetItem_deprecated3(data, *pktsize);
case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem (data, *pktsize);
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize);
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize);
default:
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;
return NULL;
break;
}
}
#endif
/*************************************************************************/
RsItem *RsGxsReputationSerialiser::create_item(uint16_t service,uint8_t subtype) const

View File

@ -72,225 +72,4 @@ RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONF
saveToDisc = true;
}
#ifdef TO_REMOVE
/*************************************************************************/
RsHistoryMsgItem::~RsHistoryMsgItem()
{
}
void RsHistoryMsgItem::clear()
{
incoming = false;
peerId.clear();
peerName.clear();
sendTime = 0;
recvTime = 0;
message.clear();
msgId = 0;
saveToDisc = true;
}
std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsHistoryMsgItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "chatPeerid: " << chatPeerId << std::endl;
printIndent(out, int_Indent);
out << "incoming: " << (incoming ? "1" : "0") << std::endl;
printIndent(out, int_Indent);
out << "peerId: " << peerId << std::endl;
printIndent(out, int_Indent);
out << "peerName: " << peerName << std::endl;
printIndent(out, int_Indent);
out << "sendTime: " << sendTime << std::endl;
printIndent(out, int_Indent);
out << "recvTime: " << recvTime << std::endl;
printIndent(out, int_Indent);
std::string cnv_message(message.begin(), message.end());
out << "message: " << cnv_message << std::endl;
printRsItemEnd(out, "RsHistoryMsgItem", indent);
return out;
}
RsHistorySerialiser::~RsHistorySerialiser()
{
}
uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item)
{
uint32_t s = 8; /* header */
s += 2; /* version */
s += item->chatPeerId.serial_size();
s += 1; /* incoming */
s += item->peerId.serial_size();
s += GetTlvStringSize(item->peerName);
s += 4; /* sendTime */
s += 4; /* recvTime */
s += GetTlvStringSize(item->message);
return s;
}
/* serialise the data to the buffer */
bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize)
{
uint32_t tlvsize = sizeHistoryMsgItem(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsHistorySerialiser::serialiseItem() Header: " << ok << std::endl;
std::cerr << "RsHistorySerialiser::serialiseItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt16(data, tlvsize, &offset, 0); // version
ok &= item->chatPeerId.serialise(data, tlvsize, offset) ;
uint8_t dummy = item->incoming ? 1 : 0;
ok &= setRawUInt8(data, tlvsize, &offset, dummy);
ok &= item->peerId.serialise(data, tlvsize, offset) ;
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->peerName);
ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime);
ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->message);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsHistorySerialiser::serialiseItem() Size Error! " << std::endl;
#endif
}
return ok;
}
RsHistoryMsgItem *RsHistorySerialiser::deserialiseHistoryMsgItem(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsHistoryMsgItem *item = new RsHistoryMsgItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
uint16_t version = 0;
ok &= getRawUInt16(data, rssize, &offset, &version);
ok &= item->chatPeerId.deserialise(data, rssize, offset) ;
uint8_t dummy;
ok &= getRawUInt8(data, rssize, &offset, &dummy);
item->incoming = (dummy == 1);
ok &= item->peerId.deserialise(data, rssize, offset) ;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->peerName);
ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime));
ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime));
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
uint32_t RsHistorySerialiser::size(RsItem *item)
{
RsHistoryMsgItem* hi;
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
{
return sizeHistoryMsgItem(hi);
}
return 0;
}
bool RsHistorySerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
{
RsHistoryMsgItem* hi;
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
{
return serialiseHistoryMsgItem(hi, data, pktsize);
}
return false;
}
RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_DEFAULT:
return deserialiseHistoryMsgItem(data, pktsize);
}
return NULL;
}
/*************************************************************************/
#endif

File diff suppressed because it is too large Load Diff

View File

@ -63,339 +63,5 @@ void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneric
RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPongTS,"mPongTS") ;
}
#ifdef TO_REMOVE
RsRttPingItem::~RsRttPingItem()
{
return;
}
void RsRttPingItem::clear()
{
mSeqNo = 0;
mPingTS = 0;
}
std::ostream& RsRttPingItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsRttPingItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "SeqNo: " << mSeqNo << std::endl;
printIndent(out, int_Indent);
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
printRsItemEnd(out, "RsRttPingItem", indent);
return out;
}
RsRttPongItem::~RsRttPongItem()
{
return;
}
void RsRttPongItem::clear()
{
mSeqNo = 0;
mPingTS = 0;
mPongTS = 0;
}
std::ostream& RsRttPongItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsRttPongItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "SeqNo: " << mSeqNo << std::endl;
printIndent(out, int_Indent);
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
printIndent(out, int_Indent);
out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl;
printRsItemEnd(out, "RsRttPongItem", indent);
return out;
}
/*************************************************************************/
uint32_t RsRttSerialiser::sizeRttPingItem(RsRttPingItem */*item*/)
{
uint32_t s = 8; /* header */
s += 4; /* seqno */
s += 8; /* pingTS */
return s;
}
/* serialise the data to the buffer */
bool RsRttSerialiser::serialiseRttPingItem(RsRttPingItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeRttPingItem(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Header: " << ok << std::endl;
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size Error! " << std::endl;
}
return ok;
}
RsRttPingItem *RsRttSerialiser::deserialiseRttPingItem(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RTT_PING != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsRttPingItem *item = new RsRttPingItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
/*************************************************************************/
uint32_t RsRttSerialiser::sizeRttPongItem(RsRttPongItem */*item*/)
{
uint32_t s = 8; /* header */
s += 4; /* seqno */
s += 8; /* pingTS */
s += 8; /* pongTS */
return s;
}
/* serialise the data to the buffer */
bool RsRttSerialiser::serialiseRttPongItem(RsRttPongItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeRttPongItem(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Header: " << ok << std::endl;
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
ok &= setRawUInt64(data, tlvsize, &offset, item->mPongTS);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size Error! " << std::endl;
}
return ok;
}
RsRttPongItem *RsRttSerialiser::deserialiseRttPongItem(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_RTT_PONG != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsRttPongItem *item = new RsRttPongItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
ok &= getRawUInt64(data, rssize, &offset, &(item->mPongTS));
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
uint32_t RsRttSerialiser::size(RsItem *i)
{
RsRttPingItem *ping;
RsRttPongItem *pong;
if (NULL != (ping = dynamic_cast<RsRttPingItem *>(i)))
{
return sizeRttPingItem(ping);
}
else if (NULL != (pong = dynamic_cast<RsRttPongItem *>(i)))
{
return sizeRttPongItem(pong);
}
return 0;
}
bool RsRttSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialise()" << std::endl;
#endif
RsRttPingItem *ping;
RsRttPongItem *pong;
if (NULL != (ping = dynamic_cast<RsRttPingItem *>(i)))
{
return serialiseRttPingItem(ping, data, pktsize);
}
else if (NULL != (pong = dynamic_cast<RsRttPongItem *>(i)))
{
return serialiseRttPongItem(pong, data, pktsize);
}
return false;
}
RsItem* RsRttSerialiser::deserialise(void *data, uint32_t *pktsize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsRttSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_RTT != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_RTT_PING:
return deserialiseRttPingItem(data, pktsize);
break;
case RS_PKT_SUBTYPE_RTT_PONG:
return deserialiseRttPongItem(data, pktsize);
break;
default:
return NULL;
break;
}
return NULL;
}
/*************************************************************************/
#endif

View File

@ -46,94 +46,6 @@ RsItem *RsGxsWikiSerialiser::create_item(uint16_t service, uint8_t item_sub_id)
}
}
#ifdef TO_REMOVE
uint32_t RsGxsWikiSerialiser::size(RsItem *item)
{
RsGxsWikiCollectionItem* grp_item = NULL;
RsGxsWikiSnapshotItem* snap_item = NULL;
RsGxsWikiCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
{
return sizeGxsWikiCollectionItem(grp_item);
}
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
{
return sizeGxsWikiSnapshotItem(snap_item);
}
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
{
return sizeGxsWikiCommentItem(com_item);
}
return 0;
}
bool RsGxsWikiSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsWikiCollectionItem* grp_item = NULL;
RsGxsWikiSnapshotItem* snap_item = NULL;
RsGxsWikiCommentItem* com_item = NULL;
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
{
return serialiseGxsWikiCollectionItem(grp_item, data, size);
}
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
{
return serialiseGxsWikiSnapshotItem(snap_item, data, size);
}
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
{
return serialiseGxsWikiCommentItem(com_item, data, size);
}
return false;
}
RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM:
return deserialiseGxsWikiCollectionItem(data, size);
break;
case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM:
return deserialiseGxsWikiSnapshotItem(data, size);
break;
case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM:
return deserialiseGxsWikiCommentItem(data, size);
break;
default:
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif
void RsGxsWikiCollectionItem::clear()
{
collection.mDescription.clear();
@ -141,38 +53,6 @@ void RsGxsWikiCollectionItem::clear()
collection.mHashTags.clear();
}
#ifdef TO_REMOVE
std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWikiCollectionItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << collection.mDescription << std::endl;
printIndent(out, int_Indent);
out << "Category: " << collection.mCategory << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << collection.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsWikiCollectionItem", indent);
return out;
}
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item)
{
const RsWikiCollection& collection = item->collection;
uint32_t s = 8; // header
s += GetTlvStringSize(collection.mDescription);
s += GetTlvStringSize(collection.mCategory);
s += GetTlvStringSize(collection.mHashTags);
return s;
}
#endif
void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,collection.mDescription,"collection.mDescription") ;
@ -180,448 +60,25 @@ void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,collection.mHashTags ,"collection.mHashTags") ;
}
#ifdef TO_REMOVE
bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWikiCollectionItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWikiCollectionItem */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWikiCollectionItem* item = new RsGxsWikiCollectionItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif
void RsGxsWikiSnapshotItem::clear()
{
snapshot.mPage.clear();
snapshot.mHashTags.clear();
}
#ifdef TO_REMOVE
std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWikiSnapshotItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Page: " << snapshot.mPage << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << snapshot.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsWikiSnapshotItem", indent);
return out;
}
uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item)
{
const RsWikiSnapshot& snapshot = item->snapshot;
uint32_t s = 8; // header
s += GetTlvStringSize(snapshot.mPage);
s += GetTlvStringSize(snapshot.mHashTags);
return s;
}
#endif
void RsGxsWikiSnapshotItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_WIKI_PAGE,snapshot.mPage,"snapshot.mPage") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG ,snapshot.mPage,"snapshot.mHashTags") ;
}
#ifdef TO_REMOVE
bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWikiSnapshotItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWikiSnapshotItem */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWikiSnapshotItem* item = new RsGxsWikiSnapshotItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif
void RsGxsWikiCommentItem::clear()
{
comment.mComment.clear();
}
#ifdef TO_REMOVE
std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWikiCommentItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Comment: " << comment.mComment << std::endl;
printRsItemEnd(out ,"RsGxsWikiCommentItem", indent);
return out;
}
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item)
{
const RsWikiComment& comment = item->comment;
uint32_t s = 8; // header
s += GetTlvStringSize(comment.mComment);
return s;
}
#endif
void RsGxsWikiCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"comment.mComment") ;
}
#ifdef TO_REMOVE
bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWikiCommentItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWikiCommentItem */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
if(offset != tlvsize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *data, uint32_t *size)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWikiCommentItem* item = new RsGxsWikiCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
if (offset != rssize)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXSID_DEBUG
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif

View File

@ -46,398 +46,19 @@ RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype)
}
}
#ifdef TO_REMOVE
uint32_t RsGxsWireSerialiser::size(RsItem *item)
{
RsGxsWireGroupItem* grp_item = NULL;
RsGxsWirePulseItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
{
return sizeGxsWireGroupItem(grp_item);
}
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
{
return sizeGxsWirePulseItem(snap_item);
}
return 0;
}
bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsWireGroupItem* grp_item = NULL;
RsGxsWirePulseItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
{
return serialiseGxsWireGroupItem(grp_item, data, size);
}
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
{
return serialiseGxsWirePulseItem(snap_item, data, size);
}
return false;
}
RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM:
return deserialiseGxsWireGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM:
return deserialiseGxsWirePulseItem(data, size);
break;
default:
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif
void RsGxsWireGroupItem::clear()
{
group.mDescription.clear();
}
#ifdef TO_REMOVE
std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWireGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << group.mDescription << std::endl;
printRsItemEnd(out ,"RsGxsWireGroupItem", indent);
return out;
}
uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item)
{
const RsWireGroup& group = item->group;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mDescription);
return s;
}
#endif
void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
}
#ifdef TO_REMOVE
bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWireGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWireGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription);
if(offset != tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef WIRE_DEBUG
if (!ok)
{
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWireGroupItem* item = new RsGxsWireGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription);
if (offset != rssize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWirePulseItem::clear()
{
pulse.mPulseText.clear();
pulse.mHashTags.clear();
}
std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWirePulseItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Page: " << pulse.mPulseText << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << pulse.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsWirePulseItem", indent);
return out;
}
uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item)
{
const RsWirePulse& pulse = item->pulse;
uint32_t s = 8; // header
s += GetTlvStringSize(pulse.mPulseText);
s += GetTlvStringSize(pulse.mHashTags);
return s;
}
#endif
void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ;
}
#ifdef TO_REMOVE
bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWirePulseItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWirePulseItem */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags);
if(offset != tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef WIRE_DEBUG
if (!ok)
{
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype)))
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWirePulseItem* item = new RsGxsWirePulseItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags);
if (offset != rssize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif