mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-27 10:21:40 -05:00
change to only one ip list instead of one local and one remote
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1807 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9a6ff52da1
commit
f85adf7c25
@ -1597,7 +1597,7 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||||||
//TODO : we update both internal and external tcp adress, we should try to determinate wich one was use for this connection
|
//TODO : we update both internal and external tcp adress, we should try to determinate wich one was use for this connection
|
||||||
bool found = false;
|
bool found = false;
|
||||||
std::list<IpAddressTimed>::iterator ipListIt;
|
std::list<IpAddressTimed>::iterator ipListIt;
|
||||||
for (ipListIt = it->second.remoteaddrList.begin(); ipListIt!=(it->second.remoteaddrList.end()); ipListIt++) {
|
for (ipListIt = it->second.ipAddressList.begin(); ipListIt!=(it->second.ipAddressList.end()); ipListIt++) {
|
||||||
if (ipListIt->ipAddr.sin_addr.s_addr == it->second.currentserveraddr.sin_addr.s_addr && ipListIt->ipAddr.sin_port == it->second.currentserveraddr.sin_port) {
|
if (ipListIt->ipAddr.sin_addr.s_addr == it->second.currentserveraddr.sin_addr.s_addr && ipListIt->ipAddr.sin_port == it->second.currentserveraddr.sin_port) {
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::connectResult() remote ip found in the list. Update seen time for : ";
|
std::cerr << "p3ConnectMgr::connectResult() remote ip found in the list. Update seen time for : ";
|
||||||
@ -1623,12 +1623,12 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||||||
std::cerr << ":" << ntohs(it->second.currentserveraddr.sin_port);
|
std::cerr << ":" << ntohs(it->second.currentserveraddr.sin_port);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
it->second.remoteaddrList.push_back(ipAdress);
|
it->second.ipAddressList.push_back(ipAdress);
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if the list contains the current local address of the connected peer
|
//check if the list contains the current local address of the connected peer
|
||||||
found = false;
|
found = false;
|
||||||
for (ipListIt = it->second.remoteaddrList.begin(); ipListIt!=(it->second.remoteaddrList.end()); ipListIt++) {
|
for (ipListIt = it->second.ipAddressList.begin(); ipListIt!=(it->second.ipAddressList.end()); ipListIt++) {
|
||||||
if (ipListIt->ipAddr.sin_addr.s_addr == it->second.currentlocaladdr.sin_addr.s_addr && ipListIt->ipAddr.sin_port == it->second.currentlocaladdr.sin_port) {
|
if (ipListIt->ipAddr.sin_addr.s_addr == it->second.currentlocaladdr.sin_addr.s_addr && ipListIt->ipAddr.sin_port == it->second.currentlocaladdr.sin_port) {
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::connectResult() remote ip found in the list. Update seen time for : ";
|
std::cerr << "p3ConnectMgr::connectResult() remote ip found in the list. Update seen time for : ";
|
||||||
@ -1653,15 +1653,15 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||||||
std::cerr << ":" << ntohs(it->second.currentlocaladdr.sin_port);
|
std::cerr << ":" << ntohs(it->second.currentlocaladdr.sin_port);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
it->second.remoteaddrList.push_back(ipAdress);
|
it->second.ipAddressList.push_back(ipAdress);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::connectResult() current ip list for the peer : " << id;
|
std::cerr << "p3ConnectMgr::connectResult() current ip list for the peer : " << id;
|
||||||
std::cerr << ", size : " << it->second.remoteaddrList.size();
|
std::cerr << ", size : " << it->second.ipAddressList.size();
|
||||||
std::cerr << ", adresses : " << std::endl;
|
std::cerr << ", adresses : " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
for (ipListIt = it->second.remoteaddrList.begin(); ipListIt!=(it->second.remoteaddrList.end()); ipListIt++) {
|
for (ipListIt = it->second.ipAddressList.begin(); ipListIt!=(it->second.ipAddressList.end()); ipListIt++) {
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr);
|
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr);
|
||||||
std::cerr << ":" << ntohs(ipListIt->ipAddr.sin_port);
|
std::cerr << ":" << ntohs(ipListIt->ipAddr.sin_port);
|
||||||
@ -1999,7 +1999,7 @@ void p3ConnectMgr::peerStatus(std::string id,
|
|||||||
tcp_delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
tcp_delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if address is same -> try local */
|
/* if address is same net -> try local */
|
||||||
if ((isValidNet(&(details.laddr.sin_addr))) &&
|
if ((isValidNet(&(details.laddr.sin_addr))) &&
|
||||||
(sameNet(&(ownState.currentlocaladdr.sin_addr), &(details.laddr.sin_addr))))
|
(sameNet(&(ownState.currentlocaladdr.sin_addr), &(details.laddr.sin_addr))))
|
||||||
|
|
||||||
@ -2954,7 +2954,7 @@ bool p3ConnectMgr::setAddressList(std::string id, std::list<IpAddressTimed> I
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* "it" points to peer */
|
/* "it" points to peer */
|
||||||
it->second.remoteaddrList = IpAddressTimedList;
|
it->second.ipAddressList = IpAddressTimedList;
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -3247,19 +3247,9 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
|
|||||||
item->visState = ownState.visState;
|
item->visState = ownState.visState;
|
||||||
item->lastContact = ownState.lastcontact;
|
item->lastContact = ownState.lastcontact;
|
||||||
|
|
||||||
std::list <IpAddressTimed> tempLocaladdrList;
|
item->currentlocaladdr = ownState.currentlocaladdr;
|
||||||
struct IpAddressTimed locaIp;
|
item->currentremoteaddr = ownState.currentserveraddr;
|
||||||
locaIp.ipAddr = ownState.currentlocaladdr;
|
item->ipAddressList = ownState.ipAddressList;
|
||||||
locaIp.seenTime = time(NULL);
|
|
||||||
tempLocaladdrList.push_back(locaIp);
|
|
||||||
item->localaddrList = tempLocaladdrList;
|
|
||||||
|
|
||||||
std::list <IpAddressTimed> tempRemoteaddrList;
|
|
||||||
struct IpAddressTimed remoteIp;
|
|
||||||
remoteIp.ipAddr = ownState.currentserveraddr;
|
|
||||||
remoteIp.seenTime = time(NULL);
|
|
||||||
tempRemoteaddrList.push_back(remoteIp);
|
|
||||||
item->remoteaddrList = tempRemoteaddrList;
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::saveList() Own Config Item:";
|
std::cerr << "p3ConnectMgr::saveList() Own Config Item:";
|
||||||
@ -3283,8 +3273,7 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
|
|||||||
item->lastContact = (it->second).lastcontact;
|
item->lastContact = (it->second).lastcontact;
|
||||||
item->currentlocaladdr = (it->second).currentlocaladdr;
|
item->currentlocaladdr = (it->second).currentlocaladdr;
|
||||||
item->currentremoteaddr = (it->second).currentserveraddr;
|
item->currentremoteaddr = (it->second).currentserveraddr;
|
||||||
item->localaddrList = (it->second).localaddrList;
|
item->ipAddressList = (it->second).ipAddressList;
|
||||||
item->remoteaddrList = (it->second).remoteaddrList;
|
|
||||||
|
|
||||||
saveData.push_back(item);
|
saveData.push_back(item);
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
@ -3371,7 +3360,7 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
|
|||||||
addFriend(pitem->pid, pitem->netMode, pitem->visState, pitem->lastContact);
|
addFriend(pitem->pid, pitem->netMode, pitem->visState, pitem->lastContact);
|
||||||
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||||
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||||
setAddressList(pitem->pid, pitem->remoteaddrList);
|
setAddressList(pitem->pid, pitem->ipAddressList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sitem)
|
else if (sitem)
|
||||||
|
@ -83,6 +83,7 @@ const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
|
|||||||
|
|
||||||
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
|
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
|
||||||
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
|
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
|
||||||
|
const uint32_t RS_NET_CONN_TCP_UNKNOW_TOPOLOGY = 0x0003;
|
||||||
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010;
|
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010;
|
||||||
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */
|
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */
|
||||||
|
|
||||||
@ -137,8 +138,9 @@ class peerConnectState
|
|||||||
uint32_t visState; /* STD, GRAY, DARK */
|
uint32_t visState; /* STD, GRAY, DARK */
|
||||||
|
|
||||||
//used to store friends ip lists
|
//used to store friends ip lists
|
||||||
std::list<IpAddressTimed> localaddrList;
|
std::list<IpAddressTimed> ipAddressList;
|
||||||
std::list<IpAddressTimed> remoteaddrList;
|
void sortIpAdressList(); //Sort the ip list ordering by seen time
|
||||||
|
void purgeIpAdressList(); //purge old addresses to keep a small list
|
||||||
|
|
||||||
//used to store current ip (for config and connection management)
|
//used to store current ip (for config and connection management)
|
||||||
struct sockaddr_in currentlocaladdr; /* Mandatory */
|
struct sockaddr_in currentlocaladdr; /* Mandatory */
|
||||||
|
@ -764,7 +764,7 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i)
|
|||||||
s += GetTlvIpAddrPortV4Size(); /* remoteaddr */
|
s += GetTlvIpAddrPortV4Size(); /* remoteaddr */
|
||||||
|
|
||||||
//add the size of the ip list
|
//add the size of the ip list
|
||||||
int ipListSize = i->remoteaddrList.size();
|
int ipListSize = i->ipAddressList.size();
|
||||||
s += ipListSize * GetTlvIpAddrPortV4Size();
|
s += ipListSize * GetTlvIpAddrPortV4Size();
|
||||||
s += ipListSize * 8; //size of an uint64
|
s += ipListSize * 8; //size of an uint64
|
||||||
|
|
||||||
@ -806,7 +806,7 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3
|
|||||||
|
|
||||||
//store the ip list
|
//store the ip list
|
||||||
std::list<IpAddressTimed>::iterator ipListIt;
|
std::list<IpAddressTimed>::iterator ipListIt;
|
||||||
for (ipListIt = item->remoteaddrList.begin(); ipListIt!=(item->remoteaddrList.end()); ipListIt++) {
|
for (ipListIt = item->ipAddressList.begin(); ipListIt!=(item->ipAddressList.end()); ipListIt++) {
|
||||||
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(ipListIt->ipAddr));
|
ok &= SetTlvIpAddrPortV4(data, tlvsize, &offset, TLV_TYPE_IPV4_REMOTE, &(ipListIt->ipAddr));
|
||||||
ok &= setRawUInt64(data, tlvsize, &offset, ipListIt->seenTime);
|
ok &= setRawUInt64(data, tlvsize, &offset, ipListIt->seenTime);
|
||||||
}
|
}
|
||||||
@ -872,7 +872,7 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
|
|||||||
ipTimed.seenTime = time;
|
ipTimed.seenTime = time;
|
||||||
ipTimedList.push_back(ipTimed);
|
ipTimedList.push_back(ipTimed);
|
||||||
}
|
}
|
||||||
item->remoteaddrList = ipTimedList;
|
item->ipAddressList = ipTimedList;
|
||||||
|
|
||||||
if (offset != rssize)
|
if (offset != rssize)
|
||||||
{
|
{
|
||||||
|
@ -76,8 +76,7 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|||||||
struct sockaddr_in currentlocaladdr; /* Mandatory */
|
struct sockaddr_in currentlocaladdr; /* Mandatory */
|
||||||
struct sockaddr_in currentremoteaddr; /* Mandatory */
|
struct sockaddr_in currentremoteaddr; /* Mandatory */
|
||||||
|
|
||||||
std::list<IpAddressTimed> localaddrList;
|
std::list<IpAddressTimed> ipAddressList;
|
||||||
std::list<IpAddressTimed> remoteaddrList;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsPeerStunItem: public RsItem
|
class RsPeerStunItem: public RsItem
|
||||||
|
@ -82,8 +82,7 @@ virtual void clear();
|
|||||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
//use for transmitting peer adress list
|
//use for transmitting peer adress list
|
||||||
std::list<IpAddressTimed> localaddrList;
|
std::list<IpAddressTimed> ipAddressList;
|
||||||
std::list<IpAddressTimed> remoteaddrList;
|
|
||||||
|
|
||||||
//use for transmitting my own adress list
|
//use for transmitting my own adress list
|
||||||
struct sockaddr_in currentladdr;
|
struct sockaddr_in currentladdr;
|
||||||
|
@ -431,8 +431,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
|
|||||||
di -> aboutId = about;
|
di -> aboutId = about;
|
||||||
|
|
||||||
// set the server address.
|
// set the server address.
|
||||||
di -> localaddrList = detail.localaddrList;
|
di -> ipAddressList = detail.ipAddressList;
|
||||||
di -> remoteaddrList = detail.remoteaddrList;
|
|
||||||
|
|
||||||
if (detail.state & RS_PEER_S_CONNECTED)
|
if (detail.state & RS_PEER_S_CONNECTED)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user