mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-18 11:29:31 -04:00
add some various tests to avoid ip address 0 bugs
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1910 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2d8f30c2c7
commit
10cd455519
2 changed files with 56 additions and 7 deletions
|
@ -1499,11 +1499,19 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||||
period = it->second.currentConnAddrAttempt.period;
|
period = it->second.currentConnAddrAttempt.period;
|
||||||
type = it->second.currentConnAddrAttempt.type;
|
type = it->second.currentConnAddrAttempt.type;
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::connectAttempt() Success: id: " << id << std::endl;
|
std::cerr << "p3ConnectMgr::connectAttempt() found an address: id: " << id << std::endl;
|
||||||
std::cerr << " laddr: " << inet_ntoa(addr.sin_addr) << " lport: " << ntohs(addr.sin_port) << " delay: " << delay << " period: " << period;
|
std::cerr << " laddr: " << inet_ntoa(addr.sin_addr) << " lport: " << ntohs(addr.sin_port) << " delay: " << delay << " period: " << period;
|
||||||
std::cerr << " type: " << type << std::endl;
|
std::cerr << " type: " << type << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
if (addr.sin_addr.s_addr == 0 || addr.sin_port == 0) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3ConnectMgr::connectAttempt() address or port is null, don't make the attempt." << std::endl;
|
||||||
|
std::cerr << " type: " << type << std::endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1528,6 +1536,12 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::connectResult() called with FAILED.");
|
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::connectResult() called with FAILED.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id == getOwnId()) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::connectResult() Failed, connecting to own id: ");
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/* check for existing */
|
/* check for existing */
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
it = mFriendList.find(id);
|
it = mFriendList.find(id);
|
||||||
|
@ -1615,6 +1629,13 @@ bool p3ConnectMgr::doNextAttempt(std::string id)
|
||||||
|
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::doNextAttempt() called id : " + id);
|
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::doNextAttempt() called id : " + id);
|
||||||
|
|
||||||
|
if (id == getOwnId()) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::doNextAttempt() Failed, connecting to own id: ");
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* check for existing */
|
/* check for existing */
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
it = mFriendList.find(id);
|
it = mFriendList.find(id);
|
||||||
|
@ -2184,7 +2205,14 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
||||||
std::cerr << "p3ConnectMgr::retryConnectTCP() id: " << id << std::endl;
|
std::cerr << "p3ConnectMgr::retryConnectTCP() id: " << id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* look up the id */
|
if (id == getOwnId()) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::retryConnectTCP() Failed, connecting to own id: ");
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* look up the id */
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||||
{
|
{
|
||||||
|
@ -2301,6 +2329,15 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
||||||
pca.type = RS_NET_CONN_TUNNEL;
|
pca.type = RS_NET_CONN_TUNNEL;
|
||||||
pca.ts = time(NULL);
|
pca.ts = time(NULL);
|
||||||
pca.period = 0;
|
pca.period = 0;
|
||||||
|
|
||||||
|
//we've got to set an address to avoid null pointer or some other bug
|
||||||
|
if (peerConnectState::extractExtAddress(it->second.getIpAddressList(), extractedAddress)) {
|
||||||
|
pca.addr = extractedAddress.ipAddr;
|
||||||
|
} else {
|
||||||
|
sockaddr_clear(&pca.addr);
|
||||||
|
pca.addr.sin_addr.s_addr = 1;
|
||||||
|
pca.addr.sin_port = 1;
|
||||||
|
}
|
||||||
it->second.connAddrs.push_back(pca);
|
it->second.connAddrs.push_back(pca);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3249,13 +3286,17 @@ void peerConnectState::purgeIpAddressList() {//purge old and useless addresses t
|
||||||
|
|
||||||
std::list<IpAddressTimed>::iterator ipListIt;
|
std::list<IpAddressTimed>::iterator ipListIt;
|
||||||
for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end());) {
|
for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end());) {
|
||||||
if (ipListIt->ipAddr.sin_addr.s_addr == 0) {
|
if (ipListIt->ipAddr.sin_addr.s_addr == 0 || ipListIt->ipAddr.sin_port == 0 ||
|
||||||
ipAddressList.erase(ipListIt++);
|
ipListIt->ipAddr.sin_addr.s_addr == 1|| ipListIt->ipAddr.sin_port == 1 ||
|
||||||
|
std::string(inet_ntoa(ipListIt->ipAddr.sin_addr)) == "1.1.1.1") {
|
||||||
|
ipAddressList.erase(ipListIt++);
|
||||||
} else {
|
} else {
|
||||||
++ipListIt;
|
++ipListIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
printIpAddressList();
|
printIpAddressList();
|
||||||
|
#endif
|
||||||
|
|
||||||
//purge duplicates
|
//purge duplicates
|
||||||
for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()); ipListIt++) {
|
for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()); ipListIt++) {
|
||||||
|
@ -3290,7 +3331,8 @@ void peerConnectState::updateIpAddressList(IpAddressTimed ipTimed) { //purge old
|
||||||
std::cerr << ":" << ntohs(ipTimed.ipAddr.sin_port);
|
std::cerr << ":" << ntohs(ipTimed.ipAddr.sin_port);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (ipTimed.ipAddr.sin_addr.s_addr == 0 || ipTimed.ipAddr.sin_port == 0 ||
|
if (ipTimed.ipAddr.sin_addr.s_addr == 0 || ipTimed.ipAddr.sin_port == 0 ||
|
||||||
|
ipTimed.ipAddr.sin_addr.s_addr == 1|| ipTimed.ipAddr.sin_port == 1 ||
|
||||||
std::string(inet_ntoa(ipTimed.ipAddr.sin_addr)) == "1.1.1.1") {
|
std::string(inet_ntoa(ipTimed.ipAddr.sin_addr)) == "1.1.1.1") {
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "peerConnectState::updateIpAdressList() ip parameter is 0.0.0.0, 1.1.1.1 or port is 0, ignoring." << std::endl;
|
std::cerr << "peerConnectState::updateIpAdressList() ip parameter is 0.0.0.0, 1.1.1.1 or port is 0, ignoring." << std::endl;
|
||||||
|
|
|
@ -284,6 +284,7 @@ void pqipersongrp::statusChange(const std::list<pqipeer> &plist)
|
||||||
|
|
||||||
if (it->actions & RS_PEER_CONNECT_REQ)
|
if (it->actions & RS_PEER_CONNECT_REQ)
|
||||||
{
|
{
|
||||||
|
|
||||||
connectPeer(it->id);
|
connectPeer(it->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,7 +397,13 @@ int pqipersongrp::connectPeer(std::string id)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
{ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||||
std::map<std::string, SearchModule *>::iterator it;
|
if (id == mConnMgr->getOwnId()) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
rslog(RSL_WARNING, p3connectzone, "pqipersongrp::connectPeer() Failed, connecting to own id.");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
std::map<std::string, SearchModule *>::iterator it;
|
||||||
it = mods.find(id);
|
it = mods.find(id);
|
||||||
if (it == mods.end())
|
if (it == mods.end())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue