mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 22:52:54 -04:00
Added Structure/Example for Port Forwarding Service.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@624 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7ede4b5755
commit
993a5e901d
4 changed files with 219 additions and 6 deletions
|
@ -88,15 +88,16 @@ const uint16_t RS_SERVICE_TYPE_CHANNEL = 0xf130;
|
||||||
|
|
||||||
/* Games/External Apps - Service Only */
|
/* Games/External Apps - Service Only */
|
||||||
const uint16_t RS_SERVICE_TYPE_GAME_LAUNCHER = 0xf200;
|
const uint16_t RS_SERVICE_TYPE_GAME_LAUNCHER = 0xf200;
|
||||||
|
const uint16_t RS_SERVICE_TYPE_PORT = 0xf201;
|
||||||
|
|
||||||
/* Example Games */
|
/* Example Games (NOT USED YET!) */
|
||||||
/* Board Games */
|
/* Board Games */
|
||||||
const uint16_t RS_SERVICE_TYPE_GAME_QTCHESS = 0xf201;
|
const uint16_t RS_SERVICE_TYPE_GAME_QTCHESS = 0xf211;
|
||||||
const uint16_t RS_SERVICE_TYPE_GAME_QGO = 0xf202;
|
const uint16_t RS_SERVICE_TYPE_GAME_QGO = 0xf212;
|
||||||
|
|
||||||
/* Card Games */
|
/* Card Games */
|
||||||
const uint16_t RS_SERVICE_TYPE_GAME_BIGTWO = 0xf203;
|
const uint16_t RS_SERVICE_TYPE_GAME_BIGTWO = 0xf213;
|
||||||
const uint16_t RS_SERVICE_TYPE_GAME_POKER = 0xf204;
|
const uint16_t RS_SERVICE_TYPE_GAME_POKER = 0xf214;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ RSOBJ = p3service.o p3chatservice.o p3msgservice.o \
|
||||||
p3status.o \
|
p3status.o \
|
||||||
p3Qblog.o \
|
p3Qblog.o \
|
||||||
p3forums.o \
|
p3forums.o \
|
||||||
p3channels.o
|
p3channels.o \
|
||||||
|
p3portservice.o
|
||||||
|
|
||||||
# dummy forums interface.
|
# dummy forums interface.
|
||||||
# p3forums-dummy.o \
|
# p3forums-dummy.o \
|
||||||
|
|
123
libretroshare/src/services/p3portservice.cc
Normal file
123
libretroshare/src/services/p3portservice.cc
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* "$Id: p3PortService.cc,v 1.24 2007-05-05 16:10:06 rmf24 Exp $"
|
||||||
|
*
|
||||||
|
* Other Bits for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2006 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".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "services/p3portservice.h"
|
||||||
|
#include "serialiser/rsserviceids.h"
|
||||||
|
|
||||||
|
p3PortService::p3PortService(p3ConnectMgr *cm)
|
||||||
|
:p3Service(RS_SERVICE_TYPE_PORT), mConnMgr(cm), mEnabled(false)
|
||||||
|
{
|
||||||
|
/* For Version 1, we'll just use the very simple RsRawItem packets
|
||||||
|
* which are handled in the RsServiceSerialiser
|
||||||
|
*/
|
||||||
|
addSerialType(new RsServiceSerialiser());
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3PortService::tick()
|
||||||
|
{
|
||||||
|
#ifdef PORT_DEBUG
|
||||||
|
std::cerr << "p3PortService::tick()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* discard data if not enabled */
|
||||||
|
if (!mEnabled)
|
||||||
|
{
|
||||||
|
RsItem *i;
|
||||||
|
while(NULL != (i = recvItem()))
|
||||||
|
{
|
||||||
|
delete i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rough list of what might happen (once the sockets are opened!) */
|
||||||
|
|
||||||
|
|
||||||
|
/* check for data on sockets */
|
||||||
|
int sockfd;
|
||||||
|
RsRawItem *item;
|
||||||
|
|
||||||
|
//while(0 < (len = recv(sockfd, ....))) ... etc.
|
||||||
|
{
|
||||||
|
|
||||||
|
/* example of how to package data up
|
||||||
|
* We use RsRawItem as it'll handle a single binary chunk.
|
||||||
|
* This is enough for version 1.... but versions 2 + 3 will
|
||||||
|
* need their own serialiser.
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
|
||||||
|
/* input data TODO! */
|
||||||
|
void *data;
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
|
uint32_t packetId = (((uint32_t) RS_PKT_VERSION_SERVICE) << 24) +
|
||||||
|
(((uint32_t) RS_SERVICE_TYPE_PORT) << 8);
|
||||||
|
|
||||||
|
/* create Packet for RS Transport */
|
||||||
|
RsRawItem *item = new RsRawItem(packetId, len);
|
||||||
|
void *item_data = item->getRawData();
|
||||||
|
memcpy(item_data, data, len);
|
||||||
|
|
||||||
|
/* set the correct peer destination. */
|
||||||
|
item->PeerId(mPeerId);
|
||||||
|
|
||||||
|
/* send data */
|
||||||
|
sendItem(item);
|
||||||
|
|
||||||
|
/* no delete -> packet cleaned up by RS internals */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* get any incoming data */
|
||||||
|
while(NULL != (item = (RsRawItem*) recvItem()))
|
||||||
|
{
|
||||||
|
/* unpackage data */
|
||||||
|
std::string src = item->PeerId();
|
||||||
|
void *item_data = item->getRawData();
|
||||||
|
uint32_t item_len = item->getRawLength();
|
||||||
|
|
||||||
|
/* push out to the socket .... */
|
||||||
|
// send(sockfd, item_len, item_data....)
|
||||||
|
|
||||||
|
/* cleanup packet */
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3PortService::enablePortForwarding(uint32_t port, std::string peerId)
|
||||||
|
{
|
||||||
|
mPort = port;
|
||||||
|
mPeerId = peerId;
|
||||||
|
mEnabled = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
88
libretroshare/src/services/p3portservice.h
Normal file
88
libretroshare/src/services/p3portservice.h
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* libretroshare/src/services: p3portservice.h
|
||||||
|
*
|
||||||
|
* Services for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 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 SERVICE_PORT_FORWARD_HEADER
|
||||||
|
#define SERVICE_PORT_FORWARD_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The start of a port forwarding service.
|
||||||
|
*
|
||||||
|
* This is just a very rough example of what might be required for version 1.
|
||||||
|
*
|
||||||
|
* FIRST VERSION:
|
||||||
|
*
|
||||||
|
* listen to a single port and send data with a single RS peer.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* SECOND VERSION:
|
||||||
|
*
|
||||||
|
* enable multiple port forwardings.
|
||||||
|
*
|
||||||
|
* each forwarding consists of a 'port, peerId & Connection Id'.
|
||||||
|
*
|
||||||
|
* THIRD VERSION:
|
||||||
|
*
|
||||||
|
* add broadcast/multicast forwardings.
|
||||||
|
* i.e. data gets sent to multiple peers.
|
||||||
|
*
|
||||||
|
* each forwarding with then consist of 'port, connectionId + list of peerIds'
|
||||||
|
* NOTE: version 3 needs some thought - might require a master host
|
||||||
|
* which distributes to all others.... or other more complicated systems.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "serialiser/rsbaseitems.h"
|
||||||
|
#include "services/p3service.h"
|
||||||
|
#include "pqi/p3connmgr.h"
|
||||||
|
|
||||||
|
|
||||||
|
class p3PortService: public p3Service
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
p3PortService(p3ConnectMgr *cm);
|
||||||
|
|
||||||
|
/* example setup functions */
|
||||||
|
bool enablePortForwarding(uint32_t port, std::string peerId);
|
||||||
|
|
||||||
|
/* overloaded */
|
||||||
|
virtual int tick();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
p3ConnectMgr *mConnMgr;
|
||||||
|
|
||||||
|
bool mEnabled;
|
||||||
|
bool mPeerOnline;
|
||||||
|
|
||||||
|
uint32_t mPort;
|
||||||
|
std::string mPeerId;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SERVICE_PORT_FORWARD_HEADER
|
Loading…
Add table
Add a link
Reference in a new issue