diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 9c484b79e..2be82a401 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1554,15 +1554,88 @@ void RsGenExchange::notifyChangedGroupStats(const RsGxsGroupId &grpId) mNotifications.push_back(gc); } +bool RsGenExchange::checkGroupMetaConsistency(const RsGroupMetaData& meta) +{ + std::cerr << "Checking group consistency:" << std::endl; + + if(meta.mGroupName.empty()) + { + std::cerr << "(EE) cannot create a group with no name." << std::endl; + return false; + } + + if(meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_PUBLIC && meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_RESTRICTED && meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_PRIVATE) + { + std::cerr << "(EE) mGroupFlags has incorrect value " << std::hex << meta.mGroupFlags << std::dec << ". A value among GXS_SERV::FLAG_PRIVACY_{PUBLIC,RESTRICTED,PRIVATE} is expected." << std::endl; + return false ; + } + + if(meta.mCircleType < GXS_CIRCLE_TYPE_PUBLIC || meta.mCircleType > GXS_CIRCLE_TYPE_YOUR_EYES_ONLY) + { + std::cerr << "(EE) mCircleType has incorrect value " << std::hex << meta.mCircleType << std::dec << ". A single value among GXS_CIRCLE_TYPE_{PUBLIC,EXTERNAL,YOUR_FRIENDS_ONLY,LOCAL,EXT_SELF,YOUR_EYES_ONLY} is expected." << std::endl; + return false ; + } + + if(meta.mCircleType == GXS_CIRCLE_TYPE_EXTERNAL) + { + if(!meta.mInternalCircle.isNull()) + { + std::cerr << "(EE) Group circle type is EXTERNAL, but an internal circle ID " << meta.mInternalCircle << " was supplied. This is an error." << std::endl; + return false ; + } + if(meta.mCircleId.isNull()) + { + std::cerr << "(EE) Group circle type is EXTERNAL, but no external circle ID was supplied. meta.mCircleId is indeed empty. This is an error." << std::endl; + return false ; + } + } + + if(meta.mCircleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) + { + if(!meta.mCircleId.isNull()) + { + std::cerr << "(EE) Group circle type is YOUR_FRIENDS_ONLY, but an external circle ID " << meta.mCircleId << " was supplied. This is an error." << std::endl; + return false ; + } + if(meta.mInternalCircle.isNull()) + { + std::cerr << "(EE) Group circle type is YOUR_FRIENDS_ONLY, but no internal circle ID was supplied. meta.mInternalCircle is indeed empty. This is an error." << std::endl; + return false ; + } + } + + if(meta.mCircleType == GXS_CIRCLE_TYPE_EXT_SELF) + { + if(!meta.mCircleId.isNull()) + { + std::cerr << "(EE) Group circle type is EXT_SELF, but an external circle ID " << meta.mCircleId << " was supplied. This is an error." << std::endl; + return false ; + } + if(!meta.mInternalCircle.isNull()) + { + std::cerr << "(EE) Group circle type is EXT_SELF, but an internal circle ID " << meta.mInternalCircle << " was supplied. This is an error." << std::endl; + return false ; + } + } + + std::cerr << "Group is clean." << std::endl; + return true ; +} + void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem) { + if(!checkGroupMetaConsistency(grpItem->meta)) + { + std::cerr << "(EE) Cannot publish group. Some information was not supplied." << std::endl; + return ; + } RS_STACK_MUTEX(mGenMtx) ; token = mDataAccess->generatePublicToken(); GxsGrpPendingSign ggps(grpItem, token); mGrpsToPublish.push_back(ggps); -#ifdef GEN_EXCH_DEBUG +#ifdef GEN_EXCH_DEBUG std::cerr << "RsGenExchange::publishGroup() token: " << token; std::cerr << std::endl; #endif @@ -1572,6 +1645,12 @@ void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem) void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem) { + if(!checkGroupMetaConsistency(grpItem->meta)) + { + std::cerr << "(EE) Cannot update group. Some information was not supplied." << std::endl; + return ; + } + RS_STACK_MUTEX(mGenMtx) ; token = mDataAccess->generatePublicToken(); mGroupUpdatePublish.push_back(GroupUpdatePublish(grpItem, token)); diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index 706ed9401..870082893 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -689,6 +689,8 @@ private: void publishMsgs(); + bool checkGroupMetaConsistency(const RsGroupMetaData& meta); + /*! * processes msg local meta changes */ diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index 7653c4e20..cade3b986 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -3890,16 +3890,14 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM #endif return false; } - - if(circleType == GXS_CIRCLE_TYPE_PUBLIC) + else if(circleType == GXS_CIRCLE_TYPE_PUBLIC || circleType == GXS_CIRCLE_TYPE_UNKNOWN) // this complies with the fact that p3IdService does not initialise the circle type. { #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " PUBLIC_CIRCLE, can send"<< std::endl; #endif return true; } - - if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) + else if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) { #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " EXTERNAL_CIRCLE, will be sent encrypted."<< std::endl; @@ -3907,8 +3905,7 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM should_encrypt = true ; return true ; } - - if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) + else if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) { #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl; @@ -3922,8 +3919,11 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " YOUREYESONLY, checking further"<< std::endl; #endif } - - return true; + else + { + std::cerr << "(EE) unknown value found in circle type for group " << grpMeta.mGroupId << ": " << (int)circleType << ": this is probably a bug in the design of the group creation." << std::endl; + return false; + } } bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& grpMeta, RsGxsCircleId& should_encrypt_id) @@ -4281,19 +4281,16 @@ bool RsGxsNetService::canSendMsgIds(std::vector& msgMetas, co #endif return false; } - - if(circleType == GXS_CIRCLE_TYPE_PUBLIC) + else if(circleType == GXS_CIRCLE_TYPE_PUBLIC || circleType == GXS_CIRCLE_TYPE_UNKNOWN) // this complies with the fact that p3IdService does not initialise the circle type. { #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl; #endif return true; } - - const RsGxsCircleId& circleId = grpMeta.mCircleId; - - if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) + else if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) { + const RsGxsCircleId& circleId = grpMeta.mCircleId; #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl; #endif @@ -4338,8 +4335,7 @@ bool RsGxsNetService::canSendMsgIds(std::vector& msgMetas, co return true ; } - - if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) + else if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) { #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl; @@ -4350,8 +4346,11 @@ bool RsGxsNetService::canSendMsgIds(std::vector& msgMetas, co #endif return res ; } - - return false; + else + { + std::cerr << "(EE) unknown value found in circle type for group " << grpMeta.mGroupId << ": " << (int)circleType << ": this is probably a bug in the design of the group creation." << std::endl; + return false; + } } /** inherited methods **/ diff --git a/libretroshare/src/retroshare/rsgxscircles.h b/libretroshare/src/retroshare/rsgxscircles.h index da9474a82..a760c008e 100644 --- a/libretroshare/src/retroshare/rsgxscircles.h +++ b/libretroshare/src/retroshare/rsgxscircles.h @@ -52,6 +52,7 @@ typedef RsPgpId RsPgpId; // The meaning of the different circle types is: // // +static const uint32_t GXS_CIRCLE_TYPE_UNKNOWN = 0x0000 ; // not known. Is treated as public. static const uint32_t GXS_CIRCLE_TYPE_PUBLIC = 0x0001 ; // not restricted to a circle static const uint32_t GXS_CIRCLE_TYPE_EXTERNAL = 0x0002 ; // restricted to an external circle, made of RsGxsId static const uint32_t GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY = 0x0003 ; // restricted to a subset of friend nodes of a given RS node given by a RsPgpId list diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 59748cf5c..6fd907898 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -33,11 +33,13 @@ typedef std::map > MsgMetaResult; class RsGxsGrpMetaData; class RsGxsMsgMetaData; - struct RsGroupMetaData { + // (csoler) The correct default value to be used in mCircleType is GXS_CIRCLE_TYPE_PUBLIC, which is defined in rsgxscircles.h, + // but because of a loop in the includes, I cannot include it here. So I replaced with its current value 0x0001. + RsGroupMetaData() : mGroupFlags(0), mSignFlags(0), mPublishTs(0), - mCircleType(0), mAuthenFlags(0), mSubscribeFlags(0), mPop(0), + mCircleType(0x0001), mAuthenFlags(0), mSubscribeFlags(0), mPop(0), mVisibleMsgCount(0), mLastPost(0), mGroupStatus(0) {} void operator =(const RsGxsGrpMetaData& rGxsMeta); diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 5da0058b3..be52a1c64 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -690,6 +690,7 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms) RsGxsIdGroup id; id.mMeta.mGroupName = params.nickname; + id.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC ; id.mImage = params.mImage; if (params.isPgpLinked) @@ -712,6 +713,7 @@ bool p3IdService::updateIdentity(uint32_t& token, RsGxsIdGroup &group) std::cerr << "p3IdService::updateIdentity()"; std::cerr << std::endl; #endif + group.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC ; updateGroup(token, group);