Merged Changes /branches/v0.5-peernet/libretroshare/:r4237-4358

Major changes are:
 * Improvements to tcponudp library to allow multiple UdpStacks / ports, with alternative recievers.
 * Resurrected the UdpStunner code, and improved it.
 * Added UdpRelay code.
 * Modified startup code and ssludp code to use the new tcponudp and add a stunner.
 * fixed buggy rs_inet_ntoa
 * fixed a bunch of apple gcc warnings. mainly for(;;); => for(;;) ;

These changes shouldn't affect libretroshare stability... those changes will follow!




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4359 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-06-29 18:02:44 +00:00
parent d58f838269
commit b683e663d6
19 changed files with 1679 additions and 151 deletions

View file

@ -25,7 +25,13 @@
*
*/
#ifdef WINDOWS_SYS
#include "util/rswin.h"
#endif
#ifndef WINDOWS_SYS
#include <netinet/in.h>
#endif
#include "tcponudp/rsudpstack.h"
#include "util/rsthreads.h"
@ -60,7 +66,10 @@ class TouStunPeer
time_t lastsend;
uint32_t failCount;
};
/*
* #define UDPSTUN_ALLOW_LOCALNET 1
*/
class UdpStunner: public UdpSubReceiver
{
@ -69,13 +78,17 @@ class UdpStunner: public UdpSubReceiver
UdpStunner(UdpPublisher *pub);
virtual ~UdpStunner() { return; }
bool setStunKeepAlive(uint32_t required);
#ifdef UDPSTUN_ALLOW_LOCALNET
// For Local Testing Mode.
void SetAcceptLocalNet();
#endif
void setTargetStunPeriod(uint32_t sec_per_stun);
bool addStunPeer(const struct sockaddr_in &remote, const char *peerid);
bool getStunPeer(int idx, std::string &id,
struct sockaddr_in &remote, struct sockaddr_in &eaddr,
uint32_t &failCount, time_t &lastSend);
bool checkStunKeepAlive();
bool needStunPeers();
bool externalAddr(struct sockaddr_in &remote, uint8_t &stable);
@ -89,17 +102,20 @@ virtual int status(std::ostream &out);
private:
bool checkStunDesired();
bool attemptStun();
int doStun(struct sockaddr_in stun_addr);
bool storeStunPeer(const struct sockaddr_in &remote, const char *peerid, bool sent);
/* STUN handling */
bool locked_handleStunPkt(void *data, int size, struct sockaddr_in &from);
int doStun(struct sockaddr_in stun_addr);
/* stun keepAlive */
bool locked_printStunList();
bool locked_recvdStun(const struct sockaddr_in &remote, const struct sockaddr_in &extaddr);
bool locked_checkExternalAddress();
bool storeStunPeer(const struct sockaddr_in &remote, const char *peerid, bool sent);
RsMutex stunMtx; /* for all class data (below) */
@ -109,12 +125,22 @@ bool storeStunPeer(const struct sockaddr_in &remote, const char *peerid, bool
bool eaddrStable; /* if true then usable. if false -> Symmettric NAT */
time_t eaddrTime;
bool mStunKeepAlive;
time_t mStunLastRecv;
time_t mStunLastSend;
time_t mStunLastRecvResp;
time_t mStunLastRecvAny;
time_t mStunLastSendStun;
time_t mStunLastSendAny;
std::list<TouStunPeer> mStunList; /* potentials */
#ifdef UDPSTUN_ALLOW_LOCALNET
// For Local Testing Mode.
bool mAcceptLocalNet;
#endif
bool mPassiveStunMode;
uint32_t mTargetStunPeriod;
double mSuccessRate;
};
/* generic stun functions */