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,9 +36,13 @@
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
{
public:
public:
// This method is called by the turtle router to send data that comes out of a turtle tunnel.
// The turtle router stays responsible for the memory management of data. Most of the time the
// data chunk is a serialized item to be de-serialized by the client service.
@ -49,19 +53,20 @@ class GRouterClientService
//
// 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 << " 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 << " message ID = " << received_id << 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 << " data status = " << data_status << std::endl;
}
// This function is mandatory. It should do two things:
// 1 - keep a pointer to the global router, so as to be able to send data (e.g. copy pt into a local variable)

View file

@ -29,118 +29,6 @@ bool RsGRouterItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvs
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 */
/**********************************************************************************************/
@ -157,46 +45,75 @@ RsItem *RsGRouterSerialiser::deserialise(void *data, uint32_t *pktsize)
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_ACK: return deserialise_RsGRouterACKItem(data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return deserialise_RsGRouterMatrixCluesItem(data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_DATA: return deserialise_RsGRouterGenericDataItem (data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: return deserialise_RsGRouterTransactionChunkItem(data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: return deserialise_RsGRouterTransactionAcknItem (data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT: return deserialise_RsGRouterSignedReceiptItem (data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return deserialise_RsGRouterMatrixCluesItem (data, *pktsize);
case RS_PKT_SUBTYPE_GROUTER_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:
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;
}
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
//{
// 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;
//}
RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem() ;
/* add mandatory parts first */
ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id);
ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_start);
ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_size);
ok &= getRawUInt32(data, tlvsize, &offset, &item->total_size);
if( 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
{
uint32_t offset = 8; // skip the header
@ -207,19 +124,29 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI
ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
ok &= item->destination_key.deserialise(data, pktsize, offset) ;
ok &= getRawUInt32(data, pktsize, &offset, &item->randomized_distance);
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)))
{
std::cerr << __PRETTY_FUNCTION__ << ": Cannot allocate memory for chunk " << item->data_size << std::endl;
return NULL ;
}
memcpy(item->data_bytes,&((uint8_t*)data)[offset],item->data_size) ;
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) ;
offset += item->data_size ;
if (offset != rssize || !ok)
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)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
return NULL ;
@ -228,16 +155,19 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI
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 rssize = getRsItemSize(data);
bool ok = true ;
RsGRouterACKItem *item = new RsGRouterACKItem() ;
RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem() ;
ok &= getRawUInt64(data, pktsize, &offset, &item->mid); // file hash
ok &= getRawUInt32(data, pktsize, &offset, &item->state); // file hash
ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
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)
{
@ -256,26 +186,20 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI
RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ;
ok &= getRawUInt32(data, pktsize, &offset, &item->status_flags);
ok &= item->origin.deserialise(data, pktsize, offset) ;
ok &= getRawTimeT(data, pktsize, &offset, item->received_time);
ok &= getRawTimeT(data, pktsize, &offset, item->last_sent);
ok &= getRawUInt32(data, pktsize, &offset, &item->client_id);
RsPeerId peer_id ;
ok &= peer_id.deserialise(data, pktsize, offset) ;
item->PeerId(peer_id) ;
uint32_t s = 0 ;
ok &= getRawUInt32(data, pktsize, &offset, &s) ;
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);
for(uint32_t i=0;i<s;++i)
{
FriendTrialRecord ftr ;
ok &= getRawTimeT(data, pktsize, &offset, item->last_tunnel_request_TS);
ok &= getRawUInt32(data, pktsize, &offset, &item->sending_attempts);
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) ;
}
ok &= getRawUInt32(data, pktsize, &offset, &item->client_id);
ok &= item->tunnel_hash.deserialise(data, pktsize, offset) ;
item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ;
if(item->data_item != NULL)
@ -283,7 +207,19 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI
else
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)
{
@ -351,70 +287,191 @@ RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesI
return item;
}
RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
{
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ;
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ;
item->routing_id = routing_id ;
item->destination_key = destination_key ;
item->data_size = data_size ;
item->randomized_distance = randomized_distance ;
// copy all members
// then duplicate the memory chunk
*item = *this ;
item->data_bytes = (uint8_t*)malloc(data_size) ;
memcpy(item->data_bytes,data_bytes,data_size) ;
// then duplicate the memory chunk
return item ;
item->data_bytes = (uint8_t*)malloc(data_size) ;
memcpy(item->data_bytes,data_bytes,data_size) ;
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 s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += 4 ; // randomized distance
s += 4 ; // data_size
s += data_size ; // data
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
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 ; // flags
return s ;
return s ;
}
uint32_t RsGRouterACKItem::serial_size() const
uint32_t RsGRouterGenericDataItem::signed_data_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += 4 ; // state
uint32_t s = 0 ; // no header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += 4 ; // data_size
s += data_size ; // data
return s ;
return s ;
}
uint32_t RsGRouterSignedReceiptItem::serial_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += destination_key.serial_size() ; // destination_key
s += data_hash.serial_size() ;
s += 4 ; // state
s += 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
return s ;
}
uint32_t RsGRouterTransactionChunkItem::serial_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
s += 4 ; // chunk_start
s += 4 ; // chunk_size
s += 4 ; // total_size
s += chunk_size ; // data
return s;
}
uint32_t RsGRouterTransactionAcknItem::serial_size() const
{
uint32_t s = 8 ; // header
s += sizeof(GRouterMsgPropagationId) ; // routing id
return s;
}
bool RsGRouterTransactionChunkItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, propagation_id);
ok &= setRawUInt32(data, tlvsize, &offset, chunk_start);
ok &= setRawUInt32(data, tlvsize, &offset, chunk_size);
ok &= setRawUInt32(data, tlvsize, &offset, total_size);
memcpy(&((uint8_t*)data)[offset],chunk_data,chunk_size) ;
offset += chunk_size ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
uint32_t tlvsize,offset=0;
bool ok = true;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
ok &= destination_key.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, randomized_distance) ;
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
if(!serialise_header(data,size,tlvsize,offset))
return false ;
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
offset += 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);
if (offset != tlvsize)
{
ok = false;
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, flags) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
}
}
return ok;
return ok;
}
bool RsGRouterACKItem::serialise(void *data,uint32_t& size) const
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);
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
offset += data_size ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterSignedReceiptItem::serialise(void *data,uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
@ -423,18 +480,41 @@ bool RsGRouterACKItem::serialise(void *data,uint32_t& size) const
return false ;
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, mid);
ok &= setRawUInt32(data, tlvsize, &offset, state);
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) ;
ok &= signature.SetTlv(data,tlvsize,&offset) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterACKItem::serialisedata() size error! " << std::endl;
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl;
}
return ok;
}
bool RsGRouterSignedReceiptItem::serialise_signed_data(void *data,uint32_t& size) const
{
bool ok = true;
uint32_t offset=0;
uint32_t tlvsize = signed_data_size() ;
/* 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 */
uint32_t RsGRouterMatrixCluesItem::serial_size() const
{
@ -456,17 +536,26 @@ uint32_t RsGRouterMatrixFriendListItem::serial_size() const
}
uint32_t RsGRouterRoutingInfoItem::serial_size() const
{
uint32_t s = 8 ; // header
s += 4 ; // status_flags
s += origin.serial_size() ; // origin
s += 8 ; // received_time
s += 8 ; // last_sent
s += 4 ; // tried_friends.size() ;
s += sizeof(GRouterServiceId) ; // service_id
s += tried_friends.size() * ( RsPeerId::SIZE_IN_BYTES + 8 + 4 + 4 ) ; // FriendTrialRecord
s += data_item->serial_size(); // data_item
uint32_t s = 8 ; // header
s += PeerId().serial_size() ;
return s ;
s += 4 ; // data status_flags
s += 4 ; // tunnel status_flags
s += 8 ; // received_time
s += 8 ; // last_sent
s += 8 ; // last_TR_TS
s += 4 ; // sending attempts
s += sizeof(GRouterServiceId) ; // service_id
s += tunnel_hash.serial_size() ;
s += data_item->serial_size(); // data_item
if(receipt_item != NULL)
s += receipt_item->serial_size(); // receipt_item
return s ;
}
bool RsGRouterMatrixFriendListItem::serialise(void *data,uint32_t& size) const
@ -545,20 +634,27 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= setRawUInt32(data, tlvsize, &offset, status_flags) ;
ok &= origin.serialise(data, tlvsize, offset) ;
ok &= setRawTimeT(data, tlvsize, &offset, received_time) ;
ok &= setRawTimeT(data, tlvsize, &offset, last_sent) ;
ok &= PeerId().serialise(data, tlvsize, offset) ; // we keep this.
ok &= setRawUInt32(data, tlvsize, &offset, data_status) ;
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_status) ;
ok &= setRawTimeT(data, tlvsize, &offset, received_time_TS) ;
ok &= setRawTimeT(data, tlvsize, &offset, last_sent_TS) ;
ok &= setRawTimeT(data, tlvsize, &offset, last_tunnel_request_TS) ;
ok &= setRawUInt32(data, tlvsize, &offset, sending_attempts) ;
ok &= setRawUInt32(data, tlvsize, &offset, client_id) ;
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ;
ok &= tunnel_hash.serialise(data, tlvsize, offset) ;
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it)
ok &= (*it).serialise(data,offset,size) ;
uint32_t ns = size - offset ;
ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ;
offset += ns ;
uint32_t ns = size - offset ;
ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ;
offset += data_item->serial_size() ;
if(receipt_item != NULL)
{
uint32_t ns = size - offset ;
ok &= receipt_item->serialise( &((uint8_t*)data)[offset], ns) ;
offset += receipt_item->serial_size() ;
}
if (offset != tlvsize)
{
ok = false;
@ -572,51 +668,46 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
// ------------------------------------- IO --------------------------------------- //
// -----------------------------------------------------------------------------------//
//
//std::ostream& RsGRouterPublishKeyItem::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)
std::ostream& RsGRouterSignedReceiptItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterACKItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " Mid: " << mid << std::endl ;
o << " State: " << state << std::endl ;
o << "RsGRouterReceiptItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " Mid: " << std::hex << routing_id << std::dec << std::endl ;
o << " State: " << flags << std::endl ;
o << " Dest: " << destination_key << std::endl ;
o << " Sign: " << signature.keyId << std::endl ;
return o ;
return o ;
}
std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterGenericDataItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " Key: " << destination_key.toStdString() << std::endl ;
o << " Data size: " << data_size << std::endl ;
o << "RsGRouterGenericDataItem:" << std::endl ;
o << " Direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " Routing ID: " << std::hex << routing_id << std::dec << "\"" << std::endl ;
o << " Key: " << destination_key.toStdString() << std::endl ;
o << " Data size: " << data_size << std::endl ;
o << " Data hash: " << RsDirUtil::sha1sum(data_bytes,data_size) << std::endl ;
o << " signature key: " << signature.keyId << std::endl;
o << " randomized dist:" << randomized_distance << std::endl;
o << " flags: " << flags << std::endl;
return o ;
return o ;
}
std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterRoutingInfoItem:" << std::endl ;
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
o << " origin: "<< origin.toStdString() << std::endl ;
o << " recv time: "<< received_time << std::endl ;
o << " Last sent: "<< last_sent << std::endl ;
o << " flags: "<< std::hex << status_flags << std::dec << std::endl ;
o << " Key: "<< data_item->destination_key.toStdString() << std::endl ;
o << " Data size: "<< data_item->data_size << std::endl ;
o << " Client id: "<< client_id << std::endl ;
o << " Tried friends: "<< tried_friends.size() << std::endl;
o << "RsGRouterRoutingInfoItem:" << std::endl ;
o << " direct origin: "<< PeerId() << std::endl ;
o << " data status: "<< std::hex<< data_status << std::dec << std::endl ;
o << " tunnel status: "<< tunnel_status << std::endl ;
o << " recv time: "<< received_time_TS << std::endl ;
o << " Last sent: "<< last_sent_TS << std::endl ;
o << " Sending attempts:"<< sending_attempts << std::endl ;
o << " destination key: "<< data_item->destination_key << std::endl ;
o << " Client id: "<< client_id << std::endl ;
o << " 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 ;
}
@ -632,6 +723,22 @@ std::ostream& RsGRouterMatrixCluesItem::print(std::ostream& o, uint16_t)
return o ;
}
std::ostream& RsGRouterTransactionChunkItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterTransactionChunkItem:" << std::endl ;
o << " total_size: " << total_size << std::endl;
o << " chunk_size: " << chunk_size << std::endl;
o << " chunk_start: " << chunk_start << std::endl;
return o ;
}
std::ostream& RsGRouterTransactionAcknItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterTransactionAcknItem:" << std::endl ;
o << " routing id: " << propagation_id << std::endl;
return o ;
}
std::ostream& RsGRouterMatrixFriendListItem::print(std::ostream& o, uint16_t)
{
o << "RsGRouterMatrixCluesItem:" << std::endl ;

View file

@ -26,23 +26,28 @@
#pragma once
#include "serialiser/rsserial.h"
#include "serialiser/rstlvkeys.h"
#include "serialiser/rsserviceids.h"
#include "retroshare/rstypes.h"
#include "retroshare/rsgrouter.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_ACK = 0x03 ; // acknowledgement of data received
const uint8_t RS_PKT_SUBTYPE_GROUTER_DATA = 0x05 ; // used to send data to a destination
const uint8_t RS_PKT_SUBTYPE_GROUTER_PUBLISH_KEY = 0x01 ; // used to publish a key
const uint8_t RS_PKT_SUBTYPE_GROUTER_ACK_deprecated = 0x03 ; // dont use!
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_MATRIX_CLUES = 0x80 ; // item to save matrix clues
const uint8_t RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST = 0x82 ; // item to save friend lists
const uint8_t RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO = 0x87 ; // item to save routing info
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 QOS_PRIORITY_RS_GROUTER_PUBLISH_KEY = 3 ; // slow items. No need to congest the network with this.
const uint8_t QOS_PRIORITY_RS_GROUTER_ACK = 3 ;
const uint8_t QOS_PRIORITY_RS_GROUTER_DATA = 3 ;
const uint8_t RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES = 0x80 ; // item to save matrix clues
const uint8_t RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST = 0x82 ; // item to save friend lists
const uint8_t RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO_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 = 3 ; // irrelevant since all items travel through tunnels
/***********************************************************************************/
@ -72,100 +77,116 @@ class RsGRouterNonCopyableObject
{
public:
RsGRouterNonCopyableObject() {}
private:
protected:
RsGRouterNonCopyableObject(const RsGRouterNonCopyableObject&) {}
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 */
/***********************************************************************************/
//class RsGRouterPublishKeyItem: public RsGRouterItem, public RsGRouterProofOfWorkObject
//{
// public:
// 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 ;
//
//};
// 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
// both signing and checking.
class RsGRouterGenericDataItem: public RsGRouterItem, public RsGRouterNonCopyableObject
class RsGRouterAbstractMsgItem: public RsGRouterItem
{
public:
RsGRouterGenericDataItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_DATA) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER_DATA) ; }
virtual ~RsGRouterGenericDataItem() { clear() ; }
public:
RsGRouterAbstractMsgItem(uint8_t pkt_subtype) : RsGRouterItem(pkt_subtype) {}
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
virtual uint32_t signed_data_size() const = 0 ;
virtual bool serialise_signed_data(void *data,uint32_t& size) const = 0 ;
virtual void clear()
{
free(data_bytes);
data_bytes=NULL;
}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ;
RsGRouterGenericDataItem *duplicate() const ;
// packet data
//
GRouterMsgPropagationId routing_id ;
GRouterKeyId destination_key ;
uint32_t randomized_distance ;
uint32_t data_size ;
uint8_t *data_bytes;
GRouterMsgPropagationId routing_id ;
GRouterKeyId destination_key ;
RsTlvKeySignature signature ; // signs mid+destination_key+state
uint32_t flags ; // packet was delivered, not delivered, bounced, etc
};
class RsGRouterACKItem: public RsGRouterItem
class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRouterNonCopyableObject
{
public:
RsGRouterACKItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_ACK) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER_ACK) ; }
public:
RsGRouterGenericDataItem() : RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_DATA) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; }
virtual ~RsGRouterGenericDataItem() { clear() ; }
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
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) ;
virtual void clear()
{
free(data_bytes);
data_bytes=NULL;
}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ;
// packet data
//
GRouterMsgPropagationId mid ; // message id to which this ack is a response
uint32_t state ; // packet was delivered, not delivered, bounced, etc
RsGRouterGenericDataItem *duplicate() const ;
// packet data
//
uint32_t data_size ;
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 RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem
{
public:
RsGRouterSignedReceiptItem() : RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT) { 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) ;
RsGRouterSignedReceiptItem *duplicate() const ;
// packet data
//
Sha1CheckSum data_hash ; // avoids an attacker to re-use a given signed receipt. This is the hash of the enceypted data.
// 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.
@ -192,7 +213,7 @@ class RsGRouterMatrixFriendListItem: public RsGRouterItem
{
public:
RsGRouterMatrixFriendListItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST)
{ setPriorityLevel(0) ; } // this item is never sent through the network
{ setPriorityLevel(0) ; } // this item is never sent through the network
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
@ -218,11 +239,12 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo,
virtual void clear()
{
if(data_item != NULL)
delete data_item ;
data_item = NULL ;
tried_friends.clear() ;
}
if(data_item != NULL) delete data_item ;
if(receipt_item != NULL) delete receipt_item ;
data_item = NULL ;
receipt_item = NULL ;
}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ;
};
@ -232,26 +254,27 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo,
class RsGRouterSerialiser: public RsSerialType
{
public:
RsGRouterSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GROUTER) {}
public:
RsGRouterSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GROUTER) {}
virtual uint32_t size (RsItem *item)
{
return dynamic_cast<RsGRouterItem *>(item)->serial_size() ;
}
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
{
return dynamic_cast<RsGRouterItem *>(item)->serialise(data,*size) ;
}
virtual RsItem *deserialise (void *data, uint32_t *size) ;
virtual uint32_t size (RsItem *item)
{
return dynamic_cast<RsGRouterItem *>(item)->serial_size() ;
}
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
{
return dynamic_cast<RsGRouterItem *>(item)->serialise(data,*size) ;
}
virtual RsItem *deserialise (void *data, uint32_t *size) ;
private:
//RsGRouterPublishKeyItem *deserialise_RsGRouterPublishKeyItem(void *data,uint32_t size) const ;
RsGRouterGenericDataItem *deserialise_RsGRouterGenericDataItem(void *data,uint32_t size) const ;
RsGRouterACKItem *deserialise_RsGRouterACKItem(void *data,uint32_t size) const ;
RsGRouterMatrixCluesItem *deserialise_RsGRouterMatrixCluesItem(void *data,uint32_t size) const ;
RsGRouterMatrixFriendListItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ;
RsGRouterRoutingInfoItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ;
private:
RsGRouterGenericDataItem *deserialise_RsGRouterGenericDataItem(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 ;
RsGRouterMatrixFriendListItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ;
RsGRouterRoutingInfoItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ;
};

View file

@ -29,43 +29,42 @@
#include <time.h>
#include <list>
#include "pgp/rscertificate.h"
#include "turtle/p3turtle.h"
#include "retroshare/rsgrouter.h"
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_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_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_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_GXS_PACKET = 0.1f ; // base contribution of GXS message 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 time_t RS_GROUTER_DEBUG_OUTPUT_PERIOD = 10 ; // Output everything
static const time_t RS_GROUTER_AUTOWASH_PERIOD = 10 ; // Autowash every minute. Not a costly operation.
static const time_t RS_GROUTER_MATRIX_UPDATE_PERIOD = 1 *10 ; // Check for key advertising every 10 minutes
static const time_t RS_GROUTER_ROUTING_WAITING_TIME = 2 *60 ; // time between two trial of sending a given message
//atic const time_t RS_GROUTER_ROUTING_WAITING_TIME = 3600 ; // time between two trial of sending a given message
static const time_t RS_GROUTER_MEAN_EXPECTED_RTT = 30 ; // reference RTT time for a message.
static const time_t RS_GROUTER_DEBUG_OUTPUT_PERIOD = 10 ; // Output everything
static const time_t RS_GROUTER_AUTOWASH_PERIOD = 10 ; // Autowash every minute. Not a costly operation.
static const time_t RS_GROUTER_MATRIX_UPDATE_PERIOD = 1 *10 ; // Check for key advertising every 10 minutes
static const time_t RS_GROUTER_ROUTING_WAITING_TIME = 2 *60 ; // time between two trial of sending a given message
//atic const time_t RS_GROUTER_ROUTING_WAITING_TIME = 3600 ; // time between two trial of sending a given message
static const time_t RS_GROUTER_MEAN_EXPECTED_RTT = 30 ; // reference RTT time for a message.
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_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 RS_GROUTER_ROUTING_STATE_UNKN = 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_ROUTING_STATE_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_ROUTING_STATE_DEAD = 0x0004 ; // item is at a dead end.
static const uint32_t RS_GROUTER_DATA_STATUS_UNKNOWN = 0x0000 ; // unknown. Unused.
static const uint32_t RS_GROUTER_DATA_STATUS_PENDING = 0x0001 ; // item is pending. Should be sent asap.
static const uint32_t RS_GROUTER_DATA_STATUS_SENT = 0x0002 ; // item is sent. Waiting for answer
static const uint32_t RS_GROUTER_DATA_STATUS_RECEIPT_OK = 0x0003 ; // item is at destination.
static const uint32_t RS_GROUTER_ACK_STATE_UNKN = 0x0000 ; // unknown destination key
static const uint32_t RS_GROUTER_ACK_STATE_RCVD = 0x0001 ; // data was received, directly
static const uint32_t RS_GROUTER_ACK_STATE_IRCV = 0x0002 ; // data was received indirectly
static const uint32_t RS_GROUTER_ACK_STATE_GVNP = 0x0003 ; // data was given up. No route.
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)
static const uint32_t RS_GROUTER_TUNNEL_STATUS_UNMANAGED = 0x0000 ; // no tunnel requested atm
static const uint32_t RS_GROUTER_TUNNEL_STATUS_PENDING = 0x0001 ; // tunnel requested to turtle
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_TUNNEL_STATUS_CAN_SEND = 0x0003 ; // tunnel is ready and data can be sent
class FriendTrialRecord
{
@ -81,16 +80,26 @@ class FriendTrialRecord
class GRouterRoutingInfo
{
public:
uint32_t status_flags ; // pending, waiting, etc.
RsPeerId origin ; // which friend sent us that item
time_t received_time ; // time at which the item was originally received
time_t last_sent ; // last time the item was sent to friends
// There's no destructor to this class, because the memory is managed elsewhere, which
// ovoids lots of duplications if the class is copied.
public:
GRouterRoutingInfo()
{
data_item = NULL ;
receipt_item = NULL ;
}
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
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
RsGRouterGenericDataItem *data_item ;
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 ;
RsGRouterSignedReceiptItem *receipt_item ;
};

File diff suppressed because it is too large Load diff

View file

@ -31,227 +31,289 @@
#include "retroshare/rsgrouter.h"
#include "retroshare/rstypes.h"
#include "retroshare/rstypes.h"
#include "turtle/turtleclientservice.h"
#include "services/p3service.h"
#include "pqi/p3cfgmgr.h"
#include "groutertypes.h"
#include "groutermatrix.h"
#include "grouteritems.h"
//#include "groutercache.h"
// To be put in pqi/p3cfgmgr.h
//
static const uint32_t CONFIG_TYPE_GROUTER = 0x0016 ;
static const uint32_t RS_GROUTER_DATA_FLAGS_ENCRYPTED = 0x0001 ;
class p3LinkMgr ;
class RsGRouterPublishKeyItem ;
class RsGRouterACKItem ;
class p3turtle ;
class p3IdService ;
class RsGRouterItem ;
class RsGRouterGenericDataItem ;
class RsGRouterTransactionChunkItem ;
class RsGRouterSignedReceiptItem ;
class RsGRouterAbstractMsgItem ;
class p3GRouter: public RsGRouter, public p3Service, public p3Config
// 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:
p3GRouter(p3ServiceControl *sc,p3LinkMgr *lm) ;
public:
GRouterTunnelInfo() :first_tunnel_ok_TS(0), last_tunnel_ok_TS(0) {}
//===================================================//
// Router clients business //
//===================================================//
// These two methods handle the memory management of buffers for each virtual peers.
// This method allows to associate client ids (that are saved to disk) to client objects deriving
// from GRouterClientService. The various services are responsible for regstering themselves to the
// global router, with consistent ids. The services are stored in a map, and arriving objects are
// passed on the correct service depending on the client id of the key they are reaching.
//
virtual bool registerClientService(const GRouterServiceId& id,GRouterClientService *service) ;
void addVirtualPeer(const TurtleVirtualPeerId& vpid) ;
void removeVirtualPeer(const TurtleVirtualPeerId& vpid) ;
// Use this method to register/unregister a key that the global router will
// forward in the network, so that is can be a possible destination for
// global messages.
//
// key : The key that is published
// fingerp : Fingerprint of the key to encrypt the data.
// 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.
// To obtain a client id, the service must register using the previous method.
//
// Unregistering a key might not have an instantaneous effect, so the client is responsible for
// 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 unregisterKey(const GRouterKeyId& key) ;
RsGRouterAbstractMsgItem *addDataChunk(const TurtleVirtualPeerId& vpid,RsGRouterTransactionChunkItem *chunk_item) ;
//===================================================//
// Routing clue collection methods //
//===================================================//
std::map<TurtleVirtualPeerId, RsGRouterTransactionChunkItem*> virtual_peers ;
virtual void addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id) ;
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) ;
//===================================================//
// Client/server request services //
//===================================================//
//===================================================//
// Router clients business //
//===================================================//
// Sends an item to the given destination. The router takes ownership of
// 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.
// The client id is supplied so that the client can be notified when the data has been received.
//
virtual void sendData(const GRouterKeyId& destination,const GRouterServiceId& client_id, RsGRouterGenericDataItem *item,GRouterMsgPropagationId& id) ;
// This method allows to associate client ids (that are saved to disk) to client objects deriving
// from GRouterClientService. The various services are responsible for regstering themselves to the
// global router, with consistent ids. The services are stored in a map, and arriving objects are
// passed on the correct service depending on the client id of the key they are reaching.
//
virtual bool registerClientService(const GRouterServiceId& id,GRouterClientService *service) ;
// Sends an ACK to the origin of the msg. This is used to notify for
// unfound route, or message correctly received, depending on the particular situation.
//
virtual void sendACK(const RsPeerId& peer,GRouterMsgPropagationId mid, uint32_t flags) ;
// Use this method to register/unregister a key that the global router will
// forward in the network, so that is can be a possible destination for
// global messages.
//
// auth_id : The GXS key that will be used to sign the data Receipts.
// contact_key : The key that is used to open tunnels
// 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.
// 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
// discarding traffic that might later come for this key.
//
virtual bool registerKey(const RsGxsId& authentication_id, const GRouterServiceId& client_id,const std::string& description_string) ;
virtual bool unregisterKey(const RsGxsId &key_id, const GRouterServiceId &sid) ;
//===================================================//
// Interface with RsGRouter //
//===================================================//
//===================================================//
// Routing clue collection methods //
//===================================================//
// debug info from routing matrix
// - list of known key ids
// - list of clues/time_stamp for each key.
// - real time routing probabilities
//
virtual bool getRoutingMatrixInfo(GRouterRoutingMatrixInfo& info) ;
virtual void addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id) ;
// debug info from routing cache
// - Cache Items
// * which message ids
// * directions
// * timestamp
// * message type
// - Cache state (memory size, etc)
//
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& info) ;
//===================================================//
// Client/server request services //
//===================================================//
//===================================================//
// Derived from p3Service //
//===================================================//
// Sends an item to the given destination. The router takes ownership of
// 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.
// 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 bool sendData(const RsGxsId& destination, const GRouterServiceId& client_id, const uint8_t *data, uint32_t data_size, const RsGxsId& signing_id, GRouterMsgPropagationId& id) ;
virtual RsServiceInfo getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_GROUTER,
SERVICE_INFO_APP_NAME,
SERVICE_INFO_APP_MAJOR_VERSION,
SERVICE_INFO_APP_MINOR_VERSION,
SERVICE_INFO_MIN_MAJOR_VERSION,
SERVICE_INFO_MIN_MINOR_VERSION) ;
}
// Cancels a given sending order. If called too late, the message might already have left. But this will remove the item from the
// re-try list.
virtual bool cancel(GRouterMsgPropagationId mid) ;
virtual void setDebugEnabled(bool b) { _debug_enabled = b ; }
protected:
//===================================================//
// Routing method handling //
//===================================================//
//===================================================//
// Interface with RsGRouter //
//===================================================//
// Calls
// - autoWash()
// - packet handling methods
// - matrix updates
//
virtual int tick() ;
// debug info from routing matrix
// - list of known key ids
// - list of clues/time_stamp for each key.
// - real time routing probabilities
//
virtual bool getRoutingMatrixInfo(GRouterRoutingMatrixInfo& info) ;
static const std::string SERVICE_INFO_APP_NAME ;
static const uint16_t SERVICE_INFO_APP_MAJOR_VERSION = 1;
static const uint16_t SERVICE_INFO_APP_MINOR_VERSION = 0;
static const uint16_t SERVICE_INFO_MIN_MAJOR_VERSION = 1;
static const uint16_t SERVICE_INFO_MIN_MINOR_VERSION = 0;
// debug info from routing cache
// - Cache Items
// * which message ids
// * directions
// * timestamp
// * message type
// - Cache state (memory size, etc)
//
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& info) ;
private:
class nullstream: public std::ostream {};
//===================================================//
// Derived from p3Service //
//===================================================//
std::ostream& grouter_debug() const
{
static nullstream null ;
virtual RsServiceInfo getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_GROUTER,
SERVICE_INFO_APP_NAME,
SERVICE_INFO_APP_MAJOR_VERSION,
SERVICE_INFO_APP_MINOR_VERSION,
SERVICE_INFO_MIN_MAJOR_VERSION,
SERVICE_INFO_MIN_MINOR_VERSION) ;
}
return _debug_enabled?(std::cerr):null;
}
virtual void setDebugEnabled(bool b) { _debug_enabled = b ; }
void autoWash() ;
void routePendingObjects() ;
void handleIncoming() ;
void debugDump() ;
virtual void connectToTurtleRouter(p3turtle *pt) ;
// 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 time_t computeNextTimeDelay(time_t duration) ;
protected:
//===================================================//
// Routing method handling //
//===================================================//
void locked_notifyClientAcknowledged(const GRouterMsgPropagationId& msg_id,const GRouterServiceId& service_id) const ;
// Calls
// - packet handling methods
// - matrix updates
//
virtual int tick() ;
uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ;
static const std::string SERVICE_INFO_APP_NAME ;
static const uint16_t SERVICE_INFO_APP_MAJOR_VERSION = 1;
static const uint16_t SERVICE_INFO_APP_MINOR_VERSION = 0;
static const uint16_t SERVICE_INFO_MIN_MAJOR_VERSION = 1;
static const uint16_t SERVICE_INFO_MIN_MINOR_VERSION = 0;
//===================================================//
// p3Config methods //
//===================================================//
//===================================================//
// Interaction with turtle router //
//===================================================//
// Load/save the routing info, the pending items in transit, and the config variables.
//
virtual bool loadList(std::list<RsItem*>& items) ;
virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ;
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) ;
virtual RsSerialiser *setupSerialiser() ;
private:
class nullstream: public std::ostream {};
//===================================================//
// Debug methods //
//===================================================//
std::ostream& grouter_debug() const
{
static nullstream null ;
// Prints the internal state of the router, for debug purpose.
//
void debug_dump() ;
return _debug_enabled?(std::cerr):null;
}
// Stores the routing info
// - list of known key ids
// - list of clues/time_stamp for each key.
// - real time routing probabilities
//
GRouterMatrix _routing_matrix ;
void routePendingObjects() ;
void handleTunnels() ;
// 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
void handleIncoming(const TurtleFileHash &hash, RsGRouterAbstractMsgItem *) ;
void handleIncomingReceiptItem(const TurtleFileHash &hash, RsGRouterSignedReceiptItem *receipt_item) ;
void handleIncomingDataItem(const TurtleFileHash &hash, RsGRouterGenericDataItem *data_item) ;
// Stores the keys which identify the router's node. For each key, a structure holds:
// - the client service
// - flags
// - usage time stamps
//
std::map<GRouterKeyId, GRouterPublishedKeyInfo> _owned_key_ids ;
bool locked_getClientAndServiceId(const TurtleFileHash& hash, const RsGxsId& destination_key, GRouterClientService *& client, GRouterServiceId& service_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
// the software, when newly created services register themselves.
std::map<GRouterServiceId,GRouterClientService *> _registered_services ;
// utility functions
//
static float computeMatrixContribution(float base,uint32_t time_shift,float probability) ;
static time_t computeNextTimeDelay(time_t duration) ;
// Data handling ethods
//
void handleRecvDataItem(RsGRouterGenericDataItem *item);
void handleRecvACKItem(RsGRouterACKItem *item);
uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ;
// Pointers to other RS objects
//
p3ServiceControl *mServiceControl ;
p3LinkMgr *mLinkMgr ;
// 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) ;
// Multi-thread protection mutex.
//
RsMutex grMtx ;
static Sha1CheckSum makeTunnelHash(const RsGxsId& destination,const GRouterServiceId& client);
static void makeGxsIdAndClientId(const TurtleFileHash &sum,RsGxsId& gxs_id,GRouterServiceId& client_id);
// config update/save variables
bool _changed ;
bool _debug_enabled ;
bool sendDataInTunnel(const TurtleVirtualPeerId& vpid,RsGRouterAbstractMsgItem *item);
time_t _last_autowash_time ;
time_t _last_matrix_update_time ;
time_t _last_debug_output_time ;
time_t _last_config_changed ;
//===================================================//
// p3Config methods //
//===================================================//
uint64_t _random_salt ;
// Load/save the routing info, the pending items in transit, and the config variables.
//
virtual bool loadList(std::list<RsItem*>& items) ;
virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ;
virtual RsSerialiser *setupSerialiser() ;
//===================================================//
// Debug methods //
//===================================================//
// Prints the internal state of the router, for debug purpose.
//
void debugDump() ;
//===================================================//
// Internal queues/variables //
//===================================================//
// Stores the routing info
// - list of known key ids
// - list of clues/time_stamp for each key.
// - real time routing probabilities
//
GRouterMatrix _routing_matrix ;
// Stores the keys which identify the router's node. For each key, a structure holds:
// - the client service
// - flags
// - usage time stamps
//
std::map<Sha1CheckSum, GRouterPublishedKeyInfo> _owned_key_ids ;
// 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
// the software, when newly created services register themselves.
std::map<GRouterServiceId,GRouterClientService *> _registered_services ;
// 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
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
//
p3ServiceControl *mServiceControl ;
p3turtle *mTurtle ;
p3IdService *mIdService ;
// Multi-thread protection mutex.
//
RsMutex grMtx ;
// config update/save variables
bool _changed ;
bool _debug_enabled ;
time_t _last_autowash_time ;
time_t _last_matrix_update_time ;
time_t _last_debug_output_time ;
time_t _last_config_changed ;
uint64_t _random_salt ;
};
template<typename T> p3GRouter::nullstream& operator<<(p3GRouter::nullstream& ns,const T&) { return ns ; }