From fe955c9a4f16976bc7099b64763bfe8554b38936 Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 14 Jan 2012 01:34:44 +0000 Subject: [PATCH 1/2] * Added NumQueryNodes() function to bdDhtFunctions. * Switched bdquery.cc to use bdNumQueryNodes(). * Extended bdStdDht class to bdModDht to allow NodesPerBucket to be modified. * Fixed up Connection Fail Callback for Relay Servers. * Added Extra debugging for Proxy Connections. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4794 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libbitdht/src/bitdht/bdconnection.cc | 23 +++++++++++++++-------- libbitdht/src/bitdht/bdiface.h | 3 ++- libbitdht/src/bitdht/bdquery.cc | 18 +++++++++--------- libbitdht/src/bitdht/bdstddht.cc | 22 +++++++++++++++++++++- libbitdht/src/bitdht/bdstddht.h | 13 ++++++++++++- 5 files changed, 59 insertions(+), 20 deletions(-) diff --git a/libbitdht/src/bitdht/bdconnection.cc b/libbitdht/src/bitdht/bdconnection.cc index 2329c7823..a6d539bc3 100644 --- a/libbitdht/src/bitdht/bdconnection.cc +++ b/libbitdht/src/bitdht/bdconnection.cc @@ -2148,7 +2148,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId bool areProxy = (srcConnAddr->id == id->id); if (areProxy) { -#ifdef DEBUG_NODE_CONNECTION +#ifdef DEBUG_PROXY_CONNECTION std::cerr << "bdConnectManager::recvedConnectionRequest() We are MID Point for Proxy / Relay Connection."; std::cerr << std::endl; #endif @@ -2170,7 +2170,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId if (mNodeSpace->find_node(&(destConnAddr->id), numNodes, matchingIds, with_flag)) { -#ifdef DEBUG_NODE_CONNECTION +#ifdef DEBUG_PROXY_CONNECTION std::cerr << "bdConnectManager::recvedConnectionRequest() Found Suitable Destination Addr"; std::cerr << std::endl; #endif @@ -2188,7 +2188,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId if (proxyOk) { -#ifdef DEBUG_NODE_CONNECTION +#ifdef DEBUG_PROXY_CONNECTION std::cerr << "bdConnectManager::recvedConnectionRequest() Proxy Addr Ok: "; bdStdPrintId(std::cerr, destConnAddr); std::cerr << "asking for AUTH to continue"; @@ -2215,7 +2215,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId else { /* clean up connection... its not going to work */ -#ifdef DEBUG_NODE_CONNECTION +#ifdef DEBUG_PROXY_CONNECTION std::cerr << "bdConnectManager::recvedConnectionRequest() WARNING No Proxy Addr, Shutting Connect Attempt"; std::cerr << std::endl; #endif @@ -2227,18 +2227,25 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId int param = 0; mPub->send_connect_msg(id, msgtype, srcConnAddr, destConnAddr, mode, param, status); - /* remove connection */ - bdConnectManager::cleanConnectionBySender(id, srcConnAddr, destConnAddr); /* WILL NEED CALLBACK FOR FAILED PROXY ATTEMPT - TO SUPPORT RELAYS PROPERLY * NODE needs to know PEERS to potentially WHITELIST! */ if (mRelayMode == BITDHT_RELAYS_SERVER) { - callbackConnect(&(conn->mSrcId),&(conn->mProxyId),&(conn->mDestId), - conn->mMode, conn->mPoint, param, BITDHT_CONNECT_CB_AUTH, +#ifdef DEBUG_PROXY_CONNECTION + std::cerr << "bdConnectManager::recvedConnectionRequest() In RelayServer Mode, doing FAIL callbackConnect()"; + std::cerr << std::endl; +#endif + + bdId proxyId; + proxyId.id = mOwnId; + callbackConnect(srcConnAddr, &proxyId, destConnAddr, mode, point, param, BITDHT_CONNECT_CB_AUTH, BITDHT_CONNECT_ERROR_NOADDRESS); } + + /* remove connection */ + bdConnectManager::cleanConnectionBySender(id, srcConnAddr, destConnAddr); } } else diff --git a/libbitdht/src/bitdht/bdiface.h b/libbitdht/src/bitdht/bdiface.h index 65b24a25f..08582629e 100644 --- a/libbitdht/src/bitdht/bdiface.h +++ b/libbitdht/src/bitdht/bdiface.h @@ -88,7 +88,8 @@ class bdDhtFunctions // bdDhtFunctions(); /* setup variables */ virtual uint16_t bdNumBuckets() = 0; -virtual uint16_t bdNodesPerBucket() = 0; /* used for query + bdspace */ +virtual uint16_t bdNodesPerBucket() = 0; /* used for bdspace */ +virtual uint16_t bdNumQueryNodes() = 0; /* used for queries */ virtual uint16_t bdBucketBitSize() = 0; virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric) = 0; diff --git a/libbitdht/src/bitdht/bdquery.cc b/libbitdht/src/bitdht/bdquery.cc index 4a076c6f3..b3f1624b4 100644 --- a/libbitdht/src/bitdht/bdquery.cc +++ b/libbitdht/src/bitdht/bdquery.cc @@ -37,7 +37,7 @@ **/ #define EXPECTED_REPLY 10 // Speed up queries -#define QUERY_IDLE_RETRY_PEER_PERIOD 300 // 5min = (mFns->bdNodesPerBucket() * 30) +#define QUERY_IDLE_RETRY_PEER_PERIOD 300 // 5min = (mFns->bdNumQueryNodes() * 30) #define MAX_QUERY_IDLE_PERIOD 900 // 15min. @@ -82,7 +82,7 @@ bdQuery::bdQuery(const bdNodeId *id, std::list &startList, uint32_t queryF mQueryFlags = queryFlags; mQueryTS = now; mSearchTime = 0; - mClosestListSize = (int) (1.5 * mFns->bdNodesPerBucket()); + mClosestListSize = (int) (1.5 * mFns->bdNumQueryNodes()); mPotPeerCleanTS = now; mQueryIdlePeerRetryPeriod = QUERY_IDLE_RETRY_PEER_PERIOD; @@ -174,7 +174,7 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId) */ if (((it->second.mLastRecvTime == 0) || (now - it->second.mLastRecvTime < EXPECTED_REPLY)) && - (i < mFns->bdNodesPerBucket())) + (i < mFns->bdNumQueryNodes())) { #ifdef DEBUG_QUERY fprintf(stderr, "NextQuery() Never Received @Idx(%d) notFinished = true: ", i); @@ -231,7 +231,7 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId) #endif /* fall through and stop */ } - else if ((mClosest.size() < mFns->bdNodesPerBucket()) || (notFinished)) + else if ((mClosest.size() < mFns->bdNumQueryNodes()) || (notFinished)) { #ifdef DEBUG_QUERY fprintf(stderr, "NextQuery() notFinished | !size(): Query not finished / No Query\n"); @@ -510,7 +510,7 @@ int bdQuery::worthyPotentialPeer(const bdId *id) eit = mClosest.upper_bound(dist); /* check if outside range, & bucket is full */ - if ((sit == mClosest.end()) && (mClosest.size() >= mFns->bdNodesPerBucket())) + if ((sit == mClosest.end()) && (mClosest.size() >= mFns->bdNumQueryNodes())) { #ifdef DEBUG_QUERY fprintf(stderr, "Peer to far away for Potential\n"); @@ -604,7 +604,7 @@ int bdQuery::updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType #if 0 /* check if outside range, & bucket is full */ - if ((sit == mPotentialPeers.end()) && (mPotentialPeers.size() >= mFns->bdNodesPerBucket())) + if ((sit == mPotentialPeers.end()) && (mPotentialPeers.size() >= mFns->bdNumQueryNodes())) { #ifdef DEBUG_QUERY fprintf(stderr, "Peer to far away for Potential\n"); @@ -640,7 +640,7 @@ int bdQuery::updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType int bdQuery::trimPotentialPeers_FixedLength() { /* trim it back */ - while(mPotentialPeers.size() > (uint32_t) (mFns->bdNodesPerBucket())) + while(mPotentialPeers.size() > (uint32_t) (mFns->bdNumQueryNodes())) { std::multimap::iterator it; it = mPotentialPeers.end(); @@ -658,7 +658,7 @@ int bdQuery::trimPotentialPeers_FixedLength() int bdQuery::trimPotentialPeers_toClosest() { - if (mPotentialPeers.size() <= (uint32_t) (mFns->bdNodesPerBucket())) + if (mPotentialPeers.size() <= (uint32_t) (mFns->bdNumQueryNodes())) return 1; std::multimap::reverse_iterator it; @@ -666,7 +666,7 @@ int bdQuery::trimPotentialPeers_toClosest() bdMetric lastClosest = it->first; /* trim it back */ - while(mPotentialPeers.size() > (uint32_t) (mFns->bdNodesPerBucket())) + while(mPotentialPeers.size() > (uint32_t) (mFns->bdNumQueryNodes())) { std::multimap::iterator it; it = mPotentialPeers.end(); diff --git a/libbitdht/src/bitdht/bdstddht.cc b/libbitdht/src/bitdht/bdstddht.cc index 974e06fbb..a053f3566 100644 --- a/libbitdht/src/bitdht/bdstddht.cc +++ b/libbitdht/src/bitdht/bdstddht.cc @@ -256,10 +256,16 @@ uint16_t bdStdDht::bdNumBuckets() return BITDHT_STANDARD_N_BUCKETS; } -uint16_t bdStdDht::bdNodesPerBucket() /* used for query + bdspace */ +uint16_t bdStdDht::bdNodesPerBucket() /* used for bdspace */ { return BITDHT_STANDARD_BUCKET_SIZE; } + +uint16_t bdStdDht::bdNumQueryNodes() /* used for queries */ +{ + return BITDHT_STANDARD_BUCKET_SIZE; +} + uint16_t bdStdDht::bdBucketBitSize() { return BITDHT_STANDARD_BUCKET_SIZE_BITS; @@ -308,6 +314,20 @@ void bdStdDht::bdPrintNodeId(std::ostream &out, const bdNodeId *a) { return bdStdPrintNodeId(out, a); } + +/**************************/ + +void bdModDht::setNodesPerBucket(uint16_t nodesPerBucket) +{ + mNodesPerBucket = nodesPerBucket; + return; +} + + +uint16_t bdModDht::bdNodesPerBucket() /* used for bdspace */ +{ + return mNodesPerBucket; +} diff --git a/libbitdht/src/bitdht/bdstddht.h b/libbitdht/src/bitdht/bdstddht.h index 71e1b44ce..a6fe8136f 100644 --- a/libbitdht/src/bitdht/bdstddht.h +++ b/libbitdht/src/bitdht/bdstddht.h @@ -69,7 +69,8 @@ class bdStdDht: public bdDhtFunctions bdStdDht(); /* setup variables */ virtual uint16_t bdNumBuckets(); -virtual uint16_t bdNodesPerBucket(); /* used for query + bdspace */ +virtual uint16_t bdNodesPerBucket(); /* used for bdspace */ +virtual uint16_t bdNumQueryNodes(); /* used for queries */ virtual uint16_t bdBucketBitSize(); virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric); @@ -86,6 +87,16 @@ virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a); }; +class bdModDht: public bdStdDht +{ + public: +virtual void setNodesPerBucket(uint16_t nodesPerBucket); +virtual uint16_t bdNodesPerBucket(); /* used for bdspace */ + + private: + uint16_t mNodesPerBucket; +}; + #endif From 96c9071920323f2f56a1ed5ba685785ae7ba756b Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 14 Jan 2012 01:54:17 +0000 Subject: [PATCH 2/2] Changes to support Relays. * added p3BitDht::addKnownNode() so that DhtIds can be used instead of SslIds. * switched from bdStdDht() functions to use bdModDht(). * made DhtFunctions a class variable. * added function to modify NodePerBucket() parameter. * Bugfix for LinkType. peerConnectAddress.flags was not initialised. * Extra debugging of LinkType data (use LINKMGR_DEBUG_LINKTYPE). * cleaned up udprelay output. * Added Compile Rules to libretroshare.pro for building LocalNet Testing Version. (testnetwork) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4795 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dht/p3bitdht.cc | 11 +++++- libretroshare/src/dht/p3bitdht.h | 5 ++- libretroshare/src/dht/p3bitdht_peers.cc | 43 +++++++++++++++++++++ libretroshare/src/dht/p3bitdht_relay.cc | 3 ++ libretroshare/src/libretroshare.pro | 21 ++++++---- libretroshare/src/pqi/p3linkmgr.cc | 51 +++++++++++++++++++++++-- libretroshare/src/tcponudp/udprelay.cc | 17 ++++++--- 7 files changed, 131 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/dht/p3bitdht.cc b/libretroshare/src/dht/p3bitdht.cc index f6150f076..167fcdd81 100644 --- a/libretroshare/src/dht/p3bitdht.cc +++ b/libretroshare/src/dht/p3bitdht.cc @@ -120,7 +120,8 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm, #endif /* standard dht behaviour */ - bdDhtFunctions *stdfns = new bdStdDht(); + //bdDhtFunctions *stdfns = new bdStdDht(); + mDhtFns = new bdModDht(); #ifdef DEBUG_BITDHT std::cerr << "p3BitDht() startup ... creating UdpBitDht"; @@ -128,7 +129,7 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm, #endif /* create dht */ - mUdpBitDht = new UdpBitDht(udpstack, &mOwnDhtId, dhtVersion, bootstrapfile, stdfns); + mUdpBitDht = new UdpBitDht(udpstack, &mOwnDhtId, dhtVersion, bootstrapfile, mDhtFns); udpstack->addReceiver(mUdpBitDht); /* setup callback to here */ @@ -170,6 +171,12 @@ void p3BitDht::setupPeerSharer(pqiNetAssistPeerShare *sharer) mPeerSharer = sharer; } + /* Tweak the DHT Parameters */ +void p3BitDht::modifyNodesPerBucket(uint16_t count) +{ + bdModDht *modFns = (bdModDht *) mDhtFns; + modFns->setNodesPerBucket(count); +} /* Support for Outsourced Relay Handling */ diff --git a/libretroshare/src/dht/p3bitdht.h b/libretroshare/src/dht/p3bitdht.h index 5df81e6d2..bed2b379f 100644 --- a/libretroshare/src/dht/p3bitdht.h +++ b/libretroshare/src/dht/p3bitdht.h @@ -173,7 +173,7 @@ virtual std::string getUdpAddressString(); void setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay); void setupPeerSharer(pqiNetAssistPeerShare *sharer); - + void modifyNodesPerBucket(uint16_t count); void start(); /* starts up the bitdht thread */ @@ -322,6 +322,7 @@ int removePeer(const std::string pid); // Can be used externally too. int calculateNodeId(const std::string pid, bdNodeId *id); +int addKnownNode(const bdId *id, uint32_t flags); private: @@ -345,6 +346,8 @@ int removeTranslation_locked(const std::string pid); pqiNetAssistPeerShare *mPeerSharer; + bdDhtFunctions *mDhtFns; + RsMutex dhtMtx; diff --git a/libretroshare/src/dht/p3bitdht_peers.cc b/libretroshare/src/dht/p3bitdht_peers.cc index 046f02cdd..982dcf135 100644 --- a/libretroshare/src/dht/p3bitdht_peers.cc +++ b/libretroshare/src/dht/p3bitdht_peers.cc @@ -275,6 +275,49 @@ int p3BitDht::addKnownPeer(const std::string &pid, const struct sockaddr_in &add return 1; } + +/* Total duplicate of above function - can't be helped, should merge somehow */ +int p3BitDht::addKnownNode(const bdId *id, uint32_t flags) +{ + int bdflags = 0; + + switch(flags & NETASSIST_KNOWN_PEER_TYPE_MASK) + { + default: + return 0; + break; + case NETASSIST_KNOWN_PEER_WHITELIST: + bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST; + + break; + case NETASSIST_KNOWN_PEER_FOF: + bdflags = BITDHT_PEER_STATUS_DHT_FOF; + + break; + case NETASSIST_KNOWN_PEER_FRIEND: + bdflags = BITDHT_PEER_STATUS_DHT_FRIEND; + + break; + case NETASSIST_KNOWN_PEER_RELAY: + bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER; + + break; + case NETASSIST_KNOWN_PEER_SELF: + bdflags = BITDHT_PEER_STATUS_DHT_SELF; + + break; + } + + if (flags & NETASSIST_KNOWN_PEER_ONLINE) + { + bdflags |= BD_FRIEND_ENTRY_ONLINE; + } + + mUdpBitDht->updateKnownPeer(id, 0, bdflags); + + return 1; +} + #if 0 diff --git a/libretroshare/src/dht/p3bitdht_relay.cc b/libretroshare/src/dht/p3bitdht_relay.cc index d4f8fadb6..5540bc41c 100644 --- a/libretroshare/src/dht/p3bitdht_relay.cc +++ b/libretroshare/src/dht/p3bitdht_relay.cc @@ -124,6 +124,9 @@ uint32_t p3BitDht::getRelayMode() int p3BitDht::setRelayMode(uint32_t mode) { + std::cerr << "p3BitDht::setRelayMode(" << mode << ")"; + std::cerr << std::endl; + if (mode & RSDHT_RELAY_ENABLED) { mUdpBitDht->ConnectionOptions( diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 1fe429cf0..d18120245 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -31,21 +31,26 @@ release { testnetwork { - #DEFINES *= PQI_DISABLE_UDP - DEFINES *= PQI_DISABLE_TUNNEL + # used in rsserver/rsinit.cc Enabled Port Restrictions, and makes Proxy Port next to Dht Port. + DEFINES *= LOCALNET_TESTING - # DEFINES *= AUTHSSL_DEBUG GPG_DEBUG - # DEFINES *= CONN_DEBUG - # DEFINES *= P3DISC_DEBUG + # used in tcponudp/udprelay.cc Debugging Info for Relays. + DEFINES *= DEBUG_UDP_RELAY - # DEFINES *= PGRP_DEBUG - # DEFINES *= PERSON_DEBUG + # used in tcponudp/udpstunner.[h | cc] enables local stun (careful - modifies class variables). + DEFINES *= UDPSTUN_ALLOW_LOCALNET - #DEFINES *= DEBUG_UDP_SORTER DEBUG_UDP_LAYER EXTADDRSEARCH_DEBUG + # used in pqi/p3linkmgr.cc prints out extra debug. + DEFINES *= LINKMGR_DEBUG_LINKTYPE + + # used in dht/connectstatebox to reduce connection times and display debug. + # DEFINES *= TESTING_PERIODS + # DEFINES *= DEBUG_CONNECTBOX QMAKE_CXXFLAGS -= -fomit-frame-pointer QMAKE_CXXFLAGS -= -O2 QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer + } diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index cb8edfe7d..f0a6ee681 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -56,6 +56,7 @@ const int p3connectzone = 3431; * #define LINKMGR_DEBUG 1 * #define LINKMGR_DEBUG_CONNFAIL 1 * #define LINKMGR_DEBUG_ACTIONS 1 + * #define LINKMGR_DEBUG_LINKTYPE 1 ***/ /**** @@ -85,7 +86,7 @@ const uint32_t P3CONNMGR_UDP_DEFAULT_PERIOD = 30; // this represents how long i void printConnectState(std::ostream &out, peerConnectState &peer); peerConnectAddress::peerConnectAddress() - :delay(0), period(0), type(0), ts(0) + :delay(0), period(0), type(0), flags(0), ts(0) { sockaddr_clear(&addr); } @@ -683,71 +684,113 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &ra #define TRICKLE_LIMIT 2001 // 2kb #define LOW_BANDWIDTH_LIMIT 5001 // 5kb +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() Setting up LinkType" << std::endl; + std::cerr << "p3LinkMgrIMPL::connectAttempt() type = " << type << std::endl; +#endif + it->second.linkType = 0; if (type & RS_NET_CONN_TCP_ALL) { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() type & TCP_ALL => TCP_UNKNOWN" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_TRANS_TCP_UNKNOWN; } else if (type & RS_NET_CONN_UDP_ALL) { if (flags & RS_CB_FLAG_MODE_UDP_DIRECT) { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() type & UDP_ALL && flags & DIRECT => UDP_DIRECT" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_TRANS_UDP_DIRECT; } else if (flags & RS_CB_FLAG_MODE_UDP_PROXY) { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() type & UDP_ALL && flags & PROXY => UDP_PROXY" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_TRANS_UDP_PROXY; } else if (flags & RS_CB_FLAG_MODE_UDP_RELAY) { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() type & UDP_ALL && flags & RELAY => UDP_RELAY" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_TRANS_UDP_RELAY; } else { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() type & UDP_ALL && else => UDP_UNKNOWN" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_TRANS_UDP_UNKNOWN; } } else if (type & RS_NET_CONN_TUNNEL) { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() type & TUNNEL => TUNNEL" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_TRANS_TUNNEL; } else { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() else => TRANS_UNKNOWN" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_TRANS_UNKNOWN; } - if (flags & RS_CB_FLAG_MODE_UDP_RELAY) + if ((type & RS_NET_CONN_UDP_ALL) && (flags & RS_CB_FLAG_MODE_UDP_RELAY)) { if (bandwidth < TRICKLE_LIMIT) { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() flags & RELAY && band < TRICKLE => SPEED_TRICKLE" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_SPEED_TRICKLE; } else if (bandwidth < LOW_BANDWIDTH_LIMIT) { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() flags & RELAY && band < LOW => SPEED_LOW" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_SPEED_LOW; } else { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() flags & RELAY && else => SPEED_NORMAL" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_SPEED_NORMAL; } } else { +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() else => SPEED_NORMAL" << std::endl; +#endif it->second.linkType |= RS_NET_CONN_SPEED_NORMAL; } uint32_t connType = mPeerMgr->getConnectionType(id); it->second.linkType |= connType; - /********* Setup LinkType parameters **********/ +#ifdef LINKMGR_DEBUG_LINKTYPE + std::cerr << "p3LinkMgrIMPL::connectAttempt() connType: " << connType << std::endl; + std::cerr << "p3LinkMgrIMPL::connectAttempt() final LinkType: " << it->second.linkType << std::endl; + - // TEMP DEBUG. std::cerr << "p3LinkMgrIMPL::connectAttempt() found an address: id: " << id << std::endl; std::cerr << " laddr: " << rs_inet_ntoa(raddr.sin_addr) << " lport: " << ntohs(raddr.sin_port) << " delay: " << delay << " period: " << period; std::cerr << " type: " << type << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() set LinkType to: " << it->second.linkType << std::endl; +#endif + /********* Setup LinkType parameters **********/ #ifdef LINKMGR_DEBUG std::cerr << "p3LinkMgrIMPL::connectAttempt() found an address: id: " << id << std::endl; diff --git a/libretroshare/src/tcponudp/udprelay.cc b/libretroshare/src/tcponudp/udprelay.cc index 908787330..ba9b61597 100644 --- a/libretroshare/src/tcponudp/udprelay.cc +++ b/libretroshare/src/tcponudp/udprelay.cc @@ -31,8 +31,6 @@ * #define DEBUG_UDP_RELAY_PKTS 1 */ -//#define DEBUG_UDP_RELAY 1 - #ifdef DEBUG_UDP_RELAY // DEBUG FUNCTION @@ -334,6 +332,10 @@ int UdpRelayReceiver::removeUdpRelay(UdpRelayAddrSet *addrSet) { RsStackMutex stack(relayMtx); /********** LOCK MUTEX *********/ +#ifdef DEBUG_UDP_RELAY + std::cerr << "UdpRelayReceiver::removeUdpRelay() :" << *addrSet << std::endl; +#endif + return removeUdpRelay_relayLocked(addrSet); } @@ -384,6 +386,10 @@ int UdpRelayReceiver::addUdpRelay(UdpRelayAddrSet *addrSet, int &relayClass, uin int UdpRelayReceiver::removeUdpRelay_relayLocked(UdpRelayAddrSet *addrSet) { +#ifdef DEBUG_UDP_RELAY + std::cerr << "UdpRelayReceiver::removeUdpRelay_relayLocked() :" << *addrSet << std::endl; +#endif + /* find in Relay list */ std::map::iterator rit = mRelays.find(*addrSet); if (rit == mRelays.end()) @@ -606,14 +612,15 @@ int UdpRelayReceiver::RelayStatus(std::ostream &out) out << "\tBandwidth: " << rit->second.mBandwidth; out << "\tDataSize: " << rit->second.mDataSize; out << "\tLastBandwidthTS: " << rit->second.mLastBandwidthTS; + out << std::endl; } out << "ClassLimits:" << std::endl; for(int i = 0; i < UDP_RELAY_NUM_CLASS; i++) { - out << "ClassLimit[" << i << "] = " << mClassLimit[i] << std::endl; - out << "ClassCount[" << i << "] = " << mClassCount[i] << std::endl; - out << "ClassBandwidth[" << i << "] = " << mClassBandwidth[i] << std::endl; + out << "Limit[" << i << "] = " << mClassLimit[i]; + out << " Count: " << mClassCount[i]; + out << " Bandwidth: " << mClassBandwidth[i]; out << std::endl; }