This commit is contained in:
Gio 2016-07-15 11:25:04 +02:00
commit c59686ff3c
69 changed files with 2610 additions and 2170 deletions

3
.gitignore vendored
View File

@ -1,5 +1,8 @@
/RetroShare.pro.user /RetroShare.pro.user
*.o *.o
*.sw?
*.so
*.so.*
moc_*.cpp moc_*.cpp
qrc_*.cpp qrc_*.cpp
ui_*.h ui_*.h

View File

@ -1,5 +1,11 @@
retroshare06 (0.6.0-1.XXXXXX~YYYYYY) YYYYYY; urgency=low retroshare06 (0.6.0-1.XXXXXX~YYYYYY) YYYYYY; urgency=low
9f7ef8b csoler Tue, 28 Jun 2016 20:59:56 -0400 fixed possible cross deadlocks between RsGxsGenExchange and RsGxsNetService
00bdc50 csoler Tue, 28 Jun 2016 17:56:37 -0400 updated changelog
bb82b6e csoler Tue, 28 Jun 2016 14:35:59 -0400 Merge pull request #429 from PhenomRetroShare/Fix_StandardQSS
456751a Phenom Tue, 28 Jun 2016 20:23:32 +0200 Fix ProgressBar Chunk with Standard.qss
019ed12 csoler Tue, 28 Jun 2016 12:37:04 -0400 Merge pull request #428 from sehraf/pr-fix-udp
ea07a13 sehraf Tue, 28 Jun 2016 17:37:22 +0200 fix TcpPacket::readPacket
c15c979 csoler Mon, 27 Jun 2016 17:17:28 +0100 Merge pull request #426 from sehraf/pr-disable-dht-stunner c15c979 csoler Mon, 27 Jun 2016 17:17:28 +0100 Merge pull request #426 from sehraf/pr-disable-dht-stunner
ff86678 csoler Sun, 26 Jun 2016 23:14:01 -0400 clear error queue before calling SSL_read()/SSL_write(), to avoid remaining errors to corrupt the next connection attempts and cause disconnections ff86678 csoler Sun, 26 Jun 2016 23:14:01 -0400 clear error queue before calling SSL_read()/SSL_write(), to avoid remaining errors to corrupt the next connection attempts and cause disconnections
31089d7 csoler Sat, 25 Jun 2016 19:12:35 +0100 added auto-clean of pending data in pqistreamer after connection is closed, to avoid confusing the peer after re-connecting (probably not the cause of the SSL error) 31089d7 csoler Sat, 25 Jun 2016 19:12:35 +0100 added auto-clean of pending data in pqistreamer after connection is closed, to avoid confusing the peer after re-connecting (probably not the cause of the SSL error)

View File

@ -87,8 +87,10 @@ bool UdpStack::getLocalAddress(struct sockaddr_in &local)
bool UdpStack::resetAddress(struct sockaddr_in &local) bool UdpStack::resetAddress(struct sockaddr_in &local)
{ {
std::cerr << "UdpStack::resetAddress(" << local << ")"; #ifdef DEBUG_UDP_RECV
std::cerr << "UdpStack::resetAddress(" << local << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
laddr = local; laddr = local;
return udpLayer->reset(local); return udpLayer->reset(local);

View File

@ -34,7 +34,6 @@
#include "pqi/p3historymgr.h" #include "pqi/p3historymgr.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
#include "retroshare/rsreputations.h"
#include "retroshare/rsidentity.h" #include "retroshare/rsidentity.h"
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#include "gxs/rsgixs.h" #include "gxs/rsgixs.h"
@ -139,7 +138,7 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
return false ; return false ;
} }
if(rsReputations->isIdentityBanned(cli->signature.keyId)) if(rsIdentity->isBanned(cli->signature.keyId))
{ {
std::cerr << "(WW) Received lobby msg/item from banned identity " << cli->signature.keyId << ". Dropping it." << std::endl; std::cerr << "(WW) Received lobby msg/item from banned identity " << cli->signature.keyId << ". Dropping it." << std::endl;
return false ; return false ;
@ -648,7 +647,7 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
#endif #endif
time_t now = time(NULL) ; time_t now = time(NULL) ;
if(rsReputations->isIdentityBanned(item->signature.keyId)) if(rsIdentity->isBanned(item->signature.keyId))
{ {
std::cerr << "(WW) Received lobby msg/item from banned identity " << item->signature.keyId << ". Dropping it." << std::endl; std::cerr << "(WW) Received lobby msg/item from banned identity " << item->signature.keyId << ". Dropping it." << std::endl;
return ; return ;

View File

@ -431,7 +431,7 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
return !results.empty() ; return !results.empty() ;
} }
bool FileIndexMonitor::findLocalFile(const RsFileHash& hash,FileSearchFlags hint_flags, const RsPeerId& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const bool FileIndexMonitor::findLocalFile(const RsFileHash& hash,FileSearchFlags hint_flags, const RsPeerId& peer_id,std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<RsNodeGroupId>& parent_groups) const
{ {
std::list<FileEntry *> results; std::list<FileEntry *> results;
bool ok = false; bool ok = false;
@ -1668,7 +1668,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, FileSear
return true ; return true ;
} }
void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list<std::string>& parent_groups) const void FileIndexMonitor::locked_findShareFlagsAndParentGroups(FileEntry *file,FileStorageFlags& flags,std::list<RsNodeGroupId>& parent_groups) const
{ {
flags.clear() ; flags.clear() ;
static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ; static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ;

View File

@ -110,7 +110,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread
virtual ~FileIndexMonitor(); virtual ~FileIndexMonitor();
/* external interface for filetransfer */ /* external interface for filetransfer */
bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const; bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<RsNodeGroupId>& parent_groups) const;
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) ; int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) ;
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) const ; int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
@ -176,7 +176,7 @@ class FileIndexMonitor: public CacheSource, public RsTickingThread
time_t locked_saveFileIndexes(bool update_cache) ; time_t locked_saveFileIndexes(bool update_cache) ;
// Finds the share flags associated with this file entry. // Finds the share flags associated with this file entry.
void locked_findShareFlagsAndParentGroups(FileEntry *fe,FileStorageFlags& shareflags,std::list<std::string>& parent_groups) const ; void locked_findShareFlagsAndParentGroups(FileEntry *fe, FileStorageFlags& shareflags, std::list<RsNodeGroupId> &parent_groups) const ;
std::string locked_findRealRoot(std::string base) const; std::string locked_findRealRoot(std::string base) const;

View File

@ -25,6 +25,7 @@
#include "ft/ftdbase.h" #include "ft/ftdbase.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include "retroshare/rspeers.h"
#include "serialiser/rsconfigitems.h" #include "serialiser/rsconfigitems.h"
@ -237,11 +238,13 @@ bool ftFiMonitor::saveList(bool &cleanup, std::list<RsItem *>& sList)
for(it = dirList.begin(); it != dirList.end(); ++it) for(it = dirList.begin(); it != dirList.end(); ++it)
{ {
RsFileConfigItem *fi = new RsFileConfigItem(); RsFileConfigItem *fi = new RsFileConfigItem();
fi->file.path = (*it).filename ; fi->file.path = (*it).filename ;
fi->file.name = (*it).virtualname ; fi->file.name = (*it).virtualname ;
fi->flags = (*it).shareflags.toUInt32() ; fi->flags = (*it).shareflags.toUInt32() ;
fi->parent_groups = (*it).parent_groups ;
for(std::list<RsNodeGroupId>::const_iterator it2( (*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2)
fi->parent_groups.ids.insert(*it2) ;
sList.push_back(fi); sList.push_back(fi);
} }
@ -332,25 +335,53 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
continue ; continue ;
} }
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it); // 07/05/2016 - This ensures backward compatibility. Can be removed in a few weeks.
if (!fi) RsFileConfigItem_deprecated *fib = dynamic_cast<RsFileConfigItem_deprecated *>(*it);
{ if (fib)
delete (*it); {
continue; /* ensure that it exists? */
}
/* ensure that it exists? */ SharedDirInfo info ;
info.filename = RsDirUtil::convertPathToUnix(fib->file.path);
info.virtualname = fib->file.name;
info.shareflags = FileStorageFlags(fib->flags) ;
info.shareflags &= PERMISSION_MASK ;
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons
SharedDirInfo info ; for(std::list<std::string>::const_iterator itt(fib->parent_groups.begin());itt!=fib->parent_groups.end();++itt)
info.filename = RsDirUtil::convertPathToUnix(fi->file.path); {
info.virtualname = fi->file.name; RsGroupInfo ginfo;
info.parent_groups = fi->parent_groups;
info.shareflags = FileStorageFlags(fi->flags) ; if(rsPeers->getGroupInfoByName(*itt,ginfo) )
info.shareflags &= PERMISSION_MASK ; {
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons info.parent_groups.push_back(ginfo.id) ;
std::cerr << "(II) converted old group ID \"" << *itt << "\" into corresponding new group id " << ginfo.id << std::endl;
}
else
std::cerr << "(EE) cannot convert old group ID \"" << *itt << "\" into corresponding new group id: no candidate found. " << std::endl;
}
dirList.push_back(info) ;
}
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
if (fi)
{
/* ensure that it exists? */
SharedDirInfo info ;
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
info.virtualname = fi->file.name;
info.shareflags = FileStorageFlags(fi->flags) ;
info.shareflags &= PERMISSION_MASK ;
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons
for(std::set<RsNodeGroupId>::const_iterator itt(fi->parent_groups.ids.begin());itt!=fi->parent_groups.ids.end();++itt)
info.parent_groups.push_back(*itt) ;
dirList.push_back(info) ;
}
dirList.push_back(info) ;
delete *it ; delete *it ;
} }

View File

@ -395,7 +395,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list<RsItem *>& sList)
std::map<RsFileHash, FileDetails>::const_iterator it; std::map<RsFileHash, FileDetails>::const_iterator it;
for(it = mFiles.begin(); it != mFiles.end(); ++it) for(it = mFiles.begin(); it != mFiles.end(); ++it)
{ {
RsFileConfigItem *fi = new RsFileConfigItem(); RsFileConfigItem_deprecated *fi = new RsFileConfigItem_deprecated();
fi->file.path = (it->second).info.path; fi->file.path = (it->second).info.path;
fi->file.name = (it->second).info.fname; fi->file.name = (it->second).info.fname;
fi->file.hash = (it->second).info.hash; fi->file.hash = (it->second).info.hash;
@ -428,7 +428,7 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
for(it = load.begin(); it != load.end(); ++it) for(it = load.begin(); it != load.end(); ++it)
{ {
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it); RsFileConfigItem_deprecated *fi = dynamic_cast<RsFileConfigItem_deprecated *>(*it);
if (!fi) if (!fi)
{ {
delete (*it); delete (*it);

View File

@ -191,7 +191,6 @@
#include "turtle/p3turtle.h" #include "turtle/p3turtle.h"
#include "gxs/rsgixs.h" #include "gxs/rsgixs.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsreputations.h"
#include "p3grouter.h" #include "p3grouter.h"
#include "grouteritems.h" #include "grouteritems.h"
@ -1994,7 +1993,7 @@ bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item,uint32_t& er
{ {
try try
{ {
if(rsReputations->isIdentityBanned(item->signature.keyId)) if(rsIdentity->isBanned(item->signature.keyId))
{ {
std::cerr << "(WW) received global router message from banned identity " << item->signature.keyId << ". Rejecting the message." << std::endl; std::cerr << "(WW) received global router message from banned identity " << item->signature.keyId << ". Rejecting the message." << std::endl;
return false ; return false ;

View File

@ -27,6 +27,7 @@
/***** /*****
* #define RS_DATA_SERVICE_DEBUG 1 * #define RS_DATA_SERVICE_DEBUG 1
* #define RS_DATA_SERVICE_DEBUG_TIME 1 * #define RS_DATA_SERVICE_DEBUG_TIME 1
* #define RS_DATA_SERVICE_DEBUG_CACHE 1
****/ ****/
#include <fstream> #include <fstream>
@ -123,6 +124,7 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
: RsGeneralDataService(), mDbMutex("RsDataService"), mServiceDir(serviceDir), mDbName(dbName), mDbPath(mServiceDir + "/" + dbName), mServType(serviceType), mDb(NULL) : RsGeneralDataService(), mDbMutex("RsDataService"), mServiceDir(serviceDir), mDbName(dbName), mDbPath(mServiceDir + "/" + dbName), mServType(serviceType), mDb(NULL)
{ {
bool isNewDatabase = !RsDirUtil::fileExists(mDbPath); bool isNewDatabase = !RsDirUtil::fileExists(mDbPath);
mGrpMetaDataCache_ContainsAllDatabase = false ;
mDb = new RetroDb(mDbPath, RetroDb::OPEN_READWRITE_CREATE, key); mDb = new RetroDb(mDbPath, RetroDb::OPEN_READWRITE_CREATE, key);
@ -1231,6 +1233,9 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
if (c) if (c)
{ {
locked_retrieveMsgMeta(c, metaSet); locked_retrieveMsgMeta(c, metaSet);
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving (all) Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
#endif
} }
}else{ }else{
@ -1245,6 +1250,9 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
if (c) if (c)
{ {
locked_retrieveMsgMeta(c, metaSet); locked_retrieveMsgMeta(c, metaSet);
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
#endif
} }
} }
} }
@ -1296,11 +1304,21 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
int requestedGroups = grp.size(); int requestedGroups = grp.size();
#endif #endif
if(grp.empty()){ if(grp.empty())
{
if(mGrpMetaDataCache_ContainsAllDatabase) // grab all the stash from the cache, so as to avoid decryption costs.
{
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": RsDataService::retrieveGxsGrpMetaData() retrieving all from cache!" << std::endl;
#endif
for(std::map<RsGxsGroupId,RsGxsGrpMetaData>::const_iterator it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it)
grp[it->first] = new RsGxsGrpMetaData(it->second);
}
else
{
#ifdef RS_DATA_SERVICE_DEBUG #ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all"; std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all" << std::endl;
std::cerr << std::endl;
#endif #endif
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", "");
@ -1315,6 +1333,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
if(g) if(g)
{ {
grp[g->mGroupId] = g; grp[g->mGroupId] = g;
mGrpMetaDataCache[g->mGroupId] = *g ;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void *)this << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl;
#endif
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -1325,12 +1347,29 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
delete c; delete c;
} }
mGrpMetaDataCache_ContainsAllDatabase = true ;
}
}else }else
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin(); std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
for(; mit != grp.end(); ++mit) for(; mit != grp.end(); ++mit)
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData>::const_iterator itt = mGrpMetaDataCache.find(mit->first) ;
if(itt != mGrpMetaDataCache.end())
{
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first << " from cache!" << std::endl;
#endif
grp[mit->first] = new RsGxsGrpMetaData(itt->second) ;
}
else
{
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first ;
#endif
const RsGxsGroupId& grpId = mit->first; const RsGxsGroupId& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", "");
@ -1338,6 +1377,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
{ {
bool valid = c->moveToFirst(); bool valid = c->moveToFirst();
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
if(!valid)
std::cerr << " Empty query! GrpId " << grpId << " is not in database" << std::endl;
#endif
while(valid) while(valid)
{ {
RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0); RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0);
@ -1345,6 +1388,10 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
if(g) if(g)
{ {
grp[g->mGroupId] = g; grp[g->mGroupId] = g;
mGrpMetaDataCache[g->mGroupId] = *g ;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << ". Got it. Updating cache." << std::endl;
#endif
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -1354,7 +1401,11 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
} }
delete c; delete c;
} }
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
else
std::cerr << ". not found!" << std::endl;
#endif
}
} }
} }
@ -1391,13 +1442,29 @@ int RsDataService::resetDataStore()
int RsDataService::updateGroupMetaData(GrpLocMetaData &meta) int RsDataService::updateGroupMetaData(GrpLocMetaData &meta)
{ {
RsStackMutex stack(mDbMutex); #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": Updating Grp Meta data: grpId = " << meta.grpId << std::endl;
#endif
RsStackMutex stack(mDbMutex);
RsGxsGroupId& grpId = meta.grpId; RsGxsGroupId& grpId = meta.grpId;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": erasing old entry from cache." << std::endl;
#endif
mGrpMetaDataCache_ContainsAllDatabase = false ;
mGrpMetaDataCache.erase(meta.grpId) ;
return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", meta.val) ? 1 : 0; return mDb->sqlUpdate(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", meta.val) ? 1 : 0;
} }
int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData) int RsDataService::updateMessageMetaData(MsgLocMetaData &metaData)
{ {
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void*)this << ": Updating Msg Meta data: grpId = " << metaData.msgId.first << " msgId = " << metaData.msgId.second << std::endl;
#endif
RsStackMutex stack(mDbMutex); RsStackMutex stack(mDbMutex);
RsGxsGroupId& grpId = metaData.msgId.first; RsGxsGroupId& grpId = metaData.msgId.first;
RsGxsMessageId& msgId = metaData.msgId.second; RsGxsMessageId& msgId = metaData.msgId.second;

View File

@ -340,6 +340,13 @@ private:
uint16_t mServType; uint16_t mServType;
RetroDb* mDb; RetroDb* mDb;
// used to store metadata instead of reading it from the database.
// The boolean variable below is also used to force re-reading when
// the entre list of grp metadata is requested (which happens quite often)
std::map<RsGxsGroupId,RsGxsGrpMetaData> mGrpMetaDataCache ;
bool mGrpMetaDataCache_ContainsAllDatabase ;
}; };
#endif // RSDATASERVICE_H #endif // RSDATASERVICE_H

View File

@ -881,8 +881,15 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
{ {
// now check reputation of the message author // now check reputation of the message author
float reputation_threshold = ( (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) && !(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)) ? (RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM): (RsReputations::REPUTATION_THRESHOLD_DEFAULT) ; float reputation_threshold = RsReputations::REPUTATION_THRESHOLD_DEFAULT;
if( (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN) && !(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN))
reputation_threshold = RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM;
else if( (signFlag & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) && !(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED))
reputation_threshold = RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM;
else
reputation_threshold = RsReputations::REPUTATION_THRESHOLD_DEFAULT;
if(details.mReputation.mOverallReputationScore < reputation_threshold) if(details.mReputation.mOverallReputationScore < reputation_threshold)
{ {
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG

View File

@ -204,9 +204,9 @@
#include "rsgxsnetservice.h" #include "rsgxsnetservice.h"
#include "gxssecurity.h" #include "gxssecurity.h"
#include "retroshare/rsconfig.h" #include "retroshare/rsconfig.h"
#include "retroshare/rsreputations.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rsgxscircles.h" #include "retroshare/rsgxscircles.h"
#include "retroshare/rspeers.h"
#include "pgp/pgpauxutils.h" #include "pgp/pgpauxutils.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/rsmemory.h" #include "util/rsmemory.h"
@ -266,7 +266,7 @@ static const uint32_t RS_NXS_ITEM_ENCRYPTION_STATUS_GXS_KEY_MISSING = 0x05 ;
|| defined(NXS_NET_DEBUG_4) || defined(NXS_NET_DEBUG_5) || defined(NXS_NET_DEBUG_6) || defined(NXS_NET_DEBUG_7) || defined(NXS_NET_DEBUG_4) || defined(NXS_NET_DEBUG_5) || defined(NXS_NET_DEBUG_6) || defined(NXS_NET_DEBUG_7)
static const RsPeerId peer_to_print = RsPeerId(std::string("")) ; static const RsPeerId peer_to_print = RsPeerId(std::string("")) ;
static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("" )) ; // use this to allow to this group id only, or "" for all IDs static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("87c769d3ffeafdc4433f557d50cdf2e8" )) ; // use this to allow to this group id only, or "" for all IDs
static const uint32_t service_to_print = 0x215 ; // use this to allow to this service id only, or 0 for all services static const uint32_t service_to_print = 0x215 ; // use this to allow to this service id only, or 0 for all services
// warning. Numbers should be SERVICE IDS (see serialiser/rsserviceids.h. E.g. 0x0215 for forums) // warning. Numbers should be SERVICE IDS (see serialiser/rsserviceids.h. E.g. 0x0215 for forums)
@ -2928,9 +2928,8 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
#endif #endif
continue; continue;
} }
// FIXTESTS global variable rsReputations not available in unittests!
if(rsReputations == 0){ std::cerr << "rsReputations==0, accepting all messages!" << std::endl; } if(rsIdentity && rsIdentity->isBanned(syncItem->authorId))
if(rsReputations && rsReputations->isIdentityBanned(syncItem->authorId))
{ {
#ifdef NXS_NET_DEBUG_1 #ifdef NXS_NET_DEBUG_1
GXSNETDEBUG_PG(item->PeerId(),grpId) << ", Identity " << syncItem->authorId << " is banned. Not requesting message!" << std::endl; GXSNETDEBUG_PG(item->PeerId(),grpId) << ", Identity " << syncItem->authorId << " is banned. Not requesting message!" << std::endl;
@ -3174,8 +3173,8 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
latestVersion = grpSyncItem->publishTs > metaIter->second->mPublishTs; latestVersion = grpSyncItem->publishTs > metaIter->second->mPublishTs;
} }
// FIXTESTS global variable rsReputations not available in unittests! // FIXTESTS global variable rsReputations not available in unittests!
if(rsReputations == 0){ std::cerr << "rsReputations==0, accepting all groups!" << std::endl; }
if(!grpSyncItem->authorId.isNull() && rsReputations && rsReputations->isIdentityBanned(grpSyncItem->authorId)) if(!grpSyncItem->authorId.isNull() && rsIdentity && rsIdentity->isBanned(grpSyncItem->authorId))
{ {
#ifdef NXS_NET_DEBUG_0 #ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grpId) << " Identity " << grpSyncItem->authorId << " is banned. Not syncing group." << std::endl; GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grpId) << " Identity " << grpSyncItem->authorId << " is banned. Not syncing group." << std::endl;
@ -4094,7 +4093,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item)
bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool& should_encrypt) bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& /* toVet */, bool& should_encrypt)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendGrpId()"<< std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendGrpId()"<< std::endl;
@ -4125,101 +4124,21 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
#endif #endif
should_encrypt = true ; should_encrypt = true ;
return true ; return true ;
#ifdef TO_BE_REMOVED_OLD_VETTING_FOR_EXTERNAL_CIRCLES
const RsGxsCircleId& circleId = grpMeta.mCircleId;
if(circleId.isNull())
{
std::cerr << " EXTERNAL_CIRCLE missing NULL CircleId: " << grpMeta.mGroupId<< std::endl;
// ERROR, will never be shared.
return false;
}
if(mCircles->isLoaded(circleId))
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " EXTERNAL_CIRCLE, checking mCircles->canSend"<< std::endl;
#endif
// the sending authorisation is based on:
// getPgpId(peer_id) being a signer of one GxsId in the Circle
//
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
bool res = mCircles->canSend(circleId, pgpId);
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " answer is: " << res << std::endl;
#endif
return res ;
}
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " grp not ready. Adding to vetting list." << std::endl;
#endif
toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, circleId, grpMeta.mAuthorId));
return false;
#endif
} }
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
{ {
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
#endif
bool res = checkPermissionsForFriendGroup(sslId,grpMeta) ;
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer: " << res << std::endl;
#endif
return res ;
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " YOUREYESONLY, checking further"<< std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " YOUREYESONLY, checking further"<< std::endl;
#endif #endif
// a non empty internal circle id means this
// is the personal circle owner
if(!grpMeta.mInternalCircle.isNull())
{
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " have mInternalCircle - we are Group creator" << std::endl;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mCircleId: " << grpMeta.mCircleId << std::endl;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle: " << grpMeta.mInternalCircle << std::endl;
#endif
if(mCircles->isLoaded(internalCircleId))
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " circle Loaded - checking mCircles->canSend" << std::endl;
#endif
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
bool should_encrypt = false ;
bool res = mCircles->canSend(internalCircleId, pgpId,should_encrypt);
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " answer is: " << res << std::endl;
#endif
return res ;
}
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle Not Loaded - add to vetting"<< std::endl;
#endif
toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, internalCircleId, grpMeta.mAuthorId));
return false;
}
else
{
// an empty internal circle id means this peer can only
// send circle related info from peer he received it
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle not set, someone else's personal circle"<< std::endl;
#endif
if(grpMeta.mOriginator == sslId)
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator matches -> can send"<< std::endl;
#endif
return true;
}
else
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator doesn't match -> cannot send"<< std::endl;
#endif
return false;
}
}
} }
return true; return true;
@ -4229,121 +4148,51 @@ bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxs
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::checkCanRecvMsgFromPeer()"; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::checkCanRecvMsgFromPeer()";
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " peer Id = " << sslId << ", grpId=" << grpMeta.mGroupId <<std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " peer Id = " << sslId << ", grpId=" << grpMeta.mGroupId <<std::endl;
#endif #endif
// first do the simple checks // first do the simple checks
uint8_t circleType = grpMeta.mCircleType; uint8_t circleType = grpMeta.mCircleType;
should_encrypt_id.clear() ; should_encrypt_id.clear() ;
if(circleType == GXS_CIRCLE_TYPE_LOCAL) if(circleType == GXS_CIRCLE_TYPE_LOCAL)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " LOCAL_CIRCLE, cannot request sync from peer" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " LOCAL_CIRCLE, cannot request sync from peer" << std::endl;
#endif #endif
return false; return false;
} }
if(circleType == GXS_CIRCLE_TYPE_PUBLIC) if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " PUBLIC_CIRCLE, can request msg sync" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " PUBLIC_CIRCLE, can request msg sync" << std::endl;
#endif #endif
return true; return true;
} }
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs will be encrypted." << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs will be encrypted." << std::endl;
#endif
should_encrypt_id = grpMeta.mCircleId ;
return true ;
#ifdef TO_BE_REMOVED_OLD_VETTING_FOR_EXTERNAL_CIRCLES
const RsGxsCircleId& circleId = grpMeta.mCircleId;
if(circleId.isNull())
{
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " ERROR; EXTERNAL_CIRCLE missing NULL CircleId";
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << grpMeta.mGroupId;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << std::endl;
#endif #endif
should_encrypt_id = grpMeta.mCircleId ;
return true ;
}
// should just be shared. ? no - this happens for if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) // do not attempt to sync msg unless to originator or those permitted
// Circle Groups which lose their CircleIds. {
// return true; #ifdef NXS_NET_DEBUG_4
} GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
#endif
bool res = checkPermissionsForFriendGroup(sslId,grpMeta) ;
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer: " << res << std::endl;
#endif
return res ;
}
if(mCircles->isLoaded(circleId)) return true;
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " EXTERNAL_CIRCLE, checking mCircles->canSend" << std::endl;
#endif
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
return mCircles->canSend(circleId, pgpId);
}
else
mCircles->loadCircle(circleId); // simply request for next pass
return false;
#endif
}
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) // do not attempt to sync msg unless to originator or those permitted
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
#endif
// a non empty internal circle id means this
// is the personal circle owner
if(!grpMeta.mInternalCircle.isNull())
{
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " have mInternalCircle - we are Group creator" << std::endl;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mCircleId: " << grpMeta.mCircleId << std::endl;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle: " << grpMeta.mInternalCircle << std::endl;
#endif
if(mCircles->isLoaded(internalCircleId))
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " circle Loaded - checking mCircles->canSend" << std::endl;
#endif
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
bool should_encrypt ;
return mCircles->canSend(internalCircleId, pgpId,should_encrypt);
}
else
mCircles->loadCircle(internalCircleId); // request for next pass
return false;
}
else
{
// an empty internal circle id means this peer can only
// send circle related info from peer he received it
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " mInternalCircle not set, someone else's personal circle" << std::endl;
#endif
if(grpMeta.mOriginator == sslId)
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator matches -> can send" << std::endl;
#endif
return true;
}
else
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Originator doesn't match -> cannot send"<< std::endl;
#endif
return false;
}
}
}
return true;
} }
bool RsGxsNetService::locked_CanReceiveUpdate(RsNxsSyncMsgReqItem *item,bool& grp_is_known) bool RsGxsNetService::locked_CanReceiveUpdate(RsNxsSyncMsgReqItem *item,bool& grp_is_known)
@ -4620,17 +4469,17 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
if(circleType == GXS_CIRCLE_TYPE_LOCAL) if(circleType == GXS_CIRCLE_TYPE_LOCAL)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: LOCAL => returning false" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: LOCAL => returning false" << std::endl;
#endif #endif
return false; return false;
} }
if(circleType == GXS_CIRCLE_TYPE_PUBLIC) if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl;
#endif #endif
return true; return true;
} }
const RsGxsCircleId& circleId = grpMeta.mCircleId; const RsGxsCircleId& circleId = grpMeta.mCircleId;
@ -4638,119 +4487,116 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl;
#endif #endif
should_encrypt_id = circleId ; should_encrypt_id = circleId ;
// For each message ID, check that the author is in the circle. If not, do not send the message, which means, remove it from the list. // For each message ID, check that the author is in the circle. If not, do not send the message, which means, remove it from the list.
// Unsigned messages are still transmitted. This is because in some groups (channels) the posts are not signed. Whether an unsigned post // Unsigned messages are still transmitted. This is because in some groups (channels) the posts are not signed. Whether an unsigned post
// is allowed at this point is anyway already vetted by the RsGxsGenExchange service. // is allowed at this point is anyway already vetted by the RsGxsGenExchange service.
// Messages that stay in the list will be sent. As a consequence true is always returned. // Messages that stay in the list will be sent. As a consequence true is always returned.
// Messages put in vetting list will be dealt with later // Messages put in vetting list will be dealt with later
std::vector<MsgIdCircleVet> toVet; std::vector<MsgIdCircleVet> toVet;
for(uint32_t i=0;i<msgMetas.size();) for(uint32_t i=0;i<msgMetas.size();)
if( msgMetas[i]->mAuthorId.isNull() ) // keep the message in this case if( msgMetas[i]->mAuthorId.isNull() ) // keep the message in this case
++i ; ++i ;
else else
{ {
if(mCircles->isLoaded(circleId) && mCircles->isRecipient(circleId, grpMeta.mGroupId, msgMetas[i]->mAuthorId)) if(mCircles->isLoaded(circleId) && mCircles->isRecipient(circleId, grpMeta.mGroupId, msgMetas[i]->mAuthorId))
{ {
++i ; ++i ;
continue ; continue ;
} }
MsgIdCircleVet mic(msgMetas[i]->mMsgId, msgMetas[i]->mAuthorId); MsgIdCircleVet mic(msgMetas[i]->mMsgId, msgMetas[i]->mAuthorId);
toVet.push_back(mic); toVet.push_back(mic);
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " deleting MsgMeta entry for msg ID " << msgMetas[i]->mMsgId << " signed by " << msgMetas[i]->mAuthorId << " who is not in group circle " << circleId << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " deleting MsgMeta entry for msg ID " << msgMetas[i]->mMsgId << " signed by " << msgMetas[i]->mAuthorId << " who is not in group circle " << circleId << std::endl;
#endif #endif
delete msgMetas[i] ; delete msgMetas[i] ;
msgMetas[i] = msgMetas[msgMetas.size()-1] ; msgMetas[i] = msgMetas[msgMetas.size()-1] ;
msgMetas.pop_back() ; msgMetas.pop_back() ;
} }
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle info not loaded. Putting in vetting list and returning false." << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle info not loaded. Putting in vetting list and returning false." << std::endl;
#endif #endif
if(!toVet.empty()) if(!toVet.empty())
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId)); mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId));
return true ; return true ;
} }
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: YOUR EYES ONLY" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
#endif #endif
// a non empty internal circle id means this bool res = checkPermissionsForFriendGroup(sslId,grpMeta) ;
// is the personal circle owner
if(!grpMeta.mInternalCircle.isNull())
{
const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle;
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Group internal circle: " << internalCircleId << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer: " << res << std::endl;
#endif
if(mCircles->isLoaded(internalCircleId))
{
const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId);
bool should_encrypt = false ;
bool res= mCircles->canSend(internalCircleId, pgpId,should_encrypt);
if(should_encrypt)
std::cerr << "(EE) inconsistent response: vetting requests to encrypt circle of type YOUR_EYES_ONLY" << std::endl;
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Answer from circle::canSend(): " << res << std::endl;
#endif
return res ;
}
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Not loaded. Putting in vetting list and returning false." << std::endl;
#endif #endif
return res ;
}
std::vector<MsgIdCircleVet> toVet; return false;
std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetas.begin();
for(; vit != msgMetas.end(); ++vit)
{
const RsGxsMsgMetaData* const& meta = *vit;
MsgIdCircleVet mic(meta->mMsgId, meta->mAuthorId);
toVet.push_back(mic);
}
if(!toVet.empty())
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils,
toVet, grpMeta.mGroupId,
sslId, grpMeta.mCircleId));
return false;
}
else
{
// an empty internal circle id means this peer can only
// send circle related info from peer he received it
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Empty internal circle: cannot only send info from Peer we received it (grpMeta.mOriginator=" << grpMeta.mOriginator << " answer is: " << (grpMeta.mOriginator == sslId) << std::endl;
#endif
if(grpMeta.mOriginator == sslId)
return true;
else
return false;
}
}
return false;
} }
/** inherited methods **/ /** inherited methods **/
bool RsGxsNetService::checkPermissionsForFriendGroup(const RsPeerId& sslId,const RsGxsGrpMetaData& grpMeta)
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: YOUR EYES ONLY - ID = " << grpMeta.mInternalCircle << std::endl;
#endif
// a non empty internal circle id means this
// is the personal circle owner
if(!grpMeta.mInternalCircle.isNull())
{
RsGroupInfo ginfo ;
RsPgpId pgpId = mPgpUtils->getPGPId(sslId) ;
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Group internal circle: " << grpMeta.mInternalCircle << ", We're owner. Sending to everyone in the group." << std::endl;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Current destination is PGP Id: " << pgpId << std::endl;
#endif
if(!rsPeers->getGroupInfo(RsNodeGroupId(grpMeta.mInternalCircle),ginfo))
{
std::cerr << "(EE) Cannot get information for internal circle (group node) ID " << grpMeta.mInternalCircle << " which conditions dissemination of GXS group " << grpMeta.mGroupId << std::endl;
return false ;
}
bool res = (ginfo.peerIds.find(pgpId) != ginfo.peerIds.end());
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final Answer is: " << res << std::endl;
#endif
return res ;
}
else
{
// An empty internal circle id means this peer can only
// send circle related info from peer he received it from.
// Normally this should be a pgp-based decision, but if we do that,
// A ---> B ----> A' ---...--->B' , then A' will also send to B' since B is the
// originator for A'. So A will lose control of who can see the data. This should
// be discussed further...
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Empty internal circle: cannot only send/recv info to/from Peer we received it from (grpMeta.mOriginator=" << grpMeta.mOriginator << ")" << std::endl;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer is: " << (grpMeta.mOriginator == sslId) << std::endl;
#endif
if(grpMeta.mOriginator == sslId)
return true;
else
return false;
}
}
void RsGxsNetService::pauseSynchronisation(bool /* enabled */) void RsGxsNetService::pauseSynchronisation(bool /* enabled */)
{ {

View File

@ -354,6 +354,15 @@ private:
bool canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool &should_encrypt); bool canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool &should_encrypt);
bool canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id); bool canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id);
/*!
* \brief checkPermissionsForFriendGroup
* Checks that we can send/recv from that node, given that the grpMeta has a distribution limited to a local circle.
* \param sslId Candidate peer to send to or to receive from.
* \param grpMeta Contains info about the group id, internal circle id, etc.
* \return true only when the internal exists and validates as a friend node group, and contains the owner of sslId.
*/
bool checkPermissionsForFriendGroup(const RsPeerId& sslId,const RsGxsGrpMetaData& grpMeta) ;
bool checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& meta, RsGxsCircleId& should_encrypt_id); bool checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& meta, RsGxsCircleId& should_encrypt_id);
void locked_createTransactionFromPending(MsgRespPending* grpPend); void locked_createTransactionFromPending(MsgRespPending* grpPend);

View File

@ -28,7 +28,6 @@
#include "rsgxsutil.h" #include "rsgxsutil.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsreputations.h"
#include "pqi/pqihash.h" #include "pqi/pqihash.h"
#include "gxs/rsgixs.h" #include "gxs/rsgixs.h"
@ -165,7 +164,7 @@ bool RsGxsIntegrityCheck::check()
std::cerr << "TimeStamping group authors' key ID " << grp->metaData->mAuthorId << " in group ID " << grp->grpId << std::endl; std::cerr << "TimeStamping group authors' key ID " << grp->metaData->mAuthorId << " in group ID " << grp->grpId << std::endl;
#endif #endif
if(rsReputations!=NULL && !rsReputations->isIdentityBanned(grp->metaData->mAuthorId)) if(rsIdentity!=NULL && !rsIdentity->isBanned(grp->metaData->mAuthorId))
used_gxs_ids.insert(grp->metaData->mAuthorId) ; used_gxs_ids.insert(grp->metaData->mAuthorId) ;
} }
} }
@ -247,7 +246,7 @@ bool RsGxsIntegrityCheck::check()
#ifdef GXSUTIL_DEBUG #ifdef GXSUTIL_DEBUG
std::cerr << "TimeStamping message authors' key ID " << msg->metaData->mAuthorId << " in message " << msg->msgId << ", group ID " << msg->grpId<< std::endl; std::cerr << "TimeStamping message authors' key ID " << msg->metaData->mAuthorId << " in message " << msg->msgId << ", group ID " << msg->grpId<< std::endl;
#endif #endif
if(rsReputations!=NULL && !rsReputations->isIdentityBanned(msg->metaData->mAuthorId)) if(rsIdentity!=NULL && !rsIdentity->isBanned(msg->metaData->mAuthorId))
used_gxs_ids.insert(msg->metaData->mAuthorId) ; used_gxs_ids.insert(msg->metaData->mAuthorId) ;
} }

View File

@ -138,8 +138,6 @@ p3LinkMgrIMPL::p3LinkMgrIMPL(p3PeerMgrIMPL *peerMgr, p3NetMgrIMPL *netMgr)
mDNSResolver = new DNSResolver(); mDNSResolver = new DNSResolver();
mRetryPeriod = MIN_RETRY_PERIOD; mRetryPeriod = MIN_RETRY_PERIOD;
lastGroupId = 1;
/* setup Banned Ip Address - static for now /* setup Banned Ip Address - static for now
*/ */

View File

@ -132,7 +132,7 @@ class peerConnectState
}; };
class p3tunnel; class p3tunnel;
class RsPeerGroupItem; class RsPeerGroupItem_deprecated;
class RsGroupInfo; class RsGroupInfo;
class p3PeerMgr; class p3PeerMgr;
@ -339,9 +339,6 @@ private:
std::map<RsPeerId, peerConnectState> mFriendList; std::map<RsPeerId, peerConnectState> mFriendList;
std::map<RsPeerId, peerConnectState> mOthersList; std::map<RsPeerId, peerConnectState> mOthersList;
std::list<RsPeerGroupItem *> groupList;
uint32_t lastGroupId;
/* relatively static list of banned ip addresses */ /* relatively static list of banned ip addresses */
std::list<struct sockaddr_storage> mBannedIpList; std::list<struct sockaddr_storage> mBannedIpList;
}; };

View File

@ -130,8 +130,6 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
mOwnState.vs_disc = RS_VS_DISC_FULL; mOwnState.vs_disc = RS_VS_DISC_FULL;
mOwnState.vs_dht = RS_VS_DHT_FULL; mOwnState.vs_dht = RS_VS_DHT_FULL;
lastGroupId = 1;
// setup default ProxyServerAddress. // setup default ProxyServerAddress.
// Tor // Tor
sockaddr_storage_clear(mProxyServerAddressTor); sockaddr_storage_clear(mProxyServerAddressTor);
@ -1071,7 +1069,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id)
std::list<RsPgpId> ids ; std::list<RsPgpId> ids ;
ids.push_back(id) ; ids.push_back(id) ;
assignPeersToGroup("", ids, false); assignPeersToGroup(RsNodeGroupId(), ids, false);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -1145,7 +1143,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPeerId &id, bool removePgpId)
/* remove id from all groups */ /* remove id from all groups */
assignPeersToGroup("", pgpid_toRemove, false); assignPeersToGroup(RsNodeGroupId(), pgpid_toRemove, false);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -1915,7 +1913,7 @@ RsSerialiser *p3PeerMgrIMPL::setupSerialiser()
bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData) bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
{ {
/* create a list of current peers */ /* create a list of current peers */
cleanup = false; cleanup = true;
bool useExtAddrFinder = mNetMgr->getIPServersEnabled(); bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
/* gather these information before mPeerMtx is locked! */ /* gather these information before mPeerMtx is locked! */
@ -1971,7 +1969,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
#endif #endif
saveData.push_back(item); saveData.push_back(item);
saveCleanupList.push_back(item);
/* iterate through all friends and save */ /* iterate through all friends and save */
std::map<RsPeerId, peerState>::iterator it; std::map<RsPeerId, peerState>::iterator it;
@ -2003,7 +2000,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
item->domain_port = (it->second).hiddenPort; item->domain_port = (it->second).hiddenPort;
saveData.push_back(item); saveData.push_back(item);
saveCleanupList.push_back(item);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::saveList() Peer Config Item:" << std::endl; std::cerr << "p3PeerMgrIMPL::saveList() Peer Config Item:" << std::endl;
item->print(std::cerr, 10); item->print(std::cerr, 10);
@ -2024,7 +2020,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
} }
saveData.push_back(sitem) ; saveData.push_back(sitem) ;
saveCleanupList.push_back(sitem);
// Now save config for network digging strategies // Now save config for network digging strategies
@ -2066,14 +2061,14 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
saveData.push_back(vitem); saveData.push_back(vitem);
saveCleanupList.push_back(vitem);
/* save groups */ /* save groups */
std::list<RsPeerGroupItem *>::iterator groupIt; for ( std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { {
saveData.push_back(*groupIt); // no delete RsNodeGroupItem *itm = new RsNodeGroupItem(groupIt->second);
} saveData.push_back(itm) ;
}
return true; return true;
} }
@ -2294,7 +2289,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
continue; continue;
} }
RsPeerGroupItem *gitem = dynamic_cast<RsPeerGroupItem *>(*it) ; RsPeerGroupItem_deprecated *gitem = dynamic_cast<RsPeerGroupItem_deprecated *>(*it) ;
if (gitem) if (gitem)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2304,20 +2300,54 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
gitem->print(std::cerr, 10); gitem->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
RsGroupInfo ginfo ;
ginfo.flag = gitem->flag ;
ginfo.name = gitem->name ;
ginfo.peerIds = gitem->pgpList.ids ;
groupList.push_back(gitem); // don't delete do { ginfo.id = RsNodeGroupId::random(); } while(groupList.find(ginfo.id) != groupList.end()) ;
if ((gitem->flag & RS_GROUP_FLAG_STANDARD) == 0) { // Ensure backward compatibility when loading the group in old format. The id must matchthe standard default id.
/* calculate group id */
uint32_t groupId = atoi(gitem->id.c_str());
if (groupId > lastGroupId) {
lastGroupId = groupId;
}
}
continue; if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FRIENDS )) ginfo.id = RS_GROUP_ID_FRIENDS ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_COWORKERS)) ginfo.id = RS_GROUP_ID_COWORKERS ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAMILY )) ginfo.id = RS_GROUP_ID_FAMILY ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ;
if(!ginfo.id.isNull())
{
groupList[ginfo.id] = ginfo ;
std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl;
}
else
std::cerr << "(EE) no group corresponding to old format group with ID=\"" << gitem->id << "\"" << std::endl;
continue;
} }
RsNodeGroupItem *gitem2 = dynamic_cast<RsNodeGroupItem*>(*it) ;
if (gitem2)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::loadList() Peer group item:" << std::endl;
gitem->print(std::cerr, 10);
std::cerr << std::endl;
#endif
RsGroupInfo info ;
info.peerIds = gitem2->pgpList.ids ;
info.id = gitem2->id ;
info.name = gitem2->name ;
info.flag = gitem2->flag ;
std::cerr << "(II) Loaded group in new format. ID = " << info.id << std::endl;
groupList[info.id] = info ;
continue;
}
RsPeerBandwidthLimitsItem *pblitem = dynamic_cast<RsPeerBandwidthLimitsItem*>(*it) ; RsPeerBandwidthLimitsItem *pblitem = dynamic_cast<RsPeerBandwidthLimitsItem*>(*it) ;
if(pblitem) if(pblitem)
@ -2363,42 +2393,19 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
/* Standard groups */ /* Standard groups */
const int standardGroupCount = 5; const int standardGroupCount = 5;
const char *standardGroup[standardGroupCount] = { RS_GROUP_ID_FRIENDS, RS_GROUP_ID_FAMILY, RS_GROUP_ID_COWORKERS, RS_GROUP_ID_OTHERS, RS_GROUP_ID_FAVORITES }; const RsNodeGroupId standardGroupIds [standardGroupCount] = { RS_GROUP_ID_FRIENDS, RS_GROUP_ID_FAMILY, RS_GROUP_ID_COWORKERS, RS_GROUP_ID_OTHERS, RS_GROUP_ID_FAVORITES };
bool foundStandardGroup[standardGroupCount] = { false, false, false, false, false }; const char *standardGroupNames[standardGroupCount] = { RS_GROUP_DEFAULT_NAME_FRIENDS, RS_GROUP_DEFAULT_NAME_FAMILY, RS_GROUP_DEFAULT_NAME_COWORKERS, RS_GROUP_DEFAULT_NAME_OTHERS, RS_GROUP_DEFAULT_NAME_FAVORITES };
std::list<RsPeerGroupItem *>::iterator groupIt; for(uint32_t k=0;k<standardGroupCount;++k)
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { if(groupList.find(standardGroupIds[k]) == groupList.end())
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) { {
int i; RsGroupInfo info ;
for (i = 0; i < standardGroupCount; ++i) { info.id = standardGroupIds[k];
if ((*groupIt)->id == standardGroup[i]) { info.name = standardGroupNames[k];
foundStandardGroup[i] = true; info.flag |= RS_GROUP_FLAG_STANDARD;
break;
}
}
if (i >= standardGroupCount) { groupList[info.id] = info;
/* No more a standard group, remove the flag standard */
(*groupIt)->flag &= ~RS_GROUP_FLAG_STANDARD;
}
} else {
uint32_t groupId = atoi((*groupIt)->id.c_str());
if (groupId == 0) {
rs_sprintf((*groupIt)->id, "%lu", lastGroupId++);
}
} }
}
/* Initialize standard groups */
for (int i = 0; i < standardGroupCount; ++i) {
if (foundStandardGroup[i] == false) {
RsPeerGroupItem *gitem = new RsPeerGroupItem;
gitem->id = standardGroup[i];
gitem->name = standardGroup[i];
gitem->flag |= RS_GROUP_FLAG_STANDARD;
groupList.push_back(gitem);
}
}
} }
// If we are hidden - don't want ExtAddrFinder - ever! // If we are hidden - don't want ExtAddrFinder - ever!
@ -2478,19 +2485,16 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
RsPeerGroupItem *groupItem = new RsPeerGroupItem; do { groupInfo.id = RsNodeGroupId::random(); } while(groupList.find(groupInfo.id) != groupList.end()) ;
groupItem->set(groupInfo);
rs_sprintf(groupItem->id, "%lu", ++lastGroupId); RsGroupInfo groupItem(groupInfo) ;
// remove standard flag // remove standard flag
groupItem->flag &= ~RS_GROUP_FLAG_STANDARD;
groupItem->PeerId(getOwnId()); groupItem.flag &= ~RS_GROUP_FLAG_STANDARD;
groupList[groupInfo.id] = groupItem;
groupList.push_back(groupItem); std::cerr << "(II) Added new group with ID " << groupInfo.id << ", name=\"" << groupInfo.name << "\"" << std::endl;
groupInfo.id = groupItem->id;
} }
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD);
@ -2500,35 +2504,39 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
return true; return true;
} }
bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo) bool p3PeerMgrIMPL::editGroup(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo)
{ {
if (groupId.empty()) { if (groupId.isNull())
return false; return false;
}
bool changed = false; bool changed = false;
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt; std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
break;
}
}
if (groupIt != groupList.end()) { if(it == groupList.end())
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) { {
// can't edit standard groups std::cerr << "(EE) cannot find local node group with ID " << groupId << std::endl;
} else { return false ;
changed = true; }
(*groupIt)->set(groupInfo);
}
}
}
if (changed) { if (it->second.flag & RS_GROUP_FLAG_STANDARD)
{
// can't edit standard groups
std::cerr << "(EE) cannot edit standard group with ID " << groupId << std::endl;
return false ;
}
else
{
changed = true;
it->second = groupInfo;
}
}
if (changed)
{
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD); RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_MOD);
IndicateConfigChanged(); IndicateConfigChanged();
@ -2537,31 +2545,35 @@ bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo
return changed; return changed;
} }
bool p3PeerMgrIMPL::removeGroup(const std::string &groupId) bool p3PeerMgrIMPL::removeGroup(const RsNodeGroupId& groupId)
{ {
if (groupId.empty()) {
return false;
}
bool changed = false; bool changed = false;
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt; std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
break;
}
}
if (groupIt != groupList.end()) { if (it != groupList.end()) {
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) { if (it->second.flag & RS_GROUP_FLAG_STANDARD)
{
// can't remove standard groups // can't remove standard groups
} else { std::cerr << "(EE) cannot remove standard group with ID " << groupId << std::endl;
return false ;
}
#warning we need to check that the local group is not used. Otherwise deleting it is going to cause problems!
// else if(!it->second.used_gxs_groups.empty())
// {
// std::cerr << "(EE) cannot remove standard group with ID " << groupId << " because it is used in the following groups: " << std::endl;
// for(std::set<RsGxsGroupId>::const_iterator it2(it->second.used_gxs_groups.begin());it2!=it->second.used_gxs_groups.end();++it2)
// std::cerr << " " << *it2 << std::endl;
//
// return false ;
// }
else
{
changed = true; changed = true;
delete(*groupIt); groupList.erase(it);
groupList.erase(groupIt);
} }
} }
} }
@ -2575,82 +2587,83 @@ bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
return changed; return changed;
} }
bool p3PeerMgrIMPL::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) bool p3PeerMgrIMPL::getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo)
{ {
if (groupId.empty()) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
return false;
}
for(std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.begin();it!=groupList.end();++it)
if(it->second.name == groupName)
{
groupInfo = it->second ;
return true ;
}
std::cerr << "(EE) getGroupInfoByName: no known group for name " << groupName << std::endl;
return false ;
}
bool p3PeerMgrIMPL::getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt; std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
(*groupIt)->get(groupInfo);
return true; if(it == groupList.end())
} return false ;
}
return false; groupInfo = it->second;
return true;
} }
bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo>& groupInfoList)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt; for (std::map<RsNodeGroupId,RsGroupInfo> ::const_iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { groupInfoList.push_back(groupIt->second);
RsGroupInfo groupInfo;
(*groupIt)->get(groupInfo);
groupInfoList.push_back(groupInfo);
}
return true; return true;
} }
// groupId == "" && assign == false -> remove from all groups // groupId.isNull() && assign == false -> remove from all groups
bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign)
{
if (groupId.empty() && assign == true) {
return false;
}
if (peerIds.empty()) { bool p3PeerMgrIMPL::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign)
{
if (groupId.isNull() && assign == true)
return false;
if (peerIds.empty())
return false; return false;
}
bool changed = false; bool changed = false;
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt; for (std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) { if (groupId.isNull() || groupIt->first == groupId)
if (groupId.empty() || (*groupIt)->id == groupId) { {
RsPeerGroupItem *groupItem = *groupIt; RsGroupInfo& groupItem = groupIt->second;
std::list<RsPgpId>::const_iterator peerIt; for (std::list<RsPgpId>::const_iterator peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt)
for (peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt) { {
std::set<RsPgpId>::iterator peerIt1 = std::find(groupItem->pgpList.ids.begin(), groupItem->pgpList.ids.end(), *peerIt); std::set<RsPgpId>::iterator peerIt1 = groupItem.peerIds.find(*peerIt);
if (assign) {
if (peerIt1 == groupItem->pgpList.ids.end()) { if (assign)
groupItem->pgpList.ids.insert(*peerIt); {
changed = true; groupItem.peerIds.insert(*peerIt);
} changed = true;
} else { }
if (peerIt1 != groupItem->pgpList.ids.end()) { else
groupItem->pgpList.ids.erase(peerIt1); {
changed = true; groupItem.peerIds.erase(*peerIt);
} changed = true;
} }
} }
if (groupId.empty() == false) { if (!groupId.isNull())
break; break;
}
} }
}
} }
if (changed) { if (changed) {

View File

@ -106,7 +106,7 @@ class peerState
uint32_t maxDnRate ; uint32_t maxDnRate ;
}; };
class RsPeerGroupItem; class RsNodeGroupItem;
class RsGroupInfo; class RsGroupInfo;
std::string textPeerState(peerState &state); std::string textPeerState(peerState &state);
@ -139,11 +139,12 @@ virtual bool removeAllFriendLocations(const RsPgpId &gpgid) = 0;
/* This is solely used by p3peers - makes sense */ /* This is solely used by p3peers - makes sense */
virtual bool addGroup(RsGroupInfo &groupInfo) = 0; virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool removeGroup(const std::string &groupId) = 0; virtual bool removeGroup(const RsNodeGroupId &groupId) = 0;
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0; virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0; virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
virtual bool resetOwnExternalAddressList() = 0 ; virtual bool resetOwnExternalAddressList() = 0 ;
@ -231,181 +232,182 @@ virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage
class p3PeerMgrIMPL: public p3PeerMgr, public p3Config class p3PeerMgrIMPL: public p3PeerMgr, public p3Config
{ {
public: public:
/************************************************************************************************/ /************************************************************************************************/
/* EXTERNAL INTERFACE */ /* EXTERNAL INTERFACE */
/************************************************************************************************/ /************************************************************************************************/
virtual bool addFriend(const RsPeerId&ssl_id, const RsPgpId&gpg_id, uint32_t netMode = RS_NET_MODE_UDP, virtual bool addFriend(const RsPeerId&ssl_id, const RsPgpId&gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL,
time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT)); time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT));
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId); virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId);
virtual bool removeFriend(const RsPgpId &pgp_id); virtual bool removeFriend(const RsPgpId &pgp_id);
virtual bool isFriend(const RsPeerId &ssl_id); virtual bool isFriend(const RsPeerId &ssl_id);
virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids); virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids);
virtual bool removeAllFriendLocations(const RsPgpId &gpgid); virtual bool removeAllFriendLocations(const RsPgpId &gpgid);
/******************** Groups **********************/ /******************** Groups **********************/
/* This is solely used by p3peers - makes sense */ /* This is solely used by p3peers - makes sense */
virtual bool addGroup(RsGroupInfo &groupInfo); virtual bool addGroup(RsGroupInfo &groupInfo);
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo); virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const std::string &groupId); virtual bool removeGroup(const RsNodeGroupId &groupId);
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo); virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList); virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo) ;
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign); virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign);
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) ; virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) ;
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ; virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) ;
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ; virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) ;
/**************** Set Net Info ****************/ /**************** Set Net Info ****************/
/* /*
* These functions are used by: * These functions are used by:
* 1) p3linkmgr * 1) p3linkmgr
* 2) p3peers - reasonable * 2) p3peers - reasonable
* 3) p3disc - reasonable * 3) p3disc - reasonable
*/ */
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr); virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr); virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns); virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) ; virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) ;
virtual bool getExtAddressReportedByFriends(struct sockaddr_storage& addr, uint8_t &isstable) ; virtual bool getExtAddressReportedByFriends(struct sockaddr_storage& addr, uint8_t &isstable) ;
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode); virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht); virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht);
virtual bool setLocation(const RsPeerId &pid, const std::string &location); virtual bool setLocation(const RsPeerId &pid, const std::string &location);
virtual bool setHiddenDomainPort(const RsPeerId &id, const std::string &domain_addr, const uint16_t domain_port); virtual bool setHiddenDomainPort(const RsPeerId &id, const std::string &domain_addr, const uint16_t domain_port);
virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr); virtual bool updateCurrentAddress(const RsPeerId& id, const pqiIpAddress &addr);
virtual bool updateLastContact(const RsPeerId& id); virtual bool updateLastContact(const RsPeerId& id);
virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs); virtual bool updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs);
virtual bool resetOwnExternalAddressList() ; virtual bool resetOwnExternalAddressList() ;
// THIS MUST ONLY BE CALLED BY NETMGR!!!! // THIS MUST ONLY BE CALLED BY NETMGR!!!!
virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, const struct sockaddr_storage &ext_addr); virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, const struct sockaddr_storage &ext_addr);
/**************** Net Status Info ****************/ /**************** Net Status Info ****************/
/* /*
* MUST RATIONALISE THE DATA FROM THESE FUNCTIONS * MUST RATIONALISE THE DATA FROM THESE FUNCTIONS
* These functions are used by: * These functions are used by:
* 1) p3face-config ... to remove! * 1) p3face-config ... to remove!
* 2) p3peers - reasonable * 2) p3peers - reasonable
* 3) p3disc - reasonable * 3) p3disc - reasonable
*/ */
virtual bool getOwnNetStatus(peerState &state); virtual bool getOwnNetStatus(peerState &state);
virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state); virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state);
virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state); virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state);
virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name); virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name);
virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId); virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId);
virtual uint32_t getConnectionType(const RsPeerId& sslId); virtual uint32_t getConnectionType(const RsPeerId& sslId);
virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr); virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr);
virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr); virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr);
virtual bool getProxyServerStatus(const uint32_t type, uint32_t &proxy_status); virtual bool getProxyServerStatus(const uint32_t type, uint32_t &proxy_status);
virtual bool isHidden(); virtual bool isHidden();
virtual bool isHidden(const uint32_t type); virtual bool isHidden(const uint32_t type);
virtual bool isHiddenPeer(const RsPeerId &ssl_id); virtual bool isHiddenPeer(const RsPeerId &ssl_id);
virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type); virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type);
virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port); virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port);
virtual uint32_t hiddenDomainToHiddenType(const std::string &domain); virtual uint32_t hiddenDomainToHiddenType(const std::string &domain);
virtual uint32_t getHiddenType(const RsPeerId &ssl_id); virtual uint32_t getHiddenType(const RsPeerId &ssl_id);
virtual int getFriendCount(bool ssl, bool online); virtual int getFriendCount(bool ssl, bool online);
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
// Single Use Function... shouldn't be here. used by p3serverconfig.cc // Single Use Function... shouldn't be here. used by p3serverconfig.cc
virtual bool haveOnceConnected(); virtual bool haveOnceConnected();
virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn); virtual bool setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn);
virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn); virtual bool getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn);
virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn); virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn);
/************************************************************************************************/ /************************************************************************************************/
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */ /* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
/************************************************************************************************/ /************************************************************************************************/
p3PeerMgrIMPL( const RsPeerId& ssl_own_id, p3PeerMgrIMPL( const RsPeerId& ssl_own_id,
const RsPgpId& gpg_own_id, const RsPgpId& gpg_own_id,
const std::string& gpg_own_name, const std::string& gpg_own_name,
const std::string& ssl_own_location) ; const std::string& ssl_own_location) ;
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr); void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr);
bool forceHiddenNode(); bool forceHiddenNode();
bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort); bool setupHiddenNode(const std::string &hiddenAddress, const uint16_t hiddenPort);
void tick(); void tick();
const RsPeerId& getOwnId(); const RsPeerId& getOwnId();
bool setOwnNetworkMode(uint32_t netMode); bool setOwnNetworkMode(uint32_t netMode);
bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht); bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht);
int getConnectAddresses(const RsPeerId &id, int getConnectAddresses(const RsPeerId &id,
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
pqiIpAddrSet &histAddrs, std::string &dyndns); pqiIpAddrSet &histAddrs, std::string &dyndns);
protected: protected:
/* Internal Functions */ /* Internal Functions */
bool removeUnusedLocations(); bool removeUnusedLocations();
bool removeBannedIps(); bool removeBannedIps();
void printPeerLists(std::ostream &out); void printPeerLists(std::ostream &out);
virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage &addr, uint32_t &count); virtual bool locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage &addr, uint32_t &count);
protected: protected:
/*****************************************************************/ /*****************************************************************/
/*********************** p3config ******************************/ /*********************** p3config ******************************/
/* Key Functions to be overloaded for Full Configuration */ /* Key Functions to be overloaded for Full Configuration */
virtual RsSerialiser *setupSerialiser(); virtual RsSerialiser *setupSerialiser();
virtual bool saveList(bool &cleanup, std::list<RsItem *>&); virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual void saveDone(); virtual void saveDone();
virtual bool loadList(std::list<RsItem *>& load); virtual bool loadList(std::list<RsItem *>& load);
/*****************************************************************/ /*****************************************************************/
/* other important managers */ /* other important managers */
p3LinkMgrIMPL *mLinkMgr;
p3NetMgrIMPL *mNetMgr;
p3LinkMgrIMPL *mLinkMgr;
p3NetMgrIMPL *mNetMgr;
private: private:
RsMutex mPeerMtx; /* protects below */ RsMutex mPeerMtx; /* protects below */
bool mStatusChanged; bool mStatusChanged;
std::list<pqiMonitor *> clients; std::list<pqiMonitor *> clients;
peerState mOwnState; peerState mOwnState;
std::map<RsPeerId, peerState> mFriendList; // <SSLid , peerState> std::map<RsPeerId, peerState> mFriendList; // <SSLid , peerState>
std::map<RsPeerId, peerState> mOthersList; std::map<RsPeerId, peerState> mOthersList;
std::map<RsPeerId,sockaddr_storage> mReportedOwnAddresses ; std::map<RsPeerId,sockaddr_storage> mReportedOwnAddresses ;
std::list<RsPeerGroupItem *> groupList;
uint32_t lastGroupId;
std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */ std::map<RsNodeGroupId,RsGroupInfo> groupList;
uint32_t lastGroupId;
std::map<RsPgpId, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key std::list<RsItem *> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
std::map<RsPgpId, PeerBandwidthLimits> mPeerBandwidthLimits ; // bandwidth limits for each gpg key
struct sockaddr_storage mProxyServerAddressTor; std::map<RsPgpId, ServicePermissionFlags> mFriendsPermissionFlags ; // permission flags for each gpg key
struct sockaddr_storage mProxyServerAddressI2P; std::map<RsPgpId, PeerBandwidthLimits> mPeerBandwidthLimits ; // bandwidth limits for each gpg key
uint32_t mProxyServerStatusTor ;
uint32_t mProxyServerStatusI2P ; struct sockaddr_storage mProxyServerAddressTor;
struct sockaddr_storage mProxyServerAddressI2P;
uint32_t mProxyServerStatusTor ;
uint32_t mProxyServerStatusI2P ;
}; };

View File

@ -99,7 +99,7 @@ struct SharedDirInfo
std::string filename ; std::string filename ;
std::string virtualname ; std::string virtualname ;
FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ... FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ...
std::list<std::string> parent_groups ; std::list<RsNodeGroupId> parent_groups ;
}; };
class RsFiles class RsFiles

View File

@ -34,6 +34,7 @@ namespace GXS_SERV {
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_REQUIRED = 0x00000200; static const uint32_t FLAG_AUTHOR_AUTHENTICATION_REQUIRED = 0x00000200;
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN = 0x00000400; static const uint32_t FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN = 0x00000400;
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES = 0x00000800; static const uint32_t FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES = 0x00000800;
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN = 0x00001000;
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_MASK = 0x000000ff; static const uint32_t FLAG_GROUP_SIGN_PUBLISH_MASK = 0x000000ff;
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_ENCRYPTED = 0x00000001; static const uint32_t FLAG_GROUP_SIGN_PUBLISH_ENCRYPTED = 0x00000001;
@ -105,6 +106,7 @@ namespace GXS_SERV {
#define IS_MSG_UNPROCESSED(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED) #define IS_MSG_UNPROCESSED(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
#define IS_GROUP_PGP_AUTHED(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) #define IS_GROUP_PGP_AUTHED(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG)
#define IS_GROUP_PGP_KNOWN_AUTHED(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN)
#define IS_GROUP_MESSAGE_TRACKING(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) #define IS_GROUP_MESSAGE_TRACKING(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES)
#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) #define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)

View File

@ -221,46 +221,48 @@ public:
RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) { return; } RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) { return; }
virtual ~RsIdentity() { return; } virtual ~RsIdentity() { return; }
/********************************************************************************************/ /********************************************************************************************/
/********************************************************************************************/ /********************************************************************************************/
// For Other Services....
// It should be impossible for them to get a message which we don't have the identity.
// Its a major error if we don't have the identity.
// We cache all identities, and provide alternative (instantaneous) // For Other Services....
// functions to extract info, rather than the standard Token system. // It should be impossible for them to get a message which we don't have the identity.
// Its a major error if we don't have the identity.
//virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0; // We cache all identities, and provide alternative (instantaneous)
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0; // functions to extract info, rather than the standard Token system.
// Fills up list of all own ids. Returns false if ids are not yet loaded. //virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0; virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0;
virtual bool isOwnId(const RsGxsId& id) = 0;
// // Fills up list of all own ids. Returns false if ids are not yet loaded.
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id, virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0;
bool absOpinion, int score) = 0; virtual bool isOwnId(const RsGxsId& id) = 0;
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params) = 0;
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0; //
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0; virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
bool absOpinion, int score) = 0;
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params) = 0;
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname, virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
const std::string &tag, RsRecognTagDetails &details) = 0; virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0; virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
const std::string &tag, RsRecognTagDetails &details) = 0;
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0;
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ; virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
virtual bool isARegularContact(const RsGxsId& id) = 0 ; virtual bool isARegularContact(const RsGxsId& id) = 0 ;
virtual bool isBanned(const RsGxsId& id) =0;
// Specific RsIdentity Functions.... virtual time_t getLastUsageTS(const RsGxsId &id) =0;
/* Specific Service Data */
/* We expose these initially for testing / GUI purposes. // Specific RsIdentity Functions....
/* Specific Service Data */
/* We expose these initially for testing / GUI purposes.
*/ */
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0; virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0; //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
}; };

View File

@ -73,14 +73,13 @@ template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> c
memcpy(bytes,id.toByteArray(),ID_SIZE_IN_BYTES) ; memcpy(bytes,id.toByteArray(),ID_SIZE_IN_BYTES) ;
} }
// Random initialization. Can be useful for testing. // Random initialization. Can be useful for testing and to generate new ids.
// //
static t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> random() static t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> random()
{ {
t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> id ; t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> id ;
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i) RSRandom::random_bytes(id.bytes,ID_SIZE_IN_BYTES) ;
id.bytes[i] = RSRandom::random_u32() & 0xff ;
return id ; return id ;
} }
@ -220,6 +219,7 @@ static const uint32_t RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE = 0x0008 ;
static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ; static const uint32_t RS_GENERIC_ID_GROUTER_ID_TYPE = 0x0009 ;
static const uint32_t RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE = 0x0010 ; static const uint32_t RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE = 0x0010 ;
static const uint32_t RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE = 0x0011 ; static const uint32_t RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE = 0x0011 ;
static const uint32_t RS_GENERIC_ID_NODE_GROUP_ID_TYPE = 0x0012 ;
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< 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 ;
@ -231,4 +231,5 @@ typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_I
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE > GXSCircleId ; typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_GXS_CIRCLE_ID_TYPE > GXSCircleId ;
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE > GXSTunnelId ; typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_TUNNEL_ID_TYPE > GXSTunnelId ;
typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE > DistantChatPeerId ; typedef t_RsGenericIdType< SSL_ID_SIZE , false, RS_GENERIC_ID_GXS_DISTANT_CHAT_ID_TYPE > DistantChatPeerId ;
typedef t_RsGenericIdType< CERT_SIGN_LEN , false, RS_GENERIC_ID_NODE_GROUP_ID_TYPE > RsNodeGroupId ;

View File

@ -185,11 +185,17 @@ const uint32_t RS_NET_PROXY_STATUS_OK = 0x0001 ;
/* Groups */ /* Groups */
#define RS_GROUP_ID_FRIENDS "Friends" static const RsNodeGroupId RS_GROUP_ID_FRIENDS ("00000000000000000000000000000001");
#define RS_GROUP_ID_FAMILY "Family" static const RsNodeGroupId RS_GROUP_ID_FAMILY ("00000000000000000000000000000002");
#define RS_GROUP_ID_COWORKERS "Co-Workers" static const RsNodeGroupId RS_GROUP_ID_COWORKERS ("00000000000000000000000000000003");
#define RS_GROUP_ID_OTHERS "Other Contacts" static const RsNodeGroupId RS_GROUP_ID_OTHERS ("00000000000000000000000000000004");
#define RS_GROUP_ID_FAVORITES "Favorites" static const RsNodeGroupId RS_GROUP_ID_FAVORITES ("00000000000000000000000000000005");
#define RS_GROUP_DEFAULT_NAME_FRIENDS "Friends"
#define RS_GROUP_DEFAULT_NAME_FAMILY "Family"
#define RS_GROUP_DEFAULT_NAME_COWORKERS "Co-Workers"
#define RS_GROUP_DEFAULT_NAME_OTHERS "Other Contacts"
#define RS_GROUP_DEFAULT_NAME_FAVORITES "Favorites"
const uint32_t RS_GROUP_FLAG_STANDARD = 0x0001; const uint32_t RS_GROUP_FLAG_STANDARD = 0x0001;
@ -295,7 +301,7 @@ class RsGroupInfo
public: public:
RsGroupInfo(); RsGroupInfo();
std::string id; RsNodeGroupId id;
std::string name; std::string name;
uint32_t flag; uint32_t flag;
@ -399,14 +405,15 @@ public:
virtual bool trustGPGCertificate(const RsPgpId &gpg_id, uint32_t trustlvl) = 0; virtual bool trustGPGCertificate(const RsPgpId &gpg_id, uint32_t trustlvl) = 0;
/* Group Stuff */ /* Group Stuff */
virtual bool addGroup(RsGroupInfo &groupInfo) = 0; virtual bool addGroup(RsGroupInfo& groupInfo) = 0;
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool editGroup(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0;
virtual bool removeGroup(const std::string &groupId) = 0; virtual bool removeGroup(const RsNodeGroupId& groupId) = 0;
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0; virtual bool getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0; virtual bool getGroupInfoByName(const std::string& groupId, RsGroupInfo& groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo>& groupInfoList) = 0;
// groupId == "" && assign == false -> remove from all groups // groupId == "" && assign == false -> remove from all groups
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId& peerId, bool assign) = 0; virtual bool assignPeerToGroup(const RsNodeGroupId& groupId, const RsPgpId& peerId, bool assign) = 0;
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0; virtual bool assignPeersToGroup(const RsNodeGroupId& groupId, const std::list<RsPgpId>& peerIds, bool assign) = 0;
/* Group sharing permission */ /* Group sharing permission */
@ -421,7 +428,7 @@ public:
// //
virtual FileSearchFlags computePeerPermissionFlags( virtual FileSearchFlags computePeerPermissionFlags(
const RsPeerId& peer_id, FileStorageFlags file_sharing_flags, const RsPeerId& peer_id, FileStorageFlags file_sharing_flags,
const std::list<std::string>& file_parent_groups) = 0; const std::list<RsNodeGroupId>& file_parent_groups) = 0;
/* Service permission flags */ /* Service permission flags */

View File

@ -50,14 +50,14 @@ public:
}; };
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0; virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0;
virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) =0 ; virtual bool getReputationInfo(const RsGxsId& id,const RsPgpId& owner_id,ReputationInfo& info) =0 ;
virtual void setNodeAutoBanThreshold(uint32_t n) =0; virtual void setNodeAutoBanThreshold(uint32_t n) =0;
virtual uint32_t nodeAutoBanThreshold() =0; virtual uint32_t nodeAutoBanThreshold() =0;
// This one is a proxy designed to allow fast checking of a GXS id. // This one is a proxy designed to allow fast checking of a GXS id.
// it basically returns true if assessment is not ASSESSMENT_OK // it basically returns true if assessment is not ASSESSMENT_OK
virtual bool isIdentityBanned(const RsGxsId& id) =0; virtual bool isIdentityBanned(const RsGxsId& id,const RsPgpId& owner_node) =0;
}; };
// To access reputations from anywhere // To access reputations from anywhere

View File

@ -211,7 +211,7 @@ class FileInfo
DwlSpeed priority ; DwlSpeed priority ;
time_t lastTS; time_t lastTS;
std::list<std::string> parent_groups ; std::list<RsNodeGroupId> parent_groups ;
}; };
std::ostream &operator<<(std::ostream &out, const FileInfo &info); std::ostream &operator<<(std::ostream &out, const FileInfo &info);
@ -243,7 +243,7 @@ class DirDetails
uint32_t min_age ; // minimum age of files in this subtree uint32_t min_age ; // minimum age of files in this subtree
std::list<DirStub> children; std::list<DirStub> children;
std::list<std::string> parent_groups; // parent groups for the shared directory std::list<RsNodeGroupId> parent_groups; // parent groups for the shared directory
}; };
class FileDetail class FileDetail

View File

@ -1280,7 +1280,7 @@ bool p3Peers::addGroup(RsGroupInfo &groupInfo)
return res ; return res ;
} }
bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo) bool p3Peers::editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo)
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::editGroup()" << std::endl; std::cerr << "p3Peers::editGroup()" << std::endl;
@ -1292,7 +1292,7 @@ bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
return res ; return res ;
} }
bool p3Peers::removeGroup(const std::string &groupId) bool p3Peers::removeGroup(const RsNodeGroupId &groupId)
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::removeGroup()" << std::endl; std::cerr << "p3Peers::removeGroup()" << std::endl;
@ -1303,7 +1303,15 @@ bool p3Peers::removeGroup(const std::string &groupId)
return res ; return res ;
} }
bool p3Peers::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) bool p3Peers::getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
#endif
return mPeerMgr->getGroupInfoByName(groupName, groupInfo);
}
bool p3Peers::getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo)
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getGroupInfo()" << std::endl; std::cerr << "p3Peers::getGroupInfo()" << std::endl;
@ -1321,7 +1329,7 @@ bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
return mPeerMgr->getGroupInfoList(groupInfoList); return mPeerMgr->getGroupInfoList(groupInfoList);
} }
bool p3Peers::assignPeerToGroup(const std::string &groupId, const RsPgpId& peerId, bool assign) bool p3Peers::assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId& peerId, bool assign)
{ {
std::list<RsPgpId> peerIds; std::list<RsPgpId> peerIds;
peerIds.push_back(peerId); peerIds.push_back(peerId);
@ -1329,7 +1337,7 @@ bool p3Peers::assignPeerToGroup(const std::string &groupId, const RsPgpId& peerI
return assignPeersToGroup(groupId, peerIds, assign); return assignPeersToGroup(groupId, peerIds, assign);
} }
bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) bool p3Peers::assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign)
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::assignPeersToGroup()" << std::endl; std::cerr << "p3Peers::assignPeersToGroup()" << std::endl;
@ -1343,7 +1351,7 @@ bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<RsP
FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id, FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
FileStorageFlags share_flags, FileStorageFlags share_flags,
const std::list<std::string>& directory_parent_groups) const std::list<RsNodeGroupId>& directory_parent_groups)
{ {
// We should be able to do that in O(1), using groups based on packs of bits. // We should be able to do that in O(1), using groups based on packs of bits.
// //
@ -1354,7 +1362,7 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
bool found = false ; bool found = false ;
RsPgpId pgp_id = getGPGId(peer_ssl_id) ; RsPgpId pgp_id = getGPGId(peer_ssl_id) ;
for(std::list<std::string>::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it) for(std::list<RsNodeGroupId>::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it)
{ {
RsGroupInfo info ; RsGroupInfo info ;
if(!getGroupInfo(*it,info)) if(!getGroupInfo(*it,info))

View File

@ -124,14 +124,15 @@ public:
/* Group Stuff */ /* Group Stuff */
virtual bool addGroup(RsGroupInfo &groupInfo); virtual bool addGroup(RsGroupInfo &groupInfo);
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo); virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const std::string &groupId); virtual bool removeGroup(const RsNodeGroupId &groupId);
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo); virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList); virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo& groupInfo);
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId &peerId, bool assign); virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId>& peerIds, bool assign); virtual bool assignPeerToGroup(const RsNodeGroupId &groupId, const RsPgpId &peerId, bool assign);
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId>& peerIds, bool assign);
virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id,FileStorageFlags share_flags,const std::list<std::string>& parent_groups); virtual FileSearchFlags computePeerPermissionFlags(const RsPeerId& peer_id, FileStorageFlags share_flags, const std::list<RsNodeGroupId> &parent_groups);
// service permission stuff // service permission stuff

View File

@ -43,34 +43,34 @@
uint32_t RsFileConfigSerialiser::size(RsItem *i) uint32_t RsFileConfigSerialiser::size(RsItem *i)
{ {
RsFileTransfer *rft; RsFileTransfer *rft;
RsFileConfigItem *rfi; RsFileConfigItem *rfj;
if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i))) if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i)))
{ {
return sizeTransfer(rft); return sizeTransfer(rft);
} }
if (NULL != (rfi = dynamic_cast<RsFileConfigItem *>(i))) if (NULL != (rfj = dynamic_cast<RsFileConfigItem *>(i)))
{ {
return sizeFileItem(rfi); return sizeFileItem(rfj);
} }
return 0; return 0;
} }
/* serialise the data to the buffer */ /* serialise the data to the buffer */
bool RsFileConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) bool RsFileConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{ {
RsFileTransfer *rft; RsFileTransfer *rft;
RsFileConfigItem *rfi; RsFileConfigItem *rfj;
if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i))) if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i)))
{ {
return serialiseTransfer(rft, data, pktsize); return serialiseTransfer(rft, data, pktsize);
} }
if (NULL != (rfi = dynamic_cast<RsFileConfigItem *>(i))) if (NULL != (rfj = dynamic_cast<RsFileConfigItem*>(i)))
{ {
return serialiseFileItem(rfi, data, pktsize); return serialiseFileItem(rfj, data, pktsize);
} }
return false; return false;
} }
RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize) RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
@ -90,10 +90,13 @@ RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
case RS_PKT_SUBTYPE_FILE_TRANSFER: case RS_PKT_SUBTYPE_FILE_TRANSFER:
return deserialiseTransfer(data, pktsize); return deserialiseTransfer(data, pktsize);
break; break;
case RS_PKT_SUBTYPE_FILE_ITEM: case RS_PKT_SUBTYPE_FILE_ITEM_deprecated:
return deserialiseFileItem(data, pktsize); return deserialiseFileItem_deprecated(data, pktsize);
break; break;
default: case RS_PKT_SUBTYPE_FILE_ITEM:
return deserialiseFileItem(data, pktsize);
break;
default:
return NULL; return NULL;
break; break;
} }
@ -158,20 +161,20 @@ std::ostream &RsFileTransfer::print(std::ostream &out, uint16_t indent)
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
RsFileConfigItem::~RsFileConfigItem() void RsFileConfigItem_deprecated::clear()
{ {
return;
}
void RsFileConfigItem::clear()
{
file.TlvClear(); file.TlvClear();
flags = 0; flags = 0;
parent_groups.clear() ; parent_groups.clear() ;
} }
std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent) void RsFileConfigItem::clear()
{
file.TlvClear();
flags = 0;
parent_groups.TlvClear() ;
}
std::ostream &RsFileConfigItem_deprecated::print(std::ostream &out, uint16_t indent)
{ {
printRsItemBase(out, "RsFileConfigItem", indent); printRsItemBase(out, "RsFileConfigItem", indent);
uint16_t int_Indent = indent + 2; uint16_t int_Indent = indent + 2;
@ -188,6 +191,22 @@ std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent)
return out; return out;
} }
std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsFileConfigItem", indent);
uint16_t int_Indent = indent + 2;
file.print(out, int_Indent);
printIndent(out, int_Indent); out << "flags: " << flags << std::endl;
printIndent(out, int_Indent); out << "groups:" ;
for(std::set<RsNodeGroupId>::const_iterator it(parent_groups.ids.begin());it!=parent_groups.ids.end();++it)
out << (*it) << " " ;
out << std::endl;
printRsItemEnd(out, "RsFileConfigItem", indent);
return out;
}
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
@ -351,8 +370,7 @@ uint32_t RsFileConfigSerialiser::sizeFileItem(RsFileConfigItem *item)
s += item->file.TlvSize(); s += item->file.TlvSize();
s += 4; // flags s += 4; // flags
for(std::list<std::string>::const_iterator it(item->parent_groups.begin());it!=item->parent_groups.end();++it) // parent groups s += item->parent_groups.TlvSize() ;
s += GetTlvStringSize(*it);
return s; return s;
} }
@ -382,9 +400,7 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
/* add mandatory parts first */ /* add mandatory parts first */
ok &= item->file.SetTlv(data, tlvsize, &offset); ok &= item->file.SetTlv(data, tlvsize, &offset);
ok &= setRawUInt32(data, tlvsize, &offset, item->flags); ok &= setRawUInt32(data, tlvsize, &offset, item->flags);
ok &= item->parent_groups.SetTlv(data, tlvsize, &offset);
for(std::list<std::string>::const_iterator it(item->parent_groups.begin());ok && it!=item->parent_groups.end();++it) // parent groups
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, *it);
if (offset != tlvsize) if (offset != tlvsize)
{ {
@ -397,6 +413,66 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
return ok; return ok;
} }
RsFileConfigItem_deprecated *RsFileConfigSerialiser::deserialiseFileItem_deprecated(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_FILE_ITEM_deprecated != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsFileConfigItem_deprecated *item = new RsFileConfigItem_deprecated();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= item->file.GetTlv(data, rssize, &offset);
ok &= getRawUInt32(data, rssize, &offset, &(item->flags));
while(offset < rssize)
{
std::string tmp ;
if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp))
item->parent_groups.push_back(tmp) ;
else
break ;
}
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32_t *pktsize) RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32_t *pktsize)
{ {
/* get the type and size */ /* get the type and size */
@ -409,7 +485,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) || (RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_FILE_ITEM != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_FILE_ITEM != getRsItemSubType(rstype)))
{ {
return NULL; /* wrong type */ return NULL; /* wrong type */
} }
@ -423,7 +499,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
bool ok = true; bool ok = true;
/* ready to load */ /* ready to load */
RsFileConfigItem *item = new RsFileConfigItem(); RsFileConfigItem *item = new RsFileConfigItem();
item->clear(); item->clear();
/* skip the header */ /* skip the header */
@ -432,15 +508,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
/* get mandatory parts first */ /* get mandatory parts first */
ok &= item->file.GetTlv(data, rssize, &offset); ok &= item->file.GetTlv(data, rssize, &offset);
ok &= getRawUInt32(data, rssize, &offset, &(item->flags)); ok &= getRawUInt32(data, rssize, &offset, &(item->flags));
ok &= item->parent_groups.GetTlv(data, rssize, &offset) ;
while(offset < rssize)
{
std::string tmp ;
if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp))
item->parent_groups.push_back(tmp) ;
else
break ;
}
if (offset != rssize) if (offset != rssize)
{ {
@ -682,7 +750,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{ {
RsPeerStunItem *psi; RsPeerStunItem *psi;
RsPeerNetItem *pni; RsPeerNetItem *pni;
RsPeerGroupItem *pgi; RsNodeGroupItem *pgi;
RsPeerServicePermissionItem *pri; RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem; RsPeerBandwidthLimitsItem *pblitem;
@ -694,7 +762,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{ {
return sizeStun(psi); return sizeStun(psi);
} }
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem *>(i))) else if (NULL != (pgi = dynamic_cast<RsNodeGroupItem*>(i)))
{ {
return sizeGroup(pgi); return sizeGroup(pgi);
} }
@ -715,7 +783,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{ {
RsPeerNetItem *pni; RsPeerNetItem *pni;
RsPeerStunItem *psi; RsPeerStunItem *psi;
RsPeerGroupItem *pgi; RsNodeGroupItem *pgi;
RsPeerServicePermissionItem *pri; RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem; RsPeerBandwidthLimitsItem *pblitem;
@ -727,7 +795,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{ {
return serialiseStun(psi, data, pktsize); return serialiseStun(psi, data, pktsize);
} }
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem *>(i))) else if (NULL != (pgi = dynamic_cast<RsNodeGroupItem*>(i)))
{ {
return serialiseGroup(pgi, data, pktsize); return serialiseGroup(pgi, data, pktsize);
} }
@ -764,9 +832,11 @@ RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
return deserialiseNet(data, pktsize); return deserialiseNet(data, pktsize);
case RS_PKT_SUBTYPE_PEER_STUN: case RS_PKT_SUBTYPE_PEER_STUN:
return deserialiseStun(data, pktsize); return deserialiseStun(data, pktsize);
case RS_PKT_SUBTYPE_PEER_GROUP: case RS_PKT_SUBTYPE_PEER_GROUP_deprecated:
return deserialiseGroup(data, pktsize); return deserialiseGroup_deprecated(data, pktsize);
case RS_PKT_SUBTYPE_PEER_PERMISSIONS: case RS_PKT_SUBTYPE_NODE_GROUP:
return deserialiseGroup(data, pktsize);
case RS_PKT_SUBTYPE_PEER_PERMISSIONS:
return deserialisePermissions(data, pktsize); return deserialisePermissions(data, pktsize);
case RS_PKT_SUBTYPE_PEER_BANDLIMITS: case RS_PKT_SUBTYPE_PEER_BANDLIMITS:
return deserialisePeerBandwidthLimits(data, pktsize); return deserialisePeerBandwidthLimits(data, pktsize);
@ -1312,16 +1382,64 @@ RsPeerStunItem *RsPeerConfigSerialiser::deserialiseStun(void *data, uint32_t *si
} }
/*************************************************************************/ /*************************************************************************/
RsNodeGroupItem::RsNodeGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
RsPeerGroupItem::RsPeerGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP)
{ {
} }
RsPeerGroupItem::~RsPeerGroupItem() RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g)
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
{
id = g.id ;
name = g.name ;
flag = g.flag ;
pgpList.ids = g.peerIds;
}
void RsNodeGroupItem::clear()
{
id.clear();
name.clear();
flag = 0;
pgpList.ids.clear();
}
std::ostream &RsNodeGroupItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsNodeGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "groupId: " << id << std::endl;
printIndent(out, int_Indent);
out << "groupName: " << name << std::endl;
printIndent(out, int_Indent);
out << "groupFlag: " << flag << std::endl;
std::set<RsPgpId>::iterator it;
for (it = pgpList.ids.begin(); it != pgpList.ids.end(); ++it) {
printIndent(out, int_Indent);
out << "peerId: " << it->toStdString() << std::endl;
}
printRsItemEnd(out, "RsNodeGroupItem", indent);
return out;
}
/*************************************************************************/
/* DEPRECATED CODE. SHOULD BE REMOVED WHEN EVERYONE USES THE NEW CLASS */
/*************************************************************************/
RsPeerGroupItem_deprecated::RsPeerGroupItem_deprecated() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP_deprecated)
{ {
} }
void RsPeerGroupItem::clear() RsPeerGroupItem_deprecated::~RsPeerGroupItem_deprecated()
{
}
void RsPeerGroupItem_deprecated::clear()
{ {
id.clear(); id.clear();
name.clear(); name.clear();
@ -1329,7 +1447,7 @@ void RsPeerGroupItem::clear()
pgpList.ids.clear(); pgpList.ids.clear();
} }
std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent) std::ostream &RsPeerGroupItem_deprecated::print(std::ostream &out, uint16_t indent)
{ {
printRsItemBase(out, "RsPeerGroupItem", indent); printRsItemBase(out, "RsPeerGroupItem", indent);
uint16_t int_Indent = indent + 2; uint16_t int_Indent = indent + 2;
@ -1353,38 +1471,67 @@ std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent)
return out; return out;
} }
/* set data from RsGroupInfo to RsPeerGroupItem */ RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup_deprecated(void *data, uint32_t *size)
void RsPeerGroupItem::set(RsGroupInfo &groupInfo)
{ {
id = groupInfo.id; /* get the type and size */
name = groupInfo.name; uint32_t rstype = getRsItemId(data);
flag = groupInfo.flag; uint32_t rssize = getRsItemSize(data);
pgpList.ids = groupInfo.peerIds;
}
/* get data from RsGroupInfo to RsPeerGroupItem */ uint32_t offset = 0;
void RsPeerGroupItem::get(RsGroupInfo &groupInfo)
{
groupInfo.id = id;
groupInfo.name = name;
groupInfo.flag = flag;
groupInfo.peerIds = pgpList.ids;
}
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*size = rssize;
bool ok = true;
RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
uint32_t version;
ok &= getRawUInt32(data, rssize, &offset, &version);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name);
ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
ok &= item->pgpList.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
return item;
}
/*************************************************************************/ /*************************************************************************/
uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem *i) uint32_t RsPeerConfigSerialiser::sizeGroup(RsNodeGroupItem *i)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += 4; /* version */ s += 4; /* version */
s += GetTlvStringSize(i->id); s += RsNodeGroupId::serial_size();
s += GetTlvStringSize(i->name); s += GetTlvStringSize(i->name);
s += 4; /* flag */ s += 4; /* flag */
s += i->pgpList.TlvSize(); s += i->pgpList.TlvSize();
return s; return s;
} }
bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, uint32_t *size) bool RsPeerConfigSerialiser::serialiseGroup(RsNodeGroupItem *item, void *data, uint32_t *size)
{ {
uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item); uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item);
uint32_t offset = 0; uint32_t offset = 0;
@ -1410,7 +1557,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
/* add mandatory parts first */ /* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, 0); ok &= setRawUInt32(data, tlvsize, &offset, 0);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_KEY, item->id); ok &= item->id.serialise(data, tlvsize, offset);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name);
ok &= setRawUInt32(data, tlvsize, &offset, item->flag); ok &= setRawUInt32(data, tlvsize, &offset, item->flag);
ok &= item->pgpList.SetTlv(data, tlvsize, &offset); ok &= item->pgpList.SetTlv(data, tlvsize, &offset);
@ -1426,7 +1573,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
return ok; return ok;
} }
RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size) RsNodeGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
{ {
/* get the type and size */ /* get the type and size */
uint32_t rstype = getRsItemId(data); uint32_t rstype = getRsItemId(data);
@ -1437,7 +1584,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_PEER_GROUP != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_NODE_GROUP != getRsItemSubType(rstype)))
{ {
return NULL; /* wrong type */ return NULL; /* wrong type */
} }
@ -1450,7 +1597,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
bool ok = true; bool ok = true;
RsPeerGroupItem *item = new RsPeerGroupItem(); RsNodeGroupItem *item = new RsNodeGroupItem();
item->clear(); item->clear();
/* skip the header */ /* skip the header */
@ -1459,7 +1606,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
/* get mandatory parts first */ /* get mandatory parts first */
uint32_t version; uint32_t version;
ok &= getRawUInt32(data, rssize, &offset, &version); ok &= getRawUInt32(data, rssize, &offset, &version);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id); ok &= item->id.deserialise(data, rssize, offset);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name);
ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
ok &= item->pgpList.GetTlv(data, rssize, &offset); ok &= item->pgpList.GetTlv(data, rssize, &offset);

View File

@ -50,15 +50,17 @@ const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01; const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
/* PEER CONFIG SUBTYPES */ /* PEER CONFIG SUBTYPES */
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02; const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03; const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP = 0x04; const uint8_t RS_PKT_SUBTYPE_PEER_GROUP_deprecated = 0x04;
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05; const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06; const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07;
/* FILE CONFIG SUBTYPES */ /* FILE CONFIG SUBTYPES */
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01; const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x02; const uint8_t RS_PKT_SUBTYPE_FILE_ITEM_deprecated = 0x02;
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x03;
/**************************************************************************/ /**************************************************************************/
@ -134,11 +136,11 @@ class RsPeerBandwidthLimitsItem : public RsItem
std::map<RsPgpId,PeerBandwidthLimits> peers ; std::map<RsPgpId,PeerBandwidthLimits> peers ;
}; };
class RsPeerGroupItem : public RsItem class RsPeerGroupItem_deprecated : public RsItem
{ {
public: public:
RsPeerGroupItem(); RsPeerGroupItem_deprecated();
virtual ~RsPeerGroupItem(); virtual ~RsPeerGroupItem_deprecated();
virtual void clear(); virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0); std::ostream &print(std::ostream &out, uint16_t indent = 0);
@ -156,6 +158,29 @@ public:
RsTlvPgpIdSet pgpList; RsTlvPgpIdSet pgpList;
}; };
class RsNodeGroupItem: public RsItem
{
public:
RsNodeGroupItem();
virtual ~RsNodeGroupItem() {}
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
explicit RsNodeGroupItem(const RsGroupInfo&) ;
// /* set data from RsGroupInfo to RsPeerGroupItem */
// void set(RsGroupInfo &groupInfo);
// /* get data from RsGroupInfo to RsPeerGroupItem */
// void get(RsGroupInfo &groupInfo);
/* Mandatory */
RsNodeGroupId id;
std::string name;
uint32_t flag;
RsTlvPgpIdSet pgpList;
};
class RsPeerStunItem: public RsItem class RsPeerStunItem: public RsItem
{ {
@ -197,9 +222,10 @@ virtual uint32_t sizeStun(RsPeerStunItem *);
virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size); virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size);
virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size); virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size);
virtual uint32_t sizeGroup(RsPeerGroupItem *); virtual uint32_t sizeGroup(RsNodeGroupItem *);
virtual bool serialiseGroup (RsPeerGroupItem *item, void *data, uint32_t *size); virtual bool serialiseGroup (RsNodeGroupItem *item, void *data, uint32_t *size);
virtual RsPeerGroupItem * deserialiseGroup(void *data, uint32_t *size); virtual RsNodeGroupItem *deserialiseGroup(void *data, uint32_t *size);
virtual RsPeerGroupItem_deprecated * deserialiseGroup_deprecated(void *data, uint32_t *size);
virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *); virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *);
virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size); virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size);
@ -303,23 +329,39 @@ class RsFileTransfer: public RsItem
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001; const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
/* Used by ft / extralist / configdirs / anyone who wants a basic file */ /* Used by ft / extralist / configdirs / anyone who wants a basic file */
class RsFileConfigItem: public RsItem class RsFileConfigItem_deprecated: public RsItem
{ {
public: public:
RsFileConfigItem() RsFileConfigItem_deprecated()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_FILE_CONFIG, RS_PKT_TYPE_FILE_CONFIG,
RS_PKT_SUBTYPE_FILE_ITEM) RS_PKT_SUBTYPE_FILE_ITEM_deprecated)
{ return; } {}
virtual ~RsFileConfigItem(); virtual ~RsFileConfigItem_deprecated() {}
virtual void clear(); virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0); std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsTlvFileItem file; RsTlvFileItem file;
uint32_t flags; uint32_t flags;
std::list<std::string> parent_groups ; std::list<std::string> parent_groups ;
}; };
class RsFileConfigItem: public RsItem
{
public:
RsFileConfigItem()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_FILE_CONFIG,
RS_PKT_SUBTYPE_FILE_ITEM)
{}
virtual ~RsFileConfigItem() {}
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsTlvFileItem file;
uint32_t flags;
RsTlvNodeGroupIdSet parent_groups ;
};
/**************************************************************************/ /**************************************************************************/
class RsFileConfigSerialiser: public RsSerialType class RsFileConfigSerialiser: public RsSerialType
@ -341,9 +383,11 @@ virtual uint32_t sizeTransfer(RsFileTransfer *);
virtual bool serialiseTransfer(RsFileTransfer *item, void *data, uint32_t *size); virtual bool serialiseTransfer(RsFileTransfer *item, void *data, uint32_t *size);
virtual RsFileTransfer * deserialiseTransfer(void *data, uint32_t *size); virtual RsFileTransfer * deserialiseTransfer(void *data, uint32_t *size);
virtual RsFileConfigItem_deprecated * deserialiseFileItem_deprecated(void *data, uint32_t *size);
virtual uint32_t sizeFileItem(RsFileConfigItem *); virtual uint32_t sizeFileItem(RsFileConfigItem *);
virtual bool serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *size); virtual bool serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *size);
virtual RsFileConfigItem * deserialiseFileItem(void *data, uint32_t *size); virtual RsFileConfigItem *deserialiseFileItem(void *data, uint32_t *size);
}; };

View File

@ -204,6 +204,7 @@ 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_GXSIDSET = 0x1025;
const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026; const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026;
const uint16_t TLV_TYPE_NODEGROUPIDSET= 0x1027;
const uint16_t TLV_TYPE_SERVICESET = 0x1030; const uint16_t TLV_TYPE_SERVICESET = 0x1030;

View File

@ -115,11 +115,12 @@ template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
std::set<ID_CLASS> ids ; std::set<ID_CLASS> ids ;
}; };
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 ; typedef t_RsTlvIdSet<RsGxsId, TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
typedef t_RsTlvIdSet<RsGxsCircleId,TLV_TYPE_GXSCIRCLEIDSET> RsTlvGxsCircleIdSet ; typedef t_RsTlvIdSet<RsGxsCircleId,TLV_TYPE_GXSCIRCLEIDSET> RsTlvGxsCircleIdSet ;
typedef t_RsTlvIdSet<RsNodeGroupId,TLV_TYPE_NODEGROUPIDSET> RsTlvNodeGroupIdSet ;
class RsTlvServiceIdSet: public RsTlvItem class RsTlvServiceIdSet: public RsTlvItem
{ {

View File

@ -380,6 +380,7 @@ bool p3GxsCircles::loadCircle(const RsGxsCircleId &circleId)
return cache_request_load(circleId); return cache_request_load(circleId);
} }
int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const RsPgpId &id, bool& should_encrypt) int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const RsPgpId &id, bool& should_encrypt)
{ {
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/

View File

@ -116,13 +116,13 @@
* 10 | 1.0 | 0 | 0.25 | 1.0 * 10 | 1.0 | 0 | 0.25 | 1.0
* *
* To check: * To check:
* [ ] Opinions are saved/loaded accross restart * [X] Opinions are saved/loaded accross restart
* [ ] Opinions are transmitted to friends * [X] Opinions are transmitted to friends
* [ ] Opinions are transmitted to friends when updated * [X] Opinions are transmitted to friends when updated
* *
* To do: * To do:
* [ ] Add debug info * [X] Add debug info
* [ ] Test the whole thing * [X] Test the whole thing
* [X] Implement a system to allow not storing info when we don't have it * [X] Implement a system to allow not storing info when we don't have it
*/ */
@ -138,6 +138,7 @@ static const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ; // reputat
static const uint32_t PGP_AUTO_BAN_THRESHOLD_DEFAULT = 2 ; // above this, auto ban any GXS id signed by this node static const uint32_t PGP_AUTO_BAN_THRESHOLD_DEFAULT = 2 ; // above this, auto ban any GXS id signed by this node
static const uint32_t IDENTITY_FLAGS_UPDATE_DELAY = 100 ; // static const uint32_t IDENTITY_FLAGS_UPDATE_DELAY = 100 ; //
static const uint32_t BANNED_NODES_UPDATE_DELAY = 313 ; // update approx every 5 mins. Chosen to not be a multiple of IDENTITY_FLAGS_UPDATE_DELAY static const uint32_t BANNED_NODES_UPDATE_DELAY = 313 ; // update approx every 5 mins. Chosen to not be a multiple of IDENTITY_FLAGS_UPDATE_DELAY
static const uint32_t REPUTATION_INFO_KEEP_DELAY = 86400*35; // remove old reputation info 5 days after last usage limit, in case the ID would come back..
p3GxsReputation::p3GxsReputation(p3LinkMgr *lm) p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
:p3Service(), p3Config(), :p3Service(), p3Config(),
@ -149,7 +150,7 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
mRequestTime = 0; mRequestTime = 0;
mStoreTime = 0; mStoreTime = 0;
mReputationsUpdated = false; mReputationsUpdated = false;
mLastActiveFriendsUpdate = 0 ; mLastActiveFriendsUpdate = time(NULL) - 0.5*ACTIVE_FRIENDS_UPDATE_PERIOD; // avoids doing it too soon since the TS from rsIdentity needs to be loaded already
mAverageActiveFriends = 0 ; mAverageActiveFriends = 0 ;
mLastBannedNodesUpdate = 0 ; mLastBannedNodesUpdate = 0 ;
} }
@ -332,12 +333,57 @@ void p3GxsReputation::updateIdentityFlags()
void p3GxsReputation::cleanup() void p3GxsReputation::cleanup()
{ {
// remove opinions from friends that havn't been seen online for more than the specified delay // remove opinions from friends that havn't been seen online for more than the specified delay
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputation::cleanup() " << std::endl;
#endif #endif
std::cerr << __PRETTY_FUNCTION__ << ": not implemented. TODO!" << std::endl; std::cerr << "p3GxsReputation::cleanup() " << std::endl;
// remove optionions about identities that do not exist anymore. That will in particular avoid asking p3idservice about deleted
// identities, which would cause an excess of hits to the database.
// We do it in two steps to avoid a deadlock when calling rsIdentity from here.
bool updated = false ;
time_t now = time(NULL) ;
std::list<RsGxsId> ids_to_check_for_last_usage_ts;
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();)
if(it->second.mOpinions.empty() && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL)
{
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
++tmp ;
mReputations.erase(it) ;
it = tmp ;
#ifdef DEBUG_REPUTATION
std::cerr << " ID " << it->first << ": own is neutral and no opinions from friends => remove entry" << std::endl;
#endif
updated = true ;
}
else
{
ids_to_check_for_last_usage_ts.push_back(it->first) ;
++it;
}
}
for(std::list<RsGxsId>::const_iterator it(ids_to_check_for_last_usage_ts.begin());it!=ids_to_check_for_last_usage_ts.end();++it)
if(rsIdentity->getLastUsageTS(*it) + REPUTATION_INFO_KEEP_DELAY < now)
{
#ifdef DEBUG_REPUTATION
std::cerr << " Identity " << *it << " has a last usage TS of " << now - rsIdentity->getLastUsageTS(*it) << " secs ago: deleting it." << std::endl;
#endif
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
mReputations.erase(*it) ;
updated = true ;
}
if(updated)
IndicateConfigChanged() ;
} }
void p3GxsReputation::updateActiveFriends() void p3GxsReputation::updateActiveFriends()
@ -668,7 +714,7 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,time_t latest_update)
* Opinion * Opinion
****/ ****/
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::ReputationInfo& info) bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& owner_id, RsReputations::ReputationInfo& info)
{ {
if(gxsid.isNull()) if(gxsid.isNull())
return false ; return false ;
@ -678,25 +724,34 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::Rep
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << "getReputationInfo() for " << gxsid << std::endl; std::cerr << "getReputationInfo() for " << gxsid << std::endl;
#endif #endif
Reputation& rep(mReputations[gxsid]) ; std::map<RsGxsId,Reputation>::const_iterator it = mReputations.find(gxsid) ;
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ; if(it == mReputations.end())
info.mOverallReputationScore = rep.mReputation ;
info.mFriendAverage = rep.mFriendAverage ;
if( (rep.mIdentityFlags & REPUTATION_IDENTITY_FLAG_PGP_LINKED) && (mBannedPgpIds.find(rep.mOwnerNode) != mBannedPgpIds.end()))
{ {
info.mAssessment = RsReputations::ASSESSMENT_BAD ; info.mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
#ifdef DEBUG_REPUTATION info.mOverallReputationScore = RsReputations::REPUTATION_THRESHOLD_DEFAULT ;
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << rep.mOwnerNode << " is banned." << std::endl; info.mFriendAverage = REPUTATION_THRESHOLD_DEFAULT ;
#endif
return true;
} }
if(info.mOverallReputationScore > REPUTATION_ASSESSMENT_THRESHOLD_X1)
info.mAssessment = RsReputations::ASSESSMENT_OK ;
else else
info.mAssessment = RsReputations::ASSESSMENT_BAD ; {
const Reputation& rep(it->second) ;
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ;
info.mOverallReputationScore = rep.mReputation ;
info.mFriendAverage = rep.mFriendAverage ;
}
if(!owner_id.isNull() && (mBannedPgpIds.find(owner_id) != mBannedPgpIds.end()))
{
#ifdef DEBUG_REPUTATION
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned." << std::endl;
#endif
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
}
else if(info.mOverallReputationScore <= REPUTATION_ASSESSMENT_THRESHOLD_X1)
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
else
info.mAssessment = RsReputations::ASSESSMENT_OK ;
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl; std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
@ -705,12 +760,13 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::Rep
return true ; return true ;
} }
bool p3GxsReputation::isIdentityBanned(const RsGxsId &id) bool p3GxsReputation::isIdentityBanned(const RsGxsId &id,const RsPgpId& owner_node)
{ {
RsReputations::ReputationInfo info ; RsReputations::ReputationInfo info ;
getReputationInfo(id,info) ; if(!getReputationInfo(id,owner_node,info))
return false ;
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << "isIdentityBanned(): returning " << (info.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl; std::cerr << "isIdentityBanned(): returning " << (info.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl;
#endif #endif

View File

@ -97,8 +97,8 @@ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /
/***** Interface for RsReputations *****/ /***** Interface for RsReputations *****/
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ; virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) ; virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &owner_id, ReputationInfo& info) ;
virtual bool isIdentityBanned(const RsGxsId& id) ; virtual bool isIdentityBanned(const RsGxsId& id, const RsPgpId &owner_node) ;
virtual void setNodeAutoBanThreshold(uint32_t n) ; virtual void setNodeAutoBanThreshold(uint32_t n) ;
virtual uint32_t nodeAutoBanThreshold() ; virtual uint32_t nodeAutoBanThreshold() ;

View File

@ -258,16 +258,13 @@ time_t p3IdService::locked_getLastUsageTS(const RsGxsId& gxs_id)
std::map<RsGxsId,time_t>::const_iterator it = mKeysTS.find(gxs_id) ; std::map<RsGxsId,time_t>::const_iterator it = mKeysTS.find(gxs_id) ;
if(it == mKeysTS.end()) if(it == mKeysTS.end())
{ return 0 ;
slowIndicateConfigChanged() ;
return mKeysTS[gxs_id] = time(NULL) ;
}
else else
return it->second ; return it->second ;
} }
void p3IdService::timeStampKey(const RsGxsId& gxs_id) void p3IdService::timeStampKey(const RsGxsId& gxs_id)
{ {
if(rsReputations->isIdentityBanned(gxs_id)) if(isBanned(gxs_id))
{ {
std::cerr << "(II) p3IdService:timeStampKey(): refusing to time stamp key " << gxs_id << " because it is banned." << std::endl; std::cerr << "(II) p3IdService:timeStampKey(): refusing to time stamp key " << gxs_id << " because it is banned." << std::endl;
return; return;
@ -327,7 +324,7 @@ public:
time_t now = time(NULL); time_t now = time(NULL);
const RsGxsId& gxs_id = entry.details.mId ; const RsGxsId& gxs_id = entry.details.mId ;
bool is_id_banned = rsReputations->isIdentityBanned(gxs_id) ; bool is_id_banned = rsReputations->isIdentityBanned(gxs_id,entry.details.mPgpId) ;
bool is_own_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_IS_OWN_ID) ; bool is_own_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_IS_OWN_ID) ;
bool is_known_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN) ; bool is_known_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN) ;
bool is_signed_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED) ; bool is_signed_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED) ;
@ -343,17 +340,15 @@ public:
std::map<RsGxsId,time_t>::const_iterator it = mLastUsageTS.find(gxs_id) ; std::map<RsGxsId,time_t>::const_iterator it = mLastUsageTS.find(gxs_id) ;
if(it == mLastUsageTS.end()) bool no_ts = (it == mLastUsageTS.end()) ;
{
std::cerr << "No Ts for this ID" << std::endl;
return true ;
}
time_t last_usage_ts = it->second; time_t last_usage_ts = no_ts?0:(it->second);
time_t max_keep_time ; time_t max_keep_time ;
if(is_id_banned) if(no_ts)
max_keep_time = MAX_KEEP_KEYS_BANNED ; max_keep_time = 0 ;
else if(is_id_banned)
max_keep_time = MAX_KEEP_KEYS_BANNED ;
else if(is_known_id) else if(is_known_id)
max_keep_time = MAX_KEEP_KEYS_SIGNED_KNOWN ; max_keep_time = MAX_KEEP_KEYS_SIGNED_KNOWN ;
else if(is_signed_id) else if(is_signed_id)
@ -413,10 +408,7 @@ void p3IdService::cleanUnusedKeys()
{ {
RS_STACK_MUTEX(mIdMtx) ; RS_STACK_MUTEX(mIdMtx) ;
std::map<RsGxsId,time_t>::iterator tmp = mKeysTS.find(*it) ; mKeysTS.erase(*it) ;
if(mKeysTS.end() != tmp)
mKeysTS.erase(tmp) ;
// mPublicKeyCache.erase(*it) ; no need to do it now. It's done in p3IdService::deleteGroup() // mPublicKeyCache.erase(*it) ; no need to do it now. It's done in p3IdService::deleteGroup()
} }
@ -509,7 +501,13 @@ bool p3IdService:: getNickname(const RsGxsId &id, std::string &nickname)
} }
#endif #endif
bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details) time_t p3IdService::getLastUsageTS(const RsGxsId &id)
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
return locked_getLastUsageTS(id) ;
}
bool p3IdService::getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
{ {
#ifdef DEBUG_IDS #ifdef DEBUG_IDS
std::cerr << "p3IdService::getIdDetails(" << id << ")"; std::cerr << "p3IdService::getIdDetails(" << id << ")";
@ -530,7 +528,7 @@ bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
if(details.mNickname.length() > RSID_MAXIMUM_NICKNAME_SIZE*4) if(details.mNickname.length() > RSID_MAXIMUM_NICKNAME_SIZE*4)
details.mNickname = "[too long a name]" ; details.mNickname = "[too long a name]" ;
rsReputations->getReputationInfo(id,details.mReputation) ; rsReputations->getReputationInfo(id,details.mPgpId,details.mReputation) ;
return true; return true;
} }
@ -542,6 +540,16 @@ bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
return false; return false;
} }
bool p3IdService::isBanned(const RsGxsId &id)
{
RsIdentityDetails det ;
getIdDetails(id,det) ;
#ifdef DEBUG_REPUTATION
std::cerr << "isIdentityBanned(): returning " << (det.mReputation.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl;
#endif
return det.mReputation.mAssessment == RsReputations::ASSESSMENT_BAD ;
}
bool p3IdService::isOwnId(const RsGxsId& id) bool p3IdService::isOwnId(const RsGxsId& id)
{ {

View File

@ -218,34 +218,34 @@ private:
class p3IdService: public RsGxsIdExchange, public RsIdentity, public GxsTokenQueue, public RsTickEvent, public p3Config class p3IdService: public RsGxsIdExchange, public RsIdentity, public GxsTokenQueue, public RsTickEvent, public p3Config
{ {
public: public:
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils); p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, PgpAuxUtils *pgpUtils);
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
static uint32_t idAuthenPolicy(); static uint32_t idAuthenPolicy();
virtual void service_tick(); // needed for background processing. virtual void service_tick(); // needed for background processing.
/*! /*!
* Design hack, id service must be constructed first as it * Design hack, id service must be constructed first as it
* is need for construction of subsequent net services * is need for construction of subsequent net services
*/ */
void setNes(RsNetworkExchangeService* nes); void setNes(RsNetworkExchangeService* nes);
/* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */ /* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */
/* Data Specific Interface */ /* Data Specific Interface */
// These are exposed via RsIdentity. // These are exposed via RsIdentity.
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups); virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions); //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
// These are local - and not exposed via RsIdentity. // These are local - and not exposed via RsIdentity.
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group);
virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group); virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
//virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion); //virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
/**************** RsIdentity External Interface. /**************** RsIdentity External Interface.
* Notes: * Notes:
@ -256,86 +256,88 @@ virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
* Also need to handle Cache updates / invalidation from internal changes. * Also need to handle Cache updates / invalidation from internal changes.
* *
*/ */
//virtual bool getNickname(const RsGxsId &id, std::string &nickname); //virtual bool getNickname(const RsGxsId &id, std::string &nickname);
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details); virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details);
// //
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id, virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
bool absOpinion, int score); bool absOpinion, int score);
virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params); virtual bool createIdentity(uint32_t& token, RsIdentityParameters &params);
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group); virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group);
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group); virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group);
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname, virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
const std::string &tag, RsRecognTagDetails &details); const std::string &tag, RsRecognTagDetails &details);
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment, virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
uint16_t tag_class, uint16_t tag_type, std::string &tag); uint16_t tag_class, uint16_t tag_type, std::string &tag);
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ; virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ;
virtual bool isARegularContact(const RsGxsId& id) ; virtual bool isARegularContact(const RsGxsId& id) ;
virtual bool isBanned(const RsGxsId& id) ;
/**************** RsGixs Implementation ***************/ virtual time_t getLastUsageTS(const RsGxsId &id) ;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds); /**************** RsGixs Implementation ***************/
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ; virtual bool getOwnIds(std::list<RsGxsId> &ownIds);
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
virtual bool isOwnId(const RsGxsId& key_id) ; //virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ;
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
virtual bool signData(const uint8_t *data,uint32_t data_size,const RsGxsId& signer_id,RsTlvKeySignature& signature,uint32_t& signing_error) ; virtual bool isOwnId(const RsGxsId& key_id) ;
virtual bool validateData(const uint8_t *data,uint32_t data_size,const RsTlvKeySignature& signature,bool force_load,uint32_t& signing_error) ;
virtual bool encryptData(const uint8_t *decrypted_data,uint32_t decrypted_data_size,uint8_t *& encrypted_data,uint32_t& encrypted_data_size,const RsGxsId& encryption_key_id,bool force_load,uint32_t& encryption_error) ; virtual bool signData(const uint8_t *data,uint32_t data_size,const RsGxsId& signer_id,RsTlvKeySignature& signature,uint32_t& signing_error) ;
virtual bool decryptData(const uint8_t *encrypted_data,uint32_t encrypted_data_size,uint8_t *& decrypted_data,uint32_t& decrypted_data_size,const RsGxsId& encryption_key_id,uint32_t& encryption_error) ; virtual bool validateData(const uint8_t *data,uint32_t data_size,const RsTlvKeySignature& signature,bool force_load,uint32_t& signing_error) ;
virtual bool haveKey(const RsGxsId &id); virtual bool encryptData(const uint8_t *decrypted_data,uint32_t decrypted_data_size,uint8_t *& encrypted_data,uint32_t& encrypted_data_size,const RsGxsId& encryption_key_id,bool force_load,uint32_t& encryption_error) ;
virtual bool havePrivateKey(const RsGxsId &id); virtual bool decryptData(const uint8_t *encrypted_data,uint32_t encrypted_data_size,uint8_t *& decrypted_data,uint32_t& decrypted_data_size,const RsGxsId& encryption_key_id,uint32_t& encryption_error) ;
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key); virtual bool haveKey(const RsGxsId &id);
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key); virtual bool havePrivateKey(const RsGxsId &id);
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers); virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key);
virtual bool requestPrivateKey(const RsGxsId &id); virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key);
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers);
virtual bool requestPrivateKey(const RsGxsId &id);
/**************** RsGixsReputation Implementation ****************/ /**************** RsGixsReputation Implementation ****************/
// get Reputation. // get Reputation.
virtual bool haveReputation(const RsGxsId &id); virtual bool haveReputation(const RsGxsId &id);
virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers); virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep); virtual bool getReputation(const RsGxsId &id, GixsReputation &rep);
protected: protected:
/** Notifications **/ /** Notifications **/
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes); virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
/** Overloaded to add PgpIdHash to Group Definition **/ /** Overloaded to add PgpIdHash to Group Definition **/
virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet); virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
// Overloaded from GxsTokenQueue for Request callbacks. // Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type); virtual void handleResponse(uint32_t token, uint32_t req_type);
// Overloaded from RsTickEvent. // Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel); virtual void handle_event(uint32_t event_type, const std::string &elabel);
//===================================================// //===================================================//
// p3Config methods // // p3Config methods //
//===================================================// //===================================================//
// Load/save the routing info, the pending items in transit, and the config variables. // Load/save the routing info, the pending items in transit, and the config variables.
// //
virtual bool loadList(std::list<RsItem*>& items) ; virtual bool loadList(std::list<RsItem*>& items) ;
virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ; virtual bool saveList(bool& cleanup,std::list<RsItem*>& items) ;
virtual RsSerialiser *setupSerialiser() ; virtual RsSerialiser *setupSerialiser() ;
private: private:
/************************************************************************ /************************************************************************
* This is the Cache for minimising calls to the DataStore. * This is the Cache for minimising calls to the DataStore.
* *
*/ */
@ -348,7 +350,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool cache_store(const RsGxsIdGroupItem *item); bool cache_store(const RsGxsIdGroupItem *item);
bool cache_update_if_cached(const RsGxsId &id, std::string serviceString); bool cache_update_if_cached(const RsGxsId &id, std::string serviceString);
bool isPendingNetworkRequest(const RsGxsId& gxsId); bool isPendingNetworkRequest(const RsGxsId& gxsId);
void requestIdsFromNet(); void requestIdsFromNet();
// Mutex protected. // Mutex protected.
@ -359,7 +361,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
// Switching to RsMemCache for Key Caching. // Switching to RsMemCache for Key Caching.
RsMemCache<RsGxsId, RsGxsIdCache> mKeyCache; RsMemCache<RsGxsId, RsGxsIdCache> mKeyCache;
/************************************************************************ /************************************************************************
* Refreshing own Ids. * Refreshing own Ids.
* *
*/ */
@ -368,7 +370,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
std::list<RsGxsId> mOwnIds; std::list<RsGxsId> mOwnIds;
/************************************************************************ /************************************************************************
* Test fns for Caching. * Test fns for Caching.
* *
*/ */
@ -376,7 +378,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool cachetest_getlist(); bool cachetest_getlist();
bool cachetest_handlerequest(uint32_t token); bool cachetest_handlerequest(uint32_t token);
/************************************************************************ /************************************************************************
* for processing background tasks that use the serviceString. * for processing background tasks that use the serviceString.
* - must be mutually exclusive to avoid clashes. * - must be mutually exclusive to avoid clashes.
*/ */
@ -386,7 +388,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool mBgSchedule_Active; bool mBgSchedule_Active;
uint32_t mBgSchedule_Mode; uint32_t mBgSchedule_Mode;
/************************************************************************ /************************************************************************
* pgphash processing. * pgphash processing.
* *
*/ */
@ -394,7 +396,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool pgphash_handlerequest(uint32_t token); bool pgphash_handlerequest(uint32_t token);
bool pgphash_process(); bool pgphash_process();
bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id, bool &error); bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id, bool &error);
void getPgpIdList(); void getPgpIdList();
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */ /* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
@ -402,7 +404,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
std::map<RsPgpId, PGPFingerprintType> mPgpFingerprintMap; std::map<RsPgpId, PGPFingerprintType> mPgpFingerprintMap;
std::list<RsGxsIdGroup> mGroupsToProcess; std::list<RsGxsIdGroup> mGroupsToProcess;
/************************************************************************ /************************************************************************
* recogn processing. * recogn processing.
* *
*/ */
@ -420,7 +422,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
void loadRecognKeys(); void loadRecognKeys();
/************************************************************************ /************************************************************************
* opinion processing. * opinion processing.
* *
*/ */
@ -448,24 +450,24 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
std::map<RsGxsId, RsGxsRecognSignerItem *> mRecognSignKeys; std::map<RsGxsId, RsGxsRecognSignerItem *> mRecognSignKeys;
std::map<RsGxsId, uint32_t> mRecognOldSignKeys; std::map<RsGxsId, uint32_t> mRecognOldSignKeys;
/************************************************************************ /************************************************************************
* Below is the background task for processing opinions => reputations * Below is the background task for processing opinions => reputations
* *
*/ */
virtual void generateDummyData(); virtual void generateDummyData();
void generateDummy_OwnIds(); void generateDummy_OwnIds();
void generateDummy_FriendPGP(); void generateDummy_FriendPGP();
void generateDummy_UnknownPGP(); void generateDummy_UnknownPGP();
void generateDummy_UnknownPseudo(); void generateDummy_UnknownPseudo();
void cleanUnusedKeys() ; void cleanUnusedKeys() ;
void slowIndicateConfigChanged() ; void slowIndicateConfigChanged() ;
virtual void timeStampKey(const RsGxsId& id) ; virtual void timeStampKey(const RsGxsId& id) ;
time_t locked_getLastUsageTS(const RsGxsId& gxs_id); time_t locked_getLastUsageTS(const RsGxsId& gxs_id);
std::string genRandomId(int len = 20); std::string genRandomId(int len = 20);
#if 0 #if 0
bool reputation_start(); bool reputation_start();
@ -478,7 +480,7 @@ std::string genRandomId(int len = 20);
bool background_processNewMessages(); bool background_processNewMessages();
bool background_FullCalcRequest(); bool background_FullCalcRequest();
bool background_processFullCalc(); bool background_processFullCalc();
bool background_cleanup(); bool background_cleanup();
#endif #endif
@ -488,40 +490,40 @@ std::string genRandomId(int len = 20);
/***** below here is locked *****/ /***** below here is locked *****/
bool mLastBgCheck; bool mLastBgCheck;
bool mBgProcessing; bool mBgProcessing;
uint32_t mBgToken; uint32_t mBgToken;
uint32_t mBgPhase; uint32_t mBgPhase;
std::map<RsGxsGroupId, RsGroupMetaData> mBgGroupMap; std::map<RsGxsGroupId, RsGroupMetaData> mBgGroupMap;
std::list<RsGxsGroupId> mBgFullCalcGroups; std::list<RsGxsGroupId> mBgFullCalcGroups;
#endif #endif
/************************************************************************ /************************************************************************
* Other Data that is protected by the Mutex. * Other Data that is protected by the Mutex.
*/ */
private: private:
std::map<uint32_t, std::set<RsGxsGroupId> > mIdsPendingCache; std::map<uint32_t, std::set<RsGxsGroupId> > mIdsPendingCache;
std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent; std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent;
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent; std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
std::map<RsGxsId,time_t> mKeysTS ; std::map<RsGxsId,time_t> mKeysTS ;
// keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only. // keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only.
std::set<RsGxsId> mContacts; std::set<RsGxsId> mContacts;
RsNetworkExchangeService* mNes; RsNetworkExchangeService* mNes;
/************************** /**************************
* AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.) * AuxUtils provides interface to Security Function (e.g. GPGAuth(), notify etc.)
* without depending directly on all these classes. * without depending directly on all these classes.
*/ */
PgpAuxUtils *mPgpUtils; PgpAuxUtils *mPgpUtils;
time_t mLastKeyCleaningTime ; time_t mLastKeyCleaningTime ;
time_t mLastConfigUpdate ; time_t mLastConfigUpdate ;
bool mOwnIdsLoaded ; bool mOwnIdsLoaded ;
}; };
#endif // P3_IDENTITY_SERVICE_HEADER #endif // P3_IDENTITY_SERVICE_HEADER

View File

@ -64,8 +64,8 @@ class rsUdpStack: public UdpStack, public pqiNetListener
/* from pqiNetListener */ /* from pqiNetListener */
virtual bool resetListener(const struct sockaddr_storage &local) virtual bool resetListener(const struct sockaddr_storage &local)
{ {
std::cerr << "rsUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")"; //std::cerr << "rsUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
std::cerr << std::endl; //std::cerr << std::endl;
if (local.ss_family != AF_INET) if (local.ss_family != AF_INET)
{ {
@ -90,16 +90,16 @@ class rsFixedUdpStack: public UdpStack, public pqiNetListener
:UdpStack(testmode, local) { return; } :UdpStack(testmode, local) { return; }
/* from pqiNetListener */ /* from pqiNetListener */
virtual bool resetListener(const struct sockaddr_storage &local) virtual bool resetListener(const struct sockaddr_storage & /* local */)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
getLocalAddress(addr); getLocalAddress(addr);
// The const_cast below is not so nice but without it, the compiler can't // The const_cast below is not so nice but without it, the compiler can't
// find the correct operator<<(). No idea why! // find the correct operator<<(). No idea why!
std::cerr << "rsFixedUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")"; //std::cerr << "rsFixedUdpStack::resetListener(" << sockaddr_storage_tostring(local) << ")";
std::cerr << " Resetting with original addr: " << const_cast<const struct sockaddr_in &>(addr); //std::cerr << " Resetting with original addr: " << const_cast<const struct sockaddr_in &>(addr);
std::cerr << std::endl; //std::cerr << std::endl;
return resetAddress(addr); return resetAddress(addr);
} }

View File

@ -103,7 +103,7 @@ CreateCircleDialog::CreateCircleDialog()
#endif #endif
//ui.idChooser->loadIds(0,RsGxsId()); //ui.idChooser->loadIds(0,RsGxsId());
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, RsGxsCircleId()); ui.circleComboBox->loadCircles(RsGxsCircleId());
} }
CreateCircleDialog::~CreateCircleDialog() CreateCircleDialog::~CreateCircleDialog()
@ -604,7 +604,7 @@ void CreateCircleDialog::updateCircleGUI()
else else
ui.radioButton_Restricted->setChecked(true); ui.radioButton_Restricted->setChecked(true);
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mCircleGroup.mMeta.mCircleId); ui.circleComboBox->loadCircles(mCircleGroup.mMeta.mCircleId);
break; break;

View File

@ -26,7 +26,6 @@
#include "gui/common/UIStateHelper.h" #include "gui/common/UIStateHelper.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsreputations.h>
// Data Requests. // Data Requests.
#define IDDETAILSDIALOG_IDDETAILS 1 #define IDDETAILSDIALOG_IDDETAILS 1
@ -261,7 +260,7 @@ void IdDetailsDialog::insertIdDetails(uint32_t token)
#endif #endif
RsReputations::ReputationInfo info ; RsReputations::ReputationInfo info ;
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ; rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),data.mPgpId,info) ;
ui->neighborNodesOpinion_TF->setText(QString::number(info.mOverallReputationScore-1.0f)); ui->neighborNodesOpinion_TF->setText(QString::number(info.mOverallReputationScore-1.0f));

View File

@ -41,7 +41,6 @@
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsreputations.h>
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
#include <iostream> #include <iostream>
@ -1360,25 +1359,31 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item,
if (!item) if (!item)
item = new TreeWidgetItem(); item = new TreeWidgetItem();
RsReputations::ReputationInfo info ; RsIdentityDetails idd ;
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ; rsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId),idd) ;
item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE)); item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE));
item->setText(RSID_COL_KEYID, QString::fromStdString(data.mMeta.mGroupId.toStdString())); item->setText(RSID_COL_KEYID, QString::fromStdString(data.mMeta.mGroupId.toStdString()));
//time_t now = time(NULL) ; if(idd.mReputation.mAssessment == RsReputations::ASSESSMENT_BAD)
//item->setText(RSID_COL_LASTUSED, getHumanReadableDuration(now - data.mLastUsageTS)) ; {
item->setForeground(RSID_COL_NICKNAME,QBrush(Qt::red));
item->setForeground(RSID_COL_KEYID,QBrush(Qt::red));
item->setForeground(RSID_COL_IDTYPE,QBrush(Qt::red));
}
else
{
item->setForeground(RSID_COL_NICKNAME,QBrush(Qt::black));
item->setForeground(RSID_COL_KEYID,QBrush(Qt::black));
item->setForeground(RSID_COL_IDTYPE,QBrush(Qt::black));
}
item->setData(RSID_COL_KEYID, Qt::UserRole,QVariant(item_flags)) ; item->setData(RSID_COL_KEYID, Qt::UserRole,QVariant(item_flags)) ;
item->setTextAlignment(RSID_COL_VOTES, Qt::AlignRight); item->setTextAlignment(RSID_COL_VOTES, Qt::AlignRight);
item->setData(RSID_COL_VOTES,Qt::DisplayRole, QString::number(info.mOverallReputationScore - 1.0f,'f',3)); item->setData(RSID_COL_VOTES,Qt::DisplayRole, QString::number(idd.mReputation.mOverallReputationScore - 1.0f,'f',3));
if(isOwnId) if(isOwnId)
{ {
RsIdentityDetails idd ;
rsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId),idd) ;
QFont font = item->font(RSID_COL_NICKNAME) ; QFont font = item->font(RSID_COL_NICKNAME) ;
font.setBold(true) ; font.setBold(true) ;
@ -1740,12 +1745,12 @@ void IdDialog::insertIdDetails(uint32_t token)
#endif #endif
RsReputations::ReputationInfo info ; RsReputations::ReputationInfo info ;
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ; rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),data.mPgpId,info) ;
ui->neighborNodesOpinion_TF->setText(QString::number(info.mFriendAverage - 1.0f));
ui->overallOpinion_TF->setText(QString::number(info.mOverallReputationScore - 1.0f) +" ("+ ui->neighborNodesOpinion_TF->setText(QString::number(info.mFriendAverage - 1.0f));
((info.mAssessment == RsReputations::ASSESSMENT_OK)? tr("OK") : tr("Banned")) +")" ) ;
ui->overallOpinion_TF->setText(QString::number(info.mOverallReputationScore - 1.0f) +" ("+
((info.mAssessment == RsReputations::ASSESSMENT_OK)? tr("OK") : tr("Banned")) +")" ) ;
switch(info.mOwnOpinion) switch(info.mOwnOpinion)
{ {
@ -2021,10 +2026,10 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
#endif #endif
RsGxsId keyId((*it)->text(RSID_COL_KEYID).toStdString()); RsGxsId keyId((*it)->text(RSID_COL_KEYID).toStdString());
RsReputations::ReputationInfo info ; RsIdentityDetails det ;
rsReputations->getReputationInfo(keyId,info) ; rsIdentity->getIdDetails(keyId,det) ;
switch(info.mOwnOpinion) switch(det.mReputation.mOwnOpinion)
{ {
case RsReputations::OPINION_NEGATIVE: ++n_negative_reputations ; case RsReputations::OPINION_NEGATIVE: ++n_negative_reputations ;
break ; break ;

View File

@ -56,8 +56,9 @@
*****/ *****/
MessengerWindow* MessengerWindow::_instance = NULL; MessengerWindow* MessengerWindow::_instance = NULL;
static std::set<std::string> *expandedPeers = NULL;
static std::set<std::string> *expandedGroups = NULL; std::set<std::string> MessengerWindow::expandedPeers ;
std::set<RsNodeGroupId> MessengerWindow::expandedGroups ;
/*static*/ void MessengerWindow::showYourself () /*static*/ void MessengerWindow::showYourself ()
{ {
@ -79,16 +80,6 @@ void MessengerWindow::releaseInstance()
if (_instance) { if (_instance) {
delete _instance; delete _instance;
} }
if (expandedPeers) {
/* delete saved expanded peers */
delete(expandedPeers);
expandedPeers = NULL;
}
if (expandedGroups) {
/* delete saved expanded groups */
delete(expandedGroups);
expandedGroups = NULL;
}
} }
/** Constructor */ /** Constructor */
@ -108,21 +99,15 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WindowFlags flags)
connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage())); connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage()));
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int))); connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int)));
if (expandedPeers != NULL) { for (std::set<std::string>::iterator peerIt = expandedPeers.begin(); peerIt != expandedPeers.end(); ++peerIt) {
for (std::set<std::string>::iterator peerIt = expandedPeers->begin(); peerIt != expandedPeers->end(); ++peerIt) {
ui.friendList->addPeerToExpand(*peerIt); ui.friendList->addPeerToExpand(*peerIt);
} }
delete expandedPeers; expandedPeers.clear();
expandedPeers = NULL;
}
if (expandedGroups != NULL) { for (std::set<RsNodeGroupId>::iterator groupIt = expandedGroups.begin(); groupIt != expandedGroups.end(); ++groupIt) {
for (std::set<std::string>::iterator groupIt = expandedGroups->begin(); groupIt != expandedGroups->end(); ++groupIt) {
ui.friendList->addGroupToExpand(*groupIt); ui.friendList->addGroupToExpand(*groupIt);
} }
delete expandedGroups; expandedGroups.clear();
expandedGroups = NULL;
}
ui.messagelineEdit->setMinimumWidth(20); ui.messagelineEdit->setMinimumWidth(20);
@ -203,22 +188,12 @@ void MessengerWindow::addFriend()
void MessengerWindow::closeEvent (QCloseEvent * /*event*/) void MessengerWindow::closeEvent (QCloseEvent * /*event*/)
{ {
/* save the expanded peers */ /* save the expanded peers */
if (expandedPeers == NULL) { expandedPeers.clear();
expandedPeers = new std::set<std::string>; ui.friendList->getExpandedPeers(expandedPeers);
} else {
expandedPeers->clear();
}
ui.friendList->getExpandedPeers(*expandedPeers);
/* save the expanded groups */ /* save the expanded groups */
if (expandedGroups == NULL) { expandedGroups.clear();
expandedGroups = new std::set<std::string>; ui.friendList->getExpandedGroups(expandedGroups);
} else {
expandedGroups->clear();
}
ui.friendList->getExpandedGroups(*expandedGroups);
} }
/** Shows Share Manager */ /** Shows Share Manager */

View File

@ -66,6 +66,9 @@ private:
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::MessengerWindow ui; Ui::MessengerWindow ui;
static std::set<std::string> expandedPeers ;
static std::set<RsNodeGroupId> expandedGroups ;
}; };
#endif #endif

View File

@ -212,12 +212,12 @@ QString RetroshareDirModel::getFlagsString(FileStorageFlags flags)
return QString(str) ; return QString(str) ;
} }
QString RetroshareDirModel::getGroupsString(const std::list<std::string>& group_ids) QString RetroshareDirModel::getGroupsString(const std::list<RsNodeGroupId>& group_ids)
{ {
QString groups_str ; QString groups_str ;
RsGroupInfo group_info ; RsGroupInfo group_info ;
for(std::list<std::string>::const_iterator it(group_ids.begin());it!=group_ids.end();) for(std::list<RsNodeGroupId>::const_iterator it(group_ids.begin());it!=group_ids.end();)
if(rsPeers->getGroupInfo(*it,group_info)) if(rsPeers->getGroupInfo(*it,group_info))
{ {
groups_str += GroupDefs::name(group_info) ; groups_str += GroupDefs::name(group_info) ;

View File

@ -91,7 +91,7 @@ class RetroshareDirModel : public QAbstractItemModel
void treeStyle(); void treeStyle();
void downloadDirectory(const DirDetails & details, int prefixLen); void downloadDirectory(const DirDetails & details, int prefixLen);
static QString getFlagsString(FileStorageFlags f) ; static QString getFlagsString(FileStorageFlags f) ;
static QString getGroupsString(const std::list<std::string>&) ; static QString getGroupsString(const std::list<RsNodeGroupId> &) ;
QString getAgeIndicatorString(const DirDetails &) const; QString getAgeIndicatorString(const DirDetails &) const;
// void getAgeIndicatorRec(const DirDetails &details, QString &ret) const; // void getAgeIndicatorRec(const DirDetails &details, QString &ret) const;

View File

@ -249,7 +249,7 @@ void ShareManager::updateGroups()
QString group_string; QString group_string;
int n = 0; int n = 0;
for (std::list<std::string>::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n) for (std::list<RsNodeGroupId>::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n)
{ {
if (n>0) if (n>0)
group_string += ", " ; group_string += ", " ;

View File

@ -116,9 +116,7 @@ FriendList::FriendList(QWidget *parent) :
mShowGroups(true), mShowGroups(true),
mShowState(false), mShowState(false),
mHideUnconnected(false), mHideUnconnected(false),
groupsHasChanged(false), groupsHasChanged(false)
openGroups(NULL),
openPeers(NULL)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -219,7 +217,17 @@ void FriendList::processSettings(bool load)
int arrayIndex = Settings->beginReadArray("Groups"); int arrayIndex = Settings->beginReadArray("Groups");
for (int index = 0; index < arrayIndex; ++index) { for (int index = 0; index < arrayIndex; ++index) {
Settings->setArrayIndex(index); Settings->setArrayIndex(index);
addGroupToExpand(Settings->value("open").toString().toStdString());
std::string gids = Settings->value("open").toString().toStdString();
RsGroupInfo ginfo ;
if(rsPeers->getGroupInfoByName(gids,ginfo)) // backward compatibility
addGroupToExpand(ginfo.id) ;
else if(rsPeers->getGroupInfo(RsNodeGroupId(gids),ginfo)) // backward compatibility
addGroupToExpand(ginfo.id) ;
else
std::cerr << "(EE) Cannot find group info for openned group \"" << gids << "\"" << std::endl;
} }
Settings->endArray(); Settings->endArray();
} else { } else {
@ -236,11 +244,11 @@ void FriendList::processSettings(bool load)
// open groups // open groups
Settings->beginWriteArray("Groups"); Settings->beginWriteArray("Groups");
int arrayIndex = 0; int arrayIndex = 0;
std::set<std::string> expandedPeers; std::set<RsNodeGroupId> expandedPeers;
getExpandedGroups(expandedPeers); getExpandedGroups(expandedPeers);
foreach (std::string groupId, expandedPeers) { foreach (RsNodeGroupId groupId, expandedPeers) {
Settings->setArrayIndex(arrayIndex++); Settings->setArrayIndex(arrayIndex++);
Settings->setValue("open", QString::fromStdString(groupId)); Settings->setValue("open", QString::fromStdString(groupId.toStdString()));
} }
Settings->endArray(); Settings->endArray();
} }
@ -369,7 +377,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu); addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu);
} }
QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu); QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu);
addToGroupAction->setData(QString::fromStdString(groupIt->id)); addToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup())); connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup()));
addToGroupMenu->addAction(addToGroupAction); addToGroupMenu->addAction(addToGroupAction);
} }
@ -378,7 +386,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu); moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu);
} }
QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu); QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu);
moveToGroupAction->setData(QString::fromStdString(groupIt->id)); moveToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup())); connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup()));
moveToGroupMenu->addAction(moveToGroupAction); moveToGroupMenu->addAction(moveToGroupAction);
} else { } else {
@ -456,7 +464,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
void FriendList::createNewGroup() void FriendList::createNewGroup()
{ {
CreateGroup createGrpDialog ("", this); CreateGroup createGrpDialog (RsNodeGroupId(), this);
createGrpDialog.exec(); createGrpDialog.exec();
} }
@ -596,7 +604,7 @@ void FriendList::insertPeers()
if (mShowGroups && groupsHasChanged) { if (mShowGroups && groupsHasChanged) {
if (parent) { if (parent) {
if (parent->type() == TYPE_GROUP) { if (parent->type() == TYPE_GROUP) {
std::string groupId = getRsId(parent); RsNodeGroupId groupId(getRsId(parent));
// the parent is a group, check if the gpg id is assigned to the group // the parent is a group, check if the gpg id is assigned to the group
for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
@ -630,7 +638,7 @@ void FriendList::insertPeers()
} }
} else if (groupsHasChanged) { } else if (groupsHasChanged) {
// remove deleted groups // remove deleted groups
std::string groupId = getRsId(item); RsNodeGroupId groupId ( getRsId(item));
for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
if (groupIt->id == groupId) { if (groupIt->id == groupId) {
break; break;
@ -671,7 +679,7 @@ void FriendList::insertPeers()
int itemCount = peerTreeWidget->topLevelItemCount(); int itemCount = peerTreeWidget->topLevelItemCount();
for (int index = 0; index < itemCount; ++index) { for (int index = 0; index < itemCount; ++index) {
QTreeWidgetItem *groupItemLoop = peerTreeWidget->topLevelItem(index); QTreeWidgetItem *groupItemLoop = peerTreeWidget->topLevelItem(index);
if (groupItemLoop->type() == TYPE_GROUP && getRsId(groupItemLoop) == groupInfo->id) { if (groupItemLoop->type() == TYPE_GROUP && RsNodeGroupId(getRsId(groupItemLoop)) == groupInfo->id) {
groupItem = groupItemLoop; groupItem = groupItemLoop;
break; break;
} }
@ -690,7 +698,7 @@ void FriendList::insertPeers()
groupItem->setForeground(COLUMN_NAME, QBrush(textColorGroup())); groupItem->setForeground(COLUMN_NAME, QBrush(textColorGroup()));
/* used to find back the item */ /* used to find back the item */
groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id)); groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id.toStdString()));
groupItem->setData(COLUMN_DATA, ROLE_STANDARD, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? true : false); groupItem->setData(COLUMN_DATA, ROLE_STANDARD, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? true : false);
/* Sort data */ /* Sort data */
@ -716,7 +724,7 @@ void FriendList::insertPeers()
} }
} }
if (openGroups != NULL && openGroups->find(groupInfo->id) != openGroups->end()) { if (openGroups.find(groupInfo->id) != openGroups.end()) {
groupItem->setExpanded(true); groupItem->setExpanded(true);
} }
@ -1182,7 +1190,7 @@ void FriendList::insertPeers()
gpgItem->setFont(i, gpgFont); gpgItem->setFont(i, gpgFont);
} }
if (openPeers != NULL && openPeers->find(gpgId.toStdString()) != openPeers->end()) { if (openPeers.find(gpgId.toStdString()) != openPeers.end()) {
gpgItem->setExpanded(true); gpgItem->setExpanded(true);
} }
} }
@ -1217,14 +1225,6 @@ void FriendList::insertPeers()
} }
groupsHasChanged = false; groupsHasChanged = false;
if (openGroups != NULL) {
delete(openGroups);
openGroups = NULL;
}
if (openPeers != NULL) {
delete(openPeers);
openPeers = NULL;
}
ui->peerTreeWidget->resort(); ui->peerTreeWidget->resort();
} }
@ -1232,13 +1232,13 @@ void FriendList::insertPeers()
/** /**
* Returns a list with all groupIds that are expanded * Returns a list with all groupIds that are expanded
*/ */
bool FriendList::getExpandedGroups(std::set<std::string> &groups) const bool FriendList::getExpandedGroups(std::set<RsNodeGroupId> &groups) const
{ {
int itemCount = ui->peerTreeWidget->topLevelItemCount(); int itemCount = ui->peerTreeWidget->topLevelItemCount();
for (int index = 0; index < itemCount; ++index) { for (int index = 0; index < itemCount; ++index) {
QTreeWidgetItem *item = ui->peerTreeWidget->topLevelItem(index); QTreeWidgetItem *item = ui->peerTreeWidget->topLevelItem(index);
if (item->type() == TYPE_GROUP && item->isExpanded()) { if (item->type() == TYPE_GROUP && item->isExpanded()) {
groups.insert(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString()); groups.insert(RsNodeGroupId(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString()));
} }
} }
return true; return true;
@ -1626,7 +1626,7 @@ void FriendList::getSslIdsFromItem(QTreeWidgetItem *item, std::list<RsPeerId> &s
case TYPE_GROUP: case TYPE_GROUP:
{ {
RsGroupInfo groupInfo; RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(peerId, groupInfo)) { if (rsPeers->getGroupInfo(RsNodeGroupId(peerId), groupInfo)) {
std::set<RsPgpId>::iterator gpgIt; std::set<RsPgpId>::iterator gpgIt;
for (gpgIt = groupInfo.peerIds.begin(); gpgIt != groupInfo.peerIds.end(); ++gpgIt) { for (gpgIt = groupInfo.peerIds.begin(); gpgIt != groupInfo.peerIds.end(); ++gpgIt) {
rsPeers->getAssociatedSSLIds(*gpgIt, sslIds); rsPeers->getAssociatedSSLIds(*gpgIt, sslIds);
@ -1649,10 +1649,10 @@ void FriendList::addToGroup()
return; return;
} }
std::string groupId = qobject_cast<QAction*>(sender())->data().toString().toStdString(); RsNodeGroupId groupId ( qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsPgpId gpgId ( getRsId(c)); RsPgpId gpgId ( getRsId(c));
if (gpgId.isNull() || groupId.empty()) { if (gpgId.isNull() || groupId.isNull()) {
return; return;
} }
@ -1675,15 +1675,15 @@ void FriendList::moveToGroup()
return; return;
} }
std::string groupId = qobject_cast<QAction*>(sender())->data().toString().toStdString(); RsNodeGroupId groupId ( qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsPgpId gpgId ( getRsId(c)); RsPgpId gpgId ( getRsId(c));
if (gpgId.isNull() || groupId.empty()) { if (gpgId.isNull() || groupId.isNull()) {
return; return;
} }
// remove from all groups // remove from all groups
rsPeers->assignPeerToGroup("", gpgId, false); rsPeers->assignPeerToGroup(RsNodeGroupId(), gpgId, false);
// automatically expand the group, the peer is added to // automatically expand the group, the peer is added to
addGroupToExpand(groupId); addGroupToExpand(groupId);
@ -1704,7 +1704,7 @@ void FriendList::removeFromGroup()
return; return;
} }
std::string groupId = qobject_cast<QAction*>(sender())->data().toString().toStdString(); RsNodeGroupId groupId ( qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsPgpId gpgId ( getRsId(c)); RsPgpId gpgId ( getRsId(c));
if (gpgId.isNull()) { if (gpgId.isNull()) {
@ -1727,14 +1727,13 @@ void FriendList::editGroup()
return; return;
} }
std::string groupId = getRsId(c); RsNodeGroupId groupId ( getRsId(c));
if (groupId.empty()) { if (!groupId.isNull())
return; {
CreateGroup editGrpDialog(groupId, this);
editGrpDialog.exec();
} }
CreateGroup editGrpDialog(groupId, this);
editGrpDialog.exec();
} }
void FriendList::removeGroup() void FriendList::removeGroup()
@ -1749,13 +1748,10 @@ void FriendList::removeGroup()
return; return;
} }
std::string groupId = getRsId(c); RsNodeGroupId groupId ( getRsId(c));
if (groupId.empty()) { if (!groupId.isNull())
return; rsPeers->removeGroup(groupId);
}
rsPeers->removeGroup(groupId);
} }
void FriendList::exportFriendlistClicked() void FriendList::exportFriendlistClicked()
@ -2089,7 +2085,7 @@ bool FriendList::importFriendlist(QString &fileName, bool &errorPeers, bool &err
// get name and flags and try to get the group ID // get name and flags and try to get the group ID
std::string groupName = group.attribute("name").toStdString(); std::string groupName = group.attribute("name").toStdString();
uint32_t flag = group.attribute("flag").toInt(); uint32_t flag = group.attribute("flag").toInt();
std::string groupId; RsNodeGroupId groupId;
if(getOrCreateGroup(groupName, flag, groupId)) { if(getOrCreateGroup(groupName, flag, groupId)) {
// group id found! // group id found!
QDomElement pgpID = group.firstChildElement("pgpID"); QDomElement pgpID = group.firstChildElement("pgpID");
@ -2123,7 +2119,7 @@ bool FriendList::importFriendlist(QString &fileName, bool &errorPeers, bool &err
* @param id groupd id for the given name * @param id groupd id for the given name
* @return success or fail * @return success or fail
*/ */
bool FriendList::getGroupIdByName(const std::string &name, std::string &id) bool FriendList::getGroupIdByName(const std::string &name, RsNodeGroupId &id)
{ {
std::list<RsGroupInfo> grpList; std::list<RsGroupInfo> grpList;
if(!rsPeers->getGroupInfoList(grpList)) if(!rsPeers->getGroupInfoList(grpList))
@ -2146,14 +2142,14 @@ bool FriendList::getGroupIdByName(const std::string &name, std::string &id)
* @param id groupd id * @param id groupd id
* @return success or failure * @return success or failure
*/ */
bool FriendList::getOrCreateGroup(const std::string &name, const uint &flag, std::string &id) bool FriendList::getOrCreateGroup(const std::string &name, const uint &flag, RsNodeGroupId &id)
{ {
if(getGroupIdByName(name, id)) if(getGroupIdByName(name, id))
return true; return true;
// -> create one // -> create one
RsGroupInfo grp; RsGroupInfo grp;
grp.id = "0"; // RS will generate an ID grp.id.clear(); // RS will generate an ID
grp.name = name; grp.name = name;
grp.flag = flag; grp.flag = flag;
@ -2271,12 +2267,9 @@ void FriendList::filterItems(const QString &text)
* Add a groupId to the openGroups list. These groups * Add a groupId to the openGroups list. These groups
* will be expanded, when they're added to the QTreeWidget * will be expanded, when they're added to the QTreeWidget
*/ */
void FriendList::addGroupToExpand(const std::string &groupId) void FriendList::addGroupToExpand(const RsNodeGroupId &groupId)
{ {
if (openGroups == NULL) { openGroups.insert(groupId);
openGroups = new std::set<std::string>;
}
openGroups->insert(groupId);
} }
/** /**
@ -2285,10 +2278,7 @@ void FriendList::addGroupToExpand(const std::string &groupId)
*/ */
void FriendList::addPeerToExpand(const std::string &gpgId) void FriendList::addPeerToExpand(const std::string &gpgId)
{ {
if (openPeers == NULL) { openPeers.insert(gpgId);
openPeers = new std::set<std::string>;
}
openPeers->insert(gpgId);
} }
void FriendList::createDisplayMenu() void FriendList::createDisplayMenu()

View File

@ -63,8 +63,8 @@ public:
// Add a tool button to the tool area // Add a tool button to the tool area
void addToolButton(QToolButton *toolButton); void addToolButton(QToolButton *toolButton);
void processSettings(bool load); void processSettings(bool load);
void addGroupToExpand(const std::string &groupId); void addGroupToExpand(const RsNodeGroupId &groupId);
bool getExpandedGroups(std::set<std::string> &groups) const; bool getExpandedGroups(std::set<RsNodeGroupId> &groups) const;
void addPeerToExpand(const std::string &gpgId); void addPeerToExpand(const std::string &gpgId);
bool getExpandedPeers(std::set<std::string> &peers) const; bool getExpandedPeers(std::set<std::string> &peers) const;
@ -119,8 +119,9 @@ private:
QString mFilterText; QString mFilterText;
bool groupsHasChanged; bool groupsHasChanged;
std::set<std::string> *openGroups; std::set<RsNodeGroupId> openGroups;
std::set<std::string> *openPeers; #warning this would needs an ID, not a std::string.
std::set<std::string> openPeers;
/* Color definitions (for standard see qss.default) */ /* Color definitions (for standard see qss.default) */
QColor mTextColorGroup; QColor mTextColorGroup;
@ -129,8 +130,8 @@ private:
QTreeWidgetItem *getCurrentPeer() const; QTreeWidgetItem *getCurrentPeer() const;
void getSslIdsFromItem(QTreeWidgetItem *item, std::list<RsPeerId> &sslIds); void getSslIdsFromItem(QTreeWidgetItem *item, std::list<RsPeerId> &sslIds);
bool getOrCreateGroup(const std::string &name, const uint &flag, std::string &id); bool getOrCreateGroup(const std::string &name, const uint &flag, RsNodeGroupId &id);
bool getGroupIdByName(const std::string &name, std::string &id); bool getGroupIdByName(const std::string &name, RsNodeGroupId &id);
bool importExportFriendlistFileDialog(QString &fileName, bool import); bool importExportFriendlistFileDialog(QString &fileName, bool import);
bool exportFriendlist(QString &fileName); bool exportFriendlist(QString &fileName);

View File

@ -271,9 +271,9 @@ void FriendSelectionWidget::secured_fillList()
selectedIds<RsPeerId,IDTYPE_SSL>(sslIdsSelected,true); selectedIds<RsPeerId,IDTYPE_SSL>(sslIdsSelected,true);
} }
std::set<std::string> groupIdsSelected; std::set<RsNodeGroupId> groupIdsSelected;
if (mShowTypes & SHOW_GROUP) { if (mShowTypes & SHOW_GROUP) {
selectedIds<std::string,IDTYPE_GROUP>(groupIdsSelected,true); selectedIds<RsNodeGroupId,IDTYPE_GROUP>(groupIdsSelected,true);
} }
std::set<RsPgpId> gpgIdsSelected; std::set<RsPgpId> gpgIdsSelected;
@ -305,6 +305,9 @@ void FriendSelectionWidget::secured_fillList()
else else
rsPeers->getGPGAcceptedList(gpgIds); rsPeers->getGPGAcceptedList(gpgIds);
// add own pgp id to the list
gpgIds.push_back(rsPeers->getGPGOwnId()) ;
std::list<RsPeerId> sslIds; std::list<RsPeerId> sslIds;
std::list<RsPeerId>::iterator sslIt; std::list<RsPeerId>::iterator sslIt;
@ -347,7 +350,7 @@ void FriendSelectionWidget::secured_fillList()
groupItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter); groupItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter);
groupItem->setIcon(COLUMN_NAME, QIcon(IMAGE_GROUP16)); groupItem->setIcon(COLUMN_NAME, QIcon(IMAGE_GROUP16));
groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id)); groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id.toStdString()));
groupItem->setExpanded(true); groupItem->setExpanded(true);
@ -363,7 +366,7 @@ void FriendSelectionWidget::secured_fillList()
groupItem->setCheckState(0, Qt::Unchecked); groupItem->setCheckState(0, Qt::Unchecked);
} }
emit itemAdded(IDTYPE_GROUP, QString::fromStdString(groupInfo->id), groupItem); emit itemAdded(IDTYPE_GROUP, QString::fromStdString(groupInfo->id.toStdString()), groupItem);
if (std::find(groupIdsSelected.begin(), groupIdsSelected.end(), groupInfo->id) != groupIdsSelected.end()) { if (std::find(groupIdsSelected.begin(), groupIdsSelected.end(), groupInfo->id) != groupIdsSelected.end()) {
setSelected(mListModus, groupItem, true); setSelected(mListModus, groupItem, true);

View File

@ -0,0 +1,117 @@
/*
* Retroshare Gxs Support
*
* Copyright 2012-2013 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "GroupChooser.h"
#include <algorithm>
#include <iostream>
#include <retroshare/rspeers.h>
/** Constructor */
GroupChooser::GroupChooser(QWidget *parent)
: QComboBox(parent), mFlags(0)
{
return;
}
void GroupChooser::loadGroups(uint32_t chooserFlags, const RsNodeGroupId& defaultId)
{
mFlags = chooserFlags;
mDefaultGroupId = defaultId;
loadGroups();
}
bool GroupChooser::makeNodeGroupDesc(const RsGroupInfo& info, QString &desc)
{
desc.clear();
if(info.name.empty())
desc = tr("[Unknown]") ;
else
desc = "\"" + QString::fromUtf8(info.name.c_str()) + "\"";
desc += " [" ;
desc += QString::fromStdString(info.id.toStdString().substr(0,3));
desc += "...";
desc += QString::fromStdString(info.id.toStdString().substr(info.id.toStdString().length()-2,2));
desc += "]";
return true;
}
void GroupChooser::loadGroups()
{
std::list<RsGroupInfo> ids;
rsPeers->getGroupInfoList(ids);
if (ids.empty())
{
std::cerr << "GroupChooser::loadGroups() ERROR no ids";
std::cerr << std::endl;
return;
}
int i = 0;
int def = -1;
for( std::list<RsGroupInfo>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
{
/* add to Chooser */
QString str;
if (!makeNodeGroupDesc(*it, str))
{
std::cerr << "GroupChooser::loadGroups() ERROR Desc for Id: " << it->id;
std::cerr << std::endl;
continue;
}
QString id = QString::fromStdString(it->id.toStdString());
addItem(str, id);
if (mDefaultGroupId == it->id)
def = i;
}
if (def >= 0)
{
setCurrentIndex(def);
}
}
bool GroupChooser::getChosenGroup(RsNodeGroupId& id)
{
if (count() < 1)
return false;
int idx = currentIndex();
QVariant var = itemData(idx);
id = RsNodeGroupId(var.toString().toStdString());
return true;
}

View File

@ -0,0 +1,45 @@
/*
* Retroshare Gxs Support
*
* Copyright 2012-2013 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#pragma once
#include <QComboBox>
#include <retroshare/rspeers.h>
class GroupChooser : public QComboBox
{
public:
GroupChooser(QWidget *parent = NULL);
void loadGroups(uint32_t chooserFlags, const RsNodeGroupId& defaultId);
bool getChosenGroup(RsNodeGroupId& id);
static bool makeNodeGroupDesc(const RsGroupInfo& info, QString &desc);
private:
void loadGroups();
uint32_t mFlags;
RsNodeGroupId mDefaultGroupId;
};

View File

@ -51,7 +51,7 @@ const QString GroupDefs::name(const RsGroupInfo &groupInfo)
return qApp->translate("GroupDefs", "Favorites"); return qApp->translate("GroupDefs", "Favorites");
} }
std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id; std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id << std::endl;
return ""; return "";
} }

View File

@ -20,7 +20,7 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent)
void GroupSelectionBox::fillGroups() void GroupSelectionBox::fillGroups()
{ {
std::list<std::string> selectedIds; std::list<RsNodeGroupId> selectedIds;
selectedGroupIds(selectedIds); selectedGroupIds(selectedIds);
clear(); clear();
@ -30,7 +30,7 @@ void GroupSelectionBox::fillGroups()
for (std::list<RsGroupInfo>::const_iterator it(groupIds.begin()); it != groupIds.end(); ++it) { for (std::list<RsGroupInfo>::const_iterator it(groupIds.begin()); it != groupIds.end(); ++it) {
QListWidgetItem *item = new QListWidgetItem(GroupDefs::name(*it)); QListWidgetItem *item = new QListWidgetItem(GroupDefs::name(*it));
item->setData(ROLE_ID, QString::fromStdString(it->id)); item->setData(ROLE_ID, QString::fromStdString(it->id.toStdString()));
item->setBackgroundColor(QColor(183,236,181)); item->setBackgroundColor(QColor(183,236,181));
addItem(item); addItem(item);
} }
@ -38,27 +38,27 @@ void GroupSelectionBox::fillGroups()
setSelectedGroupIds(selectedIds); setSelectedGroupIds(selectedIds);
} }
void GroupSelectionBox::selectedGroupIds(std::list<std::string> &groupIds) const void GroupSelectionBox::selectedGroupIds(std::list<RsNodeGroupId> &groupIds) const
{ {
int itemCount = count(); int itemCount = count();
for (int i = 0; i < itemCount; ++i) { for (int i = 0; i < itemCount; ++i) {
QListWidgetItem *listItem = item(i); QListWidgetItem *listItem = item(i);
if (listItem->checkState() == Qt::Checked) { if (listItem->checkState() == Qt::Checked) {
groupIds.push_back(item(i)->data(ROLE_ID).toString().toStdString()); groupIds.push_back(RsNodeGroupId(item(i)->data(ROLE_ID).toString().toStdString()));
std::cerr << "Adding selected item " << groupIds.back() << std::endl; std::cerr << "Adding selected item " << groupIds.back() << std::endl;
} }
} }
} }
void GroupSelectionBox::setSelectedGroupIds(const std::list<std::string>& groupIds) void GroupSelectionBox::setSelectedGroupIds(const std::list<RsNodeGroupId>& groupIds)
{ {
int itemCount = count(); int itemCount = count();
for (int i = 0; i < itemCount; ++i) { for (int i = 0; i < itemCount; ++i) {
QListWidgetItem *listItem = item(i); QListWidgetItem *listItem = item(i);
if (std::find(groupIds.begin(), groupIds.end(), listItem->data(ROLE_ID).toString().toStdString()) != groupIds.end()) { if (std::find(groupIds.begin(), groupIds.end(), RsNodeGroupId(listItem->data(ROLE_ID).toString().toStdString())) != groupIds.end()) {
listItem->setCheckState(Qt::Checked); listItem->setCheckState(Qt::Checked);
} else { } else {
listItem->setCheckState(Qt::Unchecked); listItem->setCheckState(Qt::Unchecked);

View File

@ -1,4 +1,5 @@
#include <QListWidget> #include <QListWidget>
#include <retroshare/rsids.h>
class GroupSelectionBox: public QListWidget class GroupSelectionBox: public QListWidget
{ {
@ -7,10 +8,10 @@ class GroupSelectionBox: public QListWidget
public: public:
GroupSelectionBox(QWidget *parent); GroupSelectionBox(QWidget *parent);
void selectedGroupIds(std::list<std::string> &groupIds) const; void selectedGroupIds(std::list<RsNodeGroupId> &groupIds) const;
void selectedGroupNames(QList<QString> &groupNames) const; void selectedGroupNames(QList<QString> &groupNames) const;
void setSelectedGroupIds(const std::list<std::string> &groupIds); void setSelectedGroupIds(const std::list<RsNodeGroupId> &groupIds);
private slots: private slots:
void fillGroups(); void fillGroups();

View File

@ -297,7 +297,7 @@ static void fillGroups(ConnectFriendWizard *wizard, QComboBox *comboBox, const Q
GroupDefs::sortByName(groupInfoList); GroupDefs::sortByName(groupInfoList);
comboBox->addItem("", ""); // empty value comboBox->addItem("", ""); // empty value
for (std::list<RsGroupInfo>::iterator groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { for (std::list<RsGroupInfo>::iterator groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
comboBox->addItem(GroupDefs::name(*groupIt), QString::fromStdString(groupIt->id)); comboBox->addItem(GroupDefs::name(*groupIt), QString::fromStdString(groupIt->id.toStdString()));
} }
if (groupId.isEmpty() == false) { if (groupId.isEmpty() == false) {
@ -853,7 +853,7 @@ void ConnectFriendWizard::accept()
} }
if (!groupId.isEmpty()) if (!groupId.isEmpty())
rsPeers->assignPeerToGroup(groupId.toStdString(), peerDetails.gpg_id, true); rsPeers->assignPeerToGroup(RsNodeGroupId(groupId.toStdString()), peerDetails.gpg_id, true);
} }
if ((accept_connection) && (!peerDetails.id.isNull())) if ((accept_connection) && (!peerDetails.id.isNull()))

View File

@ -31,7 +31,7 @@
#include <algorithm> #include <algorithm>
/** Default constructor */ /** Default constructor */
CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent) CreateGroup::CreateGroup(const RsNodeGroupId &groupId, QWidget *parent)
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
{ {
/* Invoke Qt Designer generated QObject setup routine */ /* Invoke Qt Designer generated QObject setup routine */
@ -45,13 +45,18 @@ CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent)
mGroupId = groupId; mGroupId = groupId;
if(!mGroupId.isNull())
ui.groupId_LE->setText(QString::fromStdString(mGroupId.toStdString())) ;
else
ui.groupId_LE->setText(tr("To be defined")) ;
/* Initialize friends list */ /* Initialize friends list */
ui.friendList->setHeaderText(tr("Friends")); ui.friendList->setHeaderText(tr("Friends"));
ui.friendList->setModus(FriendSelectionWidget::MODUS_CHECK); ui.friendList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui.friendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_GPG); ui.friendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_GPG);
ui.friendList->start(); ui.friendList->start();
if (mGroupId.empty() == false) { if (!mGroupId.isNull()) {
/* edit exisiting group */ /* edit exisiting group */
RsGroupInfo groupInfo; RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(mGroupId, groupInfo)) { if (rsPeers->getGroupInfo(mGroupId, groupInfo)) {
@ -83,7 +88,7 @@ CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent)
std::list<RsGroupInfo>::iterator groupIt; std::list<RsGroupInfo>::iterator groupIt;
for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) { for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
if (mGroupId.empty() || groupIt->id != mGroupId) { if (mGroupId.isNull() || groupIt->id != mGroupId) {
mUsedGroupNames.append(GroupDefs::name(*groupIt)); mUsedGroupNames.append(GroupDefs::name(*groupIt));
} }
} }
@ -104,9 +109,9 @@ CreateGroup::~CreateGroup()
void CreateGroup::groupNameChanged(QString text) void CreateGroup::groupNameChanged(QString text)
{ {
if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) { if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) {
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
} else { } else {
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
} }
} }
@ -114,14 +119,19 @@ void CreateGroup::changeGroup()
{ {
RsGroupInfo groupInfo; RsGroupInfo groupInfo;
if (mGroupId.empty()) { if (mGroupId.isNull())
{
// add new group // add new group
groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData(); groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData();
if (!rsPeers->addGroup(groupInfo)) {
if (!rsPeers->addGroup(groupInfo))
return; return;
}
} else { }
if (rsPeers->getGroupInfo(mGroupId, groupInfo) == true) { else
{
if (rsPeers->getGroupInfo(mGroupId, groupInfo))
{
if (!mIsStandard) { if (!mIsStandard) {
groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData(); groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData();
if (!rsPeers->editGroup(mGroupId, groupInfo)) { if (!rsPeers->editGroup(mGroupId, groupInfo)) {

View File

@ -30,7 +30,7 @@ class CreateGroup : public QDialog
public: public:
/** Default constructor */ /** Default constructor */
CreateGroup(const std::string &groupId, QWidget *parent = 0); CreateGroup(const RsNodeGroupId &groupId, QWidget *parent = 0);
/** Default destructor */ /** Default destructor */
~CreateGroup(); ~CreateGroup();
@ -39,7 +39,7 @@ private slots:
void groupNameChanged(QString); void groupNameChanged(QString);
private: private:
std::string mGroupId; RsNodeGroupId mGroupId;
QStringList mUsedGroupNames; QStringList mUsedGroupNames;
bool mIsStandard; bool mIsStandard;

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>386</width> <width>575</width>
<height>298</height> <height>485</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -23,9 +23,6 @@
<property name="margin"> <property name="margin">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0">
<widget class="HeaderFrame" name="headerFrame"/>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QFrame" name="frame"> <widget class="QFrame" name="frame">
<property name="frameShape"> <property name="frameShape">
@ -36,27 +33,35 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="groupLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="spacing"> <item row="0" column="0">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="groupLabel"> <widget class="QLabel" name="groupLabel">
<property name="text"> <property name="text">
<string>Group Name</string> <string>Group Name:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QLineEdit" name="groupName"> <widget class="QLineEdit" name="groupName">
<property name="toolTip"> <property name="toolTip">
<string>Enter a name for your group</string> <string>Enter a name for your group</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="groupId_LB">
<property name="text">
<string>Group ID:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="groupId_LE">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -79,6 +84,9 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="HeaderFrame" name="headerFrame"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>

View File

@ -31,14 +31,13 @@
/** Constructor */ /** Constructor */
GxsCircleChooser::GxsCircleChooser(QWidget *parent) GxsCircleChooser::GxsCircleChooser(QWidget *parent)
: QComboBox(parent), mFlags(0) : QComboBox(parent)
{ {
return; return;
} }
void GxsCircleChooser::loadCircles(uint32_t chooserFlags, const RsGxsCircleId &defaultId) void GxsCircleChooser::loadCircles(const RsGxsCircleId &defaultId)
{ {
mFlags = chooserFlags;
mDefaultCircleId = defaultId; mDefaultCircleId = defaultId;
loadGxsCircles(); loadGxsCircles();
} }
@ -68,14 +67,7 @@ bool MakeGxsCircleDesc(const RsGxsCircleId &id, QString &desc)
void GxsCircleChooser::loadGxsCircles() void GxsCircleChooser::loadGxsCircles()
{ {
std::list<RsGxsCircleId> ids; std::list<RsGxsCircleId> ids;
if (mFlags & GXS_CIRCLE_CHOOSER_EXTERNAL) rsGxsCircles->getCircleExternalIdList(ids);
{
rsGxsCircles->getCircleExternalIdList(ids);
}
if (mFlags & GXS_CIRCLE_CHOOSER_PERSONAL)
{
rsGxsCircles->getCirclePersonalIdList(ids);
}
if (ids.empty()) if (ids.empty())
{ {

View File

@ -28,11 +28,6 @@
#include <QComboBox> #include <QComboBox>
#include <retroshare/rsgxscircles.h> #include <retroshare/rsgxscircles.h>
#define GXS_CIRCLE_CHOOSER_EXTERNAL 0x0001
#define GXS_CIRCLE_CHOOSER_PERSONAL 0x0002
#define GXS_CIRCLE_CHOOSER_ALLCIRCLES 0x0003 // OR of other two.
class GxsCircleChooser : public QComboBox class GxsCircleChooser : public QComboBox
{ {
Q_OBJECT Q_OBJECT
@ -40,12 +35,11 @@ class GxsCircleChooser : public QComboBox
public: public:
GxsCircleChooser(QWidget *parent = NULL); GxsCircleChooser(QWidget *parent = NULL);
void loadCircles(uint32_t chooserFlags, const RsGxsCircleId &defaultId); void loadCircles(const RsGxsCircleId &defaultId);
bool getChosenCircle(RsGxsCircleId &id); bool getChosenCircle(RsGxsCircleId &id);
private: private:
void loadGxsCircles(); void loadGxsCircles();
uint32_t mFlags;
RsGxsCircleId mDefaultCircleId; RsGxsCircleId mDefaultCircleId;
}; };

View File

@ -124,8 +124,8 @@ void GxsGroupDialog::init()
/* Setup Reasonable Defaults */ /* Setup Reasonable Defaults */
ui.idChooser->loadIds(0,RsGxsId()); ui.idChooser->loadIds(0,RsGxsId());
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, RsGxsCircleId()); ui.circleComboBox->loadCircles(RsGxsCircleId());
ui.localComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, RsGxsCircleId()); ui.localComboBox->loadGroups(0, RsNodeGroupId());
ui.groupDesc->setPlaceholderText(tr("Set a descriptive description here")); ui.groupDesc->setPlaceholderText(tr("Set a descriptive description here"));
@ -302,7 +302,13 @@ void GxsGroupDialog::setupDefaults()
} }
} }
ui.antiSpam_trackMessages->setChecked((bool)(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_TRACK)); ui.antiSpam_trackMessages->setChecked((bool)(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_TRACK));
ui.antiSpam_signedIds->setChecked((bool)(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP));
if( (mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP) && (mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP_KNOWN))
ui.antiSpam_perms_CB->setCurrentIndex(2) ;
else if(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP)
ui.antiSpam_perms_CB->setCurrentIndex(1) ;
else
ui.antiSpam_perms_CB->setCurrentIndex(0) ;
QString antispam_string ; QString antispam_string ;
if(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_TRACK) antispam_string += tr("Message tracking") ; if(mDefaultsFlags & GXS_GROUP_DEFAULTS_ANTISPAM_TRACK) antispam_string += tr("Message tracking") ;
@ -315,8 +321,6 @@ void GxsGroupDialog::setupDefaults()
ui.typeGroup_3->setEnabled(false); ui.typeGroup_3->setEnabled(false);
ui.typeLocal_3->setEnabled(false); ui.typeLocal_3->setEnabled(false);
#endif #endif
ui.typeLocal->setEnabled(false); // for now, since local circles not fully tested.
ui.typeLocal->setToolTip(tr("This feature is not yet available, but it will be available very soon!")); // for now, since local circles not fully tested.
} }
void GxsGroupDialog::setupVisibility() void GxsGroupDialog::setupVisibility()
@ -394,85 +398,97 @@ void GxsGroupDialog::newGroup()
void GxsGroupDialog::updateFromExistingMeta(const QString &description) void GxsGroupDialog::updateFromExistingMeta(const QString &description)
{ {
std::cerr << "void GxsGroupDialog::updateFromExistingMeta()"; std::cerr << "void GxsGroupDialog::updateFromExistingMeta()";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "void GxsGroupDialog::updateFromExistingMeta() mGrpMeta.mCircleType: "; std::cerr << "void GxsGroupDialog::updateFromExistingMeta() mGrpMeta.mCircleType: ";
std::cerr << mGrpMeta.mCircleType << " Internal: " << mGrpMeta.mInternalCircle; std::cerr << mGrpMeta.mCircleType << " Internal: " << mGrpMeta.mInternalCircle;
std::cerr << " External: " << mGrpMeta.mCircleId; std::cerr << " External: " << mGrpMeta.mCircleId;
std::cerr << std::endl; std::cerr << std::endl;
setupDefaults(); setupDefaults();
setupVisibility(); setupVisibility();
setupReadonly(); setupReadonly();
clearForm(); clearForm();
setGroupSignFlags(mGrpMeta.mSignFlags) ; setGroupSignFlags(mGrpMeta.mSignFlags) ;
/* setup name */ /* setup name */
ui.groupName->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str())); ui.groupName->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
/* Show Mode */ /* Show Mode */
ui.nameline->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str())); ui.nameline->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
ui.popline->setText(QString::number( mGrpMeta.mPop)) ; ui.popline->setText(QString::number( mGrpMeta.mPop)) ;
ui.postsline->setText(QString::number(mGrpMeta.mVisibleMsgCount)); ui.postsline->setText(QString::number(mGrpMeta.mVisibleMsgCount));
ui.lastpostline->setText(DateTime::formatLongDateTime(mGrpMeta.mLastPost)); ui.lastpostline->setText(DateTime::formatLongDateTime(mGrpMeta.mLastPost));
ui.authorLabel->setId(mGrpMeta.mAuthorId); ui.authorLabel->setId(mGrpMeta.mAuthorId);
ui.IDline->setText(QString::fromStdString(mGrpMeta.mGroupId.toStdString())); ui.IDline->setText(QString::fromStdString(mGrpMeta.mGroupId.toStdString()));
ui.descriptiontextEdit->setPlainText(description); ui.descriptiontextEdit->setPlainText(description);
switch (mode())
{
case MODE_CREATE:{
}
break;
case MODE_SHOW:{
ui.headerFrame->setHeaderText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
if (!mPicture.isNull())
ui.headerFrame->setHeaderImage(mPicture);
}
break;
case MODE_EDIT:{
}
break;
}
/* set description */
ui.groupDesc->setPlainText(description);
QString distribution_string = "[Unknown]";
switch(mGrpMeta.mCircleType) switch (mode())
{ {
case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY: case MODE_CREATE:{
ui.typeLocal->setChecked(true); }
distribution_string = tr("Your friends only") ; break;
ui.localComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle); case MODE_SHOW:{
ui.distributionCircleComboBox->setVisible(true) ; ui.headerFrame->setHeaderText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
ui.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle); if (!mPicture.isNull())
break; ui.headerFrame->setHeaderImage(mPicture);
case GXS_CIRCLE_TYPE_PUBLIC: }
ui.typePublic->setChecked(true); break;
distribution_string = tr("Public") ; case MODE_EDIT:{
ui.distributionCircleComboBox->setVisible(false) ; }
break; break;
case GXS_CIRCLE_TYPE_EXTERNAL: }
ui.typeGroup->setChecked(true); /* set description */
distribution_string = tr("Restricted to circle:") ; ui.groupDesc->setPlainText(description);
ui.distributionCircleComboBox->setVisible(true) ; QString distribution_string = "[Unknown]";
ui.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId);
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId); switch(mGrpMeta.mCircleType)
break; {
default: case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY:
std::cerr << "CreateCircleDialog::updateCircleGUI() INVALID mCircleType"; {
std::cerr << std::endl; ui.typeLocal->setChecked(true);
break; distribution_string = tr("Only friends nodes in group ") ;
}
RsGroupInfo ginfo ;
rsPeers->getGroupInfo(RsNodeGroupId(mGrpMeta.mInternalCircle),ginfo) ;
QString desc;
GroupChooser::makeNodeGroupDesc(ginfo, desc);
distribution_string += desc ;
ui.localComboBox->loadGroups(0, RsNodeGroupId(mGrpMeta.mInternalCircle));
ui.distributionCircleComboBox->setVisible(false) ;
ui.localComboBox->setVisible(true) ;
}
break;
case GXS_CIRCLE_TYPE_PUBLIC:
ui.typePublic->setChecked(true);
distribution_string = tr("Public") ;
ui.distributionCircleComboBox->setVisible(false) ;
ui.localComboBox->setVisible(false) ;
break;
case GXS_CIRCLE_TYPE_EXTERNAL:
ui.typeGroup->setChecked(true);
distribution_string = tr("Restricted to circle:") ;
ui.localComboBox->setVisible(false) ;
ui.distributionCircleComboBox->setVisible(true) ;
ui.distributionCircleComboBox->loadCircles(mGrpMeta.mCircleId);
ui.circleComboBox->loadCircles(mGrpMeta.mCircleId);
break;
default:
std::cerr << "CreateCircleDialog::updateCircleGUI() INVALID mCircleType";
std::cerr << std::endl;
break;
}
ui.distributionValueLabel->setText(distribution_string) ; ui.distributionValueLabel->setText(distribution_string) ;
ui.idChooser->loadIds(0, mGrpMeta.mAuthorId); ui.idChooser->loadIds(0, mGrpMeta.mAuthorId);
if(!mGrpMeta.mAuthorId.isNull())
ui.idChooser->setChosenId(mGrpMeta.mAuthorId) ;
updateCircleOptions(); if(!mGrpMeta.mAuthorId.isNull())
ui.idChooser->setChosenId(mGrpMeta.mAuthorId) ;
updateCircleOptions();
} }
void GxsGroupDialog::submitGroup() void GxsGroupDialog::submitGroup()
@ -613,32 +629,37 @@ void GxsGroupDialog::createGroup()
uint32_t GxsGroupDialog::getGroupSignFlags() uint32_t GxsGroupDialog::getGroupSignFlags()
{ {
/* grab from the ui options -> */ /* grab from the ui options -> */
uint32_t signFlags = 0; uint32_t signFlags = 0;
if (ui.publish_encrypt->isChecked()) { if (ui.publish_encrypt->isChecked()) {
signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_ENCRYPTED; signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_ENCRYPTED;
} else if (ui.publish_required->isChecked()) { } else if (ui.publish_required->isChecked()) {
signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_ALLSIGNED; signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_ALLSIGNED;
} else if (ui.publish_threads->isChecked()) { } else if (ui.publish_threads->isChecked()) {
signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_THREADHEAD; signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_THREADHEAD;
} else { // publish_open (default). } else { // publish_open (default).
signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_NONEREQ; signFlags |= GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_NONEREQ;
} }
if (ui.personal_required->isChecked()) if (ui.personal_required->isChecked())
signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_REQUIRED; signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_REQUIRED;
if (ui.personal_ifnopub->isChecked()) if (ui.personal_ifnopub->isChecked())
signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN; signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN;
// Author Signature. // Author Signature.
if (ui.antiSpam_signedIds->isChecked()) switch(ui.antiSpam_perms_CB->currentIndex())
signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG; {
case 0: break ;
if (ui.antiSpam_trackMessages->isChecked()) case 2: signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN; // no break below, since we want *both* flags in this case.
signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES; case 1: signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG;
break ;
return signFlags; }
if (ui.antiSpam_trackMessages->isChecked())
signFlags |= GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES;
return signFlags;
} }
void GxsGroupDialog::setGroupSignFlags(uint32_t signFlags) void GxsGroupDialog::setGroupSignFlags(uint32_t signFlags)
@ -660,11 +681,19 @@ void GxsGroupDialog::setGroupSignFlags(uint32_t signFlags)
ui.personal_ifnopub->setChecked(true); ui.personal_ifnopub->setChecked(true);
ui.antiSpam_trackMessages ->setChecked((bool)(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) ); ui.antiSpam_trackMessages ->setChecked((bool)(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) );
ui.antiSpam_signedIds ->setChecked((bool)(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) );
if( (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN) && (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG))
ui.antiSpam_perms_CB->setCurrentIndex(2) ;
else if(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG)
ui.antiSpam_perms_CB->setCurrentIndex(1) ;
else
ui.antiSpam_perms_CB->setCurrentIndex(0) ;
QString antispam_string ; QString antispam_string ;
if(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) antispam_string += tr("Message tracking") ; if(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) antispam_string += tr("Message tracking") ;
if(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) antispam_string += (antispam_string.isNull()?"":" and ")+tr("PGP signature required") ; if(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN) antispam_string += (antispam_string.isNull()?"":" and ")+tr("PGP signature from known ID required") ;
else
if(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) antispam_string += (antispam_string.isNull()?"":" and ")+tr("PGP signature required") ;
ui.antiSpamValueLabel->setText(antispam_string) ; ui.antiSpamValueLabel->setText(antispam_string) ;
//ui.antiSpam_trackMessages_2->setChecked((bool)(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) ); //ui.antiSpam_trackMessages_2->setChecked((bool)(signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES) );
@ -720,41 +749,42 @@ void GxsGroupDialog::updateCircleOptions()
bool GxsGroupDialog::setCircleParameters(RsGroupMetaData &meta) bool GxsGroupDialog::setCircleParameters(RsGroupMetaData &meta)
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC; meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear(); meta.mCircleId.clear();
meta.mOriginator.clear(); meta.mOriginator.clear();
meta.mInternalCircle.clear(); meta.mInternalCircle.clear();
if (ui.typePublic->isChecked()) if (ui.typePublic->isChecked())
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC; meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear(); meta.mCircleId.clear();
} }
else if (ui.typeGroup->isChecked()) else if (ui.typeGroup->isChecked())
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL; meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
if (!ui.circleComboBox->getChosenCircle(meta.mCircleId)) if (!ui.circleComboBox->getChosenCircle(meta.mCircleId))
{ {
return false; return false;
} }
} }
else if (ui.typeLocal->isChecked()) else if (ui.typeLocal->isChecked())
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY; meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY;
meta.mCircleId.clear(); meta.mCircleId.clear();
meta.mOriginator.clear(); meta.mOriginator.clear();
meta.mInternalCircle.clear() ; meta.mInternalCircle.clear() ;
if (!ui.localComboBox->getChosenCircle(meta.mInternalCircle)) RsNodeGroupId ngi ;
{
return false; if (!ui.localComboBox->getChosenGroup(ngi))
} return false;
}
else meta.mInternalCircle = RsGxsCircleId(ngi) ;
{ }
return false; else
} return false;
return true;
return true;
} }
void GxsGroupDialog::cancelDialog() void GxsGroupDialog::cancelDialog()

View File

@ -90,8 +90,9 @@ public:
#define GXS_GROUP_DEFAULTS_COMMENTS_YES 0x00001000 #define GXS_GROUP_DEFAULTS_COMMENTS_YES 0x00001000
#define GXS_GROUP_DEFAULTS_COMMENTS_NO 0x00002000 #define GXS_GROUP_DEFAULTS_COMMENTS_NO 0x00002000
#define GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP 0x00100000 #define GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP 0x00100000
#define GXS_GROUP_DEFAULTS_ANTISPAM_TRACK 0x00200000 #define GXS_GROUP_DEFAULTS_ANTISPAM_TRACK 0x00200000
#define GXS_GROUP_DEFAULTS_ANTISPAM_FAVOR_PGP_KNOWN 0x00400000
/*! /*!
* The aim of this dialog is to be convenient to encapsulate group * The aim of this dialog is to be convenient to encapsulate group

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@
#include <math.h> #include <math.h>
#include "GxsIdDetails.h" #include "GxsIdDetails.h"
#include "retroshare-gui/RsAutoUpdatePage.h" #include "retroshare-gui/RsAutoUpdatePage.h"
#include "retroshare/rsreputations.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
@ -905,7 +904,7 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, QLi
QString GxsIdDetails::getName(const RsIdentityDetails &details) QString GxsIdDetails::getName(const RsIdentityDetails &details)
{ {
if(rsReputations->isIdentityBanned(details.mId)) if(rsIdentity->isBanned(details.mId))
return tr("[Banned]") ; return tr("[Banned]") ;
QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE); QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE);
@ -924,7 +923,7 @@ QString GxsIdDetails::getComment(const RsIdentityDetails &details)
QString comment; QString comment;
QString nickname ; QString nickname ;
bool banned = rsReputations->isIdentityBanned(details.mId) ; bool banned = rsIdentity->isBanned(details.mId) ;
if(details.mNickname.empty()) if(details.mNickname.empty())
nickname = tr("[Unknown]") ; nickname = tr("[Unknown]") ;
@ -963,7 +962,7 @@ void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList<QIcon> &icon
{ {
QPixmap pix ; QPixmap pix ;
if(rsReputations->isIdentityBanned(details.mId)) if(rsIdentity->isBanned(details.mId))
{ {
icons.clear() ; icons.clear() ;
icons.push_back(QIcon(IMAGE_BANNED)) ; icons.push_back(QIcon(IMAGE_BANNED)) ;

View File

@ -25,7 +25,6 @@
#include "GxsIdTreeWidgetItem.h" #include "GxsIdTreeWidgetItem.h"
#include "GxsIdDetails.h" #include "GxsIdDetails.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "retroshare/rsreputations.h"
#define BANNED_IMAGE ":/icons/yellow_biohazard64.png" #define BANNED_IMAGE ":/icons/yellow_biohazard64.png"
@ -117,14 +116,14 @@ void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column, bool retryWhenF
void GxsIdRSTreeWidgetItem::updateBannedState() void GxsIdRSTreeWidgetItem::updateBannedState()
{ {
if(mBannedState != rsReputations->isIdentityBanned(mId)) if(mBannedState != rsIdentity->isBanned(mId))
forceUpdate() ; forceUpdate() ;
} }
void GxsIdRSTreeWidgetItem::forceUpdate() void GxsIdRSTreeWidgetItem::forceUpdate()
{ {
mIdFound = false; mIdFound = false;
mBannedState = rsReputations->isIdentityBanned(mId) ; mBannedState = rsIdentity->isBanned(mId) ;
startProcess(); startProcess();
} }
@ -170,7 +169,7 @@ QVariant GxsIdRSTreeWidgetItem::data(int column, int role) const
if(mId.isNull()) if(mId.isNull())
return RSTreeWidgetItem::data(column, role); return RSTreeWidgetItem::data(column, role);
else if(rsReputations->isIdentityBanned(mId)) else if(rsIdentity->isBanned(mId))
pix = QImage(BANNED_IMAGE) ; pix = QImage(BANNED_IMAGE) ;
else if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG")) else if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG"))
pix = GxsIdDetails::makeDefaultIcon(mId); pix = GxsIdDetails::makeDefaultIcon(mId);

View File

@ -212,7 +212,7 @@ void CreateGxsForumMsg::loadFormInformation()
//std::cerr << "CreateGxsForumMsg::loadMsgInformation() using signFlags=" << std::hex << mForumMeta.mSignFlags << std::dec << std::endl; //std::cerr << "CreateGxsForumMsg::loadMsgInformation() using signFlags=" << std::hex << mForumMeta.mSignFlags << std::dec << std::endl;
if(mForumMeta.mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) if( (mForumMeta.mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG) || (mForumMeta.mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN))
ui.idChooser->setFlags(IDCHOOSER_ID_REQUIRED | IDCHOOSER_NON_ANONYMOUS) ; ui.idChooser->setFlags(IDCHOOSER_ID_REQUIRED | IDCHOOSER_NON_ANONYMOUS) ;
else else
ui.idChooser->setFlags(IDCHOOSER_ID_REQUIRED) ; ui.idChooser->setFlags(IDCHOOSER_ID_REQUIRED) ;

View File

@ -44,7 +44,6 @@
#include <retroshare/rsgxsforums.h> #include <retroshare/rsgxsforums.h>
#include <retroshare/rsgrouter.h> #include <retroshare/rsgrouter.h>
#include <retroshare/rsreputations.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
// These should be in retroshare/ folder. // These should be in retroshare/ folder.
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
@ -791,7 +790,8 @@ void GxsForumThreadWidget::insertGroupData()
tw->ui->forumName->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); tw->ui->forumName->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str()));
QString anti_spam_features1 ; QString anti_spam_features1 ;
if(IS_GROUP_PGP_AUTHED(tw->mSignFlags)) anti_spam_features1 = tr("Anonymous IDs reputation threshold set to 0.4"); if(IS_GROUP_PGP_KNOWN_AUTHED(tw->mSignFlags)) anti_spam_features1 = tr("Anonymous/unknown node IDs reputation threshold set to 0.4");
else if(IS_GROUP_PGP_AUTHED(tw->mSignFlags)) anti_spam_features1 = tr("Anonymous IDs reputation threshold set to 0.4");
QString anti_spam_features2 ; QString anti_spam_features2 ;
if(IS_GROUP_MESSAGE_TRACKING(tw->mSignFlags)) anti_spam_features2 = tr("Message routing info kept for 10 days"); if(IS_GROUP_MESSAGE_TRACKING(tw->mSignFlags)) anti_spam_features2 = tr("Message routing info kept for 10 days");
@ -817,9 +817,20 @@ void GxsForumThreadWidget::insertGroupData()
distrib_string = tr("Restricted to members of circle ")+QString::fromStdString(group.mMeta.mCircleId.toStdString()) ; distrib_string = tr("Restricted to members of circle ")+QString::fromStdString(group.mMeta.mCircleId.toStdString()) ;
} }
break ; break ;
case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY: distrib_string = tr("Your eyes only"); case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY:
break ; {
case GXS_CIRCLE_TYPE_LOCAL: distrib_string = tr("You and your friend nodes"); distrib_string = tr("Only friends nodes in group ") ;
RsGroupInfo ginfo ;
rsPeers->getGroupInfo(RsNodeGroupId(group.mMeta.mInternalCircle),ginfo) ;
QString desc;
GroupChooser::makeNodeGroupDesc(ginfo, desc);
distrib_string += desc ;
}
break ;
case GXS_CIRCLE_TYPE_LOCAL: distrib_string = tr("Your eyes only"); // this is not yet supported. If you see this, it is a bug!
break ; break ;
default: default:
std::cerr << "(EE) badly initialised group distribution ID = " << group.mMeta.mCircleType << std::endl; std::cerr << "(EE) badly initialised group distribution ID = " << group.mMeta.mCircleType << std::endl;
@ -985,7 +996,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
// is flagged with a bad reputation // is flagged with a bad reputation
bool redacted = rsReputations->isIdentityBanned(msg.mMeta.mAuthorId) ; bool redacted = rsIdentity->isBanned(msg.mMeta.mAuthorId) ;
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_ALL || (redacted?(GxsIdDetails::ICON_TYPE_REDACTED):0)); GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_ALL || (redacted?(GxsIdDetails::ICON_TYPE_REDACTED):0));
item->moveToThread(ui->threadTreeWidget->thread()); item->moveToThread(ui->threadTreeWidget->thread());
@ -1408,7 +1419,7 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
return; return;
} }
bool redacted = rsReputations->isIdentityBanned(msg.mMeta.mAuthorId) ; bool redacted = rsIdentity->isBanned(msg.mMeta.mAuthorId) ;
mStateHelper->setActive(mTokenTypeMessageData, true); mStateHelper->setActive(mTokenTypeMessageData, true);

View File

@ -887,7 +887,7 @@ void MessageComposer::calculateTitle()
setWindowTitle(tr("Compose") + ": " + misc::removeNewLine(ui.titleEdit->text())); setWindowTitle(tr("Compose") + ": " + misc::removeNewLine(ui.titleEdit->text()));
} }
static void calculateGroupsOfSslIds(const std::list<RsGroupInfo> &existingGroupInfos, std::list<RsPeerId> &checkSslIds, std::list<std::string> &checkGroupIds) static void calculateGroupsOfSslIds(const std::list<RsGroupInfo> &existingGroupInfos, std::list<RsPeerId> &checkSslIds, std::list<RsNodeGroupId> &checkGroupIds)
{ {
checkGroupIds.clear(); checkGroupIds.clear();
@ -1342,7 +1342,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
{ {
case PEER_TYPE_GROUP: { case PEER_TYPE_GROUP: {
RsGroupInfo groupInfo; RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(id, groupInfo) == false) { if (rsPeers->getGroupInfo(RsNodeGroupId(id), groupInfo) == false) {
// group not found // group not found
continue; continue;
} }
@ -1587,7 +1587,7 @@ void MessageComposer::setRecipientToRow(int row, enumType type, destinationType
icon = QIcon(IMAGE_GROUP16); icon = QIcon(IMAGE_GROUP16);
RsGroupInfo groupInfo; RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(id, groupInfo)) { if (rsPeers->getGroupInfo(RsNodeGroupId(id), groupInfo)) {
name = GroupDefs::name(groupInfo); name = GroupDefs::name(groupInfo);
} else { } else {
name = tr("Unknown"); name = tr("Unknown");
@ -1771,7 +1771,7 @@ 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, PEER_TYPE_GROUP, groupIt->id); setRecipientToRow(row, type, PEER_TYPE_GROUP, groupIt->id.toStdString());
return; return;
} }
} }

View File

@ -14,6 +14,13 @@ DEFINES += TARGET=\\\"$TARGET\\\"
#CONFIG += debug #CONFIG += debug
#DEFINES *= SIGFPE_DEBUG #DEFINES *= SIGFPE_DEBUG
profiling {
QMAKE_CXXFLAGS -= -fomit-frame-pointer
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
QMAKE_LFLAGS *= -pg
}
#QMAKE_CFLAGS += -fmudflap #QMAKE_CFLAGS += -fmudflap
#LIBS *= /usr/lib/gcc/x86_64-linux-gnu/4.4/libmudflap.a /usr/lib/gcc/x86_64-linux-gnu/4.4/libmudflapth.a #LIBS *= /usr/lib/gcc/x86_64-linux-gnu/4.4/libmudflap.a /usr/lib/gcc/x86_64-linux-gnu/4.4/libmudflapth.a
@ -69,7 +76,7 @@ linux-* {
PKGCONFIG *= x11 xscrnsaver PKGCONFIG *= x11 xscrnsaver
LIBS *= -rdynamic LIBS *= -rdynamic
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
DEFINES *= HAS_GNOME_KEYRING DEFINES *= HAS_GNOME_KEYRING
} }
@ -466,6 +473,7 @@ HEADERS += rshare.h \
gui/common/AvatarDefs.h \ gui/common/AvatarDefs.h \
gui/common/GroupFlagsWidget.h \ gui/common/GroupFlagsWidget.h \
gui/common/GroupSelectionBox.h \ gui/common/GroupSelectionBox.h \
gui/common/GroupChooser.h \
gui/common/StatusDefs.h \ gui/common/StatusDefs.h \
gui/common/TagDefs.h \ gui/common/TagDefs.h \
gui/common/GroupDefs.h \ gui/common/GroupDefs.h \
@ -775,6 +783,7 @@ SOURCES += main.cpp \
gui/common/AvatarDialog.cpp \ gui/common/AvatarDialog.cpp \
gui/common/GroupFlagsWidget.cpp \ gui/common/GroupFlagsWidget.cpp \
gui/common/GroupSelectionBox.cpp \ gui/common/GroupSelectionBox.cpp \
gui/common/GroupChooser.cpp \
gui/common/StatusDefs.cpp \ gui/common/StatusDefs.cpp \
gui/common/TagDefs.cpp \ gui/common/TagDefs.cpp \
gui/common/GroupDefs.cpp \ gui/common/GroupDefs.cpp \