mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-19 22:40:36 -04:00
Added basic ZeroConf interface.
- registers oneself, browses and resolves services. - Lots still TODO: - parse TxtRecords. - Track peers. - feedback to libretroshare - etc, etc. Enabled ZeroConf in libretroshare.pro & rsinit.cc. Compiles and runs on OSX. Added RelayHandler to Dht, to enable external control of Relays. Marked pqiAssist Interface for changes... will be revamped with ZeroConf. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4727 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2048bb5e47
commit
4d2175636e
9 changed files with 1488 additions and 19 deletions
|
@ -91,6 +91,8 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm,
|
|||
|
||||
mPeerSharer = NULL;
|
||||
|
||||
mRelayHandler = NULL;
|
||||
|
||||
std::string dhtVersion = "RS51"; // should come from elsewhere!
|
||||
mOwnRsId = id;
|
||||
|
||||
|
@ -162,6 +164,23 @@ void p3BitDht::setupPeerSharer(pqiNetAssistPeerShare *sharer)
|
|||
mPeerSharer = sharer;
|
||||
}
|
||||
|
||||
|
||||
/* Support for Outsourced Relay Handling */
|
||||
|
||||
void p3BitDht::installRelayHandler(p3BitDhtRelayHandler *handler)
|
||||
{
|
||||
/* The Handler is mutex protected, as its installation can occur when the dht is already running */
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
|
||||
mRelayHandler = handler;
|
||||
}
|
||||
|
||||
UdpRelayReceiver *p3BitDht::getRelayReceiver()
|
||||
{
|
||||
return mRelay;
|
||||
}
|
||||
|
||||
|
||||
void p3BitDht::start()
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
|
|
|
@ -118,6 +118,21 @@ class PeerAction
|
|||
|
||||
|
||||
|
||||
/******
|
||||
* Adding the ability to install alternative Handler
|
||||
* for monitoring/controlling Relay Connections outside of p3bitdht.
|
||||
***/
|
||||
|
||||
class p3BitDhtRelayHandler
|
||||
{
|
||||
public:
|
||||
|
||||
int (*mInstallRelay)(const bdId *srcId, const bdId *destId, uint32_t mode, uint32_t &bandwidth);
|
||||
int (*mLogFailedConnection)(const bdId *srcId, const bdId *destId, uint32_t mode, uint32_t errcode);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class UdpRelayReceiver;
|
||||
class UdpStunner;
|
||||
|
@ -251,6 +266,14 @@ void UdpConnectionFailed_locked(DhtPeerDetails *dpd);
|
|||
void ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrChgLikely);
|
||||
|
||||
|
||||
/*** RELAY HANDLER CODE ***/
|
||||
void installRelayHandler(p3BitDhtRelayHandler *);
|
||||
UdpRelayReceiver *getRelayReceiver();
|
||||
|
||||
int RelayHandler_InstallRelayConnection(const bdId *srcId, const bdId *destId, uint32_t mode, uint32_t &bandwidth);
|
||||
int RelayHandler_LogFailedProxyAttempt(const bdId *srcId, const bdId *destId, uint32_t mode, uint32_t errcode);
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
************************** Internal Accounting (p3bitdht_peers.cc) ****************************
|
||||
************************************************************************************************/
|
||||
|
@ -264,6 +287,9 @@ void ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrChgLikely);
|
|||
//int addOther(const std::string pid);
|
||||
int removePeer(const std::string pid);
|
||||
|
||||
// Can be used externally too.
|
||||
int calculateNodeId(const std::string pid, bdNodeId *id);
|
||||
|
||||
private:
|
||||
|
||||
DhtPeerDetails *addInternalPeer_locked(const std::string pid, int type);
|
||||
|
@ -276,7 +302,6 @@ int lookupNodeId_locked(const std::string pid, bdNodeId *id);
|
|||
int lookupRsId_locked(const bdNodeId *id, std::string &pid);
|
||||
int storeTranslation_locked(const std::string pid);
|
||||
int removeTranslation_locked(const std::string pid);
|
||||
int calculateNodeId(const std::string pid, bdNodeId *id);
|
||||
|
||||
UdpBitDht *mUdpBitDht; /* has own mutex, is static except for creation/destruction */
|
||||
UdpStunner *mDhtStunner;
|
||||
|
@ -289,6 +314,9 @@ int calculateNodeId(const std::string pid, bdNodeId *id);
|
|||
|
||||
RsMutex dhtMtx;
|
||||
|
||||
|
||||
p3BitDhtRelayHandler *mRelayHandler;
|
||||
|
||||
std::string mOwnRsId;
|
||||
bdNodeId mOwnDhtId;
|
||||
|
||||
|
|
|
@ -516,6 +516,13 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
|
|||
bdStdPrintId(std::cerr, destId);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* if there is an error code - then it is just to inform us of a failed attempt */
|
||||
if (errcode)
|
||||
{
|
||||
RelayHandler_LogFailedProxyAttempt(srcId, destId, mode, errcode);
|
||||
/* END MID FAILED ATTEMPT */
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t bandwidth = 0;
|
||||
|
||||
|
@ -1622,7 +1629,7 @@ int p3BitDht::checkProxyAllowed(const bdId *srcId, const bdId *destId, int mode,
|
|||
/* will install the Relay Here... so that we reserve the Relay Space for later.
|
||||
* decide on relay bandwidth limitation as well
|
||||
*/
|
||||
if (installRelayConnection(srcId, destId, bandwidth))
|
||||
if (RelayHandler_InstallRelayConnection(srcId, destId, mode, bandwidth))
|
||||
{
|
||||
#ifdef DEBUG_PEERNET
|
||||
std::cerr << "p3BitDht::checkProxyAllowed() Successfully added Relay, Connection OKAY";
|
||||
|
@ -2385,4 +2392,43 @@ void p3BitDht::ConnectionFeedback(std::string pid, int mode)
|
|||
}
|
||||
|
||||
|
||||
/***** Check for a RelayHandler... and call its functions preferentially */
|
||||
|
||||
int p3BitDht::RelayHandler_LogFailedProxyAttempt(const bdId *srcId, const bdId *destId, uint32_t mode, uint32_t errcode)
|
||||
{
|
||||
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
|
||||
if ((mRelayHandler) && (mRelayHandler->mLogFailedConnection))
|
||||
{
|
||||
return mRelayHandler->mLogFailedConnection(srcId, destId, mode, errcode);
|
||||
}
|
||||
}
|
||||
|
||||
/* NO standard handler */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int p3BitDht::RelayHandler_InstallRelayConnection(const bdId *srcId, const bdId *destId,
|
||||
uint32_t mode, uint32_t &bandwidth)
|
||||
{
|
||||
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
|
||||
if ((mRelayHandler) && (mRelayHandler->mInstallRelay))
|
||||
{
|
||||
return mRelayHandler->mInstallRelay(srcId, destId, mode, bandwidth);
|
||||
}
|
||||
}
|
||||
|
||||
/* standard handler */
|
||||
return installRelayConnection(srcId, destId, bandwidth);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue