don't add an external address if we are not reachable with it

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1934 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-12-22 18:43:04 +00:00
parent 3d4036782d
commit bccd4e7d22
3 changed files with 41 additions and 16 deletions

View File

@ -1578,14 +1578,8 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
return false;
}
it->second.inConnAttempt = false;
if (success)
{
/* remove other attempts */
it->second.inConnAttempt = false;
netAssistFriend(id, false);
/* update address (will come although through from DISC) */
#ifdef CONN_DEBUG
@ -1600,10 +1594,16 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
it->second.actions |= RS_PEER_CONNECTED;
it->second.lastcontact = time(NULL); /* time of connect */
it->second.connecttype = flags;
//used to send back to the peer it's own ext address
it->second.currentserveraddr = remote_peer_address;
if (remote_peer_address.sin_addr.s_addr != 0
&& !(remote_peer_address.sin_addr.s_addr == ownState.currentlocaladdr.sin_addr.s_addr)
&& (!isLoopbackNet(&remote_peer_address.sin_addr))
//add the ip address in the address list if we were in a connect attempt and the attempt address is the same as the connect result
if (it->second.inConnAttempt &&
it->second.currentConnAddrAttempt.addr.sin_addr.s_addr == remote_peer_address.sin_addr.s_addr &&
it->second.currentConnAddrAttempt.addr.sin_port == remote_peer_address.sin_port &&
remote_peer_address.sin_addr.s_addr != 0 &&
!(remote_peer_address.sin_addr.s_addr == ownState.currentlocaladdr.sin_addr.s_addr) &&
(!isLoopbackNet(&remote_peer_address.sin_addr))
) {
IpAddressTimed ipLocalAddressTimed;
ipLocalAddressTimed.ipAddr = remote_peer_address;
@ -1617,10 +1617,16 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
#endif
}
/* remove other attempts */
it->second.inConnAttempt = false;
it->second.connAddrs.clear();
netAssistFriend(id, false);
mStatusChanged = true;
return true;
}
it->second.inConnAttempt = false;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::connectResult() Disconnect/Fail: id: " << id << std::endl;
std::cerr << " Success: " << success << " flags: " << flags << std::endl;

View File

@ -276,6 +276,10 @@ bool doNextAttempt(std::string id);
p3tunnel* getP3tunnel();
void setP3tunnel(p3tunnel *p3tun);
bool getUpnpExtAddress(struct sockaddr_in &addr);
bool getStunExtAddress(struct sockaddr_in &addr);
bool getExtFinderExtAddress(struct sockaddr_in &addr);
protected:
/****************** Internal Interface *******************/
@ -346,10 +350,6 @@ void tickMonitors();
bool retryConnectTCP(std::string id);
bool retryConnectNotify(std::string id);
bool getUpnpExtAddress(struct sockaddr_in &addr);
bool getStunExtAddress(struct sockaddr_in &addr);
bool getExtFinderExtAddress(struct sockaddr_in &addr);
/* temporary for testing */
//virtual void loadConfiguration() { return; }
@ -421,11 +421,13 @@ private:
bool oldnetFlagStunOk;
bool oldnetFlagExtraAddressCheckOk;
public:
peerConnectState ownState;
protected:
void addPeer(std::string id, std::string name); /* tmp fn */
peerConnectState ownState;
std::list<std::string> mStunList;
std::map<std::string, peerConnectState> mFriendList;

View File

@ -235,10 +235,10 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
if ((pit->state & RS_PEER_S_FRIEND) &&
(pit->actions & RS_PEER_CONNECTED))
{
/* send our details to them */
sendOwnDetails(pit->id);
/* send their own details to them. Usefull for ext ip address detection */
sendPeerDetails(pit->id, pit->id);
/* send our details to them */
sendOwnDetails(pit->id);
}
}
}
@ -761,7 +761,24 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
/* send Own Ip list to connect manager. It will extract the external ip address from it */
if (peerId == mConnMgr->getOwnId())
{
//setAddressList might also set our own external address
mConnMgr->setAddressList(mConnMgr->getOwnId(), item->ipAddressList);
if (item->currentsaddr.sin_addr.s_addr != 0 && item->currentsaddr.sin_port != 0 &&
item->currentsaddr.sin_addr.s_addr != 1 && item->currentsaddr.sin_port != 1 &&
std::string(inet_ntoa(item->currentsaddr.sin_addr)) != "1.1.1.1" &&
(!isLoopbackNet(&item->currentsaddr.sin_addr)) &&
(!isPrivateNet(&item->currentsaddr.sin_addr))
) {
//the current server address given by the peer looks nice, let's use it for our own ext address if needed
sockaddr_in tempAddr;
if (!mConnMgr->getExtFinderExtAddress(tempAddr) && !mConnMgr->getUpnpExtAddress(tempAddr)) {
//don't change the port, just the ip
item->currentsaddr.sin_port = mConnMgr->ownState.currentserveraddr.sin_port;
mConnMgr->setExtAddress(mConnMgr->getOwnId(), item->currentsaddr);
}
}
}