2014-04-13 17:52:53 -04:00
|
|
|
/*
|
|
|
|
* nxsgrpsync_test.cc
|
|
|
|
*
|
|
|
|
* Created on: 13 Apr 2014
|
|
|
|
* Author: crispy
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nxsgrpsync_test.h"
|
|
|
|
#include "retroshare/rstypes.h"
|
|
|
|
#include "gxs/rsdataservice.h"
|
|
|
|
#include "nxsdummyservices.h"
|
2014-04-18 17:58:14 -04:00
|
|
|
#include "../common/data_support.h"
|
2014-04-13 17:52:53 -04:00
|
|
|
|
|
|
|
using namespace rs_nxs_test;
|
|
|
|
|
2014-04-26 06:07:25 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
|
2015-12-13 14:48:55 -05:00
|
|
|
NxsGrpSync::NxsGrpSync(RsGcxs* circle, RsGixsReputation* reputation):
|
|
|
|
mServType(0)
|
2014-04-13 17:52:53 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
int numPeers = 2;
|
|
|
|
|
|
|
|
for(int i =0; i < numPeers; i++)
|
|
|
|
{
|
|
|
|
RsPeerId id = RsPeerId::random();
|
|
|
|
mPeerIds.push_back(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::list<RsPeerId>::iterator it = mPeerIds.begin();
|
|
|
|
for(; it != mPeerIds.end(); it++)
|
|
|
|
{
|
|
|
|
// data stores
|
2014-05-18 12:44:19 -04:00
|
|
|
RsGeneralDataService* ds = createDataStore(*it, mServType);
|
2014-04-18 17:58:14 -04:00
|
|
|
mDataServices.insert(std::make_pair(*it, ds));
|
2014-04-13 17:52:53 -04:00
|
|
|
// net managers
|
|
|
|
std::list<RsPeerId> otherPeers;
|
|
|
|
copy_all_but<RsPeerId>(*it, mPeerIds, otherPeers);
|
2014-04-18 17:58:14 -04:00
|
|
|
RsNxsNetMgr* mgr = new rs_nxs_test::RsNxsNetDummyMgr(*it, otherPeers);
|
2014-04-13 17:52:53 -04:00
|
|
|
mNxsNetMgrs.insert(std::make_pair(*it, mgr));
|
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
}
|
2014-04-13 17:52:53 -04:00
|
|
|
|
2014-04-26 06:07:25 -04:00
|
|
|
RsNxsSimpleDummyReputation::RepMap reMap;
|
|
|
|
// now reputation service
|
2014-05-27 17:14:05 -04:00
|
|
|
|
|
|
|
if(!reputation)
|
|
|
|
mRep = new RsNxsSimpleDummyReputation(reMap, true);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mRep = reputation;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!circle)
|
|
|
|
mCircles = new RsNxsSimpleDummyCircles();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mCircles = circle;
|
|
|
|
}
|
2014-04-26 06:07:25 -04:00
|
|
|
|
|
|
|
|
2014-05-27 17:14:05 -04:00
|
|
|
mPgpUtils = new RsDummyPgpUtils();
|
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
// lets create some a group each for all peers
|
|
|
|
DataMap::iterator mit = mDataServices.begin();
|
|
|
|
for(; mit != mDataServices.end(); mit++)
|
|
|
|
{
|
|
|
|
RsNxsGrp* grp = new RsNxsGrp(mServType);
|
|
|
|
|
|
|
|
init_item(*grp);
|
|
|
|
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
|
|
|
init_item(meta);
|
|
|
|
grp->metaData = meta;
|
2014-04-19 06:20:07 -04:00
|
|
|
meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
2014-04-18 17:58:14 -04:00
|
|
|
|
2014-05-27 17:14:05 -04:00
|
|
|
if(circle)
|
|
|
|
{
|
|
|
|
meta->mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
|
2015-01-11 17:19:32 -05:00
|
|
|
meta->mCircleId = RsGxsCircleId::random();
|
2014-05-27 17:14:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
RsGxsGroupId grpId = grp->grpId;
|
2014-04-18 17:58:14 -04:00
|
|
|
|
|
|
|
RsGeneralDataService::GrpStoreMap gsp;
|
|
|
|
gsp.insert(std::make_pair(grp, meta));
|
|
|
|
mit->second->storeGroup(gsp);
|
|
|
|
|
|
|
|
// the expected result is that each peer has the group of the others
|
|
|
|
it = mPeerIds.begin();
|
|
|
|
for(; it != mPeerIds.end(); it++)
|
2014-05-27 17:14:05 -04:00
|
|
|
{
|
|
|
|
mExpectedResult[*it].push_back(grpId);
|
2014-04-18 17:58:14 -04:00
|
|
|
}
|
2014-04-13 17:52:53 -04:00
|
|
|
}
|
2014-04-18 17:58:14 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NxsGrpSync::getPeers(std::list<RsPeerId>& peerIds)
|
|
|
|
{
|
|
|
|
peerIds = mPeerIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RsGeneralDataService* NxsGrpSync::getDataService(const RsPeerId& peerId)
|
|
|
|
{
|
|
|
|
return mDataServices[peerId];
|
|
|
|
}
|
|
|
|
|
|
|
|
RsNxsNetMgr* NxsGrpSync::getDummyNetManager(const RsPeerId& peerId)
|
|
|
|
{
|
|
|
|
return mNxsNetMgrs[peerId];
|
|
|
|
}
|
|
|
|
|
2017-01-21 10:31:22 -05:00
|
|
|
RsGcxs* NxsGrpSync::getDummyCircles(const RsPeerId& /*peerId*/)
|
2014-04-13 17:52:53 -04:00
|
|
|
{
|
|
|
|
return mCircles;
|
|
|
|
}
|
|
|
|
|
2017-01-21 10:31:22 -05:00
|
|
|
RsGixsReputation* NxsGrpSync::getDummyReputations(const RsPeerId& /*peerId*/)
|
2014-04-13 17:52:53 -04:00
|
|
|
{
|
|
|
|
return mRep;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t NxsGrpSync::getServiceType()
|
|
|
|
{
|
2014-04-18 17:58:14 -04:00
|
|
|
return mServType;
|
2014-04-13 17:52:53 -04:00
|
|
|
}
|
2014-04-18 17:58:14 -04:00
|
|
|
|
|
|
|
rs_nxs_test::NxsGrpSync::~NxsGrpSync()
|
|
|
|
{
|
|
|
|
// clean up data stores
|
|
|
|
DataMap::iterator mit = mDataServices.begin();
|
|
|
|
for(; mit != mDataServices.end(); mit++)
|
|
|
|
{
|
|
|
|
RsGxsGroupId::std_vector grpIds;
|
|
|
|
mit->second->resetDataStore();
|
|
|
|
std::string dbFile = "grp_store_" + mit->first.toStdString();
|
|
|
|
remove(dbFile.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RsServiceInfo rs_nxs_test::NxsGrpSync::getServiceInfo() {
|
|
|
|
return mServInfo;
|
|
|
|
}
|
|
|
|
|
2014-05-27 17:14:05 -04:00
|
|
|
PgpAuxUtils* rs_nxs_test::NxsGrpSync::getDummyPgpUtils()
|
|
|
|
{
|
|
|
|
return mPgpUtils;
|
|
|
|
}
|
|
|
|
|
2014-04-25 18:02:34 -04:00
|
|
|
const NxsGrpTestScenario::ExpectedMap& rs_nxs_test::NxsGrpSync::getExpectedMap() {
|
|
|
|
return mExpectedResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|