mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Use retrocompatible iterators
Explain why shuffling the local addresses list before looking for a viable local is a bad idea.
This commit is contained in:
parent
0c99975800
commit
2044a2c848
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
@ -1018,13 +1019,25 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||
/* 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;
|
||||
* code. */
|
||||
|
||||
std::vector<sockaddr_storage> addrs;
|
||||
if (getLocalAddresses(addrs))
|
||||
{
|
||||
for (auto&& addr : addrs)
|
||||
|
||||
/* To work around one address limitation, to shuffle the list of
|
||||
* local addresses in the hope that with enough time every local
|
||||
* address is advertised to trusted nodes so they may try to
|
||||
* connect to all of them including the most convenient if a local
|
||||
* connection exists, is a bad idea. It would cause net reset every
|
||||
* time a different local address is selected, potentially breaking
|
||||
* broader RS assumptions.
|
||||
*/
|
||||
//std::random_shuffle(addrs.begin(), addrs.end());
|
||||
|
||||
for (auto it = addrs.begin(); it!=addrs.end(); ++it)
|
||||
{
|
||||
sockaddr_storage& addr(*it);
|
||||
if( sockaddr_storage_isValidNet(addr) &&
|
||||
!sockaddr_storage_isLoopbackNet(addr) &&
|
||||
!sockaddr_storage_isLinkLocalNet(addr))
|
||||
@ -1035,10 +1048,11 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||
}
|
||||
}
|
||||
|
||||
// If no satisfactory local address has been found yet relax and
|
||||
// accept also link local addresses
|
||||
if(!validAddr) for (auto&& addr : addrs)
|
||||
/* If no satisfactory local address has been found yet relax and
|
||||
* accept also link local addresses */
|
||||
if(!validAddr) for (auto it = addrs.begin(); it!=addrs.end(); ++it)
|
||||
{
|
||||
sockaddr_storage& addr(*it);
|
||||
if( sockaddr_storage_isValidNet(addr) &&
|
||||
!sockaddr_storage_isLoopbackNet(addr) )
|
||||
{
|
||||
|
@ -3,7 +3,8 @@
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 by Robert Fernie.
|
||||
* Copyright (C) 2004-2006 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
|
||||
@ -284,7 +285,7 @@ int inet_aton(const char *name, struct in_addr *addr)
|
||||
# include <net/if.h>
|
||||
#endif // WINDOWS_SYS
|
||||
|
||||
bool getLocalAddresses(std::list<sockaddr_storage> & addrs)
|
||||
bool getLocalAddresses(std::vector<sockaddr_storage>& addrs)
|
||||
{
|
||||
addrs.clear();
|
||||
|
||||
|
@ -3,7 +3,8 @@
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 by Robert Fernie.
|
||||
* Copyright (C) 2004-2006 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
|
||||
@ -24,10 +25,10 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_PQI_NETWORKING_HEADER
|
||||
#define MRK_PQI_NETWORKING_HEADER
|
||||
|
||||
#include <vector>
|
||||
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
@ -95,7 +96,7 @@ void showSocketError(std::string &out);
|
||||
|
||||
std::string socket_errorType(int err);
|
||||
|
||||
bool getLocalAddresses(std::list<struct sockaddr_storage> & addrs);
|
||||
bool getLocalAddresses(std::vector<sockaddr_storage> & addrs);
|
||||
|
||||
/* universal socket interface */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user