From 685182ff0b8939899afdefac1075cf8ff8b4fecc Mon Sep 17 00:00:00 2001 From: drbob Date: Mon, 25 Feb 2008 23:56:23 +0000 Subject: [PATCH] Modified DHT to notify of all possible stun peers, as it doesn't know whether we need to stun or not. Added a Type parameter, so that the connection Mgr can determine if there is an external port available or not. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@354 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 25 +++++++++++++++---------- libretroshare/src/pqi/p3connmgr.h | 2 +- libretroshare/src/pqi/p3dhtmgr.cc | 12 ++++++++---- libretroshare/src/pqi/pqimonitor.cc | 10 +++++----- libretroshare/src/pqi/pqimonitor.h | 4 ++-- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index cb3b9f448..9f2cb907b 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -529,11 +529,11 @@ bool p3ConnectMgr::stunCheck() return false; } -void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags) +void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags) { std::cerr << "p3ConnectMgr::stunStatus()"; - std::cerr << " id: " << RsUtil::BinToHex(id) << " addr: " << inet_ntoa(addr.sin_addr); - std::cerr << " port: " << ntohs(addr.sin_port); + std::cerr << " id: " << RsUtil::BinToHex(id) << " raddr: " << inet_ntoa(raddr.sin_addr); + std::cerr << ":" << ntohs(raddr.sin_port); std::cerr << std::endl; connMtx.lock(); /* LOCK MUTEX */ @@ -542,17 +542,22 @@ void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in addr, uint32_t connMtx.unlock(); /* UNLOCK MUTEX */ - if (stillStunning) + /* only useful if they have an exposed TCP/UDP port */ + if (type & RS_NET_CONN_TCP_EXTERNAL) { + if (stillStunning) + { + #ifdef CONN_DEBUG - std::cerr << "p3ConnectMgr::stunStatus() Sending to UDP" << std::endl; + std::cerr << "p3ConnectMgr::stunStatus() Sending to UDP" << std::endl; #endif - /* push to the UDP */ - udpStunPeer(id, addr); - } + /* push to the UDP */ + udpStunPeer(id, raddr); + } - /* push to the stunCollect */ - stunCollect(id, addr, flags); + /* push to the stunCollect */ + stunCollect(id, raddr, flags); + } } /* FLAGS diff --git a/libretroshare/src/pqi/p3connmgr.h b/libretroshare/src/pqi/p3connmgr.h index cc4b06fab..8aaabfad5 100644 --- a/libretroshare/src/pqi/p3connmgr.h +++ b/libretroshare/src/pqi/p3connmgr.h @@ -190,7 +190,7 @@ virtual void peerStatus(std::string id, struct sockaddr_in laddr, struct sockaddr_in raddr, uint32_t type, uint32_t flags, uint32_t source); virtual void peerConnectRequest(std::string id, uint32_t type); -virtual void stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags); +virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags); /****************** Connections *******************/ bool connectAttempt(std::string id, struct sockaddr_in &addr, uint32_t &type); diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index 6536cfdd8..8581d24c0 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -1339,9 +1339,13 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash, doNotify = true; } - /* if stun not happy yet - doStun aswell */ - if ((mDhtState != DHT_STATE_OFF) && - (mDhtState != DHT_STATE_ACTIVE)) + /* if stun not happy yet - doStun as well.. + * as the DHT doesn't know if the Stun is happy - send + * it through always! + * if ((mDhtState != DHT_STATE_OFF) && + * (mDhtState != DHT_STATE_ACTIVE)) + */ + if (mDhtState != DHT_STATE_OFF) { doStun = true; stunFlags = RS_STUN_FRIEND | RS_STUN_ONLINE; @@ -1375,7 +1379,7 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash, if (doStun) { - connCb->stunStatus(idhash, raddr, stunFlags); + connCb->stunStatus(idhash, raddr, type, stunFlags); } return true; diff --git a/libretroshare/src/pqi/pqimonitor.cc b/libretroshare/src/pqi/pqimonitor.cc index 51cc4a74d..16b3ff8f7 100644 --- a/libretroshare/src/pqi/pqimonitor.cc +++ b/libretroshare/src/pqi/pqimonitor.cc @@ -69,13 +69,13 @@ void pqiConnectCbDummy::peerConnectRequest(std::string id, uint32_t type) std::cerr << std::endl; } - - -void pqiConnectCbDummy::stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags) +void pqiConnectCbDummy::stunStatus(std::string id, struct sockaddr_in raddr, + uint32_t type, uint32_t flags) { std::cerr << "pqiConnectCbDummy::stunStatus()"; - std::cerr << " idhash: " << RsUtil::BinToHex(id) << " addr: " << inet_ntoa(addr.sin_addr); - std::cerr << " port: " << ntohs(addr.sin_port); + std::cerr << " idhash: " << RsUtil::BinToHex(id) << " raddr: " << inet_ntoa(raddr.sin_addr); + std::cerr << ":" << ntohs(raddr.sin_port); + std::cerr << " type: " << type; std::cerr << " flags: " << flags; std::cerr << std::endl; } diff --git a/libretroshare/src/pqi/pqimonitor.h b/libretroshare/src/pqi/pqimonitor.h index 9a5c25b0e..2f2256142 100644 --- a/libretroshare/src/pqi/pqimonitor.h +++ b/libretroshare/src/pqi/pqimonitor.h @@ -110,7 +110,7 @@ virtual void peerStatus(std::string id, virtual void peerConnectRequest(std::string id, uint32_t type) = 0; -virtual void stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags) = 0; +virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags) = 0; }; @@ -126,7 +126,7 @@ virtual void peerStatus(std::string id, virtual void peerConnectRequest(std::string id, uint32_t type); -virtual void stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags); +virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags); }; #endif // PQI_MONITOR_H