diff --git a/libretroshare/src/dht/p3bitdht_peernet.cc b/libretroshare/src/dht/p3bitdht_peernet.cc index c8fbe8ef8..3d04a541d 100644 --- a/libretroshare/src/dht/p3bitdht_peernet.cc +++ b/libretroshare/src/dht/p3bitdht_peernet.cc @@ -21,7 +21,11 @@ #define PEERNET_CONNECT_TIMEOUT 45 -#define DEBUG_BITDHT 1 +/*** + * + * #define DEBUG_BITDHT_COMMON 1 // These are the things that are called regularly (annoying for debugging specifics) + * + **/ #if 0 int p3BitDht::add_peer(std::string id) @@ -184,7 +188,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags) if ((mProxyStunner) && (mProxyStunner->needStunPeers())) { -#ifdef DEBUG_BITDHT +#ifdef DEBUG_BITDHT_COMMON std::cerr << "p3BitDht::NodeCallback() Passing BitDHT Peer to DhtStunner: "; bdStdPrintId(std::cerr, id); std::cerr << std::endl; @@ -195,7 +199,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags) if ((mDhtStunner) && (mDhtStunner->needStunPeers())) { -#ifdef DEBUG_BITDHT +#ifdef DEBUG_BITDHT_COMMON std::cerr << "p3BitDht::NodeCallback() Passing BitDHT Peer to DhtStunner: "; bdStdPrintId(std::cerr, id); std::cerr << std::endl; @@ -915,8 +919,10 @@ int p3BitDht::tick() time_t now = time(NULL); +#ifdef PEERNET_DEBUG std::cerr << "p3BitDht::tick() TIME: " << ctime(&now) << std::endl; std::cerr.flush(); +#endif return 1; } diff --git a/libretroshare/src/dht/p3bitdht_peers.cc b/libretroshare/src/dht/p3bitdht_peers.cc index f26146b9d..45b00300c 100644 --- a/libretroshare/src/dht/p3bitdht_peers.cc +++ b/libretroshare/src/dht/p3bitdht_peers.cc @@ -40,8 +40,6 @@ * **/ -#define DEBUG_BITDHT 1 - /****************************************************************************************** ********************************* Existing Interface ************************************* ******************************************************************************************/ diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index b421abf5f..bc13a1bf0 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -52,9 +52,10 @@ const int p3connectzone = 3431; /**** * #define LINKMGR_DEBUG 1 + * #define LINKMGR_DEBUG_CONNFAIL 1 ***/ -#define LINKMGR_DEBUG 1 +#define LINKMGR_DEBUG_CONNFAIL 1 /**** * #define P3CONNMGR_NO_TCP_CONNECTIONS 1 @@ -90,7 +91,6 @@ peerAddrInfo::peerAddrInfo() peerConnectState::peerConnectState() :id("unknown"), - lastcontact(0), connecttype(0), lastavailable(0), lastattempt(0), @@ -661,6 +661,8 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag { bool doDhtAssist = false ; bool updatePeerAddr = false; + bool updateLastContact = false; + { RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ @@ -694,6 +696,10 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag if (success) { /* update address (should also come through from DISC) */ +#ifdef LINKMGR_DEBUG_CONNFAIL + std::cerr << "p3LinkMgr::connectResult() Connect!: id: " << id << std::endl; + std::cerr << " Success: " << success << " flags: " << flags << std::endl; +#endif #ifdef LINKMGR_DEBUG std::cerr << "p3LinkMgr::connectResult() Connect!: id: " << id << std::endl; @@ -705,9 +711,9 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag /* change state */ it->second.state |= RS_PEER_S_CONNECTED; it->second.actions |= RS_PEER_CONNECTED; - it->second.lastcontact = time(NULL); /* time of connect */ it->second.connecttype = flags; + updateLastContact = true; /* time of connect */ /* only update the peer's address if we were in a connect attempt. * Otherwise, they connected to us, and the address will be a @@ -741,6 +747,22 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag } else { +#ifdef LINKMGR_DEBUG_CONNFAIL + std::cerr << "p3LinkMgr::connectResult() Disconnect/Fail: flags: " << flags << " id: " << id; + std::cerr << std::endl; + + if (it->second.inConnAttempt) + { + std::cerr << "p3LinkMgr::connectResult() Likely Connect Fail, as inConnAttempt Flag is set"; + std::cerr << std::endl; + } + if (it->second.state & RS_PEER_S_CONNECTED) + { + std::cerr << "p3LinkMgr::connectResult() Likely DISCONNECT, as state set to Connected"; + std::cerr << std::endl; + } +#endif + it->second.inConnAttempt = false; #ifdef LINKMGR_DEBUG @@ -755,7 +777,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag it->second.actions |= RS_PEER_DISCONNECTED; mStatusChanged = true; - it->second.lastcontact = time(NULL); /* time of disconnect */ + updateLastContact = true; /* time of disconnect */ } if (it->second.connAddrs.size() >= 1) @@ -779,17 +801,22 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag raddr.mSrc = 0; #ifdef LINKMGR_DEBUG - std::cerr << "p3LinkMgr::connectResult() SUCCESS and we initiated connection... Updating Address"; + std::cerr << "p3LinkMgr::connectResult() Success and we initiated connection... Updating Address"; std::cerr << std::endl; #endif mPeerMgr->updateCurrentAddress(id, raddr); } + if (updateLastContact) + { + mPeerMgr->updateLastContact(id); + } + if (success) { #ifdef LINKMGR_DEBUG - std::cerr << "p3LinkMgr::connectResult() SUCCESS switching off DhtAssist for friend: " << id; + std::cerr << "p3LinkMgr::connectResult() Success switching off DhtAssist for friend: " << id; std::cerr << std::endl; #endif /* always switch it off now */ @@ -800,7 +827,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag if (doDhtAssist) { #ifdef LINKMGR_DEBUG - std::cerr << "p3LinkMgr::connectResult() FAIL, Enabling DhtAssist for: " << id; + std::cerr << "p3LinkMgr::connectResult() Fail, Enabling DhtAssist for: " << id; std::cerr << std::endl; #endif mNetMgr->netAssistFriend(id,true) ; @@ -808,7 +835,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag else { #ifdef LINKMGR_DEBUG - std::cerr << "p3LinkMgr::connectResult() FAIL, No DhtAssist, as No DHT visibility for: " << id; + std::cerr << "p3LinkMgr::connectResult() Fail, No DhtAssist, as No DHT visibility for: " << id; std::cerr << std::endl; #endif } diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index c1f780871..c7d3648b6 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -108,7 +108,7 @@ class peerConnectState bool dhtVisible; - time_t lastcontact; + //time_t lastcontact; uint32_t connecttype; // RS_NET_CONN_TCP_ALL / RS_NET_CONN_UDP_ALL time_t lastavailable; diff --git a/libretroshare/src/pqi/p3netmgr.cc b/libretroshare/src/pqi/p3netmgr.cc index 3bcb4afc1..6ef3988b3 100644 --- a/libretroshare/src/pqi/p3netmgr.cc +++ b/libretroshare/src/pqi/p3netmgr.cc @@ -73,8 +73,6 @@ const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5; * #define NETMGR_DEBUG_TICK 1 ***/ -#define NETMGR_DEBUG 1 -#define NETMGR_DEBUG_RESET 1 pqiNetStatus::pqiNetStatus() :mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false), diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 16e87a520..05f7061e9 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -790,7 +790,7 @@ bool p3PeerMgr::updateCurrentAddress(const std::string& id, const pqiIpAddres it->second.ipAddrs.updateExtAddrs(addr); it->second.serveraddr = addr.mAddr; } - + #ifdef CONN_DEBUG std::cerr << "p3PeerMgr::updatedCurrentAddress() Updated Address for: " << id; std::cerr << std::endl; @@ -801,7 +801,37 @@ bool p3PeerMgr::updateCurrentAddress(const std::string& id, const pqiIpAddres IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ return true; +} + + +bool p3PeerMgr::updateLastContact(const std::string& id) +{ +#ifdef CONN_DEBUG + std::cerr << "p3PeerMgr::updateLastContact() called for id : " << id << std::endl; +#endif + + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + + /* cannot be own id */ + + /* check if it is a friend */ + std::map::iterator it; + if (mFriendList.end() == (it = mFriendList.find(id))) + { + if (mOthersList.end() == (it = mOthersList.find(id))) + { + std::cerr << "p3PeerMgr::updateLastContact() ERROR peer id not found: " << id << std::endl; + return false; + } } + + it->second.lastcontact = time(NULL); + + IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ + + return true; +} + diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 0e1912f02..a0c6454be 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -132,8 +132,10 @@ void setOwnVisState(uint32_t visState); bool setLocalAddress(const std::string &id, struct sockaddr_in addr); bool setExtAddress(const std::string &id, struct sockaddr_in addr); bool setDynDNS(const std::string &id, const std::string &dyndns); + bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs); bool updateCurrentAddress(const std::string& id, const pqiIpAddress &addr); +bool updateLastContact(const std::string& id); bool setNetworkMode(const std::string &id, uint32_t netMode); bool setVisState(const std::string &id, uint32_t visState);