mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-26 07:16:11 -05:00
Improvements to DHT, to support UDP connections.
* Changed getDhtPeerAddress() / Value() function to use const *bdNodeId. * Filled in getDhtPeerAddress()... to support UDP connections. * fixed bug in bdnode:: pong msg... wasn't checking if version existed. * printed out version string, as part of debug. * added IpAddr field to bdmanager peer search data. * stored IpAddr from queries... when peer found. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3604 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
26491f4b73
commit
20a49a59cf
@ -173,8 +173,8 @@ virtual void addCallback(BitDhtCallback *cb) = 0;
|
||||
virtual void removeCallback(BitDhtCallback *cb) = 0;
|
||||
|
||||
/***** Get Results Details *****/
|
||||
virtual int getDhtPeerAddress(bdNodeId *id, struct sockaddr_in &from) = 0;
|
||||
virtual int getDhtValue(bdNodeId *id, std::string key, std::string &value) = 0;
|
||||
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from) = 0;
|
||||
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -94,6 +94,10 @@ void bdNodeManager::addFindNode(bdNodeId *id, uint32_t qflags)
|
||||
peer.mId.id = (*id);
|
||||
peer.mStatus = BITDHT_QUERY_READY; //QUERYING;
|
||||
peer.mQFlags = qflags;
|
||||
|
||||
peer.mDhtAddr.sin_addr.s_addr = 0;
|
||||
peer.mDhtAddr.sin_port = 0;
|
||||
|
||||
mActivePeers[*id] = peer;
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::addFindNode() Added QueryPeer as READY....";
|
||||
@ -291,6 +295,7 @@ int bdNodeManager::checkStatus()
|
||||
bool doPing = false;
|
||||
bool doRemove = false;
|
||||
bool doCallback = false;
|
||||
bool doSaveAddress = false;
|
||||
uint32_t callbackStatus = 0;
|
||||
|
||||
switch(it->second.mStatus)
|
||||
@ -358,6 +363,7 @@ int bdNodeManager::checkStatus()
|
||||
//foundId =
|
||||
doRemove = true;
|
||||
doCallback = true;
|
||||
doSaveAddress = true;
|
||||
callbackStatus = BITDHT_MGR_QUERY_PEER_ONLINE;
|
||||
}
|
||||
break;
|
||||
@ -422,6 +428,18 @@ int bdNodeManager::checkStatus()
|
||||
pit->second.mStatus = it->second.mStatus;
|
||||
}
|
||||
|
||||
if (doSaveAddress)
|
||||
{
|
||||
if (it->second.mResults.size() > 0)
|
||||
{
|
||||
pit->second.mDhtAddr = it->second.mResults.front().addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pit->second.mDhtAddr.sin_addr.s_addr = 0;
|
||||
pit->second.mDhtAddr.sin_port = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* add successful queries to ping list */
|
||||
if (doPing)
|
||||
@ -553,7 +571,7 @@ void bdNodeManager::findDhtValue(bdNodeId * /*id*/, std::string /*key*/, uint32_
|
||||
|
||||
|
||||
/***** Get Results Details *****/
|
||||
int bdNodeManager::getDhtPeerAddress(bdNodeId *id, struct sockaddr_in & /*from*/)
|
||||
int bdNodeManager::getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from)
|
||||
{
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::getDhtPeerAddress() Id: ";
|
||||
@ -563,10 +581,34 @@ int bdNodeManager::getDhtPeerAddress(bdNodeId *id, struct sockaddr_in & /*from*/
|
||||
(void) id;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
std::map<bdNodeId, bdQueryPeer>::iterator pit;
|
||||
pit = mActivePeers.find(*id);
|
||||
|
||||
std::cerr << "bdNodeManager::getDhtPeerAddress() Id: ";
|
||||
mFns->bdPrintNodeId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (pit != mActivePeers.end())
|
||||
{
|
||||
std::cerr << "bdNodeManager::getDhtPeerAddress() Found ActiveQuery";
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (pit->second.mStatus == BITDHT_QUERY_SUCCESS)
|
||||
{
|
||||
from = pit->second.mDhtAddr;
|
||||
|
||||
std::cerr << "bdNodeManager::getDhtPeerAddress() Found Peer Address:";
|
||||
std::cerr << inet_ntoa(from.sin_addr) << ":" << htons(from.sin_port);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int bdNodeManager::getDhtValue(bdNodeId *id, std::string key, std::string & /*value*/)
|
||||
int bdNodeManager::getDhtValue(const bdNodeId *id, std::string key, std::string & /*value*/)
|
||||
{
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::getDhtValue() Id: ";
|
||||
|
@ -66,6 +66,7 @@ class bdQueryPeer
|
||||
uint32_t mQFlags;
|
||||
time_t mLastQuery;
|
||||
time_t mLastFound;
|
||||
struct sockaddr_in mDhtAddr;
|
||||
};
|
||||
|
||||
|
||||
@ -108,8 +109,8 @@ virtual void addCallback(BitDhtCallback *cb);
|
||||
virtual void removeCallback(BitDhtCallback *cb);
|
||||
|
||||
/***** Get Results Details *****/
|
||||
virtual int getDhtPeerAddress(bdNodeId *id, struct sockaddr_in &from);
|
||||
virtual int getDhtValue(bdNodeId *id, std::string key, std::string &value);
|
||||
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from);
|
||||
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value);
|
||||
|
||||
/******************* Internals *************************/
|
||||
|
||||
|
@ -1348,27 +1348,40 @@ void bdNode::msgin_pong(bdId *id, bdToken *transId, bdToken *versionId)
|
||||
bool sameAppl = false;
|
||||
bool sameVersion = false;
|
||||
|
||||
/* check two bytes */
|
||||
if ((versionId->len > 2) && (mDhtVersion.size() > 2) &&
|
||||
(versionId->data[0] == mDhtVersion[0]) && (versionId->data[1] == mDhtVersion[1]))
|
||||
if (versionId)
|
||||
{
|
||||
sameDhtEngine = true;
|
||||
|
||||
#ifdef DEBUG_NODE_MSGIN
|
||||
std::cerr << "bdNode::msgin_pong() Peer Version: ";
|
||||
for(int i = 0; i < versionId->len; i++)
|
||||
{
|
||||
std::cerr << versionId->data[i];
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* check two bytes */
|
||||
if ((versionId->len > 2) && (mDhtVersion.size() > 2) &&
|
||||
(versionId->data[0] == mDhtVersion[0]) && (versionId->data[1] == mDhtVersion[1]))
|
||||
{
|
||||
sameDhtEngine = true;
|
||||
}
|
||||
|
||||
/* check two bytes */
|
||||
if ((versionId->len > 4) && (mDhtVersion.size() > 4) &&
|
||||
(versionId->data[2] == mDhtVersion[2]) && (versionId->data[3] == mDhtVersion[3]))
|
||||
{
|
||||
sameAppl = true;
|
||||
}
|
||||
|
||||
/* check two bytes */
|
||||
if ((versionId->len > 6) && (mDhtVersion.size() > 6) &&
|
||||
(versionId->data[4] == mDhtVersion[4]) && (versionId->data[5] == mDhtVersion[5]))
|
||||
{
|
||||
sameVersion = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* check two bytes */
|
||||
if ((versionId->len > 4) && (mDhtVersion.size() > 4) &&
|
||||
(versionId->data[2] == mDhtVersion[2]) && (versionId->data[3] == mDhtVersion[3]))
|
||||
{
|
||||
sameAppl = true;
|
||||
}
|
||||
|
||||
/* check two bytes */
|
||||
if ((versionId->len > 6) && (mDhtVersion.size() > 6) &&
|
||||
(versionId->data[4] == mDhtVersion[4]) && (versionId->data[5] == mDhtVersion[5]))
|
||||
{
|
||||
sameVersion = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t peerflags = BITDHT_PEER_STATUS_RECV_PONG; /* should have id too */
|
||||
if (sameDhtEngine)
|
||||
|
@ -103,14 +103,14 @@ void UdpBitDht::removeCallback(BitDhtCallback *cb)
|
||||
mBitDhtManager->removeCallback(cb);
|
||||
}
|
||||
|
||||
int UdpBitDht::getDhtPeerAddress(bdNodeId *id, struct sockaddr_in &from)
|
||||
int UdpBitDht::getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from)
|
||||
{
|
||||
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||
|
||||
return mBitDhtManager->getDhtPeerAddress(id, from);
|
||||
}
|
||||
|
||||
int UdpBitDht::getDhtValue(bdNodeId *id, std::string key, std::string &value)
|
||||
int UdpBitDht::getDhtValue(const bdNodeId *id, std::string key, std::string &value)
|
||||
{
|
||||
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||
|
||||
|
@ -68,8 +68,8 @@ virtual void addCallback(BitDhtCallback *cb);
|
||||
virtual void removeCallback(BitDhtCallback *cb);
|
||||
|
||||
/***** Get Results Details *****/
|
||||
virtual int getDhtPeerAddress(bdNodeId *id, struct sockaddr_in &from);
|
||||
virtual int getDhtValue(bdNodeId *id, std::string key, std::string &value);
|
||||
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from);
|
||||
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value);
|
||||
|
||||
/******************* Internals *************************/
|
||||
/***** Iteration / Loop Management *****/
|
||||
|
Loading…
x
Reference in New Issue
Block a user