merged new GRouter model (branch v0.6-NewGRouterModel 7837-7863). Provides a fully functional distant messaging system. The asynchronous part will be implemented shortly

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7867 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-01-23 19:28:10 +00:00
commit 34f968a112
44 changed files with 2447 additions and 1854 deletions

View File

@ -36,6 +36,10 @@
class RsItem ; class RsItem ;
static const uint32_t GROUTER_CLIENT_SERVICE_DATA_STATUS_UNKNOWN = 0x0000 ; // unused.
static const uint32_t GROUTER_CLIENT_SERVICE_DATA_STATUS_RECEIVED = 0x0001 ; // sent when data has been received and a receipt is available.
static const uint32_t GROUTER_CLIENT_SERVICE_DATA_STATUS_FAILED = 0x0002 ; // sent if the global router cannot send after a while
class GRouterClientService class GRouterClientService
{ {
public: public:
@ -49,18 +53,19 @@ class GRouterClientService
// //
// GRouter stays owner of the item, so the client should not delete it! // GRouter stays owner of the item, so the client should not delete it!
// //
virtual void receiveGRouterData(const GRouterKeyId& destination_key, const RsGRouterGenericDataItem * /*item*/) virtual void receiveGRouterData(const RsGxsId& destination_key,const RsGxsId& signing_key, GRouterServiceId &client_id, uint8_t *data, uint32_t data_size)
{ {
std::cerr << "!!!!!! Received Data from global router, but the client service is not handling it !!!!!!!!!!" << std::endl ; std::cerr << "!!!!!! Received Data from global router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
std::cerr << " destination key_id = " << destination_key.toStdString() << std::endl; std::cerr << " destination key_id = " << destination_key.toStdString() << std::endl;
} }
// This method is called by the global router when a message has been acknowledged, in order to notify the client. // This method is called by the global router when a message has been received, or cannot be sent, etc.
// //
virtual void acknowledgeDataReceived(const GRouterMsgPropagationId& received_id) virtual void notifyDataStatus(const GRouterMsgPropagationId& received_id,uint32_t data_status)
{ {
std::cerr << "!!!!!! Received Data acknowledge from global router, but the client service is not handling it !!!!!!!!!!" << std::endl ; std::cerr << "!!!!!! Received Data status from global router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
std::cerr << " message ID = " << received_id << std::endl; std::cerr << " message ID = " << received_id << std::endl;
std::cerr << " data status = " << data_status << std::endl;
} }
// This function is mandatory. It should do two things: // This function is mandatory. It should do two things:

View File

@ -29,118 +29,6 @@ bool RsGRouterItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvs
return true ; return true ;
} }
/* serialise the data to the buffer */
// uint32_t RsGRouterPublishKeyItem::serial_size() const
// {
// uint32_t s = 8 ; // header
// s += POW_PAYLOAD_SIZE ; // proof of work bytes
// s += 4 ; // diffusion_id
// s += published_key.serial_size() ; // sha1 for published_key
// s += 4 ; // service id
// s += 4 ; // randomized distance
// s += GetTlvStringSize(description_string) ; // description
// s += fingerprint.serial_size() ; // fingerprint
//
// return s ;
// }
//bool RsGRouterPublishKeyItem::serialise(void *data, uint32_t& pktsize) const
//{
// uint32_t tlvsize,offset=0;
// bool ok = true;
//
// if(!serialise_header(data,pktsize,tlvsize,offset))
// return false ;
//
// memcpy(&((uint8_t*)data)[offset],pow_bytes,POW_PAYLOAD_SIZE) ;
// offset += 8 ;
//
// /* add mandatory parts first */
// ok &= setRawUInt32(data, tlvsize, &offset, diffusion_id);
// ok &= published_key.serialise(data, tlvsize, offset) ;
// ok &= setRawUInt32(data, tlvsize, &offset, service_id);
// ok &= setRawUFloat32(data, tlvsize, &offset, randomized_distance);
// ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, description_string);
// ok &= fingerprint.serialise(data, tlvsize, offset) ;
//
// if (offset != tlvsize)
// {
// ok = false;
// std::cerr << "RsFileItemSerialiser::serialiseData() Size Error! " << std::endl;
// }
//
// return ok;
//}
/**********************************************************************************************/
/* PROOF OF WORK STUFF */
/**********************************************************************************************/
bool RsGRouterProofOfWorkObject::checkProofOfWork()
{
uint32_t size = serial_size() ;
unsigned char *mem = (unsigned char *)malloc(size) ;
if(mem == NULL)
{
std::cerr << "RsGRouterProofOfWorkObject: cannot allocate memory for " << size << " bytes." << std::endl;
return false ;
}
serialise(mem,size) ;
bool res = checkProofOfWork(mem,size) ;
free(mem) ;
return res ;
}
bool RsGRouterProofOfWorkObject::updateProofOfWork()
{
uint32_t size = serial_size() ;
unsigned char *mem = (unsigned char *)malloc(size) ;
if(mem == NULL)
{
std::cerr << "RsGRouterProofOfWorkObject: cannot allocate memory for " << size << " bytes." << std::endl;
return false ;
}
serialise(mem,size) ;
memset(mem,0,POW_PAYLOAD_SIZE) ; // init the payload
while(true)
{
if(checkProofOfWork(mem,size))
break ;
int k ;
for(k=0;k<POW_PAYLOAD_SIZE;++k)
{
++mem[k] ;
if(mem[k]!=0)
break ;
}
if(k == POW_PAYLOAD_SIZE)
return false ;
}
memcpy(pow_bytes,mem,POW_PAYLOAD_SIZE) ; // copy the good bytes.
free(mem) ;
return true ;
}
bool RsGRouterProofOfWorkObject::checkProofOfWork(unsigned char *mem,uint32_t size)
{
Sha1CheckSum sum = RsDirUtil::sha1sum(mem,size) ;
for(int i=0;i<PROOF_OF_WORK_REQUESTED_BYTES;++i)
if(sum.toByteArray()[i] != 0)
return false ;
return true ;
}
/**********************************************************************************************/ /**********************************************************************************************/
/* SERIALISER STUFF */ /* SERIALISER STUFF */
/**********************************************************************************************/ /**********************************************************************************************/
@ -157,46 +45,75 @@ RsItem *RsGRouterSerialiser::deserialise(void *data, uint32_t *pktsize)
switch(getRsItemSubType(rstype)) switch(getRsItemSubType(rstype))
{ {
//case RS_PKT_SUBTYPE_GROUTER_PUBLISH_KEY: return deserialise_RsGRouterPublishKeyItem(data, *pktsize); case RS_PKT_SUBTYPE_GROUTER_DATA: return deserialise_RsGRouterGenericDataItem (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_ACK: return deserialise_RsGRouterACKItem(data, *pktsize); case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: return deserialise_RsGRouterTransactionAcknItem (data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return deserialise_RsGRouterMatrixCluesItem(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_FRIENDS_LIST: return deserialise_RsGRouterMatrixFriendListItem(data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO: return deserialise_RsGRouterRoutingInfoItem(data, *pktsize); case RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO: return deserialise_RsGRouterRoutingInfoItem (data, *pktsize);
default: default:
std::cerr << "RsGRouterSerialiser::deserialise(): Could not de-serialise item. SubPacket id = " << std::hex << getRsItemSubType(rstype) << " id = " << rstype << std::dec << std::endl; 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;
} }
return NULL; return NULL;
} }
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 ;
//RsGRouterPublishKeyItem *RsGRouterSerialiser::deserialise_RsGRouterPublishKeyItem(void *data, uint32_t pktsize) const RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem() ;
//{
// uint32_t offset = 8; // skip the header
// uint32_t rssize = getRsItemSize(data);
// bool ok = true ;
//
// RsGRouterPublishKeyItem *item = new RsGRouterPublishKeyItem() ;
//
// memcpy(&((uint8_t*)data)[offset],item->pow_bytes,RsGRouterProofOfWorkObject::POW_PAYLOAD_SIZE) ;
// offset += 8 ;
//
// ok &= getRawUInt32(data, pktsize, &offset, &item->diffusion_id); // file hash
// ok &= item->published_key.deserialise(data, pktsize, offset) ;
// ok &= getRawUInt32(data, pktsize, &offset, &item->service_id); // file hash
// ok &= getRawUFloat32(data, pktsize, &offset, item->randomized_distance); // file hash
// ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE,item->description_string);
// ok &= item->fingerprint.deserialise(data,pktsize,offset) ;
//
// if (offset != rssize || !ok)
// {
// std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
// return NULL ;
// }
//
// return item;
//}
/* 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( NULL == (item->chunk_data = (uint8_t*)malloc(item->chunk_size)))
{
std::cerr << __PRETTY_FUNCTION__ << ": Cannot allocate memory for chunk " << item->chunk_size << std::endl;
return NULL ;
}
if(item->chunk_size + offset > rssize)
{
std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl;
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;
return NULL ;
}
return item;
}
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;
return NULL ;
}
return item;
}
RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *data, uint32_t pktsize) const RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *data, uint32_t pktsize) const
{ {
uint32_t offset = 8; // skip the header uint32_t offset = 8; // skip the header
@ -207,7 +124,6 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI
ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id); ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
ok &= item->destination_key.deserialise(data, pktsize, offset) ; ok &= item->destination_key.deserialise(data, pktsize, offset) ;
ok &= getRawUInt32(data, pktsize, &offset, &item->randomized_distance);
ok &= getRawUInt32(data, pktsize, &offset, &item->data_size); ok &= getRawUInt32(data, pktsize, &offset, &item->data_size);
if( NULL == (item->data_bytes = (uint8_t*)malloc(item->data_size))) if( NULL == (item->data_bytes = (uint8_t*)malloc(item->data_size)))
@ -216,9 +132,20 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI
return NULL ; return NULL ;
} }
if(item->data_size + offset > rssize)
{
std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl;
return NULL ;
}
memcpy(item->data_bytes,&((uint8_t*)data)[offset],item->data_size) ; memcpy(item->data_bytes,&((uint8_t*)data)[offset],item->data_size) ;
offset += item->data_size ; offset += item->data_size ;
ok &= item->signature.GetTlv(data, pktsize, &offset) ;
ok &= getRawUInt32(data, pktsize, &offset, &item->randomized_distance);
ok &= getRawUInt32(data, pktsize, &offset, &item->flags);
if (offset != rssize || !ok) if (offset != rssize || !ok)
{ {
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
@ -228,16 +155,19 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI
return item; return item;
} }
RsGRouterACKItem *RsGRouterSerialiser::deserialise_RsGRouterACKItem(void *data, uint32_t pktsize) const RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedReceiptItem(void *data, uint32_t pktsize) const
{ {
uint32_t offset = 8; // skip the header uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data); uint32_t rssize = getRsItemSize(data);
bool ok = true ; bool ok = true ;
RsGRouterACKItem *item = new RsGRouterACKItem() ; RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem() ;
ok &= getRawUInt64(data, pktsize, &offset, &item->mid); // file hash ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
ok &= getRawUInt32(data, pktsize, &offset, &item->state); // file hash ok &= getRawUInt32(data, pktsize, &offset, &item->flags);
ok &= item->destination_key.deserialise(data, pktsize, offset);
ok &= item->data_hash.deserialise(data, pktsize, offset);
ok &= item->signature.GetTlv(data, pktsize, &offset); // signature
if (offset != rssize || !ok) if (offset != rssize || !ok)
{ {
@ -256,26 +186,20 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI
RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ; RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ;
ok &= getRawUInt32(data, pktsize, &offset, &item->status_flags); RsPeerId peer_id ;
ok &= item->origin.deserialise(data, pktsize, offset) ; ok &= peer_id.deserialise(data, pktsize, offset) ;
ok &= getRawTimeT(data, pktsize, &offset, item->received_time); item->PeerId(peer_id) ;
ok &= getRawTimeT(data, pktsize, &offset, item->last_sent);
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 &= getRawUInt32(data, pktsize, &offset, &item->client_id);
ok &= item->tunnel_hash.deserialise(data, pktsize, offset) ;
uint32_t s = 0 ;
ok &= getRawUInt32(data, pktsize, &offset, &s) ;
for(uint32_t i=0;i<s;++i)
{
FriendTrialRecord ftr ;
ok &= ftr.friend_id.deserialise(data, pktsize, offset) ;
ok &= getRawTimeT(data, pktsize, &offset, ftr.time_stamp) ;
ok &= getRawUFloat32(data, pktsize, &offset, ftr.probability) ;
ok &= getRawUInt32(data, pktsize, &offset, &ftr.nb_friends) ;
item->tried_friends.push_back(ftr) ;
}
item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ; item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ;
if(item->data_item != NULL) if(item->data_item != NULL)
@ -283,7 +207,19 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI
else else
ok = false ; ok = false ;
item->destination_key = item->data_item->destination_key ; // 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) if (offset != rssize || !ok)
{ {
@ -351,16 +287,13 @@ RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesI
return item; return item;
} }
RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
{ {
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ; RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ;
item->routing_id = routing_id ; // copy all members
item->destination_key = destination_key ;
item->data_size = data_size ; *item = *this ;
item->randomized_distance = randomized_distance ;
// then duplicate the memory chunk // then duplicate the memory chunk
@ -370,25 +303,103 @@ RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
return item ; return item ;
} }
RsGRouterSignedReceiptItem *RsGRouterSignedReceiptItem::duplicate() const
{
RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem ;
// copy all members
*item = *this ;
return item ;
}
uint32_t RsGRouterGenericDataItem::serial_size() const uint32_t RsGRouterGenericDataItem::serial_size() const
{ {
uint32_t s = 8 ; // header uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key s += destination_key.serial_size() ; // destination_key
s += 4 ; // data_size
s += data_size ; // data
s += signature.TlvSize() ; // signature
s += 4 ; // randomized distance s += 4 ; // randomized distance
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 ; // data_size
s += data_size ; // data s += data_size ; // data
return s ; return s ;
} }
uint32_t RsGRouterACKItem::serial_size() const uint32_t RsGRouterSignedReceiptItem::serial_size() const
{ {
uint32_t s = 8 ; // header uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += data_hash.serial_size() ;
s += 4 ; // state
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 ; // state s += 4 ; // state
return s ; 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 bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
{ {
uint32_t tlvsize,offset=0; uint32_t tlvsize,offset=0;
@ -400,7 +411,53 @@ bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
/* add mandatory parts first */ /* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id); ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= destination_key.serialise(data, tlvsize, offset) ; ok &= destination_key.serialise(data, tlvsize, offset) ;
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, randomized_distance) ; ok &= setRawUInt32(data, tlvsize, &offset, randomized_distance) ;
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() ;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= destination_key.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, data_size); ok &= setRawUInt32(data, tlvsize, &offset, data_size);
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ; memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
@ -414,7 +471,7 @@ bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
return ok; return ok;
} }
bool RsGRouterACKItem::serialise(void *data,uint32_t& size) const bool RsGRouterSignedReceiptItem::serialise(void *data,uint32_t& size) const
{ {
uint32_t tlvsize,offset=0; uint32_t tlvsize,offset=0;
bool ok = true; bool ok = true;
@ -423,18 +480,41 @@ bool RsGRouterACKItem::serialise(void *data,uint32_t& size) const
return false ; return false ;
/* add mandatory parts first */ /* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, mid); ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= setRawUInt32(data, tlvsize, &offset, state); ok &= setRawUInt32(data, tlvsize, &offset, flags);
ok &= destination_key.serialise(data,tlvsize,offset) ;
ok &= data_hash.serialise(data,tlvsize,offset) ;
ok &= signature.SetTlv(data,tlvsize,&offset) ;
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
std::cerr << "RsGRouterACKItem::serialisedata() size error! " << std::endl; std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl;
} }
return ok; 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() ;
/* 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 &= 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 */ /* serialise the data to the buffer */
uint32_t RsGRouterMatrixCluesItem::serial_size() const uint32_t RsGRouterMatrixCluesItem::serial_size() const
{ {
@ -457,15 +537,24 @@ uint32_t RsGRouterMatrixFriendListItem::serial_size() const
uint32_t RsGRouterRoutingInfoItem::serial_size() const uint32_t RsGRouterRoutingInfoItem::serial_size() const
{ {
uint32_t s = 8 ; // header uint32_t s = 8 ; // header
s += 4 ; // status_flags s += PeerId().serial_size() ;
s += origin.serial_size() ; // origin
s += 4 ; // data status_flags
s += 4 ; // tunnel status_flags
s += 8 ; // received_time s += 8 ; // received_time
s += 8 ; // last_sent s += 8 ; // last_sent
s += 4 ; // tried_friends.size() ;
s += 8 ; // last_TR_TS
s += 4 ; // sending attempts
s += sizeof(GRouterServiceId) ; // service_id s += sizeof(GRouterServiceId) ; // service_id
s += tried_friends.size() * ( RsPeerId::SIZE_IN_BYTES + 8 + 4 + 4 ) ; // FriendTrialRecord s += tunnel_hash.serial_size() ;
s += data_item->serial_size(); // data_item s += data_item->serial_size(); // data_item
if(receipt_item != NULL)
s += receipt_item->serial_size(); // receipt_item
return s ; return s ;
} }
@ -545,20 +634,27 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
if(!serialise_header(data,size,tlvsize,offset)) if(!serialise_header(data,size,tlvsize,offset))
return false ; return false ;
ok &= setRawUInt32(data, tlvsize, &offset, status_flags) ; ok &= PeerId().serialise(data, tlvsize, offset) ; // we keep this.
ok &= origin.serialise(data, tlvsize, offset) ; ok &= setRawUInt32(data, tlvsize, &offset, data_status) ;
ok &= setRawTimeT(data, tlvsize, &offset, received_time) ; ok &= setRawUInt32(data, tlvsize, &offset, tunnel_status) ;
ok &= setRawTimeT(data, tlvsize, &offset, last_sent) ; ok &= setRawTimeT(data, tlvsize, &offset, received_time_TS) ;
ok &= setRawUInt32(data, tlvsize, &offset, client_id) ; ok &= setRawTimeT(data, tlvsize, &offset, last_sent_TS) ;
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ; ok &= setRawTimeT(data, tlvsize, &offset, last_tunnel_request_TS) ;
ok &= setRawUInt32(data, tlvsize, &offset, sending_attempts) ;
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it) ok &= setRawUInt32(data, tlvsize, &offset, client_id) ;
ok &= (*it).serialise(data,offset,size) ; ok &= tunnel_hash.serialise(data, tlvsize, offset) ;
uint32_t ns = size - offset ; uint32_t ns = size - offset ;
ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ; ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ;
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) if (offset != tlvsize)
{ {
ok = false; ok = false;
@ -572,35 +668,28 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
// ------------------------------------- IO --------------------------------------- // // ------------------------------------- IO --------------------------------------- //
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
// //
//std::ostream& RsGRouterPublishKeyItem::print(std::ostream& o, uint16_t) std::ostream& RsGRouterSignedReceiptItem::print(std::ostream& o, uint16_t)
//{
// o << "GRouterPublishKeyItem:" << std::endl ;
// o << " POW bytes : \""<< RsPgpId(pow_bytes).toStdString() << "\"" << std::endl ;
// o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
// o << " Key: " << published_key.toStdString() << std::endl ;
// o << " Req. Id: " << std::hex << diffusion_id << std::dec << std::endl ;
// o << " Srv. Id: " << std::hex << service_id << std::dec << std::endl ;
// o << " Distance: " << randomized_distance << std::endl ;
// o << " Description: " << description_string << std::endl ;
// o << " Fingerprint: " << fingerprint.toStdString() << std::endl ;
//
// return o ;
//}
std::ostream& RsGRouterACKItem::print(std::ostream& o, uint16_t)
{ {
o << "RsGRouterACKItem:" << std::endl ; o << "RsGRouterReceiptItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << std::endl ; o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " Mid: " << mid << std::endl ; o << " Mid: " << std::hex << routing_id << std::dec << std::endl ;
o << " State: " << state << std::endl ; o << " State: " << flags << std::endl ;
o << " Dest: " << destination_key << std::endl ;
o << " Sign: " << signature.keyId << std::endl ;
return o ; return o ;
} }
std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t) std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t)
{ {
o << "RsGRouterGenericDataItem:" << std::endl ; o << "RsGRouterGenericDataItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << 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 << " Key: " << destination_key.toStdString() << std::endl ;
o << " Data size: " << data_size << 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 << " randomized dist:" << randomized_distance << std::endl;
o << " flags: " << flags << std::endl;
return o ; return o ;
} }
@ -608,15 +697,17 @@ std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t)
std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t) std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t)
{ {
o << "RsGRouterRoutingInfoItem:" << std::endl ; o << "RsGRouterRoutingInfoItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << std::endl ; o << " direct origin: "<< PeerId() << std::endl ;
o << " origin: "<< origin.toStdString() << std::endl ; o << " data status: "<< std::hex<< data_status << std::dec << std::endl ;
o << " recv time: "<< received_time << std::endl ; o << " tunnel status: "<< tunnel_status << std::endl ;
o << " Last sent: "<< last_sent << std::endl ; o << " recv time: "<< received_time_TS << std::endl ;
o << " flags: "<< std::hex << status_flags << std::dec << std::endl ; o << " Last sent: "<< last_sent_TS << std::endl ;
o << " Key: "<< data_item->destination_key.toStdString() << std::endl ; o << " Sending attempts:"<< sending_attempts << std::endl ;
o << " Data size: "<< data_item->data_size << std::endl ; o << " destination key: "<< data_item->destination_key << std::endl ;
o << " Client id: "<< client_id << std::endl ; o << " Client id: "<< client_id << std::endl ;
o << " Tried friends: "<< tried_friends.size() << 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 ; return o ;
} }
@ -632,6 +723,22 @@ std::ostream& RsGRouterMatrixCluesItem::print(std::ostream& o, uint16_t)
return o ; 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) std::ostream& RsGRouterMatrixFriendListItem::print(std::ostream& o, uint16_t)
{ {
o << "RsGRouterMatrixCluesItem:" << std::endl ; o << "RsGRouterMatrixCluesItem:" << std::endl ;

View File

@ -26,6 +26,7 @@
#pragma once #pragma once
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvkeys.h"
#include "serialiser/rsserviceids.h" #include "serialiser/rsserviceids.h"
#include "retroshare/rstypes.h" #include "retroshare/rstypes.h"
@ -33,16 +34,20 @@
#include "p3grouter.h" #include "p3grouter.h"
const uint8_t RS_PKT_SUBTYPE_GROUTER_PUBLISH_KEY = 0x01 ; // used to publish a key const uint8_t RS_PKT_SUBTYPE_GROUTER_PUBLISH_KEY = 0x01 ; // used to publish a key
const uint8_t RS_PKT_SUBTYPE_GROUTER_ACK = 0x03 ; // acknowledgement of data received const uint8_t RS_PKT_SUBTYPE_GROUTER_ACK_deprecated = 0x03 ; // dont use!
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA = 0x05 ; // used to send data to a destination const uint8_t RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT = 0x04 ; // long-distance acknowledgement of data received
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA_deprecated = 0x05 ; // dont use!
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA = 0x06 ; // used to send data to a destination (Signed by source)
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_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_FRIENDS_LIST = 0x82 ; // item to save friend lists
const uint8_t RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO = 0x87 ; // item to save routing info const uint8_t RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO_deprecated = 0x87 ; // deprecated. Don't use.
const uint8_t RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO = 0x89 ; // item to save routing info
const uint8_t QOS_PRIORITY_RS_GROUTER_PUBLISH_KEY = 3 ; // slow items. No need to congest the network with this. const uint8_t QOS_PRIORITY_RS_GROUTER = 3 ; // irrelevant since all items travel through tunnels
const uint8_t QOS_PRIORITY_RS_GROUTER_ACK = 3 ;
const uint8_t QOS_PRIORITY_RS_GROUTER_DATA = 3 ;
/***********************************************************************************/ /***********************************************************************************/
@ -72,61 +77,37 @@ class RsGRouterNonCopyableObject
{ {
public: public:
RsGRouterNonCopyableObject() {} RsGRouterNonCopyableObject() {}
private: protected:
RsGRouterNonCopyableObject(const RsGRouterNonCopyableObject&) {} RsGRouterNonCopyableObject(const RsGRouterNonCopyableObject&) {}
RsGRouterNonCopyableObject operator=(const RsGRouterNonCopyableObject&) { return *this ;} RsGRouterNonCopyableObject operator=(const RsGRouterNonCopyableObject&) { return *this ;}
}; };
class RsGRouterProofOfWorkObject
{
public:
RsGRouterProofOfWorkObject() {}
virtual bool serialise(void *data,uint32_t& size) const =0;
virtual uint32_t serial_size() const =0;
virtual bool checkProofOfWork() ; // checks that the serialized object hashes down to a hash beginning with LEADING_BYTES_SIZE zeroes
virtual bool updateProofOfWork() ; // computes the pow_bytes so that the hash starts with LEADING_BYTES_SIZE zeroes.
static bool checkProofOfWork(unsigned char *mem,uint32_t size) ;
static const int POW_PAYLOAD_SIZE = 8 ;
static const int PROOF_OF_WORK_REQUESTED_BYTES = 4 ;
unsigned char pow_bytes[POW_PAYLOAD_SIZE] ; // 8 bytes to put at the beginning of the serialized packet, so that
// the hash starts with a fixed number of zeroes.
};
/***********************************************************************************/ /***********************************************************************************/
/* Specific packets */ /* Specific packets */
/***********************************************************************************/ /***********************************************************************************/
//class RsGRouterPublishKeyItem: public RsGRouterItem, public RsGRouterProofOfWorkObject // This abstract item class encapsulates 2 types of signed items. All have signature, destination key
//{ // and routing ID. Sub-items are responsible for providing the serialised data to be signed for
// public: // both signing and checking.
// RsGRouterPublishKeyItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_PUBLISH_KEY) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER_PUBLISH_KEY) ; }
//
// 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
// //
// GRouterKeyPropagationId diffusion_id ;
// GRouterKeyId published_key ;
// uint32_t service_id ;
// float randomized_distance ;
// std::string description_string ;
// PGPFingerprintType fingerprint ;
//
//};
class RsGRouterGenericDataItem: public RsGRouterItem, public RsGRouterNonCopyableObject class RsGRouterAbstractMsgItem: public RsGRouterItem
{
public:
RsGRouterAbstractMsgItem(uint8_t pkt_subtype) : RsGRouterItem(pkt_subtype) {}
virtual uint32_t signed_data_size() const = 0 ;
virtual bool serialise_signed_data(void *data,uint32_t& size) const = 0 ;
GRouterMsgPropagationId routing_id ;
GRouterKeyId destination_key ;
RsTlvKeySignature signature ; // signs mid+destination_key+state
uint32_t flags ; // packet was delivered, not delivered, bounced, etc
};
class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRouterNonCopyableObject
{ {
public: public:
RsGRouterGenericDataItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_DATA) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER_DATA) ; } RsGRouterGenericDataItem() : RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_DATA) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; }
virtual ~RsGRouterGenericDataItem() { clear() ; } virtual ~RsGRouterGenericDataItem() { clear() ; }
virtual bool serialise(void *data,uint32_t& size) const ; virtual bool serialise(void *data,uint32_t& size) const ;
@ -143,18 +124,20 @@ class RsGRouterGenericDataItem: public RsGRouterItem, public RsGRouterNonCopyabl
// packet data // packet data
// //
GRouterMsgPropagationId routing_id ;
GRouterKeyId destination_key ;
uint32_t randomized_distance ;
uint32_t data_size ; uint32_t data_size ;
uint8_t *data_bytes; uint8_t *data_bytes;
uint32_t randomized_distance ; // number of hops (tunnel wise. Does not preclude of the real distance)
// utility methods for signing data
virtual uint32_t signed_data_size() const ;
virtual bool serialise_signed_data(void *data,uint32_t& size) const ;
}; };
class RsGRouterACKItem: public RsGRouterItem class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem
{ {
public: public:
RsGRouterACKItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_ACK) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER_ACK) ; } RsGRouterSignedReceiptItem() : RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; }
virtual bool serialise(void *data,uint32_t& size) const ; virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ; virtual uint32_t serial_size() const ;
@ -162,10 +145,48 @@ class RsGRouterACKItem: public RsGRouterItem
virtual void clear() {} virtual void clear() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ;
RsGRouterSignedReceiptItem *duplicate() const ;
// packet data // packet data
// //
GRouterMsgPropagationId mid ; // message id to which this ack is a response Sha1CheckSum data_hash ; // avoids an attacker to re-use a given signed receipt. This is the hash of the enceypted data.
uint32_t state ; // packet was delivered, not delivered, bounced, etc
// utility methods for signing data
virtual uint32_t signed_data_size() const ;
virtual bool serialise_signed_data(void *data,uint32_t& size) const ;
};
// Low-level data items
class RsGRouterTransactionChunkItem: public RsGRouterItem, public RsGRouterNonCopyableObject
{
public:
RsGRouterTransactionChunkItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; }
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) ;
GRouterMsgPropagationId propagation_id ;
uint32_t chunk_start ;
uint32_t chunk_size ;
uint32_t total_size ;
uint8_t *chunk_data ;
};
class RsGRouterTransactionAcknItem: public RsGRouterItem
{
public:
RsGRouterTransactionAcknItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; }
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) ;
GRouterMsgPropagationId propagation_id ;
}; };
// Items for saving the routing matrix information. // Items for saving the routing matrix information.
@ -218,10 +239,11 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo,
virtual void clear() virtual void clear()
{ {
if(data_item != NULL) if(data_item != NULL) delete data_item ;
delete data_item ; if(receipt_item != NULL) delete receipt_item ;
data_item = NULL ; data_item = NULL ;
tried_friends.clear() ; receipt_item = NULL ;
} }
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ;
}; };
@ -232,7 +254,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo,
class RsGRouterSerialiser: public RsSerialType class RsGRouterSerialiser: public RsSerialType
{ {
public: public:
RsGRouterSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GROUTER) {} RsGRouterSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GROUTER) {}
virtual uint32_t size (RsItem *item) virtual uint32_t size (RsItem *item)
@ -245,10 +267,11 @@ class RsGRouterSerialiser: public RsSerialType
} }
virtual RsItem *deserialise (void *data, uint32_t *size) ; virtual RsItem *deserialise (void *data, uint32_t *size) ;
private: private:
//RsGRouterPublishKeyItem *deserialise_RsGRouterPublishKeyItem(void *data,uint32_t size) const ;
RsGRouterGenericDataItem *deserialise_RsGRouterGenericDataItem(void *data,uint32_t size) const ; RsGRouterGenericDataItem *deserialise_RsGRouterGenericDataItem(void *data,uint32_t size) const ;
RsGRouterACKItem *deserialise_RsGRouterACKItem(void *data,uint32_t size) const ; RsGRouterTransactionChunkItem *deserialise_RsGRouterTransactionChunkItem(void *data,uint32_t size) const ;
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 ; RsGRouterMatrixCluesItem *deserialise_RsGRouterMatrixCluesItem(void *data,uint32_t size) const ;
RsGRouterMatrixFriendListItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ; RsGRouterMatrixFriendListItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ;
RsGRouterRoutingInfoItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ; RsGRouterRoutingInfoItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ;

View File

@ -29,15 +29,17 @@
#include <time.h> #include <time.h>
#include <list> #include <list>
#include "pgp/rscertificate.h" #include "pgp/rscertificate.h"
#include "turtle/p3turtle.h"
#include "retroshare/rsgrouter.h" #include "retroshare/rsgrouter.h"
class RsGRouterGenericDataItem ; class RsGRouterGenericDataItem ;
class RsGRouterSignedReceiptItem ;
static const uint32_t GROUTER_CLIENT_ID_MESSAGES = 0x1001 ; static const uint16_t GROUTER_CLIENT_ID_MESSAGES = 0x1001 ;
static const uint32_t RS_GROUTER_MATRIX_MAX_HIT_ENTRIES = 10; // max number of clues to store static const uint32_t RS_GROUTER_MATRIX_MAX_HIT_ENTRIES = 10 ; // max number of clues to store
static const uint32_t RS_GROUTER_MATRIX_MIN_TIME_BETWEEN_HITS = 60; // can be set to up to half the publish time interval. Prevents flooding routes. static const uint32_t RS_GROUTER_MATRIX_MIN_TIME_BETWEEN_HITS = 60 ; // can be set to up to half the publish time interval. Prevents flooding routes.
static const uint32_t RS_GROUTER_MIN_CONFIG_SAVE_PERIOD = 5; // at most save config every 5 seconds static const uint32_t RS_GROUTER_MIN_CONFIG_SAVE_PERIOD = 5 ; // at most save config every 5 seconds
static const float RS_GROUTER_BASE_WEIGHT_ROUTED_MSG = 1.0f ; // base contribution of routed message clue to routing matrix static const float RS_GROUTER_BASE_WEIGHT_ROUTED_MSG = 1.0f ; // base contribution of routed message clue to routing matrix
static const float RS_GROUTER_BASE_WEIGHT_GXS_PACKET = 0.1f ; // base contribution of GXS message to routing matrix static const float RS_GROUTER_BASE_WEIGHT_GXS_PACKET = 0.1f ; // base contribution of GXS message to routing matrix
@ -51,21 +53,18 @@ static const time_t RS_GROUTER_MEAN_EXPECTED_RTT = 30 ; // refer
static const uint32_t GROUTER_ITEM_DISTANCE_UNIT = 256 ; // One unit of distance between two peers static const uint32_t GROUTER_ITEM_DISTANCE_UNIT = 256 ; // One unit of distance between two peers
static const uint32_t GROUTER_ITEM_MAX_TRAVEL_DISTANCE = 6*256 ; // 6 distance units. That is a lot. static const uint32_t GROUTER_ITEM_MAX_TRAVEL_DISTANCE = 6*256 ; // 6 distance units. That is a lot.
static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME = 30*86400 ; // ACKN Items are kept in cache for 1 month, to allow sending acknowledgements to peers while not online. static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME = 86400 ; // Cached items are kept for 24 hours at most.
static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME_DEAD= 3600 ; // DEAD Items are kept in cache for only 1 hour to favor re-exploring dead routes. static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME_DEAD= 3600 ; // DEAD Items are kept in cache for only 1 hour to favor re-exploring dead routes.
static const uint32_t RS_GROUTER_ROUTING_STATE_UNKN = 0x0000 ; // unknown. Unused. static const uint32_t RS_GROUTER_DATA_STATUS_UNKNOWN = 0x0000 ; // unknown. Unused.
static const uint32_t RS_GROUTER_ROUTING_STATE_PEND = 0x0001 ; // item is pending. Should be sent asap. static const uint32_t RS_GROUTER_DATA_STATUS_PENDING = 0x0001 ; // item is pending. Should be sent asap.
static const uint32_t RS_GROUTER_ROUTING_STATE_SENT = 0x0002 ; // item is sent. Waiting for answer static const uint32_t RS_GROUTER_DATA_STATUS_SENT = 0x0002 ; // item is sent. Waiting for answer
static const uint32_t RS_GROUTER_ROUTING_STATE_ARVD = 0x0003 ; // item is at destination. The cache only holds it to avoid duplication. static const uint32_t RS_GROUTER_DATA_STATUS_RECEIPT_OK = 0x0003 ; // item is at destination.
static const uint32_t RS_GROUTER_ROUTING_STATE_DEAD = 0x0004 ; // item is at a dead end.
static const uint32_t RS_GROUTER_ACK_STATE_UNKN = 0x0000 ; // unknown destination key static const uint32_t RS_GROUTER_TUNNEL_STATUS_UNMANAGED = 0x0000 ; // no tunnel requested atm
static const uint32_t RS_GROUTER_ACK_STATE_RCVD = 0x0001 ; // data was received, directly static const uint32_t RS_GROUTER_TUNNEL_STATUS_PENDING = 0x0001 ; // tunnel requested to turtle
static const uint32_t RS_GROUTER_ACK_STATE_IRCV = 0x0002 ; // data was received indirectly static const uint32_t RS_GROUTER_TUNNEL_STATUS_READY = 0x0002 ; // tunnel is ready but we're still waiting for various confirmations
static const uint32_t RS_GROUTER_ACK_STATE_GVNP = 0x0003 ; // data was given up. No route. static const uint32_t RS_GROUTER_TUNNEL_STATUS_CAN_SEND = 0x0003 ; // tunnel is ready and data can be sent
static const uint32_t RS_GROUTER_ACK_STATE_NORO = 0x0004 ; // data was given up. No route.
static const uint32_t RS_GROUTER_ACK_STATE_TOOF = 0x0005 ; // dropped because of distance (too far)
class FriendTrialRecord class FriendTrialRecord
{ {
@ -81,16 +80,26 @@ class FriendTrialRecord
class GRouterRoutingInfo class GRouterRoutingInfo
{ {
public: // There's no destructor to this class, because the memory is managed elsewhere, which
uint32_t status_flags ; // pending, waiting, etc. // ovoids lots of duplications if the class is copied.
RsPeerId origin ; // which friend sent us that item public:
time_t received_time ; // time at which the item was originally received GRouterRoutingInfo()
time_t last_sent ; // last time the item was sent to friends {
data_item = NULL ;
receipt_item = NULL ;
}
uint32_t data_status ; // pending, waiting, etc.
uint32_t tunnel_status ; // status of tunnel handling.
time_t received_time_TS ; // time at which the item was originally received
time_t last_sent_TS ; // last time the item was sent to friends
time_t last_tunnel_request_TS ; // last time tunnels have been asked for this item.
uint32_t sending_attempts ; // number of times tunnels have been asked for this peer without success
std::list<FriendTrialRecord> tried_friends ; // list of friends to which the item was sent ordered with time.
GRouterKeyId destination_key ; // ultimate destination for this key
GRouterServiceId client_id ; // service ID of the client. Only valid when origin==OwnId GRouterServiceId client_id ; // service ID of the client. Only valid when origin==OwnId
TurtleFileHash tunnel_hash ; // tunnel hash to be used for this item
RsGRouterGenericDataItem *data_item ; RsGRouterGenericDataItem *data_item ;
RsGRouterSignedReceiptItem *receipt_item ;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -31,27 +31,55 @@
#include "retroshare/rsgrouter.h" #include "retroshare/rsgrouter.h"
#include "retroshare/rstypes.h" #include "retroshare/rstypes.h"
#include "retroshare/rstypes.h"
#include "turtle/turtleclientservice.h"
#include "services/p3service.h" #include "services/p3service.h"
#include "pqi/p3cfgmgr.h" #include "pqi/p3cfgmgr.h"
#include "groutertypes.h" #include "groutertypes.h"
#include "groutermatrix.h" #include "groutermatrix.h"
#include "grouteritems.h" #include "grouteritems.h"
//#include "groutercache.h"
// To be put in pqi/p3cfgmgr.h // To be put in pqi/p3cfgmgr.h
// //
static const uint32_t CONFIG_TYPE_GROUTER = 0x0016 ; static const uint32_t CONFIG_TYPE_GROUTER = 0x0016 ;
class p3LinkMgr ; static const uint32_t RS_GROUTER_DATA_FLAGS_ENCRYPTED = 0x0001 ;
class RsGRouterPublishKeyItem ;
class RsGRouterACKItem ;
class p3GRouter: public RsGRouter, public p3Service, public p3Config class p3LinkMgr ;
class p3turtle ;
class p3IdService ;
class RsGRouterItem ;
class RsGRouterGenericDataItem ;
class RsGRouterTransactionChunkItem ;
class RsGRouterSignedReceiptItem ;
class RsGRouterAbstractMsgItem ;
// This class is responsible for accepting data chunks and merging them into a final object. When the object is
// complete, it is de-serialised and returned as a RsGRouterGenericDataItem*.
class GRouterTunnelInfo
{ {
public: public:
p3GRouter(p3ServiceControl *sc,p3LinkMgr *lm) ; GRouterTunnelInfo() :first_tunnel_ok_TS(0), last_tunnel_ok_TS(0) {}
// These two methods handle the memory management of buffers for each virtual peers.
void addVirtualPeer(const TurtleVirtualPeerId& vpid) ;
void removeVirtualPeer(const TurtleVirtualPeerId& vpid) ;
RsGRouterAbstractMsgItem *addDataChunk(const TurtleVirtualPeerId& vpid,RsGRouterTransactionChunkItem *chunk_item) ;
std::map<TurtleVirtualPeerId, RsGRouterTransactionChunkItem*> virtual_peers ;
time_t first_tunnel_ok_TS ; // timestamp when 1st tunnel was received.
time_t last_tunnel_ok_TS ; // timestamp when last tunnel was received.
};
class p3GRouter: public RsGRouter, public RsTurtleClientService, public p3Service, public p3Config
{
public:
p3GRouter(p3ServiceControl *sc,p3IdService *is) ;
//===================================================// //===================================================//
// Router clients business // // Router clients business //
@ -68,17 +96,17 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// forward in the network, so that is can be a possible destination for // forward in the network, so that is can be a possible destination for
// global messages. // global messages.
// //
// key : The key that is published // auth_id : The GXS key that will be used to sign the data Receipts.
// fingerp : Fingerprint of the key to encrypt the data. // contact_key : The key that is used to open tunnels
// desc_str : Any fixed length string (< 20 characters) to descript the address in words. // desc_str : Any fixed length string (< 20 characters) to descript the address in words.
// client_id: id of the client service to send the traffic to. // client_id : Id of the client service to send the traffic to.
// To obtain a client id, the service must register using the previous method. // The client ID should match the ID that has been registered using the previous method.
// //
// Unregistering a key might not have an instantaneous effect, so the client is responsible for // Unregistering a key might not have an instantaneous effect, so the client is responsible for
// discarding traffic that might later come for this key. // discarding traffic that might later come for this key.
// //
virtual bool registerKey(const GRouterKeyId& key, const GRouterServiceId& client_id,const std::string& description_string) ; virtual bool registerKey(const RsGxsId& authentication_id, const GRouterServiceId& client_id,const std::string& description_string) ;
virtual bool unregisterKey(const GRouterKeyId& key) ; virtual bool unregisterKey(const RsGxsId &key_id, const GRouterServiceId &sid) ;
//===================================================// //===================================================//
// Routing clue collection methods // // Routing clue collection methods //
@ -94,13 +122,13 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// the memory. That means item_data will be erase on return. The returned id should be // the memory. That means item_data will be erase on return. The returned id should be
// remembered by the client, so that he knows when the data has been received. // remembered by the client, so that he knows when the data has been received.
// The client id is supplied so that the client can be notified when the data has been received. // The client id is supplied so that the client can be notified when the data has been received.
// Data is not modified by the global router.
// //
virtual void sendData(const GRouterKeyId& destination,const GRouterServiceId& client_id, RsGRouterGenericDataItem *item,GRouterMsgPropagationId& id) ; virtual bool sendData(const RsGxsId& destination, const GRouterServiceId& client_id, const uint8_t *data, uint32_t data_size, const RsGxsId& signing_id, GRouterMsgPropagationId& id) ;
// Sends an ACK to the origin of the msg. This is used to notify for // Cancels a given sending order. If called too late, the message might already have left. But this will remove the item from the
// unfound route, or message correctly received, depending on the particular situation. // re-try list.
// virtual bool cancel(GRouterMsgPropagationId mid) ;
virtual void sendACK(const RsPeerId& peer,GRouterMsgPropagationId mid, uint32_t flags) ;
//===================================================// //===================================================//
// Interface with RsGRouter // // Interface with RsGRouter //
@ -138,13 +166,15 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
} }
virtual void setDebugEnabled(bool b) { _debug_enabled = b ; } virtual void setDebugEnabled(bool b) { _debug_enabled = b ; }
protected:
virtual void connectToTurtleRouter(p3turtle *pt) ;
protected:
//===================================================// //===================================================//
// Routing method handling // // Routing method handling //
//===================================================// //===================================================//
// Calls // Calls
// - autoWash()
// - packet handling methods // - packet handling methods
// - matrix updates // - matrix updates
// //
@ -156,7 +186,16 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
static const uint16_t SERVICE_INFO_MIN_MAJOR_VERSION = 1; static const uint16_t SERVICE_INFO_MIN_MAJOR_VERSION = 1;
static const uint16_t SERVICE_INFO_MIN_MINOR_VERSION = 0; static const uint16_t SERVICE_INFO_MIN_MINOR_VERSION = 0;
private: //===================================================//
// Interaction with turtle router //
//===================================================//
virtual bool handleTunnelRequest(const RsFileHash& /*hash*/,const RsPeerId& /*peer_id*/) ;
virtual void receiveTurtleData(RsTurtleGenericTunnelItem */*item*/,const RsFileHash& /*hash*/,const RsPeerId& /*virtual_peer_id*/,RsTurtleGenericTunnelItem::Direction /*direction*/);
virtual void addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) ;
virtual void removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) ;
private:
class nullstream: public std::ostream {}; class nullstream: public std::ostream {};
std::ostream& grouter_debug() const std::ostream& grouter_debug() const
@ -166,22 +205,34 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
return _debug_enabled?(std::cerr):null; return _debug_enabled?(std::cerr):null;
} }
void autoWash() ;
void routePendingObjects() ; void routePendingObjects() ;
void handleIncoming() ; void handleTunnels() ;
void debugDump() ;
void handleIncoming(const TurtleFileHash &hash, RsGRouterAbstractMsgItem *) ;
void handleIncomingReceiptItem(const TurtleFileHash &hash, RsGRouterSignedReceiptItem *receipt_item) ;
void handleIncomingDataItem(const TurtleFileHash &hash, RsGRouterGenericDataItem *data_item) ;
bool locked_getClientAndServiceId(const TurtleFileHash& hash, const RsGxsId& destination_key, GRouterClientService *& client, GRouterServiceId& service_id);
// utility functions // utility functions
// //
static uint32_t computeBranchingFactor(const std::vector<RsPeerId>& friends,uint32_t dist) ;
std::set<uint32_t> computeRoutingFriends(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t N) ;
static float computeMatrixContribution(float base,uint32_t time_shift,float probability) ; static float computeMatrixContribution(float base,uint32_t time_shift,float probability) ;
static time_t computeNextTimeDelay(time_t duration) ; static time_t computeNextTimeDelay(time_t duration) ;
void locked_notifyClientAcknowledged(const GRouterMsgPropagationId& msg_id,const GRouterServiceId& service_id) const ;
uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ; uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ;
// signs an item with the given key.
bool signDataItem(RsGRouterAbstractMsgItem *item,const RsGxsId& id) ;
bool verifySignedDataItem(RsGRouterAbstractMsgItem *item) ;
bool encryptDataItem(RsGRouterGenericDataItem *item,const RsGxsId& destination_key) ;
bool decryptDataItem(RsGRouterGenericDataItem *item) ;
static Sha1CheckSum makeTunnelHash(const RsGxsId& destination,const GRouterServiceId& client);
static void makeGxsIdAndClientId(const TurtleFileHash &sum,RsGxsId& gxs_id,GRouterServiceId& client_id);
bool sendDataInTunnel(const TurtleVirtualPeerId& vpid,RsGRouterAbstractMsgItem *item);
//===================================================// //===================================================//
// p3Config methods // // p3Config methods //
//===================================================// //===================================================//
@ -199,7 +250,11 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// Prints the internal state of the router, for debug purpose. // Prints the internal state of the router, for debug purpose.
// //
void debug_dump() ; void debugDump() ;
//===================================================//
// Internal queues/variables //
//===================================================//
// Stores the routing info // Stores the routing info
// - list of known key ids // - list of known key ids
@ -208,19 +263,13 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// //
GRouterMatrix _routing_matrix ; GRouterMatrix _routing_matrix ;
// Stores the routing events.
// - ongoing requests, waiting for return ACK
// - pending items
// Both a stored in 2 different lists, to allow a more efficient handling.
//
std::map<GRouterMsgPropagationId, GRouterRoutingInfo> _pending_messages;// pending messages
// Stores the keys which identify the router's node. For each key, a structure holds: // Stores the keys which identify the router's node. For each key, a structure holds:
// - the client service // - the client service
// - flags // - flags
// - usage time stamps // - usage time stamps
// //
std::map<GRouterKeyId, GRouterPublishedKeyInfo> _owned_key_ids ; std::map<Sha1CheckSum, GRouterPublishedKeyInfo> _owned_key_ids ;
// Registered services. These are known to the different peers with a common id, // Registered services. These are known to the different peers with a common id,
// so it's important to keep consistency here. This map is volatile, and re-created at each startup of // so it's important to keep consistency here. This map is volatile, and re-created at each startup of
@ -228,15 +277,28 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
std::map<GRouterServiceId,GRouterClientService *> _registered_services ; std::map<GRouterServiceId,GRouterClientService *> _registered_services ;
// Data handling ethods // Stores the routing events.
// - ongoing requests, waiting for return ACK
// - pending items
// Both a stored in 2 different lists, to allow a more efficient handling.
// //
void handleRecvDataItem(RsGRouterGenericDataItem *item); std::map<GRouterMsgPropagationId, GRouterRoutingInfo> _pending_messages;// pending messages
void handleRecvACKItem(RsGRouterACKItem *item);
std::map<TurtleFileHash,GRouterTunnelInfo> _virtual_peers ;
// Queue of incoming items. Might be receipts or data. Should always be empty (not a storage place)
std::list<RsGRouterItem*> _incoming_items ;
// Data handling methods
//
//void handleRecvDataItem(RsGRouterGenericDataItem *item);
//void handleRecvReceiptItem(RsGRouterReceiptItem *item);
// Pointers to other RS objects // Pointers to other RS objects
// //
p3ServiceControl *mServiceControl ; p3ServiceControl *mServiceControl ;
p3LinkMgr *mLinkMgr ; p3turtle *mTurtle ;
p3IdService *mIdService ;
// Multi-thread protection mutex. // Multi-thread protection mutex.
// //

View File

@ -385,7 +385,13 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
if(!EVP_SealInit(&ctx, EVP_aes_128_cbc(), &ek, &eklen, iv, &public_key, 1)) return false; if(!EVP_SealInit(&ctx, EVP_aes_128_cbc(), &ek, &eklen, iv, &public_key, 1)) return false;
// now assign memory to out accounting for data, and cipher block size, key length, and key length val // now assign memory to out accounting for data, and cipher block size, key length, and key length val
out = new uint8_t[inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH]; out = (uint8_t*)malloc(inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH);
if(out == NULL)
{
std::cerr << "gxssecurity::encrypt(): cnnot allocate memory of size " << inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH << " to encrypt data." << std::endl;
return false ;
}
net_ekl = htonl(eklen); net_ekl = htonl(eklen);
memcpy((unsigned char*)out + out_offset, &net_ekl, size_net_ekl); memcpy((unsigned char*)out + out_offset, &net_ekl, size_net_ekl);
@ -400,7 +406,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
// now encrypt actual data // now encrypt actual data
if(!EVP_SealUpdate(&ctx, (unsigned char*) out + out_offset, &out_currOffset, (unsigned char*) in, inlen)) if(!EVP_SealUpdate(&ctx, (unsigned char*) out + out_offset, &out_currOffset, (unsigned char*) in, inlen))
{ {
delete[] out ; free(out) ;
out = NULL ; out = NULL ;
return false; return false;
} }
@ -411,7 +417,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
// add padding // add padding
if(!EVP_SealFinal(&ctx, (unsigned char*) out + out_offset, &out_currOffset)) if(!EVP_SealFinal(&ctx, (unsigned char*) out + out_offset, &out_currOffset))
{ {
delete[] out ; free(out) ;
out = NULL ; out = NULL ;
return false; return false;
} }
@ -422,7 +428,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
// make sure offset has not gone passed valid memory bounds // make sure offset has not gone passed valid memory bounds
if(out_offset > max_outlen) if(out_offset > max_outlen)
{ {
delete[] out ; free(out) ;
out = NULL ; out = NULL ;
return false; return false;
} }
@ -498,11 +504,17 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
std::cerr << "Severe error in " << __PRETTY_FUNCTION__ << ": cannot encrypt. " << std::endl; std::cerr << "Severe error in " << __PRETTY_FUNCTION__ << ": cannot encrypt. " << std::endl;
return false ; return false ;
} }
out = new uint8_t[inlen - in_offset]; out = (uint8_t*)malloc(inlen - in_offset);
if(out == NULL)
{
std::cerr << "gxssecurity::decrypt(): cannot allocate memory of size " << inlen - in_offset << " to decrypt data." << std::endl;
return false;
}
if(!EVP_OpenUpdate(&ctx, (unsigned char*) out, &out_currOffset, (unsigned char*)in + in_offset, inlen - in_offset)) if(!EVP_OpenUpdate(&ctx, (unsigned char*) out, &out_currOffset, (unsigned char*)in + in_offset, inlen - in_offset))
{ {
delete[] out ; free(out) ;
out = NULL ; out = NULL ;
return false; return false;
} }
@ -511,7 +523,7 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
if(!EVP_OpenFinal(&ctx, (unsigned char*)out + out_currOffset, &out_currOffset)) if(!EVP_OpenFinal(&ctx, (unsigned char*)out + out_currOffset, &out_currOffset))
{ {
delete[] out ; free(out) ;
out = NULL ; out = NULL ;
return false; return false;
} }

View File

@ -438,7 +438,8 @@ HEADERS += services/p3msgservice.h \
HEADERS += turtle/p3turtle.h \ HEADERS += turtle/p3turtle.h \
turtle/rsturtleitem.h \ turtle/rsturtleitem.h \
turtle/turtletypes.h turtle/turtletypes.h \
turtle/turtleclientservice.h
HEADERS += util/folderiterator.h \ HEADERS += util/folderiterator.h \
util/rsdebug.h \ util/rsdebug.h \

View File

@ -27,8 +27,9 @@
#include "util/rsdir.h" #include "util/rsdir.h"
#include "retroshare/rsids.h" #include "retroshare/rsids.h"
#include "retroshare/rsgxsifacetypes.h"
typedef GRouterKeyIdType GRouterKeyId ; // we use SSLIds, so that it's easier in the GUI to mix up peer ids with grouter ids. typedef RsGxsId GRouterKeyId ; // we use SSLIds, so that it's easier in the GUI to mix up peer ids with grouter ids.
typedef uint32_t GRouterServiceId ; typedef uint32_t GRouterServiceId ;
typedef uint64_t GRouterMsgPropagationId ; typedef uint64_t GRouterMsgPropagationId ;
@ -37,7 +38,7 @@ class RsGRouterGenericDataItem ;
class RsGRouter class RsGRouter
{ {
public: public:
// This is the interface file for the global router service. // This is the interface file for the global router service.
// //
struct GRouterRoutingCacheInfo struct GRouterRoutingCacheInfo
@ -45,14 +46,20 @@ class RsGRouter
GRouterMsgPropagationId mid ; GRouterMsgPropagationId mid ;
RsPeerId local_origin; RsPeerId local_origin;
GRouterKeyId destination ; GRouterKeyId destination ;
time_t time_stamp ; time_t routing_time;
uint32_t status ; time_t last_tunnel_attempt_time;
time_t last_sent_time;
bool receipt_available ;
uint32_t data_status ;
uint32_t tunnel_status ;
uint32_t data_size ; uint32_t data_size ;
Sha1CheckSum data_hash ;
}; };
struct GRouterPublishedKeyInfo struct GRouterPublishedKeyInfo
{ {
std::string description_string ; std::string description_string ;
RsGxsId authentication_key ;
uint32_t service_id ; uint32_t service_id ;
}; };
@ -69,7 +76,7 @@ class RsGRouter
// List of own published keys, with associated service ID // List of own published keys, with associated service ID
// //
std::map<GRouterKeyId,GRouterPublishedKeyInfo> published_keys ; std::map<Sha1CheckSum,GRouterPublishedKeyInfo> published_keys ;
}; };
//===================================================// //===================================================//
@ -85,8 +92,10 @@ class RsGRouter
// Communication to other services. // // Communication to other services. //
//===================================================// //===================================================//
virtual void sendData(const GRouterKeyId& destination, const GRouterServiceId& client_id, RsGRouterGenericDataItem *item,GRouterMsgPropagationId& id) =0; virtual bool sendData(const RsGxsId& destination, const GRouterServiceId& client_id, const uint8_t *data, uint32_t data_size, const RsGxsId& signing_id, GRouterMsgPropagationId& id) =0;
virtual bool registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description_string) =0; virtual bool cancel(GRouterMsgPropagationId mid) =0;
virtual bool registerKey(const RsGxsId& authentication_id, const GRouterServiceId& client_id,const std::string& description_string)=0 ;
//===================================================// //===================================================//
// Routage feedback from other services // // Routage feedback from other services //

View File

@ -219,7 +219,7 @@ static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ; static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ;
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ; typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_SSL_ID_TYPE> SSLIdType ;
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GROUTER_ID_TYPE> GRouterKeyIdType ; //typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GROUTER_ID_TYPE> GRouterKeyIdType ;
typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , true, RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType ; typedef t_RsGenericIdType< PGP_KEY_ID_SIZE , true, RS_GENERIC_ID_PGP_ID_TYPE> PGPIdType ;
typedef t_RsGenericIdType< SHA1_SIZE , false, RS_GENERIC_ID_SHA1_ID_TYPE> Sha1CheckSum ; typedef t_RsGenericIdType< SHA1_SIZE , false, RS_GENERIC_ID_SHA1_ID_TYPE> Sha1CheckSum ;
typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, true, RS_GENERIC_ID_PGP_FINGERPRINT_TYPE> PGPFingerprintType ; typedef t_RsGenericIdType< PGP_KEY_FINGERPRINT_SIZE, true, RS_GENERIC_ID_PGP_FINGERPRINT_TYPE> PGPFingerprintType ;

View File

@ -95,7 +95,7 @@ typedef uint64_t ChatLobbyMsgId ;
typedef std::string ChatLobbyNickName ; typedef std::string ChatLobbyNickName ;
typedef RsPeerId DistantChatPeerId ; typedef RsPeerId DistantChatPeerId ;
typedef GRouterKeyIdType DistantMsgPeerId ; //typedef GRouterKeyId DistantMsgPeerId ;
typedef uint64_t MessageId ; typedef uint64_t MessageId ;
@ -368,14 +368,6 @@ std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
class RsMsgs; class RsMsgs;
extern RsMsgs *rsMsgs; extern RsMsgs *rsMsgs;
struct DistantOfflineMessengingInvite
{
RsPgpId issuer_pgp_id ;
DistantMsgPeerId peer_id ;
time_t time_of_validity ;
};
class RsMsgs class RsMsgs
{ {
public: public:
@ -390,7 +382,6 @@ virtual ~RsMsgs() { return; }
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0; virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0;
virtual bool getMessage(const std::string &mId, MessageInfo &msg) = 0; virtual bool getMessage(const std::string &mId, MessageInfo &msg) = 0;
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox) = 0; virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox) = 0;
virtual bool decryptMessage(const std::string& mId) = 0 ;
virtual bool MessageSend(MessageInfo &info) = 0; virtual bool MessageSend(MessageInfo &info) = 0;
virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) = 0; virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) = 0;

View File

@ -295,10 +295,6 @@ bool p3Msgs::MessageSend(MessageInfo &info)
return mMsgSrv->MessageSend(info); return mMsgSrv->MessageSend(info);
} }
bool p3Msgs::decryptMessage(const std::string& mId)
{
return mMsgSrv->decryptMessage(mId);
}
void p3Msgs::enableDistantMessaging(bool b) void p3Msgs::enableDistantMessaging(bool b)
{ {
mMsgSrv->enableDistantMessaging(b); mMsgSrv->enableDistantMessaging(b);

View File

@ -59,7 +59,6 @@ class p3Msgs: public RsMsgs
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox); virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox);
virtual bool MessageSend(MessageInfo &info); virtual bool MessageSend(MessageInfo &info);
virtual bool decryptMessage(const std::string& mid);
virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
virtual bool MessageToDraft(MessageInfo &info, const std::string &msgParentId); virtual bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
virtual bool MessageToTrash(const std::string &mid, bool bTrash); virtual bool MessageToTrash(const std::string &mid, bool bTrash);

View File

@ -1449,7 +1449,7 @@ int RsServer::StartupRetroShare()
mStatusSrv = new p3StatusService(serviceCtrl); mStatusSrv = new p3StatusService(serviceCtrl);
#ifdef ENABLE_GROUTER #ifdef ENABLE_GROUTER
p3GRouter *gr = new p3GRouter(serviceCtrl,mLinkMgr) ; p3GRouter *gr = new p3GRouter(serviceCtrl,mGxsIdService) ;
rsGRouter = gr ; rsGRouter = gr ;
pqih->addService(gr,true) ; pqih->addService(gr,true) ;
#endif #endif
@ -1466,6 +1466,7 @@ int RsServer::StartupRetroShare()
ftserver->connectToTurtleRouter(tr) ; ftserver->connectToTurtleRouter(tr) ;
chatSrv->connectToTurtleRouter(tr) ; chatSrv->connectToTurtleRouter(tr) ;
gr->connectToTurtleRouter(tr) ;
#ifdef ENABLE_GROUTER #ifdef ENABLE_GROUTER
msgSrv->connectToGlobalRouter(gr) ; msgSrv->connectToGlobalRouter(gr) ;
#endif #endif

View File

@ -479,6 +479,7 @@ bool p3IdService::isPendingNetworkRequest(const RsGxsId& gxsId) const
bool p3IdService::getKey(const RsGxsId &id, RsTlvSecurityKey &key) bool p3IdService::getKey(const RsGxsId &id, RsTlvSecurityKey &key)
{ {
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data; RsGxsIdCache data;
if (mPublicKeyCache.fetch(id, data)) if (mPublicKeyCache.fetch(id, data))
@ -486,6 +487,10 @@ bool p3IdService::getKey(const RsGxsId &id, RsTlvSecurityKey &key)
key = data.pubkey; key = data.pubkey;
return true; return true;
} }
}
cache_request_load(id);
key.keyId.clear() ; key.keyId.clear() ;
return false; return false;
} }
@ -494,11 +499,13 @@ bool p3IdService::requestPrivateKey(const RsGxsId &id)
{ {
if (havePrivateKey(id)) if (havePrivateKey(id))
return true; return true;
return cache_request_load(id); return cache_request_load(id);
} }
bool p3IdService::getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key) bool p3IdService::getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key)
{ {
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data; RsGxsIdCache data;
if (mPrivateKeyCache.fetch(id, data)) if (mPrivateKeyCache.fetch(id, data))
@ -506,7 +513,12 @@ bool p3IdService::getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key)
key = data.pubkey; key = data.pubkey;
return true; return true;
} }
return false; }
key.keyId.clear() ;
cache_request_load(id);
return false ;
} }

View File

@ -315,19 +315,12 @@ void p3MsgService::checkSizeAndSendMessage(RsMsgItem *msg)
// Indicate that the message is to be continued. // Indicate that the message is to be continued.
// //
item->msgFlags |= RS_MSG_FLAGS_PARTIAL ; item->msgFlags |= RS_MSG_FLAGS_PARTIAL ;
if(msg->msgFlags & RS_MSG_FLAGS_DISTANT)
sendPrivateMsgItem(item) ;
else
sendItem(item) ; sendItem(item) ;
} }
#ifdef DEBUG_DISTANT_MSG #ifdef DEBUG_DISTANT_MSG
std::cerr << " Chopped off msg of size " << msg->message.size() << std::endl; std::cerr << " Chopped off msg of size " << msg->message.size() << std::endl;
#endif #endif
if(msg->msgFlags & RS_MSG_FLAGS_DISTANT)
sendPrivateMsgItem(msg) ;
else
sendItem(msg) ; sendItem(msg) ;
} }
@ -414,6 +407,9 @@ int p3MsgService::checkOutgoingMessages()
} }
for(std::list<RsMsgItem*>::const_iterator it(output_queue.begin());it!=output_queue.end();++it) for(std::list<RsMsgItem*>::const_iterator it(output_queue.begin());it!=output_queue.end();++it)
if((*it)->msgFlags & RS_MSG_FLAGS_DISTANT) // don't split distant messages. The global router takes care of it.
sendDistantMsgItem(*it) ;
else
checkSizeAndSendMessage(*it) ; checkSizeAndSendMessage(*it) ;
if(changed) if(changed)
@ -996,7 +992,7 @@ bool p3MsgService::setMsgParentId(uint32_t msgId, uint32_t msgParentId)
/****************************************/ /****************************************/
/****************************************/ /****************************************/
/* Message Items */ /* Message Items */
int p3MsgService::sendMessage(RsMsgItem *item) uint32_t p3MsgService::sendMessage(RsMsgItem *item)
{ {
if(!item) if(!item)
return 0 ; return 0 ;
@ -1021,15 +1017,23 @@ int p3MsgService::sendMessage(RsMsgItem *item)
msi->srcId = item->PeerId(); msi->srcId = item->PeerId();
mSrcIds.insert(std::pair<uint32_t, RsMsgSrcId*>(msi->msgId, msi)); mSrcIds.insert(std::pair<uint32_t, RsMsgSrcId*>(msi->msgId, msi));
} }
} }
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST, NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST, NOTIFY_TYPE_ADD);
checkOutgoingMessages(); return item->msgId;
}
uint32_t p3MsgService::sendDistantMessage(RsMsgItem *item,const RsGxsId& from)
{
uint32_t msg_id = sendMessage(item) ;
return 1; RS_STACK_MUTEX(mMsgMtx) ;
mDistantOutgoingMsgSigners[msg_id] = from ;
return msg_id ;
} }
bool p3MsgService::MessageSend(MessageInfo &info) bool p3MsgService::MessageSend(MessageInfo &info)
@ -1038,9 +1042,9 @@ bool p3MsgService::MessageSend(MessageInfo &info)
for(std::list<RsPeerId>::const_iterator pit = info.rspeerid_msgcc.begin(); pit != info.rspeerid_msgcc.end(); ++pit) sendMessage(initMIRsMsg(info, *pit)); for(std::list<RsPeerId>::const_iterator pit = info.rspeerid_msgcc.begin(); pit != info.rspeerid_msgcc.end(); ++pit) sendMessage(initMIRsMsg(info, *pit));
for(std::list<RsPeerId>::const_iterator pit = info.rspeerid_msgbcc.begin(); pit != info.rspeerid_msgbcc.end(); ++pit) sendMessage(initMIRsMsg(info, *pit)); for(std::list<RsPeerId>::const_iterator pit = info.rspeerid_msgbcc.begin(); pit != info.rspeerid_msgbcc.end(); ++pit) sendMessage(initMIRsMsg(info, *pit));
for(std::list<RsGxsId>::const_iterator pit = info.rsgxsid_msgto.begin(); pit != info.rsgxsid_msgto.end(); ++pit) sendMessage(initMIRsMsg(info, *pit)); for(std::list<RsGxsId>::const_iterator pit = info.rsgxsid_msgto.begin(); pit != info.rsgxsid_msgto.end(); ++pit) sendDistantMessage(initMIRsMsg(info, *pit),info.rsgxsid_srcId);
for(std::list<RsGxsId>::const_iterator pit = info.rsgxsid_msgcc.begin(); pit != info.rsgxsid_msgcc.end(); ++pit) sendMessage(initMIRsMsg(info, *pit)); for(std::list<RsGxsId>::const_iterator pit = info.rsgxsid_msgcc.begin(); pit != info.rsgxsid_msgcc.end(); ++pit) sendDistantMessage(initMIRsMsg(info, *pit),info.rsgxsid_srcId);
for(std::list<RsGxsId>::const_iterator pit = info.rsgxsid_msgbcc.begin(); pit != info.rsgxsid_msgbcc.end(); ++pit) sendMessage(initMIRsMsg(info, *pit)); for(std::list<RsGxsId>::const_iterator pit = info.rsgxsid_msgbcc.begin(); pit != info.rsgxsid_msgbcc.end(); ++pit) sendDistantMessage(initMIRsMsg(info, *pit),info.rsgxsid_srcId);
/* send to ourselves as well */ /* send to ourselves as well */
RsMsgItem *msg = initMIRsMsg(info, mServiceCtrl->getOwnId()); RsMsgItem *msg = initMIRsMsg(info, mServiceCtrl->getOwnId());
@ -1643,21 +1647,21 @@ RsMsgItem *p3MsgService::initMIRsMsg(const MessageInfo& info, const RsGxsId& to)
initMIRsMsg(msg,info) ; initMIRsMsg(msg,info) ;
msg->PeerId(RsPeerId()); msg->PeerId(RsPeerId(to));
msg->msgFlags |= RS_MSG_FLAGS_DISTANT; msg->msgFlags |= RS_MSG_FLAGS_DISTANT;
if (info.msgflags & RS_MSG_SIGNED) if (info.msgflags & RS_MSG_SIGNED)
msg->msgFlags |= RS_MSG_FLAGS_SIGNED; msg->msgFlags |= RS_MSG_FLAGS_SIGNED;
// We replace the msg text by the whole message serialized possibly signed, // // We replace the msg text by the whole message serialized possibly signed,
// and binary encrypted, so as to obfuscate all its content. // // and binary encrypted, so as to obfuscate all its content.
// // //
if(!createDistantMessage(to,info.rsgxsid_srcId,msg)) // if(!createDistantMessage(to,info.rsgxsid_srcId,msg))
{ // {
std::cerr << "Cannot encrypt distant message. Something went wrong." << std::endl; // std::cerr << "Cannot encrypt distant message. Something went wrong." << std::endl;
delete msg ; // delete msg ;
return NULL ; // return NULL ;
} // }
return msg ; return msg ;
} }
@ -1676,6 +1680,7 @@ RsMsgItem *p3MsgService::initMIRsMsg(const MessageInfo &info, const RsPeerId& to
return msg; return msg;
} }
#ifdef TO_BE_REMOVED
bool p3MsgService::createDistantMessage(const RsGxsId& destination_gxs_id,const RsGxsId& source_gxs_id,RsMsgItem *item) bool p3MsgService::createDistantMessage(const RsGxsId& destination_gxs_id,const RsGxsId& source_gxs_id,RsMsgItem *item)
{ {
#ifdef DEBUG_DISTANT_MSG #ifdef DEBUG_DISTANT_MSG
@ -2094,6 +2099,7 @@ bool p3MsgService::decryptMessage(const std::string& mId)
return false ; return false ;
} }
} }
#endif
void p3MsgService::connectToGlobalRouter(p3GRouter *gr) void p3MsgService::connectToGlobalRouter(p3GRouter *gr)
{ {
@ -2123,10 +2129,12 @@ void p3MsgService::enableDistantMessaging(bool b)
#endif #endif
for(std::list<RsGxsId>::const_iterator it(own_id_list.begin());it!=own_id_list.end();++it) for(std::list<RsGxsId>::const_iterator it(own_id_list.begin());it!=own_id_list.end();++it)
{
if(b) if(b)
mGRouter->registerKey(GRouterKeyId(*it),GROUTER_CLIENT_ID_MESSAGES,"Messaging contact") ; mGRouter->registerKey(*it,GROUTER_CLIENT_ID_MESSAGES,"Messaging contact") ;
else else
mGRouter->unregisterKey(GRouterKeyId(*it)) ; mGRouter->unregisterKey(*it,GROUTER_CLIENT_ID_MESSAGES) ;
}
if(cchanged) if(cchanged)
IndicateConfigChanged() ; IndicateConfigChanged() ;
@ -2147,38 +2155,19 @@ void p3MsgService::manageDistantPeers()
enableDistantMessaging(mDistantMessagingEnabled) ; enableDistantMessaging(mDistantMessagingEnabled) ;
} }
void p3MsgService::sendGRouterData(const GRouterKeyId& key_id,RsMsgItem *msgitem) void p3MsgService::notifyDataStatus(const GRouterMsgPropagationId& id,uint32_t data_status)
{ {
// The item is serialized and turned into a generic turtle item. if(data_status == GROUTER_CLIENT_SERVICE_DATA_STATUS_FAILED)
uint32_t msg_serialized_rssize = _serialiser->size(msgitem) ;
unsigned char *msg_serialized_data = new unsigned char[msg_serialized_rssize] ;
if(!_serialiser->serialise(msgitem,msg_serialized_data,&msg_serialized_rssize))
{ {
std::cerr << "(EE) p3MsgService::sendTurtleData(): Serialization error." << std::endl; std::cerr << __PRETTY_FUNCTION__ << ": Not fully implemented. The global router fails to send apacket, but we don't deal with it. Please remind the devs to do it" << std::endl;
delete[] msg_serialized_data ; return ;
}
if(data_status != GROUTER_CLIENT_SERVICE_DATA_STATUS_RECEIVED)
{
std::cerr << "p3MsgService: unhandled data status info from global router for msg ID " << id << ": this is a bug." << std::endl;
return ; return ;
} }
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ;
item->data_bytes = (uint8_t*)malloc(msg_serialized_rssize) ;
item->data_size = msg_serialized_rssize ;
memcpy(item->data_bytes,msg_serialized_data,msg_serialized_rssize) ;
delete[] msg_serialized_data ;
GRouterMsgPropagationId grouter_message_id ;
mGRouter->sendData(key_id,GROUTER_CLIENT_ID_MESSAGES,item,grouter_message_id) ;
// now store the grouter id along with the message id, so that we can keep track of received messages
_ongoing_messages[grouter_message_id] = msgitem->msgId ;
}
void p3MsgService::acknowledgeDataReceived(const GRouterMsgPropagationId& id)
{
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
#ifdef DEBUG_DISTANT_MSG #ifdef DEBUG_DISTANT_MSG
std::cerr << "p3MsgService::acknowledgeDataReceived(): acknowledging data received for msg propagation id " << id << std::endl; std::cerr << "p3MsgService::acknowledgeDataReceived(): acknowledging data received for msg propagation id " << id << std::endl;
@ -2209,38 +2198,79 @@ void p3MsgService::acknowledgeDataReceived(const GRouterMsgPropagationId& id)
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD);
IndicateConfigChanged() ; IndicateConfigChanged() ;
} }
void p3MsgService::receiveGRouterData(const GRouterKeyId& key, const RsGRouterGenericDataItem *gitem) void p3MsgService::receiveGRouterData(const RsGxsId& destination_key, const RsGxsId& signing_key,GRouterServiceId& client_id,uint8_t *data,uint32_t data_size)
{ {
std::cerr << "p3MsgService::receiveGRouterData(): received message item of size " << gitem->data_size << ", for key " << key << std::endl; std::cerr << "p3MsgService::receiveGRouterData(): received message item of size " << data_size << ", for key " << destination_key << std::endl;
uint32_t size = gitem->data_size ; RsItem *item = _serialiser->deserialise(data,&data_size) ;
RsItem *item = _serialiser->deserialise(gitem->data_bytes,&size) ;
RsMsgItem *encrypted_msg_item = dynamic_cast<RsMsgItem*>(item) ; free(data) ;
if(encrypted_msg_item != NULL) RsMsgItem *msg_item = dynamic_cast<RsMsgItem*>(item) ;
if(msg_item != NULL)
{ {
std::cerr << " Encrypted item correctly deserialised. Passing on to incoming list." << std::endl; std::cerr << " Encrypted item correctly deserialised. Passing on to incoming list." << std::endl;
encrypted_msg_item->PeerId(RsPeerId(key)) ; // hack to pass on GXS id. msg_item->PeerId(RsPeerId(signing_key)) ; // hack to pass on GXS id.
handleIncomingItem(encrypted_msg_item) ; handleIncomingItem(msg_item) ;
} }
else else
std::cerr << " Item could not be deserialised. Format error??" << std::endl; std::cerr << " Item could not be deserialised. Format error??" << std::endl;
} }
void p3MsgService::sendPrivateMsgItem(RsMsgItem *msgitem) void p3MsgService::sendDistantMsgItem(RsMsgItem *msgitem)
{ {
#ifdef DEBUG_DISTANT_MSG RsGxsId destination_key_id(msgitem->PeerId()) ;
std::cerr << "p3MsgService::sendDistanteMsgItem(): sending distant msg item to peer " << msgitem->PeerId() << std::endl; RsGxsId signing_key_id ;
#endif
GRouterKeyId key_id(msgitem->PeerId()) ;
{
RS_STACK_MUTEX(mMsgMtx) ;
signing_key_id = mDistantOutgoingMsgSigners[msgitem->msgId] ;
if(signing_key_id.isNull())
{
std::cerr << "ERROR: cannot find signing key id for msg id " << msgitem->msgId << std::endl;
std::cerr << " available keys are:" << std::endl;
for(std::map<uint32_t,RsGxsId>::const_iterator it(mDistantOutgoingMsgSigners.begin());it!=mDistantOutgoingMsgSigners.end();++it)
std::cerr << " " << it->first << " " << it->second << std::endl;
return ;
}
}
#ifdef DEBUG_DISTANT_MSG #ifdef DEBUG_DISTANT_MSG
std::cerr << " Flushing msg " << msgitem->msgId << " for peer id " << msgitem->PeerId() << std::endl; std::cerr << "p3MsgService::sendDistanteMsgItem(): sending distant msg item" << std::endl;
std::cerr << " msg ID : " << msgitem->msgId << std::endl;
std::cerr << " to peer : " << destination_key_id << std::endl;
std::cerr << " signing : " << signing_key_id << std::endl;
#endif #endif
sendGRouterData(key_id,msgitem) ; // The item is serialized and turned into a generic turtle item.
uint32_t msg_serialized_rssize = _serialiser->size(msgitem) ;
unsigned char *msg_serialized_data = new unsigned char[msg_serialized_rssize] ;
if(!_serialiser->serialise(msgitem,msg_serialized_data,&msg_serialized_rssize))
{
std::cerr << "(EE) p3MsgService::sendTurtleData(): Serialization error." << std::endl;
delete[] msg_serialized_data ;
return ;
}
#ifdef DEBUG_DISTANT_MSG
std::cerr << " serialised size : " << msg_serialized_rssize << std::endl;
#endif
GRouterMsgPropagationId grouter_message_id ;
mGRouter->sendData(destination_key_id,GROUTER_CLIENT_ID_MESSAGES,msg_serialized_data,msg_serialized_rssize,signing_key_id,grouter_message_id) ;
delete[] msg_serialized_data ;
// now store the grouter id along with the message id, so that we can keep track of received messages
{
RS_STACK_MUTEX(mMsgMtx) ;
_ongoing_messages[grouter_message_id] = msgitem->msgId ;
}
} }

View File

@ -127,7 +127,7 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
bool distantMessagingEnabled() ; bool distantMessagingEnabled() ;
private: private:
void sendPrivateMsgItem(RsMsgItem *msgitem) ; void sendDistantMsgItem(RsMsgItem *msgitem) ;
// This contains the ongoing tunnel handling contacts. // This contains the ongoing tunnel handling contacts.
// The map is indexed by the hash // The map is indexed by the hash
@ -136,21 +136,22 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
// Overloaded from GRouterClientService // Overloaded from GRouterClientService
virtual void receiveGRouterData(const GRouterKeyId& key,const RsGRouterGenericDataItem *item) ; virtual void receiveGRouterData(const RsGxsId& destination_key,const RsGxsId& signing_key, GRouterServiceId &client_id, uint8_t *data, uint32_t data_size) ;
virtual void acknowledgeDataReceived(const GRouterMsgPropagationId& msg_id) ; virtual void notifyDataStatus(const GRouterMsgPropagationId& msg_id,uint32_t data_status) ;
// Utility functions // Utility functions
bool createDistantMessage(const RsGxsId& destination_gxs_id,const RsGxsId& source_gxs_id,RsMsgItem *msg) ; bool createDistantMessage(const RsGxsId& destination_gxs_id,const RsGxsId& source_gxs_id,RsMsgItem *msg) ;
bool locked_findHashForVirtualPeerId(const RsPeerId& pid,Sha1CheckSum& hash) ; bool locked_findHashForVirtualPeerId(const RsPeerId& pid,Sha1CheckSum& hash) ;
void sendGRouterData(const GRouterKeyId &key_id,RsMsgItem *) ; void sendGRouterData(const RsGxsId &key_id,RsMsgItem *) ;
void manageDistantPeers() ; void manageDistantPeers() ;
void handleIncomingItem(RsMsgItem *) ; void handleIncomingItem(RsMsgItem *) ;
uint32_t getNewUniqueMsgId(); uint32_t getNewUniqueMsgId();
int sendMessage(RsMsgItem *item); uint32_t sendMessage(RsMsgItem *item);
uint32_t sendDistantMessage(RsMsgItem *item,const RsGxsId& signing_gxs_id);
void checkSizeAndSendMessage(RsMsgItem *msg); void checkSizeAndSendMessage(RsMsgItem *msg);
int incomingMsgs(); int incomingMsgs();
@ -192,6 +193,9 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
// used delete msgSrcIds after config save // used delete msgSrcIds after config save
std::map<uint32_t, RsMsgSrcId*> mSrcIds; std::map<uint32_t, RsMsgSrcId*> mSrcIds;
// temporary storage. Will not be needed when messages have a proper "from" field. Not saved!
std::map<uint32_t, RsGxsId> mDistantOutgoingMsgSigners;
// save the parent of the messages in draft for replied and forwarded // save the parent of the messages in draft for replied and forwarded
std::map<uint32_t, RsMsgParentId*> mParentId; std::map<uint32_t, RsMsgParentId*> mParentId;

View File

@ -1521,19 +1521,6 @@ void MessagesDialog::insertMsgTxtAndFiles(QTreeWidgetItem *item, bool bSetToRead
updateInterface(); updateInterface();
} }
void MessagesDialog::decryptSelectedMsg()
{
if (!MessageWidget::decryptMsg(mCurrMsgId)) {
return;
}
// Force refill
mCurrMsgId.clear();
msgWidget->fill("");
insertMsgTxtAndFiles(ui.messageTreeWidget->currentItem());
}
bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid) bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid)
{ {
QTreeWidgetItem *item = ui.messageTreeWidget->currentItem(); QTreeWidgetItem *item = ui.messageTreeWidget->currentItem();

View File

@ -69,7 +69,6 @@ private slots:
/** Create the context popup menu and it's submenus */ /** Create the context popup menu and it's submenus */
void messageTreeWidgetCustomPopupMenu(QPoint point); void messageTreeWidgetCustomPopupMenu(QPoint point);
void folderlistWidgetCustomPopupMenu(QPoint); void folderlistWidgetCustomPopupMenu(QPoint);
void decryptSelectedMsg() ;
void changeBox(int newrow); void changeBox(int newrow);
void changeQuickView(int newrow); void changeQuickView(int newrow);

View File

@ -1279,7 +1279,6 @@ static void processList(const QStringList &list, const QString &textSingular, co
std::cerr << " RetroShareLink::process MessageRequest : id : " << link.hash().toStdString() << ", subject : " << link.name().toStdString() << std::endl; std::cerr << " RetroShareLink::process MessageRequest : id : " << link.hash().toStdString() << ", subject : " << link.name().toStdString() << std::endl;
#endif #endif
RsPeerDetails detail; RsPeerDetails detail;
DistantMsgPeerId dm_pid ;
// This is awful, but apparently the hash can be multiple different types. Let's check! // This is awful, but apparently the hash can be multiple different types. Let's check!

View File

@ -125,7 +125,6 @@ const QString PeerDefs::rsidFromId(const RsPeerId &id, QString *name /* = NULL*/
QString rsid; QString rsid;
std::string peerName = rsPeers->getPeerName(id); std::string peerName = rsPeers->getPeerName(id);
DistantMsgPeerId pid ;
if(!peerName.empty()) if(!peerName.empty())
{ {

View File

@ -59,6 +59,8 @@ public:
void setDefaultId(RsGxsId defId) {mDefaultId=defId;} void setDefaultId(RsGxsId defId) {mDefaultId=defId;}
void setDefaultId(std::string defIdName) {mDefaultIdName=defIdName;} void setDefaultId(std::string defIdName) {mDefaultIdName=defIdName;}
bool hasAvailableIds() const { return !mDefaultId.isNull() ; }
bool setChosenId(RsGxsId &gxsId); bool setChosenId(RsGxsId &gxsId);
ChosenId_Ret getChosenId(RsGxsId &gxsId); ChosenId_Ret getChosenId(RsGxsId &gxsId);

View File

@ -2370,7 +2370,7 @@ void MessageComposer::addContact(enumType type)
std::list<RsGxsId> gxsIds ; std::list<RsGxsId> gxsIds ;
ui.friendSelectionWidget->selectedIds<RsGxsId,FriendSelectionWidget::IDTYPE_GXS>(gxsIds, false); ui.friendSelectionWidget->selectedIds<RsGxsId,FriendSelectionWidget::IDTYPE_GXS>(gxsIds, false);
if(!gxsIds.empty() && ui.respond_to_CB->count() == 0) if(!gxsIds.empty() && ui.respond_to_CB->hasAvailableIds())
{ {
QMessageBox::warning(NULL,tr("Cannot send distant messages"),tr("In order to send distant messages, you need an identity to sign with. Please go to the Identities tab and create one first.")); QMessageBox::warning(NULL,tr("Cannot send distant messages"),tr("In order to send distant messages, you need an identity to sign with. Please go to the Identities tab and create one first."));
return ; return ;

View File

@ -133,14 +133,12 @@ MessageWidget::MessageWidget(bool controlled, QWidget *parent, Qt::WindowFlags f
connect(ui.expandFilesButton, SIGNAL(clicked()), this, SLOT(togglefileview())); connect(ui.expandFilesButton, SIGNAL(clicked()), this, SLOT(togglefileview()));
connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(getallrecommended())); connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(getallrecommended()));
connect(ui.msgText, SIGNAL(anchorClicked(QUrl)), this, SLOT(anchorClicked(QUrl))); connect(ui.msgText, SIGNAL(anchorClicked(QUrl)), this, SLOT(anchorClicked(QUrl)));
connect(ui.decryptButton, SIGNAL(clicked()), this, SLOT(decrypt()));
connect(NotifyQt::getInstance(), SIGNAL(messagesTagsChanged()), this, SLOT(messagesTagsChanged())); connect(NotifyQt::getInstance(), SIGNAL(messagesTagsChanged()), this, SLOT(messagesTagsChanged()));
connect(NotifyQt::getInstance(), SIGNAL(messagesChanged()), this, SLOT(messagesChanged())); connect(NotifyQt::getInstance(), SIGNAL(messagesChanged()), this, SLOT(messagesChanged()));
ui.imageBlockWidget->addButtonAction(tr("Load images always for this message"), this, SLOT(loadImagesAlways()), true); ui.imageBlockWidget->addButtonAction(tr("Load images always for this message"), this, SLOT(loadImagesAlways()), true);
ui.msgText->setImageBlockWidget(ui.imageBlockWidget); ui.msgText->setImageBlockWidget(ui.imageBlockWidget);
ui.decryptFrame->hide();
/* hide the Tree +/- */ /* hide the Tree +/- */
ui.msgList->setRootIsDecorated( false ); ui.msgList->setRootIsDecorated( false );
@ -445,8 +443,6 @@ void MessageWidget::fill(const std::string &msgId)
// return; // return;
// } // }
ui.decryptFrame->hide();
currMsgId = msgId; currMsgId = msgId;
if (currMsgId.empty()) { if (currMsgId.empty()) {
@ -573,12 +569,7 @@ void MessageWidget::fill(const std::string &msgId)
ui.fromText->setToolTip(tooltip_string) ; ui.fromText->setToolTip(tooltip_string) ;
} }
if (msgInfo.msgflags & RS_MSG_ENCRYPTED) {
ui.subjectText->setText(tr("Encrypted message"));
ui.fromText->setText(tr("Unknown (needs decryption)")) ;
} else {
ui.subjectText->setText(QString::fromUtf8(msgInfo.title.c_str())); ui.subjectText->setText(QString::fromUtf8(msgInfo.title.c_str()));
}
text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromUtf8(msgInfo.msg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_REPLACE_LINKS); text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromUtf8(msgInfo.msg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_REPLACE_LINKS);
ui.msgText->resetImagesStatus(Settings->getMsgLoadEmbeddedImages() || (msgInfo.msgflags & RS_MSG_LOAD_EMBEDDED_IMAGES)); ui.msgText->resetImagesStatus(Settings->getMsgLoadEmbeddedImages() || (msgInfo.msgflags & RS_MSG_LOAD_EMBEDDED_IMAGES));
@ -587,10 +578,6 @@ void MessageWidget::fill(const std::string &msgId)
ui.filesText->setText(QString("%1").arg(msgInfo.count)); ui.filesText->setText(QString("%1").arg(msgInfo.count));
ui.filesSize->setText(QString(misc::friendlyUnit(msgInfo.size))); ui.filesSize->setText(QString(misc::friendlyUnit(msgInfo.size)));
if (msgInfo.msgflags & RS_MSG_ENCRYPTED) {
ui.decryptFrame->show();
}
showTagLabels(); showTagLabels();
currMsgFlags = msgInfo.msgflags; currMsgFlags = msgInfo.msgflags;
@ -748,40 +735,3 @@ void MessageWidget::loadImagesAlways()
rsMsgs->MessageLoadEmbeddedImages(currMsgId, true); rsMsgs->MessageLoadEmbeddedImages(currMsgId, true);
} }
void MessageWidget::decrypt()
{
if (!decryptMsg(currMsgId)) {
return;
}
// Force refill
std::string msgId = currMsgId;
currMsgId.clear();
fill(msgId);
}
bool MessageWidget::decryptMsg(const std::string &msgId)
{
if (msgId.empty()) {
return false;
}
MessageInfo msgInfo;
if (!rsMsgs->getMessage(msgId, msgInfo)) {
return false;
}
if (!(msgInfo.msgflags & RS_MSG_ENCRYPTED)) {
QMessageBox::warning(NULL, tr("Decryption failed!"), tr("This message is not encrypted. Cannot decrypt!"));
return false;
}
if (!rsMsgs->decryptMessage(msgId)) {
QMessageBox::warning(NULL, tr("Decryption failed!"), tr("This message could not be decrypted."));
return false;
}
return true;
}

View File

@ -59,7 +59,6 @@ public:
QString subject(bool noEmpty); QString subject(bool noEmpty);
static bool decryptMsg(const std::string &msgId);
private slots: private slots:
void reply(); void reply();
@ -82,7 +81,6 @@ private slots:
void anchorClicked(const QUrl &url); void anchorClicked(const QUrl &url);
void loadImagesAlways(); void loadImagesAlways();
void decrypt();
private: private:
void clearTagLabels(); void clearTagLabels();

View File

@ -23,7 +23,7 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="1" column="0"> <item row="0" column="0">
<widget class="QSplitter" name="msgSplitter"> <widget class="QSplitter" name="msgSplitter">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -414,125 +414,6 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QFrame" name="decryptFrame">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>255</green>
<blue>204</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>255</green>
<blue>204</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>255</green>
<blue>204</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>204</red>
<green>255</green>
<blue>204</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="decryptImage">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/mail-encrypted-full.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="decryptLabel">
<property name="text">
<string>This messages is encrypted. Click the right button to decrypt it.</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>280</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="decryptButton">
<property name="text">
<string>Decrypt</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
<action name="actionPrint"> <action name="actionPrint">
<property name="text"> <property name="text">

View File

@ -170,10 +170,10 @@ void GlobalRouterStatisticsWidget::updateContent()
painter.drawText(ox,oy+celly,tr("Managed keys")+":" + QString::number(matrix_info.published_keys.size())) ; oy += celly*2 ; painter.drawText(ox,oy+celly,tr("Managed keys")+":" + QString::number(matrix_info.published_keys.size())) ; oy += celly*2 ;
painter.setFont(monospace_f) ; painter.setFont(monospace_f) ;
for(std::map<GRouterKeyId,RsGRouter::GRouterPublishedKeyInfo>::const_iterator it(matrix_info.published_keys.begin());it!=matrix_info.published_keys.end();++it) for(std::map<Sha1CheckSum,RsGRouter::GRouterPublishedKeyInfo>::const_iterator it(matrix_info.published_keys.begin());it!=matrix_info.published_keys.end();++it)
{ {
QString packet_string ; QString packet_string ;
packet_string += QString::fromStdString(it->first.toStdString()) ; packet_string += QString::fromStdString(it->second.authentication_key.toStdString()) ;
packet_string += tr(" : Service ID = ")+QString::number(it->second.service_id,16) ; packet_string += tr(" : Service ID = ")+QString::number(it->second.service_id,16) ;
packet_string += " \""+QString::fromUtf8(it->second.description_string.c_str()) + "\"" ; packet_string += " \""+QString::fromUtf8(it->second.description_string.c_str()) + "\"" ;
@ -181,6 +181,45 @@ void GlobalRouterStatisticsWidget::updateContent()
} }
oy += celly ; oy += celly ;
painter.setFont(times_f) ;
painter.drawText(ox,oy+celly,tr("Pending packets")+":" + QString::number(cache_infos.size())) ; oy += celly*2 ;
painter.setFont(monospace_f) ;
static const QString data_status_string[4] = { "UNKOWN","PENDING","SENT","RECEIVED" } ;
static const QString tunnel_status_string[3] = { "UNMANAGED", "REQUESTED","ACTIVE" } ;
time_t now = time(NULL) ;
std::map<QString, std::vector<QString> > tos ;
for(uint32_t i=0;i<cache_infos.size();++i)
{
QString packet_string ;
packet_string += QString("Id=")+QString::number(cache_infos[i].mid,16) ;
//packet_string += tr(" By ")+QString::fromStdString(cache_infos[i].local_origin.toStdString()) ;
packet_string += tr(" Size: ")+QString::number(cache_infos[i].data_size) ;
packet_string += tr(" Data status: ")+data_status_string[cache_infos[i].data_status % 4] ;
packet_string += tr(" Tunnel status: ")+tunnel_status_string[cache_infos[i].tunnel_status % 3] ;
packet_string += " " + tr("Received: %1 secs ago, Send: %2 secs ago, Tried: %3 secs ago")
.arg(now - cache_infos[i].routing_time)
.arg(now - cache_infos[i].last_sent_time)
.arg(now - cache_infos[i].last_tunnel_attempt_time);
tos[ QString::fromStdString(cache_infos[i].destination.toStdString()) ].push_back(packet_string) ;
}
for(std::map<QString,std::vector<QString> >::const_iterator it(tos.begin());it!=tos.end();++it)
{
painter.drawText(ox+2*cellx,oy+celly,tr("To: ")+it->first ) ; oy += celly ;
for(uint32_t i=0;i<it->second.size();++i)
{
painter.drawText(ox+4*cellx,oy+celly,it->second[i] ) ;
oy += celly ;
}
}
oy += celly ;
QString prob_string ; QString prob_string ;
painter.setFont(times_f) ; painter.setFont(times_f) ;
QString Q = tr("Routing matrix (") ; QString Q = tr("Routing matrix (") ;
@ -215,39 +254,6 @@ void GlobalRouterStatisticsWidget::updateContent()
oy += celly ; oy += celly ;
} }
oy += celly ;
painter.setFont(times_f) ;
painter.drawText(ox,oy+celly,tr("Pending packets")+":" + QString::number(cache_infos.size())) ; oy += celly*2 ;
painter.setFont(monospace_f) ;
static const QString status_string[5] = { "UNKN", "PEND","SENT","ACKN","DEAD" } ;
time_t now = time(NULL) ;
std::map<QString, std::vector<QString> > tos ;
for(uint32_t i=0;i<cache_infos.size();++i)
{
QString packet_string ;
packet_string += QString("Id=")+QString::number(cache_infos[i].mid,16) ;
packet_string += tr(" by ")+QString::fromStdString(cache_infos[i].local_origin.toStdString()) ;
packet_string += tr(" size=")+QString::number(cache_infos[i].data_size) ;
packet_string += tr(" Status ")+status_string[cache_infos[i].status % 6] ;
packet_string += " " + tr("%1 secs ago").arg(now - cache_infos[i].time_stamp);
tos[ QString::fromStdString(cache_infos[i].destination.toStdString()) ].push_back(packet_string) ;
}
for(std::map<QString,std::vector<QString> >::const_iterator it(tos.begin());it!=tos.end();++it)
{
painter.drawText(ox+2*cellx,oy+celly,tr("To: ")+it->first ) ; oy += celly ;
for(uint32_t i=0;i<it->second.size();++i)
{
painter.drawText(ox+4*cellx,oy+celly,it->second[i] ) ;
oy += celly ;
}
}
oy += celly ; oy += celly ;

View File

@ -31,7 +31,7 @@ static FileIndex *createBasicFileIndex(time_t age);
TEST(libretroshare_dbase, SaveTest) TEST(libretroshare_dbase, SaveTest)
{ {
RsPeerId peerId; RsPeerId peerId;
peerId.random(); peerId = RsPeerId::random();
FileIndex *fi1 = createBasicFileIndex(100); FileIndex *fi1 = createBasicFileIndex(100);
FileIndex *fi2 = new FileIndex(peerId); FileIndex *fi2 = new FileIndex(peerId);
@ -59,7 +59,7 @@ TEST(libretroshare_dbase, SaveTest)
FileIndex *createBasicFileIndex(time_t age) FileIndex *createBasicFileIndex(time_t age)
{ {
RsPeerId peerId; RsPeerId peerId;
peerId.random(); peerId = RsPeerId::random();
FileIndex *fi = new FileIndex(peerId); FileIndex *fi = new FileIndex(peerId);
FileEntry fe; FileEntry fe;

View File

@ -156,7 +156,7 @@ int test2(FileIndex *fi)
FileIndex *createBasicFileIndex(time_t age) FileIndex *createBasicFileIndex(time_t age)
{ {
RsPeerId peerId; RsPeerId peerId;
peerId.random(); peerId = RsPeerId::random();
FileIndex *fi = new FileIndex(peerId); FileIndex *fi = new FileIndex(peerId);
FileEntry fe; FileEntry fe;

View File

@ -30,7 +30,7 @@
TEST(libretroshare_dbase, SearchTest) TEST(libretroshare_dbase, SearchTest)
{ {
RsPeerId peerId; RsPeerId peerId;
peerId.random(); peerId = RsPeerId::random();
std::cout << std::string::npos << std::endl; std::cout << std::string::npos << std::endl;
std::string testfile = "searchtest.index"; std::string testfile = "searchtest.index";

View File

@ -107,7 +107,7 @@ void init_item(RsGxsGrpMetaData* metaGrp)
metaGrp->mSubscribeFlags = rand()%2251; metaGrp->mSubscribeFlags = rand()%2251;
metaGrp->mPop = rand()%5262; metaGrp->mPop = rand()%5262;
metaGrp->mMsgCount = rand()%2421; metaGrp->mVisibleMsgCount = rand()%2421;
metaGrp->mLastPost = rand()%2211; metaGrp->mLastPost = rand()%2211;
metaGrp->mReputationCutOff = rand()%5262; metaGrp->mReputationCutOff = rand()%5262;

View File

@ -139,8 +139,8 @@ void test_messageStoresAndRetrieve()
// first create a grpId // first create a grpId
RsGxsGroupId grpId0, grpId1; RsGxsGroupId grpId0, grpId1;
grpId0.random(); grpId0 = RsGxsGroupId::random();
grpId1.random(); grpId1 = RsGxsGroupId::random();
std::vector<RsGxsGroupId> grpV; // stores grpIds of all msgs stored and retrieved std::vector<RsGxsGroupId> grpV; // stores grpIds of all msgs stored and retrieved
grpV.push_back(grpId0); grpV.push_back(grpId0);
grpV.push_back(grpId1); grpV.push_back(grpId1);

View File

@ -310,10 +310,10 @@ void GenExchangeTest::init(RsMsgMetaData& msgMetaData) const
//randString(SHORT_STR, msgMeta.mAuthorId); //randString(SHORT_STR, msgMeta.mAuthorId);
randString(SHORT_STR, msgMetaData.mMsgName); randString(SHORT_STR, msgMetaData.mMsgName);
randString(SHORT_STR, msgMetaData.mServiceString); randString(SHORT_STR, msgMetaData.mServiceString);
msgMetaData.mOrigMsgId.random(); msgMetaData.mOrigMsgId = RsGxsMessageId::random();
msgMetaData.mParentId.random(); msgMetaData.mParentId = RsGxsMessageId::random();
msgMetaData.mThreadId.random(); msgMetaData.mThreadId = RsGxsMessageId::random();
msgMetaData.mGroupId.random(); msgMetaData.mGroupId = RsGxsGroupId::random();
msgMetaData.mChildTs = randNum(); msgMetaData.mChildTs = randNum();
msgMetaData.mMsgStatus = randNum(); msgMetaData.mMsgStatus = randNum();
@ -328,7 +328,7 @@ uint32_t GenExchangeTest::randNum() const
void GenExchangeTest::init(RsGroupMetaData& grpMetaData) const void GenExchangeTest::init(RsGroupMetaData& grpMetaData) const
{ {
grpMetaData.mGroupId.random(); grpMetaData.mGroupId = RsGxsGroupId::random();
//randString(SHORT_STR, grpMetaData.mAuthorId); //randString(SHORT_STR, grpMetaData.mAuthorId);
randString(SHORT_STR, grpMetaData.mGroupName); randString(SHORT_STR, grpMetaData.mGroupName);
randString(SHORT_STR, grpMetaData.mServiceString); randString(SHORT_STR, grpMetaData.mServiceString);
@ -337,7 +337,7 @@ void GenExchangeTest::init(RsGroupMetaData& grpMetaData) const
grpMetaData.mGroupFlags = randNum(); grpMetaData.mGroupFlags = randNum();
grpMetaData.mLastPost = randNum(); grpMetaData.mLastPost = randNum();
grpMetaData.mGroupStatus = randNum(); grpMetaData.mGroupStatus = randNum();
grpMetaData.mMsgCount = randNum(); grpMetaData.mVisibleMsgCount = randNum();
grpMetaData.mPop = randNum(); grpMetaData.mPop = randNum();
grpMetaData.mSignFlags = randNum(); grpMetaData.mSignFlags = randNum();
grpMetaData.mPublishTs = randNum(); grpMetaData.mPublishTs = randNum();
@ -568,7 +568,7 @@ bool operator ==(const RsGroupMetaData& lMeta, const RsGroupMetaData& rMeta)
if(lMeta.mGroupName != rMeta.mGroupName) return false; if(lMeta.mGroupName != rMeta.mGroupName) return false;
if(lMeta.mGroupStatus != rMeta.mGroupStatus) return false; if(lMeta.mGroupStatus != rMeta.mGroupStatus) return false;
if(lMeta.mLastPost != rMeta.mLastPost) return false; if(lMeta.mLastPost != rMeta.mLastPost) return false;
if(lMeta.mMsgCount != rMeta.mMsgCount) return false; if(lMeta.mVisibleMsgCount != rMeta.mVisibleMsgCount) return false;
if(lMeta.mPop != rMeta.mPop) return false; if(lMeta.mPop != rMeta.mPop) return false;
// if(lMeta.mPublishTs != rMeta.mPublishTs) return false; set in gxs // if(lMeta.mPublishTs != rMeta.mPublishTs) return false; set in gxs
if(lMeta.mServiceString != rMeta.mServiceString) return false; if(lMeta.mServiceString != rMeta.mServiceString) return false;

View File

@ -155,8 +155,8 @@ public:
* @return a pointer to a valid profile if successful, otherwise NULL * @return a pointer to a valid profile if successful, otherwise NULL
* *
*/ */
int getKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; } bool getKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; }
int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; } // For signing outgoing messages. bool getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; } // For signing outgoing messages.
private: private:

View File

@ -76,7 +76,7 @@ NxsGrpSync::NxsGrpSync(RsGcxs* circle, RsGixsReputation* reputation)
if(circle) if(circle)
{ {
meta->mCircleType = GXS_CIRCLE_TYPE_EXTERNAL; meta->mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
meta->mCircleId.random(); meta->mCircleId = RsGxsCircleId::random();
} }
RsGxsGroupId grpId = grp->grpId; RsGxsGroupId grpId = grp->grpId;

View File

@ -121,10 +121,10 @@ void rs_nxs_test::NxsTestHub::StartTest()
PeerNxsMap::iterator mit = mPeerNxsMap.begin(); PeerNxsMap::iterator mit = mPeerNxsMap.begin();
for(; mit != mPeerNxsMap.end(); mit++) for(; mit != mPeerNxsMap.end(); mit++)
{ {
createThread(*(mit->second)); (mit->second)->start() ;
} }
createThread(*this); start() ;
} }

View File

@ -23,44 +23,39 @@
* *
*/ */
#include <iostream>
#include <math.h> #include <math.h>
#include "util/rsrandom.h" #include <gtest/gtest.h>
#include <iostream>
#include <sstream>
#include "grouter/grouteritems.h" #include "grouter/grouteritems.h"
#include "serialiser/rstlvutil.h"
#include "support.h" #include "support.h"
#include "rstlvutil.h"
RsSerialType* init_item(RsGRouterGenericDataItem& cmi) RsSerialType* init_item(RsGRouterGenericDataItem& cmi)
{ {
cmi.routing_id = RSRandom::random_u32() ;
cmi.destination_key = GRouterKeyId::random() ;
cmi.data_size = lrand48()%1000 + 1000 ; cmi.data_size = lrand48()%1000 + 1000 ;
cmi.data_bytes = (uint8_t*)malloc(cmi.data_size) ; cmi.data_bytes = (uint8_t*)malloc(cmi.data_size) ;
RSRandom::random_bytes(cmi.data_bytes,cmi.data_size) ; RSRandom::random_bytes(cmi.data_bytes,cmi.data_size) ;
cmi.routing_id = RSRandom::random_u32() ;
Sha1CheckSum cs ; init_item(cmi.signature) ;
for(int i=0;i<5;++i) cs.fourbytes[i] = RSRandom::random_u32() ;
cmi.destination_key = cs ; cmi.randomized_distance = RSRandom::random_u32() ;
cmi.flags = RSRandom::random_u32() ;
return new RsGRouterSerialiser(); return new RsGRouterSerialiser();
} }
RsSerialType* init_item(RsGRouterACKItem& cmi) RsSerialType* init_item(RsGRouterReceiptItem& cmi)
{ {
cmi.mid = RSRandom::random_u32() ; cmi.mid = RSRandom::random_u64() ;
cmi.state = RSRandom::random_u32() ; cmi.state = RSRandom::random_u32() ;
cmi.destination_key = GRouterKeyId::random() ;
return new RsGRouterSerialiser(); init_item(cmi.signature) ;
}
RsSerialType* init_item(RsGRouterPublishKeyItem& cmi)
{
cmi.diffusion_id = RSRandom::random_u32() ;
cmi.service_id = RSRandom::random_u32() ;
cmi.randomized_distance = RSRandom::random_f32() ;
Sha1CheckSum cs ;
for(int i=0;i<5;++i) cs.fourbytes[i] = RSRandom::random_u32() ;
cmi.published_key = cs ;
cmi.description_string = "test key" ;
return new RsGRouterSerialiser(); return new RsGRouterSerialiser();
} }
@ -68,10 +63,13 @@ RsSerialType* init_item(RsGRouterRoutingInfoItem& cmi)
{ {
cmi.origin = SSLIdType::random() ; cmi.origin = SSLIdType::random() ;
cmi.received_time = RSRandom::random_u64() ; cmi.received_time = RSRandom::random_u64() ;
cmi.last_sent = RSRandom::random_u64() ;
cmi.status_flags = RSRandom::random_u32() ; cmi.status_flags = RSRandom::random_u32() ;
cmi.data_item = new RsGRouterGenericDataItem ; cmi.data_item = new RsGRouterGenericDataItem ;
init_item(*cmi.data_item) ;
uint32_t n = 10+(RSRandom::random_u32()%30) ; uint32_t n = 10+(RSRandom::random_u32()%30) ;
for(uint32_t i=0;i<n;++i) for(uint32_t i=0;i<n;++i)
@ -79,11 +77,15 @@ RsSerialType* init_item(RsGRouterRoutingInfoItem& cmi)
FriendTrialRecord ftr ; FriendTrialRecord ftr ;
ftr.friend_id = SSLIdType::random() ; ftr.friend_id = SSLIdType::random() ;
ftr.time_stamp = RSRandom::random_u64() ; ftr.time_stamp = RSRandom::random_u64() ;
ftr.probability = RSRandom::random_f32() ;
ftr.nb_friends = 1+RSRandom::random_u32()%10 ;
cmi.tried_friends.push_back(ftr) ; cmi.tried_friends.push_back(ftr) ;
} }
cmi.destination_key = cmi.data_item->destination_key ;
cmi.client_id = RSRandom::random_u32() ;
return init_item(*cmi.data_item) ; return new RsGRouterSerialiser();
} }
RsSerialType* init_item(RsGRouterMatrixFriendListItem& cmi) RsSerialType* init_item(RsGRouterMatrixFriendListItem& cmi)
{ {
@ -97,7 +99,7 @@ RsSerialType* init_item(RsGRouterMatrixFriendListItem& cmi)
} }
RsSerialType* init_item(RsGRouterMatrixCluesItem& cmi) RsSerialType* init_item(RsGRouterMatrixCluesItem& cmi)
{ {
cmi.destination_key = Sha1CheckSum::random() ; cmi.destination_key = GRouterKeyId::random() ;
uint32_t n = 10+(RSRandom::random_u32()%30) ; uint32_t n = 10+(RSRandom::random_u32()%30) ;
@ -116,27 +118,24 @@ RsSerialType* init_item(RsGRouterMatrixCluesItem& cmi)
bool operator ==(const RsGRouterGenericDataItem& cmiLeft,const RsGRouterGenericDataItem& cmiRight) bool operator ==(const RsGRouterGenericDataItem& cmiLeft,const RsGRouterGenericDataItem& cmiRight)
{ {
if(cmiLeft.routing_id != cmiRight.routing_id) return false; if(cmiLeft.routing_id != cmiRight.routing_id) return false;
if(cmiLeft.data_size != cmiRight.data_size) return false;
if(!(cmiLeft.destination_key == cmiRight.destination_key)) return false; if(!(cmiLeft.destination_key == cmiRight.destination_key)) return false;
if(cmiLeft.data_size != cmiRight.data_size) return false;
if(memcmp(cmiLeft.data_bytes,cmiRight.data_bytes,cmiLeft.data_size)) return false; if(memcmp(cmiLeft.data_bytes,cmiRight.data_bytes,cmiLeft.data_size)) return false;
return true ; if(!(cmiLeft.signature == cmiRight.signature)) return false ;
} if(cmiLeft.randomized_distance != cmiRight.randomized_distance ) return false ;
bool operator ==(const RsGRouterPublishKeyItem& cmiLeft,const RsGRouterPublishKeyItem& cmiRight) if(cmiLeft.flags != cmiRight.flags ) return false ;
{
if(cmiLeft.diffusion_id != cmiRight.diffusion_id) return false;
if(!(cmiLeft.published_key == cmiRight.published_key)) return false;
if(cmiLeft.service_id != cmiRight.service_id) return false;
if(fabs(cmiLeft.randomized_distance - cmiRight.randomized_distance) > 0.001) return false;
if(cmiLeft.description_string != cmiRight.description_string) return false;
return true ; return true ;
} }
bool operator ==(const RsGRouterACKItem& cmiLeft,const RsGRouterACKItem& cmiRight) bool operator ==(const RsGRouterReceiptItem& cmiLeft,const RsGRouterReceiptItem& cmiRight)
{ {
if(cmiLeft.mid != cmiRight.mid) return false; if(cmiLeft.mid != cmiRight.mid) return false;
if(cmiLeft.state != cmiRight.state) return false; if(cmiLeft.state != cmiRight.state) return false;
if(cmiLeft.destination_key != cmiRight.destination_key) return false;
if(!(cmiLeft.signature == cmiRight.signature)) return false ;
return true; return true;
} }
bool operator ==(const RsGRouterMatrixCluesItem& cmiLeft,const RsGRouterMatrixCluesItem& cmiRight) bool operator ==(const RsGRouterMatrixCluesItem& cmiLeft,const RsGRouterMatrixCluesItem& cmiRight)
@ -173,19 +172,24 @@ bool operator ==(const RsGRouterRoutingInfoItem& cmiLeft,const RsGRouterRoutingI
if(cmiLeft.status_flags != cmiRight.status_flags) return false ; if(cmiLeft.status_flags != cmiRight.status_flags) return false ;
if(cmiLeft.origin != cmiRight.origin) return false ; if(cmiLeft.origin != cmiRight.origin) return false ;
if(cmiLeft.received_time != cmiRight.received_time) return false ; if(cmiLeft.received_time != cmiRight.received_time) return false ;
if(cmiLeft.last_sent != cmiRight.last_sent) return false ;
if(cmiLeft.tried_friends.size() != cmiRight.tried_friends.size()) return false ; if(cmiLeft.tried_friends.size() != cmiRight.tried_friends.size()) return false ;
std::list<FriendTrialRecord>::const_iterator itl(cmiLeft.tried_friends.begin()) ; std::list<FriendTrialRecord>::const_iterator itl(cmiLeft.tried_friends.begin()) ;
std::list<FriendTrialRecord>::const_iterator itr(cmiRight.tried_friends.begin()) ; std::list<FriendTrialRecord>::const_iterator itr(cmiRight.tried_friends.begin()) ;
while(itl != cmiLeft.tried_friends.end()) // while(itl != cmiLeft.tried_friends.end())
{ // {
if( (*itl).friend_id != (*itr).friend_id) return false ; // if( (*itl).friend_id != (*itr).friend_id) return false ;
if( (*itl).time_stamp != (*itr).time_stamp) return false ; // if( (*itl).time_stamp != (*itr).time_stamp) return false ;
// if( fabs((*itl).probability - (*itr).probability)<0.001) return false ;
++itl ; // if( (*itl).nb_friends != (*itr).nb_friends) return false ;
++itr ; //
} // ++itl ;
// ++itr ;
// }
if(cmiLeft.destination_key != cmiRight.destination_key) return false ;
if(cmiLeft.client_id != cmiRight.client_id) return false ;
if(!(*cmiLeft.data_item == *cmiRight.data_item)) return false ; if(!(*cmiLeft.data_item == *cmiRight.data_item)) return false ;
@ -196,8 +200,7 @@ bool operator ==(const RsGRouterRoutingInfoItem& cmiLeft,const RsGRouterRoutingI
TEST(libretroshare_serialiser, RsGRouterItem) TEST(libretroshare_serialiser, RsGRouterItem)
{ {
test_RsItem<RsGRouterGenericDataItem >(); test_RsItem<RsGRouterGenericDataItem >();
test_RsItem<RsGRouterACKItem >(); test_RsItem<RsGRouterReceiptItem >();
test_RsItem<RsGRouterPublishKeyItem >();
test_RsItem<RsGRouterRoutingInfoItem >(); test_RsItem<RsGRouterRoutingInfoItem >();
test_RsItem<RsGRouterMatrixFriendListItem >(); test_RsItem<RsGRouterMatrixFriendListItem >();
test_RsItem<RsGRouterMatrixCluesItem >(); test_RsItem<RsGRouterMatrixCluesItem >();

View File

@ -15,18 +15,18 @@ RsSerialType* init_item(RsGxsGrpUpdateItem& i)
{ {
i.clear(); i.clear();
i.grpUpdateTS = rand()%2424; i.grpUpdateTS = rand()%2424;
i.peerId.random(); i.peerId = RsPeerId::random();
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsGxsMsgUpdateItem& i) RsSerialType* init_item(RsGxsMsgUpdateItem& i)
{ {
i.clear(); i.clear();
i.peerId.random(); i.peerId = RsPeerId::random();
int numUpdates = rand()%123; int numUpdates = rand()%123;
RsPeerId peer; RsPeerId peer;
peer.random(); peer = RsPeerId::random();
for(int j=0; j < numUpdates; j++) for(int j=0; j < numUpdates; j++)
{ {
i.msgUpdateTS.insert(std::make_pair(peer, rand()%45)); i.msgUpdateTS.insert(std::make_pair(peer, rand()%45));
@ -46,7 +46,7 @@ RsSerialType* init_item(RsGxsServerGrpUpdateItem& i)
RsSerialType* init_item(RsGxsServerMsgUpdateItem& i) RsSerialType* init_item(RsGxsServerMsgUpdateItem& i)
{ {
i.clear(); i.clear();
i.grpId.random(); i.grpId = RsGxsGroupId::random();
i.msgUpdateTS = rand()%4252; i.msgUpdateTS = rand()%4252;
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }

View File

@ -99,7 +99,7 @@ RsSerialType* init_item(RsChatLobbyInviteItem& cmi)
RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi) RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi)
{ {
pcmi.configPeerId.random(); pcmi.configPeerId = RsPeerId::random();
pcmi.chatFlags = rand()%34; pcmi.chatFlags = rand()%34;
pcmi.configFlags = rand()%21; pcmi.configFlags = rand()%21;
pcmi.sendTime = rand()%422224; pcmi.sendTime = rand()%422224;
@ -174,7 +174,7 @@ RsSerialType* init_item(RsMsgTags& mt)
RsSerialType* init_item(RsMsgSrcId& ms) RsSerialType* init_item(RsMsgSrcId& ms)
{ {
ms.msgId = rand()%434; ms.msgId = rand()%434;
ms.srcId.random(); ms.srcId = RsPeerId::random();
return new RsMsgSerialiser(); return new RsMsgSerialiser();
} }

View File

@ -68,7 +68,7 @@ void init_item(RsTlvSecurityKeySet& ks)
for(int i=1; i<n; i++) for(int i=1; i<n; i++)
{ {
RsGxsId a_str; RsGxsId a_str;
a_str.random(); a_str = RsGxsId::random();
RsTlvSecurityKey& a_key = ks.keys[a_str]; RsTlvSecurityKey& a_key = ks.keys[a_str];
init_item(a_key); init_item(a_key);
@ -190,7 +190,7 @@ void init_item(RsTlvSecurityKey& sk)
sk.endTS = randnum; sk.endTS = randnum;
sk.keyFlags = randnum; sk.keyFlags = randnum;
sk.startTS = randnum; sk.startTS = randnum;
sk.keyId.random(); sk.keyId = RsGxsId::random();
std::string randomStr; std::string randomStr;
randString(LARGE_STR, randomStr); randString(LARGE_STR, randomStr);
@ -202,7 +202,7 @@ void init_item(RsTlvSecurityKey& sk)
void init_item(RsTlvKeySignature& ks) void init_item(RsTlvKeySignature& ks)
{ {
ks.keyId.random(); ks.keyId = RsGxsId::random();
std::string signData; std::string signData;
randString(LARGE_STR, signData); randString(LARGE_STR, signData);

View File

@ -176,7 +176,7 @@ TEST(libretroshare_serialiser, test_RsTlvPeerIdSet)
for(int i = 0; i < 15 ; i++) for(int i = 0; i < 15 ; i++)
{ {
testId.random(); testId = RsPeerId::random();
i1.ids.push_back(testId); i1.ids.push_back(testId);
} }
@ -296,7 +296,7 @@ TEST(libretroshare_serialiser, test_RsTlvHashSet)
for(int i = 0; i < numRandStrings ; i++) for(int i = 0; i < numRandStrings ; i++)
{ {
RsPeerId randId; RsPeerId randId;
randId.random(); randId = RsPeerId::random();
i1.ids.push_back(randId); i1.ids.push_back(randId);
} }

View File

@ -55,8 +55,8 @@ GxsIsolatedServiceTester::GxsIsolatedServiceTester(const RsPeerId &ownId, const
node->AddService(mTestNs); node->AddService(mTestNs);
//mConfigMgr->addConfiguration("posted.cfg", posted_ns); //mConfigMgr->addConfiguration("posted.cfg", posted_ns);
createThread(*mTestService); mTestService->start();
createThread(*mTestNs); mTestNs->start();
//node->AddPqiServiceMonitor(status); //node->AddPqiServiceMonitor(status);
addSerialType(new RsNxsSerialiser(RS_SERVICE_GXS_TYPE_TEST)); addSerialType(new RsNxsSerialiser(RS_SERVICE_GXS_TYPE_TEST));

View File

@ -122,14 +122,14 @@ GxsPeerNode::GxsPeerNode(const RsPeerId &ownId, const std::list<RsPeerId> &frien
//mConfigMgr->addConfiguration("gxsid.cfg", mGxsIdNs); //mConfigMgr->addConfiguration("gxsid.cfg", mGxsIdNs);
//mConfigMgr->addConfiguration("gxscircles.cfg", mGxsCircleNs); //mConfigMgr->addConfiguration("gxscircles.cfg", mGxsCircleNs);
createThread(*mGxsIdService); mGxsIdService->start();
createThread(*mGxsIdNs); mGxsIdNs->start();
createThread(*mGxsCircles); mGxsCircles->start();
createThread(*mGxsCirclesNs); mGxsCirclesNs->start();
} }
createThread(*mTestService); mTestService->start();
createThread(*mTestNs); mTestNs->start();
//node->AddPqiServiceMonitor(status); //node->AddPqiServiceMonitor(status);
} }

View File

@ -262,6 +262,7 @@ SOURCES += libretroshare/serialiser/rsturtleitem_test.cc \
libretroshare/serialiser/tlvbase_test.cc \ libretroshare/serialiser/tlvbase_test.cc \
libretroshare/serialiser/tlvstack_test.cc \ libretroshare/serialiser/tlvstack_test.cc \
libretroshare/serialiser/tlvitems_test.cc \ libretroshare/serialiser/tlvitems_test.cc \
libretroshare/serialiser/rsgrouteritem_test.cc \
libretroshare/serialiser/tlvtypes_test.cc \ libretroshare/serialiser/tlvtypes_test.cc \
libretroshare/serialiser/tlvkey_test.cc \ libretroshare/serialiser/tlvkey_test.cc \
libretroshare/serialiser/support.cc \ libretroshare/serialiser/support.cc \