add new option to qmake to enable dht stunner

removed dht stunner code when option is not set
This commit is contained in:
sehraf 2016-06-21 13:55:23 +02:00
parent ddce43b282
commit 4d2d825d5b
10 changed files with 89 additions and 21 deletions

View file

@ -30,7 +30,9 @@
#include "bitdht/bdstddht.h"
#include "tcponudp/udprelay.h"
#ifdef RS_USE_DHT_STUNNER
#include "tcponudp/udpstunner.h"
#endif // RS_USE_DHT_STUNNER
#include <openssl/sha.h>
@ -86,8 +88,10 @@ p3BitDht::p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
UdpStack *udpstack, std::string bootstrapfile,const std::string& filteredipfile)
:p3Config(), pqiNetAssistConnect(id, cb), mNetMgr(nm), dhtMtx("p3BitDht")
{
#ifdef RS_USE_DHT_STUNNER
mDhtStunner = NULL;
mProxyStunner = NULL;
#endif
mRelay = NULL;
mPeerSharer = NULL;
@ -168,13 +172,19 @@ bool p3BitDht::getOwnDhtId(std::string &ownDhtId)
return true;
}
#ifdef RS_USE_DHT_STUNNER
void p3BitDht::setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay)
{
mDhtStunner = dhtStunner;
mProxyStunner = proxyStunner;
mRelay = relay;
}
#else // RS_USE_DHT_STUNNER
void p3BitDht::setupConnectBits(UdpRelayReceiver *relay)
{
mRelay = relay;
}
#endif //RS_USE_DHT_STUNNER
void p3BitDht::setupPeerSharer(pqiNetAssistPeerShare *sharer)
{

View file

@ -136,7 +136,9 @@ class p3BitDhtRelayHandler
class UdpRelayReceiver;
#ifdef RS_USE_DHT_STUNNER
class UdpStunner;
#endif // RS_USE_DHT_STUNNER
class p3NetMgr;
class p3BitDht: public p3Config, public pqiNetAssistConnect, public RsDht
@ -174,8 +176,11 @@ public:
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
************************************************************************************************/
#ifdef RS_USE_DHT_STUNNER
void setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay);
#else // RS_USE_DHT_STUNNER
void setupConnectBits(UdpRelayReceiver *relay);
#endif // RS_USE_DHT_STUNNER
void setupPeerSharer(pqiNetAssistPeerShare *sharer);
void modifyNodesPerBucket(uint16_t count);
@ -359,8 +364,10 @@ private:
int removeTranslation_locked(const RsPeerId& pid);
UdpBitDht *mUdpBitDht; /* has own mutex, is static except for creation/destruction */
#ifdef RS_USE_DHT_STUNNER
UdpStunner *mDhtStunner;
UdpStunner *mProxyStunner;
#endif // RS_USE_DHT_STUNNER
UdpRelayReceiver *mRelay;
p3NetMgr *mNetMgr;

View file

@ -152,7 +152,7 @@ std::string p3BitDht::getUdpAddressString()
struct sockaddr_in extAddr;
uint8_t extStable;
#ifdef RS_USE_DHT_STUNNER
if (mDhtStunner->externalAddr(extAddr, extStable))
{
rs_sprintf_append(out, " DhtExtAddr: %s:%u", rs_inet_ntoa(extAddr.sin_addr).c_str(), ntohs(extAddr.sin_port));
@ -187,7 +187,10 @@ std::string p3BitDht::getUdpAddressString()
{
out += " ProxyExtAddr: Unknown ";
}
#else // RS_USE_DHT_STUNNER
// whitespaces taken from above
out = " DhtExtAddr: Unknown ProxyExtAddr: Unknown ";
#endif // RS_USE_DHT_STUNNER
return out;
}

View file

@ -81,6 +81,7 @@ int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/
mPeerSharer->updatePeer(rsid, tmpaddr, outtype, outreason, outage);
}
#ifdef RS_USE_DHT_STUNNER
/* call to the Stunners to drop the address as well */
/* IDEALLY these addresses should all be filtered at UdpLayer level instead! */
if (mDhtStunner)
@ -91,6 +92,7 @@ int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/
{
mProxyStunner->dropStunPeer(addr);
}
#endif // RS_USE_DHT_STUNNER
return 1;
}
@ -135,7 +137,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
}
}
#ifdef RS_USE_DHT_STUNNER
if ((mProxyStunner) && (mProxyStunner->needStunPeers()))
{
#ifdef DEBUG_BITDHT_COMMON
@ -156,6 +158,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
#endif
mDhtStunner->addStunPeer(id->addr, NULL);
}
#endif // RS_USE_DHT_STUNNER
}
return 1;
}
@ -731,6 +734,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl;
}
#ifdef RS_USE_DHT_STUNNER
UdpStunner *stunner = mProxyStunner;
if (!proxyPort)
{
@ -849,6 +853,9 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl;
#endif
}
#else // RS_USE_DHT_STUNNER
connectionAllowed = BITDHT_CONNECT_ERROR_TEMPUNAVAIL;
#endif // RS_USE_DHT_STUNNER
}
ca.mMode = mode;
@ -1234,6 +1241,7 @@ int p3BitDht::doActions()
std::cerr << std::endl;
}
}
#ifdef RS_USE_DHT_STUNNER
UdpStunner *stunner = mProxyStunner;
if (!proxyPort)
{
@ -1333,6 +1341,10 @@ int p3BitDht::doActions()
connectionReqFailed = true;
failReason = CSB_UPDATE_RETRY_ATTEMPT;
}
#else // RS_USE_DHT_STUNNER
connectionReqFailed = true;
failReason = CSB_UPDATE_RETRY_ATTEMPT;
#endif //RS_USE_DHT_STUNNER
}
if (doConnectionRequest)
@ -1416,7 +1428,9 @@ int p3BitDht::doActions()
{
std::cerr << "PeerAction: ERROR ERROR, we grabd Exclusive Port to do this, trying emergency release";
std::cerr << std::endl;
#ifdef RS_USE_DHT_STUNNER
mProxyStunner->releaseExclusiveMode(pid,false);
#endif // RS_USE_DHT_STUNNER
}
}
}
@ -2378,6 +2392,7 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
if (dpd->mExclusiveProxyLock)
{
#ifdef RS_USE_DHT_STUNNER
if (mProxyStunner->releaseExclusiveMode(pid, addrChgLikely))
{
dpd->mExclusiveProxyLock = false;
@ -2389,6 +2404,7 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
#endif
}
else
#endif // RS_USE_DHT_STUNNER
{
dpd->mExclusiveProxyLock = false;

View file

@ -202,7 +202,7 @@ int p3BitDht::addBadPeer(const struct sockaddr_storage &addr, uint32_t /*reason*
addrv4.sin_addr = ap->sin_addr;
addrv4.sin_port = ap->sin_port;
#ifdef RS_USE_DHT_STUNNER
if (mDhtStunner)
{
mDhtStunner->dropStunPeer(addrv4);
@ -211,7 +211,7 @@ int p3BitDht::addBadPeer(const struct sockaddr_storage &addr, uint32_t /*reason*
{
mProxyStunner->dropStunPeer(addrv4);
}
#endif // RS_USE_DHT_STUNNER
return 1;
}