Added librssimulator, and very basic test for statusservice.

Obviously lots to do here - but its a start!



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7258 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-04-10 08:46:15 +00:00
parent 5221ec0aca
commit c98d6d1595
12 changed files with 966 additions and 8 deletions

View File

@ -0,0 +1,246 @@
TEMPLATE = lib
CONFIG += staticlib
CONFIG -= qt
TARGET = rssimulator
CONFIG += gxs debug
profiling {
QMAKE_CXXFLAGS -= -fomit-frame-pointer
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
}
debug {
QMAKE_CXXFLAGS -= -O2 -fomit-frame-pointer
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
}
# gxs defines.
gxs {
DEFINES *= RS_ENABLE_GXS
DEFINES *= SQLITE_HAS_CODEC
DEFINES *= GXS_ENABLE_SYNC_MSGS
}
INCLUDEPATH += ../../libretroshare/src/
######################### Peer ##################################
HEADERS += peer/FakeLinkMgr.h \
peer/FakePeerMgr.h \
peer/FakeNetMgr.h \
peer/FakePublisher.h \
peer/FakeServiceControl.h \
peer/PeerNode.h \
SOURCES += peer/PeerNode.cc \
###################### Unit Tests ###############################
HEADERS += testing/IsolatedServiceTester.h \
SOURCES += testing/IsolatedServiceTester.cc \
##################### Network Sims ##############################
# to be ported over.
#HEADERS += network/Network.h \
#SOURCES += network/Network.cc \
################################# Linux ##########################################
linux-* {
isEmpty(PREFIX) { PREFIX = /usr }
isEmpty(INC_DIR) { INC_DIR = $${PREFIX}/include/retroshare/ }
isEmpty(LIB_DIR) { LIB_DIR = $${PREFIX}/lib/ }
# These two lines fixe compilation on ubuntu natty. Probably a ubuntu packaging error.
INCLUDEPATH += $$system(pkg-config --cflags glib-2.0 | sed -e "s/-I//g")
OPENPGPSDK_DIR = ../../openpgpsdk/src
INCLUDEPATH *= $${OPENPGPSDK_DIR} ../openpgpsdk
DESTDIR = lib
QMAKE_CXXFLAGS *= -Wall -D_FILE_OFFSET_BITS=64
QMAKE_CC = g++
SSL_DIR = /usr/include/openssl
UPNP_DIR = /usr/include/upnp
INCLUDEPATH += . $${SSL_DIR} $${UPNP_DIR}
# where to put the shared library itself
target.path = $$LIB_DIR
INSTALLS *= target
# where to put the librarys interface
include_rsiface.path = $${INC_DIR}
include_rsiface.files = $$PUBLIC_HEADERS
INSTALLS += include_rsiface
#CONFIG += version_detail_bash_script
# linux/bsd can use either - libupnp is more complete and packaged.
#CONFIG += upnp_miniupnpc
CONFIG += upnp_libupnp
# Check if the systems libupnp has been Debian-patched
system(grep -E 'char[[:space:]]+PublisherUrl' $${UPNP_DIR}/upnp.h >/dev/null 2>&1) {
# Normal libupnp
} else {
# Patched libupnp or new unreleased version
DEFINES *= PATCHED_LIBUPNP
}
DEFINES *= UBUNTU
INCLUDEPATH += /usr/include/glib-2.0/ /usr/lib/glib-2.0/include
LIBS *= -lgnome-keyring
}
linux-g++ {
OBJECTS_DIR = temp/linux-g++/obj
}
linux-g++-64 {
OBJECTS_DIR = temp/linux-g++-64/obj
}
version_detail_bash_script {
QMAKE_EXTRA_TARGETS += write_version_detail
PRE_TARGETDEPS = write_version_detail
write_version_detail.commands = ./version_detail.sh
}
#################### Cross compilation for windows under Linux ####################
win32-x-g++ {
OBJECTS_DIR = temp/win32xgcc/obj
DESTDIR = lib.win32xgcc
DEFINES *= WINDOWS_SYS WIN32 WIN_CROSS_UBUNTU
QMAKE_CXXFLAGS *= -Wmissing-include-dirs
QMAKE_CC = i586-mingw32msvc-g++
QMAKE_LIB = i586-mingw32msvc-ar
QMAKE_AR = i586-mingw32msvc-ar
DEFINES *= STATICLIB WIN32
CONFIG += upnp_miniupnpc
SSL_DIR=../../../../openssl
UPNPC_DIR = ../../../../miniupnpc-1.3
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
GPGME_DIR = ../../../../gpgme-1.1.8
INCLUDEPATH *= /usr/i586-mingw32msvc/include ${HOME}/.wine/drive_c/pthreads/include/
}
################################# Windows ##########################################
win32 {
QMAKE_CC = g++
OBJECTS_DIR = temp/obj
MOC_DIR = temp/moc
DEFINES *= WINDOWS_SYS WIN32 STATICLIB MINGW WIN32_LEAN_AND_MEAN _USE_32BIT_TIME_T
DEFINES *= MINIUPNPC_VERSION=13
# This defines the platform to be WinXP or later and is needed for getaddrinfo (_WIN32_WINNT_WINXP)
DEFINES *= WINVER=0x0501
DESTDIR = lib
# Switch on extra warnings
QMAKE_CFLAGS += -Wextra
QMAKE_CXXFLAGS += -Wextra
# Switch off optimization for release version
QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE += -O0
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -O0
# Switch on optimization for debug version
#QMAKE_CXXFLAGS_DEBUG += -O2
#QMAKE_CFLAGS_DEBUG += -O2
DEFINES += USE_CMD_ARGS
CONFIG += upnp_miniupnpc
UPNPC_DIR = ../../../miniupnpc-1.3
ZLIB_DIR = ../../../zlib-1.2.3
SSL_DIR = ../../../openssl-1.0.1c
OPENPGPSDK_DIR = ../../openpgpsdk/src
INCLUDEPATH += . $${SSL_DIR}/include $${UPNPC_DIR} $${ZLIB_DIR} $${OPENPGPSDK_DIR}
# SQLite include path is required to compile GXS.
gxs {
SQLITE_DIR = ../../../sqlcipher-2.2.0
INCLUDEPATH += $${SQLITE_DIR}
}
}
################################# MacOSX ##########################################
mac {
QMAKE_CC = g++
OBJECTS_DIR = temp/obj
MOC_DIR = temp/moc
#DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW
#DEFINES *= MINIUPNPC_VERSION=13
DESTDIR = lib
CONFIG += upnp_miniupnpc
# zeroconf disabled at the end of libretroshare.pro (but need the code)
CONFIG += zeroconf
CONFIG += zcnatassist
# Beautiful Hack to fix 64bit file access.
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs
UPNPC_DIR = ../../../miniupnpc-1.0
#GPG_ERROR_DIR = ../../../../libgpg-error-1.7
#GPGME_DIR = ../../../../gpgme-1.1.8
OPENPGPSDK_DIR = ../../openpgpsdk/src
INCLUDEPATH += . $${UPNPC_DIR}
INCLUDEPATH += $${OPENPGPSDK_DIR}
#../openpgpsdk
#INCLUDEPATH += . $${UPNPC_DIR} $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src
}
################################# FreeBSD ##########################################
freebsd-* {
INCLUDEPATH *= /usr/local/include/gpgme
INCLUDEPATH *= /usr/local/include/glib-2.0
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen
# linux/bsd can use either - libupnp is more complete and packaged.
#CONFIG += upnp_miniupnpc
CONFIG += upnp_libupnp
DESTDIR = lib
}
################################# OpenBSD ##########################################
openbsd-* {
INCLUDEPATH *= /usr/local/include
INCLUDEPATH += $$system(pkg-config --cflags glib-2.0 | sed -e "s/-I//g")
OPENPGPSDK_DIR = ../../openpgpsdk/src
INCLUDEPATH *= $${OPENPGPSDK_DIR} ../openpgpsdk
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen
CONFIG += upnp_libupnp
DESTDIR = lib
}
################################### COMMON stuff ##################################

View File

@ -0,0 +1,70 @@
#pragma once
#include <iostream>
#include <list>
#include <retroshare/rsids.h>
#include <pqi/p3linkmgr.h>
class FakePeerListStatus
{
public:
bool mOnline;
};
class FakeLinkMgr: public p3LinkMgrIMPL
{
public:
FakeLinkMgr(const RsPeerId& own_id,const std::list<RsPeerId>& friends, bool peersOnline)
: p3LinkMgrIMPL(NULL,NULL), mOwnId(own_id), mFriends()
{
std::list<RsPeerId>::const_iterator it;
for(it = friends.begin(); it != friends.end(); it++)
{
setOnlineStatus(*it, peersOnline);
}
}
virtual const RsPeerId& getOwnId() { return mOwnId; }
virtual void getOnlineList(std::list<RsPeerId>& lst)
{
std::map<RsPeerId, FakePeerListStatus>::iterator it;
for(it = mFriends.begin(); it != mFriends.end(); it++)
{
if (it->second.mOnline)
{
lst.push_back(it->first);
}
}
}
virtual void getFriendList(std::list<RsPeerId> &ssl_peers)
{
std::map<RsPeerId, FakePeerListStatus>::iterator it;
for(it = mFriends.begin(); it != mFriends.end(); it++)
{
ssl_peers.push_back(it->first);
}
}
virtual uint32_t getLinkType(const RsPeerId&) { return RS_NET_CONN_TCP_ALL | RS_NET_CONN_SPEED_NORMAL; }
virtual bool getPeerName(const RsPeerId &ssl_id, std::string &name) { name = ssl_id.toStdString() ; return true ;}
// functions to manipulate status.
virtual void setOnlineStatus(RsPeerId id, bool online)
{
FakePeerListStatus status;
status.mOnline = online;
mFriends[id] = status;
}
private:
RsPeerId mOwnId;
std::map<RsPeerId, FakePeerListStatus> mFriends;
};

View File

@ -0,0 +1,21 @@
#pragma once
#include <iostream>
#include <list>
#include <retroshare/rsids.h>
#include <pqi/p3netmgr.h>
class FakeNetMgr: public p3NetMgrIMPL
{
public:
FakeNetMgr()
: p3NetMgrIMPL()
{
return;
}
private:
//RsPeerId mOwnId;
};

View File

@ -0,0 +1,26 @@
#pragma once
#include <list>
#include <retroshare/rsids.h>
#include <pqi/p3peermgr.h>
class FakePeerMgr: public p3PeerMgrIMPL
{
public:
FakePeerMgr(const RsPeerId& own,const std::list<RsPeerId>& ids)
: p3PeerMgrIMPL(own,RsPgpId(),"no name","location name")
{
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
_ids.insert(*it) ;
}
virtual bool idFriend(const RsPeerId& ssl_id) { return _ids.find(ssl_id) != _ids.end() ; }
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& /*ssl_id*/)
{
return ~ServicePermissionFlags(0) ;
}
std::set<RsPeerId> _ids ;
};

View File

@ -0,0 +1,35 @@
#pragma once
#include <list>
#include <serialiser/rsserial.h>
#include <pqi/pqiservice.h>
class FakePublisher: public pqiPublisher
{
public:
virtual bool sendItem(RsRawItem *item)
{
_item_queue.push_back(item) ;
return true;
}
RsRawItem *outgoing()
{
if(_item_queue.empty())
return NULL ;
RsRawItem *item = _item_queue.front() ;
_item_queue.pop_front() ;
return item ;
}
bool outgoingEmpty()
{
return _item_queue.empty();
}
private:
std::list<RsRawItem*> _item_queue ;
};

View File

@ -0,0 +1,35 @@
#pragma once
#include <iostream>
#include <list>
#include <retroshare/rsids.h>
#include <pqi/p3linkmgr.h>
#include <pqi/p3servicecontrol.h>
class FakeServiceControl: public p3ServiceControl
{
public:
FakeServiceControl(p3LinkMgr *lm)
: p3ServiceControl(lm),mLink(lm)
{
}
virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet)
{
(void) serviceId;
std::list<RsPeerId> ids ;
mLink->getOnlineList(ids) ;
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
peerSet.insert(*it) ;
}
virtual bool checkFilter(uint32_t,const RsPeerId& id)
{
(void) id;
return true ;
}
p3LinkMgr *mLink;
};

View File

@ -0,0 +1,193 @@
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <list>
#include <string.h>
#include <retroshare/rsids.h>
#include <retroshare/rspeers.h>
#include <turtle/p3turtle.h>
#include <serialiser/rsserial.h>
#include <pqi/p3linkmgr.h>
#include <pqi/p3peermgr.h>
#include <ft/ftserver.h>
#include <ft/ftcontroller.h>
#include <services/p3service.h>
#include "PeerNode.h"
#include "FakeLinkMgr.h"
#include "FakePeerMgr.h"
#include "FakeNetMgr.h"
#include "FakePublisher.h"
#include "FakeServiceControl.h"
PeerNode::PeerNode(const RsPeerId& id,const std::list<RsPeerId>& friends, bool online)
: _id(id)
{
// add a service server.
mLinkMgr = new FakeLinkMgr(id, friends, online) ;
mPeerMgr = new FakePeerMgr(id, friends) ;
mPublisher = new FakePublisher() ;
_service_control = new FakeServiceControl(mLinkMgr) ;
_service_server = new p3ServiceServer(mPublisher,_service_control);
}
PeerNode::~PeerNode()
{
delete _service_server ;
delete mPublisher;
delete mPeerMgr;
delete mLinkMgr;
}
void PeerNode::AddService(pqiService *service)
{
_service_server->addService(service, true);
}
void PeerNode::AddPqiMonitor(pqiMonitor *service)
{
mPqiMonitors.push_back(service);
}
void PeerNode::AddPqiServiceMonitor(pqiServiceMonitor *service)
{
mPqiServiceMonitors.push_back(service);
}
p3NetMgr *PeerNode::getNetMgr()
{
return mNetMgr;
}
p3LinkMgr *PeerNode::getLinkMgr()
{
return mLinkMgr;
}
p3PeerMgr *PeerNode::getPeerMgr()
{
return mPeerMgr;
}
void PeerNode::notifyOfFriends()
{
std::list<RsPeerId> friendList;
mLinkMgr->getFriendList(friendList);
std::list<RsPeerId>::iterator it;
for(it = friendList.begin(); it != friendList.end(); it++)
{
pqipeer peer;
peer.id = *it;
peer.state = RS_PEER_S_FRIEND;
peer.actions = RS_PEER_NEW;
}
}
void PeerNode::bringOnline(std::list<RsPeerId> &onlineList)
{
std::list<RsPeerId>::iterator it;
std::list<pqipeer> pqiMonitorChanges;
std::list<pqiServicePeer> pqiServiceMonitorChanges;
for(it = onlineList.begin(); it != onlineList.end(); it++)
{
mLinkMgr->setOnlineStatus(*it, true);
pqipeer peer;
peer.id = *it;
peer.state = RS_PEER_S_FRIEND | RS_PEER_S_CONNECTED;
peer.actions = RS_PEER_CONNECTED;
pqiMonitorChanges.push_back(peer);
pqiServicePeer sp;
sp.id = *it;
sp.actions = RS_SERVICE_PEER_CONNECTED;
pqiServiceMonitorChanges.push_back(sp);
}
std::list<pqiMonitor *>::iterator pit;
for(pit = mPqiMonitors.begin(); pit != mPqiMonitors.end(); pit++)
{
(*pit)->statusChange(pqiMonitorChanges);
}
std::list<pqiServiceMonitor *>::iterator spit;
for(spit = mPqiServiceMonitors.begin(); spit != mPqiServiceMonitors.end(); spit++)
{
(*spit)->statusChange(pqiServiceMonitorChanges);
}
}
void PeerNode::takeOffline(std::list<RsPeerId> &offlineList)
{
std::list<RsPeerId>::iterator it;
std::list<pqipeer> pqiMonitorChanges;
std::list<pqiServicePeer> pqiServiceMonitorChanges;
for(it = offlineList.begin(); it != offlineList.end(); it++)
{
mLinkMgr->setOnlineStatus(*it, false);
pqipeer peer;
peer.id = *it;
peer.state = RS_PEER_S_FRIEND;
peer.actions = RS_PEER_DISCONNECTED;
pqiMonitorChanges.push_back(peer);
pqiServicePeer sp;
sp.id = *it;
sp.actions = RS_SERVICE_PEER_DISCONNECTED;
pqiServiceMonitorChanges.push_back(sp);
}
std::list<pqiMonitor *>::iterator pit;
for(pit = mPqiMonitors.begin(); pit != mPqiMonitors.end(); pit++)
{
(*pit)->statusChange(pqiMonitorChanges);
}
std::list<pqiServiceMonitor *>::iterator spit;
for(spit = mPqiServiceMonitors.begin(); spit != mPqiServiceMonitors.end(); spit++)
{
(*spit)->statusChange(pqiServiceMonitorChanges);
}
}
void PeerNode::tick()
{
std::cerr << " ticking peer node " << _id << std::endl;
_service_server->tick() ;
}
void PeerNode::incoming(RsRawItem *item)
{
_service_server->recvItem(item) ;
}
RsRawItem *PeerNode::outgoing()
{
return mPublisher->outgoing() ;
}
bool PeerNode::haveOutgoingPackets()
{
return (!(mPublisher->outgoingEmpty()));
}

View File

@ -0,0 +1,64 @@
#pragma once
#include <list>
#include "retroshare/rsids.h"
class RsRawItem ;
class p3ServiceServer ;
class FakePublisher;
class p3ServiceControl;
class FakeLinkMgr;
class FakePeerMgr;
class FakeNetMgr;
class pqiMonitor;
class pqiServiceMonitor;
class pqiService;
class PeerNode
{
public:
PeerNode(const RsPeerId& id,const std::list<RsPeerId>& friends, bool online) ;
~PeerNode() ;
RsRawItem *outgoing() ;
void incoming(RsRawItem *) ;
bool haveOutgoingPackets();
const RsPeerId& id() const { return _id ;}
void tick() ;
p3ServiceControl *getServiceControl() const { return _service_control; }
p3LinkMgr *getLinkMgr();
p3PeerMgr *getPeerMgr();
p3NetMgr *getNetMgr();
void AddService(pqiService *service);
void AddPqiMonitor(pqiMonitor *service);
void AddPqiServiceMonitor(pqiServiceMonitor *service);
//
void notifyOfFriends();
void bringOnline(std::list<RsPeerId> &friends);
void takeOffline(std::list<RsPeerId> &friends);
private:
RsPeerId _id;
p3ServiceServer *_service_server ;
FakePublisher *mPublisher ;
p3ServiceControl *_service_control;
FakeLinkMgr *mLinkMgr;
FakePeerMgr *mPeerMgr;
FakeNetMgr *mNetMgr;
/* for monitors */
std::list<pqiMonitor *> mPqiMonitors;
std::list<pqiServiceMonitor *> mPqiServiceMonitors;
};

View File

@ -0,0 +1,142 @@
#include <list>
#include "retroshare/rsids.h"
#include "serialiser/rsserial.h"
#include "testing/IsolatedServiceTester.h"
#include "peer/PeerNode.h"
IsolatedServiceTester::IsolatedServiceTester(RsPeerId ownId, std::list<RsPeerId> peers)
{
mNode = new PeerNode(ownId, peers, false);
mRsSerialiser = new RsSerialiser();
}
IsolatedServiceTester::~IsolatedServiceTester()
{
delete mNode;
delete mRsSerialiser;
}
void IsolatedServiceTester::addSerialType(RsSerialType *st)
{
mRsSerialiser->addSerialType(st);
}
bool IsolatedServiceTester::startup()
{
mNode->notifyOfFriends();
return true;
}
bool IsolatedServiceTester::tick()
{
return true;
}
bool IsolatedServiceTester::tickUntilPacket(int max_ticks)
{
for(int i = 0; i < max_ticks; i++)
{
tick();
if (mNode->haveOutgoingPackets())
{
return true;
}
}
return false;
}
RsItem *IsolatedServiceTester::getPacket()
{
RsRawItem *rawitem = mNode->outgoing();
if (rawitem)
{
/* convert back to standard item for convenience */
std::cerr << "IsolatedServiceTester::getPacket() have RsRawItem";
std::cerr << std::endl;
/* convert to RsServiceItem */
uint32_t size = rawitem->getRawLength();
RsItem *item = mRsSerialiser->deserialise(rawitem->getRawData(), &size);
if ((!item) || (size != rawitem->getRawLength()))
{
/* error in conversion */
std::cerr << "IsolatedServiceTester::getPacket() Error";
std::cerr << std::endl;
std::cerr << "IsolatedServiceTester::getPacket() Size: " << size;
std::cerr << std::endl;
std::cerr << "IsolatedServiceTester::getPacket() RawLength: " << rawitem->getRawLength();
std::cerr << std::endl;
if (item)
{
std::cerr << "p3Service::recv() Bad Item:";
std::cerr << std::endl;
item->print(std::cerr, 0);
std::cerr << std::endl;
delete item;
item=NULL ;
}
}
else
{
item->PeerId(rawitem->PeerId());
}
delete rawitem;
return item;
}
return NULL;
}
bool IsolatedServiceTester::sendPacket(RsItem *si)
{
std::cerr << "IsolatedServiceTester::sendPacket()";
std::cerr << std::endl;
/* try to convert */
uint32_t size = mRsSerialiser->size(si);
if (!size)
{
std::cerr << "IsolatedServiceTester::sendPacket() ERROR size == 0";
std::cerr << std::endl;
/* can't convert! */
delete si;
return false;
}
RsRawItem *raw = new RsRawItem(si->PacketId(), size);
if (!mRsSerialiser->serialise(si, raw->getRawData(), &size))
{
std::cerr << "IsolatedServiceTester::sendPacket() ERROR serialise failed";
std::cerr << std::endl;
delete raw;
raw = NULL;
}
if ((raw) && (size != raw->getRawLength()))
{
std::cerr << "IsolatedServiceTester::sendPacket() ERROR serialise size mismatch";
std::cerr << std::endl;
delete raw;
raw = NULL;
}
if (raw)
{
raw->PeerId(si->PeerId());
mNode->incoming(raw);
}
delete si;
return (raw != NULL);
}

View File

@ -0,0 +1,38 @@
#pragma once
#include <list>
#include "retroshare/rsids.h"
#include "pqi/p3linkmgr.h"
class RsItem;
class PeerNode;
class RsSerialType;
class RsSerialiser;
class IsolatedServiceTester
{
public:
IsolatedServiceTester(RsPeerId ownId, std::list<RsPeerId> peers);
~IsolatedServiceTester();
void addSerialType(RsSerialType *st);
bool startup();
void notifyPeers();
bool bringOnline(std::list<RsPeerId> peers);
bool tick();
bool tickUntilPacket(int max_ticks);
RsItem *getPacket();
bool sendPacket(RsItem *);
PeerNode *getPeerNode() { return mNode; }
private:
PeerNode *mNode;
RsSerialiser *mRsSerialiser;
};

View File

@ -0,0 +1,86 @@
#include <gtest/gtest.h>
// from librssimulator
#include "testing/IsolatedServiceTester.h"
#include "peer/PeerNode.h"
// from libretroshare
#include "services/p3statusservice.h"
#include "serialiser/rsstatusitems.h"
#define N_PEERS 10
TEST(libretroshare_services, Status_test1)
{
RsPeerId ownId = RsPeerId::random();
RsPeerId friendId = RsPeerId::random();
std::list<RsPeerId> peers;
peers.push_back(friendId);
for(int i = 0; i < N_PEERS; i++)
{
peers.push_back(RsPeerId::random());
}
IsolatedServiceTester tester(ownId, peers);
// extract bits we need.
PeerNode *node = tester.getPeerNode();
p3PeerMgr *peerMgr = node->getPeerMgr();
p3LinkMgr *linkMgr = node->getLinkMgr();
p3NetMgr *netMgr = node->getNetMgr();
p3ServiceControl *serviceCtrl = node->getServiceControl();
// add in service.
p3StatusService *status = new p3StatusService(serviceCtrl);
node->AddService(status);
node->AddPqiServiceMonitor(status);
tester.addSerialType(new RsStatusSerialiser());
/**************** Start Test ****************/
// setup.
tester.startup();
tester.tick();
// Expect no packets - as noone is online.
EXPECT_FALSE(tester.tickUntilPacket(20));
/*************** Connect Peers **************/
// bring people online.
std::list<RsPeerId> onlineList;
onlineList.push_back(friendId);
node->bringOnline(onlineList);
EXPECT_TRUE(tester.tickUntilPacket(20));
/*************** First Packet ***************/
RsItem *item = tester.getPacket();
EXPECT_TRUE(item != NULL);
// expecting Discovery
RsStatusItem *statusitem = dynamic_cast<RsStatusItem *>(item);
EXPECT_TRUE(statusitem != NULL);
EXPECT_TRUE(statusitem->PeerId() == friendId);
if (statusitem)
{
delete statusitem;
}
/*************** Reply Packet ***************/
statusitem = new RsStatusItem();
statusitem->PeerId(friendId);
tester.sendPacket(statusitem);
// expect...
//EXPECT_TRUE(test.tickUntilPacket(20));
}

View File

@ -22,6 +22,7 @@ linux-* {
PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a
LIBS += ../../libretroshare/src/lib/libretroshare.a
LIBS += ../librssimulator/lib/librssimulator.a
LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2
LIBS += -lssl -lupnp -lixml -lXss -lgnome-keyring
LIBS *= -lcrypto -ldl -lX11 -lz
@ -93,6 +94,7 @@ win32 {
#QTPLUGIN += qjpeg
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
PRE_TARGETDEPS *= ../librssimulator/lib/librssimulator.a
PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a
LIBS += ../../libretroshare/src/lib/libretroshare.a
@ -131,6 +133,7 @@ macx {
CONFIG += version_detail_bash_script
LIBS += ../../libretroshare/src/lib/libretroshare.a
LIBS += ../librssimulator/lib/librssimulator.a
LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2
LIBS += -lssl -lcrypto -lz
#LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan
@ -159,6 +162,7 @@ macx {
freebsd-* {
INCLUDEPATH *= /usr/local/include/gpgme
LIBS *= ../../libretroshare/src/lib/libretroshare.a
LIBS *= ../librssimulator/lib/librssimulator.a
LIBS *= -lssl
LIBS *= -lgpgme
LIBS *= -lupnp
@ -181,6 +185,7 @@ openbsd-* {
PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a
LIBS *= ../../libretroshare/src/lib/libretroshare.a
LIBS *= ../librssimulator/lib/librssimulator.a
LIBS *= ../../openpgpsdk/src/lib/libops.a -lbz2
LIBS *= -lssl -lcrypto
LIBS *= -lgpgme
@ -218,13 +223,7 @@ win32 {
DEPENDPATH += . \
INCLUDEPATH += ../../libretroshare/src/
# Input
#
# gui/channels/ChannelUserNotify.h \
# gui/settings/ForumPage.h \
INCLUDEPATH += ../librssimulator/
SOURCES += unittests.cc \
@ -293,7 +292,6 @@ SOURCES += libretroshare/gxs/data_service/rsdataservice_test.cc \
################################ dbase #####################################
#HEADERS += libretroshare/dbase
SOURCES += libretroshare/dbase/fisavetest.cc \
libretroshare/dbase/fitest2.cc \
@ -303,4 +301,8 @@ SOURCES += libretroshare/dbase/fisavetest.cc \
# libretroshare/dbase/fimontest.cc \
############################### services ###################################
SOURCES += libretroshare/services/status/status_test.cc \