mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-28 00:07:09 -05:00
add ext address detector when connectiong to peers
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1882 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b7ace087e6
commit
76d5072624
@ -1086,7 +1086,7 @@ void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in raddr, uint3
|
||||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
/* only useful if they have an exposed TCP/UDP port */
|
||||
/* only useful if they have an exposed TCP/UDP port */
|
||||
if (type & RS_NET_CONN_TCP_EXTERNAL)
|
||||
{
|
||||
if (stillStunning)
|
||||
@ -1536,7 +1536,7 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||
*
|
||||
*/
|
||||
|
||||
bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address)
|
||||
{
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
@ -1558,16 +1558,15 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
it->second.inConnAttempt = false;
|
||||
it->second.inConnAttempt = false;
|
||||
|
||||
if (success)
|
||||
{
|
||||
/* remove other attempts */
|
||||
it->second.connAddrs.clear();
|
||||
netAssistFriend(id, false);
|
||||
/* remove other attempts */
|
||||
it->second.inConnAttempt = false;
|
||||
netAssistFriend(id, false);
|
||||
|
||||
/* update address (will come through from DISC) */
|
||||
/* update address (will come although through from DISC) */
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() Connect!: id: " << id << std::endl;
|
||||
@ -1579,24 +1578,25 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
/* change state */
|
||||
it->second.state |= RS_PEER_S_CONNECTED;
|
||||
it->second.actions |= RS_PEER_CONNECTED;
|
||||
mStatusChanged = true;
|
||||
it->second.lastcontact = time(NULL); /* time of connect */
|
||||
it->second.connecttype = flags;
|
||||
it->second.connecttype = flags;
|
||||
|
||||
IpAddressTimed ipLocalAddressTimed;
|
||||
ipLocalAddressTimed.ipAddr = it->second.currentlocaladdr;
|
||||
ipLocalAddressTimed.seenTime = time(NULL);
|
||||
it->second.updateIpAddressList(ipLocalAddressTimed);
|
||||
if (remote_peer_address.sin_addr.s_addr != 0) {
|
||||
IpAddressTimed ipLocalAddressTimed;
|
||||
ipLocalAddressTimed.ipAddr = remote_peer_address;
|
||||
ipLocalAddressTimed.seenTime = time(NULL);
|
||||
it->second.updateIpAddressList(ipLocalAddressTimed);
|
||||
|
||||
IpAddressTimed ipRemoteAddressTimed;
|
||||
ipRemoteAddressTimed.ipAddr = it->second.currentserveraddr;
|
||||
ipRemoteAddressTimed.seenTime = time(NULL);
|
||||
it->second.updateIpAddressList(ipRemoteAddressTimed);
|
||||
it->second.purgeIpAddressList();
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() adding current peer adress in list." << std::endl;
|
||||
it->second.printIpAddressList();
|
||||
#endif
|
||||
}
|
||||
|
||||
it->second.purgeIpAddressList();
|
||||
it->second.printIpAddressList(); //output log
|
||||
return true;
|
||||
}
|
||||
mStatusChanged = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() Disconnect/Fail: id: " << id << std::endl;
|
||||
@ -2450,17 +2450,13 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
|
||||
{
|
||||
if (id == mAuthMgr->OwnId())
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
ownState.currentserveraddr = addr;
|
||||
}
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
if ((ownState.netMode & RS_NET_MODE_ACTUAL) == RS_NET_MODE_EXT ||
|
||||
(ownState.netMode & RS_NET_MODE_ACTUAL) == RS_NET_MODE_UDP) {
|
||||
netReset();
|
||||
}
|
||||
if (ownState.currentserveraddr.sin_addr.s_addr != addr.sin_addr.s_addr ||
|
||||
ownState.currentserveraddr.sin_port != addr.sin_port) {
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
ownState.currentserveraddr = addr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
/* check if it is a friend */
|
||||
@ -2491,9 +2487,40 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
|
||||
|
||||
bool p3ConnectMgr::setAddressList(std::string id, std::list<IpAddressTimed> IpAddressTimedList)
|
||||
{
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
/* check if it is our own ip */
|
||||
if (id == getOwnId()) {
|
||||
//extract first address that is not the same as local address
|
||||
//check if the ip list contains the current remote address of the connected peer
|
||||
bool found = false;
|
||||
std::list<IpAddressTimed>::iterator ipListIt;
|
||||
for (ipListIt = IpAddressTimedList.begin(); ipListIt!=(IpAddressTimedList.end()) && !found; ipListIt++) {
|
||||
//assume address is valid if not same as local address, is not 0 and is not loopback
|
||||
if (!(ipListIt->ipAddr.sin_addr.s_addr == ownState.currentlocaladdr.sin_addr.s_addr)
|
||||
&& (ipListIt->ipAddr.sin_addr.s_addr != 0)
|
||||
&& (!isLoopbackNet(&ipListIt->ipAddr.sin_addr))
|
||||
) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* check if it is a friend */
|
||||
if (found) {
|
||||
//the pointer ipListIt is pointing to an external address
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::setAddressList() setting own ext adress from p3disc : ";
|
||||
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr) << ":" << ntohs(ipListIt->ipAddr.sin_port) << " seenTime : " << ipListIt->seenTime << std::endl;
|
||||
#endif
|
||||
|
||||
setExtAddress(getOwnId(), ipListIt->ipAddr);
|
||||
}
|
||||
|
||||
|
||||
IndicateConfigChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* check if it is a friend */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
|
@ -226,7 +226,6 @@ bool setLocalAddress(std::string id, struct sockaddr_in addr);
|
||||
bool setExtAddress(std::string id, struct sockaddr_in addr);
|
||||
bool setAddressList(std::string id, std::list<IpAddressTimed> IpAddressTimedList);
|
||||
|
||||
|
||||
bool setNetworkMode(std::string id, uint32_t netMode);
|
||||
bool setVisState(std::string id, uint32_t visState);
|
||||
|
||||
@ -268,7 +267,7 @@ virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t ty
|
||||
/****************** Connections *******************/
|
||||
bool connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||
uint32_t &delay, uint32_t &period, uint32_t &type);
|
||||
bool connectResult(std::string id, bool success, uint32_t flags);
|
||||
bool connectResult(std::string id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address);
|
||||
bool doNextAttempt(std::string id);
|
||||
|
||||
p3tunnel* getP3tunnel();
|
||||
@ -287,7 +286,7 @@ virtual bool netAssistConnectEnabled();
|
||||
virtual bool netAssistConnectActive();
|
||||
virtual bool netAssistConnectShutdown();
|
||||
|
||||
/* Assist Firewall */
|
||||
/* Assist Firewall */
|
||||
bool netAssistExtAddress(struct sockaddr_in &extAddr);
|
||||
bool netAssistFirewallPorts(uint16_t iport, uint16_t eport);
|
||||
|
||||
|
@ -374,6 +374,7 @@ virtual int stoplistening() = 0;
|
||||
virtual int disconnect() = 0;
|
||||
virtual int reset() = 0;
|
||||
virtual std::string PeerId() { return peerId; }
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr) = 0;
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value) = 0;
|
||||
|
||||
|
@ -138,6 +138,7 @@ virtual int stoplistening();
|
||||
virtual int disconnect();
|
||||
virtual int reset();
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value) { return false; }
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr) {return 0;}
|
||||
|
||||
// Bin Interface.
|
||||
virtual int tick();
|
||||
|
@ -156,7 +156,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
}
|
||||
|
||||
/* find the pqi, */
|
||||
pqiconnect *pqi = NULL;
|
||||
pqiconnect *pqi = NULL;
|
||||
uint32_t type = 0;
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
|
||||
@ -193,8 +193,11 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
case CONNECT_SUCCESS:
|
||||
|
||||
/* notify */
|
||||
if (pqipg)
|
||||
pqipg->notifyConnect(PeerId(), type, true);
|
||||
if (pqipg) {
|
||||
struct sockaddr_in remote_peer_address;
|
||||
pqi->getConnectAddress(remote_peer_address);
|
||||
pqipg->notifyConnect(PeerId(), type, true, remote_peer_address);
|
||||
}
|
||||
|
||||
if ((active) && (activepqi != pqi)) // already connected - trouble
|
||||
{
|
||||
|
@ -69,6 +69,7 @@ virtual int stoplistening() { return ni -> stoplistening(); }
|
||||
virtual int reset() { return ni -> reset(); }
|
||||
virtual int disconnect() { return ni -> reset(); }
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value) { return ni -> connect_parameter(type, value);}
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr){ return ni->getConnectAddress(raddr); }
|
||||
|
||||
// get the contact from the net side!
|
||||
virtual std::string PeerId()
|
||||
|
@ -476,7 +476,13 @@ int pqipersongrp::connectPeer(std::string id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success)
|
||||
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success) {
|
||||
struct sockaddr_in remote_peer_address;
|
||||
sockaddr_clear(&remote_peer_address);
|
||||
notifyConnect(id, ptype, success, remote_peer_address);
|
||||
}
|
||||
|
||||
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success, struct sockaddr_in remote_peer_address)
|
||||
{
|
||||
uint32_t type = 0;
|
||||
if (ptype == PQI_CONNECT_TCP)
|
||||
@ -496,7 +502,7 @@ bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success
|
||||
if (ptype == PQI_CONNECT_DO_NEXT_ATTEMPT) {
|
||||
mConnMgr->doNextAttempt(id);
|
||||
} else {
|
||||
mConnMgr->connectResult(id, success, type);
|
||||
mConnMgr->connectResult(id, success, type, remote_peer_address);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,7 @@ int removePeer(std::string id);
|
||||
int connectPeer(std::string id);
|
||||
|
||||
/*** callback from children ****/
|
||||
bool notifyConnect(std::string id, uint32_t type, bool success, struct sockaddr_in remote_peer_address);
|
||||
bool notifyConnect(std::string id, uint32_t type, bool success);
|
||||
|
||||
// tick interfaces.
|
||||
|
@ -178,6 +178,11 @@ int pqissl::disconnect()
|
||||
return reset();
|
||||
}
|
||||
|
||||
int pqissl::getConnectAddress(struct sockaddr_in &raddr) {
|
||||
raddr = remote_addr;
|
||||
return (remote_addr.sin_addr.s_addr == 0);
|
||||
}
|
||||
|
||||
/* BinInterface version of reset() for pqistreamer */
|
||||
int pqissl::close()
|
||||
{
|
||||
|
@ -104,6 +104,7 @@ virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int reset();
|
||||
virtual int disconnect();
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr);
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value);
|
||||
|
||||
|
@ -196,6 +196,11 @@ int pqissltunnel::reset()
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqissltunnel::getConnectAddress(struct sockaddr_in &raddr) {
|
||||
sockaddr_clear(&raddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool pqissltunnel::connect_parameter(uint32_t type, uint32_t value)
|
||||
{
|
||||
{
|
||||
|
@ -85,6 +85,7 @@ virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int reset();
|
||||
virtual int disconnect();
|
||||
virtual int getConnectAddress(struct sockaddr_in &raddr);
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value);
|
||||
|
||||
|
@ -710,6 +710,13 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
|
||||
mConnMgr->stunStatus(hashid1, item->currentsaddr, type, RS_STUN_FRIEND_OF_FRIEND);
|
||||
}
|
||||
|
||||
/* send Own Ip list to connect manager. It will extract the external ip address from it */
|
||||
if (peerId == mConnMgr->getOwnId())
|
||||
{
|
||||
mConnMgr->setAddressList(mConnMgr->getOwnId(), item->ipAddressList);
|
||||
}
|
||||
|
||||
|
||||
addDiscoveryData(item->PeerId(), peerId, item->currentladdr, item->currentsaddr, item->discFlags, time(NULL));
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
|
||||
|
Loading…
x
Reference in New Issue
Block a user