Added External Interface to control "Attached" Mode

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4483 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-21 11:23:56 +00:00
parent d0f52f1d5f
commit f6002b3981
7 changed files with 32 additions and 2 deletions

View File

@ -322,6 +322,8 @@ virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t m
uint32_t bandwidth, uint32_t delay, uint32_t answer) = 0;
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags) = 0;
virtual bool setAttachMode(bool on) = 0;
/***** Add / Remove Callback Clients *****/
virtual void addCallback(BitDhtCallback *cb) = 0;

View File

@ -144,6 +144,21 @@ uint32_t bdNodeManager::statsBDVersionSize()
return mBdNetworkSize;
}
bool bdNodeManager::setAttachMode(bool on)
{
if (on)
{
setNodeOptions(BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT);
}
else
{
setNodeOptions(0);
}
return on;
}
void bdNodeManager::addFindNode(bdNodeId *id, uint32_t qflags)
{

View File

@ -126,6 +126,7 @@ virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId,
uint32_t mode, uint32_t loc, uint32_t bandwidth, uint32_t delay, uint32_t answer);
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags);
virtual bool setAttachMode(bool on);
/* stats and Dht state */
virtual int startDht();

View File

@ -92,11 +92,11 @@ void bdNode::setNodeOptions(uint32_t optFlags)
mNodeOptionFlags = optFlags;
if (optFlags & BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT)
{
mNodeSpace.setAttachedFlag(BITDHT_PEER_STATUS_DHT_ENGINE, ATTACH_NUMBER);
mNodeSpace.setAttachedFlag(BITDHT_PEER_STATUS_DHT_ENGINE | BITDHT_PEER_STATUS_DHT_ENGINE_VERSION, ATTACH_NUMBER);
}
else
{
mNodeSpace.setAttachedFlag(BITDHT_PEER_STATUS_DHT_ENGINE, 0);
mNodeSpace.setAttachedFlag(BITDHT_PEER_STATUS_DHT_ENGINE | BITDHT_PEER_STATUS_DHT_ENGINE_VERSION, 0);
}
}

View File

@ -547,10 +547,14 @@ int bdSpace::updateAttachedPeers()
bool doAttached = (mAttachedCount > 0);
int attachedCount = 0;
// Must scan through - otherwise we can never remove Attached state.
// It is only once every 10 minutes or so!
#if 0
if (!doAttached)
{
return 0;
}
#endif
std::map<bdMetric, bdId> closest;
std::map<bdMetric, bdId>::iterator mit;

View File

@ -150,6 +150,13 @@ void UdpBitDht::ConnectionOptions(uint32_t allowedModes, uint32_t flags)
mBitDhtManager->ConnectionOptions(allowedModes, flags);
}
bool UdpBitDht::setAttachMode(bool on)
{
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
return mBitDhtManager->setAttachMode(on);
}
int UdpBitDht::getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from)
{

View File

@ -72,6 +72,7 @@ virtual bool ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint
virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc,
uint32_t bandwidth, uint32_t delay, uint32_t answer);
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags);
virtual bool setAttachMode(bool on);
/***** Get Results Details *****/
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from);