From c05f90bda33d08f38fbc0aa2827b02d45602387c Mon Sep 17 00:00:00 2001 From: drbob Date: Fri, 20 Jan 2012 15:12:02 +0000 Subject: [PATCH] Introduced tracking of Source & ErrCodes associated with every Proxy / Relay connection. - This is mainly for algorithm improvements / debugging. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4823 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libbitdht/src/bitdht/bdconnection.cc | 130 +++++++++++++++++++++------ libbitdht/src/bitdht/bdconnection.h | 34 ++++++- 2 files changed, 134 insertions(+), 30 deletions(-) diff --git a/libbitdht/src/bitdht/bdconnection.cc b/libbitdht/src/bitdht/bdconnection.cc index a6d539bc3..1a79bd284 100644 --- a/libbitdht/src/bitdht/bdconnection.cc +++ b/libbitdht/src/bitdht/bdconnection.cc @@ -259,6 +259,12 @@ int bdConnectManager::killConnectionRequest(struct sockaddr_in *laddr, bdNodeId BITDHT_CONNECT_ERROR_USER; +#ifdef DEBUG_PROXY_CONNECTION + std::cerr << "bdConnectManager::killConnectionRequest() Flagging Connection Request as DONE"; + std::cerr << std::endl; + // Print Connection Attempt. + std::cerr << it->second << std::endl; +#endif return 1; } @@ -293,8 +299,14 @@ int bdConnectManager::requestConnection_direct(struct sockaddr_in *laddr, bdNode connreq.setupDirectConnection(laddr, target); - mQueryMgr->result(target, connreq.mGoodProxies); - + std::list goodProxies; + std::list::iterator pit; + mQueryMgr->result(target, goodProxies); + for(pit = goodProxies.begin(); pit != goodProxies.end(); pit++) + { + connreq.mGoodProxies.push_back(bdProxyId(*pit, BD_PI_SRC_QUERYRESULT, 0)); + } + /* now look in the bdSpace as well */ if (connreq.mGoodProxies.size() < MIN_START_DIRECT_COUNT) { @@ -302,16 +314,22 @@ int bdConnectManager::requestConnection_direct(struct sockaddr_in *laddr, bdNode int with_flag = BITDHT_PEER_STATUS_DHT_ENGINE_VERSION; std::list matchIds; std::list::iterator it; - std::list::iterator pit; + std::list::iterator git; + mNodeSpace->find_node(target, number, matchIds, with_flag); /* merge lists (costly should use sets or something) */ for(it = matchIds.begin(); it != matchIds.end(); it++) { - pit = std::find(connreq.mGoodProxies.begin(), connreq.mGoodProxies.end(), *it); - if (pit != connreq.mGoodProxies.end()) + for(git = connreq.mGoodProxies.begin(); git != connreq.mGoodProxies.end(); git++) { - connreq.mGoodProxies.push_back(*it); + if (git->id == *it) + break; + } + + if (git == connreq.mGoodProxies.end()) + { + connreq.mGoodProxies.push_back(bdProxyId(*it, BD_PI_SRC_NODESPACE_ENGINEVERSION, 0)); } } } @@ -417,7 +435,7 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI mFns->bdPrintId(std::cerr, &(*pit)); std::cerr << std::endl; #endif - connreq.mGoodProxies.push_back(*pit); + connreq.mGoodProxies.push_back(bdProxyId(*pit, BD_PI_SRC_QUERYPROXY, 0)); } } @@ -445,7 +463,7 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI mFns->bdPrintId(std::cerr, &(it->second)); std::cerr << std::endl; #endif - connreq.mGoodProxies.push_back(it->second); + connreq.mGoodProxies.push_back(bdProxyId(it->second, BD_PI_SRC_NODESPACE_SERVER, 0)); } } @@ -466,7 +484,7 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI mFns->bdPrintId(std::cerr, &(it->second)); std::cerr << std::endl; #endif - connreq.mGoodProxies.push_back(it->second); + connreq.mGoodProxies.push_back(bdProxyId(it->second, BD_PI_SRC_NODESPACE_FRIEND, 0)); } } @@ -481,7 +499,7 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI mFns->bdPrintId(std::cerr, &(*pit)); std::cerr << std::endl; #endif - connreq.mGoodProxies.push_back(*pit); + connreq.mGoodProxies.push_back(bdProxyId(*pit, BD_PI_SRC_QUERYPROXY, 0)); } } @@ -518,7 +536,6 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI { connreq.mPotentialProxies.push_back(*pit); - // If the pings come back will be handled by // updatePotentialConnectionProxy() @@ -886,8 +903,8 @@ void bdConnectManager::iterateConnectionRequests() // Cleanup if (now - it->second.mStateTS > BITDHT_CONNREQUEST_MAX_AGE) { -#ifdef DEBUG_NODE_CONNECTION - std::cerr << "bdConnectManager::iterateConnectionAttempt() Cleaning Old ConnReq: "; +#ifdef DEBUG_PROXY_CONNECTION + std::cerr << "bdConnectManager::iterateConnectionAttempt() Should clean Old ConnReq???: "; std::cerr << std::endl; std::cerr << it->second; std::cerr << std::endl; @@ -917,6 +934,13 @@ void bdConnectManager::iterateConnectionRequests() it = mConnectionRequests.find(*eit); if (it != mConnectionRequests.end()) { +#ifdef DEBUG_PROXY_CONNECTION + std::cerr << "bdConnectManager::iterateConnectionAttempt() Erasing Old Connection Request: "; + std::cerr << std::endl; + std::cerr << it->second; + std::cerr << std::endl; +#endif + mConnectionRequests.erase(it); } } @@ -969,10 +993,13 @@ int bdConnectManager::startConnectionAttempt(bdConnectionRequest *req) srcConnAddr.id = mOwnId; srcConnAddr.addr = req->mLocalAddr; - proxyId = req->mGoodProxies.front(); + bdProxyId pidset = req->mGoodProxies.front(); + proxyId = pidset.id; req->mGoodProxies.pop_front(); req->mCurrentAttempt = proxyId; + req->mCurrentSrcType = pidset.srcType; + //req->mPeersTried.push_back(proxyId); req->mState = BITDHT_CONNREQUEST_INPROGRESS; @@ -1349,12 +1376,12 @@ void bdConnectManager::callbackConnectRequest(bdId *srcId, bdId *proxyId, bdId * if (recycle) { /* rotate around */ - cr->mGoodProxies.push_back(cr->mCurrentAttempt); + cr->mGoodProxies.push_back(bdProxyId(cr->mCurrentAttempt, cr->mCurrentSrcType, errcode)); cr->mRecycled++; } else { - cr->mPeersTried.push_back(cr->mCurrentAttempt); + cr->mPeersTried.push_back(bdProxyId(cr->mCurrentAttempt, cr->mCurrentSrcType, errcode)); } /* setup for next one */ @@ -3148,10 +3175,21 @@ int bdConnectionRequest::addGoodProxy(const bdId *srcId) return 0; } - std::list::iterator it = std::find(mPeersTried.begin(), mPeersTried.end(), *srcId); + std::list::iterator it; + for(it = mPeersTried.begin(); it != mPeersTried.end(); it++) + { + if (*srcId == it->id) + break; + } + if (it == mPeersTried.end()) { - it = std::find(mGoodProxies.begin(), mGoodProxies.end(), *srcId); + for(it = mGoodProxies.begin(); it != mGoodProxies.end(); it++) + { + if (*srcId == it->id) + break; + } + if (it == mGoodProxies.end()) { #ifdef DEBUG_NODE_CONNECTION @@ -3160,18 +3198,19 @@ int bdConnectionRequest::addGoodProxy(const bdId *srcId) std::cerr << std::endl; #endif - mGoodProxies.push_back(*srcId); + mGoodProxies.push_back(bdProxyId(*srcId, BD_PI_SRC_ADDGOODPROXY, 0)); /* if it is potentialProxies then remove */ - it = std::find(mPotentialProxies.begin(), mPotentialProxies.end(), *srcId); - if (it != mPotentialProxies.end()) + std::list::iterator pit; + pit = std::find(mPotentialProxies.begin(), mPotentialProxies.end(), *srcId); + if (pit != mPotentialProxies.end()) { #ifdef DEBUG_NODE_CONNECTION std::cerr << "bdConnectionRequest::addGoodProxy() Removing from PotentialProxy List"; std::cerr << std::endl; #endif - it = mPotentialProxies.erase(it); + pit = mPotentialProxies.erase(pit); } return 1; } @@ -3218,21 +3257,24 @@ std::ostream &operator<<(std::ostream &out, const bdConnectionRequest &req) out << "GoodProxies:"; out << std::endl; - std::list::const_iterator it; + std::list::const_iterator it; + std::list::const_iterator pit; for(it = req.mGoodProxies.begin(); it != req.mGoodProxies.end(); it++) { out << "\t"; - bdStdPrintId(out, &(*it)); + bdStdPrintId(out, &(it->id)); + out << ", " << it->proxySrcType(); + out << ", " << decodeConnectionError(it->errcode); out << std::endl; } out << "PotentialProxies:"; out << std::endl; - for(it = req.mPotentialProxies.begin(); it != req.mPotentialProxies.end(); it++) + for(pit = req.mPotentialProxies.begin(); pit != req.mPotentialProxies.end(); pit++) { out << "\t"; - bdStdPrintId(out, &(*it)); + bdStdPrintId(out, &(*pit)); out << std::endl; } @@ -3242,7 +3284,9 @@ std::ostream &operator<<(std::ostream &out, const bdConnectionRequest &req) for(it = req.mPeersTried.begin(); it != req.mPeersTried.end(); it++) { out << "\t"; - bdStdPrintId(out, &(*it)); + bdStdPrintId(out, &(it->id)); + out << ", " << it->proxySrcType(); + out << ", " << decodeConnectionError(it->errcode); out << std::endl; } return out; @@ -3450,4 +3494,34 @@ std::string decodeConnectionError(uint32_t errcode) return totalerror; } - + +std::string bdProxyId::proxySrcType() const +{ + std::string str("Unknown"); + + switch (srcType) { + case BD_PI_SRC_QUERYRESULT: + str = "QueryResult"; + break; + case BD_PI_SRC_QUERYPROXY: + str = "QueryProxy"; + break; + case BD_PI_SRC_NODESPACE_FRIEND: + str = "NodeSpaceFriend"; + break; + case BD_PI_SRC_NODESPACE_SERVER: + str = "NodeSpaceServer"; + break; + case BD_PI_SRC_NODESPACE_ENGINEVERSION: + str = "NodeSpaceEngineVersion"; + break; + case BD_PI_SRC_ADDGOODPROXY: + str = "AddGoodProxy"; + break; + case BD_PI_SRC_UNKNOWN: + default: + break; + } + return str; +} + diff --git a/libbitdht/src/bitdht/bdconnection.h b/libbitdht/src/bitdht/bdconnection.h index aa5cd8492..d8df77659 100644 --- a/libbitdht/src/bitdht/bdconnection.h +++ b/libbitdht/src/bitdht/bdconnection.h @@ -140,6 +140,32 @@ class bdConnection }; +#define BD_PI_SRC_UNKNOWN 0 +#define BD_PI_SRC_QUERYRESULT 1 +#define BD_PI_SRC_QUERYPROXY 2 +#define BD_PI_SRC_NODESPACE_FRIEND 3 +#define BD_PI_SRC_NODESPACE_SERVER 4 +#define BD_PI_SRC_NODESPACE_ENGINEVERSION 5 +#define BD_PI_SRC_ADDGOODPROXY 6 + + +class bdProxyId +{ + public: + + bdProxyId(const bdId &in_id, uint32_t in_srctype, uint32_t errcode) + :id(in_id), srcType(in_srctype) { return; } + + bdProxyId() :srcType(BD_PI_SRC_UNKNOWN) { return; } + + std::string proxySrcType() const; + + bdId id; + uint32_t srcType; + uint32_t errcode; +}; + + class bdConnectionRequest { public: @@ -162,12 +188,16 @@ class bdConnectionRequest int mDelay; time_t mRequestTS; // reference Time for mDelay. - std::list mGoodProxies; + std::list mGoodProxies; std::list mPotentialProxies; + //std::list mGoodProxies; int mRecycled; bdId mCurrentAttempt; - std::list mPeersTried; + uint32_t mCurrentSrcType; + + std::list mPeersTried; + //std::list mPeersTried; }; std::ostream &operator<<(std::ostream &out, const bdConnectionRequest &req);