mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-12 01:14:29 -05:00
modified the update system for address lists, so that the list is totally replaced (and not merged) when it comes from the peer itself. This helps cleaning wrong addresses
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@3148 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a38ae6241e
commit
aa15f95907
@ -2075,7 +2075,7 @@ int AuthSSL::VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx)
|
|||||||
if (mConnMgr->getFriendNetStatus(peer_id_in_context, detail)) {
|
if (mConnMgr->getFriendNetStatus(peer_id_in_context, detail)) {
|
||||||
//transfer ips only if the two peers got the same gpg key
|
//transfer ips only if the two peers got the same gpg key
|
||||||
if (detail.gpg_id == getX509CNString(X509_STORE_CTX_get_current_cert(ctx)->cert_info->issuer)) {
|
if (detail.gpg_id == getX509CNString(X509_STORE_CTX_get_current_cert(ctx)->cert_info->issuer)) {
|
||||||
mConnMgr->setAddressList(certId, detail.getIpAddressList());
|
mConnMgr->updateAddressList(certId, detail.getIpAddressList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -308,7 +308,7 @@ void p3ConnectMgr::netReset()
|
|||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr time since last reset : " << delta << std::endl;
|
std::cerr << "p3ConnectMgr time since last reset : " << delta << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (delta < MIN_TIME_BETWEEN_NET_RESET) {
|
if (delta < (time_t)MIN_TIME_BETWEEN_NET_RESET) {
|
||||||
{
|
{
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
mNetStatus = RS_NET_NEED_RESET;
|
mNetStatus = RS_NET_NEED_RESET;
|
||||||
@ -577,7 +577,7 @@ void p3ConnectMgr::netTick()
|
|||||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
/* start tcp network - if necessary */
|
/* start tcp network - if necessary */
|
||||||
//TODO : implement stop listeners in net reset
|
//TODO : implement stop listeners in net reset
|
||||||
if (!mListenerActive && netStatus != RS_NET_NEED_RESET && (time(NULL) - mNetInitTS) > (MIN_TIME_BETWEEN_NET_RESET + 2)) {//start connection 2 second after the possible next one net reset
|
if (!mListenerActive && netStatus != RS_NET_NEED_RESET && (time(NULL) - mNetInitTS) > (time_t)(MIN_TIME_BETWEEN_NET_RESET + 2)) {//start connection 2 second after the possible next one net reset
|
||||||
startListeners();
|
startListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,7 +658,7 @@ void p3ConnectMgr::netDhtInit()
|
|||||||
#endif
|
#endif
|
||||||
connMtx.lock(); /* LOCK MUTEX */
|
connMtx.lock(); /* LOCK MUTEX */
|
||||||
|
|
||||||
uint32_t vs = ownState.visState;
|
//uint32_t vs = ownState.visState;
|
||||||
|
|
||||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
|
|
||||||
@ -707,7 +707,7 @@ void p3ConnectMgr::netUpnpCheck()
|
|||||||
struct sockaddr_in extAddr;
|
struct sockaddr_in extAddr;
|
||||||
int upnpState = netAssistFirewallActive();
|
int upnpState = netAssistFirewallActive();
|
||||||
|
|
||||||
if ((upnpState == 0) && (delta > MAX_UPNP_INIT))
|
if ((upnpState == 0) && (delta > (time_t)MAX_UPNP_INIT))
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG_TICK
|
#ifdef CONN_DEBUG_TICK
|
||||||
std::cerr << "p3ConnectMgr::netUpnpCheck() ";
|
std::cerr << "p3ConnectMgr::netUpnpCheck() ";
|
||||||
@ -2097,6 +2097,7 @@ bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMod
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Authentication is now tested at connection time, we don't store the ssl cert anymore
|
//Authentication is now tested at connection time, we don't store the ssl cert anymore
|
||||||
|
//
|
||||||
if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId())
|
if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId())
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
@ -2656,7 +2657,7 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ConnectMgr::setAddressList(const std::string& id, const std::list<IpAddressTimed>& IpAddressTimedList)
|
bool p3ConnectMgr::updateAddressList(const std::string& id, const std::list<IpAddressTimed>& IpAddressTimedList,bool merge)
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::setAddressList() called for id : " << id << std::endl;
|
std::cerr << "p3ConnectMgr::setAddressList() called for id : " << id << std::endl;
|
||||||
@ -2667,7 +2668,7 @@ bool p3ConnectMgr::setAddressList(const std::string& id, const std::list<IpAd
|
|||||||
/* check if it is our own ip */
|
/* check if it is our own ip */
|
||||||
if (id == getOwnId())
|
if (id == getOwnId())
|
||||||
{
|
{
|
||||||
ownState.updateIpAddressList(IpAddressTimedList);
|
ownState.updateIpAddressList(IpAddressTimedList,merge);
|
||||||
|
|
||||||
//if we have no ext address from upnp or extAdrFinder, we will use this list for ext ip detection
|
//if we have no ext address from upnp or extAdrFinder, we will use this list for ext ip detection
|
||||||
//useless, already done in network consistency check
|
//useless, already done in network consistency check
|
||||||
@ -2701,7 +2702,7 @@ bool p3ConnectMgr::setAddressList(const std::string& id, const std::list<IpAd
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* "it" points to peer */
|
/* "it" points to peer */
|
||||||
it->second.updateIpAddressList(IpAddressTimedList);
|
it->second.updateIpAddressList(IpAddressTimedList,merge);
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -3069,7 +3070,7 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
|
|||||||
}
|
}
|
||||||
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||||
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||||
setAddressList(pitem->pid, pitem->ipAddressList);
|
updateAddressList(pitem->pid, pitem->ipAddressList,false);
|
||||||
}
|
}
|
||||||
else if (sitem)
|
else if (sitem)
|
||||||
{
|
{
|
||||||
@ -3447,8 +3448,11 @@ std::list<IpAddressTimed> peerConnectState::getIpAddressList()
|
|||||||
return ipAddressList;
|
return ipAddressList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void peerConnectState::updateIpAddressList(const std::list<IpAddressTimed>& ipTimedList) //purge old addresses to keep a small list
|
void peerConnectState::updateIpAddressList(const std::list<IpAddressTimed>& ipTimedList,bool merge) //purge old addresses to keep a small list
|
||||||
{
|
{
|
||||||
|
if(!merge)
|
||||||
|
ipAddressList.clear() ;
|
||||||
|
|
||||||
std::list<IpAddressTimed>::const_iterator ipListIt;
|
std::list<IpAddressTimed>::const_iterator ipListIt;
|
||||||
|
|
||||||
for (ipListIt = ipTimedList.begin(); ipListIt!=(ipTimedList.end()); ++ipListIt)
|
for (ipListIt = ipTimedList.begin(); ipListIt!=(ipTimedList.end()); ++ipListIt)
|
||||||
|
@ -144,8 +144,13 @@ class peerConnectState
|
|||||||
//used to store friends ip lists
|
//used to store friends ip lists
|
||||||
void sortIpAddressListBySeenTime(); //Sort the ip list ordering by seen time
|
void sortIpAddressListBySeenTime(); //Sort the ip list ordering by seen time
|
||||||
std::list<IpAddressTimed> getIpAddressList(); //return the sorted ant purged list.
|
std::list<IpAddressTimed> getIpAddressList(); //return the sorted ant purged list.
|
||||||
|
|
||||||
|
// The function that takes a list, can either merge the list into the
|
||||||
|
// existing list (default behavior), or only set the list to the new data,
|
||||||
|
// which might be used if the info is from an authoritative source.
|
||||||
|
//
|
||||||
|
void updateIpAddressList(const std::list<IpAddressTimed>& ipTimedList,bool merge=true);
|
||||||
void updateIpAddressList(const IpAddressTimed& ipTimed);
|
void updateIpAddressList(const IpAddressTimed& ipTimed);
|
||||||
void updateIpAddressList(const std::list<IpAddressTimed>& ipTimedList);
|
|
||||||
void printIpAddressList();
|
void printIpAddressList();
|
||||||
|
|
||||||
static bool is_same_address (const IpAddressTimed& first, const IpAddressTimed& second);
|
static bool is_same_address (const IpAddressTimed& first, const IpAddressTimed& second);
|
||||||
@ -225,7 +230,7 @@ bool getNetStatusExtraAddressCheckOk();
|
|||||||
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
||||||
bool setLocalAddress(std::string id, struct sockaddr_in addr);
|
bool setLocalAddress(std::string id, struct sockaddr_in addr);
|
||||||
bool setExtAddress(std::string id, struct sockaddr_in addr);
|
bool setExtAddress(std::string id, struct sockaddr_in addr);
|
||||||
bool setAddressList(const std::string& id, const std::list<IpAddressTimed>& IpAddressTimedList);
|
bool updateAddressList(const std::string& id, const std::list<IpAddressTimed>& IpAddressTimedList,bool merge = true);
|
||||||
|
|
||||||
bool setNetworkMode(std::string id, uint32_t netMode);
|
bool setNetworkMode(std::string id, uint32_t netMode);
|
||||||
bool setVisState(std::string id, uint32_t visState);
|
bool setVisState(std::string id, uint32_t visState);
|
||||||
|
@ -552,6 +552,8 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||||||
//
|
//
|
||||||
if(AuthGPG::getAuthGPG()->isGPGAccepted(pitem->gpg_id) || pitem->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
if(AuthGPG::getAuthGPG()->isGPGAccepted(pitem->gpg_id) || pitem->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
||||||
{
|
{
|
||||||
|
bool merge = true ;
|
||||||
|
|
||||||
// Add with no disc by default. If friend already exists, it will do nothing
|
// Add with no disc by default. If friend already exists, it will do nothing
|
||||||
//
|
//
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
@ -578,6 +580,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||||||
// The info from the peer itself is ultimately trustable, so we can override some info,
|
// The info from the peer itself is ultimately trustable, so we can override some info,
|
||||||
// such as:
|
// such as:
|
||||||
// - local and global addresses
|
// - local and global addresses
|
||||||
|
// - address list
|
||||||
//
|
//
|
||||||
if (item->PeerId() == pitem->pid)
|
if (item->PeerId() == pitem->pid)
|
||||||
{
|
{
|
||||||
@ -591,6 +594,11 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||||||
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||||
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||||
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
||||||
|
|
||||||
|
// When the peer sends his own list of IPs, the info replaces the existing info, because the
|
||||||
|
// peer is the primary source of his own IPs.
|
||||||
|
//
|
||||||
|
merge = false ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
@ -602,7 +610,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// allways update address list, except if it's ours
|
// allways update address list, except if it's ours
|
||||||
mConnMgr->setAddressList(pitem->pid, pitem->ipAddressList);
|
mConnMgr->updateAddressList(pitem->pid, pitem->ipAddressList,merge);
|
||||||
}
|
}
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user