Added connexion to the msg system and fingerprint into grouter addresses. flushing current changes before 0.6 merge.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7072 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-01-30 22:14:37 +00:00
parent 1aa2e221d2
commit e12929d9d7
8 changed files with 90 additions and 19 deletions

View File

@ -187,7 +187,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterPublishKeyItem(void *da
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 &= getRawPGPFingerprint(data,pktsize,&offset,&item->fingerprint) ;
ok &= getRawPGPFingerprint(data,pktsize,&offset,item->fingerprint) ;
if (offset != rssize || !ok)
{

View File

@ -36,6 +36,8 @@ typedef uint32_t GRouterServiceId ;
typedef uint32_t GRouterKeyPropagationId ;
typedef uint32_t GRouterMsgPropagationId ;
static const uint32_t GROUTER_CLIENT_ID_MESSAGES = 0x1001 ;
static const uint32_t RS_GROUTER_MATRIX_MAX_HIT_ENTRIES = 5;
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
@ -59,6 +61,7 @@ class GRouterPublishedKeyInfo
public:
GRouterServiceId service_id ;
std::string description_string ;
PGPFingerprintType fpr ;
time_t last_published_time ;
time_t validity_time ;
};

View File

@ -38,15 +38,6 @@ p3GRouter::p3GRouter(p3LinkMgr *lm)
addSerialType(new RsGRouterSerialiser()) ;
_changed = false ;
// Debug stuff. Create a random key and register it.
uint8_t random_hash_buff[20] ;
RSRandom::random_bytes(random_hash_buff,20) ;
GRouterKeyId key(random_hash_buff) ;
static GRouterServiceId client_id = 0x0300ae15 ;
static std::string description = "Test string for debug purpose" ;
registerKey(key,client_id,description) ;
}
int p3GRouter::tick()
@ -320,12 +311,14 @@ void p3GRouter::publishKeys()
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
std::cerr << " Service id : " << std::hex << info.service_id << std::dec << std::endl;
std::cerr << " Description : " << info.description_string << std::endl;
std::cerr << " Fingerprint : " << info.fpr.toStdString() << std::endl;
RsGRouterPublishKeyItem item ;
item.diffusion_id = RSRandom::random_u32() ;
item.published_key = it->first ;
item.service_id = info.service_id ;
item.randomized_distance = drand48() ;
item.fingerprint = info.fpr;
item.description_string = info.description_string ;
item.PeerId("") ; // no peer id => key is forwarded to all friends.
@ -361,13 +354,14 @@ void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
else
std::cerr << " Not forwarding to source id " << item.PeerId() << std::endl;
}
bool p3GRouter::registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description)
bool p3GRouter::registerKey(const GRouterKeyId& key,const PGPFingerprintType& fps,const GRouterServiceId& client_id,const std::string& description)
{
RsStackMutex mtx(grMtx) ;
GRouterPublishedKeyInfo info ;
info.service_id = client_id ;
info.description_string = description;
info.fpr = fps ;
info.description_string = description.substr(0,20);
info.validity_time = 0 ; // not used yet.
info.last_published_time = 0 ; // means never published, se it will be re-published soon.
@ -376,7 +370,7 @@ bool p3GRouter::registerKey(const GRouterKeyId& key,const GRouterServiceId& clie
std::cerr << "Registered the following key: " << std::endl;
std::cerr << " Key id : " << key.toStdString() << std::endl;
std::cerr << " Client id : " << std::hex << client_id << std::dec << std::endl;
std::cerr << " Description : " << description << std::endl;
std::cerr << " Description : " << info.description_string << std::endl;
return true ;
}

View File

@ -66,14 +66,18 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// forward in the network, so that is can be a possible destination for
// global messages.
//
// key : the key that is published
// 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.
//
bool registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description_string) ;
bool registerKey(const GRouterKeyId& key,const PGPFingerprintType& pgp_fingerprint,
const GRouterServiceId& client_id,const std::string& description_string) ;
bool unregisterKey(const GRouterKeyId& key) ;
//===================================================//

View File

@ -72,7 +72,7 @@ class RsGRouter
//===================================================//
virtual void sendData(const GRouterKeyId& destination, RsGRouterGenericDataItem *item) =0;
virtual bool registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description_string) =0;
virtual bool registerKey(const GRouterKeyId& key,const PGPFingerprintType& fps,const GRouterServiceId& client_id,const std::string& description_string) =0;
};

View File

@ -288,6 +288,38 @@ bool setRawSSLId(void *data,uint32_t size,uint32_t *offset,const SSLIdType& cs)
return true ;
}
bool getRawPGPFingerprint(void *data,uint32_t size,uint32_t *offset,PGPFingerprintType& cs)
{
uint32_t len = 20 ; // SSL id type
/* check there is space for string */
if (size < *offset + len)
{
std::cerr << "getRawPGPFingerprint() not enough size" << std::endl;
return false;
}
bool ok = true ;
cs = PGPFingerprintType(&((uint8_t*)data)[*offset]) ;
*offset += 20 ;
return ok ;
}
bool setRawPGPFingerprint(void *data,uint32_t size,uint32_t *offset,const PGPFingerprintType& cs)
{
uint32_t len = 20 ; // SHA1 length in bytes
if (size < *offset + len)
{
std::cerr << "setRawPGPFingerprint() Not enough size" << std::endl;
return false;
}
memcpy((void *) &(((uint8_t *) data)[*offset]), cs.toByteArray(), 20);
*offset += 20 ;
return true ;
}
bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr)
{
uint32_t len = 0;

View File

@ -74,6 +74,9 @@ bool setRawSha1(void *data, uint32_t size, uint32_t *offset, const Sha1CheckSum&
bool setRawSSLId(void *data, uint32_t size, uint32_t *offset, const SSLIdType& inStr);
bool getRawSSLId(void *data, uint32_t size, uint32_t *offset, SSLIdType& outStr);
bool setRawPGPFingerprint(void *data, uint32_t size, uint32_t *offset, const PGPFingerprintType& inStr);
bool getRawPGPFingerprint(void *data, uint32_t size, uint32_t *offset, PGPFingerprintType& outStr);
bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const time_t& inStr);
bool getRawTimeT(void *data, uint32_t size, uint32_t *offset, time_t& outStr);

View File

@ -37,6 +37,10 @@
#include "pqi/p3cfgmgr.h"
#include "rsserver/p3face.h"
#include "serialiser/rsconfigitems.h"
#ifdef GROUTER
#include "grouter/p3grouter.h"
#include "grouter/groutertypes.h"
#endif
#include "util/rsdebug.h"
#include "util/rsdir.h"
@ -83,6 +87,25 @@ p3MsgService::p3MsgService(p3LinkMgr *lm)
/* Initialize standard tag types */
if(lm)
initStandardTagTypes();
#ifdef GROUTER
// Debug stuff. Create a random key and register it.
std::string own_ssl_id = rsPeers->getOwnId() ;
std::string gpg_id = rsPeers->getGPGOwnId() ;
RsPeerDetails d;
rsPeers->getPeerDetails(gpg_id,d) ;
PGPFingerprintType fingerp( d.fpr ) ;
// Re-hash the SSL id, to make it one way. Will be replaced by proper invitations in the future.
//
GRouterKeyId key ( RsDirUtil::sha1sum( (uint8_t*)own_ssl_id.c_str(),own_ssl_id.length() ).toStdString() ) ;
static GRouterServiceId client_id = GROUTER_CLIENT_ID_MESSAGES;
static std::string description = "Test string for debug purpose" ;
mGRouter->registerKey(key,fingerp,client_id,description) ;
#endif
}
uint32_t p3MsgService::getNewUniqueMsgId()
@ -2123,10 +2146,22 @@ void p3MsgService::enableDistantMessaging(bool b)
#ifdef GROUTER
std::cerr << "Notifying the global router." << std::endl;
std::string pname = rsPeers->getPeerName(mLinkMgr->getOwnId()) ;
Sha1CheckSum grouter_hash = RsDirUtil::sha1sum((uint8_t*)mLinkMgr->getOwnId().c_str(),16);
// Debug stuff. Create a random key and register it.
std::string own_ssl_id = rsPeers->getOwnId() ;
std::string gpg_id = rsPeers->getGPGOwnId() ;
mGRouter->registerKey(grouter_hash, RS_SERVICE_TYPE_MSG, std::string("Contact address for ")+pname) ;
RsPeerDetails d;
rsPeers->getPeerDetails(gpg_id,d) ;
PGPFingerprintType fingerp( d.fpr ) ;
// Re-hash the SSL id, to make it one way. Will be replaced by proper invitations in the future.
//
GRouterKeyId key ( RsDirUtil::sha1sum( (uint8_t*)own_ssl_id.c_str(),own_ssl_id.length() ).toStdString() ) ;
static GRouterServiceId client_id = GROUTER_CLIENT_ID_MESSAGES;
static std::string description = "Test string for debug purpose" ;
mGRouter->registerKey(key,fingerp,client_id,description) ;
#endif
cchanged = true ;
}