mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 02:25:34 -04:00
Addition of libbitdht.
============================================================ This is intended to be a completely independent library from RS, (hosted at sf.net/projects/bitdht) hence is being commited at the top level. As initial further development / testing will be driven by RS integration it is being added to the RS repository. Equally important is ensuring that RS can compile without requiring aux libraries. Once libbitdht is further developed, this section of the repository is expected to be removed... But that will not be for a while, I expect. drbob. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3276 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9b72977bba
commit
c415bb6158
56 changed files with 11344 additions and 0 deletions
110
libbitdht/src/udp/udpstack.h
Normal file
110
libbitdht/src/udp/udpstack.h
Normal file
|
@ -0,0 +1,110 @@
|
|||
#ifndef BITDHT_UDP_STACK_RECEIVER_H
|
||||
#define BITDHT_UDP_STACK_RECEIVER_H
|
||||
|
||||
/*
|
||||
* bitdht/udpstack.h
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 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 3 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 "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "util/bdthreads.h"
|
||||
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <map>
|
||||
|
||||
#include "udplayer.h"
|
||||
|
||||
/* UdpStackReceiver is a Generic Receiver of info from a UdpLayer class.
|
||||
* it provides a UdpReceiver class, and accepts a stack of UdpReceivers,
|
||||
* which will be iterated through (in-order) until someone accepts the packet.
|
||||
*
|
||||
* It is important to order these Receivers correctly!
|
||||
*
|
||||
* This infact becomes the holder of the UdpLayer, and all controls
|
||||
* go through the StackReceiver.
|
||||
*/
|
||||
|
||||
class UdpSubReceiver: public UdpReceiver
|
||||
{
|
||||
public:
|
||||
UdpSubReceiver(UdpPublisher *pub);
|
||||
|
||||
/* calls mPublisher->sendPkt */
|
||||
virtual int sendPkt(const void *data, int size, struct sockaddr_in &to, int ttl);
|
||||
/* callback for recved data (overloaded from UdpReceiver) */
|
||||
//virtual int recvPkt(void *data, int size, struct sockaddr_in &from) = 0;
|
||||
|
||||
UdpPublisher *mPublisher;
|
||||
};
|
||||
|
||||
|
||||
class UdpStack: public UdpReceiver, public UdpPublisher
|
||||
{
|
||||
public:
|
||||
|
||||
UdpStack(struct sockaddr_in &local);
|
||||
virtual ~UdpStack() { return; }
|
||||
|
||||
bool resetAddress(struct sockaddr_in &local);
|
||||
|
||||
|
||||
/* add in a receiver */
|
||||
int addReceiver(UdpReceiver *recv);
|
||||
int removeReceiver(UdpReceiver *recv);
|
||||
|
||||
/* Packet IO */
|
||||
/* pass-through send packets */
|
||||
virtual int sendPkt(const void *data, int size, struct sockaddr_in &to, int ttl);
|
||||
/* callback for recved data (overloaded from UdpReceiver) */
|
||||
|
||||
virtual int recvPkt(void *data, int size, struct sockaddr_in &from);
|
||||
|
||||
int status(std::ostream &out);
|
||||
|
||||
/* setup connections */
|
||||
int openSocket();
|
||||
|
||||
/* monitoring / updates */
|
||||
int okay();
|
||||
// int tick();
|
||||
|
||||
int close();
|
||||
|
||||
private:
|
||||
|
||||
UdpLayer *udpLayer;
|
||||
|
||||
bdMutex stackMtx; /* for all class data (below) */
|
||||
|
||||
struct sockaddr_in laddr; /* local addr */
|
||||
|
||||
std::list<UdpReceiver *> mReceivers;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue