mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-05 07:35:12 -04:00
Changes to integrate bitdht into libretroshare.
Mainly re-organising tcponudp... tests->test area network->trash (uses libbitdht classes). new udp interfaces (udppeer + udpstunner) Changes include: * p3bitdht: added "addReceiver() call, and more debugging. * p3bitdht: added DO_IDLE flag so searches are continous. * p3bitdht/pqiassist: matched up Assist interface. * fixed pqiNetListener interface. * rsinit/p3connmgr: setup udp init * tcpstream: switched to new udp receiver. * added "blogs" switch in libretroshare.pro (was stopping compiling ;) * added "bitdht" switch in libretroshare.pro git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3323 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c1b624832f
commit
fcdd7ee113
34 changed files with 627 additions and 1770 deletions
|
@ -33,7 +33,7 @@ static const int kInitStreamTable = 5;
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "udplayer.h"
|
||||
#include "udp/udpstack.h"
|
||||
#include "tcpstream.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
@ -55,115 +55,34 @@ typedef struct TcpOnUdp_t TcpOnUdp;
|
|||
static std::vector<TcpOnUdp *> tou_streams;
|
||||
|
||||
static int tou_inited = 0;
|
||||
static UdpSorter *udps = NULL;
|
||||
|
||||
|
||||
#include "udp/udpstack.h"
|
||||
#include "tcponudp/udppeer.h"
|
||||
|
||||
static UdpStack *udpstack = NULL;
|
||||
static UdpPeerReceiver *udps = NULL;
|
||||
|
||||
static int tou_tick_all();
|
||||
|
||||
/* tou_init - opens the udp port (universal bind) */
|
||||
int tou_init(const struct sockaddr *my_addr, socklen_t addrlen)
|
||||
int tou_init(UdpStack *stack)
|
||||
{
|
||||
if (tou_inited)
|
||||
{
|
||||
struct sockaddr_in *addr = (struct sockaddr_in *) my_addr;
|
||||
udps->resetAddress(*addr);
|
||||
if (!(udps->okay()))
|
||||
{
|
||||
std::cerr << "tou_init() FATAL ERROR: Cannot reset Udp Socket to: "
|
||||
<< rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
tou_streams.resize(kInitStreamTable);
|
||||
|
||||
udps = new UdpSorter( *((struct sockaddr_in *) my_addr));
|
||||
|
||||
/* check the bind succeeded */
|
||||
if (!(udps->okay()))
|
||||
{
|
||||
delete (udps);
|
||||
udps = NULL;
|
||||
return -1;
|
||||
}
|
||||
udpstack = stack;
|
||||
udps = new UdpPeerReceiver(stack);
|
||||
stack->addReceiver(udps);
|
||||
|
||||
tou_inited = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* tou_stunpeer supply tou with stun peers. */
|
||||
int tou_stunpeer(const struct sockaddr *my_addr, socklen_t addrlen,
|
||||
const char *id)
|
||||
{
|
||||
if (!tou_inited)
|
||||
return -1;
|
||||
|
||||
udps->addStunPeer(*(struct sockaddr_in *) my_addr, id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tou_stunkeepalive(int required)
|
||||
{
|
||||
if (!tou_inited)
|
||||
return -1;
|
||||
|
||||
udps->setStunKeepAlive(required);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int tou_getstunpeer(int i, struct sockaddr *remote_addr, socklen_t *raddrlen,
|
||||
struct sockaddr *ext_addr, socklen_t *eaddrlen,
|
||||
uint32_t *failCount, time_t *lastSend)
|
||||
{
|
||||
if (!tou_inited)
|
||||
return -1;
|
||||
|
||||
std::string id;
|
||||
|
||||
bool ret = udps->getStunPeer(i, id,
|
||||
*((struct sockaddr_in *) remote_addr),
|
||||
*((struct sockaddr_in *) ext_addr),
|
||||
*failCount, *lastSend);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int tou_needstunpeers()
|
||||
{
|
||||
if (!tou_inited)
|
||||
return -1;
|
||||
|
||||
if (udps->needStunPeers())
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int tou_tick_stunkeepalive()
|
||||
{
|
||||
if (!tou_inited)
|
||||
return -1;
|
||||
|
||||
udps->tick();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tou_extaddr(struct sockaddr *ext_addr, socklen_t *addrlen, uint8_t *stable)
|
||||
{
|
||||
if (!tou_inited)
|
||||
return -1;
|
||||
|
||||
if (udps->externalAddr(*(struct sockaddr_in *) ext_addr, *stable))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* open - which does nothing */
|
||||
int tou_socket(int /*domain*/, int /*type*/, int /*protocol*/)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue