mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 22:52:54 -04:00
merged remaining of v0.6-IdCleaning branch (7180->7213) to incorporate global router stuff in trunk
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7214 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0e6302ac6a
commit
1042744685
53 changed files with 2387 additions and 1904 deletions
|
@ -1006,7 +1006,8 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool fileExists = RsDirUtil::checkFile(filename);
|
uint64_t tmp_size ;
|
||||||
|
bool fileExists = RsDirUtil::checkFile(filename,tmp_size);
|
||||||
if (fileExists)
|
if (fileExists)
|
||||||
{
|
{
|
||||||
#ifdef CS_DEBUG
|
#ifdef CS_DEBUG
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "rsserver/p3face.h"
|
#include "rsserver/p3face.h"
|
||||||
#include "dbase/fimonitor.h"
|
#include "dbase/fimonitor.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
#include "pqi/authssl.h"
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
#include "retroshare/rsiface.h"
|
#include "retroshare/rsiface.h"
|
||||||
#include "pqi/p3notify.h"
|
#include "pqi/p3notify.h"
|
||||||
|
@ -47,16 +48,17 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
//***********
|
// ***********
|
||||||
//#define FIM_DEBUG 1
|
// #define FIM_DEBUG 1
|
||||||
// ***********/
|
// ***********/
|
||||||
|
|
||||||
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const RsPeerId& pid,const std::string& config_dir)
|
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, const RsPeerId& pid,const std::string& config_dir)
|
||||||
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid),
|
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid),
|
||||||
pendingDirs(false), pendingForceCacheWrite(false),
|
pendingDirs(false), pendingForceCacheWrite(false),
|
||||||
mForceCheck(false), mInCheck(false), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true)
|
mForceCheck(false), mInCheck(false), hashCache(config_dir+"/" + "file_cache"),useHashCache(true)
|
||||||
|
|
||||||
{
|
{
|
||||||
updatePeriod = 15 * 60; // 15 minutes
|
updatePeriod = 15 * 60; // 15 minutes
|
||||||
|
@ -114,7 +116,63 @@ HashCache::HashCache(const std::string& path)
|
||||||
_max_cache_duration_days = 10 ; // 10 days is the default value.
|
_max_cache_duration_days = 10 ; // 10 days is the default value.
|
||||||
_files.clear() ;
|
_files.clear() ;
|
||||||
_changed = false ;
|
_changed = false ;
|
||||||
std::ifstream f(_path.c_str()) ;
|
|
||||||
|
// check for unencrypted
|
||||||
|
|
||||||
|
std::istream *f = NULL ;
|
||||||
|
uint64_t file_size ;
|
||||||
|
|
||||||
|
if(RsDirUtil::checkFile( _path+".bin",file_size,false ) )
|
||||||
|
{
|
||||||
|
std::cerr << "Encrypted hash cache file present. Reading it." << std::endl;
|
||||||
|
|
||||||
|
// read the binary stream into memory.
|
||||||
|
//
|
||||||
|
void *buffer = malloc(file_size) ;
|
||||||
|
|
||||||
|
if(buffer == NULL)
|
||||||
|
{
|
||||||
|
std::cerr << "Cannot allocate memory for reading encrypted file cache, bytes=" << file_size << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
FILE *F = fopen( (_path+".bin").c_str(),"rb") ;
|
||||||
|
|
||||||
|
if(fread(buffer,1,file_size,F) != file_size)
|
||||||
|
{
|
||||||
|
std::cerr << "Cannot read from file " + _path+".bin" << ": something's wrong." << std::endl;
|
||||||
|
free(buffer) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
fclose(F) ;
|
||||||
|
|
||||||
|
void *decrypted_data ;
|
||||||
|
int decrypted_data_size ;
|
||||||
|
|
||||||
|
if(!AuthSSL::getAuthSSL()->decrypt(decrypted_data, decrypted_data_size, buffer, file_size))
|
||||||
|
{
|
||||||
|
std::cerr << "Cannot decrypt encrypted file cache. Something's wrong." << std::endl;
|
||||||
|
free(buffer) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
free(buffer) ;
|
||||||
|
|
||||||
|
std::string s((char *)decrypted_data,decrypted_data_size) ;
|
||||||
|
f = new std::istringstream(s) ;
|
||||||
|
|
||||||
|
free(decrypted_data) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Encrypted file cache not present. Trying unencrypted..." << std::endl;
|
||||||
|
|
||||||
|
f = new std::ifstream( (_path+".lst").c_str()) ;
|
||||||
|
|
||||||
|
if(!f->good())
|
||||||
|
{
|
||||||
|
std::cerr << "Unencrypted file cache not present either." << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::streamsize max_line_size = 2000 ; // should be enough. Anyway, if we
|
std::streamsize max_line_size = 2000 ; // should be enough. Anyway, if we
|
||||||
// miss one entry, we just lose some
|
// miss one entry, we just lose some
|
||||||
|
@ -127,21 +185,21 @@ HashCache::HashCache(const std::string& path)
|
||||||
int n=0 ;
|
int n=0 ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(!f.eof())
|
while(!f->eof())
|
||||||
{
|
{
|
||||||
HashCacheInfo info ;
|
HashCacheInfo info ;
|
||||||
|
|
||||||
f.getline(buff,max_line_size,'\n') ;
|
f->getline(buff,max_line_size,'\n') ;
|
||||||
std::string name(buff) ;
|
std::string name(buff) ;
|
||||||
|
|
||||||
f.getline(buff,max_line_size,'\n') ; //if(sscanf(buff,"%llu",&info.size) != 1) break ;
|
f->getline(buff,max_line_size,'\n') ; //if(sscanf(buff,"%llu",&info.size) != 1) break ;
|
||||||
|
|
||||||
info.size = 0 ;
|
info.size = 0 ;
|
||||||
sscanf(buff, RsDirUtil::scanf_string_for_uint(sizeof(info.size)), &info.size);
|
sscanf(buff, RsDirUtil::scanf_string_for_uint(sizeof(info.size)), &info.size);
|
||||||
|
|
||||||
f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.time_stamp)),&info.time_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; }
|
f->getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.time_stamp)),&info.time_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; }
|
||||||
f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.modf_stamp)),&info.modf_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; }
|
f->getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.modf_stamp)),&info.modf_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; }
|
||||||
f.getline(buff,max_line_size,'\n') ; info.hash = std::string(buff) ;
|
f->getline(buff,max_line_size,'\n') ; info.hash = std::string(buff) ;
|
||||||
|
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << " (" << name << ", " << info.size << ", " << info.time_stamp << ", " << info.modf_stamp << ", " << info.hash << std::endl ;
|
std::cerr << " (" << name << ", " << info.size << ", " << info.time_stamp << ", " << info.modf_stamp << ", " << info.hash << std::endl ;
|
||||||
|
@ -149,9 +207,9 @@ HashCache::HashCache(const std::string& path)
|
||||||
#endif
|
#endif
|
||||||
_files[name] = info ;
|
_files[name] = info ;
|
||||||
}
|
}
|
||||||
f.close() ;
|
|
||||||
|
|
||||||
delete[] buff ;
|
delete[] buff ;
|
||||||
|
delete f ;
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << n << " entries loaded." << std::endl ;
|
std::cerr << n << " entries loaded." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
@ -164,7 +222,7 @@ void HashCache::save()
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "Saving Hash Cache to file " << _path << "..." << std::endl ;
|
std::cerr << "Saving Hash Cache to file " << _path << "..." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
std::ofstream f( (_path+".tmp").c_str() ) ;
|
std::ostringstream f ;
|
||||||
|
|
||||||
for(std::map<std::string,HashCacheInfo>::const_iterator it(_files.begin());it!=_files.end();++it)
|
for(std::map<std::string,HashCacheInfo>::const_iterator it(_files.begin());it!=_files.end();++it)
|
||||||
{
|
{
|
||||||
|
@ -174,9 +232,34 @@ void HashCache::save()
|
||||||
f << it->second.modf_stamp << std::endl;
|
f << it->second.modf_stamp << std::endl;
|
||||||
f << it->second.hash << std::endl;
|
f << it->second.hash << std::endl;
|
||||||
}
|
}
|
||||||
f.close() ;
|
|
||||||
|
|
||||||
RsDirUtil::renameFile(_path+".tmp",_path) ;
|
void *encryptedData = NULL ;
|
||||||
|
int encDataLen = 0 ;
|
||||||
|
|
||||||
|
if(!AuthSSL::getAuthSSL()->encrypt(encryptedData, encDataLen, f.str().c_str(), f.str().length(), AuthSSL::getAuthSSL()->OwnId()))
|
||||||
|
{
|
||||||
|
std::cerr << "Cannot encrypt hash cache. Something's wrong." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *F = fopen( (_path+".bin.tmp").c_str(),"wb" ) ;
|
||||||
|
|
||||||
|
if(F == NULL)
|
||||||
|
{
|
||||||
|
std::cerr << "Cannot open encrypted file cache for writing: " << _path+".bin.tmp" << std::endl;
|
||||||
|
free(encryptedData) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if(fwrite(encryptedData,1,encDataLen,F) != encDataLen)
|
||||||
|
{
|
||||||
|
std::cerr << "Could not write entire encrypted hash cache file. Out of disc space??" << std::endl;
|
||||||
|
free(encryptedData) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
fclose(F) ;
|
||||||
|
free(encryptedData) ;
|
||||||
|
|
||||||
|
RsDirUtil::renameFile(_path+".bin.tmp",_path+".bin") ;
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "done." << std::endl ;
|
std::cerr << "done." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -49,7 +49,7 @@ 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(RsGRouterGenericDataItem * /*item*/,const GRouterKeyId& destination_key)
|
virtual void receiveGRouterData(const GRouterKeyId& destination_key, const RsGRouterGenericDataItem * /*item*/)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|
|
@ -35,11 +35,11 @@ uint32_t RsGRouterPublishKeyItem::serial_size() const
|
||||||
uint32_t s = 8 ; // header
|
uint32_t s = 8 ; // header
|
||||||
s += POW_PAYLOAD_SIZE ; // proof of work bytes
|
s += POW_PAYLOAD_SIZE ; // proof of work bytes
|
||||||
s += 4 ; // diffusion_id
|
s += 4 ; // diffusion_id
|
||||||
s += 20 ; // sha1 for published_key
|
s += published_key.serial_size() ; // sha1 for published_key
|
||||||
s += 4 ; // service id
|
s += 4 ; // service id
|
||||||
s += 4 ; // randomized distance
|
s += 4 ; // randomized distance
|
||||||
s += GetTlvStringSize(description_string) ; // description
|
s += GetTlvStringSize(description_string) ; // description
|
||||||
s += PGP_KEY_FINGERPRINT_SIZE ; // fingerprint
|
s += fingerprint.serial_size() ; // fingerprint
|
||||||
|
|
||||||
return s ;
|
return s ;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ RsItem *RsGRouterSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterPublishKeyItem(void *data, uint32_t pktsize) const
|
RsGRouterPublishKeyItem *RsGRouterSerialiser::deserialise_RsGRouterPublishKeyItem(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);
|
||||||
|
@ -197,7 +197,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterPublishKeyItem(void *da
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGRouterItem *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
|
||||||
uint32_t rssize = getRsItemSize(data);
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
@ -205,9 +205,10 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *d
|
||||||
|
|
||||||
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ;
|
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ;
|
||||||
|
|
||||||
ok &= getRawUInt32(data, pktsize, &offset, &item->routing_id); // file hash
|
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->data_size); // file hash
|
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)))
|
||||||
{
|
{
|
||||||
|
@ -227,7 +228,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *d
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterACKItem(void *data, uint32_t pktsize) const
|
RsGRouterACKItem *RsGRouterSerialiser::deserialise_RsGRouterACKItem(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);
|
||||||
|
@ -235,7 +236,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterACKItem(void *data, uin
|
||||||
|
|
||||||
RsGRouterACKItem *item = new RsGRouterACKItem() ;
|
RsGRouterACKItem *item = new RsGRouterACKItem() ;
|
||||||
|
|
||||||
ok &= getRawUInt32(data, pktsize, &offset, &item->mid); // file hash
|
ok &= getRawUInt64(data, pktsize, &offset, &item->mid); // file hash
|
||||||
ok &= getRawUInt32(data, pktsize, &offset, &item->state); // file hash
|
ok &= getRawUInt32(data, pktsize, &offset, &item->state); // file hash
|
||||||
|
|
||||||
if (offset != rssize || !ok)
|
if (offset != rssize || !ok)
|
||||||
|
@ -247,7 +248,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterACKItem(void *data, uin
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *data, uint32_t pktsize) const
|
RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(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);
|
||||||
|
@ -268,19 +269,13 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
||||||
|
|
||||||
ok &= ftr.friend_id.deserialise(data, pktsize, offset) ;
|
ok &= ftr.friend_id.deserialise(data, pktsize, offset) ;
|
||||||
ok &= getRawTimeT(data, pktsize, &offset, ftr.time_stamp) ;
|
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->tried_friends.push_back(ftr) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
item->data_item = new RsGRouterGenericDataItem ;
|
item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ;
|
||||||
|
|
||||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_item->routing_id);
|
|
||||||
ok &= item->data_item->destination_key.deserialise(data, pktsize, offset) ;
|
|
||||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_item->data_size) ;
|
|
||||||
|
|
||||||
item->data_item->data_bytes = (uint8_t*)malloc(item->data_item->data_size) ;
|
|
||||||
memcpy(item->data_item->data_bytes,&((uint8_t*)data)[offset],item->data_item->data_size) ;
|
|
||||||
offset += item->data_item->data_size ;
|
|
||||||
|
|
||||||
if (offset != rssize || !ok)
|
if (offset != rssize || !ok)
|
||||||
{
|
{
|
||||||
|
@ -290,7 +285,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(void *data, uint32_t pktsize) const
|
RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(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);
|
||||||
|
@ -314,7 +309,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(vo
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *data, uint32_t pktsize) const
|
RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(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);
|
||||||
|
@ -357,6 +352,7 @@ RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
|
||||||
item->routing_id = routing_id ;
|
item->routing_id = routing_id ;
|
||||||
item->destination_key = destination_key ;
|
item->destination_key = destination_key ;
|
||||||
item->data_size = data_size ;
|
item->data_size = data_size ;
|
||||||
|
item->randomized_distance = randomized_distance ;
|
||||||
|
|
||||||
// then duplicate the memory chunk
|
// then duplicate the memory chunk
|
||||||
|
|
||||||
|
@ -370,9 +366,10 @@ 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 += 20 ; // sha1 for published_key
|
s += destination_key.serial_size() ; // destination_key
|
||||||
|
s += 4 ; // randomized distance
|
||||||
s += 4 ; // data_size
|
s += 4 ; // data_size
|
||||||
s += data_size ; // data_size
|
s += data_size ; // data
|
||||||
|
|
||||||
return s ;
|
return s ;
|
||||||
}
|
}
|
||||||
|
@ -393,8 +390,9 @@ bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
|
||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
/* add mandatory parts first */
|
/* add mandatory parts first */
|
||||||
ok &= setRawUInt32(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, randomized_distance) ;
|
||||||
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) ;
|
||||||
|
@ -417,7 +415,7 @@ bool RsGRouterACKItem::serialise(void *data,uint32_t& size) const
|
||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
/* add mandatory parts first */
|
/* add mandatory parts first */
|
||||||
ok &= setRawUInt32(data, tlvsize, &offset, mid);
|
ok &= setRawUInt64(data, tlvsize, &offset, mid);
|
||||||
ok &= setRawUInt32(data, tlvsize, &offset, state);
|
ok &= setRawUInt32(data, tlvsize, &offset, state);
|
||||||
|
|
||||||
if (offset != tlvsize)
|
if (offset != tlvsize)
|
||||||
|
@ -434,7 +432,7 @@ uint32_t RsGRouterMatrixCluesItem::serial_size() const
|
||||||
{
|
{
|
||||||
uint32_t s = 8 ; // header
|
uint32_t s = 8 ; // header
|
||||||
|
|
||||||
s += 20 ; // Key size
|
s += destination_key.serial_size() ; // Key size
|
||||||
s += 4 ; // list<RoutingMatrixHitEntry>::size()
|
s += 4 ; // list<RoutingMatrixHitEntry>::size()
|
||||||
s += (4+4+8) * clues.size() ;
|
s += (4+4+8) * clues.size() ;
|
||||||
|
|
||||||
|
@ -452,16 +450,11 @@ uint32_t RsGRouterRoutingInfoItem::serial_size() const
|
||||||
{
|
{
|
||||||
uint32_t s = 8 ; // header
|
uint32_t s = 8 ; // header
|
||||||
s += 4 ; // status_flags
|
s += 4 ; // status_flags
|
||||||
s += origin.SIZE_IN_BYTES ; // origin
|
s += origin.serial_size() ; // origin
|
||||||
s += 8 ; // received_time
|
s += 8 ; // received_time
|
||||||
s += 4 ; // tried_friends.size() ;
|
s += 4 ; // tried_friends.size() ;
|
||||||
|
s += tried_friends.size() * ( RsPeerId::SIZE_IN_BYTES + 8 + 4 + 4 ) ; // FriendTrialRecord
|
||||||
s += tried_friends.size() * ( RsPeerId::SIZE_IN_BYTES + 8 ) ; // FriendTrialRecord
|
s += data_item->serial_size(); // data_item
|
||||||
|
|
||||||
s += 4; // data_item->routing_id
|
|
||||||
s += data_item->destination_key.SIZE_IN_BYTES; // data_item->destination_key
|
|
||||||
s += 4; // data_item->data_size
|
|
||||||
s += data_item->data_size; // data_item->data_bytes
|
|
||||||
|
|
||||||
return s ;
|
return s ;
|
||||||
}
|
}
|
||||||
|
@ -515,6 +508,25 @@ bool RsGRouterMatrixCluesItem::serialise(void *data,uint32_t& size) const
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FriendTrialRecord::deserialise(void *data,uint32_t& offset,uint32_t size)
|
||||||
|
{
|
||||||
|
bool ok = true ;
|
||||||
|
ok &= friend_id.deserialise(data, size, offset) ;
|
||||||
|
ok &= getRawTimeT(data, size, &offset, time_stamp) ;
|
||||||
|
ok &= getRawUFloat32(data, size, &offset, probability) ;
|
||||||
|
ok &= getRawUInt32(data, size, &offset, &nb_friends) ;
|
||||||
|
return ok ;
|
||||||
|
}
|
||||||
|
bool FriendTrialRecord::serialise(void *data,uint32_t& offset,uint32_t size) const
|
||||||
|
{
|
||||||
|
bool ok = true ;
|
||||||
|
ok &= friend_id.serialise(data, size, offset) ;
|
||||||
|
ok &= setRawTimeT(data, size, &offset, time_stamp) ;
|
||||||
|
ok &= setRawUFloat32(data, size, &offset, probability) ;
|
||||||
|
ok &= setRawUInt32(data, size, &offset, nb_friends) ;
|
||||||
|
return ok ;
|
||||||
|
}
|
||||||
bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
||||||
{
|
{
|
||||||
uint32_t tlvsize,offset=0;
|
uint32_t tlvsize,offset=0;
|
||||||
|
@ -529,17 +541,11 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
||||||
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ;
|
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ;
|
||||||
|
|
||||||
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it)
|
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it)
|
||||||
{
|
ok &= (*it).serialise(data,offset,size - offset) ;
|
||||||
ok &= (*it).friend_id.serialise(data, tlvsize, offset ) ;
|
|
||||||
ok &= setRawTimeT(data, tlvsize, &offset, (*it).time_stamp) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->routing_id) ;
|
uint32_t ns = size - offset ;
|
||||||
ok &= data_item->destination_key.serialise(data, tlvsize, offset) ;
|
ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ;
|
||||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->data_size) ;
|
offset += ns ;
|
||||||
|
|
||||||
memcpy(&((uint8_t*)data)[offset],data_item->data_bytes,data_item->data_size) ;
|
|
||||||
offset += data_item->data_size ;
|
|
||||||
|
|
||||||
if (offset != tlvsize)
|
if (offset != tlvsize)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,20 +26,19 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "serialiser/rsserial.h"
|
#include "serialiser/rsserial.h"
|
||||||
|
#include "serialiser/rsserviceids.h"
|
||||||
#include "retroshare/rstypes.h"
|
#include "retroshare/rstypes.h"
|
||||||
#include "rsgrouter.h"
|
|
||||||
|
#include "retroshare/rsgrouter.h"
|
||||||
#include "p3grouter.h"
|
#include "p3grouter.h"
|
||||||
|
|
||||||
// To be put in serialiser/rsserviceids.h
|
|
||||||
static const uint8_t RS_SERVICE_TYPE_GROUTER = 0x0016 ;
|
|
||||||
|
|
||||||
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_DATA = 0x02 ; // used to send data to a destination
|
|
||||||
const uint8_t RS_PKT_SUBTYPE_GROUTER_ACK = 0x03 ; // acknowledgement of data received
|
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_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_ROUTING_INFO = 0x81 ; // item to save routing info
|
|
||||||
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 = 0x85 ; // 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_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_ACK = 3 ;
|
||||||
|
@ -50,6 +49,7 @@ const uint32_t RS_GROUTER_ACK_STATE_RECEIVED_INDIRECTLY = 0x0002 ; // data was
|
||||||
const uint32_t RS_GROUTER_ACK_STATE_GIVEN_UP = 0x0003 ; // data was given up. No route.
|
const uint32_t RS_GROUTER_ACK_STATE_GIVEN_UP = 0x0003 ; // data was given up. No route.
|
||||||
const uint32_t RS_GROUTER_ACK_STATE_NO_ROUTE = 0x0004 ; // data was given up. No route.
|
const uint32_t RS_GROUTER_ACK_STATE_NO_ROUTE = 0x0004 ; // data was given up. No route.
|
||||||
const uint32_t RS_GROUTER_ACK_STATE_UNKNOWN = 0x0005 ; // unknown destination key
|
const uint32_t RS_GROUTER_ACK_STATE_UNKNOWN = 0x0005 ; // unknown destination key
|
||||||
|
const uint32_t RS_GROUTER_ACK_STATE_TOO_FAR = 0x0006 ; // dropped because of distance
|
||||||
|
|
||||||
/***********************************************************************************/
|
/***********************************************************************************/
|
||||||
/* Basic GRouter Item Class */
|
/* Basic GRouter Item Class */
|
||||||
|
@ -151,6 +151,7 @@ class RsGRouterGenericDataItem: public RsGRouterItem, public RsGRouterNonCopyabl
|
||||||
//
|
//
|
||||||
GRouterMsgPropagationId routing_id ;
|
GRouterMsgPropagationId routing_id ;
|
||||||
GRouterKeyId destination_key ;
|
GRouterKeyId destination_key ;
|
||||||
|
uint32_t randomized_distance ;
|
||||||
|
|
||||||
uint32_t data_size ;
|
uint32_t data_size ;
|
||||||
uint8_t *data_bytes;
|
uint8_t *data_bytes;
|
||||||
|
@ -251,12 +252,12 @@ class RsGRouterSerialiser: public RsSerialType
|
||||||
virtual RsItem *deserialise (void *data, uint32_t *size) ;
|
virtual RsItem *deserialise (void *data, uint32_t *size) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RsGRouterItem *deserialise_RsGRouterPublishKeyItem(void *data,uint32_t size) const ;
|
RsGRouterPublishKeyItem *deserialise_RsGRouterPublishKeyItem(void *data,uint32_t size) const ;
|
||||||
RsGRouterItem *deserialise_RsGRouterGenericDataItem(void *data,uint32_t size) const ;
|
RsGRouterGenericDataItem *deserialise_RsGRouterGenericDataItem(void *data,uint32_t size) const ;
|
||||||
RsGRouterItem *deserialise_RsGRouterACKItem(void *data,uint32_t size) const ;
|
RsGRouterACKItem *deserialise_RsGRouterACKItem(void *data,uint32_t size) const ;
|
||||||
RsGRouterItem *deserialise_RsGRouterMatrixCluesItem(void *data,uint32_t size) const ;
|
RsGRouterMatrixCluesItem *deserialise_RsGRouterMatrixCluesItem(void *data,uint32_t size) const ;
|
||||||
RsGRouterItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ;
|
RsGRouterMatrixFriendListItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ;
|
||||||
RsGRouterItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ;
|
RsGRouterRoutingInfoItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,7 @@ GRouterMatrix::GRouterMatrix()
|
||||||
_proba_need_updating = true ;
|
_proba_need_updating = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServiceId& sid,float distance,
|
bool GRouterMatrix::addRoutingClue(const GRouterKeyId& key_id,const RsPeerId& source_friend,float weight)
|
||||||
const std::string& desc_string,const RsPeerId& source_friend)
|
|
||||||
{
|
{
|
||||||
// 1 - get the friend index.
|
// 1 - get the friend index.
|
||||||
//
|
//
|
||||||
|
@ -44,7 +43,7 @@ bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServ
|
||||||
time_t now = time(NULL) ;
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
RoutingMatrixHitEntry rc ;
|
RoutingMatrixHitEntry rc ;
|
||||||
rc.weight = 1.0f / (1.0f + distance) ;
|
rc.weight = weight ;
|
||||||
rc.time_stamp = now ;
|
rc.time_stamp = now ;
|
||||||
rc.friend_id = fid ;
|
rc.friend_id = fid ;
|
||||||
|
|
||||||
|
@ -103,6 +102,14 @@ uint32_t GRouterMatrix::getFriendId(const RsPeerId& source_friend)
|
||||||
return it->second ;
|
return it->second ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GRouterMatrix::getListOfKnownKeys(std::vector<GRouterKeyId>& key_ids) const
|
||||||
|
{
|
||||||
|
key_ids.clear() ;
|
||||||
|
|
||||||
|
for(std::map<GRouterKeyId,std::vector<float> >::const_iterator it(_time_combined_hits.begin());it!=_time_combined_hits.end();++it)
|
||||||
|
key_ids.push_back(it->first) ;
|
||||||
|
}
|
||||||
|
|
||||||
void GRouterMatrix::debugDump() const
|
void GRouterMatrix::debugDump() const
|
||||||
{
|
{
|
||||||
std::cerr << " Proba needs up: " << _proba_need_updating << std::endl;
|
std::cerr << " Proba needs up: " << _proba_need_updating << std::endl;
|
||||||
|
@ -130,7 +137,7 @@ void GRouterMatrix::debugDump() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const
|
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::vector<RsPeerId>& friends, std::vector<float>& probas) const
|
||||||
{
|
{
|
||||||
// Routing probabilities are computed according to routing clues
|
// Routing probabilities are computed according to routing clues
|
||||||
//
|
//
|
||||||
|
@ -144,34 +151,41 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
|
||||||
if(_proba_need_updating)
|
if(_proba_need_updating)
|
||||||
std::cerr << "GRouterMatrix::computeRoutingProbabilities(): matrix is not up to date. Not a real problem, but still..." << std::endl;
|
std::cerr << "GRouterMatrix::computeRoutingProbabilities(): matrix is not up to date. Not a real problem, but still..." << std::endl;
|
||||||
|
|
||||||
probas.clear() ;
|
probas.resize(friends.size(),0.0f) ;
|
||||||
float total = 0.0f ;
|
float total = 0.0f ;
|
||||||
|
|
||||||
std::map<GRouterKeyId,std::vector<float> >::const_iterator it2 = _time_combined_hits.find(key_id) ;
|
std::map<GRouterKeyId,std::vector<float> >::const_iterator it2 = _time_combined_hits.find(key_id) ;
|
||||||
|
|
||||||
if(it2 == _time_combined_hits.end())
|
if(it2 == _time_combined_hits.end())
|
||||||
{
|
{
|
||||||
std::cerr << "GRouterMatrix::computeRoutingProbabilities(): key id " << key_id.toStdString() << " does not exist!" << std::endl;
|
// The key is not known. In this case, we return equal probabilities for all peers.
|
||||||
|
//
|
||||||
|
float p = 1.0f / friends.size() ;
|
||||||
|
|
||||||
|
probas.clear() ;
|
||||||
|
probas.resize(friends.size(),p) ;
|
||||||
|
|
||||||
|
std::cerr << "GRouterMatrix::computeRoutingProbabilities(): key id " << key_id.toStdString() << " does not exist! Returning uniform probabilities." << std::endl;
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
const std::vector<float>& w(it2->second) ;
|
const std::vector<float>& w(it2->second) ;
|
||||||
|
|
||||||
for(std::list<RsPeerId>::const_iterator it(friends.begin());it!=friends.end();++it)
|
for(uint32_t i=0;i<friends.size();++i)
|
||||||
{
|
{
|
||||||
uint32_t findex = getFriendId_const(*it) ;
|
uint32_t findex = getFriendId_const(friends[i]) ;
|
||||||
|
|
||||||
if(findex >= w.size())
|
if(findex >= w.size())
|
||||||
probas[*it] = 0.0f ;
|
probas[i] = 0.0f ;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
probas[*it] = w[findex] ;
|
probas[i] = w[findex] ;
|
||||||
total += w[findex] ;
|
total += w[findex] ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(total > 0.0f)
|
if(total > 0.0f)
|
||||||
for(std::map<RsPeerId,float>::iterator it(probas.begin());it!=probas.end();++it)
|
for(int i=0;i<friends.size();++i)
|
||||||
it->second /= total ;
|
probas[i] /= total ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include "pgp/rscertificate.h"
|
#include "pgp/rscertificate.h"
|
||||||
|
#include "retroshare/rsgrouter.h"
|
||||||
#include "groutertypes.h"
|
#include "groutertypes.h"
|
||||||
#include "rsgrouter.h"
|
|
||||||
|
|
||||||
class RsItem ;
|
class RsItem ;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class GRouterMatrix
|
||||||
// the computation accounts for the time at which the info was received and the
|
// the computation accounts for the time at which the info was received and the
|
||||||
// weight of each routing hit record.
|
// weight of each routing hit record.
|
||||||
//
|
//
|
||||||
bool computeRoutingProbabilities(const GRouterKeyId& id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const ;
|
bool computeRoutingProbabilities(const GRouterKeyId& id, const std::vector<RsPeerId>& friends, std::vector<float>& probas) const ;
|
||||||
|
|
||||||
// Update routing probabilities for each key, accounting for all received events, but without
|
// Update routing probabilities for each key, accounting for all received events, but without
|
||||||
// activity information
|
// activity information
|
||||||
|
@ -60,14 +60,15 @@ class GRouterMatrix
|
||||||
|
|
||||||
// Record one routing clue. The events can possibly be merged in time buckets.
|
// Record one routing clue. The events can possibly be merged in time buckets.
|
||||||
//
|
//
|
||||||
bool addRoutingClue(const GRouterKeyId& id,const GRouterServiceId& sid,float distance,const std::string& desc_string,const RsPeerId& source_friend) ;
|
bool addRoutingClue(const GRouterKeyId& id,const RsPeerId& source_friend,float weight) ;
|
||||||
|
|
||||||
|
bool saveList(std::list<RsItem*>& items) ;
|
||||||
|
bool loadList(std::list<RsItem*>& items) ;
|
||||||
|
|
||||||
// Dump info in terminal.
|
// Dump info in terminal.
|
||||||
//
|
//
|
||||||
void debugDump() const ;
|
void debugDump() const ;
|
||||||
|
void getListOfKnownKeys(std::vector<GRouterKeyId>& key_ids) const ;
|
||||||
bool saveList(std::list<RsItem*>& items) ;
|
|
||||||
bool loadList(std::list<RsItem*>& items) ;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// returns the friend id, possibly creating a new id.
|
// returns the friend id, possibly creating a new id.
|
||||||
|
|
|
@ -34,7 +34,7 @@ class RsGRouterGenericDataItem ;
|
||||||
|
|
||||||
typedef uint32_t GRouterServiceId ;
|
typedef uint32_t GRouterServiceId ;
|
||||||
typedef uint32_t GRouterKeyPropagationId ;
|
typedef uint32_t GRouterKeyPropagationId ;
|
||||||
typedef uint32_t GRouterMsgPropagationId ;
|
typedef uint64_t GRouterMsgPropagationId ;
|
||||||
|
|
||||||
static const uint32_t GROUTER_CLIENT_ID_MESSAGES = 0x1001 ;
|
static const uint32_t GROUTER_CLIENT_ID_MESSAGES = 0x1001 ;
|
||||||
|
|
||||||
|
@ -50,36 +50,35 @@ static const time_t RS_GROUTER_PUBLISH_CAMPAIGN_PERIOD = 1 *60 ; // Check
|
||||||
static const time_t RS_GROUTER_PUBLISH_KEY_TIME_INTERVAL = 2 *60 ; // Advertise each key once a day at most.
|
static const time_t RS_GROUTER_PUBLISH_KEY_TIME_INTERVAL = 2 *60 ; // Advertise each key once a day at most.
|
||||||
static const time_t RS_GROUTER_ROUTING_WAITING_TIME = 3600 ; // time between two trial of sending a given message
|
static const time_t RS_GROUTER_ROUTING_WAITING_TIME = 3600 ; // time between two trial of sending a given message
|
||||||
static const time_t RS_GROUTER_KEY_DIFFUSION_MAX_KEEP = 7200 ; // time to keep key diffusion items in cache, to avoid multiple diffusion.
|
static const time_t RS_GROUTER_KEY_DIFFUSION_MAX_KEEP = 7200 ; // time to keep key diffusion items in cache, to avoid multiple diffusion.
|
||||||
|
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 = 16*256 ; // 16 distance units. That is a lot.
|
||||||
|
|
||||||
static const uint32_t RS_GROUTER_ROUTING_STATE_UNKN = 0x0000 ; // unknown. Unused.
|
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_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_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_ARVD = 0x0003 ; // item is at destination. The cache only holds it to avoid duplication.
|
||||||
|
|
||||||
class GRouterPublishedKeyInfo
|
class FriendTrialRecord
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GRouterServiceId service_id ;
|
|
||||||
std::string description_string ;
|
|
||||||
PGPFingerprintType fpr ;
|
|
||||||
time_t last_published_time ;
|
|
||||||
time_t validity_time ;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FriendTrialRecord
|
|
||||||
{
|
|
||||||
RsPeerId friend_id ; // id of the friend
|
RsPeerId friend_id ; // id of the friend
|
||||||
time_t time_stamp ; // time of the last tried
|
time_t time_stamp ; // time of the last tried
|
||||||
|
float probability ; // probability at which the item was selected
|
||||||
|
uint32_t nb_friends ; // number of friends at the time of sending the item
|
||||||
|
|
||||||
|
bool serialise(void *data,uint32_t& offset,uint32_t size) const ;
|
||||||
|
bool deserialise(void *data,uint32_t& offset,uint32_t size) ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GRouterRoutingInfo
|
class GRouterRoutingInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGRouterGenericDataItem *data_item ;
|
|
||||||
|
|
||||||
uint32_t status_flags ; // pending, waiting, etc.
|
uint32_t status_flags ; // pending, waiting, etc.
|
||||||
std::list<FriendTrialRecord> tried_friends ; // list of friends to which the item was sent ordered with time.
|
|
||||||
RsPeerId origin ; // which friend sent us that item
|
RsPeerId origin ; // which friend sent us that item
|
||||||
time_t received_time ; // time at which the item was received
|
time_t received_time ; // time at which the item was received
|
||||||
|
|
||||||
|
std::list<FriendTrialRecord> tried_friends ; // list of friends to which the item was sent ordered with time.
|
||||||
|
|
||||||
|
RsGRouterGenericDataItem *data_item ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,17 @@
|
||||||
// - which probability was used to chose this friend (will be useful
|
// - which probability was used to chose this friend (will be useful
|
||||||
// to compute the routing contribution if the msg is ACK-ed)
|
// to compute the routing contribution if the msg is ACK-ed)
|
||||||
//
|
//
|
||||||
|
// Two probabilities are computed:
|
||||||
|
// - routing probabilities among connected friends
|
||||||
|
// * this is computed by the routing matrix
|
||||||
|
// - branching factor N
|
||||||
|
// * depends on the depth of the items
|
||||||
|
// * depends on the distribution of probabilities (min and max)
|
||||||
|
//
|
||||||
|
// Once computed,
|
||||||
|
// - the item is forwarded randomly to N peers drawn from the list of connected peers with the given probabilities.
|
||||||
|
// - the depth of the item is incremented randomly
|
||||||
|
//
|
||||||
// - downward: look into routing cache. If info not present, drop the item.
|
// - downward: look into routing cache. If info not present, drop the item.
|
||||||
// Forward item into stored direction.
|
// Forward item into stored direction.
|
||||||
//
|
//
|
||||||
|
@ -137,6 +148,7 @@
|
||||||
// - packet service ID (Can be messenging, channels, etc).
|
// - packet service ID (Can be messenging, channels, etc).
|
||||||
// - packet data (void* + size_t)
|
// - packet data (void* + size_t)
|
||||||
// - flags (such as ACK or response required, and packet direction)
|
// - flags (such as ACK or response required, and packet direction)
|
||||||
|
// - routed directions and probabilities
|
||||||
// * ACK packet.
|
// * ACK packet.
|
||||||
// - packet unique ID (the id of the corresponding data)
|
// - packet unique ID (the id of the corresponding data)
|
||||||
// - flags (reason for ACK. Could be data delivered, or error, too far, etc)
|
// - flags (reason for ACK. Could be data delivered, or error, too far, etc)
|
||||||
|
@ -179,8 +191,10 @@
|
||||||
#include "groutertypes.h"
|
#include "groutertypes.h"
|
||||||
#include "grouterclientservice.h"
|
#include "grouterclientservice.h"
|
||||||
|
|
||||||
|
const std::string p3GRouter::SERVICE_INFO_APP_NAME = "Global Router" ;
|
||||||
|
|
||||||
p3GRouter::p3GRouter(p3LinkMgr *lm)
|
p3GRouter::p3GRouter(p3LinkMgr *lm)
|
||||||
: p3Service(RS_SERVICE_TYPE_GROUTER), p3Config(CONFIG_TYPE_GROUTER), mLinkMgr(lm), grMtx("GRouter")
|
: p3Service(), p3Config(), mLinkMgr(lm), grMtx("GRouter")
|
||||||
{
|
{
|
||||||
addSerialType(new RsGRouterSerialiser()) ;
|
addSerialType(new RsGRouterSerialiser()) ;
|
||||||
|
|
||||||
|
@ -215,7 +229,8 @@ int p3GRouter::tick()
|
||||||
{
|
{
|
||||||
last_publish_campaign_time = now ;
|
last_publish_campaign_time = now ;
|
||||||
|
|
||||||
publishKeys() ;
|
//publishKeys() ; // we don't publish keys anymore.
|
||||||
|
//
|
||||||
_routing_matrix.updateRoutingProbabilities() ;
|
_routing_matrix.updateRoutingProbabilities() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,39 +299,6 @@ void p3GRouter::routePendingObjects()
|
||||||
{
|
{
|
||||||
RsStackMutex mtx(grMtx) ;
|
RsStackMutex mtx(grMtx) ;
|
||||||
|
|
||||||
// Go through list of published keys
|
|
||||||
// broadcast a publishKeyItem for each of them.
|
|
||||||
//
|
|
||||||
// The routing rules are the following:
|
|
||||||
//
|
|
||||||
// Go through list of cached routing objects. For each object:
|
|
||||||
// if(Last try is old)
|
|
||||||
// put the object in pending list
|
|
||||||
//
|
|
||||||
// (This loop is costly (could handle lots of items), so it should be done less often.)
|
|
||||||
//
|
|
||||||
// Add peer to the list of tried routes with time stamp
|
|
||||||
// Keep the list of tried friends
|
|
||||||
//
|
|
||||||
// Go through list of pendign objects. For each object:
|
|
||||||
// Select one route direction
|
|
||||||
// - according to current probabilities from the routing matrix
|
|
||||||
// - according to list of previous attempts
|
|
||||||
//
|
|
||||||
// if(route found)
|
|
||||||
// forward item, update state and time stamp
|
|
||||||
// else
|
|
||||||
// if(I am not the sender)
|
|
||||||
// send back ACK(given up) // if I am the sender, I will keep trying.
|
|
||||||
//
|
|
||||||
// Item has received an ACK
|
|
||||||
//
|
|
||||||
// ACK: given up => change route
|
|
||||||
// ACK: received => Remove item from routed items
|
|
||||||
//
|
|
||||||
// The list in _pending_messages is necessarily short and most of the time empty. Once
|
|
||||||
// treated, objects are stored in _routing_cache, where they wait for an answer.
|
|
||||||
|
|
||||||
time_t now = time(NULL) ;
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
std::cerr << "p3GRouter::routeObjects() triage phase:" << std::endl;
|
std::cerr << "p3GRouter::routeObjects() triage phase:" << std::endl;
|
||||||
|
@ -326,93 +308,68 @@ void p3GRouter::routePendingObjects()
|
||||||
mLinkMgr->getOnlineList(lst) ;
|
mLinkMgr->getOnlineList(lst) ;
|
||||||
RsPeerId own_id( mLinkMgr->getOwnId() );
|
RsPeerId own_id( mLinkMgr->getOwnId() );
|
||||||
|
|
||||||
|
std::vector<RsPeerId> pids ;
|
||||||
|
for(std::list<RsPeerId>::const_iterator it(lst.begin());it!=lst.end();++it)
|
||||||
|
pids.push_back(*it) ;
|
||||||
|
|
||||||
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();)
|
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();)
|
||||||
if((it->second.status_flags & RS_GROUTER_ROUTING_STATE_PEND) || (it->second.status_flags == RS_GROUTER_ROUTING_STATE_SENT && it->second.tried_friends.front().time_stamp+RS_GROUTER_ROUTING_WAITING_TIME < now))
|
if((it->second.status_flags == RS_GROUTER_ROUTING_STATE_PEND) || (it->second.status_flags == RS_GROUTER_ROUTING_STATE_SENT && it->second.tried_friends.front().time_stamp+RS_GROUTER_ROUTING_WAITING_TIME < now))
|
||||||
{
|
{
|
||||||
std::cerr << " Msg id: " << std::hex << it->first << std::dec << std::endl;
|
std::cerr << " Msg id: " << std::hex << it->first << std::dec << std::endl;
|
||||||
std::cerr << " Origin: " << it->second.origin.toStdString() << std::endl;
|
std::cerr << " Origin: " << it->second.origin.toStdString() << std::endl;
|
||||||
std::cerr << " Last : " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
|
std::cerr << " Last : " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
|
||||||
std::cerr << " Time : " << it->second.tried_friends.front().time_stamp << std::endl;
|
std::cerr << " Time : " << it->second.tried_friends.front().time_stamp << std::endl;
|
||||||
std::cerr << " Flags : " << it->second.status_flags << std::endl;
|
std::cerr << " Flags : " << it->second.status_flags << std::endl;
|
||||||
|
std::cerr << " Dist : " << it->second.data_item->randomized_distance<< std::endl;
|
||||||
std::cerr << " Probabilities: " << std::endl;
|
std::cerr << " Probabilities: " << std::endl;
|
||||||
|
|
||||||
std::map<RsPeerId,float> probas ; // friends probabilities for online friend list.
|
std::vector<float> probas ; // friends probabilities for online friend list.
|
||||||
RsPeerId routed_friend ; // friend chosen for the next hop
|
RsPeerId routed_friend ; // friend chosen for the next hop
|
||||||
float best_proba = 0.0f; // temp variable used to select the best proba
|
|
||||||
bool should_remove = false ; // should we remove this from the map?
|
bool should_remove = false ; // should we remove this from the map?
|
||||||
|
|
||||||
// retrieve probabilities for this key.
|
// Retrieve probabilities for this key. This call always succeeds. If no route is known, all probabilities become equal.
|
||||||
//
|
//
|
||||||
if(! _routing_matrix.computeRoutingProbabilities(it->second.data_item->destination_key, lst, probas))
|
_routing_matrix.computeRoutingProbabilities(it->second.data_item->destination_key, pids, probas) ;
|
||||||
|
|
||||||
|
// Compute the branching factor.
|
||||||
|
|
||||||
|
int N = computeBranchingFactor(pids,probas,it->second.data_item->randomized_distance) ;
|
||||||
|
|
||||||
|
// Now use this to select N random peers according to the given probabilities
|
||||||
|
|
||||||
|
std::set<uint32_t> routing_friend_indices = computeRoutingFriends(pids,probas,N) ;
|
||||||
|
|
||||||
|
std::cerr << " Routing statistics: " << std::endl;
|
||||||
|
|
||||||
|
// Actually send the item.
|
||||||
|
|
||||||
|
for(std::set<uint32_t>::const_iterator its(routing_friend_indices.begin());its!=routing_friend_indices.end();++its)
|
||||||
{
|
{
|
||||||
// key does not exist in routing matrix => send back an ACK(unknown)
|
std::cerr << " Friend : " << (*its) << std::endl;
|
||||||
|
|
||||||
std::cerr << " [Cannot compute. Unknown destination key!!] " << std::endl;
|
|
||||||
|
|
||||||
if(it->second.origin != own_id)
|
|
||||||
{
|
|
||||||
std::cerr << " removing item and notifying the sender (" << it->second.origin.toStdString() << ")" << std::endl;
|
|
||||||
|
|
||||||
sendACK(it->second.origin,it->first,RS_GROUTER_ACK_STATE_UNKNOWN) ;
|
|
||||||
|
|
||||||
// remove item from cache
|
|
||||||
//
|
|
||||||
should_remove = true ;
|
|
||||||
}
|
|
||||||
std::cerr << " item is ours. Keeping it until a route is known." << std::endl;
|
|
||||||
|
|
||||||
// else, select a routing friend at random, or just wait? Wait is probably better.
|
|
||||||
}
|
|
||||||
|
|
||||||
bool friend_found = false ;
|
|
||||||
|
|
||||||
for(std::map<RsPeerId,float>::const_iterator it2(probas.begin());it2!=probas.end();++it2)
|
|
||||||
{
|
|
||||||
std::cerr << " " << it2->first.toStdString() << " : " << it2->second << std::endl;
|
|
||||||
|
|
||||||
// select the peer with highest probability that hasn't yet been tried.
|
|
||||||
|
|
||||||
if(it2->second > best_proba && !(it2->first == it->second.tried_friends.front().friend_id))
|
|
||||||
{
|
|
||||||
routed_friend = it2->first ;
|
|
||||||
best_proba = it2->second ;
|
|
||||||
friend_found = true ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << " Best route: " << routed_friend.toStdString() << ", with probability " << best_proba << std::endl;
|
|
||||||
|
|
||||||
// now, send the item.
|
|
||||||
|
|
||||||
if(friend_found)
|
|
||||||
{
|
|
||||||
// make a deep copy of the item
|
// make a deep copy of the item
|
||||||
RsGRouterGenericDataItem *new_item = it->second.data_item->duplicate() ;
|
RsGRouterGenericDataItem *new_item = it->second.data_item->duplicate() ;
|
||||||
|
|
||||||
// update cache entry
|
// update cache entry
|
||||||
FriendTrialRecord ftr ;
|
FriendTrialRecord ftr ;
|
||||||
ftr.time_stamp = now ;
|
ftr.time_stamp = now ;
|
||||||
ftr.friend_id = routed_friend ;
|
ftr.friend_id = pids[*its];
|
||||||
|
ftr.probability = probas[*its] ;
|
||||||
|
ftr.nb_friends = probas.size() ;
|
||||||
|
|
||||||
it->second.tried_friends.push_front(ftr) ;
|
it->second.tried_friends.push_front(ftr) ;
|
||||||
it->second.status_flags = RS_GROUTER_ROUTING_STATE_SENT ;
|
it->second.status_flags = RS_GROUTER_ROUTING_STATE_SENT ;
|
||||||
|
|
||||||
|
std::cerr << " Routing probability: " << ftr.probability << std::endl;
|
||||||
std::cerr << " Sending..." << std::endl;
|
std::cerr << " Sending..." << std::endl;
|
||||||
|
|
||||||
// send
|
// send
|
||||||
new_item->PeerId(routed_friend) ;
|
new_item->PeerId(pids[*its]) ;
|
||||||
|
new_item->randomized_distance += computeRandomDistanceIncrement(pids[*its],new_item->destination_key) ;
|
||||||
|
|
||||||
sendItem(new_item) ;
|
sendItem(new_item) ;
|
||||||
}
|
}
|
||||||
else if(it->second.origin != mLinkMgr->getOwnId() || std::find(lst.begin(),lst.end(),it->second.origin) != lst.end())
|
|
||||||
{
|
|
||||||
// There's no correct friend to send this item to. We keep it for a while. If it's too old,
|
|
||||||
// we discard it. For now, the procedure is to send back an ACK.
|
|
||||||
|
|
||||||
std::cerr << " Item has no route candidate. It's too old. " << std::endl;
|
|
||||||
std::cerr << " sending ACK(no route) to peer " << it->second.origin.toStdString() << std::endl;
|
|
||||||
|
|
||||||
sendACK(it->second.origin,it->first,RS_GROUTER_ACK_STATE_NO_ROUTE) ;
|
|
||||||
|
|
||||||
should_remove = true ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(should_remove)
|
if(should_remove)
|
||||||
{
|
{
|
||||||
|
@ -430,11 +387,56 @@ void p3GRouter::routePendingObjects()
|
||||||
++it ;
|
++it ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
std::cerr << "Skipping " << std::hex << it->first << std::dec << ", dest=" << it->second.data_item->destination_key.toStdString() << ", state = " << it->second.status_flags << ", stamp=" << it->second.tried_friends.front().time_stamp << " - " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
|
std::cerr << "Skipping " << std::hex << it->first << std::dec << ", dest=" << it->second.data_item->destination_key.toStdString() << ", state = " << it->second.status_flags << ", stamp=" << it->second.tried_friends.front().time_stamp << " - " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
|
||||||
|
++it ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t p3GRouter::computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_key)
|
||||||
|
{
|
||||||
|
// This computes a consistent random bias between 0 and 255, which only depends on the
|
||||||
|
// destination key and the friend the item is going to be routed through.
|
||||||
|
// Makes it much harder for attakcers to figure out what is going on with
|
||||||
|
// distances in the network, and makes statistics about multiple sending
|
||||||
|
// attempts impossible.
|
||||||
|
//
|
||||||
|
static uint64_t random_salt = RSRandom::random_u64() ;
|
||||||
|
static const int total_size = RsPeerId::SIZE_IN_BYTES + GRouterKeyId::SIZE_IN_BYTES + sizeof(random_salt) ;
|
||||||
|
|
||||||
|
unsigned char tmpmem[total_size] ;
|
||||||
|
*(uint64_t*)&tmpmem[0] = random_salt ;
|
||||||
|
memcpy(&tmpmem[sizeof(random_salt)],pid.toByteArray(),RsPeerId::SIZE_IN_BYTES) ;
|
||||||
|
memcpy(&tmpmem[sizeof(random_salt) + RsPeerId::SIZE_IN_BYTES],destination_key.toByteArray(),GRouterKeyId::SIZE_IN_BYTES) ;
|
||||||
|
|
||||||
|
return RsDirUtil::sha1sum(tmpmem,total_size).toByteArray()[5] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t p3GRouter::computeBranchingFactor(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t dist)
|
||||||
|
{
|
||||||
|
// This should be made a bit more adaptive ;-)
|
||||||
|
//
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<uint32_t> p3GRouter::computeRoutingFriends(const std::vector<RsPeerId>& pids,const std::vector<float>& probas,uint32_t N)
|
||||||
|
{
|
||||||
|
// We draw N friends according to the routing probabilitites that are passed as parameter.
|
||||||
|
//
|
||||||
|
|
||||||
|
std::set<uint32_t> res ;
|
||||||
|
|
||||||
|
if(probas.empty())
|
||||||
|
return res ;
|
||||||
|
|
||||||
|
res.insert(0) ;
|
||||||
|
|
||||||
|
return res ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3GRouter::publishKeys()
|
void p3GRouter::publishKeys()
|
||||||
{
|
{
|
||||||
|
#ifdef SUSPENDED
|
||||||
RsStackMutex mtx(grMtx) ;
|
RsStackMutex mtx(grMtx) ;
|
||||||
|
|
||||||
// Go through list of published keys
|
// Go through list of published keys
|
||||||
|
@ -454,14 +456,13 @@ void p3GRouter::publishKeys()
|
||||||
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
|
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
|
||||||
std::cerr << " Service id : " << std::hex << info.service_id << std::dec << 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 << " Description : " << info.description_string << std::endl;
|
||||||
std::cerr << " Fingerprint : " << info.fpr.toStdString() << std::endl;
|
|
||||||
|
|
||||||
RsGRouterPublishKeyItem item ;
|
RsGRouterPublishKeyItem item ;
|
||||||
item.diffusion_id = RSRandom::random_u32() ;
|
item.diffusion_id = RSRandom::random_u32() ;
|
||||||
item.published_key = it->first ;
|
item.published_key = it->first ;
|
||||||
item.service_id = info.service_id ;
|
item.service_id = info.service_id ;
|
||||||
item.randomized_distance = drand48() ;
|
item.randomized_distance = drand48() ;
|
||||||
item.fingerprint = info.fpr;
|
item.fingerprint.clear() ; // not set
|
||||||
item.description_string = info.description_string ;
|
item.description_string = info.description_string ;
|
||||||
item.PeerId(RsPeerId()) ; // no peer id => key is forwarded to all friends.
|
item.PeerId(RsPeerId()) ; // no peer id => key is forwarded to all friends.
|
||||||
|
|
||||||
|
@ -471,6 +472,7 @@ void p3GRouter::publishKeys()
|
||||||
info.last_published_time = now ;
|
info.last_published_time = now ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
|
void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
|
||||||
|
@ -497,16 +499,20 @@ void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
|
||||||
else
|
else
|
||||||
std::cerr << " Not forwarding to source id " << item.PeerId() << std::endl;
|
std::cerr << " Not forwarding to source id " << item.PeerId() << std::endl;
|
||||||
}
|
}
|
||||||
bool p3GRouter::registerKey(const GRouterKeyId& key,const PGPFingerprintType& fps,const GRouterServiceId& client_id,const std::string& description)
|
bool p3GRouter::registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description)
|
||||||
{
|
{
|
||||||
RsStackMutex mtx(grMtx) ;
|
RsStackMutex mtx(grMtx) ;
|
||||||
|
|
||||||
|
if(_registered_services.find(client_id) == _registered_services.end())
|
||||||
|
{
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << ": unable to register key " << key << " for client id " << client_id << ": client id is not known." << std::endl;
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
|
||||||
GRouterPublishedKeyInfo info ;
|
GRouterPublishedKeyInfo info ;
|
||||||
info.service_id = client_id ;
|
info.service_id = client_id ;
|
||||||
info.fpr = fps ;
|
|
||||||
info.description_string = description.substr(0,20);
|
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.
|
||||||
info.last_published_time = 0 ; // means never published, se it will be re-published soon.
|
|
||||||
|
|
||||||
_owned_key_ids[key] = info ;
|
_owned_key_ids[key] = info ;
|
||||||
|
|
||||||
|
@ -575,7 +581,7 @@ void p3GRouter::handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item)
|
||||||
|
|
||||||
// update the route matrix
|
// update the route matrix
|
||||||
|
|
||||||
_routing_matrix.addRoutingClue(item->published_key,item->service_id,item->randomized_distance,item->description_string,RsPeerId(item->PeerId())) ;
|
_routing_matrix.addRoutingClue(item->published_key,RsPeerId(item->PeerId()),1) ;
|
||||||
|
|
||||||
// forward the key to other peers according to key forwarding cache
|
// forward the key to other peers according to key forwarding cache
|
||||||
|
|
||||||
|
@ -602,7 +608,7 @@ void p3GRouter::handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item)
|
||||||
void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||||
{
|
{
|
||||||
RsStackMutex mtx(grMtx) ;
|
RsStackMutex mtx(grMtx) ;
|
||||||
std::cerr << "Received ACK item, mid=" << std::hex << item->mid << std::dec << std::endl;
|
std::cerr << "Received ACK item, mid=" << std::hex << item->mid << std::dec << ", ACK type = "<< item->state << std::endl;
|
||||||
|
|
||||||
// find the item in the pendign list,
|
// find the item in the pendign list,
|
||||||
// - if not found, drop.
|
// - if not found, drop.
|
||||||
|
@ -624,15 +630,30 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||||
switch(item->state)
|
switch(item->state)
|
||||||
{
|
{
|
||||||
case RS_GROUTER_ACK_STATE_RECEIVED_INDIRECTLY:
|
case RS_GROUTER_ACK_STATE_RECEIVED_INDIRECTLY:
|
||||||
// Do nothing. It was indirectly received: fine. We don't need to notify the origin
|
|
||||||
// otherwise lots of ACKs will flow to the origin.
|
|
||||||
break ;
|
|
||||||
case RS_GROUTER_ACK_STATE_RECEIVED:
|
case RS_GROUTER_ACK_STATE_RECEIVED:
|
||||||
// Notify the origin. This is the main route and it was successful.
|
// Notify the origin. This is the main route and it was successful.
|
||||||
|
|
||||||
std::cerr << " forwarding ACK to origin: " << it->second.origin.toStdString() << std::endl;
|
std::cerr << " updating routing matrix." << std::endl;
|
||||||
|
|
||||||
sendACK(it->second.origin,item->mid,RS_GROUTER_ACK_STATE_RECEIVED) ;
|
it->second.status_flags = RS_GROUTER_ROUTING_STATE_ARVD ;
|
||||||
|
|
||||||
|
{
|
||||||
|
#warning UNFINISHED code.
|
||||||
|
|
||||||
|
// Now compute the weight for that particular item. See with what probabilities it was chosen.
|
||||||
|
//
|
||||||
|
float weight = (item->state == RS_GROUTER_ACK_STATE_RECEIVED)?1.0f : 0.5;
|
||||||
|
std::cerr << " weight = " << weight << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
_routing_matrix.addRoutingClue(it->second.data_item->destination_key,item->PeerId(),weight) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(it->second.origin != mLinkMgr->getOwnId())
|
||||||
|
{
|
||||||
|
std::cerr << " forwarding ACK to origin: " << it->second.origin.toStdString() << std::endl;
|
||||||
|
sendACK(it->second.origin,item->mid,item->state) ;
|
||||||
|
}
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case RS_GROUTER_ACK_STATE_GIVEN_UP: // route is bad. We forward back and update the routing matrix.
|
case RS_GROUTER_ACK_STATE_GIVEN_UP: // route is bad. We forward back and update the routing matrix.
|
||||||
|
@ -645,23 +666,45 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
||||||
std::cerr << " We're owner: should notify client id" << std::endl;
|
std::cerr << " We're owner: should notify client id" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always remove the item.
|
// Just decrement the list of tried friends
|
||||||
//
|
//
|
||||||
|
for(std::list<FriendTrialRecord>::iterator it2(it->second.tried_friends.begin());it2!=it->second.tried_friends.end();++it2)
|
||||||
|
if( (*it2).friend_id == item->PeerId())
|
||||||
|
{
|
||||||
|
std::cerr << " Removing friend try for peer " << item->PeerId() << ". " << it->second.tried_friends.size() << " tries left." << std::endl;
|
||||||
|
it->second.tried_friends.erase(it2) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(it->second.tried_friends.empty())
|
||||||
|
{
|
||||||
delete it->second.data_item ;
|
delete it->second.data_item ;
|
||||||
_pending_messages.erase(it) ;
|
_pending_messages.erase(it) ;
|
||||||
|
|
||||||
|
std::cerr << " No tries left. Removing item from pending list." << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||||
{
|
{
|
||||||
RsStackMutex mtx(grMtx) ;
|
RsStackMutex mtx(grMtx) ;
|
||||||
std::cerr << "Received data item for key " << item->destination_key << std::endl;
|
std::cerr << "Received data item for key " << item->destination_key << ", distance = " << item->randomized_distance << std::endl;
|
||||||
|
|
||||||
|
// check the item depth. If too large, send a ACK back.
|
||||||
|
|
||||||
|
if(item->randomized_distance > GROUTER_ITEM_MAX_TRAVEL_DISTANCE)
|
||||||
|
{
|
||||||
|
std::cerr << " Distance is too large: " << item->randomized_distance << " units. Item is dropped." << std::endl;
|
||||||
|
sendACK(item->PeerId(),item->routing_id,RS_GROUTER_ACK_STATE_TOO_FAR) ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
// Do we have this item in the cache already?
|
// Do we have this item in the cache already?
|
||||||
// - if not, add in the pending items
|
// - if not, add in the pending items
|
||||||
// - if yet. Ignore, or send ACK for shorter route.
|
// - if yet. Ignore, or send ACK for shorter route.
|
||||||
|
|
||||||
std::map<GRouterKeyId,GRouterPublishedKeyInfo>::const_iterator it = _owned_key_ids.find(item->destination_key) ;
|
std::map<GRouterKeyId,GRouterPublishedKeyInfo>::const_iterator it = _owned_key_ids.find(item->destination_key) ;
|
||||||
std::map<GRouterMsgPropagationId,GRouterRoutingInfo>::const_iterator itr = _pending_messages.find(item->routing_id) ;
|
std::map<GRouterMsgPropagationId,GRouterRoutingInfo>::iterator itr = _pending_messages.find(item->routing_id) ;
|
||||||
RsGRouterGenericDataItem *item_copy = NULL;
|
RsGRouterGenericDataItem *item_copy = NULL;
|
||||||
|
|
||||||
if(itr != _pending_messages.end())
|
if(itr != _pending_messages.end())
|
||||||
|
@ -670,7 +713,7 @@ void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||||
|
|
||||||
item_copy = itr->second.data_item ;
|
item_copy = itr->second.data_item ;
|
||||||
}
|
}
|
||||||
else // item is now known. Store it into pending msgs. We make a copy, since the item will be deleted otherwise.
|
else // item is not known. Store it into pending msgs. We make a copy, since the item will be deleted otherwise.
|
||||||
{
|
{
|
||||||
std::cerr << " Item is new. Storing in cache as pending messages." << std::endl;
|
std::cerr << " Item is new. Storing in cache as pending messages." << std::endl;
|
||||||
|
|
||||||
|
@ -679,38 +722,40 @@ void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||||
info.data_item = item->duplicate() ;
|
info.data_item = item->duplicate() ;
|
||||||
item_copy = info.data_item ;
|
item_copy = info.data_item ;
|
||||||
|
|
||||||
if(it != _owned_key_ids.end())
|
|
||||||
info.status_flags = RS_GROUTER_ROUTING_STATE_ARVD ;
|
|
||||||
else
|
|
||||||
info.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
|
||||||
|
|
||||||
info.origin = RsPeerId(item->PeerId()) ;
|
info.origin = RsPeerId(item->PeerId()) ;
|
||||||
info.received_time = time(NULL) ;
|
info.received_time = time(NULL) ;
|
||||||
|
|
||||||
_pending_messages[item->routing_id] = info ;
|
_pending_messages[item->routing_id] = info ;
|
||||||
|
itr = _pending_messages.find(item->routing_id) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the item for us? If so, find the client service and send the item back.
|
// Is the item for us? If so, find the client service and send the item back.
|
||||||
|
//
|
||||||
if(it != _owned_key_ids.end())
|
if(it != _owned_key_ids.end())
|
||||||
if(time(NULL) < it->second.validity_time)
|
|
||||||
{
|
{
|
||||||
// test validity time. If too old, we don't forward.
|
if(itr->second.status_flags == RS_GROUTER_ROUTING_STATE_ARVD)
|
||||||
|
sendACK(item->PeerId(), item->routing_id, RS_GROUTER_ACK_STATE_RECEIVED_INDIRECTLY) ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendACK(item->PeerId(), item->routing_id, RS_GROUTER_ACK_STATE_RECEIVED) ;
|
||||||
|
itr->second.status_flags = RS_GROUTER_ROUTING_STATE_ARVD ;
|
||||||
|
|
||||||
std::map<GRouterServiceId,GRouterClientService*>::const_iterator its = _registered_services.find(it->second.service_id) ;
|
std::map<GRouterServiceId,GRouterClientService*>::const_iterator its = _registered_services.find(it->second.service_id) ;
|
||||||
|
|
||||||
if(its != _registered_services.end())
|
if(its != _registered_services.end())
|
||||||
{
|
{
|
||||||
std::cerr << " Key is owned by us. Notifying service for this item." << std::endl;
|
std::cerr << " Key is owned by us. Notifying service for this item." << std::endl;
|
||||||
its->second->receiveGRouterData(item_copy,it->first) ;
|
its->second->receiveGRouterData(it->first,item_copy) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cerr << " (EE) weird situation. No service registered for a key that we own. Key id = " << item->destination_key.toStdString() << ", service id = " << it->second.service_id << std::endl;
|
std::cerr << " (EE) weird situation. No service registered for a key that we own. Key id = " << item->destination_key.toStdString() << ", service id = " << it->second.service_id << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
std::cerr << " (WW) key is outdated. Dropping this item." << std::endl;
|
{
|
||||||
else
|
std::cerr << " item is not for us. Storing in pending mode." << std::endl;
|
||||||
std::cerr << " Item is not for us. Leaving in pending msgs to be routed later." << std::endl;
|
itr->second.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
||||||
|
}
|
||||||
|
|
||||||
_changed = true ;
|
_changed = true ;
|
||||||
}
|
}
|
||||||
|
@ -732,17 +777,22 @@ void p3GRouter::sendData(const GRouterKeyId& destination, RsGRouterGenericDataIt
|
||||||
info.data_item = item ;
|
info.data_item = item ;
|
||||||
info.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
info.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
||||||
info.origin = RsPeerId(mLinkMgr->getOwnId()) ;
|
info.origin = RsPeerId(mLinkMgr->getOwnId()) ;
|
||||||
info.received_time = time(NULL) ;
|
info.data_item->randomized_distance = 0 ;
|
||||||
|
|
||||||
// Make sure we have a unique id (at least locally).
|
// Make sure we have a unique id (at least locally).
|
||||||
//
|
//
|
||||||
GRouterMsgPropagationId propagation_id ;
|
GRouterMsgPropagationId propagation_id ;
|
||||||
do { propagation_id = RSRandom::random_u32(); } while(_pending_messages.find(propagation_id) != _pending_messages.end()) ;
|
do { propagation_id = RSRandom::random_u32(); } while(_pending_messages.find(propagation_id) != _pending_messages.end()) ;
|
||||||
|
|
||||||
|
item->destination_key = destination ;
|
||||||
|
item->routing_id = propagation_id ;
|
||||||
|
|
||||||
std::cerr << "p3GRouter::sendGRouterData(): pushing the followign item in the msg pending list:" << std::endl;
|
std::cerr << "p3GRouter::sendGRouterData(): pushing the followign item in the msg pending list:" << std::endl;
|
||||||
std::cerr << " data_item.size = " << info.data_item->data_size << std::endl;
|
std::cerr << " data_item.size = " << info.data_item->data_size << std::endl;
|
||||||
std::cerr << " data_item.byte = " << info.data_item->data_bytes << std::endl;
|
std::cerr << " data_item.byte = " << info.data_item->data_bytes << std::endl;
|
||||||
|
std::cerr << " destination = " << info.data_item->destination_key << std::endl;
|
||||||
std::cerr << " status = " << info.status_flags << std::endl;
|
std::cerr << " status = " << info.status_flags << std::endl;
|
||||||
|
std::cerr << " distance = " << info.data_item->randomized_distance << std::endl;
|
||||||
std::cerr << " origin = " << info.origin.toStdString() << std::endl;
|
std::cerr << " origin = " << info.origin.toStdString() << std::endl;
|
||||||
std::cerr << " Recv time = " << info.received_time << std::endl;
|
std::cerr << " Recv time = " << info.received_time << std::endl;
|
||||||
|
|
||||||
|
@ -821,6 +871,54 @@ bool p3GRouter::saveList(bool& cleanup,std::list<RsItem*>& items)
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool p3GRouter::getRoutingMatrixInfo(RsGRouter::GRouterRoutingMatrixInfo& info)
|
||||||
|
{
|
||||||
|
info.per_friend_probabilities.clear() ;
|
||||||
|
info.friend_ids.clear() ;
|
||||||
|
info.published_keys.clear() ;
|
||||||
|
|
||||||
|
std::list<RsPeerId> ids ;
|
||||||
|
mLinkMgr->getOnlineList(ids) ;
|
||||||
|
|
||||||
|
RsStackMutex mtx(grMtx) ;
|
||||||
|
|
||||||
|
info.published_keys = _owned_key_ids ;
|
||||||
|
|
||||||
|
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||||
|
info.friend_ids.push_back(*it) ;
|
||||||
|
|
||||||
|
std::vector<GRouterKeyId> known_keys ;
|
||||||
|
std::vector<float> probas ;
|
||||||
|
_routing_matrix.getListOfKnownKeys(known_keys) ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<known_keys.size();++i)
|
||||||
|
{
|
||||||
|
_routing_matrix.computeRoutingProbabilities(known_keys[i],info.friend_ids,probas) ;
|
||||||
|
info.per_friend_probabilities[known_keys[i]] = probas ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
bool p3GRouter::getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& infos)
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(grMtx) ;
|
||||||
|
infos.clear() ;
|
||||||
|
|
||||||
|
for(std::map<GRouterMsgPropagationId,GRouterRoutingInfo>::const_iterator it(_pending_messages.begin());it!=_pending_messages.end();++it)
|
||||||
|
{
|
||||||
|
infos.push_back(GRouterRoutingCacheInfo()) ;
|
||||||
|
GRouterRoutingCacheInfo& cinfo(infos.back()) ;
|
||||||
|
|
||||||
|
cinfo.mid = it->first ;
|
||||||
|
cinfo.local_origin = it->second.origin ;
|
||||||
|
cinfo.destination = it->second.data_item->destination_key ;
|
||||||
|
cinfo.time_stamp = it->second.received_time ;
|
||||||
|
cinfo.status = it->second.status_flags ;
|
||||||
|
cinfo.data_size = it->second.data_item->data_size ;
|
||||||
|
}
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
// Dump everything
|
// Dump everything
|
||||||
//
|
//
|
||||||
void p3GRouter::debugDump()
|
void p3GRouter::debugDump()
|
||||||
|
@ -837,7 +935,7 @@ void p3GRouter::debugDump()
|
||||||
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
|
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
|
||||||
std::cerr << " Service id : " << std::hex << it->second.service_id << std::dec << std::endl;
|
std::cerr << " Service id : " << std::hex << it->second.service_id << std::dec << std::endl;
|
||||||
std::cerr << " Description : " << it->second.description_string << std::endl;
|
std::cerr << " Description : " << it->second.description_string << std::endl;
|
||||||
std::cerr << " Last published: " << now - it->second.last_published_time << " secs ago" << std::endl;
|
//std::cerr << " Last published: " << now - it->second.last_published_time << " secs ago" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << " Registered services: " << std::endl;
|
std::cerr << " Registered services: " << std::endl;
|
||||||
|
@ -854,7 +952,18 @@ void p3GRouter::debugDump()
|
||||||
std::cerr << " [Not shown yet] " << std::endl;
|
std::cerr << " [Not shown yet] " << std::endl;
|
||||||
|
|
||||||
std::cerr << " Data items: " << std::endl;
|
std::cerr << " Data items: " << std::endl;
|
||||||
std::cerr << " [Not shown yet] " << std::endl;
|
|
||||||
|
static std::string statusString[4] = { "Unkn","Pend","Sent","Ackn" };
|
||||||
|
|
||||||
|
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();++it)
|
||||||
|
std::cerr << " Msg id: " << std::hex << it->first << std::dec
|
||||||
|
<< " Local Origin: " << it->second.origin.toStdString()
|
||||||
|
<< " Destination: " << it->second.data_item->destination_key
|
||||||
|
<< " Time : " << now - it->second.tried_friends.front().time_stamp << " secs ago."
|
||||||
|
<< " Status: " << statusString[it->second.status_flags] << std::endl;
|
||||||
|
|
||||||
|
// << " Last : " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
|
||||||
|
// << " Probabilities: " << std::endl;
|
||||||
|
|
||||||
std::cerr << " Routing matrix: " << std::endl;
|
std::cerr << " Routing matrix: " << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,16 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#include "rsgrouter.h"
|
#include "retroshare/rsgrouter.h"
|
||||||
|
#include "retroshare/rstypes.h"
|
||||||
|
|
||||||
#include "services/p3service.h"
|
#include "services/p3service.h"
|
||||||
#include "pqi/p3cfgmgr.h"
|
#include "pqi/p3cfgmgr.h"
|
||||||
#include "retroshare/rstypes.h"
|
|
||||||
|
|
||||||
#include "groutertypes.h"
|
#include "groutertypes.h"
|
||||||
#include "groutermatrix.h"
|
#include "groutermatrix.h"
|
||||||
#include "groutercache.h"
|
|
||||||
#include "grouteritems.h"
|
#include "grouteritems.h"
|
||||||
|
//#include "groutercache.h"
|
||||||
|
|
||||||
// To be put in pqi/p3cfgmgr.h
|
// To be put in pqi/p3cfgmgr.h
|
||||||
//
|
//
|
||||||
|
@ -75,9 +76,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||||
// 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.
|
||||||
//
|
//
|
||||||
bool registerKey(const GRouterKeyId& key,const PGPFingerprintType& pgp_fingerprint,
|
bool registerKey(const GRouterKeyId& key, const GRouterServiceId& client_id,const std::string& description_string) ;
|
||||||
const GRouterServiceId& client_id,const std::string& description_string) ;
|
|
||||||
|
|
||||||
bool unregisterKey(const GRouterKeyId& key) ;
|
bool unregisterKey(const GRouterKeyId& key) ;
|
||||||
|
|
||||||
//===================================================//
|
//===================================================//
|
||||||
|
@ -103,7 +102,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||||
// - list of clues/time_stamp for each key.
|
// - list of clues/time_stamp for each key.
|
||||||
// - real time routing probabilities
|
// - real time routing probabilities
|
||||||
//
|
//
|
||||||
virtual bool getRoutingMatrixInfo(RoutingMatrixInfo& info) { return false ;}
|
virtual bool getRoutingMatrixInfo(GRouterRoutingMatrixInfo& info) ;
|
||||||
|
|
||||||
// debug info from routing cache
|
// debug info from routing cache
|
||||||
// - Cache Items
|
// - Cache Items
|
||||||
|
@ -113,8 +112,21 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||||
// * message type
|
// * message type
|
||||||
// - Cache state (memory size, etc)
|
// - Cache state (memory size, etc)
|
||||||
//
|
//
|
||||||
virtual bool getRoutingCacheInfo(RoutingCacheInfo& info) { return false ;}
|
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& info) ;
|
||||||
|
|
||||||
|
//===================================================//
|
||||||
|
// Derived from p3Service //
|
||||||
|
//===================================================//
|
||||||
|
|
||||||
|
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) ;
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
//===================================================//
|
//===================================================//
|
||||||
// Routing method handling //
|
// Routing method handling //
|
||||||
|
@ -127,6 +139,12 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||||
//
|
//
|
||||||
virtual int tick() ;
|
virtual int tick() ;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void autoWash() ;
|
void autoWash() ;
|
||||||
void routePendingObjects() ;
|
void routePendingObjects() ;
|
||||||
|
@ -135,6 +153,12 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
||||||
void debugDump() ;
|
void debugDump() ;
|
||||||
void locked_forwardKey(const RsGRouterPublishKeyItem&) ;
|
void locked_forwardKey(const RsGRouterPublishKeyItem&) ;
|
||||||
|
|
||||||
|
// utility functions
|
||||||
|
//
|
||||||
|
static uint32_t computeBranchingFactor(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t dist) ;
|
||||||
|
static std::set<uint32_t> computeRoutingFriends(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t N) ;
|
||||||
|
static uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ;
|
||||||
|
|
||||||
//===================================================//
|
//===================================================//
|
||||||
// p3Config methods //
|
// p3Config methods //
|
||||||
//===================================================//
|
//===================================================//
|
||||||
|
|
|
@ -49,9 +49,9 @@ RSA *GxsSecurity::extractPublicKey(const RsTlvSecurityKey& key)
|
||||||
return rsakey;
|
return rsakey;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GxsSecurity::getSignature(char* data, uint32_t data_len, RsTlvSecurityKey* privKey, RsTlvKeySignature& sign)
|
bool GxsSecurity::getSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& privKey, RsTlvKeySignature& sign)
|
||||||
{
|
{
|
||||||
RSA* rsa_pub = extractPrivateKey(*privKey);
|
RSA* rsa_pub = extractPrivateKey(privKey);
|
||||||
EVP_PKEY *key_pub = EVP_PKEY_new();
|
EVP_PKEY *key_pub = EVP_PKEY_new();
|
||||||
EVP_PKEY_assign_RSA(key_pub, rsa_pub);
|
EVP_PKEY_assign_RSA(key_pub, rsa_pub);
|
||||||
|
|
||||||
|
@ -69,11 +69,33 @@ bool GxsSecurity::getSignature(char* data, uint32_t data_len, RsTlvSecurityKey*
|
||||||
EVP_PKEY_free(key_pub);
|
EVP_PKEY_free(key_pub);
|
||||||
|
|
||||||
sign.signData.setBinData(sigbuf, siglen);
|
sign.signData.setBinData(sigbuf, siglen);
|
||||||
sign.keyId = privKey->keyId;
|
sign.keyId = privKey.keyId;
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GxsSecurity::validateSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& key, const RsTlvKeySignature& signature)
|
||||||
|
{
|
||||||
|
RSA *rsakey = RSAPublicKey_dup(extractPublicKey(key)) ;
|
||||||
|
|
||||||
|
EVP_PKEY *signKey = EVP_PKEY_new();
|
||||||
|
EVP_PKEY_assign_RSA(signKey, rsakey);
|
||||||
|
|
||||||
|
/* calc and check signature */
|
||||||
|
EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
|
||||||
|
|
||||||
|
EVP_VerifyInit(mdctx, EVP_sha1());
|
||||||
|
EVP_VerifyUpdate(mdctx, data, data_len);
|
||||||
|
|
||||||
|
int signOk = EVP_VerifyFinal(mdctx, (unsigned char*)signature.signData.bin_data, signature.signData.bin_len, signKey);
|
||||||
|
|
||||||
|
/* clean up */
|
||||||
|
EVP_PKEY_free(signKey);
|
||||||
|
EVP_MD_CTX_destroy(mdctx);
|
||||||
|
|
||||||
|
return signOk;
|
||||||
|
}
|
||||||
|
|
||||||
bool GxsSecurity::validateNxsMsg(RsNxsMsg& msg, RsTlvKeySignature& sign, RsTlvSecurityKey& key)
|
bool GxsSecurity::validateNxsMsg(RsNxsMsg& msg, RsTlvKeySignature& sign, RsTlvSecurityKey& key)
|
||||||
{
|
{
|
||||||
#ifdef GXS_SECURITY_DEBUG
|
#ifdef GXS_SECURITY_DEBUG
|
||||||
|
@ -204,22 +226,21 @@ std::string GxsSecurity::getBinDataSign(void *data, int len)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool GxsSecurity::encrypt(void *& out, int & outlen, const void *in, int inlen, EVP_PKEY *privateKey)
|
bool GxsSecurity::encrypt(void *& out, int & outlen, const void *in, int inlen, const RsTlvSecurityKey& key)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
#ifdef DISTRIB_DEBUG
|
#ifdef DISTRIB_DEBUG
|
||||||
std::cerr << "GxsSecurity::encrypt() " << std::endl;
|
std::cerr << "GxsSecurity::encrypt() " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RSA *rsa_publish_pub = NULL;
|
RSA *rsa_publish_pub = RSAPublicKey_dup(extractPublicKey(key)) ;
|
||||||
EVP_PKEY *public_key = NULL;
|
EVP_PKEY *public_key = NULL;
|
||||||
|
|
||||||
RSA* rsa_publish = EVP_PKEY_get1_RSA(privateKey);
|
//RSA* rsa_publish = EVP_PKEY_get1_RSA(privateKey);
|
||||||
rsa_publish_pub = RSAPublicKey_dup(rsa_publish);
|
//rsa_publish_pub = RSAPublicKey_dup(rsa_publish);
|
||||||
|
|
||||||
|
|
||||||
if(rsa_publish_pub != NULL){
|
if(rsa_publish_pub != NULL)
|
||||||
|
{
|
||||||
public_key = EVP_PKEY_new();
|
public_key = EVP_PKEY_new();
|
||||||
EVP_PKEY_assign_RSA(public_key, rsa_publish_pub);
|
EVP_PKEY_assign_RSA(public_key, rsa_publish_pub);
|
||||||
}else{
|
}else{
|
||||||
|
@ -282,23 +303,35 @@ bool GxsSecurity::encrypt(void *& out, int & outlen, const void *in, int inlen,
|
||||||
|
|
||||||
outlen = out_offset;
|
outlen = out_offset;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
delete[] ek;
|
|
||||||
|
|
||||||
#ifdef DISTRIB_DEBUG
|
|
||||||
std::cerr << "GxsSecurity::encrypt() finished with outlen : " << outlen << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GxsSecurity::decrypt(void *& out, int & outlen, const void *in, int inlen, EVP_PKEY *privateKey)
|
bool GxsSecurity::decrypt(void *& out, int & outlen, const void *in, int inlen, const RsTlvSecurityKey& key)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef DISTRIB_DEBUG
|
#ifdef DISTRIB_DEBUG
|
||||||
std::cerr << "GxsSecurity::decrypt() " << std::endl;
|
std::cerr << "GxsSecurity::decrypt() " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
RSA *rsa_publish = RSAPrivateKey_dup(extractPrivateKey(key)) ;
|
||||||
|
EVP_PKEY *privateKey = NULL;
|
||||||
|
|
||||||
|
//RSA* rsa_publish = EVP_PKEY_get1_RSA(privateKey);
|
||||||
|
//rsa_publish_pub = RSAPublicKey_dup(rsa_publish);
|
||||||
|
|
||||||
|
if(rsa_publish != NULL)
|
||||||
|
{
|
||||||
|
privateKey = EVP_PKEY_new();
|
||||||
|
EVP_PKEY_assign_RSA(privateKey, rsa_publish);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef DISTRIB_DEBUG
|
||||||
|
std::cerr << "GxsSecurity(): Could not generate publish key " << grpId
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EVP_CIPHER_CTX ctx;
|
EVP_CIPHER_CTX ctx;
|
||||||
int eklen = 0, net_ekl = 0;
|
int eklen = 0, net_ekl = 0;
|
||||||
|
|
|
@ -98,7 +98,7 @@ public:
|
||||||
*@param in
|
*@param in
|
||||||
*@param inlen
|
*@param inlen
|
||||||
*/
|
*/
|
||||||
static bool encrypt(void *&out, int &outlen, const void *in, int inlen, EVP_PKEY *privateKey);
|
static bool encrypt(void *&out, int &outlen, const void *in, int inlen, const RsTlvSecurityKey& key) ;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,7 +110,7 @@ public:
|
||||||
* @param inlen
|
* @param inlen
|
||||||
* @return false if encryption failed
|
* @return false if encryption failed
|
||||||
*/
|
*/
|
||||||
static bool decrypt(void *&out, int &outlen, const void *in, int inlen, EVP_PKEY *privateKey);
|
static bool decrypt(void *&out, int &outlen, const void *in, int inlen, const RsTlvSecurityKey& key) ;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* uses grp signature to check if group has been
|
* uses grp signature to check if group has been
|
||||||
|
@ -139,7 +139,16 @@ public:
|
||||||
* @param sign the signature is stored here
|
* @param sign the signature is stored here
|
||||||
* @return false if signature creation failed, true is signature created
|
* @return false if signature creation failed, true is signature created
|
||||||
*/
|
*/
|
||||||
static bool getSignature(char* data, uint32_t data_len, RsTlvSecurityKey* privKey, RsTlvKeySignature& sign);
|
static bool getSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& privKey, RsTlvKeySignature& sign);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @param data data that has been signed
|
||||||
|
* @param data_len length of signed data
|
||||||
|
* @param privKey public key to used to check signature
|
||||||
|
* @param sign Signature for the data
|
||||||
|
* @return true if signature checks
|
||||||
|
*/
|
||||||
|
static bool validateSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& pubKey, const RsTlvKeySignature& sign);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GXSSECURITY_H
|
#endif // GXSSECURITY_H
|
||||||
|
|
|
@ -392,7 +392,7 @@ uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKe
|
||||||
memcpy(allGrpData+(grp->grp.bin_len), metaData, metaDataLen);
|
memcpy(allGrpData+(grp->grp.bin_len), metaData, metaDataLen);
|
||||||
|
|
||||||
RsTlvKeySignature adminSign;
|
RsTlvKeySignature adminSign;
|
||||||
bool ok = GxsSecurity::getSignature(allGrpData, allGrpDataLen, &privAdminKey, adminSign);
|
bool ok = GxsSecurity::getSignature(allGrpData, allGrpDataLen, privAdminKey, adminSign);
|
||||||
|
|
||||||
// add admin sign to grpMeta
|
// add admin sign to grpMeta
|
||||||
meta->signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_ADMIN] = adminSign;
|
meta->signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_ADMIN] = adminSign;
|
||||||
|
@ -458,7 +458,7 @@ int RsGenExchange::createGroupSignatures(RsTlvKeySignatureSet& signSet, RsTlvBin
|
||||||
RsTlvKeySignature sign;
|
RsTlvKeySignature sign;
|
||||||
|
|
||||||
if(GxsSecurity::getSignature((char*)grpData.bin_data, grpData.bin_len,
|
if(GxsSecurity::getSignature((char*)grpData.bin_data, grpData.bin_len,
|
||||||
&authorKey, sign))
|
authorKey, sign))
|
||||||
{
|
{
|
||||||
id_ret = SIGN_SUCCESS;
|
id_ret = SIGN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -584,7 +584,7 @@ int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinar
|
||||||
|
|
||||||
RsTlvKeySignature pubSign = signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH];
|
RsTlvKeySignature pubSign = signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH];
|
||||||
|
|
||||||
publishSignSuccess = GxsSecurity::getSignature((char*)msgData.bin_data, msgData.bin_len, pubKey, pubSign);
|
publishSignSuccess = GxsSecurity::getSignature((char*)msgData.bin_data, msgData.bin_len, *pubKey, pubSign);
|
||||||
|
|
||||||
//place signature in msg meta
|
//place signature in msg meta
|
||||||
signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH] = pubSign;
|
signSet.keySignSet[GXS_SERV::FLAG_AUTHEN_PUBLISH] = pubSign;
|
||||||
|
@ -617,7 +617,7 @@ int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinar
|
||||||
RsTlvKeySignature sign;
|
RsTlvKeySignature sign;
|
||||||
|
|
||||||
if(GxsSecurity::getSignature((char*)msgData.bin_data, msgData.bin_len,
|
if(GxsSecurity::getSignature((char*)msgData.bin_data, msgData.bin_len,
|
||||||
&authorKey, sign))
|
authorKey, sign))
|
||||||
{
|
{
|
||||||
id_ret = SIGN_SUCCESS;
|
id_ret = SIGN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ TARGET = retroshare
|
||||||
#GXS Stuff.
|
#GXS Stuff.
|
||||||
# This should be disabled for releases until further notice.
|
# This should be disabled for releases until further notice.
|
||||||
CONFIG += gxs debug
|
CONFIG += gxs debug
|
||||||
#CONFIG += grouter
|
|
||||||
#CONFIG += dsdv
|
#CONFIG += dsdv
|
||||||
|
|
||||||
profiling {
|
profiling {
|
||||||
|
@ -34,23 +34,6 @@ debug {
|
||||||
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
grouter {
|
|
||||||
DEFINES *= GROUTER
|
|
||||||
|
|
||||||
HEADERS += grouter/groutercache.h \
|
|
||||||
grouter/rsgrouter.h \
|
|
||||||
grouter/grouteritems.h \
|
|
||||||
grouter/p3grouter.h \
|
|
||||||
grouter/rsgroutermatrix.h \
|
|
||||||
grouter/rsgrouterclient.h
|
|
||||||
|
|
||||||
SOURCES += grouter/p3grouter.cc \
|
|
||||||
grouter/grouteritems.cc \
|
|
||||||
grouter/groutermatrix.cc
|
|
||||||
# grouter/groutercache.cc \
|
|
||||||
# grouter/rsgrouterclient.cc
|
|
||||||
}
|
|
||||||
|
|
||||||
dsdv {
|
dsdv {
|
||||||
DEFINES *= SERVICES_DSDV
|
DEFINES *= SERVICES_DSDV
|
||||||
HEADERS += services/p3dsdv.h \
|
HEADERS += services/p3dsdv.h \
|
||||||
|
@ -397,6 +380,13 @@ HEADERS += rsserver/p3face.h \
|
||||||
rsserver/rsaccounts.h \
|
rsserver/rsaccounts.h \
|
||||||
rsserver/p3serverconfig.h
|
rsserver/p3serverconfig.h
|
||||||
|
|
||||||
|
HEADERS += grouter/groutercache.h \
|
||||||
|
grouter/rsgrouter.h \
|
||||||
|
grouter/grouteritems.h \
|
||||||
|
grouter/p3grouter.h \
|
||||||
|
grouter/rsgroutermatrix.h \
|
||||||
|
grouter/rsgrouterclient.h
|
||||||
|
|
||||||
HEADERS += serialiser/rsbaseserial.h \
|
HEADERS += serialiser/rsbaseserial.h \
|
||||||
serialiser/rsfiletransferitems.h \
|
serialiser/rsfiletransferitems.h \
|
||||||
serialiser/rsserviceserialiser.h \
|
serialiser/rsserviceserialiser.h \
|
||||||
|
@ -533,6 +523,10 @@ SOURCES += rsserver/p3face-config.cc \
|
||||||
rsserver/rstypes.cc \
|
rsserver/rstypes.cc \
|
||||||
rsserver/p3serverconfig.cc
|
rsserver/p3serverconfig.cc
|
||||||
|
|
||||||
|
SOURCES += grouter/p3grouter.cc \
|
||||||
|
grouter/grouteritems.cc \
|
||||||
|
grouter/groutermatrix.cc
|
||||||
|
|
||||||
SOURCES += plugins/pluginmanager.cc \
|
SOURCES += plugins/pluginmanager.cc \
|
||||||
plugins/dlfcn_win32.cc \
|
plugins/dlfcn_win32.cc \
|
||||||
serialiser/rspluginitems.cc
|
serialiser/rspluginitems.cc
|
||||||
|
|
|
@ -27,43 +27,56 @@
|
||||||
|
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
#include "grouter/groutertypes.h"
|
#include "grouter/groutertypes.h"
|
||||||
|
#include "retroshare/rsids.h"
|
||||||
|
|
||||||
|
typedef GRouterKeyIdType GRouterKeyId ; // we use SSLIds, so that it's easier in the GUI to mix up peer ids with grouter ids.
|
||||||
|
|
||||||
typedef Sha1CheckSum GRouterKeyId ; // we use sha1. Gives sufficient entropy.
|
|
||||||
class GRouterClientService ;
|
class GRouterClientService ;
|
||||||
class RsGRouterGenericDataItem ;
|
class RsGRouterGenericDataItem ;
|
||||||
|
|
||||||
// This is the interface file for the global router service.
|
class RsGRouter
|
||||||
//
|
|
||||||
struct RoutingCacheInfo
|
|
||||||
{
|
{
|
||||||
// what do we want to show here?
|
public:
|
||||||
// - recently routed items
|
// This is the interface file for the global router service.
|
||||||
// - ongoing routing info
|
//
|
||||||
// - pending items, waiting for an answer
|
struct GRouterRoutingCacheInfo
|
||||||
// -
|
{
|
||||||
};
|
GRouterMsgPropagationId mid ;
|
||||||
|
RsPeerId local_origin;
|
||||||
|
GRouterKeyId destination ;
|
||||||
|
time_t time_stamp ;
|
||||||
|
uint32_t status ;
|
||||||
|
uint32_t data_size ;
|
||||||
|
};
|
||||||
|
|
||||||
struct RoutingMatrixInfo
|
struct GRouterPublishedKeyInfo
|
||||||
{
|
{
|
||||||
|
std::string description_string ;
|
||||||
|
uint32_t service_id ;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GRouterRoutingMatrixInfo
|
||||||
|
{
|
||||||
// Probabilities of reaching a given key for each friend.
|
// Probabilities of reaching a given key for each friend.
|
||||||
// This concerns all known keys.
|
// This concerns all known keys.
|
||||||
//
|
//
|
||||||
std::map<GRouterKeyId, std::vector<float> > per_friend_probabilities ;
|
std::map<GRouterKeyId, std::vector<float> > per_friend_probabilities ;
|
||||||
|
|
||||||
|
// List of friend ids in the same order. Should roughly correspond to the friends that are currently online.
|
||||||
|
//
|
||||||
|
std::vector<RsPeerId> friend_ids ;
|
||||||
|
|
||||||
// List of own published keys, with associated service ID
|
// List of own published keys, with associated service ID
|
||||||
//
|
//
|
||||||
std::map<GRouterKeyId, GRouterClientService *> published_keys ;
|
std::map<GRouterKeyId,GRouterPublishedKeyInfo> published_keys ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGRouter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
//===================================================//
|
//===================================================//
|
||||||
// Debugging info //
|
// Debugging info //
|
||||||
//===================================================//
|
//===================================================//
|
||||||
|
|
||||||
virtual bool getRoutingCacheInfo(RoutingCacheInfo& info) =0;
|
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& infos) =0;
|
||||||
virtual bool getRoutingMatrixInfo(RoutingMatrixInfo& info) =0;
|
virtual bool getRoutingMatrixInfo(GRouterRoutingMatrixInfo& info) =0;
|
||||||
|
|
||||||
// retrieve the routing probabilities
|
// retrieve the routing probabilities
|
||||||
|
|
||||||
|
@ -72,8 +85,7 @@ class RsGRouter
|
||||||
//===================================================//
|
//===================================================//
|
||||||
|
|
||||||
virtual void sendData(const GRouterKeyId& destination, RsGRouterGenericDataItem *item) =0;
|
virtual void sendData(const GRouterKeyId& destination, RsGRouterGenericDataItem *item) =0;
|
||||||
virtual bool registerKey(const GRouterKeyId& key,const PGPFingerprintType& fps,const GRouterServiceId& client_id,const std::string& description_string) =0;
|
virtual bool registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description_string) =0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// To access the GRouter from anywhere
|
// To access the GRouter from anywhere
|
|
@ -218,8 +218,10 @@ static const uint32_t RS_GENERIC_ID_GXS_GROUP_ID_TYPE = 0x0005 ;
|
||||||
static const uint32_t RS_GENERIC_ID_GXS_ID_TYPE = 0x0006 ;
|
static const uint32_t RS_GENERIC_ID_GXS_ID_TYPE = 0x0006 ;
|
||||||
static const uint32_t RS_GENERIC_ID_GXS_MSG_ID_TYPE = 0x0007 ;
|
static const uint32_t RS_GENERIC_ID_GXS_MSG_ID_TYPE = 0x0007 ;
|
||||||
static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
|
static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
|
||||||
|
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< 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 ;
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "rstypes.h"
|
#include "rstypes.h"
|
||||||
|
#include "rsgxsifacetypes.h"
|
||||||
|
|
||||||
/********************** For Messages and Channels *****************/
|
/********************** For Messages and Channels *****************/
|
||||||
|
|
||||||
|
@ -88,20 +89,30 @@ typedef uint64_t ChatLobbyMsgId ;
|
||||||
typedef std::string ChatLobbyNickName ;
|
typedef std::string ChatLobbyNickName ;
|
||||||
|
|
||||||
typedef RsPeerId DistantChatPeerId ;
|
typedef RsPeerId DistantChatPeerId ;
|
||||||
typedef RsPeerId DistantMsgPeerId ;
|
typedef GRouterKeyIdType DistantMsgPeerId ;
|
||||||
|
|
||||||
class MessageInfo
|
class MessageInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessageInfo() {}
|
MessageInfo() {}
|
||||||
std::string msgId;
|
std::string msgId;
|
||||||
RsPeerId srcId;
|
|
||||||
|
RsPeerId rspeerid_srcId;
|
||||||
|
RsGxsId rsgxsid_srcId;
|
||||||
|
|
||||||
unsigned int msgflags;
|
unsigned int msgflags;
|
||||||
|
|
||||||
std::list<RsPeerId> msgto;
|
// friend destinations
|
||||||
std::list<RsPeerId> msgcc;
|
//
|
||||||
std::list<RsPeerId> msgbcc;
|
std::list<RsPeerId> rspeerid_msgto; // RsPeerId is used here for various purposes:
|
||||||
|
std::list<RsPeerId> rspeerid_msgcc; // - real peer ids which are actual friend locations
|
||||||
|
std::list<RsPeerId> rspeerid_msgbcc; // -
|
||||||
|
|
||||||
|
// distant peers
|
||||||
|
//
|
||||||
|
std::list<RsGxsId> rsgxsid_msgto; // RsPeerId is used here for various purposes:
|
||||||
|
std::list<RsGxsId> rsgxsid_msgcc; // - real peer ids which are actual friend locations
|
||||||
|
std::list<RsGxsId> rsgxsid_msgbcc; // -
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
@ -109,7 +120,7 @@ class MessageInfo
|
||||||
std::string attach_title;
|
std::string attach_title;
|
||||||
std::string attach_comment;
|
std::string attach_comment;
|
||||||
std::list<FileInfo> files;
|
std::list<FileInfo> files;
|
||||||
std::map<std::string,std::string> encryption_keys ; // for concerned ids only the public pgp key id to encrypt the message with.
|
|
||||||
int size; /* total of files */
|
int size; /* total of files */
|
||||||
int count; /* file count */
|
int count; /* file count */
|
||||||
|
|
||||||
|
@ -241,7 +252,7 @@ extern RsMsgs *rsMsgs;
|
||||||
struct DistantOfflineMessengingInvite
|
struct DistantOfflineMessengingInvite
|
||||||
{
|
{
|
||||||
RsPgpId issuer_pgp_id ;
|
RsPgpId issuer_pgp_id ;
|
||||||
Sha1CheckSum hash ;
|
DistantMsgPeerId peer_id ;
|
||||||
time_t time_of_validity ;
|
time_t time_of_validity ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -291,11 +302,8 @@ virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0;
|
||||||
/* Private distant messages */
|
/* Private distant messages */
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
|
||||||
virtual bool createDistantOfflineMessengingInvite(time_t validity_time_stamp, DistantMsgPeerId& hash)=0 ;
|
|
||||||
virtual bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites) = 0 ;
|
|
||||||
virtual void enableDistantMessaging(bool b) = 0;
|
virtual void enableDistantMessaging(bool b) = 0;
|
||||||
virtual bool distantMessagingEnabled() = 0;
|
virtual bool distantMessagingEnabled() = 0;
|
||||||
virtual bool getDistantMessagePeerId(const RsPgpId& pgp_id, DistantMsgPeerId& peerId) = 0;
|
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/* Chat */
|
/* Chat */
|
||||||
|
|
|
@ -100,14 +100,6 @@ bool p3Msgs::decryptMessage(const std::string& mId)
|
||||||
{
|
{
|
||||||
return mMsgSrv->decryptMessage(mId);
|
return mMsgSrv->decryptMessage(mId);
|
||||||
}
|
}
|
||||||
bool p3Msgs::createDistantOfflineMessengingInvite(time_t ts, DistantMsgPeerId &hash)
|
|
||||||
{
|
|
||||||
return mMsgSrv->createDistantOfflineMessengingInvite(ts,hash) ;
|
|
||||||
}
|
|
||||||
bool p3Msgs::getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites)
|
|
||||||
{
|
|
||||||
return mMsgSrv->getDistantOfflineMessengingInvites(invites);
|
|
||||||
}
|
|
||||||
void p3Msgs::enableDistantMessaging(bool b)
|
void p3Msgs::enableDistantMessaging(bool b)
|
||||||
{
|
{
|
||||||
mMsgSrv->enableDistantMessaging(b);
|
mMsgSrv->enableDistantMessaging(b);
|
||||||
|
@ -116,10 +108,6 @@ bool p3Msgs::distantMessagingEnabled()
|
||||||
{
|
{
|
||||||
return mMsgSrv->distantMessagingEnabled();
|
return mMsgSrv->distantMessagingEnabled();
|
||||||
}
|
}
|
||||||
bool p3Msgs::getDistantMessagePeerId(const RsPgpId& pgp_id,DistantMsgPeerId &pid)
|
|
||||||
{
|
|
||||||
return mMsgSrv->getDistantMessagePeerId(pgp_id,pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
|
bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "retroshare/rsmsgs.h"
|
#include "retroshare/rsmsgs.h"
|
||||||
|
#include "retroshare/rsgxsifacetypes.h"
|
||||||
|
|
||||||
class p3MsgService;
|
class p3MsgService;
|
||||||
class p3ChatService;
|
class p3ChatService;
|
||||||
|
@ -80,12 +81,8 @@ class p3Msgs: public RsMsgs
|
||||||
|
|
||||||
virtual bool resetMessageStandardTagTypes(MsgTagType& tags);
|
virtual bool resetMessageStandardTagTypes(MsgTagType& tags);
|
||||||
|
|
||||||
virtual bool createDistantOfflineMessengingInvite(time_t, DistantMsgPeerId&) ;
|
|
||||||
virtual bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>&);
|
|
||||||
|
|
||||||
virtual void enableDistantMessaging(bool b) ;
|
virtual void enableDistantMessaging(bool b) ;
|
||||||
virtual bool distantMessagingEnabled() ;
|
virtual bool distantMessagingEnabled() ;
|
||||||
virtual bool getDistantMessagePeerId(const RsPgpId& pgp_id,DistantMsgPeerId& pid) ;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* gets avatar from peer, image data in jpeg format
|
* gets avatar from peer, image data in jpeg format
|
||||||
|
|
|
@ -56,6 +56,8 @@
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#define ENABLE_GROUTER
|
||||||
|
|
||||||
#if (defined(__unix__) || defined(unix)) && !defined(USG)
|
#if (defined(__unix__) || defined(unix)) && !defined(USG)
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,7 +71,7 @@
|
||||||
#include "pqi/sslfns.h"
|
#include "pqi/sslfns.h"
|
||||||
#include "pqi/authgpg.h"
|
#include "pqi/authgpg.h"
|
||||||
|
|
||||||
#ifdef GROUTER
|
#ifdef ENABLE_GROUTER
|
||||||
#include "grouter/p3grouter.h"
|
#include "grouter/p3grouter.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -839,7 +841,7 @@ bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
|
||||||
|
|
||||||
RsFiles *rsFiles = NULL;
|
RsFiles *rsFiles = NULL;
|
||||||
RsTurtle *rsTurtle = NULL ;
|
RsTurtle *rsTurtle = NULL ;
|
||||||
#ifdef GROUTER
|
#ifdef ENABLE_GROUTER
|
||||||
RsGRouter *rsGRouter = NULL ;
|
RsGRouter *rsGRouter = NULL ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1111,7 +1113,8 @@ int RsServer::StartupRetroShare()
|
||||||
* if not... copy from dataDirectory
|
* if not... copy from dataDirectory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!RsDirUtil::checkFile(bootstrapfile,true))
|
uint64_t tmp_size ;
|
||||||
|
if (!RsDirUtil::checkFile(bootstrapfile,tmp_size,true))
|
||||||
{
|
{
|
||||||
std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile << std::endl;
|
std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile << std::endl;
|
||||||
std::string installfile = rsAccounts.PathDataDirectory();
|
std::string installfile = rsAccounts.PathDataDirectory();
|
||||||
|
@ -1119,7 +1122,7 @@ int RsServer::StartupRetroShare()
|
||||||
installfile += BITDHT_BOOTSTRAP_FILENAME;
|
installfile += BITDHT_BOOTSTRAP_FILENAME;
|
||||||
|
|
||||||
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
|
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
|
||||||
if ((installfile != "") && (RsDirUtil::checkFile(installfile)))
|
if ((installfile != "") && (RsDirUtil::checkFile(installfile,tmp_size)))
|
||||||
{
|
{
|
||||||
std::cerr << "Copying Installation DHT bootstrap file..." << std::endl;
|
std::cerr << "Copying Installation DHT bootstrap file..." << std::endl;
|
||||||
if (RsDirUtil::copyFile(installfile, bootstrapfile))
|
if (RsDirUtil::copyFile(installfile, bootstrapfile))
|
||||||
|
@ -1295,67 +1298,6 @@ int RsServer::StartupRetroShare()
|
||||||
//
|
//
|
||||||
mPluginsManager->loadPlugins(programatically_inserted_plugins) ;
|
mPluginsManager->loadPlugins(programatically_inserted_plugins) ;
|
||||||
|
|
||||||
/* create Services */
|
|
||||||
p3ServiceInfo *serviceInfo = new p3ServiceInfo(serviceCtrl);
|
|
||||||
mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr, serviceCtrl);
|
|
||||||
mHeart = new p3heartbeat(serviceCtrl, pqih);
|
|
||||||
msgSrv = new p3MsgService(serviceCtrl);
|
|
||||||
chatSrv = new p3ChatService(serviceCtrl, mLinkMgr, mHistoryMgr);
|
|
||||||
mStatusSrv = new p3StatusService(serviceCtrl);
|
|
||||||
|
|
||||||
#ifdef GROUTER
|
|
||||||
p3GRouter *gr = new p3GRouter(mLinkMgr) ;
|
|
||||||
rsGRouter = gr ;
|
|
||||||
pqih->addService(gr, true) ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
p3turtle *tr = new p3turtle(mLinkMgr) ;
|
|
||||||
rsTurtle = tr ;
|
|
||||||
pqih -> addService(tr, true);
|
|
||||||
pqih -> addService(ftserver, true);
|
|
||||||
|
|
||||||
rsDisc = mDisc;
|
|
||||||
rsMsgs = new p3Msgs(msgSrv, chatSrv);
|
|
||||||
|
|
||||||
// connect components to turtle router.
|
|
||||||
|
|
||||||
ftserver->connectToTurtleRouter(tr) ;
|
|
||||||
chatSrv->connectToTurtleRouter(tr) ;
|
|
||||||
#ifdef GROUTER
|
|
||||||
msgSrv->connectToGlobalRouter(gr) ;
|
|
||||||
#endif
|
|
||||||
msgSrv->connectToTurtleRouter(tr) ;
|
|
||||||
|
|
||||||
pqih -> addService(serviceInfo, true);
|
|
||||||
pqih -> addService(mHeart, true);
|
|
||||||
pqih -> addService(mDisc, true);
|
|
||||||
pqih -> addService(msgSrv, true);
|
|
||||||
pqih -> addService(chatSrv, true);
|
|
||||||
pqih ->addService(mStatusSrv, true);
|
|
||||||
|
|
||||||
|
|
||||||
// set interfaces for plugins
|
|
||||||
//
|
|
||||||
RsPlugInInterfaces interfaces;
|
|
||||||
interfaces.mFiles = rsFiles;
|
|
||||||
interfaces.mPeers = rsPeers;
|
|
||||||
interfaces.mMsgs = rsMsgs;
|
|
||||||
interfaces.mTurtle = rsTurtle;
|
|
||||||
interfaces.mDisc = rsDisc;
|
|
||||||
interfaces.mDht = rsDht;
|
|
||||||
// don't exist no more.
|
|
||||||
//interfaces.mForums = mForums;
|
|
||||||
interfaces.mNotify = mNotify;
|
|
||||||
|
|
||||||
mPluginsManager->setInterfaces(interfaces);
|
|
||||||
|
|
||||||
// now add plugin objects inside the loop:
|
|
||||||
// - client services provided by plugins.
|
|
||||||
// - cache services provided by plugins.
|
|
||||||
//
|
|
||||||
mPluginsManager->registerClientServices(pqih) ;
|
|
||||||
mPluginsManager->registerCacheServices() ;
|
|
||||||
|
|
||||||
#ifdef RS_ENABLE_GXS
|
#ifdef RS_ENABLE_GXS
|
||||||
|
|
||||||
// The idea is that if priorGxsDir is non
|
// The idea is that if priorGxsDir is non
|
||||||
|
@ -1553,6 +1495,67 @@ int RsServer::StartupRetroShare()
|
||||||
|
|
||||||
#endif // RS_ENABLE_GXS.
|
#endif // RS_ENABLE_GXS.
|
||||||
|
|
||||||
|
/* create Services */
|
||||||
|
p3ServiceInfo *serviceInfo = new p3ServiceInfo(serviceCtrl);
|
||||||
|
mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr, serviceCtrl);
|
||||||
|
mHeart = new p3heartbeat(serviceCtrl, pqih);
|
||||||
|
msgSrv = new p3MsgService(serviceCtrl,mGxsIdService);
|
||||||
|
chatSrv = new p3ChatService(serviceCtrl, mLinkMgr, mHistoryMgr);
|
||||||
|
mStatusSrv = new p3StatusService(serviceCtrl);
|
||||||
|
|
||||||
|
#ifdef ENABLE_GROUTER
|
||||||
|
p3GRouter *gr = new p3GRouter(mLinkMgr) ;
|
||||||
|
rsGRouter = gr ;
|
||||||
|
pqih->addService(gr,true) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
p3turtle *tr = new p3turtle(mLinkMgr) ;
|
||||||
|
rsTurtle = tr ;
|
||||||
|
pqih -> addService(tr,true);
|
||||||
|
pqih -> addService(ftserver,true);
|
||||||
|
|
||||||
|
rsDisc = mDisc;
|
||||||
|
rsMsgs = new p3Msgs(msgSrv, chatSrv);
|
||||||
|
|
||||||
|
// connect components to turtle router.
|
||||||
|
|
||||||
|
ftserver->connectToTurtleRouter(tr) ;
|
||||||
|
chatSrv->connectToTurtleRouter(tr) ;
|
||||||
|
#ifdef ENABLE_GROUTER
|
||||||
|
msgSrv->connectToGlobalRouter(gr) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pqih -> addService(serviceInfo,true);
|
||||||
|
pqih -> addService(mHeart,true);
|
||||||
|
pqih -> addService(mDisc,true);
|
||||||
|
pqih -> addService(msgSrv,true);
|
||||||
|
pqih -> addService(chatSrv,true);
|
||||||
|
pqih ->addService(mStatusSrv,true);
|
||||||
|
|
||||||
|
|
||||||
|
// set interfaces for plugins
|
||||||
|
//
|
||||||
|
RsPlugInInterfaces interfaces;
|
||||||
|
interfaces.mFiles = rsFiles;
|
||||||
|
interfaces.mPeers = rsPeers;
|
||||||
|
interfaces.mMsgs = rsMsgs;
|
||||||
|
interfaces.mTurtle = rsTurtle;
|
||||||
|
interfaces.mDisc = rsDisc;
|
||||||
|
interfaces.mDht = rsDht;
|
||||||
|
// don't exist no more.
|
||||||
|
//interfaces.mForums = mForums;
|
||||||
|
interfaces.mNotify = mNotify;
|
||||||
|
|
||||||
|
mPluginsManager->setInterfaces(interfaces);
|
||||||
|
|
||||||
|
// now add plugin objects inside the loop:
|
||||||
|
// - client services provided by plugins.
|
||||||
|
// - cache services provided by plugins.
|
||||||
|
//
|
||||||
|
mPluginsManager->registerClientServices(pqih) ;
|
||||||
|
mPluginsManager->registerCacheServices() ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef RS_RTT
|
#ifdef RS_RTT
|
||||||
p3rtt *mRtt = new p3rtt(serviceCtrl);
|
p3rtt *mRtt = new p3rtt(serviceCtrl);
|
||||||
|
@ -1635,7 +1638,7 @@ int RsServer::StartupRetroShare()
|
||||||
mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr);
|
mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr);
|
||||||
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
|
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
|
||||||
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
||||||
#ifdef GROUTER
|
#ifdef ENABLE_GROUTER
|
||||||
mConfigMgr->addConfiguration("grouter.cfg", gr);
|
mConfigMgr->addConfiguration("grouter.cfg", gr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1380,9 +1380,13 @@ void RsMsgItem::clear()
|
||||||
subject.clear();
|
subject.clear();
|
||||||
message.clear();
|
message.clear();
|
||||||
|
|
||||||
msgto.TlvClear();
|
rspeerid_msgto.TlvClear();
|
||||||
msgcc.TlvClear();
|
rspeerid_msgcc.TlvClear();
|
||||||
msgbcc.TlvClear();
|
rspeerid_msgbcc.TlvClear();
|
||||||
|
|
||||||
|
rsgxsid_msgto.TlvClear();
|
||||||
|
rsgxsid_msgcc.TlvClear();
|
||||||
|
rsgxsid_msgbcc.TlvClear();
|
||||||
|
|
||||||
attachment.TlvClear();
|
attachment.TlvClear();
|
||||||
}
|
}
|
||||||
|
@ -1403,15 +1407,18 @@ std::ostream &RsMsgItem::print(std::ostream &out, uint16_t indent)
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
out << "Message To: " << std::endl;
|
out << "Message To: " << std::endl;
|
||||||
msgto.print(out, int_Indent);
|
rspeerid_msgto.print(out, int_Indent);
|
||||||
|
rsgxsid_msgto.print(out, int_Indent);
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
out << "Message CC: " << std::endl;
|
out << "Message CC: " << std::endl;
|
||||||
msgcc.print(out, int_Indent);
|
rspeerid_msgcc.print(out, int_Indent);
|
||||||
|
rsgxsid_msgcc.print(out, int_Indent);
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
out << "Message BCC: " << std::endl;
|
out << "Message BCC: " << std::endl;
|
||||||
msgbcc.print(out, int_Indent);
|
rspeerid_msgbcc.print(out, int_Indent);
|
||||||
|
rsgxsid_msgbcc.print(out, int_Indent);
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
std::string cnv_subject(subject.begin(), subject.end());
|
std::string cnv_subject(subject.begin(), subject.end());
|
||||||
|
@ -1514,9 +1521,14 @@ uint32_t RsMsgItem::serial_size(bool m_bConfiguration)
|
||||||
s += GetTlvStringSize(subject);
|
s += GetTlvStringSize(subject);
|
||||||
s += GetTlvStringSize(message);
|
s += GetTlvStringSize(message);
|
||||||
|
|
||||||
s += msgto.TlvSize();
|
s += rspeerid_msgto.TlvSize();
|
||||||
s += msgcc.TlvSize();
|
s += rspeerid_msgcc.TlvSize();
|
||||||
s += msgbcc.TlvSize();
|
s += rspeerid_msgbcc.TlvSize();
|
||||||
|
|
||||||
|
s += rsgxsid_msgto.TlvSize();
|
||||||
|
s += rsgxsid_msgcc.TlvSize();
|
||||||
|
s += rsgxsid_msgbcc.TlvSize();
|
||||||
|
|
||||||
s += attachment.TlvSize();
|
s += attachment.TlvSize();
|
||||||
|
|
||||||
if (m_bConfiguration) {
|
if (m_bConfiguration) {
|
||||||
|
@ -1558,9 +1570,13 @@ bool RsMsgItem::serialise(void *data, uint32_t& pktsize,bool config)
|
||||||
ok &= SetTlvString(data,tlvsize,&offset,TLV_TYPE_STR_SUBJECT,subject);
|
ok &= SetTlvString(data,tlvsize,&offset,TLV_TYPE_STR_SUBJECT,subject);
|
||||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message);
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message);
|
||||||
|
|
||||||
ok &= msgto.SetTlv(data, tlvsize, &offset);
|
ok &= rspeerid_msgto.SetTlv(data, tlvsize, &offset);
|
||||||
ok &= msgcc.SetTlv(data, tlvsize, &offset);
|
ok &= rspeerid_msgcc.SetTlv(data, tlvsize, &offset);
|
||||||
ok &= msgbcc.SetTlv(data, tlvsize, &offset);
|
ok &= rspeerid_msgbcc.SetTlv(data, tlvsize, &offset);
|
||||||
|
|
||||||
|
ok &= rsgxsid_msgto.SetTlv(data, tlvsize, &offset);
|
||||||
|
ok &= rsgxsid_msgcc.SetTlv(data, tlvsize, &offset);
|
||||||
|
ok &= rsgxsid_msgbcc.SetTlv(data, tlvsize, &offset);
|
||||||
|
|
||||||
ok &= attachment.SetTlv(data, tlvsize, &offset);
|
ok &= attachment.SetTlv(data, tlvsize, &offset);
|
||||||
|
|
||||||
|
@ -1614,9 +1630,14 @@ RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize)
|
||||||
|
|
||||||
ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_SUBJECT,item->subject);
|
ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_SUBJECT,item->subject);
|
||||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message);
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message);
|
||||||
ok &= item->msgto.GetTlv(data, rssize, &offset);
|
|
||||||
ok &= item->msgcc.GetTlv(data, rssize, &offset);
|
ok &= item->rspeerid_msgto.GetTlv(data, rssize, &offset);
|
||||||
ok &= item->msgbcc.GetTlv(data, rssize, &offset);
|
ok &= item->rspeerid_msgcc.GetTlv(data, rssize, &offset);
|
||||||
|
ok &= item->rspeerid_msgbcc.GetTlv(data, rssize, &offset);
|
||||||
|
ok &= item->rsgxsid_msgto.GetTlv(data, rssize, &offset);
|
||||||
|
ok &= item->rsgxsid_msgcc.GetTlv(data, rssize, &offset);
|
||||||
|
ok &= item->rsgxsid_msgbcc.GetTlv(data, rssize, &offset);
|
||||||
|
|
||||||
ok &= item->attachment.GetTlv(data, rssize, &offset);
|
ok &= item->attachment.GetTlv(data, rssize, &offset);
|
||||||
|
|
||||||
if (m_bConfiguration) {
|
if (m_bConfiguration) {
|
||||||
|
|
|
@ -458,11 +458,6 @@ class RsMsgItem: public RsMessageItem
|
||||||
public:
|
public:
|
||||||
RsMsgItem() :RsMessageItem(RS_PKT_SUBTYPE_DEFAULT) {}
|
RsMsgItem() :RsMessageItem(RS_PKT_SUBTYPE_DEFAULT) {}
|
||||||
|
|
||||||
// RsMsgItem(uint16_t type)
|
|
||||||
// :RsItem(RS_PKT_VERSION_SERVICE, type,
|
|
||||||
// RS_PKT_SUBTYPE_DEFAULT)
|
|
||||||
// { setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ; }
|
|
||||||
|
|
||||||
virtual ~RsMsgItem() {}
|
virtual ~RsMsgItem() {}
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
|
@ -482,9 +477,13 @@ class RsMsgItem: public RsMessageItem
|
||||||
std::string subject;
|
std::string subject;
|
||||||
std::string message;
|
std::string message;
|
||||||
|
|
||||||
RsTlvPeerIdSet msgto;
|
RsTlvPeerIdSet rspeerid_msgto;
|
||||||
RsTlvPeerIdSet msgcc;
|
RsTlvPeerIdSet rspeerid_msgcc;
|
||||||
RsTlvPeerIdSet msgbcc;
|
RsTlvPeerIdSet rspeerid_msgbcc;
|
||||||
|
|
||||||
|
RsTlvGxsIdSet rsgxsid_msgto;
|
||||||
|
RsTlvGxsIdSet rsgxsid_msgcc;
|
||||||
|
RsTlvGxsIdSet rsgxsid_msgbcc;
|
||||||
|
|
||||||
RsTlvFileSet attachment;
|
RsTlvFileSet attachment;
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,7 @@ const uint16_t RS_SERVICE_TYPE_TURTLE = 0x0014;
|
||||||
const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
|
const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
|
||||||
const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016;
|
const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016;
|
||||||
const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017;
|
const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017;
|
||||||
|
const uint16_t RS_SERVICE_TYPE_GROUTER = 0x0018;
|
||||||
|
|
||||||
/* BanList Still Testing at the moment - Service Only */
|
/* BanList Still Testing at the moment - Service Only */
|
||||||
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
||||||
|
|
|
@ -230,6 +230,7 @@ const uint16_t TLV_TYPE_HASHSET = 0x1022;
|
||||||
|
|
||||||
const uint16_t TLV_TYPE_PGPIDSET = 0x1023;
|
const uint16_t TLV_TYPE_PGPIDSET = 0x1023;
|
||||||
const uint16_t TLV_TYPE_RECOGNSET = 0x1024;
|
const uint16_t TLV_TYPE_RECOGNSET = 0x1024;
|
||||||
|
const uint16_t TLV_TYPE_GXSIDSET = 0x1025;
|
||||||
|
|
||||||
const uint16_t TLV_TYPE_SERVICESET = 0x1030;
|
const uint16_t TLV_TYPE_SERVICESET = 0x1030;
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include <serialiser/rstlvtypes.h>
|
#include <serialiser/rstlvtypes.h>
|
||||||
#include <serialiser/rstlvbase.h>
|
#include <serialiser/rstlvbase.h>
|
||||||
#include <serialiser/rsbaseserial.h>
|
#include <serialiser/rsbaseserial.h>
|
||||||
|
#include <retroshare/rsgxsifacetypes.h>
|
||||||
|
|
||||||
//! A base class for all tlv items
|
//! A base class for all tlv items
|
||||||
/*! This class is provided to allow the serialisation and deserialization of compund
|
/*! This class is provided to allow the serialisation and deserialization of compund
|
||||||
|
@ -193,6 +193,7 @@ template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
|
||||||
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
||||||
typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
|
typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
|
||||||
typedef t_RsTlvIdSet<Sha1CheckSum,TLV_TYPE_HASHSET> RsTlvHashSet ;
|
typedef t_RsTlvIdSet<Sha1CheckSum,TLV_TYPE_HASHSET> RsTlvHashSet ;
|
||||||
|
typedef t_RsTlvIdSet<RsGxsId,TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
|
||||||
|
|
||||||
class RsTlvServiceIdSet: public RsTlvItem
|
class RsTlvServiceIdSet: public RsTlvItem
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -43,79 +43,74 @@
|
||||||
#include "serialiser/rsmsgitems.h"
|
#include "serialiser/rsmsgitems.h"
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
#ifdef GROUTER
|
#include "retroshare/rsgxsifacetypes.h"
|
||||||
|
|
||||||
#include "grouter/p3grouter.h"
|
#include "grouter/p3grouter.h"
|
||||||
#include "grouter/grouterclientservice.h"
|
#include "grouter/grouterclientservice.h"
|
||||||
#endif
|
|
||||||
#include "turtle/p3turtle.h"
|
#include "turtle/p3turtle.h"
|
||||||
#include "turtle/turtleclientservice.h"
|
#include "turtle/turtleclientservice.h"
|
||||||
|
|
||||||
class p3LinkMgr;
|
class p3LinkMgr;
|
||||||
|
class p3IdService;
|
||||||
|
|
||||||
// Temp tweak to test grouter
|
// Temp tweak to test grouter
|
||||||
class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, public RsTurtleClientService
|
class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, public GRouterClientService
|
||||||
#ifdef GROUTER
|
|
||||||
, public GRouterClientService
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3MsgService(p3ServiceControl *sc);
|
p3MsgService(p3ServiceControl *sc, p3IdService *id_service);
|
||||||
virtual RsServiceInfo getServiceInfo();
|
virtual RsServiceInfo getServiceInfo();
|
||||||
|
|
||||||
/* External Interface */
|
/* External Interface */
|
||||||
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
||||||
bool getMessage(const std::string &mid, MessageInfo &msg);
|
bool getMessage(const std::string &mid, MessageInfo &msg);
|
||||||
void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox);
|
void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox);
|
||||||
|
|
||||||
bool decryptMessage(const std::string& mid) ;
|
bool decryptMessage(const std::string& mid) ;
|
||||||
bool removeMsgId(const std::string &mid);
|
bool removeMsgId(const std::string &mid);
|
||||||
bool markMsgIdRead(const std::string &mid, bool bUnreadByUser);
|
bool markMsgIdRead(const std::string &mid, bool bUnreadByUser);
|
||||||
bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask);
|
bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask);
|
||||||
bool getMsgParentId(const std::string &msgId, std::string &msgParentId);
|
bool getMsgParentId(const std::string &msgId, std::string &msgParentId);
|
||||||
// msgParentId == 0 --> remove
|
// msgParentId == 0 --> remove
|
||||||
bool setMsgParentId(uint32_t msgId, uint32_t msgParentId);
|
bool setMsgParentId(uint32_t msgId, uint32_t msgParentId);
|
||||||
|
|
||||||
bool MessageSend(MessageInfo &info);
|
bool MessageSend(MessageInfo &info);
|
||||||
bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
|
bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
|
||||||
bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
|
bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
|
||||||
bool MessageToTrash(const std::string &mid, bool bTrash);
|
bool MessageToTrash(const std::string &mid, bool bTrash);
|
||||||
|
|
||||||
bool getMessageTagTypes(MsgTagType& tags);
|
bool getMessageTagTypes(MsgTagType& tags);
|
||||||
bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color);
|
bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color);
|
||||||
bool removeMessageTagType(uint32_t tagId);
|
bool removeMessageTagType(uint32_t tagId);
|
||||||
|
|
||||||
bool getMessageTag(const std::string &msgId, MsgTagInfo& info);
|
bool getMessageTag(const std::string &msgId, MsgTagInfo& info);
|
||||||
/* set == false && tagId == 0 --> remove all */
|
/* set == false && tagId == 0 --> remove all */
|
||||||
bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set);
|
bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set);
|
||||||
|
|
||||||
bool resetMessageStandardTagTypes(MsgTagType& tags);
|
bool resetMessageStandardTagTypes(MsgTagType& tags);
|
||||||
|
|
||||||
void loadWelcomeMsg(); /* startup message */
|
void loadWelcomeMsg(); /* startup message */
|
||||||
|
|
||||||
//std::list<RsMsgItem *> &getMsgList();
|
//std::list<RsMsgItem *> &getMsgList();
|
||||||
//std::list<RsMsgItem *> &getMsgOutList();
|
//std::list<RsMsgItem *> &getMsgOutList();
|
||||||
|
|
||||||
int tick();
|
int tick();
|
||||||
int status();
|
int status();
|
||||||
|
|
||||||
/*** Overloaded from p3Config ****/
|
/*** Overloaded from p3Config ****/
|
||||||
virtual RsSerialiser *setupSerialiser();
|
virtual RsSerialiser *setupSerialiser();
|
||||||
virtual bool saveList(bool& cleanup, std::list<RsItem*>&);
|
virtual bool saveList(bool& cleanup, std::list<RsItem*>&);
|
||||||
virtual bool loadList(std::list<RsItem*>& load);
|
virtual bool loadList(std::list<RsItem*>& load);
|
||||||
virtual void saveDone();
|
virtual void saveDone();
|
||||||
/*** Overloaded from p3Config ****/
|
/*** Overloaded from p3Config ****/
|
||||||
|
|
||||||
/*** Overloaded from pqiMonitor ***/
|
/*** Overloaded from pqiMonitor ***/
|
||||||
virtual void statusChange(const std::list<pqiServicePeer> &plist);
|
virtual void statusChange(const std::list<pqiServicePeer> &plist);
|
||||||
int checkOutgoingMessages();
|
int checkOutgoingMessages();
|
||||||
/*** Overloaded from pqiMonitor ***/
|
/*** Overloaded from pqiMonitor ***/
|
||||||
|
|
||||||
/*** overloaded from p3turtle ***/
|
/*** overloaded from p3turtle ***/
|
||||||
|
|
||||||
#ifdef GROUTER
|
|
||||||
virtual void connectToGlobalRouter(p3GRouter *) ;
|
virtual void connectToGlobalRouter(p3GRouter *) ;
|
||||||
#endif
|
|
||||||
virtual void connectToTurtleRouter(p3turtle *) ;
|
|
||||||
|
|
||||||
struct DistantMessengingInvite
|
struct DistantMessengingInvite
|
||||||
{
|
{
|
||||||
|
@ -128,67 +123,51 @@ int checkOutgoingMessages();
|
||||||
uint32_t status ;
|
uint32_t status ;
|
||||||
bool pending_messages ;
|
bool pending_messages ;
|
||||||
};
|
};
|
||||||
bool createDistantOfflineMessengingInvite(time_t time_of_validity,DistantMsgPeerId &peer_id) ;
|
|
||||||
bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites) ;
|
|
||||||
|
|
||||||
void enableDistantMessaging(bool b) ;
|
void enableDistantMessaging(bool b) ;
|
||||||
bool distantMessagingEnabled() ;
|
bool distantMessagingEnabled() ;
|
||||||
bool getDistantMessagePeerId(const RsPgpId& pgp_id,DistantMsgPeerId &peer_id) ;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool getDistantMessageHash(const RsPgpId& pgp_id,Sha1CheckSum &hash) ;
|
void sendPrivateMsgItem(RsMsgItem *msgitem) ;
|
||||||
void sendPrivateMsgItem(const Sha1CheckSum& hash,RsMsgItem *) ;
|
|
||||||
|
|
||||||
// This maps contains the current invitations to respond to.
|
|
||||||
// The map is indexed by the hash
|
|
||||||
std::map<Sha1CheckSum,DistantMessengingInvite> _messenging_invites ;
|
|
||||||
|
|
||||||
// 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
|
||||||
std::map<Sha1CheckSum,DistantMessengingContact> _messenging_contacts ;
|
//
|
||||||
|
std::map<GRouterKeyId,DistantMessengingContact> _messenging_contacts ;
|
||||||
|
|
||||||
// Overloaded from RsTurtleClientService
|
// Overloaded from GRouterClientService
|
||||||
|
|
||||||
#ifdef GROUTER
|
virtual void receiveGRouterData(const GRouterKeyId& key,const RsGRouterGenericDataItem *item) ;
|
||||||
virtual void receiveGRouterData(RsGRouterGenericDataItem *item, const GRouterKeyId& key) ;
|
|
||||||
#endif
|
|
||||||
virtual bool handleTunnelRequest(const Sha1CheckSum& hash,const RsPeerId& peer_id) ;
|
|
||||||
// virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const Sha1CheckSum& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
|
||||||
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction /* dir */) {}
|
|
||||||
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) {}
|
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
|
||||||
bool encryptMessage(const RsPgpId& pgp_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 manageDistantPeers() ;
|
void manageDistantPeers() ;
|
||||||
void sendTurtleData(const Sha1CheckSum& hash,RsMsgItem *) ;
|
|
||||||
#ifdef GROUTER
|
|
||||||
void sendGRouterData(const Sha1CheckSum& hash,RsMsgItem *) ;
|
|
||||||
#endif
|
|
||||||
void handleIncomingItem(RsMsgItem *) ;
|
void handleIncomingItem(RsMsgItem *) ;
|
||||||
|
|
||||||
#ifdef GROUTER
|
uint32_t getNewUniqueMsgId();
|
||||||
p3GRouter *mGRouter ;
|
int sendMessage(RsMsgItem *item);
|
||||||
#endif
|
void checkSizeAndSendMessage(RsMsgItem *msg);
|
||||||
p3turtle *mTurtle ;
|
|
||||||
|
|
||||||
uint32_t getNewUniqueMsgId();
|
int incomingMsgs();
|
||||||
int sendMessage(RsMsgItem *item);
|
void processMsg(RsMsgItem *mi, bool incoming);
|
||||||
void checkSizeAndSendMessage(RsMsgItem *msg);
|
bool checkAndRebuildPartialMessage(RsMsgItem*) ;
|
||||||
|
|
||||||
int incomingMsgs();
|
void initRsMI(RsMsgItem *msg, MessageInfo &mi);
|
||||||
void processMsg(RsMsgItem *mi, bool incoming);
|
void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis);
|
||||||
bool checkAndRebuildPartialMessage(RsMsgItem*) ;
|
|
||||||
|
|
||||||
void initRsMI(RsMsgItem *msg, MessageInfo &mi);
|
RsMsgItem *initMIRsMsg(const MessageInfo &info, const RsPeerId& to);
|
||||||
void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis);
|
RsMsgItem *initMIRsMsg(const MessageInfo &info, const RsGxsId& to);
|
||||||
RsMsgItem *initMIRsMsg(MessageInfo &info, const RsPeerId &to);
|
void initMIRsMsg(RsMsgItem *item,const MessageInfo &info) ;
|
||||||
|
|
||||||
void initStandardTagTypes();
|
void initStandardTagTypes();
|
||||||
|
|
||||||
p3ServiceControl *mServiceCtrl;
|
p3ServiceControl *mServiceCtrl;
|
||||||
|
p3IdService *mIdService ;
|
||||||
|
p3GRouter *mGRouter ;
|
||||||
|
|
||||||
/* Mutex Required for stuff below */
|
/* Mutex Required for stuff below */
|
||||||
|
|
||||||
|
|
|
@ -294,7 +294,7 @@ bool RsDirUtil::copyFile(const std::string& source,const std::string& dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RsDirUtil::checkFile(const std::string& filename,bool disallow_empty_file)
|
bool RsDirUtil::checkFile(const std::string& filename,uint64_t& file_size,bool disallow_empty_file)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
mode_t st_mode;
|
mode_t st_mode;
|
||||||
|
@ -327,6 +327,8 @@ bool RsDirUtil::checkFile(const std::string& filename,bool disallow_empty_file)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_size = buf.st_size ;
|
||||||
|
|
||||||
if(disallow_empty_file && buf.st_size == 0)
|
if(disallow_empty_file && buf.st_size == 0)
|
||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ int breakupDirList(const std::string& path, std::list<std::string> &subdirs
|
||||||
|
|
||||||
bool copyFile(const std::string& source,const std::string& dest);
|
bool copyFile(const std::string& source,const std::string& dest);
|
||||||
bool fileExists(const std::string& file);
|
bool fileExists(const std::string& file);
|
||||||
bool checkFile(const std::string& filename,bool disallow_empty_file = false);
|
bool checkFile(const std::string& filename,uint64_t& file_size,bool disallow_empty_file = false);
|
||||||
bool checkDirectory(const std::string& dir);
|
bool checkDirectory(const std::string& dir);
|
||||||
bool checkCreateDirectory(const std::string& dir);
|
bool checkCreateDirectory(const std::string& dir);
|
||||||
|
|
||||||
|
|
|
@ -1114,19 +1114,28 @@ void MessagesDialog::insertMessages()
|
||||||
|
|
||||||
text.clear();
|
text.clear();
|
||||||
|
|
||||||
std::list<RsPeerId>::const_iterator pit;
|
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgto.begin(); pit != msgInfo.rspeerid_msgto.end(); pit++)
|
||||||
for (pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++)
|
|
||||||
{
|
{
|
||||||
if (text.isEmpty() == false) {
|
if (!text.isEmpty())
|
||||||
text += ", ";
|
text += ", ";
|
||||||
}
|
|
||||||
|
|
||||||
std::string peerName = rsPeers->getPeerName(*pit);
|
std::string peerName = rsPeers->getPeerName(*pit);
|
||||||
if (peerName.empty()) {
|
if (peerName.empty())
|
||||||
text += PeerDefs::rsid("", *pit);
|
text += PeerDefs::rsid("", *pit);
|
||||||
} else {
|
else
|
||||||
text += QString::fromUtf8(peerName.c_str());
|
text += QString::fromUtf8(peerName.c_str());
|
||||||
}
|
}
|
||||||
|
for(std::list<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgto.begin(); pit != msgInfo.rsgxsid_msgto.end(); pit++)
|
||||||
|
{
|
||||||
|
if (!text.isEmpty())
|
||||||
|
text += ", ";
|
||||||
|
|
||||||
|
// We should improve this by showing the real names of each GXS id.
|
||||||
|
std::string peerName = "GXS_id("+(*pit).toStdString() + ")" ;
|
||||||
|
if (peerName.empty())
|
||||||
|
text += PeerDefs::rsid("", *pit);
|
||||||
|
else
|
||||||
|
text += QString::fromUtf8(peerName.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl;
|
std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl;
|
||||||
|
|
|
@ -221,7 +221,7 @@ void NetworkDialog::connectTreeWidgetCostumPopupMenu( QPoint /*point*/ )
|
||||||
contextMnu->addAction(QIcon(IMAGE_EXPORT), tr("Export my certificate..."), this, SLOT(on_actionExportKey_activated()));
|
contextMnu->addAction(QIcon(IMAGE_EXPORT), tr("Export my certificate..."), this, SLOT(on_actionExportKey_activated()));
|
||||||
|
|
||||||
contextMnu->addAction(QIcon(IMAGE_PEERDETAILS), tr("Peer details..."), this, SLOT(peerdetails()));
|
contextMnu->addAction(QIcon(IMAGE_PEERDETAILS), tr("Peer details..."), this, SLOT(peerdetails()));
|
||||||
contextMnu->addAction(QIcon(IMAGE_MESSAGE), tr("Send Message"), this, SLOT(sendDistantMessage()));
|
//contextMnu->addAction(QIcon(IMAGE_MESSAGE), tr("Send Message"), this, SLOT(sendDistantMessage()));
|
||||||
contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
|
contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
|
||||||
contextMnu->addSeparator() ;
|
contextMnu->addSeparator() ;
|
||||||
contextMnu->addAction(QIcon(IMAGE_CLEAN_UNUSED), tr("Remove unused keys..."), this, SLOT(removeUnusedKeys()));
|
contextMnu->addAction(QIcon(IMAGE_CLEAN_UNUSED), tr("Remove unused keys..."), this, SLOT(removeUnusedKeys()));
|
||||||
|
@ -352,30 +352,30 @@ void NetworkDialog::copyLink()
|
||||||
RSLinkClipboard::copyLinks(urls);
|
RSLinkClipboard::copyLinks(urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDialog::sendDistantMessage()
|
//void NetworkDialog::sendDistantMessage()
|
||||||
{
|
//{
|
||||||
QTreeWidgetItem *wi = getCurrentNeighbour();
|
// QTreeWidgetItem *wi = getCurrentNeighbour();
|
||||||
if (wi == NULL) {
|
// if (wi == NULL) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
// MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
||||||
if (nMsgDialog == NULL) {
|
// if (nMsgDialog == NULL) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
DistantMsgPeerId pid ;
|
// DistantMsgPeerId pid ;
|
||||||
RsPgpId mGpgId(wi->text(COLUMN_PEERID).toStdString()) ;
|
// RsPgpId mGpgId(wi->text(COLUMN_PEERID).toStdString()) ;
|
||||||
|
//
|
||||||
if(rsMsgs->getDistantMessagePeerId(mGpgId,pid))
|
// if(rsMsgs->getDistantMessagePeerId(mGpgId,pid))
|
||||||
{
|
// {
|
||||||
nMsgDialog->addRecipient(MessageComposer::TO, pid, mGpgId);
|
// nMsgDialog->addRecipient(MessageComposer::TO, pid, mGpgId);
|
||||||
nMsgDialog->show();
|
// nMsgDialog->show();
|
||||||
nMsgDialog->activateWindow();
|
// nMsgDialog->activateWindow();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/* window will destroy itself! */
|
// /* window will destroy itself! */
|
||||||
}
|
//}
|
||||||
|
|
||||||
void NetworkDialog::updateDisplay()
|
void NetworkDialog::updateDisplay()
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,7 +72,7 @@ private slots:
|
||||||
// void deleteCert() ;
|
// void deleteCert() ;
|
||||||
void peerdetails();
|
void peerdetails();
|
||||||
void copyLink();
|
void copyLink();
|
||||||
void sendDistantMessage();
|
// void sendDistantMessage();
|
||||||
/** Create the context popup menu and it's submenus */
|
/** Create the context popup menu and it's submenus */
|
||||||
void connectTreeWidgetCostumPopupMenu( QPoint point );
|
void connectTreeWidgetCostumPopupMenu( QPoint point );
|
||||||
//void unvalidGPGKeyWidgetCostumPopupMenu( QPoint point );
|
//void unvalidGPGKeyWidgetCostumPopupMenu( QPoint point );
|
||||||
|
|
|
@ -565,7 +565,23 @@ bool RetroShareLink::createMessage(const RsPeerId& peerId, const QString& subjec
|
||||||
|
|
||||||
return valid();
|
return valid();
|
||||||
}
|
}
|
||||||
|
bool RetroShareLink::createMessage(const RsGxsId& peerId, const QString& subject)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
_hash = QString::fromStdString(peerId.toStdString());
|
||||||
|
|
||||||
|
//PeerDefs::rsidFromId(peerId, &_name);
|
||||||
|
_name = QString::fromStdString("GXS_id("+peerId.toStdString()+")") ;
|
||||||
|
// do something better here!!
|
||||||
|
_subject = subject;
|
||||||
|
|
||||||
|
_type = TYPE_MESSAGE;
|
||||||
|
|
||||||
|
check();
|
||||||
|
|
||||||
|
return valid();
|
||||||
|
}
|
||||||
void RetroShareLink::clear()
|
void RetroShareLink::clear()
|
||||||
{
|
{
|
||||||
_valid = false;
|
_valid = false;
|
||||||
|
@ -1507,13 +1523,14 @@ static void processList(const QStringList &list, const QString &textSingular, co
|
||||||
{
|
{
|
||||||
if (detail.accept_connection || RsPeerId(detail.id) == rsPeers->getOwnId() || RsPgpId(detail.gpg_id) == rsPeers->getGPGOwnId()) {
|
if (detail.accept_connection || RsPeerId(detail.id) == rsPeers->getOwnId() || RsPgpId(detail.gpg_id) == rsPeers->getGPGOwnId()) {
|
||||||
MessageComposer *msg = MessageComposer::newMsg();
|
MessageComposer *msg = MessageComposer::newMsg();
|
||||||
msg->addRecipient(MessageComposer::TO, detail.id, false);
|
msg->addRecipient(MessageComposer::TO, detail.id);
|
||||||
if (link.subject().isEmpty() == false) {
|
if (link.subject().isEmpty() == false) {
|
||||||
msg->setTitleText(link.subject());
|
msg->setTitleText(link.subject());
|
||||||
}
|
}
|
||||||
msg->show();
|
msg->show();
|
||||||
messageStarted.append(PeerDefs::nameWithLocation(detail));
|
messageStarted.append(PeerDefs::nameWithLocation(detail));
|
||||||
}
|
}
|
||||||
|
#ifdef SUSPENDED
|
||||||
else if(rsMsgs->getDistantMessagePeerId(detail.gpg_id,dm_pid))
|
else if(rsMsgs->getDistantMessagePeerId(detail.gpg_id,dm_pid))
|
||||||
{
|
{
|
||||||
MessageComposer *msg = MessageComposer::newMsg();
|
MessageComposer *msg = MessageComposer::newMsg();
|
||||||
|
@ -1526,6 +1543,7 @@ static void processList(const QStringList &list, const QString &textSingular, co
|
||||||
messageStarted.append(PeerDefs::nameWithLocation(detail));
|
messageStarted.append(PeerDefs::nameWithLocation(detail));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
messageReceipientNotAccepted.append(PeerDefs::nameWithLocation(detail));
|
messageReceipientNotAccepted.append(PeerDefs::nameWithLocation(detail));
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <retroshare/rstypes.h>
|
#include <retroshare/rstypes.h>
|
||||||
|
#include <retroshare/rsgxsifacetypes.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
@ -79,7 +80,8 @@ class RetroShareLink
|
||||||
bool createForum(const std::string& id, const std::string& msgId);
|
bool createForum(const std::string& id, const std::string& msgId);
|
||||||
bool createChannel(const std::string& id, const std::string& msgId);
|
bool createChannel(const std::string& id, const std::string& msgId);
|
||||||
bool createSearch(const QString& keywords);
|
bool createSearch(const QString& keywords);
|
||||||
bool createMessage(const RsPeerId& peerId, const QString& subject);
|
bool createMessage(const RsPeerId &peerId, const QString& subject);
|
||||||
|
bool createMessage(const RsGxsId &peerId, const QString& subject);
|
||||||
bool createCertificate(const RsPeerId &ssl_id) ;
|
bool createCertificate(const RsPeerId &ssl_id) ;
|
||||||
bool createPrivateChatInvite(time_t time_stamp,const QString& gpg_id,const QString& encrypted_chat_info) ;
|
bool createPrivateChatInvite(time_t time_stamp,const QString& gpg_id,const QString& encrypted_chat_info) ;
|
||||||
bool createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ;
|
bool createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ;
|
||||||
|
|
|
@ -1312,7 +1312,7 @@ void FriendList::msgfriend()
|
||||||
|
|
||||||
std::string id = getRsId(peer);
|
std::string id = getRsId(peer);
|
||||||
|
|
||||||
MessageComposer::msgFriend(RsPeerId(id), (peer->type() == TYPE_GROUP));
|
MessageComposer::msgFriend(RsPeerId(id)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendList::recommendfriend()
|
void FriendList::recommendfriend()
|
||||||
|
|
|
@ -46,6 +46,27 @@ std::list<RsPeerId> FriendSelectionDialog::selectFriends_SSL(QWidget *parent,con
|
||||||
|
|
||||||
return sids ;
|
return sids ;
|
||||||
}
|
}
|
||||||
|
std::list<RsGxsId> FriendSelectionDialog::selectFriends_GXS(QWidget *parent,const QString& caption,const QString& header_text,
|
||||||
|
FriendSelectionWidget::Modus modus,
|
||||||
|
FriendSelectionWidget::ShowTypes show_type,
|
||||||
|
const std::list<RsGxsId>& pre_selected_ids)
|
||||||
|
{
|
||||||
|
std::list<std::string> psids ;
|
||||||
|
for(std::list<RsGxsId>::const_iterator it(pre_selected_ids.begin());it!=pre_selected_ids.end();++it)
|
||||||
|
psids.push_back( (*it).toStdString() ) ;
|
||||||
|
|
||||||
|
FriendSelectionDialog dialog(parent,header_text,modus,show_type,FriendSelectionWidget::IDTYPE_SSL,psids) ;
|
||||||
|
|
||||||
|
dialog.setWindowTitle(caption) ;
|
||||||
|
|
||||||
|
if(QDialog::Rejected == dialog.exec())
|
||||||
|
return std::list<RsGxsId>() ;
|
||||||
|
|
||||||
|
std::list<RsGxsId> sids ;
|
||||||
|
dialog.friends_widget->selectedIds<RsGxsId,FriendSelectionWidget::IDTYPE_GXS>(sids,false) ;
|
||||||
|
|
||||||
|
return sids ;
|
||||||
|
}
|
||||||
FriendSelectionDialog::FriendSelectionDialog(QWidget *parent,const QString& header_text,
|
FriendSelectionDialog::FriendSelectionDialog(QWidget *parent,const QString& header_text,
|
||||||
FriendSelectionWidget::Modus modus,
|
FriendSelectionWidget::Modus modus,
|
||||||
FriendSelectionWidget::ShowTypes show_type,
|
FriendSelectionWidget::ShowTypes show_type,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <retroshare/rstypes.h>
|
#include <retroshare/rstypes.h>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
#include <gui/common/FriendSelectionWidget.h>
|
#include <gui/common/FriendSelectionWidget.h>
|
||||||
|
|
||||||
class FriendSelectionDialog : public QDialog
|
class FriendSelectionDialog : public QDialog
|
||||||
|
@ -9,13 +10,19 @@ class FriendSelectionDialog : public QDialog
|
||||||
public:
|
public:
|
||||||
static std::list<RsPgpId> selectFriends_PGP(QWidget *parent,const QString& caption,const QString& header_string,
|
static std::list<RsPgpId> selectFriends_PGP(QWidget *parent,const QString& caption,const QString& header_string,
|
||||||
FriendSelectionWidget::Modus modus = FriendSelectionWidget::MODUS_MULTI,
|
FriendSelectionWidget::Modus modus = FriendSelectionWidget::MODUS_MULTI,
|
||||||
FriendSelectionWidget::ShowTypes = FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL,
|
FriendSelectionWidget::ShowTypes = FriendSelectionWidget::SHOW_GROUP,
|
||||||
const std::list<RsPgpId>& pre_selected_ids = std::list<RsPgpId>()) ;
|
const std::list<RsPgpId>& pre_selected_ids = std::list<RsPgpId>()) ;
|
||||||
|
|
||||||
static std::list<RsPeerId> selectFriends_SSL(QWidget *parent,const QString& caption,const QString& header_string,
|
static std::list<RsPeerId> selectFriends_SSL(QWidget *parent,const QString& caption,const QString& header_string,
|
||||||
FriendSelectionWidget::Modus modus = FriendSelectionWidget::MODUS_MULTI,
|
FriendSelectionWidget::Modus modus = FriendSelectionWidget::MODUS_MULTI,
|
||||||
FriendSelectionWidget::ShowTypes = FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL,
|
FriendSelectionWidget::ShowTypes = FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL,
|
||||||
const std::list<RsPeerId>& pre_selected_ids = std::list<RsPeerId>()) ;
|
const std::list<RsPeerId>& pre_selected_ids = std::list<RsPeerId>()) ;
|
||||||
|
|
||||||
|
static std::list<RsGxsId> selectFriends_GXS(QWidget *parent,const QString& caption,const QString& header_string,
|
||||||
|
FriendSelectionWidget::Modus modus = FriendSelectionWidget::MODUS_MULTI,
|
||||||
|
FriendSelectionWidget::ShowTypes = FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_GXS,
|
||||||
|
const std::list<RsGxsId>& pre_selected_ids = std::list<RsGxsId>()) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~FriendSelectionDialog() ;
|
virtual ~FriendSelectionDialog() ;
|
||||||
FriendSelectionDialog(QWidget *parent,const QString& header_string,FriendSelectionWidget::Modus modus,FriendSelectionWidget::ShowTypes show_type,
|
FriendSelectionDialog(QWidget *parent,const QString& header_string,FriendSelectionWidget::Modus modus,FriendSelectionWidget::ShowTypes show_type,
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#define COLUMN_DATA 0
|
#define COLUMN_DATA 0
|
||||||
#define COLUMN_COUNT 1
|
#define COLUMN_COUNT 1
|
||||||
|
|
||||||
|
#define IDDIALOG_IDLIST 1
|
||||||
|
|
||||||
#define ROLE_ID Qt::UserRole
|
#define ROLE_ID Qt::UserRole
|
||||||
#define ROLE_SORT Qt::UserRole + 1
|
#define ROLE_SORT Qt::UserRole + 1
|
||||||
|
|
||||||
|
@ -73,9 +75,8 @@ static void setSelected(FriendSelectionWidget::Modus modus, QTreeWidgetItem *ite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) :
|
FriendSelectionWidget::FriendSelectionWidget(QWidget *parent)
|
||||||
QWidget(parent),
|
: RsGxsUpdateBroadcastPage(rsIdentity,parent), ui(new Ui::FriendSelectionWidget)
|
||||||
ui(new Ui::FriendSelectionWidget)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -87,6 +88,8 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) :
|
||||||
mInSslItemChanged = false;
|
mInSslItemChanged = false;
|
||||||
mInFillList = false;
|
mInFillList = false;
|
||||||
|
|
||||||
|
mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this);
|
||||||
|
|
||||||
connect(ui->friendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
connect(ui->friendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
||||||
connect(ui->friendList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int)));
|
connect(ui->friendList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int)));
|
||||||
connect(ui->friendList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int)));
|
connect(ui->friendList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int)));
|
||||||
|
@ -228,6 +231,34 @@ void FriendSelectionWidget::fillList()
|
||||||
secured_fillList() ;
|
secured_fillList() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendSelectionWidget::loadRequest(const TokenQueue */*queue*/, const TokenRequest &req)
|
||||||
|
{
|
||||||
|
// store all IDs locally, and call fillList() ;
|
||||||
|
|
||||||
|
uint32_t token = req.mToken ;
|
||||||
|
|
||||||
|
RsGxsIdGroup data;
|
||||||
|
std::vector<RsGxsIdGroup> datavector;
|
||||||
|
std::vector<RsGxsIdGroup>::iterator vit;
|
||||||
|
|
||||||
|
if (!rsIdentity->getGroupData(token, datavector))
|
||||||
|
{
|
||||||
|
std::cerr << "FriendSelectionWidget::loadRequest() ERROR. Cannot load data from rsIdentity." << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
gxsIds.clear() ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<datavector.size();++i)
|
||||||
|
{
|
||||||
|
gxsIds.push_back(datavector[i].mMeta.mGroupId) ;
|
||||||
|
std::cerr << " got ID = " << datavector[i].mMeta.mGroupId << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "Got all " << datavector.size() << " ids from rsIdentity. Calling update of list." << std::endl;
|
||||||
|
fillList() ;
|
||||||
|
}
|
||||||
|
|
||||||
void FriendSelectionWidget::secured_fillList()
|
void FriendSelectionWidget::secured_fillList()
|
||||||
{
|
{
|
||||||
mInFillList = true;
|
mInFillList = true;
|
||||||
|
@ -248,6 +279,10 @@ void FriendSelectionWidget::secured_fillList()
|
||||||
selectedIds<RsPgpId,IDTYPE_GPG>(gpgIdsSelected,true);
|
selectedIds<RsPgpId,IDTYPE_GPG>(gpgIdsSelected,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<RsGxsId> gxsIdsSelected;
|
||||||
|
if (mShowTypes & SHOW_GXS)
|
||||||
|
selectedIds<RsGxsId,IDTYPE_GXS>(gxsIdsSelected,true);
|
||||||
|
|
||||||
// remove old items
|
// remove old items
|
||||||
ui->friendList->clear();
|
ui->friendList->clear();
|
||||||
|
|
||||||
|
@ -282,9 +317,11 @@ void FriendSelectionWidget::secured_fillList()
|
||||||
while (true) {
|
while (true) {
|
||||||
QTreeWidgetItem *groupItem = NULL;
|
QTreeWidgetItem *groupItem = NULL;
|
||||||
QTreeWidgetItem *gpgItem = NULL;
|
QTreeWidgetItem *gpgItem = NULL;
|
||||||
|
QTreeWidgetItem *gxsItem = NULL;
|
||||||
RsGroupInfo *groupInfo = NULL;
|
RsGroupInfo *groupInfo = NULL;
|
||||||
|
|
||||||
if ((mShowTypes & SHOW_GROUP) && groupIt != groupInfoList.end()) {
|
if ((mShowTypes & SHOW_GROUP) && groupIt != groupInfoList.end())
|
||||||
|
{
|
||||||
groupInfo = &(*groupIt);
|
groupInfo = &(*groupIt);
|
||||||
|
|
||||||
if (groupInfo->peerIds.size() == 0) {
|
if (groupInfo->peerIds.size() == 0) {
|
||||||
|
@ -323,7 +360,8 @@ void FriendSelectionWidget::secured_fillList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) {
|
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG))
|
||||||
|
{
|
||||||
// iterate through gpg ids
|
// iterate through gpg ids
|
||||||
for (gpgIt = gpgIds.begin(); gpgIt != gpgIds.end(); gpgIt++) {
|
for (gpgIt = gpgIds.begin(); gpgIt != gpgIds.end(); gpgIt++) {
|
||||||
if (groupInfo) {
|
if (groupInfo) {
|
||||||
|
@ -422,7 +460,9 @@ void FriendSelectionWidget::secured_fillList()
|
||||||
setSelected(mListModus, gpgItem, true);
|
setSelected(mListModus, gpgItem, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// iterate through ssl ids
|
// iterate through ssl ids
|
||||||
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) {
|
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) {
|
||||||
RsPeerDetails detail;
|
RsPeerDetails detail;
|
||||||
|
@ -470,6 +510,47 @@ void FriendSelectionWidget::secured_fillList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mShowTypes & SHOW_GXS)
|
||||||
|
{
|
||||||
|
// iterate through gpg ids
|
||||||
|
for (std::vector<RsGxsGroupId>::const_iterator gxsIt = gxsIds.begin(); gxsIt != gxsIds.end(); gxsIt++)
|
||||||
|
{
|
||||||
|
// we fill the not assigned gpg ids
|
||||||
|
if (std::find(filledIds.begin(), filledIds.end(), (*gxsIt).toStdString()) != filledIds.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// add equal too, its no problem
|
||||||
|
filledIds.push_back((*gxsIt).toStdString());
|
||||||
|
|
||||||
|
RsIdentityDetails detail;
|
||||||
|
if (!rsIdentity->getIdDetails(RsGxsId(*gxsIt), detail))
|
||||||
|
continue; /* BAD */
|
||||||
|
|
||||||
|
// make a widget per friend
|
||||||
|
gxsItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GXS);
|
||||||
|
|
||||||
|
QString name = QString::fromUtf8(detail.mNickname.c_str());
|
||||||
|
gxsItem->setText(COLUMN_NAME, name + " ("+QString::fromStdString( (*gxsIt).toStdString() )+")");
|
||||||
|
|
||||||
|
gxsItem->setTextColor(COLUMN_NAME, textColorOnline());
|
||||||
|
gxsItem->setFlags(Qt::ItemIsUserCheckable | gxsItem->flags());
|
||||||
|
gxsItem->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(RS_STATUS_ONLINE)));
|
||||||
|
gxsItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.mId.toStdString()));
|
||||||
|
gxsItem->setData(COLUMN_DATA, ROLE_SORT, "2 " + name);
|
||||||
|
|
||||||
|
if (mListModus == MODUS_CHECK)
|
||||||
|
gxsItem->setCheckState(0, Qt::Unchecked);
|
||||||
|
|
||||||
|
ui->friendList->addTopLevelItem(gxsItem);
|
||||||
|
|
||||||
|
gxsItem->setExpanded(true);
|
||||||
|
|
||||||
|
emit itemAdded(IDTYPE_GXS, QString::fromStdString(detail.mId.toStdString()), gxsItem);
|
||||||
|
|
||||||
|
if (std::find(gxsIdsSelected.begin(), gxsIdsSelected.end(), detail.mId) != gxsIdsSelected.end())
|
||||||
|
setSelected(mListModus, gxsItem, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (groupIt != groupInfoList.end()) {
|
if (groupIt != groupInfoList.end()) {
|
||||||
groupIt++;
|
groupIt++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -488,6 +569,29 @@ void FriendSelectionWidget::secured_fillList()
|
||||||
|
|
||||||
emit contentChanged();
|
emit contentChanged();
|
||||||
}
|
}
|
||||||
|
void FriendSelectionWidget::updateDisplay(bool)
|
||||||
|
{
|
||||||
|
requestGXSIdList() ;
|
||||||
|
}
|
||||||
|
void FriendSelectionWidget::requestGXSIdList()
|
||||||
|
{
|
||||||
|
if (!mIdQueue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//mStateHelper->setLoading(IDDIALOG_IDLIST, true);
|
||||||
|
//mStateHelper->setLoading(IDDIALOG_IDDETAILS, true);
|
||||||
|
//mStateHelper->setLoading(IDDIALOG_REPLIST, true);
|
||||||
|
|
||||||
|
mIdQueue->cancelActiveRequestTokens(IDDIALOG_IDLIST);
|
||||||
|
|
||||||
|
RsTokReqOptions opts;
|
||||||
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||||
|
|
||||||
|
uint32_t token;
|
||||||
|
|
||||||
|
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, IDDIALOG_IDLIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void FriendSelectionWidget::groupsChanged(int /*type*/)
|
void FriendSelectionWidget::groupsChanged(int /*type*/)
|
||||||
{
|
{
|
||||||
|
@ -657,6 +761,7 @@ void FriendSelectionWidget::itemChanged(QTreeWidgetItem *item, int column)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IDTYPE_GPG:
|
case IDTYPE_GPG:
|
||||||
|
case IDTYPE_GXS:
|
||||||
{
|
{
|
||||||
if (mInGpgItemChanged) {
|
if (mInGpgItemChanged) {
|
||||||
break;
|
break;
|
||||||
|
@ -790,7 +895,9 @@ void FriendSelectionWidget::selectedIds(IdType idType, std::list<std::string> &i
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IDTYPE_GPG:
|
case IDTYPE_GPG:
|
||||||
if (idType == IDTYPE_GPG) {
|
case IDTYPE_GXS:
|
||||||
|
if (idType == IDTYPE_GPG || idType == IDTYPE_GXS)
|
||||||
|
{
|
||||||
if (isSelected(mListModus, item)) {
|
if (isSelected(mListModus, item)) {
|
||||||
id = idFromItem(item);
|
id = idFromItem(item);
|
||||||
} else {
|
} else {
|
||||||
|
@ -858,6 +965,7 @@ void FriendSelectionWidget::setSelectedIds(IdType idType, const std::list<std::s
|
||||||
case IDTYPE_GROUP:
|
case IDTYPE_GROUP:
|
||||||
case IDTYPE_GPG:
|
case IDTYPE_GPG:
|
||||||
case IDTYPE_SSL:
|
case IDTYPE_SSL:
|
||||||
|
case IDTYPE_GXS:
|
||||||
if (idType == itemType) {
|
if (idType == itemType) {
|
||||||
if (std::find(ids.begin(), ids.end(), id) != ids.end()) {
|
if (std::find(ids.begin(), ids.end(), id) != ids.end()) {
|
||||||
setSelected(mListModus, item, true);
|
setSelected(mListModus, item, true);
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include <gui/gxs/RsGxsUpdateBroadcastPage.h>
|
||||||
|
#include "util/TokenQueue.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class FriendSelectionWidget;
|
class FriendSelectionWidget;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +36,7 @@ class FriendSelectionWidget;
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
class RSTreeWidgetItemCompareRole;
|
class RSTreeWidgetItemCompareRole;
|
||||||
|
|
||||||
class FriendSelectionWidget : public QWidget
|
class FriendSelectionWidget : public RsGxsUpdateBroadcastPage, public TokenResponse
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -45,7 +48,8 @@ public:
|
||||||
IDTYPE_NONE,
|
IDTYPE_NONE,
|
||||||
IDTYPE_GROUP,
|
IDTYPE_GROUP,
|
||||||
IDTYPE_SSL,
|
IDTYPE_SSL,
|
||||||
IDTYPE_GPG
|
IDTYPE_GPG,
|
||||||
|
IDTYPE_GXS
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Modus
|
enum Modus
|
||||||
|
@ -61,6 +65,7 @@ public:
|
||||||
SHOW_GPG = 2,
|
SHOW_GPG = 2,
|
||||||
SHOW_SSL = 4,
|
SHOW_SSL = 4,
|
||||||
SHOW_NON_FRIEND_GPG = 8,
|
SHOW_NON_FRIEND_GPG = 8,
|
||||||
|
SHOW_GXS =16
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_FLAGS(ShowTypes, ShowType)
|
Q_DECLARE_FLAGS(ShowTypes, ShowType)
|
||||||
|
@ -107,6 +112,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
|
|
||||||
|
virtual void loadRequest(const TokenQueue *queue,const TokenRequest& req);
|
||||||
|
virtual void updateDisplay(bool complete);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemAdded(int idType, const QString &id, QTreeWidgetItem *item);
|
void itemAdded(int idType, const QString &id, QTreeWidgetItem *item);
|
||||||
void contentChanged();
|
void contentChanged();
|
||||||
|
@ -132,6 +140,8 @@ private:
|
||||||
void selectedIds(IdType idType, std::list<std::string> &ids, bool onlyDirectSelected);
|
void selectedIds(IdType idType, std::list<std::string> &ids, bool onlyDirectSelected);
|
||||||
void setSelectedIds(IdType idType, const std::list<std::string> &ids, bool add);
|
void setSelectedIds(IdType idType, const std::list<std::string> &ids, bool add);
|
||||||
|
|
||||||
|
void requestGXSIdList() ;
|
||||||
|
|
||||||
bool mStarted;
|
bool mStarted;
|
||||||
RSTreeWidgetItemCompareRole *mCompareRole;
|
RSTreeWidgetItemCompareRole *mCompareRole;
|
||||||
Modus mListModus;
|
Modus mListModus;
|
||||||
|
@ -147,6 +157,9 @@ private:
|
||||||
Ui::FriendSelectionWidget *ui;
|
Ui::FriendSelectionWidget *ui;
|
||||||
|
|
||||||
friend class FriendSelectionDialog ;
|
friend class FriendSelectionDialog ;
|
||||||
|
|
||||||
|
std::vector<RsGxsGroupId> gxsIds ;
|
||||||
|
TokenQueue *mIdQueue ;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(FriendSelectionWidget::ShowTypes)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(FriendSelectionWidget::ShowTypes)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
#include <retroshare/rsmsgs.h>
|
#include <retroshare/rsmsgs.h>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
||||||
#include "PeerDefs.h"
|
#include "PeerDefs.h"
|
||||||
|
|
||||||
|
@ -42,6 +43,14 @@ const QString PeerDefs::rsid(const std::string &name, const RsPgpId &id)
|
||||||
|
|
||||||
return QString::fromUtf8(name.c_str()) + "@" + QString::fromStdString(id.toStdString());
|
return QString::fromUtf8(name.c_str()) + "@" + QString::fromStdString(id.toStdString());
|
||||||
}
|
}
|
||||||
|
const QString PeerDefs::rsid(const std::string &name, const RsGxsId &id)
|
||||||
|
{
|
||||||
|
if (name.empty()) {
|
||||||
|
return qApp->translate("PeerDefs", "Unknown") + "@" + QString::fromStdString(id.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString::fromUtf8(name.c_str()) + "@" + QString::fromStdString(id.toStdString());
|
||||||
|
}
|
||||||
const QString PeerDefs::rsid(const std::string &name, const RsPeerId &id)
|
const QString PeerDefs::rsid(const std::string &name, const RsPeerId &id)
|
||||||
{
|
{
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
|
@ -66,26 +75,36 @@ const QString PeerDefs::rsidFromId(const RsPeerId &id, QString *name /* = NULL*/
|
||||||
{
|
{
|
||||||
rsid = PeerDefs::rsid(peerName, id);
|
rsid = PeerDefs::rsid(peerName, id);
|
||||||
|
|
||||||
if (name) {
|
if (name)
|
||||||
*name = QString::fromUtf8(peerName.c_str());
|
*name = QString::fromUtf8(peerName.c_str());
|
||||||
|
|
||||||
|
return rsid ;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(rsMsgs->getDistantMessagePeerId(rsPeers->getGPGOwnId(),pid) && pid == id)
|
std::list<RsGxsId> gxs_ids ;
|
||||||
|
rsIdentity->getOwnIds(gxs_ids) ;
|
||||||
|
|
||||||
|
for(std::list<RsGxsId>::const_iterator it(gxs_ids.begin());it!=gxs_ids.end();++it)
|
||||||
|
if(RsPeerId(*it) == id)
|
||||||
{
|
{
|
||||||
// not a real peer. Try from hash for distant messages
|
// not a real peer. Try from hash for distant messages
|
||||||
|
|
||||||
peerName = rsPeers->getGPGName(rsPeers->getGPGOwnId()) ;
|
RsIdentityDetails details ;
|
||||||
rsid = PeerDefs::rsid(peerName, rsPeers->getGPGOwnId());
|
if(!rsIdentity->getIdDetails(*it,details))
|
||||||
|
continue ;
|
||||||
|
|
||||||
|
peerName = details.mNickname ;
|
||||||
|
|
||||||
|
rsid = PeerDefs::rsid(peerName, *it);
|
||||||
if(name)
|
if(name)
|
||||||
*name = QString::fromUtf8(peerName.c_str());
|
*name = QString::fromUtf8(peerName.c_str());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
rsid = PeerDefs::rsid("", id);
|
rsid = PeerDefs::rsid("", id);
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
*name = qApp->translate("PeerDefs", "Unknown");
|
*name = qApp->translate("PeerDefs", "Unknown");
|
||||||
}
|
|
||||||
|
|
||||||
return rsid;
|
return rsid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define _PEERDEFS_H
|
#define _PEERDEFS_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
||||||
class RsPeerDetails;
|
class RsPeerDetails;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public:
|
||||||
static const QString rsid(const RsPeerDetails &details);
|
static const QString rsid(const RsPeerDetails &details);
|
||||||
static const QString rsid(const std::string &name, const RsPeerId &id);
|
static const QString rsid(const std::string &name, const RsPeerId &id);
|
||||||
static const QString rsid(const std::string &name, const RsPgpId &id);
|
static const QString rsid(const std::string &name, const RsPgpId &id);
|
||||||
|
static const QString rsid(const std::string &name, const RsGxsId &id);
|
||||||
static const QString rsidFromId(const RsPgpId &id, QString *name = NULL);
|
static const QString rsidFromId(const RsPgpId &id, QString *name = NULL);
|
||||||
static const QString rsidFromId(const RsPeerId &id, QString *name = NULL);
|
static const QString rsidFromId(const RsPeerId &id, QString *name = NULL);
|
||||||
static RsPeerId idFromRsid(const QString &rsid, bool check);
|
static RsPeerId idFromRsid(const QString &rsid, bool check);
|
||||||
|
|
|
@ -197,7 +197,7 @@ void ChatMsgItem::sendMsg()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId, false);
|
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId);
|
||||||
nMsgDialog->show();
|
nMsgDialog->show();
|
||||||
nMsgDialog->activateWindow();
|
nMsgDialog->activateWindow();
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ void ChatMsgItem::sendMessage()
|
||||||
|
|
||||||
mi.title = tr("Quick Message").toUtf8().constData();
|
mi.title = tr("Quick Message").toUtf8().constData();
|
||||||
mi.msg = quickmsgText->toHtml().toUtf8().constData();
|
mi.msg = quickmsgText->toHtml().toUtf8().constData();
|
||||||
mi.msgto.push_back(mPeerId);
|
mi.rspeerid_msgto.push_back(mPeerId);
|
||||||
|
|
||||||
rsMsgs->MessageSend(mi);
|
rsMsgs->MessageSend(mi);
|
||||||
|
|
||||||
|
|
|
@ -81,16 +81,16 @@ void MsgItem::updateItemStatic()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* get peer Id */
|
/* get peer Id */
|
||||||
mPeerId = mi.srcId;
|
mPeerId = mi.rspeerid_srcId;
|
||||||
|
|
||||||
avatar->setId(mPeerId);
|
avatar->setId(mPeerId);
|
||||||
|
|
||||||
QString title;
|
QString title;
|
||||||
QString srcName;
|
QString srcName;
|
||||||
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.srcId == rsPeers->getOwnId()) {
|
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.rspeerid_srcId == rsPeers->getOwnId()) {
|
||||||
srcName = "RetroShare";
|
srcName = "RetroShare";
|
||||||
} else {
|
} else {
|
||||||
srcName = QString::fromUtf8(rsPeers->getPeerName(mi.srcId).c_str());
|
srcName = QString::fromUtf8(rsPeers->getPeerName(mi.rspeerid_srcId).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
timestampLabel->setText(DateTime::formatLongDateTime(mi.ts));
|
timestampLabel->setText(DateTime::formatLongDateTime(mi.ts));
|
||||||
|
@ -138,7 +138,7 @@ void MsgItem::updateItemStatic()
|
||||||
for(it = mi.files.begin(); it != mi.files.end(); it++)
|
for(it = mi.files.begin(); it != mi.files.end(); it++)
|
||||||
{
|
{
|
||||||
/* add file */
|
/* add file */
|
||||||
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->path, it->size, SFI_STATE_REMOTE, mi.srcId);
|
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->path, it->size, SFI_STATE_REMOTE, mi.rspeerid_srcId);
|
||||||
mFileItems.push_back(fi);
|
mFileItems.push_back(fi);
|
||||||
|
|
||||||
QLayout *layout = expandFrame->layout();
|
QLayout *layout = expandFrame->layout();
|
||||||
|
|
|
@ -275,7 +275,7 @@ void PeerItem::sendMsg()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId, false);
|
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId);
|
||||||
nMsgDialog->show();
|
nMsgDialog->show();
|
||||||
nMsgDialog->activateWindow();
|
nMsgDialog->activateWindow();
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ void PeerItem::sendMessage()
|
||||||
|
|
||||||
mi.title = tr("Quick Message").toUtf8().constData();
|
mi.title = tr("Quick Message").toUtf8().constData();
|
||||||
mi.msg = quickmsgText->toHtml().toUtf8().constData();
|
mi.msg = quickmsgText->toHtml().toUtf8().constData();
|
||||||
mi.msgto.push_back(mPeerId);
|
mi.rspeerid_msgto.push_back(mPeerId);
|
||||||
|
|
||||||
rsMsgs->MessageSend(mi);
|
rsMsgs->MessageSend(mi);
|
||||||
|
|
||||||
|
|
|
@ -375,6 +375,8 @@ void SecurityItem::sendMsg()
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << ": suspended for now." << std::endl;
|
||||||
|
#ifdef SUSPENDED
|
||||||
MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
||||||
if (nMsgDialog == NULL) {
|
if (nMsgDialog == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -390,6 +392,7 @@ void SecurityItem::sendMsg()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* window will destroy itself! */
|
/* window will destroy itself! */
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SecurityItem::openChat()
|
void SecurityItem::openChat()
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <retroshare/rsmsgs.h>
|
#include <retroshare/rsmsgs.h>
|
||||||
#include <retroshare/rsstatus.h>
|
#include <retroshare/rsstatus.h>
|
||||||
#include <retroshare/rsfiles.h>
|
#include <retroshare/rsfiles.h>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
||||||
#include "gui/notifyqt.h"
|
#include "gui/notifyqt.h"
|
||||||
#include "gui/common/RSTreeWidgetItem.h"
|
#include "gui/common/RSTreeWidgetItem.h"
|
||||||
|
@ -73,9 +74,6 @@
|
||||||
|
|
||||||
#define COLOR_CONNECT Qt::blue
|
#define COLOR_CONNECT Qt::blue
|
||||||
|
|
||||||
#define TYPE_GROUP 0
|
|
||||||
#define TYPE_SSL 1
|
|
||||||
|
|
||||||
#define COLUMN_RECIPIENT_TYPE 0
|
#define COLUMN_RECIPIENT_TYPE 0
|
||||||
#define COLUMN_RECIPIENT_ICON 1
|
#define COLUMN_RECIPIENT_ICON 1
|
||||||
#define COLUMN_RECIPIENT_NAME 2
|
#define COLUMN_RECIPIENT_NAME 2
|
||||||
|
@ -83,7 +81,7 @@
|
||||||
#define COLUMN_RECIPIENT_DATA COLUMN_RECIPIENT_ICON // the column with a QTableWidgetItem
|
#define COLUMN_RECIPIENT_DATA COLUMN_RECIPIENT_ICON // the column with a QTableWidgetItem
|
||||||
|
|
||||||
#define ROLE_RECIPIENT_ID Qt::UserRole
|
#define ROLE_RECIPIENT_ID Qt::UserRole
|
||||||
#define ROLE_RECIPIENT_GROUP Qt::UserRole + 1
|
#define ROLE_RECIPIENT_TYPE Qt::UserRole + 1
|
||||||
|
|
||||||
#define COLUMN_FILE_CHECKED 0
|
#define COLUMN_FILE_CHECKED 0
|
||||||
#define COLUMN_FILE_NAME 0
|
#define COLUMN_FILE_NAME 0
|
||||||
|
@ -215,7 +213,8 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags)
|
||||||
ui.friendSelectionWidget->setModus(FriendSelectionWidget::MODUS_MULTI);
|
ui.friendSelectionWidget->setModus(FriendSelectionWidget::MODUS_MULTI);
|
||||||
ui.friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_GROUP
|
ui.friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_GROUP
|
||||||
| FriendSelectionWidget::SHOW_SSL
|
| FriendSelectionWidget::SHOW_SSL
|
||||||
| (ui.onlyTrustedKeys->isChecked()? FriendSelectionWidget::SHOW_NONE : FriendSelectionWidget::SHOW_NON_FRIEND_GPG));
|
| FriendSelectionWidget::SHOW_GXS);
|
||||||
|
//| (ui.onlyTrustedKeys->isChecked()? FriendSelectionWidget::SHOW_NONE : FriendSelectionWidget::SHOW_NON_FRIEND_GPG));
|
||||||
//ui.friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL );
|
//ui.friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL );
|
||||||
ui.friendSelectionWidget->start();
|
ui.friendSelectionWidget->start();
|
||||||
|
|
||||||
|
@ -359,29 +358,27 @@ void MessageComposer::processSettings(bool bLoad)
|
||||||
|
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
}
|
}
|
||||||
/*static*/ void MessageComposer::msgDistantPeer(const RsPgpId& pgp_id)
|
|
||||||
|
/*static*/ void MessageComposer::msgGxsIdentity(const RsGxsId &id)
|
||||||
{
|
{
|
||||||
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
|
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
|
||||||
|
|
||||||
/* create a message */
|
/* create a message */
|
||||||
|
|
||||||
DistantMsgPeerId pid ;
|
|
||||||
rsMsgs->getDistantMessagePeerId(pgp_id,pid) ;
|
|
||||||
|
|
||||||
MessageComposer *pMsgDialog = MessageComposer::newMsg();
|
MessageComposer *pMsgDialog = MessageComposer::newMsg();
|
||||||
|
|
||||||
if (pMsgDialog == NULL)
|
if (pMsgDialog == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pMsgDialog->addRecipient(TO,pid,pgp_id) ;
|
pMsgDialog->addRecipient(TO, id);
|
||||||
pMsgDialog->show();
|
pMsgDialog->show();
|
||||||
|
|
||||||
/* window will destroy itself! */
|
/* window will destroy itself! */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/ void MessageComposer::msgFriend(const RsPeerId &id)
|
||||||
/*static*/ void MessageComposer::msgFriend(const RsPeerId &id, bool group)
|
|
||||||
{
|
{
|
||||||
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
|
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
|
||||||
|
|
||||||
/* create a message */
|
/* create a message */
|
||||||
|
|
||||||
|
@ -390,25 +387,10 @@ void MessageComposer::processSettings(bool bLoad)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group) {
|
|
||||||
pMsgDialog->addRecipient(TO, id, true);
|
|
||||||
} else {
|
|
||||||
RsPeerDetails detail;
|
RsPeerDetails detail;
|
||||||
if (rsPeers->getPeerDetails(id, detail) && detail.accept_connection)
|
if (rsPeers->getPeerDetails(id, detail) && detail.accept_connection)
|
||||||
{
|
{
|
||||||
// if (detail.isOnlyGPGdetail) {
|
pMsgDialog->addRecipient(TO, id);
|
||||||
// //put all sslChilds in message list
|
|
||||||
// std::list<RsPeerId> sslIds;
|
|
||||||
// rsPeers->getAssociatedSSLIds(id, sslIds);
|
|
||||||
//
|
|
||||||
// std::list<RsPeerId>::const_iterator it;
|
|
||||||
// for (it = sslIds.begin(); it != sslIds.end(); it++) {
|
|
||||||
// pMsgDialog->addRecipient(TO, *it, false);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
pMsgDialog->addRecipient(TO, detail.id, false);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pMsgDialog->show();
|
pMsgDialog->show();
|
||||||
|
@ -460,7 +442,7 @@ void MessageComposer::recommendFriend(const std::list <RsPeerId> &sslIds, const
|
||||||
composer->msgFlags |= RS_MSG_FRIEND_RECOMMENDATION;
|
composer->msgFlags |= RS_MSG_FRIEND_RECOMMENDATION;
|
||||||
|
|
||||||
if (!to.isNull()) {
|
if (!to.isNull()) {
|
||||||
composer->addRecipient(TO, to, false);
|
composer->addRecipient(TO, to);
|
||||||
}
|
}
|
||||||
RsPgpId ownPgpId = rsPeers->getGPGOwnId();
|
RsPgpId ownPgpId = rsPeers->getGPGOwnId();
|
||||||
RetroShareLink link;
|
RetroShareLink link;
|
||||||
|
@ -479,7 +461,7 @@ void MessageComposer::recommendFriend(const std::list <RsPeerId> &sslIds, const
|
||||||
if (*peerIt == to) {
|
if (*peerIt == to) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
composer->addRecipient(CC, *peerIt, false);
|
composer->addRecipient(CC, *peerIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoSend) {
|
if (autoSend) {
|
||||||
|
@ -683,18 +665,19 @@ void MessageComposer::peerStatusChanged(const QString& peer_id, int status)
|
||||||
|
|
||||||
for (row = 0; row < rowCount; row++) {
|
for (row = 0; row < rowCount; row++) {
|
||||||
enumType type;
|
enumType type;
|
||||||
|
destinationType dtype ;
|
||||||
std::string id;
|
std::string id;
|
||||||
bool group;
|
bool group;
|
||||||
|
|
||||||
if (getRecipientFromRow(row, type, id, group) && !id.empty() ) {
|
if (getRecipientFromRow(row, type,dtype, id) && !id.empty() ) {
|
||||||
if (group == false && QString::fromStdString(id) == peer_id) {
|
if (dtype == PEER_TYPE_SSL && QString::fromStdString(id) == peer_id)
|
||||||
|
{
|
||||||
QTableWidgetItem *item = ui.recipientWidget->item(row, COLUMN_RECIPIENT_ICON);
|
QTableWidgetItem *item = ui.recipientWidget->item(row, COLUMN_RECIPIENT_ICON);
|
||||||
if (item) {
|
if (item)
|
||||||
item->setIcon(QIcon(StatusDefs::imageUser(status)));
|
item->setIcon(QIcon(StatusDefs::imageUser(status)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageComposer::setFileList(const std::list<DirDetails>& dir_info)
|
void MessageComposer::setFileList(const std::list<DirDetails>& dir_info)
|
||||||
|
@ -892,38 +875,34 @@ MessageComposer *MessageComposer::newMsg(const std::string &msgId /* = ""*/)
|
||||||
|
|
||||||
std::list<std::string> groupIds;
|
std::list<std::string> groupIds;
|
||||||
std::list<std::string>::iterator groupIt;
|
std::list<std::string>::iterator groupIt;
|
||||||
std::list<RsPeerId>::iterator it;
|
|
||||||
|
|
||||||
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgto, groupIds);
|
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgto, groupIds);
|
||||||
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
|
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
|
||||||
// msgComposer->addRecipient(MessageComposer::TO, *groupIt, true) ;
|
// msgComposer->addRecipient(MessageComposer::TO, *groupIt, true) ;
|
||||||
// }
|
// }
|
||||||
for (it = msgInfo.msgto.begin(); it != msgInfo.msgto.end(); it++ ) {
|
|
||||||
msgComposer->addRecipient(MessageComposer::TO, *it, false) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgcc, groupIds);
|
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgcc, groupIds);
|
||||||
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
|
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
|
||||||
// msgComposer->addRecipient(MessageComposer::CC, *groupIt, true) ;
|
// msgComposer->addRecipient(MessageComposer::CC, *groupIt, true) ;
|
||||||
// }
|
// }
|
||||||
for (it = msgInfo.msgcc.begin(); it != msgInfo.msgcc.end(); it++ ) {
|
|
||||||
msgComposer->addRecipient(MessageComposer::CC, *it, false) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgbcc, groupIds);
|
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgbcc, groupIds);
|
||||||
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
|
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
|
||||||
// msgComposer->addRecipient(MessageComposer::BCC, *groupIt, true) ;
|
// msgComposer->addRecipient(MessageComposer::BCC, *groupIt, true) ;
|
||||||
// }
|
// }
|
||||||
for (it = msgInfo.msgbcc.begin(); it != msgInfo.msgbcc.end(); it++ ) {
|
|
||||||
msgComposer->addRecipient(MessageComposer::BCC, *it, false) ;
|
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgto.begin(); it != msgInfo.rspeerid_msgto.end(); it++ ) msgComposer->addRecipient(MessageComposer::TO, *it) ;
|
||||||
}
|
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgcc.begin(); it != msgInfo.rspeerid_msgcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::CC, *it) ;
|
||||||
|
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgbcc.begin(); it != msgInfo.rspeerid_msgbcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::BCC, *it) ;
|
||||||
|
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgto.begin(); it != msgInfo.rsgxsid_msgto.end(); it++ ) msgComposer->addRecipient(MessageComposer::TO, *it) ;
|
||||||
|
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgcc.begin(); it != msgInfo.rsgxsid_msgcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::CC, *it) ;
|
||||||
|
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgbcc.begin(); it != msgInfo.rsgxsid_msgbcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::BCC, *it) ;
|
||||||
|
|
||||||
MsgTagInfo tagInfo;
|
MsgTagInfo tagInfo;
|
||||||
rsMsgs->getMessageTag(msgId, tagInfo);
|
rsMsgs->getMessageTag(msgId, tagInfo);
|
||||||
|
|
||||||
msgComposer->m_tagIds = tagInfo.tagIds;
|
msgComposer->m_tagIds = tagInfo.tagIds;
|
||||||
|
|
||||||
msgComposer->showTagLabels();
|
msgComposer->showTagLabels();
|
||||||
|
|
||||||
msgComposer->ui.msgText->document()->setModified(false);
|
msgComposer->ui.msgText->document()->setModified(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -935,29 +914,44 @@ MessageComposer *MessageComposer::newMsg(const std::string &msgId /* = ""*/)
|
||||||
QString MessageComposer::buildReplyHeader(const MessageInfo &msgInfo)
|
QString MessageComposer::buildReplyHeader(const MessageInfo &msgInfo)
|
||||||
{
|
{
|
||||||
RetroShareLink link;
|
RetroShareLink link;
|
||||||
link.createMessage(msgInfo.srcId, "");
|
link.createMessage(msgInfo.rspeerid_srcId, "");
|
||||||
QString from = link.toHtml();
|
QString from = link.toHtml();
|
||||||
|
|
||||||
QString to;
|
QString to;
|
||||||
std::list<RsPeerId>::const_iterator it;
|
for ( std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgto.begin(); it != msgInfo.rspeerid_msgto.end(); it++)
|
||||||
for (it = msgInfo.msgto.begin(); it != msgInfo.msgto.end(); it++) {
|
if (link.createMessage(*it, ""))
|
||||||
if (link.createMessage(*it, "")) {
|
{
|
||||||
if (!to.isEmpty()) {
|
if (!to.isEmpty())
|
||||||
to += ", ";
|
to += ", ";
|
||||||
}
|
|
||||||
to += link.toHtml();
|
to += link.toHtml();
|
||||||
}
|
}
|
||||||
|
for ( std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgto.begin(); it != msgInfo.rsgxsid_msgto.end(); it++)
|
||||||
|
if (link.createMessage(*it, ""))
|
||||||
|
{
|
||||||
|
if (!to.isEmpty())
|
||||||
|
to += ", ";
|
||||||
|
|
||||||
|
to += link.toHtml();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString cc;
|
QString cc;
|
||||||
for (it = msgInfo.msgcc.begin(); it != msgInfo.msgcc.end(); it++) {
|
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgcc.begin(); it != msgInfo.rspeerid_msgcc.end(); it++)
|
||||||
if (link.createMessage(*it, "")) {
|
if (link.createMessage(*it, "")) {
|
||||||
if (!cc.isEmpty()) {
|
if (!cc.isEmpty()) {
|
||||||
cc += ", ";
|
cc += ", ";
|
||||||
}
|
}
|
||||||
cc += link.toHtml();
|
cc += link.toHtml();
|
||||||
}
|
}
|
||||||
|
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgcc.begin(); it != msgInfo.rsgxsid_msgcc.end(); it++)
|
||||||
|
if (link.createMessage(*it, "")) {
|
||||||
|
if (!cc.isEmpty()) {
|
||||||
|
cc += ", ";
|
||||||
}
|
}
|
||||||
|
cc += link.toHtml();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString header = QString("<span>-----%1-----").arg(tr("Original Message"));
|
QString header = QString("<span>-----%1-----").arg(tr("Original Message"));
|
||||||
header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("From"), from);
|
header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("From"), from);
|
||||||
|
@ -1030,22 +1024,28 @@ MessageComposer *MessageComposer::replyMsg(const std::string &msgId, bool all)
|
||||||
msgComposer->setTitleText(QString::fromUtf8(msgInfo.title.c_str()), REPLY);
|
msgComposer->setTitleText(QString::fromUtf8(msgInfo.title.c_str()), REPLY);
|
||||||
msgComposer->setQuotedMsg(QString::fromUtf8(msgInfo.msg.c_str()), buildReplyHeader(msgInfo));
|
msgComposer->setQuotedMsg(QString::fromUtf8(msgInfo.msg.c_str()), buildReplyHeader(msgInfo));
|
||||||
|
|
||||||
msgComposer->addRecipient(MessageComposer::TO, msgInfo.srcId, false);
|
if(!msgInfo.rspeerid_srcId.isNull()) msgComposer->addRecipient(MessageComposer::TO, msgInfo.rspeerid_srcId);
|
||||||
|
if(!msgInfo.rsgxsid_srcId.isNull()) msgComposer->addRecipient(MessageComposer::TO, msgInfo.rsgxsid_srcId);
|
||||||
|
|
||||||
if (all) {
|
if (all)
|
||||||
|
{
|
||||||
RsPeerId ownId = rsPeers->getOwnId();
|
RsPeerId ownId = rsPeers->getOwnId();
|
||||||
|
|
||||||
for (std::list<RsPeerId>::iterator tli = msgInfo.msgto.begin(); tli != msgInfo.msgto.end(); tli++) {
|
for (std::list<RsPeerId>::iterator tli = msgInfo.rspeerid_msgto.begin(); tli != msgInfo.rspeerid_msgto.end(); tli++)
|
||||||
if (ownId != *tli) {
|
if (ownId != *tli)
|
||||||
msgComposer->addRecipient(MessageComposer::TO, *tli, false) ;
|
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (std::list<RsPeerId>::iterator tli = msgInfo.msgcc.begin(); tli != msgInfo.msgcc.end(); tli++) {
|
for (std::list<RsPeerId>::iterator tli = msgInfo.rspeerid_msgcc.begin(); tli != msgInfo.rspeerid_msgcc.end(); tli++)
|
||||||
if (ownId != *tli) {
|
if (ownId != *tli)
|
||||||
msgComposer->addRecipient(MessageComposer::TO, *tli, false) ;
|
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
|
||||||
}
|
|
||||||
}
|
for (std::list<RsGxsId>::iterator tli = msgInfo.rsgxsid_msgto.begin(); tli != msgInfo.rsgxsid_msgto.end(); tli++)
|
||||||
|
//if (ownId != *tli)
|
||||||
|
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
|
||||||
|
|
||||||
|
for (std::list<RsGxsId>::iterator tli = msgInfo.rsgxsid_msgcc.begin(); tli != msgInfo.rsgxsid_msgcc.end(); tli++)
|
||||||
|
//if (ownId != *tli)
|
||||||
|
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// needed to send system flags with reply
|
// needed to send system flags with reply
|
||||||
|
@ -1139,9 +1139,10 @@ void MessageComposer::sendMessage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T> void addUnique(std::list<T>& lst,const T& t) { if(std::find(lst.begin(),lst.end(),t) == lst.end()) lst.push_back(t) ; }
|
||||||
|
|
||||||
bool MessageComposer::sendMessage_internal(bool bDraftbox)
|
bool MessageComposer::sendMessage_internal(bool bDraftbox)
|
||||||
{
|
{
|
||||||
#ifdef SUSPENDED
|
|
||||||
/* construct a message */
|
/* construct a message */
|
||||||
MessageInfo mi;
|
MessageInfo mi;
|
||||||
|
|
||||||
|
@ -1165,7 +1166,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
|
||||||
for (int i = 0; i < filesCount; i++) {
|
for (int i = 0; i < filesCount; i++) {
|
||||||
QTreeWidgetItem *item = ui.msgFileList->topLevelItem(i);
|
QTreeWidgetItem *item = ui.msgFileList->topLevelItem(i);
|
||||||
if (item->checkState(COLUMN_FILE_CHECKED)) {
|
if (item->checkState(COLUMN_FILE_CHECKED)) {
|
||||||
std::string hash = item->text(COLUMN_FILE_HASH).toStdString();
|
RsFileHash hash ( item->text(COLUMN_FILE_HASH).toStdString() );
|
||||||
for(std::list<FileInfo>::iterator it = _recList.begin(); it != _recList.end(); it++) {
|
for(std::list<FileInfo>::iterator it = _recList.begin(); it != _recList.end(); it++) {
|
||||||
if (it->hash == hash) {
|
if (it->hash == hash) {
|
||||||
mi.files.push_back(*it);
|
mi.files.push_back(*it);
|
||||||
|
@ -1185,21 +1186,26 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
|
||||||
int rowCount = ui.recipientWidget->rowCount();
|
int rowCount = ui.recipientWidget->rowCount();
|
||||||
int row;
|
int row;
|
||||||
|
|
||||||
for (row = 0; row < rowCount; row++) {
|
for (row = 0; row < rowCount; row++)
|
||||||
|
{
|
||||||
enumType type;
|
enumType type;
|
||||||
|
destinationType dtype ;
|
||||||
std::string id;
|
std::string id;
|
||||||
bool group;
|
bool group;
|
||||||
|
|
||||||
if (getRecipientFromRow(row, type, id, group) && !id.empty())
|
if (!getRecipientFromRow(row, type,dtype, id) || id.empty())
|
||||||
|
continue ;
|
||||||
|
|
||||||
|
switch(dtype)
|
||||||
{
|
{
|
||||||
if (group) {
|
case PEER_TYPE_GROUP: {
|
||||||
RsGroupInfo groupInfo;
|
RsGroupInfo groupInfo;
|
||||||
if (rsPeers->getGroupInfo(id, groupInfo) == false) {
|
if (rsPeers->getGroupInfo(id, groupInfo) == false) {
|
||||||
// group not found
|
// group not found
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::string>::const_iterator groupIt;
|
std::list<RsPgpId>::const_iterator groupIt;
|
||||||
for (groupIt = groupInfo.peerIds.begin(); groupIt != groupInfo.peerIds.end(); groupIt++) {
|
for (groupIt = groupInfo.peerIds.begin(); groupIt != groupInfo.peerIds.end(); groupIt++) {
|
||||||
std::list<RsPeerId> sslIds;
|
std::list<RsPeerId> sslIds;
|
||||||
rsPeers->getAssociatedSSLIds(*groupIt, sslIds);
|
rsPeers->getAssociatedSSLIds(*groupIt, sslIds);
|
||||||
|
@ -1211,53 +1217,58 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type)
|
||||||
case TO:
|
{
|
||||||
if (std::find(mi.msgto.begin(), mi.msgto.end(), *sslIt) == mi.msgto.end()) {
|
case TO: addUnique(mi.rspeerid_msgto,*sslIt);
|
||||||
mi.msgto.push_back(*sslIt);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case CC:
|
case CC: addUnique(mi.rspeerid_msgcc,*sslIt);
|
||||||
if (std::find(mi.msgcc.begin(), mi.msgcc.end(), *sslIt) == mi.msgcc.end()) {
|
|
||||||
mi.msgcc.push_back(*sslIt);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case BCC:
|
case BCC:addUnique(mi.rspeerid_msgbcc,*sslIt);
|
||||||
if (std::find(mi.msgbcc.begin(), mi.msgbcc.end(), *sslIt) == mi.msgbcc.end()) {
|
|
||||||
mi.msgbcc.push_back(*sslIt);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (_distant_peers.find(id)==_distant_peers.end() && std::find(peers.begin(), peers.end(), id) == peers.end()) {
|
|
||||||
// no friend
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
break ;
|
||||||
|
case PEER_TYPE_SSL:
|
||||||
|
{
|
||||||
|
RsPeerId pid(id) ;
|
||||||
|
|
||||||
switch (type) {
|
switch (type)
|
||||||
case TO:
|
{
|
||||||
if (std::find(mi.msgto.begin(), mi.msgto.end(), id) == mi.msgto.end()) {
|
case TO: addUnique(mi.rspeerid_msgto,pid);
|
||||||
mi.msgto.push_back(id);
|
break ;
|
||||||
}
|
case CC: addUnique(mi.rspeerid_msgcc,pid);
|
||||||
break;
|
break ;
|
||||||
case CC:
|
case BCC:addUnique(mi.rspeerid_msgbcc,pid);
|
||||||
if (std::find(mi.msgcc.begin(), mi.msgcc.end(), id) == mi.msgcc.end()) {
|
break ;
|
||||||
mi.msgcc.push_back(id);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BCC:
|
|
||||||
if (std::find(mi.msgbcc.begin(), mi.msgbcc.end(), id) == mi.msgbcc.end()) {
|
|
||||||
mi.msgbcc.push_back(id);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break ;
|
||||||
|
case PEER_TYPE_GXS:
|
||||||
|
{
|
||||||
|
RsGxsId gid(id) ;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case TO: addUnique(mi.rsgxsid_msgto,gid) ;
|
||||||
|
break ;
|
||||||
|
case CC: addUnique(mi.rsgxsid_msgcc,gid) ;
|
||||||
|
break ;
|
||||||
|
case BCC:addUnique(mi.rsgxsid_msgbcc,gid) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << ": Unhandled desitnation type " << dtype << std::endl;
|
||||||
|
break ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bDraftbox) {
|
if (bDraftbox)
|
||||||
|
{
|
||||||
mi.msgId = m_sDraftMsgId;
|
mi.msgId = m_sDraftMsgId;
|
||||||
|
|
||||||
rsMsgs->MessageToDraft(mi, m_msgParentId);
|
rsMsgs->MessageToDraft(mi, m_msgParentId);
|
||||||
|
@ -1275,14 +1286,16 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
|
||||||
rsMsgs->MessageForwarded(m_sDraftMsgId, true);
|
rsMsgs->MessageForwarded(m_sDraftMsgId, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* check for the recipient */
|
/* check for the recipient */
|
||||||
if (mi.msgto.empty()) {
|
if (mi.rspeerid_msgto.empty() && mi.rspeerid_msgcc.empty() && mi.rspeerid_msgbcc.empty()
|
||||||
|
&& mi.rsgxsid_msgto.empty() && mi.rsgxsid_msgcc.empty() && mi.rsgxsid_msgbcc.empty())
|
||||||
|
{
|
||||||
QMessageBox::warning(this, tr("RetroShare"), tr("Please insert at least one recipient."), QMessageBox::Ok);
|
QMessageBox::warning(this, tr("RetroShare"), tr("Please insert at least one recipient."), QMessageBox::Ok);
|
||||||
return false; // Don't send with no recipient
|
return false; // Don't send with no recipient
|
||||||
}
|
}
|
||||||
mi.encryption_keys = _distant_peers ;
|
|
||||||
|
|
||||||
if(ui.signMessage_CB->isChecked())
|
if(ui.signMessage_CB->isChecked())
|
||||||
mi.msgflags |= RS_MSG_SIGNED ;
|
mi.msgflags |= RS_MSG_SIGNED ;
|
||||||
|
|
||||||
|
@ -1324,7 +1337,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui.msgText->document()->setModified(false);
|
ui.msgText->document()->setModified(false);
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1350,10 +1363,10 @@ void MessageComposer::addEmptyRecipient()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setRecipientToRow(lastRow, TO,"", false);
|
setRecipientToRow(lastRow, TO,PEER_TYPE_SSL,"");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageComposer::getRecipientFromRow(int row, enumType &type, std::string &id, bool &group)
|
bool MessageComposer::getRecipientFromRow(int row, enumType &type, destinationType& dest_type,std::string &id)
|
||||||
{
|
{
|
||||||
if (row >= ui.recipientWidget->rowCount()) {
|
if (row >= ui.recipientWidget->rowCount()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1366,12 +1379,12 @@ bool MessageComposer::getRecipientFromRow(int row, enumType &type, std::string &
|
||||||
|
|
||||||
type = (enumType) cb->itemData(cb->currentIndex(), Qt::UserRole).toInt();
|
type = (enumType) cb->itemData(cb->currentIndex(), Qt::UserRole).toInt();
|
||||||
id = ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->data(ROLE_RECIPIENT_ID).toString().toStdString();
|
id = ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->data(ROLE_RECIPIENT_ID).toString().toStdString();
|
||||||
group = ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->data(ROLE_RECIPIENT_GROUP).toBool();
|
dest_type = (destinationType)ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->data(ROLE_RECIPIENT_TYPE).toInt();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageComposer::setRecipientToRow(int row, enumType type, const std::string& id, bool group)
|
void MessageComposer::setRecipientToRow(int row, enumType type, destinationType dest_type, const std::string &id)
|
||||||
{
|
{
|
||||||
if (row + 1 > ui.recipientWidget->rowCount()) {
|
if (row + 1 > ui.recipientWidget->rowCount()) {
|
||||||
ui.recipientWidget->setRowCount(row + 1);
|
ui.recipientWidget->setRowCount(row + 1);
|
||||||
|
@ -1408,8 +1421,9 @@ void MessageComposer::setRecipientToRow(int row, enumType type, const std::strin
|
||||||
QString name;
|
QString name;
|
||||||
if (!id.empty())
|
if (!id.empty())
|
||||||
{
|
{
|
||||||
if (group)
|
switch(dest_type)
|
||||||
{
|
{
|
||||||
|
case PEER_TYPE_GROUP: {
|
||||||
icon = QIcon(IMAGE_GROUP16);
|
icon = QIcon(IMAGE_GROUP16);
|
||||||
|
|
||||||
RsGroupInfo groupInfo;
|
RsGroupInfo groupInfo;
|
||||||
|
@ -1419,23 +1433,32 @@ void MessageComposer::setRecipientToRow(int row, enumType type, const std::strin
|
||||||
name = tr("Unknown");
|
name = tr("Unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
break ;
|
||||||
{
|
|
||||||
RsPeerDetails details;
|
|
||||||
|
|
||||||
if(_distant_peers.find(RsPeerId(id)) != _distant_peers.end())
|
case PEER_TYPE_GXS: {
|
||||||
|
|
||||||
|
RsIdentityDetails detail;
|
||||||
|
RsGxsId gid(id) ;
|
||||||
|
|
||||||
|
if(!rsIdentity->getIdDetails(gid, detail))
|
||||||
{
|
{
|
||||||
if(!rsPeers->getGPGDetails(_distant_peers[RsPeerId(id)], details))
|
std::cerr << "Can't get peer details from " << gid << std::endl;
|
||||||
{
|
|
||||||
std::cerr << "Can't get peer details from " << _distant_peers[RsPeerId(id)] << std::endl;
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = tr("Distant peer (name: %2, PGP key: %1)").arg(QString::fromStdString(_distant_peers[RsPeerId(id)].toStdString())).arg(QString::fromStdString(details.name)) ;
|
name = tr("Distant peer (name: %2, PGP key: %1)").arg(QString::fromStdString(gid.toStdString())).arg(QString::fromStdString(detail.mNickname)) ;
|
||||||
icon = QIcon(StatusDefs::imageUser(RS_STATUS_ONLINE));
|
icon = QIcon(StatusDefs::imageUser(RS_STATUS_ONLINE));
|
||||||
}
|
}
|
||||||
else if(rsPeers->getPeerDetails(RsPeerId(id), details) && (!details.isOnlyGPGdetail))
|
break ;
|
||||||
|
|
||||||
|
case PEER_TYPE_SSL: {
|
||||||
|
RsPeerDetails details ;
|
||||||
|
|
||||||
|
if(!rsPeers->getPeerDetails(RsPeerId(id), details))
|
||||||
{
|
{
|
||||||
|
std::cerr << "Can't get peer details from " << id << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
name = PeerDefs::nameWithLocation(details);
|
name = PeerDefs::nameWithLocation(details);
|
||||||
|
|
||||||
StatusInfo peerStatusInfo;
|
StatusInfo peerStatusInfo;
|
||||||
|
@ -1444,28 +1467,26 @@ void MessageComposer::setRecipientToRow(int row, enumType type, const std::strin
|
||||||
|
|
||||||
icon = QIcon(StatusDefs::imageUser(peerStatusInfo.status));
|
icon = QIcon(StatusDefs::imageUser(peerStatusInfo.status));
|
||||||
}
|
}
|
||||||
else
|
break ;
|
||||||
{
|
default:
|
||||||
icon = QIcon(StatusDefs::imageUser(RS_STATUS_OFFLINE));
|
std::cerr << __PRETTY_FUNCTION__ << ": Unhandled type " << dest_type << std::endl;
|
||||||
name = tr("Unknown friend");
|
return ;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
comboBox->setCurrentIndex(comboBox->findData(type, Qt::UserRole));
|
comboBox->setCurrentIndex(comboBox->findData(type, Qt::UserRole));
|
||||||
|
|
||||||
lineEdit->setText(name);
|
lineEdit->setText(name);
|
||||||
if (id.empty()) {
|
if (id.empty())
|
||||||
lineEdit->setStyleSheet(QString(STYLE_FAIL).arg(lineEdit->objectName()));
|
lineEdit->setStyleSheet(QString(STYLE_FAIL).arg(lineEdit->objectName()));
|
||||||
} else {
|
else
|
||||||
lineEdit->setStyleSheet(QString(STYLE_NORMAL).arg(lineEdit->objectName()));
|
lineEdit->setStyleSheet(QString(STYLE_NORMAL).arg(lineEdit->objectName()));
|
||||||
}
|
|
||||||
|
|
||||||
QTableWidgetItem *item = new QTableWidgetItem(icon, "", 0);
|
QTableWidgetItem *item = new QTableWidgetItem(icon, "", 0);
|
||||||
item->setFlags(Qt::NoItemFlags);
|
item->setFlags(Qt::NoItemFlags);
|
||||||
ui.recipientWidget->setItem(row, COLUMN_RECIPIENT_ICON, item);
|
ui.recipientWidget->setItem(row, COLUMN_RECIPIENT_ICON, item);
|
||||||
ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_ID, QString::fromStdString(id));
|
ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_ID, QString::fromStdString(id));
|
||||||
ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_GROUP, group);
|
ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_TYPE, dest_type);
|
||||||
|
|
||||||
addEmptyRecipient();
|
addEmptyRecipient();
|
||||||
}
|
}
|
||||||
|
@ -1532,13 +1553,14 @@ void MessageComposer::editingRecipientFinished()
|
||||||
|
|
||||||
enumType type;
|
enumType type;
|
||||||
std::string id; // dummy
|
std::string id; // dummy
|
||||||
bool group; // dummy
|
destinationType dtype ;
|
||||||
getRecipientFromRow(row, type, id, group);
|
|
||||||
|
getRecipientFromRow(row, type, dtype, id);
|
||||||
|
|
||||||
QString text = lineEdit->text();
|
QString text = lineEdit->text();
|
||||||
|
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
setRecipientToRow(row, type, "", false);
|
setRecipientToRow(row, type,PEER_TYPE_SSL, "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1556,7 +1578,7 @@ void MessageComposer::editingRecipientFinished()
|
||||||
QString name = PeerDefs::nameWithLocation(details);
|
QString name = PeerDefs::nameWithLocation(details);
|
||||||
if (text.compare(name, Qt::CaseSensitive) == 0) {
|
if (text.compare(name, Qt::CaseSensitive) == 0) {
|
||||||
// found it
|
// found it
|
||||||
setRecipientToRow(row, type, details.id.toStdString(), false);
|
setRecipientToRow(row, type, PEER_TYPE_SSL, details.id.toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1570,19 +1592,42 @@ void MessageComposer::editingRecipientFinished()
|
||||||
QString groupName = GroupDefs::name(*groupIt);
|
QString groupName = GroupDefs::name(*groupIt);
|
||||||
if (text.compare(groupName, Qt::CaseSensitive) == 0) {
|
if (text.compare(groupName, Qt::CaseSensitive) == 0) {
|
||||||
// found it
|
// found it
|
||||||
setRecipientToRow(row, type, groupIt->id, true);
|
setRecipientToRow(row, type, PEER_TYPE_GROUP, groupIt->id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setRecipientToRow(row, type, "", false);
|
setRecipientToRow(row, type, PEER_TYPE_SSL, "");
|
||||||
lineEdit->setStyleSheet(QString(STYLE_FAIL).arg(lineEdit->objectName()));
|
lineEdit->setStyleSheet(QString(STYLE_FAIL).arg(lineEdit->objectName()));
|
||||||
lineEdit->setText(text);
|
lineEdit->setText(text);
|
||||||
}
|
}
|
||||||
|
void MessageComposer::addRecipient(enumType type, const RsPeerId& pid)
|
||||||
void MessageComposer::addRecipient(enumType type, const DistantMsgPeerId& pid,const RsPgpId& pgp_id)
|
|
||||||
{
|
{
|
||||||
_distant_peers[pid] = pgp_id ;
|
int rowCount = ui.recipientWidget->rowCount();
|
||||||
|
int row;
|
||||||
|
for (row = 0; row < rowCount; row++)
|
||||||
|
{
|
||||||
|
enumType rowType;
|
||||||
|
std::string rowId;
|
||||||
|
destinationType dtype ;
|
||||||
|
|
||||||
|
if (getRecipientFromRow(row, rowType, dtype, rowId))
|
||||||
|
{
|
||||||
|
if (rowId.empty()) // use row
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (RsPeerId(rowId) == pid && rowType == type) // existing row
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else // use row
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRecipientToRow(row, type, PEER_TYPE_SSL,pid.toStdString());
|
||||||
|
}
|
||||||
|
void MessageComposer::addRecipient(enumType type, const RsGxsId& gxs_id)
|
||||||
|
{
|
||||||
|
_distant_peers.insert(gxs_id) ;
|
||||||
|
|
||||||
int rowCount = ui.recipientWidget->rowCount();
|
int rowCount = ui.recipientWidget->rowCount();
|
||||||
int row;
|
int row;
|
||||||
|
@ -1590,69 +1635,41 @@ void MessageComposer::addRecipient(enumType type, const DistantMsgPeerId& pid,co
|
||||||
{
|
{
|
||||||
enumType rowType;
|
enumType rowType;
|
||||||
std::string rowId;
|
std::string rowId;
|
||||||
bool rowGroup;
|
destinationType dtype ;
|
||||||
|
|
||||||
if (getRecipientFromRow(row, rowType, rowId, rowGroup) == true)
|
if (getRecipientFromRow(row, rowType, dtype, rowId))
|
||||||
{
|
{
|
||||||
if (rowId.empty()) // use row
|
if (rowId.empty()) // use row
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (rowId == pid.toStdString() && rowType == type) // existing row
|
if (RsGxsId(rowId) == gxs_id && rowType == type) // existing row
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else // use row
|
else // use row
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
setRecipientToRow(row, type, pid.toStdString(), false);
|
setRecipientToRow(row, type, PEER_TYPE_GXS,gxs_id.toStdString());
|
||||||
}
|
}
|
||||||
void MessageComposer::addRecipient(enumType type, const RsPeerId &id, bool group)
|
void MessageComposer::addRecipient(enumType type, const std::string& id)
|
||||||
{
|
{
|
||||||
std::list<RsPeerId> sslIds;
|
|
||||||
if (group) {
|
|
||||||
sslIds.push_back(id);
|
|
||||||
} else {
|
|
||||||
// check for gpg id or ssl id
|
|
||||||
RsPeerDetails detail;
|
|
||||||
if (!rsPeers->getPeerDetails(id, detail)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (detail.isOnlyGPGdetail)
|
|
||||||
// {
|
|
||||||
// if( (!rsPeers->getAssociatedSSLIds(id, sslIds)) || sslIds.empty())
|
|
||||||
// {
|
|
||||||
// std::string hash ;
|
|
||||||
// if(rsMsgs->getDistantMessageHash(id,hash))
|
|
||||||
// addRecipient(type, hash, id);
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// QMessageBox::warning(this,tr("PGP key unknown"),tr("You dont have the PGP key of the message sender. So you cannot respond!"),QMessageBox::Ok) ;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
sslIds.push_back(id);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
std::list<RsPeerId>::const_iterator sslIt;
|
|
||||||
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) {
|
|
||||||
// search existing or empty row
|
// search existing or empty row
|
||||||
int rowCount = ui.recipientWidget->rowCount();
|
int rowCount = ui.recipientWidget->rowCount();
|
||||||
int row;
|
int row;
|
||||||
for (row = 0; row < rowCount; row++) {
|
for (row = 0; row < rowCount; row++) {
|
||||||
enumType rowType;
|
enumType rowType;
|
||||||
std::string rowId;
|
std::string rowId;
|
||||||
|
destinationType dtype ;
|
||||||
bool rowGroup;
|
bool rowGroup;
|
||||||
|
|
||||||
if (getRecipientFromRow(row, rowType, rowId, rowGroup) == true) {
|
if (getRecipientFromRow(row, rowType, dtype,rowId))
|
||||||
|
{
|
||||||
if (rowId.empty()) {
|
if (rowId.empty()) {
|
||||||
// use row
|
// use row
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rowId == (*sslIt).toStdString() && rowType == type && group == rowGroup) {
|
if (rowId == id && rowType == type && dtype == PEER_TYPE_GROUP) {
|
||||||
// existing row
|
// existing row
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1662,8 +1679,7 @@ void MessageComposer::addRecipient(enumType type, const RsPeerId &id, bool group
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setRecipientToRow(row, type, (*sslIt).toStdString(), group);
|
setRecipientToRow(row, type, PEER_TYPE_GROUP, id);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageComposer::setupFileActions()
|
void MessageComposer::setupFileActions()
|
||||||
|
@ -2310,25 +2326,21 @@ void MessageComposer::addContact(enumType type)
|
||||||
std::list<RsPeerId> ids ;
|
std::list<RsPeerId> ids ;
|
||||||
ui.friendSelectionWidget->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(ids, true);
|
ui.friendSelectionWidget->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(ids, true);
|
||||||
for (std::list<RsPeerId>::const_iterator idIt = ids.begin(); idIt != ids.end(); idIt++) {
|
for (std::list<RsPeerId>::const_iterator idIt = ids.begin(); idIt != ids.end(); idIt++) {
|
||||||
addRecipient(type, *idIt, false);
|
addRecipient(type, *idIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<RsPgpId> id2 ;
|
std::list<RsGxsId> id2 ;
|
||||||
ui.friendSelectionWidget->selectedIds<RsPgpId,FriendSelectionWidget::IDTYPE_GPG>(id2, true);
|
ui.friendSelectionWidget->selectedIds<RsGxsId,FriendSelectionWidget::IDTYPE_GXS>(id2, true);
|
||||||
for (std::list<RsPgpId>::const_iterator idIt = id2.begin(); idIt != id2.end(); idIt++)
|
for (std::list<RsGxsId>::const_iterator idIt = id2.begin(); idIt != id2.end(); idIt++)
|
||||||
{
|
addRecipient(type, *idIt);
|
||||||
DistantMsgPeerId pid ;
|
|
||||||
|
|
||||||
if(rsMsgs->getDistantMessagePeerId(*idIt,pid))
|
|
||||||
addRecipient(type, pid, *idIt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageComposer::toggleShowNonFriend(bool bValue)
|
void MessageComposer::toggleShowNonFriend(bool bValue)
|
||||||
{
|
{
|
||||||
ui.friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_GROUP
|
ui.friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_GROUP
|
||||||
| FriendSelectionWidget::SHOW_SSL
|
| FriendSelectionWidget::SHOW_SSL
|
||||||
| (bValue?FriendSelectionWidget::SHOW_NONE : FriendSelectionWidget::SHOW_NON_FRIEND_GPG));
|
| (bValue?FriendSelectionWidget::SHOW_NONE : FriendSelectionWidget::SHOW_GXS));
|
||||||
|
|
||||||
Settings->setValueToGroup("MessageComposer", "ShowOnlyTrustedKeys", bValue);
|
Settings->setValueToGroup("MessageComposer", "ShowOnlyTrustedKeys", bValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2352,14 +2364,16 @@ void MessageComposer::addRecommend()
|
||||||
std::list<RsPeerId> sslIds;
|
std::list<RsPeerId> sslIds;
|
||||||
ui.friendSelectionWidget->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(sslIds, false);
|
ui.friendSelectionWidget->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(sslIds, false);
|
||||||
|
|
||||||
if (sslIds.empty()) {
|
std::list<RsGxsId> gxsIds ;
|
||||||
return;
|
ui.friendSelectionWidget->selectedIds<RsGxsId,FriendSelectionWidget::IDTYPE_GXS>(gxsIds, true);
|
||||||
}
|
|
||||||
|
|
||||||
std::list <RsPeerId>::iterator it;
|
if (sslIds.empty() && gxsIds.empty())
|
||||||
for (it = sslIds.begin(); it != sslIds.end(); it++) {
|
return;
|
||||||
addRecipient(CC, *it, false);
|
|
||||||
}
|
for(std::list <RsPeerId>::iterator it = sslIds.begin(); it != sslIds.end(); it++)
|
||||||
|
addRecipient(CC, *it);
|
||||||
|
for (std::list<RsGxsId>::const_iterator it = gxsIds.begin(); it != gxsIds.end(); it++)
|
||||||
|
addRecipient(TO, *it);
|
||||||
|
|
||||||
QString text = buildRecommendHtml(sslIds);
|
QString text = buildRecommendHtml(sslIds);
|
||||||
ui.msgText->textCursor().insertHtml(text);
|
ui.msgText->textCursor().insertHtml(text);
|
||||||
|
|
|
@ -42,6 +42,7 @@ class MessageComposer : public QMainWindow
|
||||||
public:
|
public:
|
||||||
enum enumType { TO, CC, BCC };
|
enum enumType { TO, CC, BCC };
|
||||||
enum enumMessageType { NORMAL, REPLY, FORWARD };
|
enum enumMessageType { NORMAL, REPLY, FORWARD };
|
||||||
|
enum destinationType { PEER_TYPE_SSL, PEER_TYPE_GROUP, PEER_TYPE_GXS };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Default Constructor */
|
/** Default Constructor */
|
||||||
|
@ -49,9 +50,9 @@ public:
|
||||||
MessageComposer(QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
MessageComposer(QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||||
~MessageComposer();
|
~MessageComposer();
|
||||||
|
|
||||||
static void msgFriend(const RsPeerId &id, bool group);
|
static void msgFriend(const RsPeerId &id);
|
||||||
//static void msgDistantPeer(const std::string& hash,const std::string& pgp_id) ;
|
static void msgGxsIdentity(const RsGxsId& gxs_id) ;
|
||||||
static void msgDistantPeer(const RsPgpId& pgp_id) ;
|
static void msgGroup(const std::string& group_id) ;
|
||||||
|
|
||||||
static QString recommendMessage();
|
static QString recommendMessage();
|
||||||
static void recommendFriend(const std::list <RsPeerId> &sslIds, const RsPeerId &to = RsPeerId(), const QString &msg = "", bool autoSend = false);
|
static void recommendFriend(const std::list <RsPeerId> &sslIds, const RsPeerId &to = RsPeerId(), const QString &msg = "", bool autoSend = false);
|
||||||
|
@ -68,8 +69,9 @@ public:
|
||||||
void setTitleText(const QString &title, enumMessageType type = NORMAL);
|
void setTitleText(const QString &title, enumMessageType type = NORMAL);
|
||||||
void setQuotedMsg(const QString &msg, const QString &header);
|
void setQuotedMsg(const QString &msg, const QString &header);
|
||||||
void setMsgText(const QString &msg, bool asHtml = false);
|
void setMsgText(const QString &msg, bool asHtml = false);
|
||||||
void addRecipient(enumType type, const RsPeerId &id, bool group);
|
void addRecipient(enumType type, const RsPeerId &id);
|
||||||
void addRecipient(enumType type, const DistantMsgPeerId &pid, const RsPgpId &pgp_id) ;
|
void addRecipient(enumType type, const RsGxsId &gxs_id) ;
|
||||||
|
void addRecipient(enumType type, const std::string& group_id) ;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/* actions to take.... */
|
/* actions to take.... */
|
||||||
|
@ -174,8 +176,8 @@ private:
|
||||||
void calculateTitle();
|
void calculateTitle();
|
||||||
void addEmptyRecipient();
|
void addEmptyRecipient();
|
||||||
|
|
||||||
bool getRecipientFromRow(int row, enumType &type, std::string &id, bool &group);
|
bool getRecipientFromRow(int row, enumType &type, destinationType& dest_type, std::string &id);
|
||||||
void setRecipientToRow(int row, enumType type, const std::string &id, bool group);
|
void setRecipientToRow(int row, enumType type, destinationType dest_type,const std::string &id);
|
||||||
|
|
||||||
void clearTagLabels();
|
void clearTagLabels();
|
||||||
void showTagLabels();
|
void showTagLabels();
|
||||||
|
@ -221,7 +223,7 @@ private:
|
||||||
Ui::MessageComposer ui;
|
Ui::MessageComposer ui;
|
||||||
|
|
||||||
std::list<FileInfo> _recList ;
|
std::list<FileInfo> _recList ;
|
||||||
std::map<DistantMsgPeerId,RsPgpId> _distant_peers ; // pairs (hash,pgp_id)
|
std::set<RsGxsId> _distant_peers ; // we keep a list of them, in order to know which peer is a GXS id.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -304,7 +304,7 @@ void MessageWidget::getcurrentrecommended()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<RsPeerId> srcIds;
|
std::list<RsPeerId> srcIds;
|
||||||
srcIds.push_back(msgInfo.srcId);
|
srcIds.push_back(msgInfo.rspeerid_srcId);
|
||||||
|
|
||||||
QModelIndexList list = ui.msgList->selectionModel()->selectedIndexes();
|
QModelIndexList list = ui.msgList->selectionModel()->selectedIndexes();
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ void MessageWidget::getallrecommended()
|
||||||
for(it = recList.begin(); it != recList.end(); it++) {
|
for(it = recList.begin(); it != recList.end(); it++) {
|
||||||
std::cerr << "MessageWidget::getallrecommended() Calling File Request" << std::endl;
|
std::cerr << "MessageWidget::getallrecommended() Calling File Request" << std::endl;
|
||||||
std::list<RsPeerId> srcIds;
|
std::list<RsPeerId> srcIds;
|
||||||
srcIds.push_back(msgInfo.srcId);
|
srcIds.push_back(msgInfo.rspeerid_srcId);
|
||||||
rsFiles->FileRequest(it->fname, it->hash, it->size, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds);
|
rsFiles->FileRequest(it->fname, it->hash, it->size, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,28 +497,23 @@ void MessageWidget::fill(const std::string &msgId)
|
||||||
ui.msgList->insertTopLevelItems(0, items);
|
ui.msgList->insertTopLevelItems(0, items);
|
||||||
|
|
||||||
/* iterate through the sources */
|
/* iterate through the sources */
|
||||||
std::list<RsPeerId>::const_iterator pit;
|
|
||||||
|
|
||||||
RetroShareLink link;
|
RetroShareLink link;
|
||||||
QString text;
|
QString text;
|
||||||
|
|
||||||
for(pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++) {
|
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgto.begin(); pit != msgInfo.rspeerid_msgto.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
|
||||||
if (link.createMessage(*pit, "")) {
|
for(std::list<RsGxsId >::const_iterator pit = msgInfo.rsgxsid_msgto.begin(); pit != msgInfo.rsgxsid_msgto.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
|
||||||
text += link.toHtml() + " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui.toText->setText(text);
|
ui.toText->setText(text);
|
||||||
|
|
||||||
if (msgInfo.msgcc.size() > 0) {
|
if (!msgInfo.rspeerid_msgcc.empty() || !msgInfo.rsgxsid_msgcc.empty())
|
||||||
|
{
|
||||||
ui.cclabel->setVisible(true);
|
ui.cclabel->setVisible(true);
|
||||||
ui.ccText->setVisible(true);
|
ui.ccText->setVisible(true);
|
||||||
|
|
||||||
text.clear();
|
text.clear();
|
||||||
for(pit = msgInfo.msgcc.begin(); pit != msgInfo.msgcc.end(); pit++) {
|
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgcc.begin(); pit != msgInfo.rspeerid_msgcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
|
||||||
if (link.createMessage(*pit, "")) {
|
for(std::list<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgcc.begin(); pit != msgInfo.rsgxsid_msgcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
|
||||||
text += link.toHtml() + " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui.ccText->setText(text);
|
ui.ccText->setText(text);
|
||||||
} else {
|
} else {
|
||||||
ui.cclabel->setVisible(false);
|
ui.cclabel->setVisible(false);
|
||||||
|
@ -526,16 +521,15 @@ void MessageWidget::fill(const std::string &msgId)
|
||||||
ui.ccText->clear();
|
ui.ccText->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msgInfo.msgbcc.size() > 0) {
|
if (!msgInfo.rspeerid_msgbcc.empty() || !msgInfo.rsgxsid_msgbcc.empty())
|
||||||
|
{
|
||||||
ui.bcclabel->setVisible(true);
|
ui.bcclabel->setVisible(true);
|
||||||
ui.bccText->setVisible(true);
|
ui.bccText->setVisible(true);
|
||||||
|
|
||||||
text.clear();
|
text.clear();
|
||||||
for(pit = msgInfo.msgbcc.begin(); pit != msgInfo.msgbcc.end(); pit++) {
|
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgbcc.begin(); pit != msgInfo.rspeerid_msgbcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
|
||||||
if (link.createMessage(*pit, "")) {
|
for(std::list<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgbcc.begin(); pit != msgInfo.rsgxsid_msgbcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
|
||||||
text += link.toHtml() + " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui.bccText->setText(text);
|
ui.bccText->setText(text);
|
||||||
} else {
|
} else {
|
||||||
ui.bcclabel->setVisible(false);
|
ui.bcclabel->setVisible(false);
|
||||||
|
@ -552,11 +546,11 @@ void MessageWidget::fill(const std::string &msgId)
|
||||||
// outgoing message are from me
|
// outgoing message are from me
|
||||||
srcId = ownId;
|
srcId = ownId;
|
||||||
} else {
|
} else {
|
||||||
srcId = msgInfo.srcId;
|
srcId = msgInfo.rspeerid_srcId;
|
||||||
}
|
}
|
||||||
link.createMessage(srcId, "");
|
link.createMessage(srcId, "");
|
||||||
|
|
||||||
if ((msgInfo.msgflags & RS_MSG_SYSTEM) && msgInfo.srcId == ownId) {
|
if ((msgInfo.msgflags & RS_MSG_SYSTEM) && msgInfo.rspeerid_srcId == ownId) {
|
||||||
ui.fromText->setText("RetroShare");
|
ui.fromText->setText("RetroShare");
|
||||||
} else {
|
} else {
|
||||||
ui.fromText->setText(link.toHtml());
|
ui.fromText->setText(link.toHtml());
|
||||||
|
|
250
retroshare-gui/src/gui/settings/GlobalRouterStatistics.cpp
Normal file
250
retroshare-gui/src/gui/settings/GlobalRouterStatistics.cpp
Normal file
|
@ -0,0 +1,250 @@
|
||||||
|
/****************************************************************
|
||||||
|
* RetroShare is distributed under the following license:
|
||||||
|
*
|
||||||
|
* Copyright (C) 20011, RetroShare Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
****************************************************************/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStylePainter>
|
||||||
|
#include <QLayout>
|
||||||
|
|
||||||
|
#include <retroshare/rsgrouter.h>
|
||||||
|
#include <retroshare/rspeers.h>
|
||||||
|
#include "GlobalRouterStatistics.h"
|
||||||
|
|
||||||
|
#include "gui/settings/rsharesettings.h"
|
||||||
|
|
||||||
|
static const int MAX_TUNNEL_REQUESTS_DISPLAY = 10 ;
|
||||||
|
|
||||||
|
static QColor colorScale(float f)
|
||||||
|
{
|
||||||
|
if(f == 0)
|
||||||
|
return QColor::fromHsv(0,0,192) ;
|
||||||
|
else
|
||||||
|
return QColor::fromHsv((int)((1.0-f)*280),200,255) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalRouterStatistics::GlobalRouterStatistics(QWidget *parent)
|
||||||
|
: RsAutoUpdatePage(2000,parent)
|
||||||
|
{
|
||||||
|
setupUi(this) ;
|
||||||
|
|
||||||
|
m_bProcessSettings = false;
|
||||||
|
|
||||||
|
_router_F->setWidget( _tst_CW = new GlobalRouterStatisticsWidget() ) ;
|
||||||
|
|
||||||
|
// load settings
|
||||||
|
processSettings(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalRouterStatistics::~GlobalRouterStatistics()
|
||||||
|
{
|
||||||
|
|
||||||
|
// save settings
|
||||||
|
processSettings(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalRouterStatistics::processSettings(bool bLoad)
|
||||||
|
{
|
||||||
|
m_bProcessSettings = true;
|
||||||
|
|
||||||
|
Settings->beginGroup(QString("GlobalRouterStatistics"));
|
||||||
|
|
||||||
|
if (bLoad) {
|
||||||
|
// load settings
|
||||||
|
|
||||||
|
// state of splitter
|
||||||
|
//splitter->restoreState(Settings->value("Splitter").toByteArray());
|
||||||
|
} else {
|
||||||
|
// save settings
|
||||||
|
|
||||||
|
// state of splitter
|
||||||
|
//Settings->setValue("Splitter", splitter->saveState());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings->endGroup();
|
||||||
|
|
||||||
|
m_bProcessSettings = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalRouterStatistics::updateDisplay()
|
||||||
|
{
|
||||||
|
_tst_CW->updateContent() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GlobalRouterStatistics::getPeerName(const RsPeerId &peer_id)
|
||||||
|
{
|
||||||
|
static std::map<RsPeerId, QString> names ;
|
||||||
|
|
||||||
|
std::map<RsPeerId,QString>::const_iterator it = names.find(peer_id) ;
|
||||||
|
|
||||||
|
if( it != names.end())
|
||||||
|
return it->second ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RsPeerDetails detail ;
|
||||||
|
if(!rsPeers->getPeerDetails(peer_id,detail))
|
||||||
|
return tr("Unknown Peer");
|
||||||
|
|
||||||
|
return (names[peer_id] = QString::fromUtf8(detail.name.c_str())) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalRouterStatisticsWidget::GlobalRouterStatisticsWidget(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
maxWidth = 400 ;
|
||||||
|
maxHeight = 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalRouterStatisticsWidget::updateContent()
|
||||||
|
{
|
||||||
|
std::vector<RsGRouter::GRouterRoutingCacheInfo> cache_infos ;
|
||||||
|
RsGRouter::GRouterRoutingMatrixInfo matrix_info ;
|
||||||
|
|
||||||
|
rsGRouter->getRoutingCacheInfo(cache_infos) ;
|
||||||
|
rsGRouter->getRoutingMatrixInfo(matrix_info) ;
|
||||||
|
|
||||||
|
// What do we need to draw?
|
||||||
|
//
|
||||||
|
// Routing matrix
|
||||||
|
// Key [][][][][][][][][][]
|
||||||
|
//
|
||||||
|
// -> each [] shows a square (one per friend location) that is the routing probabilities for all connected friends
|
||||||
|
// computed using the "computeRoutingProbabilitites()" method.
|
||||||
|
//
|
||||||
|
// Own key ids
|
||||||
|
// key service id description
|
||||||
|
//
|
||||||
|
// Data items
|
||||||
|
// Msg id Local origin Destination Time Status
|
||||||
|
//
|
||||||
|
static const int cellx = 6 ;
|
||||||
|
static const int celly = 10+4 ;
|
||||||
|
|
||||||
|
QPixmap tmppixmap(maxWidth, maxHeight);
|
||||||
|
tmppixmap.fill(this, 0, 0);
|
||||||
|
setFixedHeight(maxHeight);
|
||||||
|
|
||||||
|
QPainter painter(&tmppixmap);
|
||||||
|
painter.initFrom(this);
|
||||||
|
painter.setPen(QColor::fromRgb(0,0,0)) ;
|
||||||
|
|
||||||
|
maxHeight = 500 ;
|
||||||
|
|
||||||
|
// std::cerr << "Drawing into pixmap of size " << maxWidth << "x" << maxHeight << std::endl;
|
||||||
|
// draw...
|
||||||
|
int ox=5,oy=5 ;
|
||||||
|
|
||||||
|
painter.drawText(ox,oy+celly,tr("Pending packets")+":" + QString::number(cache_infos.size())) ; oy += celly*2 ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<cache_infos.size();++i)
|
||||||
|
{
|
||||||
|
QString packet_string ;
|
||||||
|
packet_string += QString::number(cache_infos[i].mid,16) ;
|
||||||
|
packet_string += tr(" by ")+QString::fromStdString(cache_infos[i].local_origin.toStdString()) ;
|
||||||
|
packet_string += tr(" to ")+QString::fromStdString(cache_infos[i].destination.toStdString()) ;
|
||||||
|
packet_string += tr(" Status ")+QString::number(cache_infos[i].status) ;
|
||||||
|
|
||||||
|
painter.drawText(ox+2*cellx,oy+celly,packet_string ) ; oy += celly ;
|
||||||
|
}
|
||||||
|
|
||||||
|
oy += celly ;
|
||||||
|
|
||||||
|
painter.drawText(ox,oy+celly,tr("Managed keys")+":" + QString::number(matrix_info.published_keys.size())) ; oy += celly*2 ;
|
||||||
|
|
||||||
|
for(std::map<GRouterKeyId,RsGRouter::GRouterPublishedKeyInfo>::const_iterator it(matrix_info.published_keys.begin());it!=matrix_info.published_keys.end();++it)
|
||||||
|
{
|
||||||
|
QString packet_string ;
|
||||||
|
packet_string += QString::fromStdString(it->first.toStdString()) ;
|
||||||
|
packet_string += tr(" : Service ID = ")+QString::number(it->second.service_id,16) ;
|
||||||
|
packet_string += " \""+QString::fromUtf8(it->second.description_string.c_str()) + "\"" ;
|
||||||
|
|
||||||
|
painter.drawText(ox+2*cellx,oy+celly,packet_string ) ; oy += celly ;
|
||||||
|
}
|
||||||
|
oy += celly ;
|
||||||
|
|
||||||
|
QString prob_string ;
|
||||||
|
|
||||||
|
painter.drawText(ox+0*cellx,oy+celly,tr("Routing matrix (")) ;
|
||||||
|
|
||||||
|
// draw scale
|
||||||
|
|
||||||
|
for(int i=0;i<100;++i)
|
||||||
|
{
|
||||||
|
painter.setPen(colorScale(i/100.0)) ;
|
||||||
|
painter.drawLine(ox+120+i,oy+celly+2,ox+120+i,oy+2) ;
|
||||||
|
}
|
||||||
|
painter.setPen(QColor::fromRgb(0,0,0)) ;
|
||||||
|
|
||||||
|
painter.drawText(ox+230,oy+celly,")") ;
|
||||||
|
|
||||||
|
oy += celly ;
|
||||||
|
oy += celly ;
|
||||||
|
|
||||||
|
static const int MaxKeySize = 20 ;
|
||||||
|
|
||||||
|
for(std::map<GRouterKeyId,std::vector<float> >::const_iterator it(matrix_info.per_friend_probabilities.begin());it!=matrix_info.per_friend_probabilities.end();++it)
|
||||||
|
{
|
||||||
|
painter.drawText(ox+2*cellx,oy+celly,QString::fromStdString(it->first.toStdString())+" : ") ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<matrix_info.friend_ids.size();++i)
|
||||||
|
painter.fillRect(ox+(MaxKeySize + i)*cellx+200,oy,cellx,celly,colorScale(it->second[i])) ;
|
||||||
|
|
||||||
|
oy += celly ;
|
||||||
|
}
|
||||||
|
|
||||||
|
oy += celly ;
|
||||||
|
oy += celly ;
|
||||||
|
|
||||||
|
// update the pixmap
|
||||||
|
//
|
||||||
|
pixmap = tmppixmap;
|
||||||
|
maxHeight = oy ;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GlobalRouterStatisticsWidget::speedString(float f)
|
||||||
|
{
|
||||||
|
if(f < 1.0f)
|
||||||
|
return QString("0 B/s") ;
|
||||||
|
if(f < 1024.0f)
|
||||||
|
return QString::number((int)f)+" B/s" ;
|
||||||
|
|
||||||
|
return QString::number(f/1024.0,'f',2) + " KB/s";
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalRouterStatisticsWidget::paintEvent(QPaintEvent */*event*/)
|
||||||
|
{
|
||||||
|
QStylePainter(this).drawPixmap(0, 0, pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalRouterStatisticsWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QRect TaskGraphRect = geometry();
|
||||||
|
maxWidth = TaskGraphRect.width();
|
||||||
|
maxHeight = TaskGraphRect.height() ;
|
||||||
|
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
updateContent();
|
||||||
|
}
|
||||||
|
|
71
retroshare-gui/src/gui/settings/GlobalRouterStatistics.h
Normal file
71
retroshare-gui/src/gui/settings/GlobalRouterStatistics.h
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/****************************************************************
|
||||||
|
* RetroShare is distributed under the following license:
|
||||||
|
*
|
||||||
|
* Copyright (C) 20011, RetroShare Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
****************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QPoint>
|
||||||
|
#include <retroshare/rsgrouter.h>
|
||||||
|
#include <retroshare/rstypes.h>
|
||||||
|
|
||||||
|
#include "RsAutoUpdatePage.h"
|
||||||
|
#include "ui_GlobalRouterStatistics.h"
|
||||||
|
|
||||||
|
class GlobalRouterStatisticsWidget ;
|
||||||
|
|
||||||
|
class GlobalRouterStatistics: public RsAutoUpdatePage, public Ui::GlobalRouterStatistics
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GlobalRouterStatistics(QWidget *parent = NULL) ;
|
||||||
|
~GlobalRouterStatistics();
|
||||||
|
|
||||||
|
// Cache for peer names.
|
||||||
|
static QString getPeerName(const RsPeerId& peer_id) ;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void processSettings(bool bLoad);
|
||||||
|
bool m_bProcessSettings;
|
||||||
|
|
||||||
|
virtual void updateDisplay() ;
|
||||||
|
|
||||||
|
GlobalRouterStatisticsWidget *_tst_CW ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
class GlobalRouterStatisticsWidget: public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GlobalRouterStatisticsWidget(QWidget *parent = NULL) ;
|
||||||
|
|
||||||
|
virtual void paintEvent(QPaintEvent *event) ;
|
||||||
|
virtual void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
|
void updateContent() ;
|
||||||
|
private:
|
||||||
|
static QString speedString(float f) ;
|
||||||
|
|
||||||
|
QPixmap pixmap ;
|
||||||
|
int maxWidth,maxHeight ;
|
||||||
|
};
|
||||||
|
|
55
retroshare-gui/src/gui/settings/GlobalRouterStatistics.ui
Normal file
55
retroshare-gui/src/gui/settings/GlobalRouterStatistics.ui
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>GlobalRouterStatistics</class>
|
||||||
|
<widget class="QWidget" name="GlobalRouterStatistics">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>611</width>
|
||||||
|
<height>408</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Router Statistics</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="images.qrc">
|
||||||
|
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QSplitter" name="splitter">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QScrollArea" name="_router_F">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>593</width>
|
||||||
|
<height>390</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="images.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -22,6 +22,7 @@
|
||||||
#include "ServerPage.h"
|
#include "ServerPage.h"
|
||||||
#include <gui/FileTransfer/TurtleRouterDialog.h>
|
#include <gui/FileTransfer/TurtleRouterDialog.h>
|
||||||
#include <gui/FileTransfer/TurtleRouterStatistics.h>
|
#include <gui/FileTransfer/TurtleRouterStatistics.h>
|
||||||
|
#include <gui/settings/GlobalRouterStatistics.h>
|
||||||
|
|
||||||
#include "rshare.h"
|
#include "rshare.h"
|
||||||
#include "rsharesettings.h"
|
#include "rsharesettings.h"
|
||||||
|
@ -78,12 +79,13 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
|
||||||
trs->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding)) ;
|
trs->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding)) ;
|
||||||
ui.tabWidget->widget(2)->layout()->addWidget(trs) ;
|
ui.tabWidget->widget(2)->layout()->addWidget(trs) ;
|
||||||
ui.tabWidget->widget(2)->layout()->setContentsMargins(0,5,0,0) ;
|
ui.tabWidget->widget(2)->layout()->setContentsMargins(0,5,0,0) ;
|
||||||
|
ui.tabWidget->widget(2)->layout()->addItem( new QSpacerItem(0,0,QSizePolicy::Expanding, QSizePolicy::Minimum)) ;
|
||||||
QSpacerItem *verticalSpacer = new QSpacerItem(0,0,QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
||||||
|
|
||||||
ui.tabWidget->widget(2)->layout()->addItem(verticalSpacer) ;
|
|
||||||
ui.tabWidget->widget(2)->layout()->update() ;
|
ui.tabWidget->widget(2)->layout()->update() ;
|
||||||
|
|
||||||
|
GlobalRouterStatistics *grs = new GlobalRouterStatistics ;
|
||||||
|
grs->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding)) ;
|
||||||
|
ui.tabWidget->addTab(grs,tr("Global routing")) ;
|
||||||
|
|
||||||
ui.torpage_incoming->setVisible(false);
|
ui.torpage_incoming->setVisible(false);
|
||||||
|
|
||||||
/* Hide platform specific features */
|
/* Hide platform specific features */
|
||||||
|
|
|
@ -25,7 +25,7 @@ gxs {
|
||||||
CONFIG += gxsgui
|
CONFIG += gxsgui
|
||||||
# thewire is incomplete - dont enable
|
# thewire is incomplete - dont enable
|
||||||
#CONFIG += thewire
|
#CONFIG += thewire
|
||||||
#CONFIG += photoshare
|
CONFIG += photoshare
|
||||||
|
|
||||||
DEFINES += RS_ENABLE_GXS
|
DEFINES += RS_ENABLE_GXS
|
||||||
}
|
}
|
||||||
|
@ -388,6 +388,7 @@ HEADERS += rshare.h \
|
||||||
gui/msgs/MessageUserNotify.h \
|
gui/msgs/MessageUserNotify.h \
|
||||||
gui/images/retroshare_win.rc.h \
|
gui/images/retroshare_win.rc.h \
|
||||||
gui/settings/rsharesettings.h \
|
gui/settings/rsharesettings.h \
|
||||||
|
gui/settings/GlobalRouterStatistics.h \
|
||||||
gui/settings/RsharePeerSettings.h \
|
gui/settings/RsharePeerSettings.h \
|
||||||
gui/settings/rsettings.h \
|
gui/settings/rsettings.h \
|
||||||
gui/settings/rsettingswin.h \
|
gui/settings/rsettingswin.h \
|
||||||
|
@ -567,6 +568,7 @@ FORMS += gui/StartDialog.ui \
|
||||||
gui/settings/ChatPage.ui \
|
gui/settings/ChatPage.ui \
|
||||||
gui/settings/RelayPage.ui \
|
gui/settings/RelayPage.ui \
|
||||||
gui/settings/ServicePermissionsPage.ui \
|
gui/settings/ServicePermissionsPage.ui \
|
||||||
|
gui/settings/GlobalRouterStatistics.ui \
|
||||||
gui/settings/PluginItem.ui \
|
gui/settings/PluginItem.ui \
|
||||||
gui/toaster/MessageToaster.ui \
|
gui/toaster/MessageToaster.ui \
|
||||||
gui/toaster/OnlineToaster.ui \
|
gui/toaster/OnlineToaster.ui \
|
||||||
|
@ -746,6 +748,7 @@ SOURCES += main.cpp \
|
||||||
gui/style/StyleDialog.cpp \
|
gui/style/StyleDialog.cpp \
|
||||||
gui/settings/rsharesettings.cpp \
|
gui/settings/rsharesettings.cpp \
|
||||||
gui/settings/RsharePeerSettings.cpp \
|
gui/settings/RsharePeerSettings.cpp \
|
||||||
|
gui/settings/GlobalRouterStatistics.cpp \
|
||||||
gui/settings/rsettings.cpp \
|
gui/settings/rsettings.cpp \
|
||||||
gui/settings/rsettingswin.cpp \
|
gui/settings/rsettingswin.cpp \
|
||||||
gui/settings/GeneralPage.cpp \
|
gui/settings/GeneralPage.cpp \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue