mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-03 11:54:30 -04:00
Use link local address only if necessary
This should solve APIPA address being always selected as preferred local address on Windows which was causing problems connecting to machines on the same local network. Now the link local address is used as fallback only if there is non link local private address available.
This commit is contained in:
parent
afc43d0ff7
commit
0c99975800
4 changed files with 80 additions and 33 deletions
|
@ -3,7 +3,8 @@
|
|||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-2011 by Robert Fernie.
|
||||
* Copyright (C) 2007-2011 Robert Fernie
|
||||
* Copyright (C) 2015-2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -37,8 +38,7 @@
|
|||
#include "util/extaddrfinder.h"
|
||||
#include "util/dnsresolver.h"
|
||||
|
||||
//#include "util/rsprint.h"
|
||||
//#include "util/rsdebug.h"
|
||||
|
||||
struct RsLog::logInfo p3netmgrzoneInfo = {RsLog::Default, "p3netmgr"};
|
||||
#define p3netmgrzone &p3netmgrzoneInfo
|
||||
|
||||
|
@ -165,11 +165,6 @@ void p3NetMgrIMPL::setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr)
|
|||
mLinkMgr = linkMgr;
|
||||
}
|
||||
|
||||
//void p3NetMgrIMPL::setDhtMgr(p3DhtMgr *dhtMgr)
|
||||
//{
|
||||
// mDhtMgr = dhtMgr;
|
||||
//}
|
||||
|
||||
#ifdef RS_USE_DHT_STUNNER
|
||||
void p3NetMgrIMPL::setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun)
|
||||
{
|
||||
|
@ -1020,19 +1015,39 @@ bool p3NetMgrIMPL::checkNetAddress()
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO: Sat Oct 24 15:51:24 CEST 2015 The fact of having just one local address is a flawed assumption, this should be redesigned soon.
|
||||
/* TODO: Sat Oct 24 15:51:24 CEST 2015 The fact of having just one local
|
||||
* address is a flawed assumption, this should be redesigned as soon as
|
||||
* possible. It will require complete reenginering of the network layer
|
||||
* code.
|
||||
*/
|
||||
std::list<sockaddr_storage> addrs;
|
||||
std::list<sockaddr_storage>::iterator it;
|
||||
if (getLocalAddresses(addrs))
|
||||
for(it = addrs.begin(); (it != addrs.end() && !validAddr); ++it)
|
||||
if(sockaddr_storage_isValidNet(*it) && !sockaddr_storage_isLoopbackNet(*it))
|
||||
{
|
||||
for (auto&& addr : addrs)
|
||||
{
|
||||
if( sockaddr_storage_isValidNet(addr) &&
|
||||
!sockaddr_storage_isLoopbackNet(addr) &&
|
||||
!sockaddr_storage_isLinkLocalNet(addr))
|
||||
{
|
||||
prefAddr = *it;
|
||||
prefAddr = addr;
|
||||
validAddr = true;
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cout << "p3NetMgrIMPL::checkNetAddress() prefAddr: " << sockaddr_storage_iptostring(prefAddr) << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If no satisfactory local address has been found yet relax and
|
||||
// accept also link local addresses
|
||||
if(!validAddr) for (auto&& addr : addrs)
|
||||
{
|
||||
if( sockaddr_storage_isValidNet(addr) &&
|
||||
!sockaddr_storage_isLoopbackNet(addr) )
|
||||
{
|
||||
prefAddr = addr;
|
||||
validAddr = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue