mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
Improve discovery
Workaround RS single local address flawed assumption by spreading all viables local addrresses via discovery Spread addresses also through hidden node as they are the only hope to help direct connection happening for common trusted nodes behind nasty firewalls
This commit is contained in:
parent
fa84d1c881
commit
2170313e42
@ -26,15 +26,11 @@
|
|||||||
|
|
||||||
#include "services/p3discovery2.h"
|
#include "services/p3discovery2.h"
|
||||||
#include "pqi/p3peermgr.h"
|
#include "pqi/p3peermgr.h"
|
||||||
#include "pqi/pqinetwork.h" // for getLocalAddresses
|
|
||||||
#include "util/rsversioninfo.h"
|
#include "util/rsversioninfo.h"
|
||||||
|
|
||||||
#include "retroshare/rsiface.h"
|
#include "retroshare/rsiface.h"
|
||||||
#include "rsserver/p3face.h"
|
#include "rsserver/p3face.h"
|
||||||
|
|
||||||
#include <vector> // for std::vector
|
|
||||||
#include <algorithm> // for std::random_shuffle
|
|
||||||
|
|
||||||
|
|
||||||
// Interface pointer.
|
// Interface pointer.
|
||||||
RsDisc *rsDisc = NULL;
|
RsDisc *rsDisc = NULL;
|
||||||
@ -43,9 +39,7 @@ RsDisc *rsDisc = NULL;
|
|||||||
* #define P3DISC_DEBUG 1
|
* #define P3DISC_DEBUG 1
|
||||||
****/
|
****/
|
||||||
|
|
||||||
static bool populateContactInfo( const peerState &detail,
|
static bool populateContactInfo(const peerState &detail, RsDiscContactItem *pkt,bool include_ip_information)
|
||||||
RsDiscContactItem *pkt,
|
|
||||||
bool include_ip_information )
|
|
||||||
{
|
{
|
||||||
pkt->clear();
|
pkt->clear();
|
||||||
|
|
||||||
@ -350,41 +344,6 @@ void p3discovery2::sendOwnContactInfo(const SSLID &sslid)
|
|||||||
peerState detail;
|
peerState detail;
|
||||||
if (mPeerMgr->getOwnNetStatus(detail))
|
if (mPeerMgr->getOwnNetStatus(detail))
|
||||||
{
|
{
|
||||||
/* Workaround to spread multiple local ip addresses when presents. This
|
|
||||||
* is needed because RS wrongly assumes that there is just one active
|
|
||||||
* local ip address at time. */
|
|
||||||
std::vector<sockaddr_storage> addrs;
|
|
||||||
if(!detail.hiddenNode && getLocalAddresses(addrs))
|
|
||||||
{
|
|
||||||
/* To work around MAX_ADDRESS_LIST_SIZE addresses limitation,
|
|
||||||
* let's 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.*/
|
|
||||||
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_sameip(addr, detail.localaddr) )
|
|
||||||
{
|
|
||||||
pqiIpAddress pqiIp;
|
|
||||||
sockaddr_storage_clear(pqiIp.mAddr);
|
|
||||||
pqiIp.mAddr.ss_family = addr.ss_family;
|
|
||||||
sockaddr_storage_copyip(pqiIp.mAddr, addr);
|
|
||||||
sockaddr_storage_setport(
|
|
||||||
pqiIp.mAddr,
|
|
||||||
sockaddr_storage_port(detail.localaddr) );
|
|
||||||
pqiIp.mSeenTime = time(nullptr);
|
|
||||||
pqiIp.mSrc = 0;
|
|
||||||
detail.ipAddrs.updateLocalAddrs(pqiIp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RsDiscContactItem *pkt = new RsDiscContactItem();
|
RsDiscContactItem *pkt = new RsDiscContactItem();
|
||||||
/* Cyril: we dont send our own IP to an hidden node. It will not use it
|
/* Cyril: we dont send our own IP to an hidden node. It will not use it
|
||||||
* anyway. */
|
* anyway. */
|
||||||
@ -502,7 +461,6 @@ void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
else if(!mPeerMgr->isHiddenNode(rsPeers->getOwnId()))
|
else if(!mPeerMgr->isHiddenNode(rsPeers->getOwnId()))
|
||||||
{
|
|
||||||
/* Cyril: we don't store IP addresses if we're a hidden node.
|
/* Cyril: we don't store IP addresses if we're a hidden node.
|
||||||
* Normally they should not be sent to us, except for old peers. */
|
* Normally they should not be sent to us, except for old peers. */
|
||||||
/* G10h4ck: sending IP information also to hidden nodes has proven very
|
/* G10h4ck: sending IP information also to hidden nodes has proven very
|
||||||
@ -513,7 +471,7 @@ void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item)
|
|||||||
* permission matrix. Disabling this instead will make life more
|
* permission matrix. Disabling this instead will make life more
|
||||||
* difficult for average user, that moreover whould have no way to
|
* difficult for average user, that moreover whould have no way to
|
||||||
* revert an hardcoded policy. */
|
* revert an hardcoded policy. */
|
||||||
|
{
|
||||||
pqiIpAddrSet addrsFromPeer;
|
pqiIpAddrSet addrsFromPeer;
|
||||||
addrsFromPeer.mLocal.extractFromTlv(item->localAddrList);
|
addrsFromPeer.mLocal.extractFromTlv(item->localAddrList);
|
||||||
addrsFromPeer.mExt.extractFromTlv(item->extAddrList);
|
addrsFromPeer.mExt.extractFromTlv(item->extAddrList);
|
||||||
|
Loading…
Reference in New Issue
Block a user