Merge pull request #434 from csoler/v0.6-LocalCircles

V0.6 local circles
This commit is contained in:
Cyril Soler 2016-07-12 22:49:21 -04:00 committed by GitHub
commit 8ccfee20bb
47 changed files with 2158 additions and 1869 deletions

3
.gitignore vendored
View File

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

View File

@ -431,7 +431,7 @@ int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<D
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;
bool ok = false;
@ -1668,7 +1668,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, FileSear
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() ;
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();
/* 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 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) ;
// 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;

View File

@ -25,6 +25,7 @@
#include "ft/ftdbase.h"
#include "util/rsdir.h"
#include "retroshare/rspeers.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)
{
RsFileConfigItem *fi = new RsFileConfigItem();
RsFileConfigItem *fi = new RsFileConfigItem();
fi->file.path = (*it).filename ;
fi->file.name = (*it).virtualname ;
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);
}
@ -332,25 +335,53 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
continue ;
}
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
if (!fi)
{
delete (*it);
continue;
}
// 07/05/2016 - This ensures backward compatibility. Can be removed in a few weeks.
RsFileConfigItem_deprecated *fib = dynamic_cast<RsFileConfigItem_deprecated *>(*it);
if (fib)
{
/* 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 ;
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
info.virtualname = fi->file.name;
info.parent_groups = fi->parent_groups;
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::list<std::string>::const_iterator itt(fib->parent_groups.begin());itt!=fib->parent_groups.end();++itt)
{
RsGroupInfo ginfo;
if(rsPeers->getGroupInfoByName(*itt,ginfo) )
{
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 ;
}

View File

@ -395,7 +395,7 @@ bool ftExtraList::saveList(bool &cleanup, std::list<RsItem *>& sList)
std::map<RsFileHash, FileDetails>::const_iterator 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.name = (it->second).info.fname;
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)
{
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
RsFileConfigItem_deprecated *fi = dynamic_cast<RsFileConfigItem_deprecated *>(*it);
if (!fi)
{
delete (*it);

View File

@ -206,6 +206,7 @@
#include "retroshare/rsconfig.h"
#include "retroshare/rsgxsflags.h"
#include "retroshare/rsgxscircles.h"
#include "retroshare/rspeers.h"
#include "pgp/pgpauxutils.h"
#include "util/rsdir.h"
#include "util/rsmemory.h"
@ -265,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)
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
// warning. Numbers should be SERVICE IDS (see serialiser/rsserviceids.h. E.g. 0x0215 for forums)
@ -4092,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
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendGrpId()"<< std::endl;
@ -4123,101 +4124,21 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
#endif
should_encrypt = 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)
{
#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
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 = 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;
@ -4227,121 +4148,51 @@ bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxs
{
#ifdef NXS_NET_DEBUG_4
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) << "RsGxsNetService::checkCanRecvMsgFromPeer()";
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " peer Id = " << sslId << ", grpId=" << grpMeta.mGroupId <<std::endl;
#endif
// first do the simple checks
uint8_t circleType = grpMeta.mCircleType;
should_encrypt_id.clear() ;
// first do the simple checks
uint8_t circleType = grpMeta.mCircleType;
should_encrypt_id.clear() ;
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
{
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
{
#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
return false;
}
return false;
}
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{
#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
return true;
}
return true;
}
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
{
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
{
#ifdef NXS_NET_DEBUG_4
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;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs will be encrypted." << std::endl;
#endif
should_encrypt_id = grpMeta.mCircleId ;
return true ;
}
// should just be shared. ? no - this happens for
// Circle Groups which lose their CircleIds.
// return true;
}
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
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))
{
#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;
return true;
}
bool RsGxsNetService::locked_CanReceiveUpdate(RsNxsSyncMsgReqItem *item,bool& grp_is_known)
@ -4618,17 +4469,17 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
{
#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
return false;
return false;
}
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{
#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
return true;
return true;
}
const RsGxsCircleId& circleId = grpMeta.mCircleId;
@ -4636,119 +4487,116 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
{
#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
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.
// 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.
// 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
// 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 put in vetting list will be dealt with later
// 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
std::vector<MsgIdCircleVet> toVet;
std::vector<MsgIdCircleVet> toVet;
for(uint32_t i=0;i<msgMetas.size();)
if( msgMetas[i]->mAuthorId.isNull() ) // keep the message in this case
++i ;
else
{
if(mCircles->isLoaded(circleId) && mCircles->isRecipient(circleId, grpMeta.mGroupId, msgMetas[i]->mAuthorId))
{
++i ;
continue ;
}
for(uint32_t i=0;i<msgMetas.size();)
if( msgMetas[i]->mAuthorId.isNull() ) // keep the message in this case
++i ;
else
{
if(mCircles->isLoaded(circleId) && mCircles->isRecipient(circleId, grpMeta.mGroupId, msgMetas[i]->mAuthorId))
{
++i ;
continue ;
}
MsgIdCircleVet mic(msgMetas[i]->mMsgId, msgMetas[i]->mAuthorId);
toVet.push_back(mic);
MsgIdCircleVet mic(msgMetas[i]->mMsgId, msgMetas[i]->mAuthorId);
toVet.push_back(mic);
#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
delete msgMetas[i] ;
msgMetas[i] = msgMetas[msgMetas.size()-1] ;
msgMetas.pop_back() ;
}
delete msgMetas[i] ;
msgMetas[i] = msgMetas[msgMetas.size()-1] ;
msgMetas.pop_back() ;
}
#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
if(!toVet.empty())
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId));
if(!toVet.empty())
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
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: YOUR EYES ONLY" << std::endl;
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;
bool res = checkPermissionsForFriendGroup(sslId,grpMeta) ;
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Group internal circle: " << internalCircleId << 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;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Final answer: " << res << std::endl;
#endif
return res ;
}
std::vector<MsgIdCircleVet> toVet;
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;
return false;
}
/** 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 */)
{

View File

@ -354,6 +354,15 @@ private:
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);
/*!
* \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);
void locked_createTransactionFromPending(MsgRespPending* grpPend);

View File

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

View File

@ -132,7 +132,7 @@ class peerConnectState
};
class p3tunnel;
class RsPeerGroupItem;
class RsPeerGroupItem_deprecated;
class RsGroupInfo;
class p3PeerMgr;
@ -339,9 +339,6 @@ private:
std::map<RsPeerId, peerConnectState> mFriendList;
std::map<RsPeerId, peerConnectState> mOthersList;
std::list<RsPeerGroupItem *> groupList;
uint32_t lastGroupId;
/* relatively static list of banned ip addresses */
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_dht = RS_VS_DHT_FULL;
lastGroupId = 1;
// setup default ProxyServerAddress.
// Tor
sockaddr_storage_clear(mProxyServerAddressTor);
@ -1071,7 +1069,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id)
std::list<RsPgpId> ids ;
ids.push_back(id) ;
assignPeersToGroup("", ids, false);
assignPeersToGroup(RsNodeGroupId(), ids, false);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -1145,7 +1143,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPeerId &id, bool removePgpId)
/* remove id from all groups */
assignPeersToGroup("", pgpid_toRemove, false);
assignPeersToGroup(RsNodeGroupId(), pgpid_toRemove, false);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -1915,7 +1913,7 @@ RsSerialiser *p3PeerMgrIMPL::setupSerialiser()
bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
{
/* create a list of current peers */
cleanup = false;
cleanup = true;
bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
/* gather these information before mPeerMtx is locked! */
@ -1971,7 +1969,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
#endif
saveData.push_back(item);
saveCleanupList.push_back(item);
/* iterate through all friends and save */
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;
saveData.push_back(item);
saveCleanupList.push_back(item);
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::saveList() Peer Config Item:" << std::endl;
item->print(std::cerr, 10);
@ -2024,7 +2020,6 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
}
saveData.push_back(sitem) ;
saveCleanupList.push_back(sitem);
// 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) ;
saveData.push_back(vitem);
saveCleanupList.push_back(vitem);
/* save groups */
std::list<RsPeerGroupItem *>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
saveData.push_back(*groupIt); // no delete
}
for ( std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
{
RsNodeGroupItem *itm = new RsNodeGroupItem(groupIt->second);
saveData.push_back(itm) ;
}
return true;
}
@ -2294,7 +2289,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
continue;
}
RsPeerGroupItem *gitem = dynamic_cast<RsPeerGroupItem *>(*it) ;
RsPeerGroupItem_deprecated *gitem = dynamic_cast<RsPeerGroupItem_deprecated *>(*it) ;
if (gitem)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2304,20 +2300,54 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
gitem->print(std::cerr, 10);
std::cerr << std::endl;
#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) {
/* calculate group id */
uint32_t groupId = atoi(gitem->id.c_str());
if (groupId > lastGroupId) {
lastGroupId = groupId;
}
}
// Ensure backward compatibility when loading the group in old format. The id must matchthe standard default id.
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) ;
if(pblitem)
@ -2363,42 +2393,19 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
/* Standard groups */
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 };
bool foundStandardGroup[standardGroupCount] = { false, false, false, false, false };
const RsNodeGroupId standardGroupIds [standardGroupCount] = { RS_GROUP_ID_FRIENDS, RS_GROUP_ID_FAMILY, RS_GROUP_ID_COWORKERS, RS_GROUP_ID_OTHERS, RS_GROUP_ID_FAVORITES };
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 (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
int i;
for (i = 0; i < standardGroupCount; ++i) {
if ((*groupIt)->id == standardGroup[i]) {
foundStandardGroup[i] = true;
break;
}
}
for(uint32_t k=0;k<standardGroupCount;++k)
if(groupList.find(standardGroupIds[k]) == groupList.end())
{
RsGroupInfo info ;
info.id = standardGroupIds[k];
info.name = standardGroupNames[k];
info.flag |= RS_GROUP_FLAG_STANDARD;
if (i >= standardGroupCount) {
/* 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++);
}
groupList[info.id] = info;
}
}
/* 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!
@ -2478,19 +2485,16 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
RsPeerGroupItem *groupItem = new RsPeerGroupItem;
groupItem->set(groupInfo);
do { groupInfo.id = RsNodeGroupId::random(); } while(groupList.find(groupInfo.id) != groupList.end()) ;
rs_sprintf(groupItem->id, "%lu", ++lastGroupId);
RsGroupInfo groupItem(groupInfo) ;
// 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);
groupInfo.id = groupItem->id;
std::cerr << "(II) Added new group with ID " << groupInfo.id << ", name=\"" << groupInfo.name << "\"" << std::endl;
}
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD);
@ -2500,35 +2504,39 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
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;
}
bool changed = false;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
break;
}
}
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
if (groupIt != groupList.end()) {
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
// can't edit standard groups
} else {
changed = true;
(*groupIt)->set(groupInfo);
}
}
}
if(it == groupList.end())
{
std::cerr << "(EE) cannot find local node group with ID " << groupId << std::endl;
return false ;
}
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);
IndicateConfigChanged();
@ -2537,31 +2545,35 @@ bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo
return changed;
}
bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
bool p3PeerMgrIMPL::removeGroup(const RsNodeGroupId& groupId)
{
if (groupId.empty()) {
return false;
}
bool changed = false;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
break;
}
}
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
if (groupIt != groupList.end()) {
if ((*groupIt)->flag & RS_GROUP_FLAG_STANDARD) {
if (it != groupList.end()) {
if (it->second.flag & RS_GROUP_FLAG_STANDARD)
{
// 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;
delete(*groupIt);
groupList.erase(groupIt);
groupList.erase(it);
}
}
}
@ -2575,82 +2587,83 @@ bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
return changed;
}
bool p3PeerMgrIMPL::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
bool p3PeerMgrIMPL::getGroupInfoByName(const std::string& groupName, RsGroupInfo &groupInfo)
{
if (groupId.empty()) {
return false;
}
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
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 *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if ((*groupIt)->id == groupId) {
(*groupIt)->get(groupInfo);
std::map<RsNodeGroupId,RsGroupInfo>::iterator it = groupList.find(groupId) ;
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 *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
RsGroupInfo groupInfo;
(*groupIt)->get(groupInfo);
groupInfoList.push_back(groupInfo);
}
for (std::map<RsNodeGroupId,RsGroupInfo> ::const_iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
groupInfoList.push_back(groupIt->second);
return true;
}
// groupId == "" && 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;
}
// groupId.isNull() && assign == false -> remove from all groups
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;
}
bool changed = false;
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::list<RsPeerGroupItem*>::iterator groupIt;
for (groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) {
if (groupId.empty() || (*groupIt)->id == groupId) {
RsPeerGroupItem *groupItem = *groupIt;
for (std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
if (groupId.isNull() || groupIt->first == groupId)
{
RsGroupInfo& groupItem = groupIt->second;
std::list<RsPgpId>::const_iterator 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);
if (assign) {
if (peerIt1 == groupItem->pgpList.ids.end()) {
groupItem->pgpList.ids.insert(*peerIt);
changed = true;
}
} else {
if (peerIt1 != groupItem->pgpList.ids.end()) {
groupItem->pgpList.ids.erase(peerIt1);
changed = true;
}
for (std::list<RsPgpId>::const_iterator peerIt = peerIds.begin(); peerIt != peerIds.end(); ++peerIt)
{
std::set<RsPgpId>::iterator peerIt1 = groupItem.peerIds.find(*peerIt);
if (assign)
{
groupItem.peerIds.insert(*peerIt);
changed = true;
}
else
{
groupItem.peerIds.erase(*peerIt);
changed = true;
}
}
if (groupId.empty() == false) {
if (!groupId.isNull())
break;
}
}
}
}
if (changed) {

View File

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

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) ;
}
// 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()
{
t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> id ;
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i)
id.bytes[i] = RSRandom::random_u32() & 0xff ;
RSRandom::random_bytes(id.bytes,ID_SIZE_IN_BYTES) ;
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_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_NODE_GROUP_ID_TYPE = 0x0012 ;
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 ;
@ -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< 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< 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 */
#define RS_GROUP_ID_FRIENDS "Friends"
#define RS_GROUP_ID_FAMILY "Family"
#define RS_GROUP_ID_COWORKERS "Co-Workers"
#define RS_GROUP_ID_OTHERS "Other Contacts"
#define RS_GROUP_ID_FAVORITES "Favorites"
static const RsNodeGroupId RS_GROUP_ID_FRIENDS ("00000000000000000000000000000001");
static const RsNodeGroupId RS_GROUP_ID_FAMILY ("00000000000000000000000000000002");
static const RsNodeGroupId RS_GROUP_ID_COWORKERS ("00000000000000000000000000000003");
static const RsNodeGroupId RS_GROUP_ID_OTHERS ("00000000000000000000000000000004");
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;
@ -295,7 +301,7 @@ class RsGroupInfo
public:
RsGroupInfo();
std::string id;
RsNodeGroupId id;
std::string name;
uint32_t flag;
@ -399,14 +405,15 @@ public:
virtual bool trustGPGCertificate(const RsPgpId &gpg_id, uint32_t trustlvl) = 0;
/* Group Stuff */
virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool removeGroup(const std::string &groupId) = 0;
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
virtual bool addGroup(RsGroupInfo& groupInfo) = 0;
virtual bool editGroup(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 0;
virtual bool removeGroup(const RsNodeGroupId& groupId) = 0;
virtual bool getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo& groupInfo) = 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
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId& peerId, bool assign) = 0;
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
virtual bool assignPeerToGroup(const RsNodeGroupId& groupId, const RsPgpId& peerId, bool assign) = 0;
virtual bool assignPeersToGroup(const RsNodeGroupId& groupId, const std::list<RsPgpId>& peerIds, bool assign) = 0;
/* Group sharing permission */
@ -421,7 +428,7 @@ public:
//
virtual FileSearchFlags computePeerPermissionFlags(
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 */

View File

@ -211,7 +211,7 @@ class FileInfo
DwlSpeed priority ;
time_t lastTS;
std::list<std::string> parent_groups ;
std::list<RsNodeGroupId> parent_groups ;
};
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
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

View File

@ -1280,7 +1280,7 @@ bool p3Peers::addGroup(RsGroupInfo &groupInfo)
return res ;
}
bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
bool p3Peers::editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::editGroup()" << std::endl;
@ -1292,7 +1292,7 @@ bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
return res ;
}
bool p3Peers::removeGroup(const std::string &groupId)
bool p3Peers::removeGroup(const RsNodeGroupId &groupId)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::removeGroup()" << std::endl;
@ -1303,7 +1303,15 @@ bool p3Peers::removeGroup(const std::string &groupId)
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
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
@ -1321,7 +1329,7 @@ bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &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;
peerIds.push_back(peerId);
@ -1329,7 +1337,7 @@ bool p3Peers::assignPeerToGroup(const std::string &groupId, const RsPgpId& peerI
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
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,
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.
//
@ -1354,7 +1362,7 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
bool found = false ;
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 ;
if(!getGroupInfo(*it,info))

View File

@ -124,14 +124,15 @@ public:
/* Group Stuff */
virtual bool addGroup(RsGroupInfo &groupInfo);
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const std::string &groupId);
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
virtual bool assignPeerToGroup(const std::string &groupId, const RsPgpId &peerId, bool assign);
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<RsPgpId>& peerIds, bool assign);
virtual bool editGroup(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const RsNodeGroupId &groupId);
virtual bool getGroupInfo(const RsNodeGroupId &groupId, RsGroupInfo &groupInfo);
virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo& groupInfo);
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
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

View File

@ -43,34 +43,34 @@
uint32_t RsFileConfigSerialiser::size(RsItem *i)
{
RsFileTransfer *rft;
RsFileConfigItem *rfi;
RsFileConfigItem *rfj;
if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i)))
{
return sizeTransfer(rft);
}
if (NULL != (rfi = dynamic_cast<RsFileConfigItem *>(i)))
{
return sizeFileItem(rfi);
}
return 0;
if (NULL != (rfj = dynamic_cast<RsFileConfigItem *>(i)))
{
return sizeFileItem(rfj);
}
return 0;
}
/* serialise the data to the buffer */
bool RsFileConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
RsFileTransfer *rft;
RsFileConfigItem *rfi;
RsFileConfigItem *rfj;
if (NULL != (rft = dynamic_cast<RsFileTransfer *>(i)))
{
return serialiseTransfer(rft, data, pktsize);
}
if (NULL != (rfi = dynamic_cast<RsFileConfigItem *>(i)))
{
return serialiseFileItem(rfi, data, pktsize);
}
return false;
if (NULL != (rfj = dynamic_cast<RsFileConfigItem*>(i)))
{
return serialiseFileItem(rfj, data, pktsize);
}
return false;
}
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:
return deserialiseTransfer(data, pktsize);
break;
case RS_PKT_SUBTYPE_FILE_ITEM:
return deserialiseFileItem(data, pktsize);
case RS_PKT_SUBTYPE_FILE_ITEM_deprecated:
return deserialiseFileItem_deprecated(data, pktsize);
break;
default:
case RS_PKT_SUBTYPE_FILE_ITEM:
return deserialiseFileItem(data, pktsize);
break;
default:
return NULL;
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();
flags = 0;
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);
uint16_t int_Indent = indent + 2;
@ -188,6 +191,22 @@ std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent)
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 += 4; // flags
for(std::list<std::string>::const_iterator it(item->parent_groups.begin());it!=item->parent_groups.end();++it) // parent groups
s += GetTlvStringSize(*it);
s += item->parent_groups.TlvSize() ;
return s;
}
@ -382,9 +400,7 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
/* add mandatory parts first */
ok &= item->file.SetTlv(data, tlvsize, &offset);
ok &= setRawUInt32(data, tlvsize, &offset, item->flags);
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);
ok &= item->parent_groups.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
@ -397,6 +413,66 @@ bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void
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)
{
/* get the type and size */
@ -409,7 +485,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(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 */
}
@ -423,7 +499,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
bool ok = true;
/* ready to load */
RsFileConfigItem *item = new RsFileConfigItem();
RsFileConfigItem *item = new RsFileConfigItem();
item->clear();
/* skip the header */
@ -432,15 +508,7 @@ RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32
/* 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 ;
}
ok &= item->parent_groups.GetTlv(data, rssize, &offset) ;
if (offset != rssize)
{
@ -682,7 +750,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{
RsPeerStunItem *psi;
RsPeerNetItem *pni;
RsPeerGroupItem *pgi;
RsNodeGroupItem *pgi;
RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem;
@ -694,7 +762,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{
return sizeStun(psi);
}
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem *>(i)))
else if (NULL != (pgi = dynamic_cast<RsNodeGroupItem*>(i)))
{
return sizeGroup(pgi);
}
@ -715,7 +783,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{
RsPeerNetItem *pni;
RsPeerStunItem *psi;
RsPeerGroupItem *pgi;
RsNodeGroupItem *pgi;
RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem;
@ -727,7 +795,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{
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);
}
@ -764,9 +832,11 @@ RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
return deserialiseNet(data, pktsize);
case RS_PKT_SUBTYPE_PEER_STUN:
return deserialiseStun(data, pktsize);
case RS_PKT_SUBTYPE_PEER_GROUP:
return deserialiseGroup(data, pktsize);
case RS_PKT_SUBTYPE_PEER_PERMISSIONS:
case RS_PKT_SUBTYPE_PEER_GROUP_deprecated:
return deserialiseGroup_deprecated(data, pktsize);
case RS_PKT_SUBTYPE_NODE_GROUP:
return deserialiseGroup(data, pktsize);
case RS_PKT_SUBTYPE_PEER_PERMISSIONS:
return deserialisePermissions(data, pktsize);
case RS_PKT_SUBTYPE_PEER_BANDLIMITS:
return deserialisePeerBandwidthLimits(data, pktsize);
@ -1312,16 +1382,64 @@ RsPeerStunItem *RsPeerConfigSerialiser::deserialiseStun(void *data, uint32_t *si
}
/*************************************************************************/
RsPeerGroupItem::RsPeerGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP)
RsNodeGroupItem::RsNodeGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_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();
name.clear();
@ -1329,7 +1447,7 @@ void RsPeerGroupItem::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);
uint16_t int_Indent = indent + 2;
@ -1353,38 +1471,67 @@ std::ostream &RsPeerGroupItem::print(std::ostream &out, uint16_t indent)
return out;
}
/* set data from RsGroupInfo to RsPeerGroupItem */
void RsPeerGroupItem::set(RsGroupInfo &groupInfo)
RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup_deprecated(void *data, uint32_t *size)
{
id = groupInfo.id;
name = groupInfo.name;
flag = groupInfo.flag;
pgpList.ids = groupInfo.peerIds;
}
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
/* get data from RsGroupInfo to RsPeerGroupItem */
void RsPeerGroupItem::get(RsGroupInfo &groupInfo)
{
groupInfo.id = id;
groupInfo.name = name;
groupInfo.flag = flag;
groupInfo.peerIds = pgpList.ids;
}
uint32_t offset = 0;
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 */
s += 4; /* version */
s += GetTlvStringSize(i->id);
s += RsNodeGroupId::serial_size();
s += GetTlvStringSize(i->name);
s += 4; /* flag */
s += i->pgpList.TlvSize();
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 offset = 0;
@ -1410,7 +1557,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
/* add mandatory parts first */
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 &= setRawUInt32(data, tlvsize, &offset, item->flag);
ok &= item->pgpList.SetTlv(data, tlvsize, &offset);
@ -1426,7 +1573,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem *item, void *data, u
return ok;
}
RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
RsNodeGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
@ -1437,7 +1584,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(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 */
}
@ -1450,7 +1597,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
bool ok = true;
RsPeerGroupItem *item = new RsPeerGroupItem();
RsNodeGroupItem *item = new RsNodeGroupItem();
item->clear();
/* skip the header */
@ -1459,7 +1606,7 @@ RsPeerGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *
/* 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 &= item->id.deserialise(data, rssize, offset);
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);

View File

@ -50,15 +50,17 @@ const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
/* PEER CONFIG SUBTYPES */
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_GROUP = 0x04;
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_STUN = 0x02;
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
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_BANDLIMITS = 0x06;
const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07;
/* FILE CONFIG SUBTYPES */
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_TRANSFER = 0x01;
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 ;
};
class RsPeerGroupItem : public RsItem
class RsPeerGroupItem_deprecated : public RsItem
{
public:
RsPeerGroupItem();
virtual ~RsPeerGroupItem();
RsPeerGroupItem_deprecated();
virtual ~RsPeerGroupItem_deprecated();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
@ -156,6 +158,29 @@ public:
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
{
@ -197,9 +222,10 @@ virtual uint32_t sizeStun(RsPeerStunItem *);
virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size);
virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size);
virtual uint32_t sizeGroup(RsPeerGroupItem *);
virtual bool serialiseGroup (RsPeerGroupItem *item, void *data, uint32_t *size);
virtual RsPeerGroupItem * deserialiseGroup(void *data, uint32_t *size);
virtual uint32_t sizeGroup(RsNodeGroupItem *);
virtual bool serialiseGroup (RsNodeGroupItem *item, 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 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;
/* Used by ft / extralist / configdirs / anyone who wants a basic file */
class RsFileConfigItem: public RsItem
class RsFileConfigItem_deprecated: public RsItem
{
public:
RsFileConfigItem()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_FILE_CONFIG,
RS_PKT_SUBTYPE_FILE_ITEM)
{ return; }
virtual ~RsFileConfigItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
public:
RsFileConfigItem_deprecated()
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
RS_PKT_TYPE_FILE_CONFIG,
RS_PKT_SUBTYPE_FILE_ITEM_deprecated)
{}
virtual ~RsFileConfigItem_deprecated() {}
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsTlvFileItem file;
uint32_t flags;
std::list<std::string> parent_groups ;
RsTlvFileItem file;
uint32_t flags;
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
@ -341,9 +383,11 @@ virtual uint32_t sizeTransfer(RsFileTransfer *);
virtual bool serialiseTransfer(RsFileTransfer *item, 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 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_GXSIDSET = 0x1025;
const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026;
const uint16_t TLV_TYPE_NODEGROUPIDSET= 0x1027;
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 ;
};
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
typedef t_RsTlvIdSet<Sha1CheckSum,TLV_TYPE_HASHSET> RsTlvHashSet ;
typedef t_RsTlvIdSet<RsGxsId,TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
typedef t_RsTlvIdSet<RsGxsCircleId,TLV_TYPE_GXSCIRCLEIDSET> RsTlvGxsCircleIdSet ;
typedef t_RsTlvIdSet<RsPeerId, TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
typedef t_RsTlvIdSet<RsPgpId, TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
typedef t_RsTlvIdSet<Sha1CheckSum, TLV_TYPE_HASHSET> RsTlvHashSet ;
typedef t_RsTlvIdSet<RsGxsId, TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
typedef t_RsTlvIdSet<RsGxsCircleId,TLV_TYPE_GXSCIRCLEIDSET> RsTlvGxsCircleIdSet ;
typedef t_RsTlvIdSet<RsNodeGroupId,TLV_TYPE_NODEGROUPIDSET> RsTlvNodeGroupIdSet ;
class RsTlvServiceIdSet: public RsTlvItem
{

View File

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

View File

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

View File

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

View File

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

View File

@ -212,12 +212,12 @@ QString RetroshareDirModel::getFlagsString(FileStorageFlags flags)
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 ;
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))
{
groups_str += GroupDefs::name(group_info) ;

View File

@ -91,7 +91,7 @@ class RetroshareDirModel : public QAbstractItemModel
void treeStyle();
void downloadDirectory(const DirDetails & details, int prefixLen);
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;
// void getAgeIndicatorRec(const DirDetails &details, QString &ret) const;

View File

@ -249,7 +249,7 @@ void ShareManager::updateGroups()
QString group_string;
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)
group_string += ", " ;

View File

@ -116,9 +116,7 @@ FriendList::FriendList(QWidget *parent) :
mShowGroups(true),
mShowState(false),
mHideUnconnected(false),
groupsHasChanged(false),
openGroups(NULL),
openPeers(NULL)
groupsHasChanged(false)
{
ui->setupUi(this);
@ -219,7 +217,17 @@ void FriendList::processSettings(bool load)
int arrayIndex = Settings->beginReadArray("Groups");
for (int index = 0; index < arrayIndex; ++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();
} else {
@ -236,11 +244,11 @@ void FriendList::processSettings(bool load)
// open groups
Settings->beginWriteArray("Groups");
int arrayIndex = 0;
std::set<std::string> expandedPeers;
std::set<RsNodeGroupId> expandedPeers;
getExpandedGroups(expandedPeers);
foreach (std::string groupId, expandedPeers) {
foreach (RsNodeGroupId groupId, expandedPeers) {
Settings->setArrayIndex(arrayIndex++);
Settings->setValue("open", QString::fromStdString(groupId));
Settings->setValue("open", QString::fromStdString(groupId.toStdString()));
}
Settings->endArray();
}
@ -369,7 +377,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu);
}
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()));
addToGroupMenu->addAction(addToGroupAction);
}
@ -378,7 +386,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu);
}
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()));
moveToGroupMenu->addAction(moveToGroupAction);
} else {
@ -456,7 +464,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
void FriendList::createNewGroup()
{
CreateGroup createGrpDialog ("", this);
CreateGroup createGrpDialog (RsNodeGroupId(), this);
createGrpDialog.exec();
}
@ -596,7 +604,7 @@ void FriendList::insertPeers()
if (mShowGroups && groupsHasChanged) {
if (parent) {
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
for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
@ -630,7 +638,7 @@ void FriendList::insertPeers()
}
} else if (groupsHasChanged) {
// remove deleted groups
std::string groupId = getRsId(item);
RsNodeGroupId groupId ( getRsId(item));
for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
if (groupIt->id == groupId) {
break;
@ -671,7 +679,7 @@ void FriendList::insertPeers()
int itemCount = peerTreeWidget->topLevelItemCount();
for (int index = 0; index < itemCount; ++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;
break;
}
@ -690,7 +698,7 @@ void FriendList::insertPeers()
groupItem->setForeground(COLUMN_NAME, QBrush(textColorGroup()));
/* 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);
/* 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);
}
@ -1182,7 +1190,7 @@ void FriendList::insertPeers()
gpgItem->setFont(i, gpgFont);
}
if (openPeers != NULL && openPeers->find(gpgId.toStdString()) != openPeers->end()) {
if (openPeers.find(gpgId.toStdString()) != openPeers.end()) {
gpgItem->setExpanded(true);
}
}
@ -1217,14 +1225,6 @@ void FriendList::insertPeers()
}
groupsHasChanged = false;
if (openGroups != NULL) {
delete(openGroups);
openGroups = NULL;
}
if (openPeers != NULL) {
delete(openPeers);
openPeers = NULL;
}
ui->peerTreeWidget->resort();
}
@ -1232,13 +1232,13 @@ void FriendList::insertPeers()
/**
* 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();
for (int index = 0; index < itemCount; ++index) {
QTreeWidgetItem *item = ui->peerTreeWidget->topLevelItem(index);
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;
@ -1626,7 +1626,7 @@ void FriendList::getSslIdsFromItem(QTreeWidgetItem *item, std::list<RsPeerId> &s
case TYPE_GROUP:
{
RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(peerId, groupInfo)) {
if (rsPeers->getGroupInfo(RsNodeGroupId(peerId), groupInfo)) {
std::set<RsPgpId>::iterator gpgIt;
for (gpgIt = groupInfo.peerIds.begin(); gpgIt != groupInfo.peerIds.end(); ++gpgIt) {
rsPeers->getAssociatedSSLIds(*gpgIt, sslIds);
@ -1649,10 +1649,10 @@ void FriendList::addToGroup()
return;
}
std::string groupId = qobject_cast<QAction*>(sender())->data().toString().toStdString();
RsNodeGroupId groupId ( qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsPgpId gpgId ( getRsId(c));
if (gpgId.isNull() || groupId.empty()) {
if (gpgId.isNull() || groupId.isNull()) {
return;
}
@ -1675,15 +1675,15 @@ void FriendList::moveToGroup()
return;
}
std::string groupId = qobject_cast<QAction*>(sender())->data().toString().toStdString();
RsNodeGroupId groupId ( qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsPgpId gpgId ( getRsId(c));
if (gpgId.isNull() || groupId.empty()) {
if (gpgId.isNull() || groupId.isNull()) {
return;
}
// remove from all groups
rsPeers->assignPeerToGroup("", gpgId, false);
rsPeers->assignPeerToGroup(RsNodeGroupId(), gpgId, false);
// automatically expand the group, the peer is added to
addGroupToExpand(groupId);
@ -1704,7 +1704,7 @@ void FriendList::removeFromGroup()
return;
}
std::string groupId = qobject_cast<QAction*>(sender())->data().toString().toStdString();
RsNodeGroupId groupId ( qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsPgpId gpgId ( getRsId(c));
if (gpgId.isNull()) {
@ -1727,14 +1727,13 @@ void FriendList::editGroup()
return;
}
std::string groupId = getRsId(c);
RsNodeGroupId groupId ( getRsId(c));
if (groupId.empty()) {
return;
if (!groupId.isNull())
{
CreateGroup editGrpDialog(groupId, this);
editGrpDialog.exec();
}
CreateGroup editGrpDialog(groupId, this);
editGrpDialog.exec();
}
void FriendList::removeGroup()
@ -1749,13 +1748,10 @@ void FriendList::removeGroup()
return;
}
std::string groupId = getRsId(c);
RsNodeGroupId groupId ( getRsId(c));
if (groupId.empty()) {
return;
}
rsPeers->removeGroup(groupId);
if (!groupId.isNull())
rsPeers->removeGroup(groupId);
}
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
std::string groupName = group.attribute("name").toStdString();
uint32_t flag = group.attribute("flag").toInt();
std::string groupId;
RsNodeGroupId groupId;
if(getOrCreateGroup(groupName, flag, groupId)) {
// group id found!
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
* @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;
if(!rsPeers->getGroupInfoList(grpList))
@ -2146,14 +2142,14 @@ bool FriendList::getGroupIdByName(const std::string &name, std::string &id)
* @param id groupd id
* @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))
return true;
// -> create one
RsGroupInfo grp;
grp.id = "0"; // RS will generate an ID
grp.id.clear(); // RS will generate an ID
grp.name = name;
grp.flag = flag;
@ -2271,12 +2267,9 @@ void FriendList::filterItems(const QString &text)
* Add a groupId to the openGroups list. These groups
* 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 = new std::set<std::string>;
}
openGroups->insert(groupId);
openGroups.insert(groupId);
}
/**
@ -2285,10 +2278,7 @@ void FriendList::addGroupToExpand(const std::string &groupId)
*/
void FriendList::addPeerToExpand(const std::string &gpgId)
{
if (openPeers == NULL) {
openPeers = new std::set<std::string>;
}
openPeers->insert(gpgId);
openPeers.insert(gpgId);
}
void FriendList::createDisplayMenu()

View File

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

View File

@ -271,9 +271,9 @@ void FriendSelectionWidget::secured_fillList()
selectedIds<RsPeerId,IDTYPE_SSL>(sslIdsSelected,true);
}
std::set<std::string> groupIdsSelected;
std::set<RsNodeGroupId> groupIdsSelected;
if (mShowTypes & SHOW_GROUP) {
selectedIds<std::string,IDTYPE_GROUP>(groupIdsSelected,true);
selectedIds<RsNodeGroupId,IDTYPE_GROUP>(groupIdsSelected,true);
}
std::set<RsPgpId> gpgIdsSelected;
@ -305,6 +305,9 @@ void FriendSelectionWidget::secured_fillList()
else
rsPeers->getGPGAcceptedList(gpgIds);
// add own pgp id to the list
gpgIds.push_back(rsPeers->getGPGOwnId()) ;
std::list<RsPeerId> sslIds;
std::list<RsPeerId>::iterator sslIt;
@ -347,7 +350,7 @@ void FriendSelectionWidget::secured_fillList()
groupItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter);
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);
@ -363,7 +366,7 @@ void FriendSelectionWidget::secured_fillList()
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()) {
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");
}
std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id;
std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id << std::endl;
return "";
}

View File

@ -20,7 +20,7 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent)
void GroupSelectionBox::fillGroups()
{
std::list<std::string> selectedIds;
std::list<RsNodeGroupId> selectedIds;
selectedGroupIds(selectedIds);
clear();
@ -30,7 +30,7 @@ void GroupSelectionBox::fillGroups()
for (std::list<RsGroupInfo>::const_iterator it(groupIds.begin()); it != groupIds.end(); ++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));
addItem(item);
}
@ -38,27 +38,27 @@ void GroupSelectionBox::fillGroups()
setSelectedGroupIds(selectedIds);
}
void GroupSelectionBox::selectedGroupIds(std::list<std::string> &groupIds) const
void GroupSelectionBox::selectedGroupIds(std::list<RsNodeGroupId> &groupIds) const
{
int itemCount = count();
for (int i = 0; i < itemCount; ++i) {
QListWidgetItem *listItem = item(i);
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;
}
}
}
void GroupSelectionBox::setSelectedGroupIds(const std::list<std::string>& groupIds)
void GroupSelectionBox::setSelectedGroupIds(const std::list<RsNodeGroupId>& groupIds)
{
int itemCount = count();
for (int i = 0; i < itemCount; ++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);
} else {
listItem->setCheckState(Qt::Unchecked);

View File

@ -1,4 +1,5 @@
#include <QListWidget>
#include <retroshare/rsids.h>
class GroupSelectionBox: public QListWidget
{
@ -7,10 +8,10 @@ class GroupSelectionBox: public QListWidget
public:
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 setSelectedGroupIds(const std::list<std::string> &groupIds);
void setSelectedGroupIds(const std::list<RsNodeGroupId> &groupIds);
private slots:
void fillGroups();

View File

@ -297,7 +297,7 @@ static void fillGroups(ConnectFriendWizard *wizard, QComboBox *comboBox, const Q
GroupDefs::sortByName(groupInfoList);
comboBox->addItem("", ""); // empty value
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) {
@ -853,7 +853,7 @@ void ConnectFriendWizard::accept()
}
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()))

View File

@ -31,7 +31,7 @@
#include <algorithm>
/** 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)
{
/* Invoke Qt Designer generated QObject setup routine */
@ -45,13 +45,18 @@ CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent)
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 */
ui.friendList->setHeaderText(tr("Friends"));
ui.friendList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui.friendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_GPG);
ui.friendList->start();
if (mGroupId.empty() == false) {
if (!mGroupId.isNull()) {
/* edit exisiting group */
RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(mGroupId, groupInfo)) {
@ -83,7 +88,7 @@ CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent)
std::list<RsGroupInfo>::iterator 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));
}
}
@ -104,9 +109,9 @@ CreateGroup::~CreateGroup()
void CreateGroup::groupNameChanged(QString text)
{
if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) {
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
} else {
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
}
@ -114,14 +119,19 @@ void CreateGroup::changeGroup()
{
RsGroupInfo groupInfo;
if (mGroupId.empty()) {
if (mGroupId.isNull())
{
// add new group
groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData();
if (!rsPeers->addGroup(groupInfo)) {
if (!rsPeers->addGroup(groupInfo))
return;
}
} else {
if (rsPeers->getGroupInfo(mGroupId, groupInfo) == true) {
}
else
{
if (rsPeers->getGroupInfo(mGroupId, groupInfo))
{
if (!mIsStandard) {
groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData();
if (!rsPeers->editGroup(mGroupId, groupInfo)) {

View File

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

View File

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

View File

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

View File

@ -28,11 +28,6 @@
#include <QComboBox>
#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
{
Q_OBJECT
@ -40,12 +35,11 @@ class GxsCircleChooser : public QComboBox
public:
GxsCircleChooser(QWidget *parent = NULL);
void loadCircles(uint32_t chooserFlags, const RsGxsCircleId &defaultId);
void loadCircles(const RsGxsCircleId &defaultId);
bool getChosenCircle(RsGxsCircleId &id);
private:
void loadGxsCircles();
uint32_t mFlags;
RsGxsCircleId mDefaultCircleId;
};

View File

@ -124,8 +124,8 @@ void GxsGroupDialog::init()
/* Setup Reasonable Defaults */
ui.idChooser->loadIds(0,RsGxsId());
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, RsGxsCircleId());
ui.localComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, RsGxsCircleId());
ui.circleComboBox->loadCircles(RsGxsCircleId());
ui.localComboBox->loadGroups(0, RsNodeGroupId());
ui.groupDesc->setPlaceholderText(tr("Set a descriptive description here"));
@ -321,8 +321,6 @@ void GxsGroupDialog::setupDefaults()
ui.typeGroup_3->setEnabled(false);
ui.typeLocal_3->setEnabled(false);
#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()
@ -400,85 +398,97 @@ void GxsGroupDialog::newGroup()
void GxsGroupDialog::updateFromExistingMeta(const QString &description)
{
std::cerr << "void GxsGroupDialog::updateFromExistingMeta()";
std::cerr << std::endl;
std::cerr << "void GxsGroupDialog::updateFromExistingMeta()";
std::cerr << std::endl;
std::cerr << "void GxsGroupDialog::updateFromExistingMeta() mGrpMeta.mCircleType: ";
std::cerr << mGrpMeta.mCircleType << " Internal: " << mGrpMeta.mInternalCircle;
std::cerr << " External: " << mGrpMeta.mCircleId;
std::cerr << std::endl;
std::cerr << "void GxsGroupDialog::updateFromExistingMeta() mGrpMeta.mCircleType: ";
std::cerr << mGrpMeta.mCircleType << " Internal: " << mGrpMeta.mInternalCircle;
std::cerr << " External: " << mGrpMeta.mCircleId;
std::cerr << std::endl;
setupDefaults();
setupVisibility();
setupReadonly();
clearForm();
setGroupSignFlags(mGrpMeta.mSignFlags) ;
setupDefaults();
setupVisibility();
setupReadonly();
clearForm();
setGroupSignFlags(mGrpMeta.mSignFlags) ;
/* setup name */
ui.groupName->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
/* Show Mode */
ui.nameline->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
ui.popline->setText(QString::number( mGrpMeta.mPop)) ;
ui.postsline->setText(QString::number(mGrpMeta.mVisibleMsgCount));
ui.lastpostline->setText(DateTime::formatLongDateTime(mGrpMeta.mLastPost));
/* setup name */
ui.groupName->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
/* Show Mode */
ui.nameline->setText(QString::fromUtf8(mGrpMeta.mGroupName.c_str()));
ui.popline->setText(QString::number( mGrpMeta.mPop)) ;
ui.postsline->setText(QString::number(mGrpMeta.mVisibleMsgCount));
ui.lastpostline->setText(DateTime::formatLongDateTime(mGrpMeta.mLastPost));
ui.authorLabel->setId(mGrpMeta.mAuthorId);
ui.IDline->setText(QString::fromStdString(mGrpMeta.mGroupId.toStdString()));
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]";
ui.IDline->setText(QString::fromStdString(mGrpMeta.mGroupId.toStdString()));
ui.descriptiontextEdit->setPlainText(description);
switch(mGrpMeta.mCircleType)
{
case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY:
ui.typeLocal->setChecked(true);
distribution_string = tr("Your friends only") ;
ui.localComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle);
ui.distributionCircleComboBox->setVisible(true) ;
ui.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle);
break;
case GXS_CIRCLE_TYPE_PUBLIC:
ui.typePublic->setChecked(true);
distribution_string = tr("Public") ;
ui.distributionCircleComboBox->setVisible(false) ;
break;
case GXS_CIRCLE_TYPE_EXTERNAL:
ui.typeGroup->setChecked(true);
distribution_string = tr("Restricted to circle:") ;
ui.distributionCircleComboBox->setVisible(true) ;
ui.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId);
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId);
break;
default:
std::cerr << "CreateCircleDialog::updateCircleGUI() INVALID mCircleType";
std::cerr << std::endl;
break;
}
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)
{
case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY:
{
ui.typeLocal->setChecked(true);
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.idChooser->loadIds(0, mGrpMeta.mAuthorId);
if(!mGrpMeta.mAuthorId.isNull())
ui.idChooser->setChosenId(mGrpMeta.mAuthorId) ;
ui.idChooser->loadIds(0, mGrpMeta.mAuthorId);
updateCircleOptions();
if(!mGrpMeta.mAuthorId.isNull())
ui.idChooser->setChosenId(mGrpMeta.mAuthorId) ;
updateCircleOptions();
}
void GxsGroupDialog::submitGroup()
@ -739,41 +749,42 @@ void GxsGroupDialog::updateCircleOptions()
bool GxsGroupDialog::setCircleParameters(RsGroupMetaData &meta)
{
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear();
meta.mOriginator.clear();
meta.mInternalCircle.clear();
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear();
meta.mOriginator.clear();
meta.mInternalCircle.clear();
if (ui.typePublic->isChecked())
{
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear();
}
else if (ui.typeGroup->isChecked())
{
meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
if (!ui.circleComboBox->getChosenCircle(meta.mCircleId))
{
return false;
}
}
else if (ui.typeLocal->isChecked())
{
meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY;
meta.mCircleId.clear();
meta.mOriginator.clear();
meta.mInternalCircle.clear() ;
if (!ui.localComboBox->getChosenCircle(meta.mInternalCircle))
{
return false;
}
}
else
{
return false;
}
return true;
if (ui.typePublic->isChecked())
{
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear();
}
else if (ui.typeGroup->isChecked())
{
meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
if (!ui.circleComboBox->getChosenCircle(meta.mCircleId))
{
return false;
}
}
else if (ui.typeLocal->isChecked())
{
meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY;
meta.mCircleId.clear();
meta.mOriginator.clear();
meta.mInternalCircle.clear() ;
RsNodeGroupId ngi ;
if (!ui.localComboBox->getChosenGroup(ngi))
return false;
meta.mInternalCircle = RsGxsCircleId(ngi) ;
}
else
return false;
return true;
}
void GxsGroupDialog::cancelDialog()

File diff suppressed because it is too large Load Diff

View File

@ -817,9 +817,20 @@ void GxsForumThreadWidget::insertGroupData()
distrib_string = tr("Restricted to members of circle ")+QString::fromStdString(group.mMeta.mCircleId.toStdString()) ;
}
break ;
case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY: distrib_string = tr("Your eyes only");
break ;
case GXS_CIRCLE_TYPE_LOCAL: distrib_string = tr("You and your friend nodes");
case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY:
{
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 ;
default:
std::cerr << "(EE) badly initialised group distribution ID = " << group.mMeta.mCircleType << std::endl;

View File

@ -887,7 +887,7 @@ void MessageComposer::calculateTitle()
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();
@ -1342,7 +1342,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
{
case PEER_TYPE_GROUP: {
RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(id, groupInfo) == false) {
if (rsPeers->getGroupInfo(RsNodeGroupId(id), groupInfo) == false) {
// group not found
continue;
}
@ -1587,7 +1587,7 @@ void MessageComposer::setRecipientToRow(int row, enumType type, destinationType
icon = QIcon(IMAGE_GROUP16);
RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(id, groupInfo)) {
if (rsPeers->getGroupInfo(RsNodeGroupId(id), groupInfo)) {
name = GroupDefs::name(groupInfo);
} else {
name = tr("Unknown");
@ -1771,7 +1771,7 @@ void MessageComposer::editingRecipientFinished()
QString groupName = GroupDefs::name(*groupIt);
if (text.compare(groupName, Qt::CaseSensitive) == 0) {
// found it
setRecipientToRow(row, type, PEER_TYPE_GROUP, groupIt->id);
setRecipientToRow(row, type, PEER_TYPE_GROUP, groupIt->id.toStdString());
return;
}
}

View File

@ -473,6 +473,7 @@ HEADERS += rshare.h \
gui/common/AvatarDefs.h \
gui/common/GroupFlagsWidget.h \
gui/common/GroupSelectionBox.h \
gui/common/GroupChooser.h \
gui/common/StatusDefs.h \
gui/common/TagDefs.h \
gui/common/GroupDefs.h \
@ -782,6 +783,7 @@ SOURCES += main.cpp \
gui/common/AvatarDialog.cpp \
gui/common/GroupFlagsWidget.cpp \
gui/common/GroupSelectionBox.cpp \
gui/common/GroupChooser.cpp \
gui/common/StatusDefs.cpp \
gui/common/TagDefs.cpp \
gui/common/GroupDefs.cpp \