diff --git a/libbitdht/src/bitdht/bdconnection.cc b/libbitdht/src/bitdht/bdconnection.cc index 36c5889fc..8e5dd647a 100644 --- a/libbitdht/src/bitdht/bdconnection.cc +++ b/libbitdht/src/bitdht/bdconnection.cc @@ -34,8 +34,12 @@ #include "util/bdnet.h" #include "util/bdrandom.h" -#define DEBUG_NODE_CONNECTION 1 +/* + * #define DEBUG_NODE_CONNECTION 1 + * #define DEBUG_NODE_CONNECTION_EXTRA 1 + */ +#define DEBUG_NODE_CONNECTION 1 #define BITDHT_CR_PAUSE_BASE_PERIOD 5 @@ -386,8 +390,10 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI mNodeSpace->find_nearest_nodes_with_flags(target, number, excluding, nearest, BITDHT_PEER_STATUS_DHT_FOF | BITDHT_PEER_STATUS_DHT_FRIEND); - - number = CONNECT_NUM_PROXY_ATTEMPTS - number; + + // just ask for the same number of closest (above doesn't return anything atm) + //int nFound = nearest.size(); + //number = CONNECT_NUM_PROXY_ATTEMPTS - nFound; mNodeSpace->find_nearest_nodes_with_flags(target, number, excluding, nearest, BITDHT_PEER_STATUS_DHT_ENGINE_VERSION ); @@ -395,10 +401,15 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI std::multimap::iterator it; for(it = nearest.begin(); it != nearest.end(); it++) { - bdNodeId midId; - mFns->bdRandomMidId(target, &(it->second.id), &midId); + std::cerr << "bdConnectManager::requestConnection_proxy() is Entry it connected to Friend? : "; + mFns->bdPrintId(std::cerr, &(it->second)); + std::cerr << std::endl; + + //bdNodeId midId; + //mFns->bdRandomMidId(target, &(it->second.id), &midId); /* trigger search */ - mPub->send_query(&(it->second), &midId); + //mPub->send_query(&(it->second), &midId); + mPub->send_query(&(it->second), target); } } @@ -437,13 +448,13 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI void bdConnectManager::addPotentialConnectionProxy(const bdId *srcId, const bdId *target) { -#ifdef DEBUG_NODE_CONNECTION - //std::cerr << "bdConnectManager::addPotentialConnectionProxy() "; - //std::cerr << " srcId: "; - //bdStdPrintId(std::cerr, srcId); - //std::cerr << " target: "; - //bdStdPrintId(std::cerr, target); - //std::cerr << std::endl; +#ifdef DEBUG_NODE_CONNECTION_EXTRA + std::cerr << "bdConnectManager::addPotentialConnectionProxy() "; + std::cerr << " srcId: "; + bdStdPrintId(std::cerr, srcId); + std::cerr << " target: "; + bdStdPrintId(std::cerr, target); + std::cerr << std::endl; #endif if (!srcId) @@ -461,9 +472,9 @@ void bdConnectManager::addPotentialConnectionProxy(const bdId *srcId, const bdId if (it == mConnectionRequests.end()) { /* not one of our targets... drop it */ -#ifdef DEBUG_NODE_CONNECTION - //std::cerr << "bdConnectManager::addPotentialConnectionProxy() Dropping Not one of Our Targets"; - //std::cerr << std::endl; +#ifdef DEBUG_NODE_CONNECTION_EXTRA + std::cerr << "bdConnectManager::addPotentialConnectionProxy() Dropping Not one of Our Targets"; + std::cerr << std::endl; #endif return; } @@ -537,7 +548,7 @@ void bdConnectManager::updatePotentialConnectionProxy(const bdId *id, uint32_t m { if (mode & BITDHT_PEER_STATUS_DHT_ENGINE_VERSION) { -#ifdef DEBUG_NODE_CONNECTION +#ifdef DEBUG_NODE_CONNECTION_EXTRA std::cerr << "bdConnectManager::updatePotentialConnectionProxy() Peer is GOOD : "; bdStdPrintId(std::cerr, id); std::cerr << std::endl; @@ -574,11 +585,13 @@ void bdConnectManager::iterateConnectionRequests() for(it = mConnectionRequests.begin(); it != mConnectionRequests.end(); it++) { bool erase = false; + +#ifdef DEBUG_NODE_CONNECTION_EXTRA std::cerr << "bdConnectManager::iterateConnectionAttempt() Request is:"; std::cerr << std::endl; std::cerr << it->second; std::cerr << std::endl; - +#endif /* check status of connection */ if (it->second.mState == BITDHT_CONNREQUEST_READY) @@ -586,8 +599,6 @@ void bdConnectManager::iterateConnectionRequests() std::cerr << "bdConnectManager::iterateConnectionAttempt() Request is READY, starting"; std::cerr << std::endl; - - /* kick off the connection if possible */ // goes to BITDHT_CONNREQUEST_INPROGRESS; if (!startConnectionAttempt(&(it->second))) @@ -1761,9 +1772,10 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId bdConnection *conn = findExistingConnectionBySender(id, srcConnAddr, destConnAddr); if (conn) { - /* ERROR */ + /* Likely ERROR: Warning */ #ifdef DEBUG_NODE_CONNECTION - std::cerr << "bdConnectManager::recvedConnectionRequest() ERROR EXISTING CONNECTION"; + std::cerr << "bdConnectManager::recvedConnectionRequest() WARNING Existing Connection: "; + std::cerr << std::endl; std::cerr << std::endl; #endif /* reply existing connection */ diff --git a/libbitdht/src/bitdht/bdconnection.h b/libbitdht/src/bitdht/bdconnection.h index 3e3f1cbc3..9b627254e 100644 --- a/libbitdht/src/bitdht/bdconnection.h +++ b/libbitdht/src/bitdht/bdconnection.h @@ -56,7 +56,7 @@ class bdNodePublisher; #define BD_CONNECTION_START_RETRY_PERIOD 5 // Should only take a couple of seconds to get reply. #define BD_CONNECTION_START_MAX_RETRY 3 -#define BD_CONNECTION_MAX_TIMEOUT 30 +#define BD_CONNECTION_MAX_TIMEOUT 45 diff --git a/libbitdht/src/bitdht/bdiface.h b/libbitdht/src/bitdht/bdiface.h index 5c4c187af..a9c859fd5 100644 --- a/libbitdht/src/bitdht/bdiface.h +++ b/libbitdht/src/bitdht/bdiface.h @@ -272,9 +272,8 @@ class bdQuerySummary #define BITDHT_QFLAGS_NONE 0x0000 #define BITDHT_QFLAGS_DISGUISE 0x0001 #define BITDHT_QFLAGS_DO_IDLE 0x0002 -#define BITDHT_QFLAGS_INTERNAL 0x0004 // means it runs through startup. -#define BITDHT_QFLAGS_QUICK 0x0008 // ONE Request per peer. -#define BITDHT_QFLAGS_UPDATES 0x0010 // Do regular updates. +#define BITDHT_QFLAGS_INTERNAL 0x0004 // runs through startup. +#define BITDHT_QFLAGS_UPDATES 0x0008 // Do regular updates. /* Connect Callback Flags */ #define BITDHT_CONNECT_CB_AUTH 1 diff --git a/libbitdht/src/bitdht/bdmanager.cc b/libbitdht/src/bitdht/bdmanager.cc index f4a663753..3a0275262 100644 --- a/libbitdht/src/bitdht/bdmanager.cc +++ b/libbitdht/src/bitdht/bdmanager.cc @@ -63,6 +63,8 @@ // This is eventually what we want. //#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_ENGINE_VERSION) +#define QUERY_UPDATE_PERIOD 59 // just under one minute... as that gets called every minute... + bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns) :bdNode(id, dhtVersion, bootfile, fns) @@ -170,6 +172,8 @@ void bdNodeManager::addFindNode(bdNodeId *id, uint32_t qflags) peer.mDhtAddr.sin_addr.s_addr = 0; peer.mDhtAddr.sin_port = 0; + peer.mCallbackTS = 0; + mActivePeers[*id] = peer; #ifdef DEBUG_MGR std::cerr << "bdNodeManager::addFindNode() Added QueryPeer as READY...."; @@ -312,7 +316,7 @@ void bdNodeManager::iteration() break; case BITDHT_MGR_STATE_ACTIVE: - if (modeAge > MAX_REFRESH_TIME) + if (modeAge >= MAX_REFRESH_TIME) { #ifdef DEBUG_MGR std::cerr << "bdNodeManager::iteration(): ACTIVE -> REFRESH"; @@ -620,7 +624,7 @@ int bdNodeManager::checkStatus() std::map queryStatus; - mQueryMgr->QueryStatus(queryStatus); + mQueryMgr->QueryStatus(queryStatus); for(it = queryStatus.begin(); it != queryStatus.end(); it++) { @@ -740,14 +744,40 @@ int bdNodeManager::checkStatus() if (pit->second.mStatus == it->second.mStatus) { /* status is unchanged */ - doPing = false; - doCallback = false; #ifdef DEBUG_MGR std::cerr << "bdNodeManager::checkStatus() Status unchanged for : "; mFns->bdPrintNodeId(std::cerr, &(it->first)); std::cerr << " status: " << it->second.mStatus; std::cerr << std::endl; #endif + + + time_t now = time(NULL); + /* now we check if we've done a callback before... */ + if (it->second.mQFlags & BITDHT_QFLAGS_UPDATES) + { + if (now - pit->second.mCallbackTS > QUERY_UPDATE_PERIOD) + { + // keep flags. +#ifdef DEBUG_MGR + std::cerr << "bdNodeManager::checkStatus() Doing Update Callback for"; + mFns->bdPrintNodeId(std::cerr, &(it->first)); + std::cerr << " status: " << it->second.mStatus; + std::cerr << std::endl; +#endif + } + else + { + /* no callback this time */ + doPing = false; + doCallback = false; + } + } + else + { + doPing = false; + doCallback = false; + } } else { @@ -795,6 +825,9 @@ int bdNodeManager::checkStatus() mFns->bdPrintNodeId(std::cerr, &(it->first)); std::cerr << std::endl; #endif + + time_t now = time(NULL); + pit->second.mCallbackTS = now; bdId id(it->first,pit->second.mDhtAddr); doPeerCallback(&id, callbackStatus); } diff --git a/libbitdht/src/bitdht/bdmanager.h b/libbitdht/src/bitdht/bdmanager.h index 4794fabe2..1e25904b8 100644 --- a/libbitdht/src/bitdht/bdmanager.h +++ b/libbitdht/src/bitdht/bdmanager.h @@ -65,9 +65,10 @@ class bdQueryPeer bdId mId; uint32_t mStatus; uint32_t mQFlags; - time_t mLastQuery; - time_t mLastFound; + //time_t mLastQuery; + //time_t mLastFound; struct sockaddr_in mDhtAddr; + time_t mCallbackTS; // for UPDATES flag. }; diff --git a/libbitdht/src/bitdht/bdnode.cc b/libbitdht/src/bitdht/bdnode.cc index 17b5fce26..9200965c8 100644 --- a/libbitdht/src/bitdht/bdnode.cc +++ b/libbitdht/src/bitdht/bdnode.cc @@ -45,7 +45,9 @@ #define BITDHT_QUERY_START_PEERS 10 #define BITDHT_QUERY_NEIGHBOUR_PEERS 8 + #define BITDHT_MAX_REMOTE_QUERY_AGE 10 +#define MAX_REMOTE_PROCESS_PER_CYCLE 5 /**** * #define USE_HISTORY 1 @@ -477,11 +479,13 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags) } /************************************ Process Remote Query *************************/ + +/* increased the allowed processing rate from 1/sec => 5/sec */ void bdNode::processRemoteQuery() { - bool processed = false; + int nProcessed = 0; time_t oldTS = time(NULL) - BITDHT_MAX_REMOTE_QUERY_AGE; - while(!processed) + while(nProcessed < MAX_REMOTE_PROCESS_PER_CYCLE) { /* extra exit clause */ if (mRemoteQueries.size() < 1) return; @@ -492,7 +496,7 @@ void bdNode::processRemoteQuery() if (query.mQueryTS > oldTS) { /* recent enough to process! */ - processed = true; + nProcessed++; switch(query.mQueryType) { @@ -541,7 +545,7 @@ void bdNode::processRemoteQuery() { /* drop */ /* unprocess! */ - processed = false; + nProcessed--; break; } } @@ -551,10 +555,10 @@ void bdNode::processRemoteQuery() } else { -#ifdef DEBUG_NODE_MSGS std::cerr << "bdNode::processRemoteQuery() Query Too Old: Discarding: "; mFns->bdPrintId(std::cerr, &(query.mId)); std::cerr << std::endl; +#ifdef DEBUG_NODE_MSGS #endif } diff --git a/libbitdht/src/bitdht/bdpeer.cc b/libbitdht/src/bitdht/bdpeer.cc index 31f450ae8..de2432926 100644 --- a/libbitdht/src/bitdht/bdpeer.cc +++ b/libbitdht/src/bitdht/bdpeer.cc @@ -400,14 +400,13 @@ int bdSpace::find_exactnode(const bdId *id, bdPeer &peer) mFns->bdDistance(&(id->id), &(mOwnId), &dist); int buckno = mFns->bdBucketDistance(&dist); +#ifdef DEBUG_BD_SPACE std::cerr << "bdSpace::find_exactnode(Id:"; mFns->bdPrintId(std::cerr, id); std::cerr << ")"; std::cerr << " Bucket #: " << buckno; std::cerr << std::endl; - -#ifdef DEBUG_BD_SPACE #endif bdBucket &buck = buckets[buckno]; @@ -418,94 +417,24 @@ int bdSpace::find_exactnode(const bdId *id, bdPeer &peer) { if (*id == eit->mPeerId) { +#ifdef DEBUG_BD_SPACE std::cerr << "bdSpace::find_exactnode() Found Matching Peer: "; mFns->bdPrintId(std::cerr, &(eit->mPeerId)); std::cerr << " withFlags: " << eit->mPeerFlags; std::cerr << std::endl; +#endif peer = (*eit); return 1; } } - std::cerr << "bdSpace::find_exactnode() ERROR Failed to find Matching Peer: "; +#ifdef DEBUG_BD_SPACE + std::cerr << "bdSpace::find_exactnode() WARNING Failed to find Matching Peer: "; std::cerr << std::endl; - - return 0; -} - - -#if 0 -int bdSpace::out_of_date_peer(bdId &id) -{ - /* - * - */ - - std::map closest; - std::map::iterator mit; - - std::vector::iterator it; - std::list::iterator eit; - time_t ts = time(NULL); - - /* iterate through the buckets, and sort by distance */ - for(it = buckets.begin(); it != buckets.end(); it++) - { - for(eit = it->entries.begin(); eit != it->entries.end(); ) - { - /* timeout on last send time! */ - if (ts - eit->mLastSendTime > BITDHT_MAX_SEND_PERIOD ) - { - /* We want to ping a peer iff: - * 1) They are out-of-date: mLastRecvTime is too old. - * 2) They don't have 0x0001 flag (we haven't received a PONG) and never sent. - */ - if ((ts - eit->mLastRecvTime > BITDHT_MAX_SEND_PERIOD ) || - !(eit->mPeerFlags & BITDHT_PEER_STATUS_RECV_PONG)) - { - id = eit->mPeerId; - eit->mLastSendTime = ts; - return 1; - } - } - - - /* we also want to remove very old entries (should it happen here?) - * which are not pushed out by newer entries (will happen in for closer buckets) - */ - - bool discard = false; - /* discard very old entries */ - if (ts - eit->mLastRecvTime > BITDHT_DISCARD_PERIOD) - { - discard = true; - } - - /* discard peers which have not responded to anything (ie have no flags set) */ - if ((ts - eit->mFoundTime > BITDHT_MAX_RESPONSE_PERIOD ) && - (eit->mPeerFlags == 0)) - { - discard = true; - } - - - /* INCREMENT */ - if (discard) - { - eit = it->entries.erase(eit); - } - else - { - eit++; - } - } - } - return 0; -} - #endif - + return 0; +} #define BITDHT_ATTACHED_SEND_PERIOD 17 diff --git a/libbitdht/src/bitdht/bdquery.cc b/libbitdht/src/bitdht/bdquery.cc index a746b2cf3..b52d1525c 100644 --- a/libbitdht/src/bitdht/bdquery.cc +++ b/libbitdht/src/bitdht/bdquery.cc @@ -36,9 +36,9 @@ * #define DEBUG_QUERY 1 **/ - #define EXPECTED_REPLY 10 // Speed up queries #define QUERY_IDLE_RETRY_PEER_PERIOD 300 // 5min = (mFns->bdNodesPerBucket() * 30) +#define MAX_QUERY_IDLE_PERIOD 900 // 15min. /************************************************************ @@ -83,6 +83,7 @@ bdQuery::bdQuery(const bdNodeId *id, std::list &startList, uint32_t queryF mQueryTS = now; mSearchTime = 0; mClosestListSize = (int) (1.5 * mFns->bdNodesPerBucket()); + mPotPeerCleanTS = now; mQueryIdlePeerRetryPeriod = QUERY_IDLE_RETRY_PEER_PERIOD; mRequiredPeerFlags = BITDHT_PEER_STATUS_DHT_ENGINE_VERSION; // XXX to update later. @@ -125,6 +126,10 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId) if ((now - mQueryTS) / 2 > mQueryIdlePeerRetryPeriod) { mQueryIdlePeerRetryPeriod = (now-mQueryTS) / 2; + if (mQueryIdlePeerRetryPeriod > MAX_QUERY_IDLE_PERIOD) + { + mQueryIdlePeerRetryPeriod = MAX_QUERY_IDLE_PERIOD; + } } bool notFinished = false; @@ -218,7 +223,7 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId) if (age > BITDHT_MAX_QUERY_AGE) { #ifdef DEBUG_QUERY - fprintf(stderr, "NextQuery() under Min Time: Query not finished / No Query\n"); + fprintf(stderr, "NextQuery() over Max Time: Query force to Finish\n"); #endif /* fall through and stop */ } @@ -242,6 +247,8 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId) mSearchTime = now - mQueryTS; } + /* cleanup PotentialPeers before doing the final State */; + removeOldPotentialPeers(); /* check if we found the node */ if (mClosest.size() > 0) { @@ -483,9 +490,9 @@ int bdQuery::worthyPotentialPeer(const bdId *id) mFns->bdDistance(&mId, &(id->id), &dist); #ifdef DEBUG_QUERY - fprintf(stderr, "bdQuery::addPotentialPeer("); + std::cerr << "bdQuery::worthyPotentialPeer("; mFns->bdPrintId(std::cerr, id); - fprintf(stderr, ", %u)\n", mode); + std::cerr << std::endl; #endif /* we check if this is a worthy potential peer.... @@ -678,6 +685,60 @@ int bdQuery::trimPotentialPeers_toClosest() } +/* as Potential Peeers are to determine if a peer is CLOSEST or UNREACHABLE + * we need to drop ones that we haven't heard about in ages. + * + * only do this in IDLE mode... + * The timeout period is dependent on our RetryPeriod. + */ + +#define POT_PEER_CLEAN_PERIOD 60 +#define POT_PEER_RECV_TIMEOUT_PERIOD (mQueryIdlePeerRetryPeriod + EXPECTED_REPLY) + +int bdQuery::removeOldPotentialPeers() +{ + if (!(mQueryFlags & BITDHT_QFLAGS_DO_IDLE)) + { + return 0; + } + + time_t now = time(NULL); + if (now - mPotPeerCleanTS < POT_PEER_CLEAN_PERIOD) + { + return 0; + } + + mPotPeerCleanTS = now; + + /* painful loop */ + std::multimap::iterator it; + for(it = mPotentialPeers.begin(); it != mPotentialPeers.end();) + { + /* which timestamp do we care about? */ + if (now - it->second.mLastRecvTime > POT_PEER_RECV_TIMEOUT_PERIOD) + { +#ifdef DEBUG_QUERY + std::cerr << "bdQuery::removeOldPotentialPeers() removing: "; + mFns->bdPrintId(std::cerr, &(it->second.mPeerId)); + fprintf(stderr, "\n"); +#endif + std::multimap::iterator it2 = it; + ++it2 ; + mPotentialPeers.erase(it); + it = it2 ; + + // Unfortunately have to start again... as pointers invalidated. + //it = mPotentialPeers.begin(); + } + else + { + ++it; + } + } + return 1 ; +} + + /******************************************************************************************* ******************************** Potential Proxies **************************************** @@ -926,7 +987,7 @@ int bdQuery::printQuery() } fprintf(stderr, "\nClosest Potential Peers:\n"); - for(it = mPotentialClosest.begin(); it != mPotentialClosest.end(); it++) + for(it = mPotentialPeers.begin(); it != mPotentialPeers.end(); it++) { fprintf(stderr, "Id: "); mFns->bdPrintId(std::cerr, &(it->second.mPeerId)); @@ -938,8 +999,8 @@ int bdQuery::printQuery() } std::list::iterator lit; - fprintf(stderr, "\nPotential Proxies:\n"); - for(lit = mPotentialProxies.begin(); lit != mPotentialProxies.end(); lit++) + fprintf(stderr, "\nProxies Flagged:\n"); + for(lit = mProxiesFlagged.begin(); lit != mProxiesFlagged.end(); lit++) { fprintf(stderr, "ProxyId: "); mFns->bdPrintId(std::cerr, &(lit->mPeerId)); @@ -948,6 +1009,18 @@ int bdQuery::printQuery() fprintf(stderr," LastRecv: %ld ago", ts-lit->mLastRecvTime); fprintf(stderr, "\n"); } + + fprintf(stderr, "\nProxies Unknown:\n"); + for(lit = mProxiesUnknown.begin(); lit != mProxiesUnknown.end(); lit++) + { + fprintf(stderr, "ProxyId: "); + mFns->bdPrintId(std::cerr, &(lit->mPeerId)); + fprintf(stderr," Found: %ld ago", ts-lit->mFoundTime); + fprintf(stderr," LastSent: %ld ago", ts-lit->mLastSendTime); + fprintf(stderr," LastRecv: %ld ago", ts-lit->mLastRecvTime); + fprintf(stderr, "\n"); + } + #else // shortened version. fprintf(stderr, "Closest Available Peer: "); diff --git a/libbitdht/src/bitdht/bdquery.h b/libbitdht/src/bitdht/bdquery.h index e2d2a3069..60660116c 100644 --- a/libbitdht/src/bitdht/bdquery.h +++ b/libbitdht/src/bitdht/bdquery.h @@ -34,7 +34,7 @@ /* Query result flags are in bdiface.h */ #define BITDHT_MIN_QUERY_AGE 10 -#define BITDHT_MAX_QUERY_AGE 1800 /* 30 minutes */ +#define BITDHT_MAX_QUERY_AGE 300 /* Query Should take <1 minute, so 5 minutes sounds reasonable */ class bdQuery { @@ -74,6 +74,7 @@ int worthyPotentialPeer(const bdId *id); int updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType); int trimPotentialPeers_FixedLength(); int trimPotentialPeers_toClosest(); +int removeOldPotentialPeers(); // Proxy Handling Fns. int addProxy(const bdId *id, const bdId *src, uint32_t srcmode); @@ -85,6 +86,7 @@ int trimProxies(); // closest peers. std::multimap mClosest; std::multimap mPotentialPeers; + time_t mPotPeerCleanTS; // periodic cleanup of PotentialPeers. uint32_t mRequiredPeerFlags; std::list mProxiesUnknown; @@ -92,6 +94,7 @@ int trimProxies(); int mClosestListSize; bdDhtFunctions *mFns; + }; #if 0 diff --git a/libbitdht/src/bitdht/bdquerymgr.cc b/libbitdht/src/bitdht/bdquerymgr.cc index fb78261f3..d766d62fd 100644 --- a/libbitdht/src/bitdht/bdquerymgr.cc +++ b/libbitdht/src/bitdht/bdquerymgr.cc @@ -26,6 +26,7 @@ #include "bitdht/bdquerymgr.h" #include "bitdht/bdnode.h" +#include #include #include #include diff --git a/libbitdht/src/udp/udpbitdht.cc b/libbitdht/src/udp/udpbitdht.cc index addcd98e3..6bfba3349 100644 --- a/libbitdht/src/udp/udpbitdht.cc +++ b/libbitdht/src/udp/udpbitdht.cc @@ -51,7 +51,9 @@ // Original RS 0.5.0/0.5.1 version, is un-numbered. #define BITDHT_VERSION "00" // First Release of BitDHT with Connections (Proxy Support + Dht Stun) -//#define BITDHT_VERSION "01" // Potentially... Connections + Full DHT implementation. (TBD) +//#define BITDHT_VERSION "01" // Full Connections +//#define BITDHT_VERSION "02" // Full DHT implementation. + /*************************************/ UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, bdDhtFunctions *fns) diff --git a/libbitdht/src/udp/udplayer.cc b/libbitdht/src/udp/udplayer.cc index 9dd467a2c..2dc345a32 100644 --- a/libbitdht/src/udp/udplayer.cc +++ b/libbitdht/src/udp/udplayer.cc @@ -539,7 +539,7 @@ int LossyUdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_in &f std::cerr << "LossyUdpLayer::receiveUdpPacket() Packet Dropped!"; std::cerr << std::endl; - size = 0; + *size = 0; return -1; } @@ -548,7 +548,7 @@ int LossyUdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_in &f return -1; } -int LossyUdpLayer::sendUdpPacket(const void *data, int size, struct sockaddr_in &to) +int LossyUdpLayer::sendUdpPacket(const void *data, int size, const struct sockaddr_in &to) { double prob = (1.0 * (rand() / (RAND_MAX + 1.0))); @@ -625,19 +625,25 @@ int RestrictedUdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_ //std::cerr << std::endl; #endif - size = 0; + *size = 0; return -1; } } + +#ifdef DEBUG_UDP_LAYER + std::cerr << "RestrictedUdpLayer::receiveUdpPacket() Accepting packet"; + std::cerr << ", Port(" << inPort << ") in Okay range!"; + std::cerr << std::endl; +#endif /* acceptable port */ return *size; } return -1; } -int RestrictedUdpLayer::sendUdpPacket(const void *data, int size, struct sockaddr_in &to) +int RestrictedUdpLayer::sendUdpPacket(const void *data, int size, const struct sockaddr_in &to) { /* check the port against list */ uint16_t outPort = ntohs(to.sin_port); @@ -661,6 +667,12 @@ int RestrictedUdpLayer::sendUdpPacket(const void *data, int size, struct sockadd } + +#ifdef DEBUG_UDP_LAYER + std::cerr << "RestrictedUdpLayer::sendUdpPacket() Sending packet"; + std::cerr << ", Port(" << outPort << ") in Okay range!"; + std::cerr << std::endl; +#endif // otherwise read normally; return UdpLayer::sendUdpPacket(data, size, to); diff --git a/libbitdht/src/udp/udplayer.h b/libbitdht/src/udp/udplayer.h index b82513d43..d543ee033 100644 --- a/libbitdht/src/udp/udplayer.h +++ b/libbitdht/src/udp/udplayer.h @@ -129,7 +129,7 @@ virtual ~LossyUdpLayer(); protected: virtual int receiveUdpPacket(void *data, int *size, struct sockaddr_in &from); -virtual int sendUdpPacket(const void *data, int size, struct sockaddr_in &to); +virtual int sendUdpPacket(const void *data, int size, const struct sockaddr_in &to); double lossFraction; }; @@ -159,7 +159,7 @@ void addRestrictedPortRange(int lp, int up); protected: virtual int receiveUdpPacket(void *data, int *size, struct sockaddr_in &from); -virtual int sendUdpPacket(const void *data, int size, struct sockaddr_in &to); +virtual int sendUdpPacket(const void *data, int size, const struct sockaddr_in &to); std::list mLostPorts; }; diff --git a/libbitdht/src/util/bdbloom.cc b/libbitdht/src/util/bdbloom.cc index 2772e937e..4c44f3ea5 100644 --- a/libbitdht/src/util/bdbloom.cc +++ b/libbitdht/src/util/bdbloom.cc @@ -25,12 +25,14 @@ #include "util/bdbloom.h" +#include #include #include #if defined(_WIN32) || defined(__MINGW32__) - #include +#include #endif + /* Bloom Filter implementation */