mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-15 19:04:25 -05:00
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:
parent
3d4036782d
commit
bccd4e7d22
@ -1578,14 +1578,8 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
it->second.inConnAttempt = false;
|
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
/* remove other attempts */
|
|
||||||
it->second.inConnAttempt = false;
|
|
||||||
netAssistFriend(id, false);
|
|
||||||
|
|
||||||
/* update address (will come although through from DISC) */
|
/* update address (will come although through from DISC) */
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#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.actions |= RS_PEER_CONNECTED;
|
||||||
it->second.lastcontact = time(NULL); /* time of connect */
|
it->second.lastcontact = time(NULL); /* time of connect */
|
||||||
it->second.connecttype = flags;
|
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
|
//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
|
||||||
&& !(remote_peer_address.sin_addr.s_addr == ownState.currentlocaladdr.sin_addr.s_addr)
|
if (it->second.inConnAttempt &&
|
||||||
&& (!isLoopbackNet(&remote_peer_address.sin_addr))
|
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;
|
IpAddressTimed ipLocalAddressTimed;
|
||||||
ipLocalAddressTimed.ipAddr = remote_peer_address;
|
ipLocalAddressTimed.ipAddr = remote_peer_address;
|
||||||
@ -1617,10 +1617,16 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove other attempts */
|
||||||
|
it->second.inConnAttempt = false;
|
||||||
|
it->second.connAddrs.clear();
|
||||||
|
netAssistFriend(id, false);
|
||||||
mStatusChanged = true;
|
mStatusChanged = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it->second.inConnAttempt = false;
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::connectResult() Disconnect/Fail: id: " << id << std::endl;
|
std::cerr << "p3ConnectMgr::connectResult() Disconnect/Fail: id: " << id << std::endl;
|
||||||
std::cerr << " Success: " << success << " flags: " << flags << std::endl;
|
std::cerr << " Success: " << success << " flags: " << flags << std::endl;
|
||||||
|
@ -276,6 +276,10 @@ bool doNextAttempt(std::string id);
|
|||||||
p3tunnel* getP3tunnel();
|
p3tunnel* getP3tunnel();
|
||||||
void setP3tunnel(p3tunnel *p3tun);
|
void setP3tunnel(p3tunnel *p3tun);
|
||||||
|
|
||||||
|
bool getUpnpExtAddress(struct sockaddr_in &addr);
|
||||||
|
bool getStunExtAddress(struct sockaddr_in &addr);
|
||||||
|
bool getExtFinderExtAddress(struct sockaddr_in &addr);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/****************** Internal Interface *******************/
|
/****************** Internal Interface *******************/
|
||||||
@ -346,10 +350,6 @@ void tickMonitors();
|
|||||||
bool retryConnectTCP(std::string id);
|
bool retryConnectTCP(std::string id);
|
||||||
bool retryConnectNotify(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 */
|
/* temporary for testing */
|
||||||
//virtual void loadConfiguration() { return; }
|
//virtual void loadConfiguration() { return; }
|
||||||
|
|
||||||
@ -421,11 +421,13 @@ private:
|
|||||||
bool oldnetFlagStunOk;
|
bool oldnetFlagStunOk;
|
||||||
bool oldnetFlagExtraAddressCheckOk;
|
bool oldnetFlagExtraAddressCheckOk;
|
||||||
|
|
||||||
|
public:
|
||||||
|
peerConnectState ownState;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void addPeer(std::string id, std::string name); /* tmp fn */
|
void addPeer(std::string id, std::string name); /* tmp fn */
|
||||||
|
|
||||||
peerConnectState ownState;
|
|
||||||
|
|
||||||
std::list<std::string> mStunList;
|
std::list<std::string> mStunList;
|
||||||
std::map<std::string, peerConnectState> mFriendList;
|
std::map<std::string, peerConnectState> mFriendList;
|
||||||
|
@ -235,10 +235,10 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
|
|||||||
if ((pit->state & RS_PEER_S_FRIEND) &&
|
if ((pit->state & RS_PEER_S_FRIEND) &&
|
||||||
(pit->actions & RS_PEER_CONNECTED))
|
(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 */
|
/* send their own details to them. Usefull for ext ip address detection */
|
||||||
sendPeerDetails(pit->id, pit->id);
|
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 */
|
/* send Own Ip list to connect manager. It will extract the external ip address from it */
|
||||||
if (peerId == mConnMgr->getOwnId())
|
if (peerId == mConnMgr->getOwnId())
|
||||||
{
|
{
|
||||||
|
//setAddressList might also set our own external address
|
||||||
mConnMgr->setAddressList(mConnMgr->getOwnId(), item->ipAddressList);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user