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
This commit is contained in:
drbob 2008-02-25 23:56:23 +00:00
parent 100a7aea82
commit 685182ff0b
5 changed files with 31 additions and 22 deletions

View File

@ -529,11 +529,11 @@ bool p3ConnectMgr::stunCheck()
return false; 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 << "p3ConnectMgr::stunStatus()";
std::cerr << " id: " << RsUtil::BinToHex(id) << " addr: " << inet_ntoa(addr.sin_addr); std::cerr << " id: " << RsUtil::BinToHex(id) << " raddr: " << inet_ntoa(raddr.sin_addr);
std::cerr << " port: " << ntohs(addr.sin_port); std::cerr << ":" << ntohs(raddr.sin_port);
std::cerr << std::endl; std::cerr << std::endl;
connMtx.lock(); /* LOCK MUTEX */ connMtx.lock(); /* LOCK MUTEX */
@ -542,17 +542,22 @@ void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in addr, uint32_t
connMtx.unlock(); /* UNLOCK MUTEX */ connMtx.unlock(); /* UNLOCK MUTEX */
if (stillStunning) /* only useful if they have an exposed TCP/UDP port */
if (type & RS_NET_CONN_TCP_EXTERNAL)
{ {
#ifdef CONN_DEBUG if (stillStunning)
std::cerr << "p3ConnectMgr::stunStatus() Sending to UDP" << std::endl; {
#endif
/* push to the UDP */
udpStunPeer(id, addr);
}
/* push to the stunCollect */ #ifdef CONN_DEBUG
stunCollect(id, addr, flags); std::cerr << "p3ConnectMgr::stunStatus() Sending to UDP" << std::endl;
#endif
/* push to the UDP */
udpStunPeer(id, raddr);
}
/* push to the stunCollect */
stunCollect(id, raddr, flags);
}
} }
/* FLAGS /* FLAGS

View File

@ -190,7 +190,7 @@ virtual void peerStatus(std::string id,
struct sockaddr_in laddr, struct sockaddr_in raddr, struct sockaddr_in laddr, struct sockaddr_in raddr,
uint32_t type, uint32_t flags, uint32_t source); uint32_t type, uint32_t flags, uint32_t source);
virtual void peerConnectRequest(std::string id, uint32_t type); 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 *******************/ /****************** Connections *******************/
bool connectAttempt(std::string id, struct sockaddr_in &addr, uint32_t &type); bool connectAttempt(std::string id, struct sockaddr_in &addr, uint32_t &type);

View File

@ -1339,9 +1339,13 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
doNotify = true; doNotify = true;
} }
/* if stun not happy yet - doStun aswell */ /* if stun not happy yet - doStun as well..
if ((mDhtState != DHT_STATE_OFF) && * as the DHT doesn't know if the Stun is happy - send
(mDhtState != DHT_STATE_ACTIVE)) * it through always!
* if ((mDhtState != DHT_STATE_OFF) &&
* (mDhtState != DHT_STATE_ACTIVE))
*/
if (mDhtState != DHT_STATE_OFF)
{ {
doStun = true; doStun = true;
stunFlags = RS_STUN_FRIEND | RS_STUN_ONLINE; stunFlags = RS_STUN_FRIEND | RS_STUN_ONLINE;
@ -1375,7 +1379,7 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
if (doStun) if (doStun)
{ {
connCb->stunStatus(idhash, raddr, stunFlags); connCb->stunStatus(idhash, raddr, type, stunFlags);
} }
return true; return true;

View File

@ -69,13 +69,13 @@ void pqiConnectCbDummy::peerConnectRequest(std::string id, uint32_t type)
std::cerr << std::endl; std::cerr << std::endl;
} }
void pqiConnectCbDummy::stunStatus(std::string id, struct sockaddr_in raddr,
uint32_t type, uint32_t flags)
void pqiConnectCbDummy::stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags)
{ {
std::cerr << "pqiConnectCbDummy::stunStatus()"; std::cerr << "pqiConnectCbDummy::stunStatus()";
std::cerr << " idhash: " << RsUtil::BinToHex(id) << " addr: " << inet_ntoa(addr.sin_addr); std::cerr << " idhash: " << RsUtil::BinToHex(id) << " raddr: " << inet_ntoa(raddr.sin_addr);
std::cerr << " port: " << ntohs(addr.sin_port); std::cerr << ":" << ntohs(raddr.sin_port);
std::cerr << " type: " << type;
std::cerr << " flags: " << flags; std::cerr << " flags: " << flags;
std::cerr << std::endl; std::cerr << std::endl;
} }

View File

@ -110,7 +110,7 @@ virtual void peerStatus(std::string id,
virtual void peerConnectRequest(std::string id, uint32_t type) = 0; 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 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 #endif // PQI_MONITOR_H