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; }