2007-12-11 20:43:17 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services p3service.h
|
|
|
|
*
|
|
|
|
* 3P/PQI network interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2008 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 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef P3_GENERIC_SERVICE_HEADER
|
|
|
|
#define P3_GENERIC_SERVICE_HEADER
|
|
|
|
|
|
|
|
#include "pqi/pqi.h"
|
|
|
|
#include "pqi/pqiservice.h"
|
|
|
|
#include "util/rsthreads.h"
|
|
|
|
|
|
|
|
/* This provides easy to use extensions to the pqiservice class provided in src/pqi.
|
|
|
|
*
|
|
|
|
* We will have a number of different strains.
|
|
|
|
*
|
|
|
|
* (1) p3Service -> pqiService
|
|
|
|
*
|
|
|
|
* Basic service with serialisation handled by a RsSerialiser.
|
|
|
|
*
|
|
|
|
* (2) p3ThreadedService -> p3service.
|
|
|
|
*
|
|
|
|
* Independent thread with mutex locks for i/o Queues.
|
|
|
|
* ideal for games etc.
|
|
|
|
*
|
|
|
|
* (3) p3CacheService -> p3service + CacheSource + CacheStore.
|
|
|
|
*
|
|
|
|
* For both Cached and Messages.
|
|
|
|
*/
|
|
|
|
|
2008-04-15 12:35:46 -04:00
|
|
|
std::string generateRandomServiceId();
|
|
|
|
|
2009-12-13 16:59:26 -05:00
|
|
|
//TODO : encryption and upload / download rate implementation
|
2008-04-15 12:35:46 -04:00
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
// p3FastService(uint16_t type)
|
|
|
|
// :pqiService((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) type) << 8)),
|
|
|
|
|
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
class p3FastService: public pqiService
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
p3FastService()
|
|
|
|
:pqiService(),
|
2013-10-01 06:11:34 -04:00
|
|
|
srvMtx("p3FastService"), rsSerialiser(NULL)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
rsSerialiser = new RsSerialiser();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
virtual ~p3FastService() { delete rsSerialiser; return; }
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
/*************** INTERFACE ******************************/
|
|
|
|
int sendItem(RsItem *);
|
|
|
|
virtual int tick() { return 0; }
|
|
|
|
/*************** INTERFACE ******************************/
|
|
|
|
|
|
|
|
public:
|
|
|
|
// overloaded pqiService interface.
|
2013-10-01 06:11:34 -04:00
|
|
|
virtual bool recv(RsRawItem *);
|
|
|
|
|
|
|
|
// called by recv().
|
|
|
|
virtual bool recvItem(RsItem *item) = 0;
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void addSerialType(RsSerialType *);
|
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
RsMutex srvMtx; /* below locked by Mutex */
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
RsSerialiser *rsSerialiser;
|
2013-10-01 06:11:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class p3Service: public p3FastService
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
p3Service()
|
|
|
|
:p3FastService()
|
2013-10-01 06:11:34 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/*************** INTERFACE ******************************/
|
|
|
|
/* called from Thread/tick/GUI */
|
|
|
|
//int sendItem(RsItem *);
|
|
|
|
RsItem * recvItem();
|
|
|
|
bool receivedItems();
|
|
|
|
|
|
|
|
//virtual int tick() { return 0; }
|
|
|
|
/*************** INTERFACE ******************************/
|
|
|
|
|
|
|
|
public:
|
|
|
|
// overloaded p3FastService interface.
|
|
|
|
virtual bool recvItem(RsItem *item);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/* below locked by srvMtx Mutex */
|
|
|
|
std::list<RsItem *> recv_queue;
|
2007-12-11 20:43:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-06-13 11:32:12 -04:00
|
|
|
class nullService: public pqiService
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
nullService()
|
|
|
|
:pqiService()
|
2008-06-13 11:32:12 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//virtual int tick()
|
|
|
|
|
|
|
|
public:
|
|
|
|
// overloaded NULL pqiService interface.
|
2013-10-01 06:11:34 -04:00
|
|
|
virtual bool recv(RsRawItem *item)
|
2008-06-13 11:32:12 -04:00
|
|
|
{
|
|
|
|
/* drop any items */
|
|
|
|
delete item;
|
2013-10-01 06:11:34 -04:00
|
|
|
return true;
|
2008-06-13 11:32:12 -04:00
|
|
|
}
|
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
virtual bool send(RsRawItem *item)
|
2008-06-13 11:32:12 -04:00
|
|
|
{
|
2013-10-01 06:11:34 -04:00
|
|
|
delete item;
|
|
|
|
return true;
|
2008-06-13 11:32:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
class p3ThreadedService: public p3Service, public RsThread
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
p3ThreadedService()
|
|
|
|
:p3Service() { return; }
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~p3ThreadedService() { return; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // P3_GENERIC_SERVICE_HEADER
|
|
|
|
|