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:
joss17 2009-11-11 16:45:46 +00:00
parent 9a6ff52da1
commit f85adf7c25
6 changed files with 25 additions and 37 deletions

View File

@ -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
bool found = false;
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) {
#ifdef CONN_DEBUG
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 << std::endl;
#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
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) {
#ifdef CONN_DEBUG
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 << std::endl;
#endif
it->second.remoteaddrList.push_back(ipAdress);
it->second.ipAddressList.push_back(ipAdress);
}
#ifdef CONN_DEBUG
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;
#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
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr);
std::cerr << ":" << ntohs(ipListIt->ipAddr.sin_port);
@ -1999,7 +1999,7 @@ void p3ConnectMgr::peerStatus(std::string id,
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))) &&
(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->second.remoteaddrList = IpAddressTimedList;
it->second.ipAddressList = IpAddressTimedList;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
@ -3247,19 +3247,9 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
item->visState = ownState.visState;
item->lastContact = ownState.lastcontact;
std::list <IpAddressTimed> tempLocaladdrList;
struct IpAddressTimed locaIp;
locaIp.ipAddr = ownState.currentlocaladdr;
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;
item->currentlocaladdr = ownState.currentlocaladdr;
item->currentremoteaddr = ownState.currentserveraddr;
item->ipAddressList = ownState.ipAddressList;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::saveList() Own Config Item:";
@ -3283,8 +3273,7 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
item->lastContact = (it->second).lastcontact;
item->currentlocaladdr = (it->second).currentlocaladdr;
item->currentremoteaddr = (it->second).currentserveraddr;
item->localaddrList = (it->second).localaddrList;
item->remoteaddrList = (it->second).remoteaddrList;
item->ipAddressList = (it->second).ipAddressList;
saveData.push_back(item);
#ifdef CONN_DEBUG
@ -3371,7 +3360,7 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
addFriend(pitem->pid, pitem->netMode, pitem->visState, pitem->lastContact);
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
setExtAddress(pitem->pid, pitem->currentremoteaddr);
setAddressList(pitem->pid, pitem->remoteaddrList);
setAddressList(pitem->pid, pitem->ipAddressList);
}
}
else if (sitem)

View File

@ -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_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_PEER_SYNC = 0x0020; /* coming soon */
@ -137,8 +138,9 @@ class peerConnectState
uint32_t visState; /* STD, GRAY, DARK */
//used to store friends ip lists
std::list<IpAddressTimed> localaddrList;
std::list<IpAddressTimed> remoteaddrList;
std::list<IpAddressTimed> ipAddressList;
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)
struct sockaddr_in currentlocaladdr; /* Mandatory */

View File

@ -764,7 +764,7 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i)
s += GetTlvIpAddrPortV4Size(); /* remoteaddr */
//add the size of the ip list
int ipListSize = i->remoteaddrList.size();
int ipListSize = i->ipAddressList.size();
s += ipListSize * GetTlvIpAddrPortV4Size();
s += ipListSize * 8; //size of an uint64
@ -806,7 +806,7 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3
//store the ip list
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 &= setRawUInt64(data, tlvsize, &offset, ipListIt->seenTime);
}
@ -872,7 +872,7 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size
ipTimed.seenTime = time;
ipTimedList.push_back(ipTimed);
}
item->remoteaddrList = ipTimedList;
item->ipAddressList = ipTimedList;
if (offset != rssize)
{

View File

@ -76,8 +76,7 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
struct sockaddr_in currentlocaladdr; /* Mandatory */
struct sockaddr_in currentremoteaddr; /* Mandatory */
std::list<IpAddressTimed> localaddrList;
std::list<IpAddressTimed> remoteaddrList;
std::list<IpAddressTimed> ipAddressList;
};
class RsPeerStunItem: public RsItem

View File

@ -82,8 +82,7 @@ virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
//use for transmitting peer adress list
std::list<IpAddressTimed> localaddrList;
std::list<IpAddressTimed> remoteaddrList;
std::list<IpAddressTimed> ipAddressList;
//use for transmitting my own adress list
struct sockaddr_in currentladdr;

View File

@ -431,8 +431,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about)
di -> aboutId = about;
// set the server address.
di -> localaddrList = detail.localaddrList;
di -> remoteaddrList = detail.remoteaddrList;
di -> ipAddressList = detail.ipAddressList;
if (detail.state & RS_PEER_S_CONNECTED)
{