Change some code according G10h4ck remarks.

This commit is contained in:
Phenom 2021-11-04 13:10:15 +01:00
parent 7755f85c4c
commit 91a35f4a21
9 changed files with 242 additions and 212 deletions

View File

@ -47,15 +47,15 @@ struct RsLog::logInfo p3netmgrzoneInfo = {RsLog::Default, "p3netmgr"};
/* Network setup States */
const uint32_t RS_NET_NEEDS_RESET = 0x0000;
const uint32_t RS_NET_UNKNOWN = 0x0001;
const uint32_t RS_NET_UPNP_INIT = 0x0002;
const uint32_t RS_NET_UPNP_SETUP = 0x0003;
const uint32_t RS_NET_EXT_SETUP = 0x0004;
const uint32_t RS_NET_DONE = 0x0005;
const uint32_t RS_NET_LOOPBACK = 0x0006;
//const uint32_t RS_NET_DOWN = 0x0007;
const uint32_t RS_NET_SHUTDOWN = 0x00FF; //Highest value to not restart UPnP nor ExtAddrFinder
constexpr uint32_t RS_NET_NEEDS_RESET = 0x0000;
constexpr uint32_t RS_NET_UNKNOWN = 0x0001;
constexpr uint32_t RS_NET_UPNP_INIT = 0x0002;
constexpr uint32_t RS_NET_UPNP_SETUP = 0x0003;
constexpr uint32_t RS_NET_EXT_SETUP = 0x0004;
constexpr uint32_t RS_NET_DONE = 0x0005;
constexpr uint32_t RS_NET_LOOPBACK = 0x0006;
//constexpr uint32_t RS_NET_DOWN = 0x0007;
constexpr uint32_t RS_NET_SHUTDOWN = 0x00FF; //Highest value to not restart UPnP nor ExtAddrFinder
/* Stun modes (TODO) */
//const uint32_t RS_STUN_DHT = 0x0001;
@ -118,7 +118,7 @@ p3NetMgrIMPL::p3NetMgrIMPL()
{
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mExtAddrFinder = new ExtAddrFinder();
@ -233,7 +233,7 @@ void p3NetMgrIMPL::netReset()
shutdown(); /* blocking shutdown call */
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetStatus = RS_NET_UNKNOWN;
}
@ -266,7 +266,7 @@ void p3NetMgrIMPL::netReset()
* as it calls back to p3ConnMgr.
*/
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
struct sockaddr_storage iaddr = mLocalAddr;
@ -284,7 +284,7 @@ void p3NetMgrIMPL::netReset()
}
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
netStatusReset_locked();
}
@ -311,7 +311,7 @@ bool p3NetMgrIMPL::shutdown() /* blocking shutdown call */
std::cerr << std::endl;
#endif
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetStatus = RS_NET_SHUTDOWN;
mNetInitTS = time(NULL);
netStatusReset_locked();
@ -347,7 +347,7 @@ void p3NetMgrIMPL::netStartup()
*/
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetInitTS = time(NULL);
netStatusReset_locked();
@ -462,7 +462,7 @@ void p3NetMgrIMPL::netStatusTick()
rstime_t age = 0;
bool needExtFinderUpdate = false;
{
RsStackMutex stack(mNetMtx); /************** LOCK MUTEX ***************/
RS_STACK_MUTEX(mNetMtx); /************** LOCK MUTEX ***************/
netStatus = mNetStatus;
age = time(NULL) - mNetInitTS;
@ -477,9 +477,10 @@ void p3NetMgrIMPL::netStatusTick()
&& ( netStatus <= RS_NET_UPNP_SETUP
|| needExtFinderUpdate) )
{
sockaddr_storage tmpip = mLocalAddr; // copies local port and correctly inits the IP family
sockaddr_storage tmpip;
sockaddr_storage_copy( mLocalAddr, tmpip); // copies local port and correctly inits the IP family
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
RsDbg(__PRETTY_FUNCTION__, " Asking ExtAddrFinder for IP. Initializing port with ", sockaddr_storage_port(tmpip));
RS_DBG("Asking ExtAddrFinder for IP. Initializing port with ", sockaddr_storage_port(tmpip));
#endif
if(mExtAddrFinder->hasValidIPV4(tmpip))
@ -487,7 +488,7 @@ void p3NetMgrIMPL::netStatusTick()
if(!sockaddr_storage_same(tmpip,mExtAddr))
{
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
RsDbg(__PRETTY_FUNCTION__, " Ext supplied by ExtAddrFinder", " ExtAddr: ", sockaddr_storage_tostring(tmpip));
RS_DBG("Ext supplied by ExtAddrFinder. ExtAddr: ", tmpip);
#endif
setExtAddress(tmpip);
}
@ -498,7 +499,7 @@ void p3NetMgrIMPL::netStatusTick()
{
//Only if no IPv4 else, reset connections on setExtAddress()
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
RsDbg(__PRETTY_FUNCTION__, " Ext supplied by ExtAddrFinder", " ExtAddr: ", sockaddr_storage_tostring(tmpip));
RS_DBG("Ext supplied by ExtAddrFinder. ExtAddr: ", tmpip);
#endif
setExtAddress(tmpip);
}
@ -593,7 +594,7 @@ void p3NetMgrIMPL::netDhtInit()
uint32_t vs = 0;
{
RsStackMutex stack(mNetMtx); /*********** LOCKED MUTEX ************/
RS_STACK_MUTEX(mNetMtx); /*********** LOCKED MUTEX ************/
vs = mVsDht;
}
@ -760,16 +761,14 @@ void p3NetMgrIMPL::netExtCheck()
if (mUseExtAddrFinder)
{
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
RsDbg(__PRETTY_FUNCTION__, " checking ExtAddrFinder");
RS_DBG("checking ExtAddrFinder");
#endif
sockaddr_storage tmpip = mLocalAddr; // copies local port and correctly inits the IP family
sockaddr_storage tmpip;
sockaddr_storage_copy( mLocalAddr, tmpip); // copies local port and correctly inits the IP family
// Test for IPv4 first to be compatible with older versions.
if (mExtAddrFinder->hasValidIPV4(tmpip))
{
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
RsDbg(__PRETTY_FUNCTION__, " Ext IPv4 supplied by ExtAddrFinder", sockaddr_storage_tostring(tmpip));
#endif
sockaddr_storage_setport(tmpip, guessNewExtPort());
mNetFlags.mExtAddrOk = true;
@ -781,13 +780,10 @@ void p3NetMgrIMPL::netExtCheck()
* (which it is not normally) */
mNetFlags.mExtAddrStableOk = true;
RsErr(__PRETTY_FUNCTION__, " reported external IPv4 address ", sockaddr_storage_iptostring(tmpip));
RS_DBG("Reported external IPv4 address ", sockaddr_storage_iptostring(tmpip));
}
else if (mExtAddrFinder->hasValidIPV6(tmpip))
{
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
RsDbg(__PRETTY_FUNCTION__, " Ext IPv6 supplied by ExtAddrFinder", sockaddr_storage_tostring(tmpip));
#endif
sockaddr_storage_setport(tmpip, guessNewExtPort());
mNetFlags.mExtAddrOk = true;
@ -799,7 +795,7 @@ void p3NetMgrIMPL::netExtCheck()
* (which it is not normally) */
mNetFlags.mExtAddrStableOk = true;
RsErr(__PRETTY_FUNCTION__, " reported external IPv6 address ", sockaddr_storage_iptostring(tmpip));
RS_DBG("Reported external IPv6 address ", sockaddr_storage_iptostring(tmpip));
}
}
}
@ -990,7 +986,7 @@ void p3NetMgrIMPL::netExtCheck()
if (netSetupDone)
{
RsDbg(__PRETTY_FUNCTION__, " netSetupDone");
RS_DBG("netSetupDone");
/* Setup NetStateBox with this info */
updateNetStateBox_startup();
@ -1008,7 +1004,7 @@ void p3NetMgrIMPL::netExtCheck()
netAssistKnownPeer(fakeId, mExtAddr, NETASSIST_KNOWN_PEER_SELF | NETASSIST_KNOWN_PEER_ONLINE);
}
RsDbg(__PRETTY_FUNCTION__, " Network Setup Complete");
RS_INFO("Network Setup Complete");
}
}
@ -1093,8 +1089,7 @@ bool p3NetMgrIMPL::checkNetAddress()
if (!validAddr)
{
RsErr() << __PRETTY_FUNCTION__ << " no valid local network address "
<<" found. Report to developers." << std::endl;
RS_ERR("no valid local network address found. Report to developers.");
print_stacktrace();
return false;
@ -1179,7 +1174,7 @@ bool p3NetMgrIMPL::checkNetAddress()
/* to allow resets of network stuff */
void p3NetMgrIMPL::addNetListener(pqiNetListener *listener)
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetListeners.push_back(listener);
}
@ -1189,7 +1184,7 @@ bool p3NetMgrIMPL::setLocalAddress(const struct sockaddr_storage &addr)
{
bool changed = false;
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
if (!sockaddr_storage_same(mLocalAddr, addr))
{
changed = true;
@ -1211,7 +1206,7 @@ bool p3NetMgrIMPL::setLocalAddress(const struct sockaddr_storage &addr)
}
bool p3NetMgrIMPL::getExtAddress(struct sockaddr_storage& addr)
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
if(mNetFlags.mExtAddrOk)
{
@ -1226,7 +1221,7 @@ bool p3NetMgrIMPL::setExtAddress(const struct sockaddr_storage &addr)
{
bool changed = false;
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
if (!sockaddr_storage_same(mExtAddr, addr))
{
changed = true;
@ -1260,7 +1255,7 @@ bool p3NetMgrIMPL::setNetworkMode(uint32_t netMode)
{
uint32_t oldNetMode;
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
/* only change TRY flags */
oldNetMode = mNetMode;
@ -1306,7 +1301,7 @@ bool p3NetMgrIMPL::setNetworkMode(uint32_t netMode)
bool p3NetMgrIMPL::setVisState(uint16_t vs_disc, uint16_t vs_dht)
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mVsDisc = vs_disc;
mVsDht = vs_dht;
@ -1668,7 +1663,7 @@ void p3NetMgrIMPL::getNetStatus(pqiNetStatus &status)
uint32_t netsize = 0, rsnetsize = 0;
netAssistConnectStats(netsize, rsnetsize);
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
/* quick update of the stuff that can change! */
mNetFlags.mDhtOk = dhtOk;
@ -1692,7 +1687,7 @@ void p3NetMgrIMPL::getNetStatus(pqiNetStatus &status)
bool p3NetMgrIMPL::getIPServersEnabled()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
return mUseExtAddrFinder;
}
@ -1721,12 +1716,12 @@ void p3NetMgrIMPL::setIPServersEnabled(bool b)
}
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mUseExtAddrFinder = b;
}
#ifdef NETMGR_DEBUG
RsDbg(__PRETTY_FUNCTION__, " set mUseExtAddrFinder to ", b);
RS_DBG("set mUseExtAddrFinder to ", b);
#endif
}
@ -1739,31 +1734,31 @@ void p3NetMgrIMPL::setIPServersEnabled(bool b)
RsNetState p3NetMgrIMPL::getNetStateMode()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetStateMode();
}
RsNetworkMode p3NetMgrIMPL::getNetworkMode()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetworkMode();
}
RsNatTypeMode p3NetMgrIMPL::getNatTypeMode()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatTypeMode();
}
RsNatHoleMode p3NetMgrIMPL::getNatHoleMode()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatHoleMode();
}
RsConnectModes p3NetMgrIMPL::getConnectModes()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getConnectModes();
}
@ -1787,7 +1782,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
/* input network bits */
if (mDhtStunner->getExternalAddr(tmpaddr, isstable))
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetStateBox.setAddressStunDht(tmpaddr, isstable);
#ifdef NETMGR_DEBUG_STATEBOX
@ -1806,7 +1801,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
/* input network bits */
if (mProxyStunner->getExternalAddr(tmpaddr, isstable))
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetStateBox.setAddressStunProxy(tmpaddr, isstable);
#ifdef NETMGR_DEBUG_STATEBOX
@ -1825,7 +1820,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
bool dhtOn = netAssistConnectEnabled();
bool dhtActive = netAssistConnectActive();
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetStateBox.setDhtState(dhtOn, dhtActive);
}
@ -1834,7 +1829,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
#ifdef NETMGR_DEBUG_STATEBOX
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
auto netstate = mNetStateBox.getNetStateMode();
auto netMode = mNetStateBox.getNetworkMode();
@ -1880,7 +1875,7 @@ void p3NetMgrIMPL::updateNatSetting()
RsNatTypeMode natType = RsNatTypeMode::UNKNOWN;
RsNatHoleMode natHole = RsNatHoleMode::UNKNOWN;
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
natType = mNetStateBox.getNatTypeMode();
natHole = mNetStateBox.getNatHoleMode();
@ -1982,7 +1977,7 @@ void p3NetMgrIMPL::updateNetStateBox_startup()
std::cerr << std::endl;
#endif
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
/* fill in the data */
struct sockaddr_storage tmpip;
@ -2077,7 +2072,7 @@ void p3NetMgrIMPL::updateNetStateBox_startup()
void p3NetMgrIMPL::updateNetStateBox_reset()
{
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetStateBox.reset();

View File

@ -1293,7 +1293,11 @@ bool p3Peers::getShortInvite(std::string& invite, const RsPeerId& _sslId, Retros
}
#else
sockaddr_storage tLocal;
if(sockaddr_storage_inet_pton(tLocal, tDetails.localAddr) && sockaddr_storage_isValidNet(tLocal) && sockaddr_storage_ipv6_to_ipv4(tLocal) && tDetails.localPort )
bool validLoc = sockaddr_storage_inet_pton(tLocal, tDetails.localAddr)
&& sockaddr_storage_isValidNet(tLocal)
&& tDetails.localPort;
bool isLocIpv4 = sockaddr_storage_ipv6_to_ipv4(tLocal);
if(validLoc && isLocIpv4)
{
uint32_t t4Addr = reinterpret_cast<sockaddr_in&>(tLocal).sin_addr.s_addr;
@ -1311,8 +1315,11 @@ bool p3Peers::getShortInvite(std::string& invite, const RsPeerId& _sslId, Retros
}
sockaddr_storage tExt;
struct in6_addr sin6_addr;
if(sockaddr_storage_inet_pton(tExt, tDetails.extAddr) && sockaddr_storage_isValidNet(tExt) && sockaddr_storage_ipv6_to_ipv4(tExt) && tDetails.extPort )
bool validExt = sockaddr_storage_inet_pton(tExt, tDetails.extAddr)
&& sockaddr_storage_isValidNet(tExt)
&& tDetails.extPort;
bool isExtIpv4 = sockaddr_storage_ipv6_to_ipv4(tExt);
if(validExt && isExtIpv4)
{
uint32_t t4Addr = reinterpret_cast<sockaddr_in&>(tExt).sin_addr.s_addr;
@ -1328,10 +1335,11 @@ bool p3Peers::getShortInvite(std::string& invite, const RsPeerId& _sslId, Retros
offset += 4+2;
}
else if(inet_pton(AF_INET6, tDetails.extAddr.c_str(), &(sin6_addr)))
else if(validExt && !isExtIpv4)
{
// External address is IPv6, save it on LOCATOR
std::string tLocator = "ipv6://[" + tDetails.extAddr + "]:" + std::to_string(tDetails.extPort);
sockaddr_storage_setport(tExt,tDetails.extPort);
std::string tLocator = sockaddr_storage_tostring(tExt);
addPacketHeader(RsShortInviteFieldType::LOCATOR, tLocator.size(),buf,offset,buf_size);
memcpy(&buf[offset],tLocator.c_str(),tLocator.size());
@ -1612,16 +1620,23 @@ std::string p3Peers::GetRetroshareInvite( const RsPeerId& sslId, RetroshareInvit
if (getPeerDetails(ssl_id, detail))
{
if(!(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY) || detail.isHiddenNode)
if( !(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY)
|| detail.isHiddenNode)
detail.ipAddressList.clear();
//Check if external address is IPv6, then move it to ipAddressList as RsCertificate only allow 4 numbers.
struct in6_addr sin6_addr;
if( inet_pton(AF_INET6, detail.extAddr.c_str(), &(sin6_addr))
&& !(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY)
&& !detail.isHiddenNode)
sockaddr_storage tExt;
bool validExt = sockaddr_storage_inet_pton(tExt, detail.extAddr)
&& sockaddr_storage_isValidNet(tExt)
&& detail.extPort;
bool isExtIpv4 = sockaddr_storage_ipv6_to_ipv4(tExt);
if( !(invite_flags & RetroshareInviteFlags::FULL_IP_HISTORY)
&& !detail.isHiddenNode
&& validExt && !isExtIpv4)
{
detail.ipAddressList.push_front("ipv6://[" + detail.extAddr + "]:" + std::to_string(detail.extPort) + " ");
sockaddr_storage_setport(tExt,detail.extPort);
detail.ipAddressList.push_front(sockaddr_storage_tostring(tExt) + " "); // Space needed to later parse.
detail.extAddr = ""; //Clear it to not trigg error.
detail.extPort = 0;
}

View File

@ -19,6 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
//#define EXTADDRSEARCH_DEBUG
#include "extaddrfinder.h"
#include "pqi/pqinetwork.h"
@ -43,8 +46,6 @@
const uint32_t MAX_IP_STORE = 300; /* seconds ip address timeout */
//#define EXTADDRSEARCH_DEBUG
class ZeroInt
{
public:
@ -52,129 +53,122 @@ public:
uint32_t n ;
};
void* doExtAddrSearch(void *p)
void ExtAddrFinder::run()
{
std::vector<std::string> res ;
ExtAddrFinder *af = (ExtAddrFinder*)p ;
for(std::list<std::string>::const_iterator it(af->_ip_servers.begin());it!=af->_ip_servers.end();++it)
for(auto& it : _ip_servers)
{
std::string ip = "";
rsGetHostByNameSpecDNS(*it,"myip.opendns.com",ip,2);
rsGetHostByNameSpecDNS(it,"myip.opendns.com",ip,2);
if(ip != "")
res.push_back(ip) ;
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " ip found through DNS ", *it, ": \"", ip, "\"");
RS_DBG("ip found through DNS ", it, ": \"", ip, "\"");
#endif
}
if(res.empty())
{
af->reset();
return NULL ;
reset();
return ;
}
std::map<sockaddr_storage,ZeroInt> addrV4_votes;
std::map<sockaddr_storage,ZeroInt> addrV6_votes;
std::string addrV4_Found;
std::string addrV6_Found;
std::string all_addrV4_Found;
std::string all_addrV6_Found;
for(auto curRes : res)
{
sockaddr_storage addr;
sockaddr_storage_clear(addr);
//sockaddr_storage_inet_pton convert IPv4 to IPv6
struct sockaddr_in * addrv4p = (struct sockaddr_in *) &addr;
struct sockaddr_in6 * addrv6p = (struct sockaddr_in6 *) &addr;
if( inet_pton(AF_INET, curRes.c_str(), &(addrv4p->sin_addr)) )
bool validIP = sockaddr_storage_inet_pton(addr, curRes)
&& sockaddr_storage_isValidNet(addr);
bool isIPv4 = sockaddr_storage_ipv6_to_ipv4(addr);
if( validIP && isIPv4 )
{
addr.ss_family = AF_INET;
addrV4_votes[addr].n++ ;
addrV4_Found += sockaddr_storage_tostring(addr) + "\n";
all_addrV4_Found += sockaddr_storage_tostring(addr) + "\n";
}
else if( inet_pton(AF_INET6, curRes.c_str(), &(addrv6p->sin6_addr)) )
else if( validIP && !isIPv4)
{
addr.ss_family = AF_INET6;
addrV6_votes[addr].n++ ;
addrV6_Found += sockaddr_storage_tostring(addr) + "\n";
all_addrV6_Found += sockaddr_storage_tostring(addr) + "\n";
}
else
RsErr(__PRETTY_FUNCTION__, " Invalid addresse reported: ", curRes) ;
RS_ERR("Invalid addresse reported: ", curRes) ;
}
if( (0 == addrV4_votes.size()) && (0 == addrV6_votes.size()) )
{
RsErr(__PRETTY_FUNCTION__, " Could not find any external address.");
af->reset();
return NULL ;
RS_ERR("Could not find any external address.");
reset();
return ;
}
if( 1 < addrV4_votes.size() )
RsErr(__PRETTY_FUNCTION__, " Multiple external IPv4 addresses reported: "
, addrV4_Found ) ;
RS_ERR("Multiple external IPv4 addresses reported: "
, all_addrV4_Found ) ;
if( 1 < addrV6_votes.size() )
RsErr(__PRETTY_FUNCTION__, " Multiple external IPv6 addresses reported: "
, addrV6_Found ) ;
RS_ERR("Multiple external IPv6 addresses reported: "
, all_addrV6_Found ) ;
{
RsStackMutex mtx(af->mAddrMtx) ;
af->mSearching = false ;
af->mFoundTS = time(NULL) ;
RS_STACK_MUTEX(mAddrMtx);
mSearching = false ;
mFoundTS = time(NULL) ;
// Only save more reported address if not only once.
uint32_t admax = 0 ;
sockaddr_storage_clear(af->mAddrV4);
sockaddr_storage_clear(mAddrV4);
for (auto it : addrV4_votes)
if (admax < it.second.n)
{
af->mAddrV4 = it.first ;
af->mFoundV4 = true ;
mAddrV4 = it.first ;
mFoundV4 = true ;
admax = it.second.n ;
}
admax = 0 ;
sockaddr_storage_clear(af->mAddrV6);
sockaddr_storage_clear(mAddrV6);
for (auto it : addrV6_votes)
if (admax < it.second.n)
{
af->mAddrV6 = it.first ;
af->mFoundV6 = true ;
mAddrV6 = it.first ;
mFoundV6 = true ;
admax = it.second.n ;
}
}
return NULL ;
return ;
}
void ExtAddrFinder::start_request()
{
void *data = (void *)this;
pthread_t tid ;
if(! pthread_create(&tid, 0, &doExtAddrSearch, data))
pthread_detach(tid); /* so memory is reclaimed in linux */
else
RsErr(__PRETTY_FUNCTION__, " Could not start ExtAddrFinder thread.");
if (!isRunning())
start("ExtAddrFinder");
}
bool ExtAddrFinder::hasValidIPV4(struct sockaddr_storage &addr)
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " Getting ip.");
RS_DBG("Getting ip.");
#endif
{
RsStackMutex mut(mAddrMtx) ;
RS_STACK_MUTEX(mAddrMtx) ;
if(mFoundV4)
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " Has stored ip responding with this ip:", sockaddr_storage_iptostring(mAddrV4)) ;
RS_DBG("Has stored ip responding with this ip:", sockaddr_storage_iptostring(mAddrV4)) ;
#endif
sockaddr_storage_copyip(addr,mAddrV4); // just copy the IP so we dont erase the port.
}
@ -182,22 +176,22 @@ bool ExtAddrFinder::hasValidIPV4(struct sockaddr_storage &addr)
testTimeOut();
RsStackMutex mut(mAddrMtx) ;
RS_STACK_MUTEX(mAddrMtx) ;
return mFoundV4;
}
bool ExtAddrFinder::hasValidIPV6(struct sockaddr_storage &addr)
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " Getting ip.");
RS_DBG("Getting ip.");
#endif
{
RsStackMutex mut(mAddrMtx) ;
RS_STACK_MUTEX(mAddrMtx) ;
if(mFoundV6)
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " Has stored ip responding with this ip:", sockaddr_storage_iptostring(mAddrV6)) ;
RS_DBG("Has stored ip responding with this ip:", sockaddr_storage_iptostring(mAddrV6)) ;
#endif
sockaddr_storage_copyip(addr,mAddrV6); // just copy the IP so we dont erase the port.
}
@ -205,7 +199,7 @@ bool ExtAddrFinder::hasValidIPV6(struct sockaddr_storage &addr)
testTimeOut();
RsStackMutex mut(mAddrMtx) ;
RS_STACK_MUTEX(mAddrMtx) ;
return mFoundV6;
}
@ -213,7 +207,7 @@ void ExtAddrFinder::testTimeOut()
{
bool timeOut;
{
RsStackMutex mut(mAddrMtx) ;
RS_STACK_MUTEX(mAddrMtx) ;
//timeout the current ip
timeOut = (mFoundTS + MAX_IP_STORE < time(NULL));
}
@ -223,21 +217,21 @@ void ExtAddrFinder::testTimeOut()
if(!mSearching)
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " No stored ip: Initiating new search.");
RS_DBG("No stored ip: Initiating new search.");
#endif
mSearching = true ;
start_request() ;
}
#ifdef EXTADDRSEARCH_DEBUG
else
RsDbg(__PRETTY_FUNCTION__, " Already searching.");
RS_DBG("Already searching.");
#endif
mFirstTime = false;
mAddrMtx.unlock();
}
#ifdef EXTADDRSEARCH_DEBUG
else
RsDbg(__PRETTY_FUNCTION__, " (Note) Could not acquire lock. Busy.");
RS_DBG("(Note) Could not acquire lock. Busy.");
#endif
}
}
@ -245,15 +239,15 @@ void ExtAddrFinder::testTimeOut()
void ExtAddrFinder::reset(bool firstTime /*=false*/)
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " firstTime=", firstTime?"true":"false");
RS_DBG("firstTime=", firstTime);
#endif
RsStackMutex mut(mAddrMtx) ;
RS_STACK_MUTEX(mAddrMtx) ;
mSearching = false ;
mFoundV4 = false ;
mFoundV6 = false ;
mFirstTime = firstTime;
mFoundTS = time(NULL);
mFoundTS = time(nullptr);
sockaddr_storage_clear(mAddrV4);
sockaddr_storage_clear(mAddrV6);
}
@ -261,15 +255,14 @@ void ExtAddrFinder::reset(bool firstTime /*=false*/)
ExtAddrFinder::~ExtAddrFinder()
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " Deleting ExtAddrFinder.");
RS_DBG("Deleting ExtAddrFinder.");
#endif
}
ExtAddrFinder::ExtAddrFinder() : mAddrMtx("ExtAddrFinder")
{
#ifdef EXTADDRSEARCH_DEBUG
RsDbg(__PRETTY_FUNCTION__, " Creating new ExtAddrFinder.");
RS_DBG("Creating new ExtAddrFinder.");
#endif
reset( true );
@ -283,4 +276,3 @@ ExtAddrFinder::ExtAddrFinder() : mAddrMtx("ExtAddrFinder")
_ip_servers.push_back(std::string( "2620:119:35::35" )) ;//resolver1.opendns.com
_ip_servers.push_back(std::string( "2620:119:53::53" )) ;//resolver2.opendns.com
}

View File

@ -30,7 +30,7 @@
struct sockaddr ;
class ExtAddrFinder
class ExtAddrFinder: public RsThread
{
public:
ExtAddrFinder() ;
@ -45,7 +45,7 @@ class ExtAddrFinder
void reset(bool firstTime = false) ;
private:
friend void* doExtAddrSearch(void *p);
virtual void run();
void testTimeOut();
RsMutex mAddrMtx;

View File

@ -21,6 +21,7 @@
*******************************************************************************/
//#define DEBUG_SPEC_DNS 1
#include "util/rsnet.h"
#include "util/rsdebug.h"
@ -101,51 +102,49 @@ struct RR_DATA
bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& hostname, std::string& returned_addr, int timeout_s /*= -1*/)
{
#ifdef DEBUG_SPEC_DNS
RsDbg()<<__PRETTY_FUNCTION__<<" servername="<< servername << " hostname=" << hostname << std::endl;
RS_DBG("servername=", servername, " hostname=", hostname);
#endif
if (strlen(servername.c_str()) > 256)
{
RsErr()<<__PRETTY_FUNCTION__<<": servername is too long > 256 chars:"<<servername<<std::endl;
RS_ERR("servername is too long > 256 chars: ", servername);
return false;
}
if (strlen(hostname.c_str()) > 256)
{
RsErr()<<__PRETTY_FUNCTION__<<": hostname is too long > 256 chars:"<<hostname<<std::endl;
RS_ERR("hostname is too long > 256 chars: ", hostname);
return false;
}
bool isIPV4 = false;
in_addr dns_server_4; in6_addr dns_server_6;
if (inet_pton(AF_INET, servername.c_str(), &dns_server_4))
isIPV4 = true;
else if (inet_pton(AF_INET6, servername.c_str(), &dns_server_6))
isIPV4 = false;
else if (rsGetHostByName(servername, dns_server_4))
isIPV4 = true;
else
sockaddr_storage serverAddr;
bool validServer = sockaddr_storage_inet_pton(serverAddr, servername)
&& sockaddr_storage_isValidNet(serverAddr);
bool isIPV4 = validServer && sockaddr_storage_ipv6_to_ipv4(serverAddr);
if (!validServer)
{
RsErr()<<__PRETTY_FUNCTION__<<": servername is on an unknow format: "<<servername<<std::endl;
return false;
in_addr in ;
if (!rsGetHostByName(servername, in))
{
RS_ERR("servername is on an unknow format: ", servername);
return false;
}
validServer = sockaddr_storage_inet_pton(serverAddr, rs_inet_ntoa(in))
&& sockaddr_storage_isValidNet(serverAddr);
isIPV4 = validServer && sockaddr_storage_ipv6_to_ipv4(serverAddr);
if (!validServer)
{
RS_ERR("rsGetHostByName return bad answer: ", rs_inet_ntoa(in));
return false;
}
}
unsigned char buf[65536];
struct sockaddr_in dest4;struct sockaddr_in6 dest6;
if (isIPV4)
{
dest4.sin_family = AF_INET;
dest4.sin_port = htons(53);
dest4.sin_addr.s_addr = dns_server_4.s_addr;
} else {
dest6.sin6_family = AF_INET6;
dest6.sin6_port = htons(53);
dest6.sin6_flowinfo = 0;
dest6.sin6_addr = dns_server_6;
dest6.sin6_scope_id = 0;
}
sockaddr_storage_setport( serverAddr, 53);
//Set the DNS structure to standard queries
unsigned char buf[65536];
struct DNS_HEADER* dns = (struct DNS_HEADER *)&buf;
dns->id = static_cast<unsigned short>(htons(getpid())); //Transaction Id
//dns flags = 0x0100 Standard Query
@ -191,86 +190,81 @@ bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& ho
curSendSize += sizeof(struct QUESTION);
#ifdef DEBUG_SPEC_DNS
RsDbg()<<__PRETTY_FUNCTION__<< " Sending Packet: " << std::endl << hexDump(buf, curSendSize) << std::endl;
RS_DBG("Sending Packet:\n", hexDump(buf, curSendSize));
#endif
int s = isIPV4 ? socket(AF_INET , SOCK_DGRAM , IPPROTO_UDP)
: socket(AF_INET6 , SOCK_DGRAM , IPPROTO_UDP) ; //UDP packet for DNS queries
int s = socket(serverAddr.ss_family , SOCK_DGRAM , IPPROTO_UDP); //UDP packet for DNS queries
if (timeout_s > -1)
{
#ifdef WINDOWS_SYS
DWORD timeout = timeout_s * 1000;
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof timeout);
#else
struct timeval tv;
tv.tv_sec = timeout_s;
tv.tv_usec = 0;
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
#endif
}
ssize_t send_size = sendto(s, (char*)buf, curSendSize, 0
,isIPV4 ? (struct sockaddr*)&dest4
: (struct sockaddr*)&dest6
,isIPV4 ? sizeof(dest4)
: sizeof(dest6)
rs_setSockTimeout(s, true, timeout_s);
ssize_t send_size = sendto( s, (char*)buf, curSendSize, 0
, (struct sockaddr*)&serverAddr
, isIPV4 ? sizeof(sockaddr_in)
: sizeof(sockaddr_in6)
);
if( send_size < 0)
{
RsErr()<<__PRETTY_FUNCTION__<<": Send Failed with size = " << send_size << std::endl;
RS_ERR("Send Failed with size = ", send_size);
return false;
}
#ifdef DEBUG_SPEC_DNS
RsDbg()<<__PRETTY_FUNCTION__<< " Waiting answer..." << std::endl;
RS_DBG("Waiting answer...");
#endif
//****************************************************************************************//
//--- Receive the answer ---//
//****************************************************************************************//
socklen_t dest_size = static_cast<socklen_t>(sizeof dest4);
ssize_t rec_size=recvfrom(s,(char*)buf , 65536 , 0 , (struct sockaddr*)&dest4 , &dest_size );
socklen_t sa_size = static_cast<socklen_t>(isIPV4 ? sizeof(sockaddr_in)
: sizeof(sockaddr_in6)
);
ssize_t rec_size=recvfrom( s,(char*)buf , 65536 , 0
, (struct sockaddr*)&serverAddr
, &sa_size
);
if(rec_size <= 0)
{
RsErr()<<__PRETTY_FUNCTION__<<": Receive Failed"<<std::endl;
RS_ERR("Receive Failed");
return false;
}
#ifdef DEBUG_SPEC_DNS
RsDbg()<<__PRETTY_FUNCTION__<< " Received: " << hexDump(buf, rec_size) << std::endl;
RS_DBG("Received:\n", hexDump(buf, rec_size));
#endif
if (rec_size< static_cast<ssize_t>(sizeof(struct DNS_HEADER)) )
{
RsErr()<<__PRETTY_FUNCTION__<<": Request received too small to get DNSHeader."<<std::endl;
RS_ERR("Request received too small to get DNSHeader.");
return false;
}
#ifdef DEBUG_SPEC_DNS
//Point to the header portion
dns = (struct DNS_HEADER*) buf;
RsDbg()<<__PRETTY_FUNCTION__<<" The response contains : " << std::endl
<<ntohs(dns->q_count) << " Questions." << std::endl
<<ntohs(dns->ans_count) << " Answers." << std::endl
<<ntohs(dns->auth_count) << " Authoritative Servers." << std::endl
<<ntohs(dns->add_count) << " Additional records." << std::endl;
RS_DBG("The response contains :\n"
,ntohs(dns->q_count) , " Questions.\n"
,ntohs(dns->ans_count) , " Answers.\n"
,ntohs(dns->auth_count) , " Authoritative Servers.\n"
,ntohs(dns->add_count) , " Additional records.");
#endif
size_t curRecSize = sizeof(struct DNS_HEADER);
if (rec_size< static_cast<ssize_t>(curRecSize + 1 + sizeof(struct QUESTION)) )
{
RsErr()<<__PRETTY_FUNCTION__<<": Request received too small to get Question return."<<std::endl;
RS_ERR("Request received too small to get Question return.");
return false;
}
//Point to the query portion
unsigned char* qnameRecv =static_cast<unsigned char*>(&buf[curRecSize]);
if (memcmp(qname,qnameRecv,qnameSize + 1 + sizeof(struct QUESTION)) )
{
RsErr()<<__PRETTY_FUNCTION__<<": Request received different from that sent."<<std::endl;
RS_ERR("Request received different from that sent.");
return false;
}
curRecSize += qnameSize + 1 + sizeof(struct QUESTION);
if (rec_size< static_cast<ssize_t>(curRecSize + 2) )
{
RsErr()<<__PRETTY_FUNCTION__<<": Request received too small to get Answer return."<<std::endl;
RS_ERR("Request received too small to get Answer return.");
return false;
}
//Point to the Answer portion
@ -290,33 +284,33 @@ bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& ho
}
else
{
RsErr()<<__PRETTY_FUNCTION__<<": Answer received with unmanaged label format."<<std::endl;
RS_ERR("Answer received with unmanaged label format.");
return false;
}
curRecSize += 2 + rLabelSize;
if (rec_size< static_cast<ssize_t>(curRecSize + sizeof(struct RR_DATA)) )
{
RsErr()<<__PRETTY_FUNCTION__<<": Request received too small to get Data return."<<std::endl;
RS_ERR("Request received too small to get Data return.");
return false;
}
//Point to the query portion
struct RR_DATA* rec_data = (struct RR_DATA *)&buf[curRecSize];
if (rec_data->rtype!=qinfo->qtype)
{
RsErr()<<__PRETTY_FUNCTION__<<": Answer's type received different from query sent."<<std::endl;
RS_ERR("Answer's type received different from query sent.");
return false;
}
if (rec_data->rclass!=qinfo->qclass)
{
RsErr()<<__PRETTY_FUNCTION__<<": Answer's class received different from query sent."<<std::endl;
RS_ERR("Answer's class received different from query sent.");
return false;
}
curRecSize += sizeof(struct RR_DATA);
if (rec_size< static_cast<ssize_t>(curRecSize + ntohs(rec_data->data_len)) )
{
RsErr()<<__PRETTY_FUNCTION__<<": Request received too small to get Full Data return."<<std::endl;
RS_ERR("Request received too small to get Full Data return.");
return false;
}
@ -328,7 +322,7 @@ bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& ho
in_addr ipv4Add;
ipv4Add.s_addr=*(in_addr_t*)&buf[curRecSize];
#ifdef DEBUG_SPEC_DNS
RsDbg()<<__PRETTY_FUNCTION__<< " Retrieve address: " << rs_inet_ntoa(ipv4Add) << std::endl;
RS_DBG("Retrieve address: ", rs_inet_ntoa(ipv4Add));
#endif
returned_addr = rs_inet_ntoa(ipv4Add);
return true;
@ -348,13 +342,13 @@ bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& ho
sockaddr_storage_setipv6(ss,&addr_ipv6);
#ifdef DEBUG_SPEC_DNS
RsDbg()<<__PRETTY_FUNCTION__<< " Retrieve address: " << sockaddr_storage_iptostring(ss).c_str() << std::endl;
RS_DBG("Retrieve address: ", sockaddr_storage_iptostring(ss).c_str());
#endif
returned_addr = sockaddr_storage_iptostring(ss);
return true;
}
}
RsErr()<<__PRETTY_FUNCTION__<< " Retrieve unmanaged data size=" << ntohs(rec_data->data_len) << std::endl;
RS_ERR("Retrieve unmanaged data size=", ntohs(rec_data->data_len));
return false;
}

View File

@ -174,3 +174,17 @@ std::string rs_inet_ntoa(struct in_addr in)
rs_sprintf(str, "%u.%u.%u.%u", (int) bytes[0], (int) bytes[1], (int) bytes[2], (int) bytes[3]);
return str;
}
int rs_setSockTimeout( int sockfd, bool forReceive /*= true*/
, int timeout_Sec /*= 0*/, int timeout_uSec /*= 0*/)
{
#ifdef WINDOWS_SYS
DWORD timeout = timeout_Sec * 1000 + timeout_uSec;
#else
struct timeval timeout;
timeout.tv_sec = timeout_Sec;
timeout.tv_usec = timeout_uSec;
#endif
return setsockopt( sockfd, SOL_SOCKET, forReceive ? SO_RCVTIMEO : SO_SNDTIMEO
, (const char*)&timeout, sizeof timeout);
}

View File

@ -84,9 +84,16 @@ bool isExternalNet(const struct in_addr *addr);
// uses a re-entrant version of gethostbyname
bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) ;
// Get hostName address using specific DNS server
// Using it allow to direct ask our Address to IP, so no need to have a DNS (IPv4 or IPv6 ???).
// If we ask to a IPv6 DNS Server, it respond for our IPv6 address.
/**
* @brief Get hostName address using specific DNS server.
* Using it allow to direct ask our Address to IP, so no need to have a DNS (IPv4 or IPv6).
* If we ask to a IPv6 DNS Server, it respond for our IPv6 address.
* @param servername: Address or name of DNS Server.
* @param hostname: HosteName to get IP ("myip.opendns.com" to get own).
* @param returned_addr: returned IP of hostname.
* @param timeout_s: Timeout in sec to wait server response.
* @return True in success.
*/
bool rsGetHostByNameSpecDNS(const std::string& servername, const std::string& hostname, std::string& returned_addr, int timeout_s = -1);
std::ostream& operator<<(std::ostream& o, const sockaddr_in&);
@ -164,4 +171,14 @@ bool sockaddr_storage_inet_ntop(const sockaddr_storage &addr, std::string &dst);
int rs_setsockopt( int sockfd, int level, int optname,
const uint8_t *optval, uint32_t optlen );
/**
* @brief Set socket Timeout.
* @param sockfd: The socket to manage.
* @param forReceive: True for Receive, False for Send.
* @param timeout_Sec: Timeout second part.
* @param timeout_uSec: Timeout micro second part.
* @return 0 on success, -1 for errors.
*/
int rs_setSockTimeout( int sockfd, bool forReceive = true, int timeout_Sec = 0, int timeout_uSec = 0);
#endif /* RS_UNIVERSAL_NETWORK_HEADER */

View File

@ -233,8 +233,7 @@ bool sockaddr_storage_setport(struct sockaddr_storage &addr, uint16_t port)
bool sockaddr_storage_setipv4(struct sockaddr_storage &addr, const sockaddr_in *addr_ipv4)
{
#ifdef SS_DEBUG
std::cerr << "sockaddr_storage_setipv4()";
std::cerr << std::endl;
RS_ERR();
#endif
sockaddr_storage_clear(addr);
@ -249,7 +248,9 @@ bool sockaddr_storage_setipv4(struct sockaddr_storage &addr, const sockaddr_in *
bool sockaddr_storage_setipv6(struct sockaddr_storage &addr, const sockaddr_in6 *addr_ipv6)
{
std::cerr << "sockaddr_storage_setipv6()" << std::endl;
#ifdef SS_DEBUG
RS_ERR();
#endif
sockaddr_storage_clear(addr);
struct sockaddr_in6 *ipv6_ptr = to_ipv6_ptr(addr);

View File

@ -459,6 +459,7 @@ void ServerPage::load()
whileBlocking(ui.ipAddressList)->clear();
detail.ipAddressList.sort();
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
whileBlocking(ui.ipAddressList)->addItem(QString::fromStdString(*it));
@ -827,7 +828,7 @@ void ServerPage::ipWhiteListContextMenu(const QPoint& /* point */)
// QString range0 = RsNetUtil::printAddrRange(addr,0) ;
// QString range1 = RsNetUtil::printAddrRange(addr,1) ;
// QString range2 = RsNetUtil::printAddrRange(addr,2) ;
//
// contextMenu.addAction(QObject::tr("Whitelist only IP " )+range0,this,SLOT(enableBannedIp()))->setEnabled(false) ;
//#warning UNIMPLEMENTED CODE
// contextMenu.addAction(QObject::tr("Whitelist entire range ")+range1,this,SLOT(enableBannedIp()))->setEnabled(false) ;
@ -1180,6 +1181,7 @@ void ServerPage::loadHiddenNode()
// show what we have in ipAddresses. (should be nothing!)
ui.ipAddressList->clear();
detail.ipAddressList.sort();
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
whileBlocking(ui.ipAddressList)->addItem(QString::fromStdString(*it));