mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-12 00:00:44 -04:00
Squeleton code for the global routing matrix. Most functions are left unimplemented, but
the basic structure is here. Functions have been added to serialise both SHA1 and floats. The router is not yet enabled since protocol is likely to change again. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6886 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
261d9102d4
commit
e0863194a3
18 changed files with 1241 additions and 4 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <stdlib.h> /* Included because GCC4.4 wants it */
|
||||
#include <string.h> /* Included because GCC4.4 wants it */
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
|
@ -186,7 +187,75 @@ bool setRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t in)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool getRawUFloat32(void *data,uint32_t size,uint32_t *offset,float& f)
|
||||
{
|
||||
uint32_t n ;
|
||||
if(!getRawUInt32(data, size, offset, &n) )
|
||||
return false ;
|
||||
|
||||
f = 1.0f/ ( n/(float)(~(uint32_t)0)) - 1.0f ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool setRawUFloat32(void *data,uint32_t size,uint32_t *offset,float f)
|
||||
{
|
||||
if(f < 0.0f)
|
||||
{
|
||||
std::cerr << "(EE) Cannot serialise invalid negative float value " << f << " in " << __PRETTY_FUNCTION__ << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// This serialisation is quite accurate. The max relative error is approx.
|
||||
// 0.01% and most of the time less than 1e-05% The error is well distributed
|
||||
// over numbers also.
|
||||
//
|
||||
uint32_t n = (uint32_t)( (1.0f/(1.0f+f) * (~(uint32_t)0))) ;
|
||||
|
||||
return setRawUInt32(data, size, offset, n);
|
||||
}
|
||||
|
||||
bool getRawSha1(void *data,uint32_t size,uint32_t *offset,Sha1CheckSum& cs)
|
||||
{
|
||||
uint32_t len = 20 ; // SHA1 length in bytes
|
||||
|
||||
/* check there is space for string */
|
||||
if (size < *offset + len)
|
||||
{
|
||||
std::cerr << "getRawSha1() not enough size" << std::endl;
|
||||
return false;
|
||||
}
|
||||
bool ok = true ;
|
||||
|
||||
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[0]) ;
|
||||
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[1]) ;
|
||||
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[2]) ;
|
||||
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[3]) ;
|
||||
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[4]) ;
|
||||
|
||||
return ok ;
|
||||
}
|
||||
|
||||
bool setRawSha1(void *data,uint32_t size,uint32_t *offset,const Sha1CheckSum& cs)
|
||||
{
|
||||
uint32_t len = 20 ; // SHA1 length in bytes
|
||||
|
||||
if (size < *offset + len)
|
||||
{
|
||||
std::cerr << "setRawSha1() Not enough size" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = true ;
|
||||
/* pack it in */
|
||||
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[0]);
|
||||
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[1]);
|
||||
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[2]);
|
||||
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[3]);
|
||||
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[4]);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
*
|
||||
******************************************************************/
|
||||
|
||||
class Sha1CheckSum ;
|
||||
|
||||
bool getRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t *out);
|
||||
bool setRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t in);
|
||||
|
@ -60,8 +61,14 @@ bool setRawUInt32(void *data, uint32_t size, uint32_t *offset, uint32_t in);
|
|||
bool getRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t *out);
|
||||
bool setRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t in);
|
||||
|
||||
bool getRawUFloat32(void *data, uint32_t size, uint32_t *offset, float& out);
|
||||
bool setRawUFloat32(void *data, uint32_t size, uint32_t *offset, float in);
|
||||
|
||||
bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr);
|
||||
bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string &inStr);
|
||||
|
||||
bool getRawSha1(void *data, uint32_t size, uint32_t *offset, Sha1CheckSum& outStr);
|
||||
bool setRawSha1(void *data, uint32_t size, uint32_t *offset, const Sha1CheckSum& inStr);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ void RsItem::print_string(std::string &out, uint16_t indent)
|
|||
|
||||
out += stream.str();
|
||||
}
|
||||
uint32_t RsItem::PacketId()
|
||||
uint32_t RsItem::PacketId() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ RsItem * RsSerialType::deserialise(void */*data*/, uint32_t */*size*/)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t RsSerialType::PacketId()
|
||||
uint32_t RsSerialType::PacketId() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ class RsItem: public RsMemoryManagement::SmallObject
|
|||
void PeerId(const std::string& id) { peerId = id; }
|
||||
|
||||
/* complete id */
|
||||
uint32_t PacketId();
|
||||
uint32_t PacketId() const;
|
||||
|
||||
/* id parts */
|
||||
uint8_t PacketVersion();
|
||||
|
@ -122,7 +122,7 @@ virtual uint32_t size(RsItem *);
|
|||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
uint32_t PacketId();
|
||||
uint32_t PacketId() const;
|
||||
private:
|
||||
uint32_t type;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue