diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index 1ac3261c5..18aa6431d 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -457,7 +457,7 @@ bool RsGxsNetService::locked_canReceive(const RsGxsGrpMetaData * const grpMeta, if(mCircles->isLoaded(grpMeta->mCircleId)) { - const RsPgpId& pgpId = rsPeers->getGPGId(peerId); + const RsPgpId& pgpId = mNetMgr->getGPGId(peerId); return mCircles->canSend(grpMeta->mCircleId, pgpId); } @@ -1912,6 +1912,7 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr) return; } + // hacky assumes a transaction only consist of a single grpId RsGxsGroupId grpId; for(;lit != tr->mItems.end(); lit++) @@ -2144,7 +2145,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item) if(!toVet.empty()) { - mPendingCircleVets.push_back(new GrpCircleIdRequestVetting(mCircles, toVet, peer)); + mPendingCircleVets.push_back(new GrpCircleIdRequestVetting(mCircles, mNetMgr, toVet, peer)); } locked_pushGrpRespFromList(itemL, peer, transN); @@ -2171,7 +2172,7 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM { if(mCircles->isLoaded(circleId)) { - const RsPgpId& pgpId = rsPeers->getGPGId(sslId); + const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); return mCircles->canSend(circleId, pgpId); } @@ -2188,7 +2189,7 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle; if(mCircles->isLoaded(internalCircleId)) { - const RsPgpId& pgpId = rsPeers->getGPGId(sslId); + const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); return mCircles->canSend(internalCircleId, pgpId); } @@ -2261,7 +2262,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item) uint32_t transN = locked_getTransactionId(); - if(/*canSendMsgIds(msgMetas, *grpMeta, peer)*/ true) + if(canSendMsgIds(msgMetas, *grpMeta, peer)) { std::vector::iterator vit = msgMetas.begin(); @@ -2337,7 +2338,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector& msgMet { if(mCircles->isLoaded(circleId)) { - const RsPgpId& pgpId = rsPeers->getGPGId(sslId); + const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); return mCircles->canSend(circleId, pgpId); } @@ -2353,7 +2354,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector& msgMet } if(!toVet.empty()) - mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, toVet, grpMeta.mGroupId, + mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mNetMgr, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId)); return false; @@ -2365,10 +2366,10 @@ bool RsGxsNetService::canSendMsgIds(const std::vector& msgMet // is the personal circle owner if(!grpMeta.mInternalCircle.isNull()) { - const RsGxsCircleId& internalCircleId = grpMeta.mCircleId; + const RsGxsCircleId& internalCircleId = grpMeta.mInternalCircle; if(mCircles->isLoaded(internalCircleId)) { - const RsPgpId& pgpId = rsPeers->getGPGId(sslId); + const RsPgpId& pgpId = mNetMgr->getGPGId(sslId); return mCircles->canSend(internalCircleId, pgpId); } @@ -2384,7 +2385,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector& msgMet } if(!toVet.empty()) - mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, toVet, grpMeta.mGroupId, + mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mNetMgr, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId)); return false; diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index a3022e4e3..d1a095ad0 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -231,11 +231,19 @@ private: void locked_genReqGrpTransaction(NxsTransaction* tr); /*! - * Generates new transaction to send msg data based on list - * of grpids received from peer stored in passed transaction + * This first checks if one can send a grpId based circles + * If it can send, then it call locked_genSendMsgsTransaction * @param tr transaction responsible for generating grp request + * @see locked_genSendMsgsTransaction */ - void locked_genSendMsgsTransaction(NxsTransaction* tr); + void locked_checkSendMsgsTransaction(NxsTransaction* tr); + + /*! + * Generates new transaction to send msg data based on list + * of grpids received from peer stored in passed transaction + * @param tr transaction responsible for generating grp request + */ + void locked_genSendMsgsTransaction(NxsTransaction* tr); /*! * Generates new transaction to send grp data based on list diff --git a/libretroshare/src/gxs/rsgxsnetutils.cc b/libretroshare/src/gxs/rsgxsnetutils.cc index 35ef64696..29d5888f9 100644 --- a/libretroshare/src/gxs/rsgxsnetutils.cc +++ b/libretroshare/src/gxs/rsgxsnetutils.cc @@ -213,8 +213,8 @@ const int GrpCircleVetting::MSG_ID_RECV_PEND = 3; GrpIdCircleVet::GrpIdCircleVet(const RsGxsGroupId& grpId, const RsGxsCircleId& circleId) : mGroupId(grpId), mCircleId(circleId), mCleared(false) {} -GrpCircleVetting::GrpCircleVetting(RsGcxs* const circles) - : mCircles(circles) {} +GrpCircleVetting::GrpCircleVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr) + : mCircles(circles), mNetMgr(netMgr) {} GrpCircleVetting::~GrpCircleVetting() {} @@ -226,7 +226,7 @@ bool GrpCircleVetting::canSend(const SSLIdType& peerId, const RsGxsCircleId& cir { if(mCircles->isLoaded(circleId)) { - const RsPgpId& pgpId = rsPeers->getGPGId(peerId); + const RsPgpId& pgpId = mNetMgr->getGPGId(peerId); return mCircles->canSend(circleId, pgpId); } @@ -236,8 +236,8 @@ bool GrpCircleVetting::canSend(const SSLIdType& peerId, const RsGxsCircleId& cir } GrpCircleIdRequestVetting::GrpCircleIdRequestVetting( - RsGcxs* const circles, std::vector grpCircleV, const RsPeerId& peerId) - : GrpCircleVetting(circles), mGrpCircleV(grpCircleV), mPeerId(peerId) {} + RsGcxs* const circles, RsNxsNetMgr* const netMgr, std::vector grpCircleV, const RsPeerId& peerId) + : GrpCircleVetting(circles, netMgr), mGrpCircleV(grpCircleV), mPeerId(peerId) {} bool GrpCircleIdRequestVetting::cleared() { @@ -274,10 +274,10 @@ MsgIdCircleVet::MsgIdCircleVet(const RsGxsMessageId& msgId, : mMsgId(msgId), mAuthorId(authorId) { } -MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles, +MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr, std::vector msgs, const RsGxsGroupId& grpId, const RsPeerId& peerId, const RsGxsCircleId& circleId) -: GrpCircleVetting(circles), mMsgs(msgs), mGrpId(grpId), mPeerId(peerId), mCircleId(circleId) {} +: GrpCircleVetting(circles, netMgr), mMsgs(msgs), mGrpId(grpId), mPeerId(peerId), mCircleId(circleId) {} bool MsgCircleIdsRequestVetting::cleared() { @@ -291,3 +291,8 @@ int MsgCircleIdsRequestVetting::getType() const return MSG_ID_SEND_PEND; } +RsPgpId RsNxsNetMgrImpl::getGPGId(const RsPeerId& peerId) { + rsPeers->getGPGId(peerId); +} + + diff --git a/libretroshare/src/gxs/rsgxsnetutils.h b/libretroshare/src/gxs/rsgxsnetutils.h index 2a816a0c2..46fb61b48 100644 --- a/libretroshare/src/gxs/rsgxsnetutils.h +++ b/libretroshare/src/gxs/rsgxsnetutils.h @@ -83,6 +83,7 @@ public: virtual ~RsNxsNetMgr(){}; virtual const RsPeerId& getOwnId() = 0; virtual void getOnlineList(const uint32_t serviceId, std::set& ssl_peers) = 0; + virtual RsPgpId getGPGId(const RsPeerId& peerId) = 0; }; @@ -94,8 +95,9 @@ public: RsNxsNetMgrImpl(p3ServiceControl* sc); virtual ~RsNxsNetMgrImpl(){}; - virtual const RsPeerId& getOwnId(); - virtual void getOnlineList(const uint32_t serviceId, std::set& ssl_peers); + const RsPeerId& getOwnId(); + void getOnlineList(const uint32_t serviceId, std::set& ssl_peers); + RsPgpId getGPGId(const RsPeerId& peerId); private: @@ -243,7 +245,7 @@ public: static const int MSG_ID_RECV_PEND; - GrpCircleVetting(RsGcxs* const circles); + GrpCircleVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr); virtual ~GrpCircleVetting(); bool expired(); virtual int getType() const = 0; @@ -255,13 +257,14 @@ protected: private: RsGcxs* const mCircles; + RsNxsNetMgr* const mNetMgr; time_t mTimeStamp; }; class GrpCircleIdRequestVetting : public GrpCircleVetting { public: - GrpCircleIdRequestVetting(RsGcxs* const circles, std::vector mGrpCircleV, const RsPeerId& peerId); + GrpCircleIdRequestVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr, std::vector mGrpCircleV, const RsPeerId& peerId); bool cleared(); int getType() const; std::vector mGrpCircleV; @@ -271,7 +274,7 @@ public: class MsgCircleIdsRequestVetting : public GrpCircleVetting { public: - MsgCircleIdsRequestVetting(RsGcxs* const circles, std::vector msgs, const RsGxsGroupId& grpId, + MsgCircleIdsRequestVetting(RsGcxs* const circles, RsNxsNetMgr* const netMgr, std::vector msgs, const RsGxsGroupId& grpId, const RsPeerId& peerId, const RsGxsCircleId& circleId); bool cleared(); int getType() const; diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc index c252b3624..863d13d91 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc @@ -20,6 +20,7 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync() { int numPeers = 2; + // create 2 peers for(int i =0; i < numPeers; i++) { RsPeerId id = RsPeerId::random(); @@ -31,7 +32,7 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync() for(; it != mPeerIds.end(); it++) { // data stores - RsGeneralDataService* ds = new RsDataService("./", "grp_store_" + + RsGeneralDataService* ds = new RsDataService("./", "data_store_" + it->toStdString(), mServType, NULL, "key"); mDataServices.insert(std::make_pair(*it, ds)); @@ -57,16 +58,17 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync() std::auto_ptr grp = std::auto_ptr(new RsNxsGrp(mServType)); init_item(*grp); - RsGxsGrpMetaData* meta = new RsGxsGrpMetaData(); - init_item(meta); - meta->mReputationCutOff = 0; + RsGxsGrpMetaData* meta = new RsGxsGrpMetaData(); + init_item(meta); + meta->mReputationCutOff = 0; meta->mGroupId = grp->grpId; grp->metaData = meta; meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED; + meta->mCircleType = GXS_CIRCLE_TYPE_PUBLIC; RsGxsGroupId grpId = grp->grpId; - // the expected result is that each peer has the group of the others + // the expected result is that each peer has all messages it = mPeerIds.begin(); DataMap::iterator mit = mDataServices.begin(); @@ -95,6 +97,7 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync() RsGxsMsgMetaData* msgMeta = new RsGxsMsgMetaData(); init_item(msgMeta); msgMeta->mGroupId = grp->grpId; + msgMeta->mMsgId = msg->msgId; RsGeneralDataService::MsgStoreMap msm; msm.insert(std::make_pair(msg , msgMeta)); RsGxsMessageId msgId = msg->msgId;