upgraded connmgr and p3disc for ext address ip detection when connecting to peers

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1912 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-12-18 21:45:45 +00:00
parent 5c436e2dde
commit 76c774a76a
2 changed files with 39 additions and 12 deletions

View File

@ -2495,14 +2495,17 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
ownState.currentserveraddr = addr; ownState.currentserveraddr = addr;
//check port and address //check port and address
if (ownState.currentserveraddr.sin_addr.s_addr == 0) { if (ownState.currentserveraddr.sin_addr.s_addr == 0 || ownState.currentserveraddr.sin_port == 0 ||
//use internal port for now ownState.currentserveraddr.sin_addr.s_addr == 1|| ownState.currentserveraddr.sin_port == 1 ||
ownState.currentserveraddr.sin_addr = ownState.currentlocaladdr.sin_addr; std::string(inet_ntoa(ownState.currentserveraddr.sin_addr)) == "1.1.1.1") {
} //try to extract ext address from the ip address list
if (addr.sin_port == 0) { IpAddressTimed extractedAddress;
//use internal port for now if (peerConnectState::extractExtAddress(ownState.getIpAddressList(), extractedAddress)) {
ownState.currentserveraddr.sin_port = ownState.currentlocaladdr.sin_port; ownState.currentserveraddr = extractedAddress.ipAddr;
} } else {
ownState.currentserveraddr = ownState.currentlocaladdr;
}
}
} }
return true; return true;
} }
@ -2536,9 +2539,23 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
bool p3ConnectMgr::setAddressList(std::string id, std::list<IpAddressTimed> IpAddressTimedList) bool p3ConnectMgr::setAddressList(std::string id, std::list<IpAddressTimed> IpAddressTimedList)
{ {
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::setAddressList() called for id : " << id << std::endl;
#endif
/* check if it is our own ip */ /* check if it is our own ip */
if (id == getOwnId()) { if (id == getOwnId()) {
ownState.updateIpAddressList(IpAddressTimedList); ownState.updateIpAddressList(IpAddressTimedList);
//if we are using firewalled or manually set port mode, and we are not using extAddrFinder, we will use this list for ip ext ip detection
if ((!ownState.netMode & RS_NET_MODE_UPNP) && !use_extr_addr_finder) {
IpAddressTimed extractedAddress;
if (peerConnectState::extractExtAddress(IpAddressTimedList, extractedAddress)) {
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::setAddressList() using ip address list to set external addres." << std::endl;
#endif
ownState.currentserveraddr.sin_addr = extractedAddress.ipAddr.sin_addr;
IndicateConfigChanged();
}
}
return true; return true;
} }
@ -3244,7 +3261,12 @@ bool p3ConnectMgr::getStunExtAddress(struct sockaddr_in &addr) {
} }
bool p3ConnectMgr::getExtFinderExtAddress(struct sockaddr_in &addr) { bool p3ConnectMgr::getExtFinderExtAddress(struct sockaddr_in &addr) {
return (use_extr_addr_finder && mExtAddrFinder->hasValidIP(&addr)); if ((use_extr_addr_finder && mExtAddrFinder->hasValidIP(&addr))) {
addr.sin_port = ownState.currentlocaladdr.sin_port;
return true;
} else {
return false;
}
} }
bool peerConnectState::compare_seen_time (IpAddressTimed first, IpAddressTimed second) { //Sort the ip list ordering by seen time bool peerConnectState::compare_seen_time (IpAddressTimed first, IpAddressTimed second) { //Sort the ip list ordering by seen time
@ -3384,9 +3406,12 @@ bool peerConnectState::extractExtAddress(std::list<IpAddressTimed> IpAddressTime
std::list<IpAddressTimed>::iterator ipListIt; std::list<IpAddressTimed>::iterator ipListIt;
for (ipListIt = IpAddressTimedList.begin(); ipListIt!=(IpAddressTimedList.end()); ++ipListIt) { for (ipListIt = IpAddressTimedList.begin(); ipListIt!=(IpAddressTimedList.end()); ++ipListIt) {
//assume address is valid if not private, is not 0 and is not loopback //assume address is valid if not private, is not 0 and is not loopback
if ((ipListIt->ipAddr.sin_addr.s_addr != 0) //if ((ipListIt->ipAddr.sin_addr.s_addr != 0)
&& (!isLoopbackNet(&ipListIt->ipAddr.sin_addr)) if (ipListIt->ipAddr.sin_addr.s_addr != 0 && ipListIt->ipAddr.sin_port != 0 &&
&& (!isPrivateNet(&ipListIt->ipAddr.sin_addr)) ipListIt->ipAddr.sin_addr.s_addr != 1 && ipListIt->ipAddr.sin_port != 1 &&
std::string(inet_ntoa(ipListIt->ipAddr.sin_addr)) == "1.1.1.1" &&
(!isLoopbackNet(&ipListIt->ipAddr.sin_addr)) &&
(!isPrivateNet(&ipListIt->ipAddr.sin_addr))
) { ) {
resultAddress = *ipListIt; resultAddress = *ipListIt;
return true; return true;

View File

@ -239,6 +239,8 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
{ {
/* send our details to them */ /* send our details to them */
sendOwnDetails(pit->id); sendOwnDetails(pit->id);
/* send their own details to them. Usefull for ext ip address detection */
sendPeerDetails(pit->id, pit->id);
} }
} }
} }