mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-24 14:20:44 -04:00
Merge pull request #426 from sehraf/pr-disable-dht-stunner
This patch set adds an option to use the DHT stunner to qmake
This commit is contained in:
commit
c15c979851
11 changed files with 100 additions and 28 deletions
|
@ -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 "retroshare/rsbanlist.h"
|
||||
|
||||
|
@ -109,8 +111,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;
|
||||
|
@ -191,13 +195,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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -149,7 +149,7 @@ int p3BitDht::getNetFailedPeer(std::string peerId, PeerStatus &status)
|
|||
std::string p3BitDht::getUdpAddressString()
|
||||
{
|
||||
std::string out;
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
struct sockaddr_in extAddr;
|
||||
uint8_t extStable;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -683,7 +686,6 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
|
|||
#endif
|
||||
|
||||
struct sockaddr_in extaddr;
|
||||
uint8_t extStable = 0;
|
||||
sockaddr_clear(&extaddr);
|
||||
|
||||
bool connectOk = false;
|
||||
|
@ -731,6 +733,9 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
|
|||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
uint8_t extStable = 0;
|
||||
|
||||
UdpStunner *stunner = mProxyStunner;
|
||||
if (!proxyPort)
|
||||
{
|
||||
|
@ -849,6 +854,11 @@ 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;
|
||||
(void) connectOk;
|
||||
(void) exclusivePort;
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
}
|
||||
|
||||
ca.mMode = mode;
|
||||
|
@ -1188,7 +1198,6 @@ int p3BitDht::doActions()
|
|||
else if (action.mMode == BITDHT_CONNECT_MODE_PROXY)
|
||||
{
|
||||
struct sockaddr_in extaddr;
|
||||
uint8_t extStable = 0;
|
||||
sockaddr_clear(&extaddr);
|
||||
bool proxyPort = true;
|
||||
bool exclusivePort = false;
|
||||
|
@ -1234,6 +1243,9 @@ int p3BitDht::doActions()
|
|||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
uint8_t extStable = 0;
|
||||
|
||||
UdpStunner *stunner = mProxyStunner;
|
||||
if (!proxyPort)
|
||||
{
|
||||
|
@ -1333,6 +1345,11 @@ int p3BitDht::doActions()
|
|||
connectionReqFailed = true;
|
||||
failReason = CSB_UPDATE_RETRY_ATTEMPT;
|
||||
}
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
connectionReqFailed = true;
|
||||
failReason = CSB_UPDATE_RETRY_ATTEMPT;
|
||||
(void) connectOk;
|
||||
#endif //RS_USE_DHT_STUNNER
|
||||
}
|
||||
|
||||
if (doConnectionRequest)
|
||||
|
@ -1416,7 +1433,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 +2397,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 +2409,9 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
|
|||
#endif
|
||||
}
|
||||
else
|
||||
#else // RS_USE_DHT_STUNNER
|
||||
(void)addrChgLikely;
|
||||
#endif // RS_USE_DHT_STUNNER
|
||||
{
|
||||
dpd->mExclusiveProxyLock = false;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue