mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added load/save of message tracking info
This commit is contained in:
parent
47dd70fbe8
commit
3de29c589c
@ -45,17 +45,18 @@ RsItem *RsGRouterSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GROUTER_DATA: return deserialise_RsGRouterGenericDataItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: return deserialise_RsGRouterTransactionChunkItem(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: return deserialise_RsGRouterTransactionAcknItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT: return deserialise_RsGRouterSignedReceiptItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return deserialise_RsGRouterMatrixCluesItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST: return deserialise_RsGRouterMatrixFriendListItem(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO: return deserialise_RsGRouterRoutingInfoItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_DATA: return deserialise_RsGRouterGenericDataItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: return deserialise_RsGRouterTransactionChunkItem(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: return deserialise_RsGRouterTransactionAcknItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT: return deserialise_RsGRouterSignedReceiptItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return deserialise_RsGRouterMatrixCluesItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK: return deserialise_RsGRouterMatrixTrackItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST: return deserialise_RsGRouterMatrixFriendListItem(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO: return deserialise_RsGRouterRoutingInfoItem (data, *pktsize);
|
||||
|
||||
default:
|
||||
std::cerr << "RsGRouterSerialiser::deserialise(): Could not de-serialise item. SubPacket id = " << std::hex << getRsItemSubType(rstype) << " id = " << rstype << std::dec << std::endl;
|
||||
return NULL;
|
||||
default:
|
||||
std::cerr << "RsGRouterSerialiser::deserialise(): Could not de-serialise item. SubPacket id = " << std::hex << getRsItemSubType(rstype) << " id = " << rstype << std::dec << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -269,6 +270,28 @@ RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixF
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
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 &= getRawUInt32(data, pktsize, &offset, &item->provider_id) ;
|
||||
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;
|
||||
}
|
||||
RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *data, uint32_t pktsize) const
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
@ -559,6 +582,17 @@ uint32_t RsGRouterMatrixFriendListItem::serial_size() const
|
||||
|
||||
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
|
||||
@ -637,6 +671,26 @@ bool RsGRouterMatrixCluesItem::serialise(void *data,uint32_t& size) const
|
||||
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 &= setRawUInt32(data, tlvsize, &offset, provider_id) ;
|
||||
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 ;
|
||||
@ -701,6 +755,7 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
||||
// ------------------------------------- IO --------------------------------------- //
|
||||
// -----------------------------------------------------------------------------------//
|
||||
//
|
||||
|
||||
std::ostream& RsGRouterSignedReceiptItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "RsGRouterReceiptItem:" << std::endl ;
|
||||
@ -746,6 +801,15 @@ std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t)
|
||||
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 ;
|
||||
|
@ -33,20 +33,19 @@
|
||||
#include "retroshare/rsgrouter.h"
|
||||
#include "groutermatrix.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_PUBLISH_KEY = 0x01 ; // used to publish a key
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_ACK_deprecated = 0x03 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT_deprecated = 0x04 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA_deprecated = 0x05 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA_deprecated2 = 0x06 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA = 0x07 ; // used to send data to a destination (Signed by source)
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT = 0x08 ; // long-distance acknowledgement of data received
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK = 0x10 ; // chunk of data. Used internally.
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN = 0x11 ; // acknowledge for finished transaction. Not necessary, but increases fiability.
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES = 0x80 ; // item to save matrix clues
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST = 0x82 ; // item to save friend lists
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO = 0x93 ; //
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_PUBLISH_KEY = 0x01 ; // used to publish a key
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_ACK_deprecated = 0x03 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT_deprecated = 0x04 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA_deprecated = 0x05 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA_deprecated2 = 0x06 ; // don't use!
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA = 0x07 ; // used to send data to a destination (Signed by source)
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT = 0x08 ; // long-distance acknowledgement of data received
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK = 0x10 ; // chunk of data. Used internally.
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN = 0x11 ; // acknowledge for finished transaction. Not necessary, but increases fiability.
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES = 0x80 ; // item to save matrix clues
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST = 0x82 ; // item to save friend lists
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO = 0x93 ; //
|
||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK = 0x94 ; // item to save matrix track info
|
||||
|
||||
const uint8_t QOS_PRIORITY_RS_GROUTER = 4 ; // relevant for items that travel through friends
|
||||
|
||||
@ -243,6 +242,24 @@ class RsGRouterMatrixCluesItem: public RsGRouterItem
|
||||
std::list<RoutingMatrixHitEntry> clues ;
|
||||
};
|
||||
|
||||
class RsGRouterMatrixTrackItem: public RsGRouterItem
|
||||
{
|
||||
public:
|
||||
RsGRouterMatrixTrackItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK)
|
||||
{ setPriorityLevel(0) ; } // this item is never sent through the network
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
virtual void clear() {}
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ;
|
||||
|
||||
// packet data
|
||||
//
|
||||
RsGxsMessageId message_id ;
|
||||
uint32_t provider_id ;
|
||||
time_t time_stamp ;
|
||||
};
|
||||
class RsGRouterMatrixFriendListItem: public RsGRouterItem
|
||||
{
|
||||
public:
|
||||
@ -317,6 +334,7 @@ private:
|
||||
RsGRouterTransactionAcknItem *deserialise_RsGRouterTransactionAcknItem(void *data,uint32_t size) const ;
|
||||
RsGRouterSignedReceiptItem *deserialise_RsGRouterSignedReceiptItem(void *data,uint32_t size) const ;
|
||||
RsGRouterMatrixCluesItem *deserialise_RsGRouterMatrixCluesItem(void *data,uint32_t size) const ;
|
||||
RsGRouterMatrixTrackItem *deserialise_RsGRouterMatrixTrackItem(void *data,uint32_t size) const ;
|
||||
RsGRouterMatrixFriendListItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ;
|
||||
RsGRouterRoutingInfoItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ;
|
||||
};
|
||||
|
@ -284,55 +284,78 @@ bool GRouterMatrix::saveList(std::list<RsItem*>& items)
|
||||
std::cerr << " GRoutingMatrix::saveList()" << std::endl;
|
||||
#endif
|
||||
|
||||
RsGRouterMatrixFriendListItem *item = new RsGRouterMatrixFriendListItem ;
|
||||
RsGRouterMatrixFriendListItem *item = new RsGRouterMatrixFriendListItem ;
|
||||
|
||||
item->reverse_friend_indices = _reverse_friend_indices ;
|
||||
items.push_back(item) ;
|
||||
item->reverse_friend_indices = _reverse_friend_indices ;
|
||||
items.push_back(item) ;
|
||||
|
||||
for(std::map<GRouterKeyId,std::list<RoutingMatrixHitEntry> >::const_iterator it(_routing_clues.begin());it!=_routing_clues.end();++it)
|
||||
{
|
||||
RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem ;
|
||||
for(std::map<GRouterKeyId,std::list<RoutingMatrixHitEntry> >::const_iterator it(_routing_clues.begin());it!=_routing_clues.end();++it)
|
||||
{
|
||||
RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem ;
|
||||
|
||||
item->destination_key = it->first ;
|
||||
item->clues = it->second ;
|
||||
item->destination_key = it->first ;
|
||||
item->clues = it->second ;
|
||||
|
||||
items.push_back(item) ;
|
||||
}
|
||||
items.push_back(item) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
for(std::map<RsGxsMessageId,RoutingTrackEntry>::const_iterator it(_tracking_clues.begin());it!=_tracking_clues.end();++it)
|
||||
{
|
||||
RsGRouterMatrixTrackItem *item = new RsGRouterMatrixTrackItem ;
|
||||
|
||||
item->provider_id = it->second.friend_id ;
|
||||
item->time_stamp = it->second.time_stamp ;
|
||||
item->message_id = it->first ;
|
||||
|
||||
items.push_back(item) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool GRouterMatrix::loadList(std::list<RsItem*>& items)
|
||||
{
|
||||
RsGRouterMatrixFriendListItem *itm1 = NULL ;
|
||||
RsGRouterMatrixCluesItem *itm2 = NULL ;
|
||||
RsGRouterMatrixFriendListItem *itm1 = NULL ;
|
||||
RsGRouterMatrixCluesItem *itm2 = NULL ;
|
||||
RsGRouterMatrixTrackItem *itm3 = NULL ;
|
||||
|
||||
#ifdef ROUTING_MATRIX_DEBUG
|
||||
std::cerr << " GRoutingMatrix::loadList()" << std::endl;
|
||||
#endif
|
||||
|
||||
for(std::list<RsItem*>::const_iterator it(items.begin());it!=items.end();++it)
|
||||
{
|
||||
if(NULL != (itm2 = dynamic_cast<RsGRouterMatrixCluesItem*>(*it)))
|
||||
{
|
||||
for(std::list<RsItem*>::const_iterator it(items.begin());it!=items.end();++it)
|
||||
{
|
||||
if(NULL != (itm3 = dynamic_cast<RsGRouterMatrixTrackItem*>(*it)))
|
||||
{
|
||||
#ifdef ROUTING_MATRIX_DEBUG
|
||||
std::cerr << " initing routing clues." << std::endl;
|
||||
std::cerr << " initing tracking clues." << std::endl;
|
||||
#endif
|
||||
RoutingTrackEntry rte ;
|
||||
rte.friend_id = itm3->provider_id ;
|
||||
rte.time_stamp = itm3->time_stamp ;
|
||||
|
||||
_tracking_clues[itm3->message_id] = rte;
|
||||
}
|
||||
if(NULL != (itm2 = dynamic_cast<RsGRouterMatrixCluesItem*>(*it)))
|
||||
{
|
||||
#ifdef ROUTING_MATRIX_DEBUG
|
||||
std::cerr << " initing routing clues." << std::endl;
|
||||
#endif
|
||||
|
||||
_routing_clues[itm2->destination_key] = itm2->clues ;
|
||||
_proba_need_updating = true ; // notifies to re-compute all the info.
|
||||
}
|
||||
if(NULL != (itm1 = dynamic_cast<RsGRouterMatrixFriendListItem*>(*it)))
|
||||
{
|
||||
_reverse_friend_indices = itm1->reverse_friend_indices ;
|
||||
_friend_indices.clear() ;
|
||||
_routing_clues[itm2->destination_key] = itm2->clues ;
|
||||
_proba_need_updating = true ; // notifies to re-compute all the info.
|
||||
}
|
||||
if(NULL != (itm1 = dynamic_cast<RsGRouterMatrixFriendListItem*>(*it)))
|
||||
{
|
||||
_reverse_friend_indices = itm1->reverse_friend_indices ;
|
||||
_friend_indices.clear() ;
|
||||
|
||||
for(uint32_t i=0;i<_reverse_friend_indices.size();++i)
|
||||
_friend_indices[_reverse_friend_indices[i]] = i ;
|
||||
for(uint32_t i=0;i<_reverse_friend_indices.size();++i)
|
||||
_friend_indices[_reverse_friend_indices[i]] = i ;
|
||||
|
||||
_proba_need_updating = true ; // notifies to re-compute all the info.
|
||||
}
|
||||
}
|
||||
_proba_need_updating = true ; // notifies to re-compute all the info.
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user