mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Restored p3disc functionality.
* Bugfix in correctly adding ipList. * restored setLocal/Ext calls from peer. * Added extra debugging in p3disc. * Cleaned up debugging in p3connmgr. * switched off debugging in rsdiscitems. * reorder ipList (most recent first). * removed DEBUG switches in libretroshare.pro git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3252 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6f219d4fef
commit
8b2cb688a8
@ -9,17 +9,23 @@ profiling {
|
||||
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
|
||||
}
|
||||
|
||||
release {
|
||||
# UDP and TUNNEL dont work anymore.
|
||||
DEFINES *= PQI_DISABLE_UDP
|
||||
DEFINES *= PQI_DISABLE_TUNNEL
|
||||
}
|
||||
|
||||
testnetwork {
|
||||
DEFINES *= PQI_DISABLE_UDP
|
||||
DEFINES *= PQI_DISABLE_TUNNEL
|
||||
|
||||
DEFINES *= AUTHSSL_DEBUG GPG_DEBUG
|
||||
DEFINES *= CONN_DEBUG
|
||||
# DEFINES *= AUTHSSL_DEBUG GPG_DEBUG
|
||||
# DEFINES *= CONN_DEBUG
|
||||
# DEFINES *= P3DISC_DEBUG
|
||||
|
||||
DEFINES *= PGRP_DEBUG
|
||||
DEFINES *= PERSON_DEBUG
|
||||
DEFINES *= DEBUG_PQISSL
|
||||
# DEFINES *= PGRP_DEBUG
|
||||
# DEFINES *= PERSON_DEBUG
|
||||
# DEFINES *= DEBUG_PQISSL
|
||||
|
||||
#DEFINES *= DEBUG_UDP_SORTER DEBUG_UDP_LAYER EXTADDRSEARCH_DEBUG
|
||||
|
||||
|
@ -72,9 +72,6 @@ const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 4;
|
||||
* #define CONN_DEBUG_TICK 1
|
||||
***/
|
||||
|
||||
#define CONN_DEBUG 1
|
||||
#define CONN_DEBUG_RESET 1
|
||||
#define CONN_DEBUG_TICK 1
|
||||
|
||||
/****
|
||||
* #define P3CONNMGR_NO_TCP_CONNECTIONS 1
|
||||
@ -200,8 +197,8 @@ p3ConnectMgr::p3ConnectMgr()
|
||||
mOldNetFlags = pqiNetStatus();
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
std::cerr << "p3ConnectMgr() Calling NetReset" << std::endl;
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr() Startup" << std::endl;
|
||||
#endif
|
||||
|
||||
netReset();
|
||||
@ -234,7 +231,9 @@ void p3ConnectMgr::setIPServersEnabled(bool b)
|
||||
{
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr: setIPServers to " << b << std::endl ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void p3ConnectMgr::setTunnelConnection(bool b)
|
||||
@ -396,7 +395,7 @@ void p3ConnectMgr::netReset()
|
||||
#endif
|
||||
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
std::cerr << "p3ConnectMgr::netReset() shutdown" << std::endl;
|
||||
std::cerr << "p3ConnectMgr::netReset() Called" << std::endl;
|
||||
#endif
|
||||
|
||||
shutdown(); /* blocking shutdown call */
|
||||
@ -409,6 +408,12 @@ void p3ConnectMgr::netReset()
|
||||
#endif
|
||||
mExtAddrFinder->reset() ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
std::cerr << "p3ConnectMgr::netReset() ExtAddrFinder Disabled" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
std::cerr << "p3ConnectMgr::netReset() resetting NetStatus" << std::endl;
|
||||
@ -425,12 +430,16 @@ void p3ConnectMgr::netReset()
|
||||
* as it calls back to p3ConnMgr.
|
||||
*/
|
||||
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
std::cerr << "p3ConnectMgr::netReset() resetting listeners" << std::endl;
|
||||
#endif
|
||||
std::list<pqiNetListener *>::const_iterator it;
|
||||
for(it = mNetListeners.begin(); it != mNetListeners.end(); it++)
|
||||
{
|
||||
std::cerr << "p3ConnectMgr::netReset() reset listener" << std::endl;
|
||||
(*it)->reset_listener();
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
std::cerr << "p3ConnectMgr::netReset() reset listener" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,6 +457,7 @@ void p3ConnectMgr::netReset()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* to allow resets of network stuff */
|
||||
void p3ConnectMgr::addNetListener(pqiNetListener *listener)
|
||||
{
|
||||
@ -490,6 +500,7 @@ void p3ConnectMgr::netStartup()
|
||||
|
||||
mNetInitTS = time(NULL);
|
||||
netStatusReset_locked();
|
||||
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
std::cerr << "p3ConnectMgr::netStartup() resetting mNetInitTS / Status" << std::endl;
|
||||
#endif
|
||||
@ -547,6 +558,10 @@ void p3ConnectMgr::tick()
|
||||
|
||||
bool p3ConnectMgr::shutdown() /* blocking shutdown call */
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::shutdown()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
{
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
mNetStatus = RS_NET_UNKNOWN;
|
||||
@ -629,7 +644,7 @@ void p3ConnectMgr::netTick()
|
||||
{
|
||||
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
//std::cerr << "p3ConnectMgr::netTick()" << std::endl;
|
||||
std::cerr << "p3ConnectMgr::netTick()" << std::endl;
|
||||
#endif
|
||||
|
||||
// Check whether we are stuck on loopback. This happens if RS starts when
|
||||
@ -651,17 +666,14 @@ void p3ConnectMgr::netTick()
|
||||
{
|
||||
case RS_NET_NEEDS_RESET:
|
||||
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
std::cerr << "p3ConnectMgr::netTick() STATUS: NEEDS_RESET" << std::endl;
|
||||
#endif
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netTick() STATUS: NEEDS_RESET" << std::endl;
|
||||
#endif
|
||||
netReset();
|
||||
break;
|
||||
|
||||
case RS_NET_UNKNOWN:
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netTick() STATUS: UNKNOWN" << std::endl;
|
||||
#endif
|
||||
|
||||
@ -671,7 +683,7 @@ void p3ConnectMgr::netTick()
|
||||
#define STARTUP_DELAY 5
|
||||
if (age < STARTUP_DELAY)
|
||||
{
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netTick() Delaying Startup" << std::endl;
|
||||
#endif
|
||||
}
|
||||
@ -683,14 +695,14 @@ void p3ConnectMgr::netTick()
|
||||
break;
|
||||
|
||||
case RS_NET_UPNP_INIT:
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netTick() STATUS: UPNP_INIT" << std::endl;
|
||||
#endif
|
||||
netUpnpInit();
|
||||
break;
|
||||
|
||||
case RS_NET_UPNP_SETUP:
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netTick() STATUS: UPNP_SETUP" << std::endl;
|
||||
#endif
|
||||
netUpnpCheck();
|
||||
@ -698,7 +710,7 @@ void p3ConnectMgr::netTick()
|
||||
|
||||
|
||||
case RS_NET_EXT_SETUP:
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netTick() STATUS: EXT_SETUP" << std::endl;
|
||||
#endif
|
||||
netExtCheck();
|
||||
@ -715,7 +727,7 @@ void p3ConnectMgr::netTick()
|
||||
case RS_NET_LOOPBACK:
|
||||
//don't do a shutdown because a client in a computer without local network might be usefull for debug.
|
||||
//shutdown();
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
|
||||
#endif
|
||||
default:
|
||||
@ -728,7 +740,7 @@ void p3ConnectMgr::netTick()
|
||||
|
||||
void p3ConnectMgr::netUdpInit()
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUdpInit()" << std::endl;
|
||||
#endif
|
||||
connMtx.lock(); /* LOCK MUTEX */
|
||||
@ -744,7 +756,7 @@ void p3ConnectMgr::netUdpInit()
|
||||
|
||||
void p3ConnectMgr::netDhtInit()
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netDhtInit()" << std::endl;
|
||||
#endif
|
||||
connMtx.lock(); /* LOCK MUTEX */
|
||||
@ -759,7 +771,7 @@ void p3ConnectMgr::netDhtInit()
|
||||
|
||||
void p3ConnectMgr::netUpnpInit()
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUpnpInit()" << std::endl;
|
||||
#endif
|
||||
uint16_t eport, iport;
|
||||
@ -789,7 +801,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
|
||||
time_t delta = time(NULL) - mNetInitTS;
|
||||
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() age: " << delta << std::endl;
|
||||
#endif
|
||||
|
||||
@ -801,7 +813,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
if (((upnpState == 0) && (delta > (time_t)MAX_UPNP_INIT)) ||
|
||||
((upnpState > 0) && (delta > (time_t)MAX_UPNP_COMPLETE)))
|
||||
{
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() ";
|
||||
std::cerr << "Upnp Check failed." << std::endl;
|
||||
#endif
|
||||
@ -816,7 +828,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
}
|
||||
else if ((upnpState > 0) && netAssistExtAddress(extAddr))
|
||||
{
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() ";
|
||||
std::cerr << "Upnp Check success state: " << upnpState << std::endl;
|
||||
#endif
|
||||
@ -829,7 +841,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
*/
|
||||
if (isValidNet(&(extAddr.sin_addr)))
|
||||
{
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() ";
|
||||
std::cerr << "UpnpAddr: " << inet_ntoa(extAddr.sin_addr);
|
||||
std::cerr << ":" << ntohs(extAddr.sin_port);
|
||||
@ -848,7 +860,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() ";
|
||||
std::cerr << "Upnp Check Continues: status: " << upnpState << std::endl;
|
||||
#endif
|
||||
@ -859,7 +871,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
|
||||
void p3ConnectMgr::netExtCheck()
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck()" << std::endl;
|
||||
#endif
|
||||
{
|
||||
@ -872,14 +884,14 @@ void p3ConnectMgr::netExtCheck()
|
||||
/* (1) UPnP -> which handles itself */
|
||||
if (!mNetFlags.mExtAddrOk)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() Ext Not Ok" << std::endl;
|
||||
#endif
|
||||
|
||||
/* net Assist */
|
||||
if (netAssistExtAddress(tmpip))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() Ext supplied from netAssistExternalAddress()" << std::endl;
|
||||
#endif
|
||||
if (isValidNet(&(tmpip.sin_addr)))
|
||||
@ -892,7 +904,7 @@ void p3ConnectMgr::netExtCheck()
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() Bad Address supplied from netAssistExternalAddress()" << std::endl;
|
||||
#endif
|
||||
}
|
||||
@ -906,14 +918,18 @@ void p3ConnectMgr::netExtCheck()
|
||||
/* ExtAddrFinder */
|
||||
if (mUseExtAddrFinder)
|
||||
{
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() checking ExtAddrFinder" << std::endl;
|
||||
#endif
|
||||
bool extFinderOk = mExtAddrFinder->hasValidIP(&(tmpip.sin_addr));
|
||||
if (extFinderOk)
|
||||
{
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
|
||||
#endif
|
||||
/* best guess at port */
|
||||
tmpip.sin_port = mNetFlags.mLocalAddr.sin_port;
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() ";
|
||||
std::cerr << "ExtAddr: " << inet_ntoa(tmpip.sin_addr);
|
||||
std::cerr << ":" << ntohs(tmpip.sin_port);
|
||||
@ -923,6 +939,11 @@ void p3ConnectMgr::netExtCheck()
|
||||
mNetFlags.mExtAddr = tmpip;
|
||||
mNetFlags.mExtAddrOk = true;
|
||||
mNetFlags.mExtAddrStableOk = isStable;
|
||||
|
||||
/* XXX HACK TO FIX */
|
||||
#warning "ALLOWING ExtAddrFinder -> ExtAddrStableOk = true (which it is not normally)"
|
||||
mNetFlags.mExtAddrStableOk = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -933,7 +954,7 @@ void p3ConnectMgr::netExtCheck()
|
||||
if (mNetFlags.mExtAddrOk)
|
||||
{
|
||||
|
||||
#ifdef CONN_DEBUG_TICK
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() ";
|
||||
std::cerr << "ExtAddr: " << inet_ntoa(mNetFlags.mExtAddr.sin_addr);
|
||||
std::cerr << ":" << ntohs(mNetFlags.mExtAddr.sin_port);
|
||||
@ -949,11 +970,13 @@ void p3ConnectMgr::netExtCheck()
|
||||
mOwnState.ipAddrs.mExt.updateIpAddressList(addrInfo);
|
||||
|
||||
mNetStatus = RS_NET_DONE;
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() Ext Ok: RS_NET_DONE" << std::endl;
|
||||
#endif
|
||||
|
||||
if (!mNetFlags.mExtAddrStableOk)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netUdpCheck() UDP Unstable :( ";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3ConnectMgr::netUdpCheck() We are unreachable";
|
||||
@ -994,7 +1017,9 @@ void p3ConnectMgr::netExtCheck()
|
||||
|
||||
if (mNetFlags.mExtAddrOk)
|
||||
{
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() setting netAssistSetAddress()" << std::endl;
|
||||
#endif
|
||||
netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mOwnState.netMode);
|
||||
}
|
||||
#if 0
|
||||
@ -1009,7 +1034,9 @@ void p3ConnectMgr::netExtCheck()
|
||||
/* flag unreachables! */
|
||||
if ((mNetFlags.mExtAddrOk) && (!mNetFlags.mExtAddrStableOk))
|
||||
{
|
||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||
std::cerr << "p3ConnectMgr::netExtCheck() Ext Unstable - Unreachable Check" << std::endl;
|
||||
#endif
|
||||
netUnreachableCheck();
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ bool pqiIpAddrList::updateIpAddressList(const pqiIpAddress &addr)
|
||||
#endif
|
||||
add = true;
|
||||
}
|
||||
else if (mAddrs.begin()->mSeenTime < addr.mSeenTime)
|
||||
else if (mAddrs.back().mSeenTime < addr.mSeenTime)
|
||||
{
|
||||
#ifdef IPADDR_DEBUG
|
||||
std::cerr << "pqiIpAddrList::updateIpAddressList() oldAddr: Add";
|
||||
@ -121,11 +121,11 @@ bool pqiIpAddrList::updateIpAddressList(const pqiIpAddress &addr)
|
||||
}
|
||||
}
|
||||
|
||||
// ordered by increasing time. (oldest at front)
|
||||
// ordered by decreaseing time. (newest at front)
|
||||
bool added = false;
|
||||
for(it = mAddrs.begin(); it != mAddrs.end(); it++)
|
||||
{
|
||||
if (it->mSeenTime > addr.mSeenTime)
|
||||
if (it->mSeenTime < addr.mSeenTime)
|
||||
{
|
||||
#ifdef IPADDR_DEBUG
|
||||
std::cerr << "pqiIpAddrList::updateIpAddressList() added orig SeenTime: " << it->mSeenTime << " new SeenTime: " << addr.mSeenTime;
|
||||
@ -147,13 +147,13 @@ bool pqiIpAddrList::updateIpAddressList(const pqiIpAddress &addr)
|
||||
}
|
||||
|
||||
/* pop if necessary */
|
||||
if (mAddrs.size() > MAX_ADDRESS_LIST_SIZE)
|
||||
while (mAddrs.size() > MAX_ADDRESS_LIST_SIZE)
|
||||
{
|
||||
#ifdef IPADDR_DEBUG
|
||||
std::cerr << "pqiIpAddrList::updateIpAddressList() popping front";
|
||||
std::cerr << "pqiIpAddrList::updateIpAddressList() popping back";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
mAddrs.pop_front();
|
||||
mAddrs.pop_back();
|
||||
}
|
||||
|
||||
return newAddr;
|
||||
|
@ -36,7 +36,6 @@
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -70,6 +70,8 @@ const uint32_t P3DISC_FLAGS_ASK_VERSION = 0x0080;
|
||||
* #define P3DISC_DEBUG 1
|
||||
****/
|
||||
|
||||
//#define P3DISC_DEBUG 1
|
||||
|
||||
/*********** NOTE ***************
|
||||
*
|
||||
* Only need Mutexs for neighbours information
|
||||
@ -94,13 +96,19 @@ p3disc::p3disc(p3ConnectMgr *cm, pqipersongrp *pqih)
|
||||
|
||||
//add own version to versions map
|
||||
versions[AuthSSL::getAuthSSL()->OwnId()] = RsUtil::retroshareVersion();
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::p3disc() setup";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int p3disc::tick()
|
||||
{
|
||||
//send a heartbeat to all connected peers
|
||||
if (time(NULL) - lastSentHeartbeatTime > HEARTBEAT_REPEAT_TIME) {
|
||||
if (time(NULL) - lastSentHeartbeatTime > HEARTBEAT_REPEAT_TIME)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::tick() sending heartbeat to all peers" << std::endl;
|
||||
#endif
|
||||
@ -126,7 +134,8 @@ int p3disc::handleIncoming()
|
||||
|
||||
// if off discard item.
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC))
|
||||
{
|
||||
while(NULL != (item = recvItem()))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
@ -174,12 +183,22 @@ int p3disc::handleIncoming()
|
||||
recvHeartbeatMsg(dta);
|
||||
nhandled++ ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::handleIncoming() Unknown Received Message!" << std::endl;
|
||||
item -> print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
delete item;
|
||||
}
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::handleIncoming() finished." << std::endl;
|
||||
#endif
|
||||
|
||||
return nhandled;
|
||||
}
|
||||
|
||||
@ -194,17 +213,32 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
|
||||
|
||||
std::list<pqipeer>::const_iterator pit;
|
||||
/* if any have switched to 'connected' then we notify */
|
||||
for(pit = plist.begin(); pit != plist.end(); pit++) {
|
||||
if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_CONNECTED)) {
|
||||
for(pit = plist.begin(); pit != plist.end(); pit++)
|
||||
{
|
||||
if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_CONNECTED))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::statusChange() Starting Disc with: " << pit->id << std::endl;
|
||||
#endif
|
||||
sendOwnVersion(pit->id);
|
||||
sendAllInfoToJustConnectedPeer(pit->id);
|
||||
sendJustConnectedPeerInfoToAllPeer(pit->id);
|
||||
}
|
||||
else if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::statusChange() Removing Friend: " << pit->id << std::endl;
|
||||
#endif
|
||||
removeFriend(pit->id);
|
||||
}
|
||||
else if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_NEW))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::statusChange() Adding Friend: " << pit->id << std::endl;
|
||||
#endif
|
||||
askInfoToAllPeers(pit->id);
|
||||
}
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::statusChange() finished." << std::endl;
|
||||
#endif
|
||||
@ -218,6 +252,7 @@ void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() id: " << id << std::endl;
|
||||
#endif
|
||||
|
||||
RsPeerDetails pd;
|
||||
rsPeers->getPeerDetails(id, pd);
|
||||
if (!pd.accept_connection || (!pd.ownsign && pd.gpg_id != rsPeers->getGPGOwnId())) { //only send info when connection is accepted and gpg key is signed or our own key
|
||||
@ -282,7 +317,8 @@ void p3disc::sendJustConnectedPeerInfoToAllPeer(std::string connectedPeerId)
|
||||
}
|
||||
|
||||
/* (dest (to), source (cert)) */
|
||||
void p3disc::sendPeerDetails(std::string to, std::string about) {
|
||||
void p3disc::sendPeerDetails(std::string to, std::string about)
|
||||
{
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() called. Sending details of: " << about << " to: " << to << std::endl;
|
||||
@ -304,7 +340,7 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
|
||||
return;
|
||||
}
|
||||
|
||||
about = rsPeers->getGPGId(about);
|
||||
std::string aboutGpgId = rsPeers->getGPGId(about);
|
||||
if (about == "") {
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() no info about this id" << std::endl;
|
||||
@ -313,7 +349,8 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
|
||||
}
|
||||
|
||||
peerConnectState detailAbout;
|
||||
if (mConnMgr->getFriendNetStatus(about, detailAbout) && detailAbout.visState & RS_VIS_STATE_NODISC) {
|
||||
if (mConnMgr->getFriendNetStatus(aboutGpgId, detailAbout) && detailAbout.visState & RS_VIS_STATE_NODISC)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() don't send info about this peer because he has no disc enabled." << std::endl;
|
||||
#endif
|
||||
@ -326,20 +363,37 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
|
||||
// Fill the message
|
||||
// Set Target as input cert.
|
||||
di -> PeerId(to);
|
||||
di -> aboutId = about;
|
||||
di -> aboutId = aboutGpgId;
|
||||
|
||||
// set the ip addresse list.
|
||||
std::list<std::string> sslChilds;
|
||||
rsPeers->getSSLChildListOfGPGId(about, sslChilds);
|
||||
rsPeers->getSSLChildListOfGPGId(aboutGpgId, sslChilds);
|
||||
bool shouldWeSendGPGKey = false;//the GPG key is send only if we've got a valid friend with DISC enabled
|
||||
|
||||
for (std::list<std::string>::iterator sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++)
|
||||
std::list<std::string>::iterator sslChildIt;
|
||||
for (sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() Found Child SSL Id:" << *sslChildIt;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if(to != *sslChildIt) // We don't send info to a peer about itself, but we allow sending info
|
||||
{ // about peers with the same GPG id.
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail) || detail.visState & RS_VIS_STATE_NODISC) {
|
||||
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail)
|
||||
|| detail.visState & RS_VIS_STATE_NODISC)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() Skipping cos No Details or NODISC flag";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() Adding Child SSL Id Details";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
shouldWeSendGPGKey = true;
|
||||
RsPeerNetItem *rsPeerNetItem = new RsPeerNetItem();
|
||||
rsPeerNetItem->clear();
|
||||
@ -359,6 +413,14 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
|
||||
|
||||
di->rsPeerList.push_back(*rsPeerNetItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() Skipping cos \"to == sslChildId\"";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//send own details
|
||||
@ -391,19 +453,25 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() GPG key should not be send, no friend with disc on found about it." << std::endl;
|
||||
#endif
|
||||
// cleanup!
|
||||
delete di;
|
||||
return;
|
||||
}
|
||||
std::string cert = AuthGPG::getAuthGPG()->SaveCertificateToString(about);
|
||||
if (cert == "") {
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() don't send details because the gpg cert is not good" << std::endl;
|
||||
|
||||
#endif
|
||||
// cleanup!
|
||||
delete di;
|
||||
return;
|
||||
}
|
||||
di -> certGPG = cert;
|
||||
|
||||
// Send off message
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::sendPeerDetails() About to Send Message:" << std::endl;
|
||||
di->print(std::cerr, 5);
|
||||
#endif
|
||||
sendItem(di);
|
||||
@ -470,8 +538,8 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||
return;
|
||||
}
|
||||
|
||||
about = rsPeers->getGPGId(about);
|
||||
if (about == "") {
|
||||
std::string aboutGpgId = rsPeers->getGPGId(about);
|
||||
if (aboutGpgId == "") {
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
||||
#endif
|
||||
@ -479,6 +547,9 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||
|
||||
// if off discard item.
|
||||
if (!mConnMgr->getOwnNetStatus(connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@ -488,10 +559,12 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||
rsPeers->getOnlineList(onlineIds);
|
||||
|
||||
/* ask info to trusted friends */
|
||||
for(onlineIdsIt = onlineIds.begin(); onlineIdsIt != onlineIds.end(); onlineIdsIt++) {
|
||||
for(onlineIdsIt = onlineIds.begin(); onlineIdsIt != onlineIds.end(); onlineIdsIt++)
|
||||
{
|
||||
RsPeerDetails details;
|
||||
rsPeers->getPeerDetails(*onlineIdsIt, details);
|
||||
if (!details.accept_connection || !details.ownsign) {
|
||||
if (!details.accept_connection || !details.ownsign)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() don't ask info message to untrusted peer." << std::endl;
|
||||
#endif
|
||||
@ -538,12 +611,6 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
||||
|
||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++)
|
||||
{
|
||||
// there's no way we can receive from a peer some info about our own dummy friend
|
||||
//don't update dummy friends
|
||||
//if (rsPeers->isDummyFriend(pitem->pid)) {
|
||||
// continue;
|
||||
//}
|
||||
|
||||
addDiscoveryData(item->PeerId(), pitem->pid, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL));
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
@ -560,8 +627,6 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
||||
//
|
||||
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
|
||||
//
|
||||
#ifdef P3DISC_DEBUG
|
||||
@ -570,20 +635,19 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
||||
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, 0, 0);
|
||||
RsPeerDetails storedDetails;
|
||||
|
||||
// Update if know this peer, and if it's not already connected.
|
||||
//
|
||||
// Update if know this peer
|
||||
if(rsPeers->getPeerDetails(pitem->pid, storedDetails))
|
||||
{
|
||||
// Update if it's fresh info or if it's from the peer itself
|
||||
// their info is fresher than ours, update ours
|
||||
//
|
||||
if(!(storedDetails.state & RS_PEER_CONNECTED))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "Friend is not connected -> updating info" << std::endl;
|
||||
std::cerr << " -> network mode: " << pitem->netMode << std::endl;
|
||||
std::cerr << " -> location: " << pitem->location << std::endl;
|
||||
#endif
|
||||
// Update if it's fresh info or if it's from the peer itself
|
||||
// their info is fresher than ours, update ours
|
||||
//
|
||||
if(!(storedDetails.state & RS_PEER_CONNECTED))
|
||||
{
|
||||
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
||||
mConnMgr->setLocation(pitem->pid, pitem->location);
|
||||
}
|
||||
@ -603,26 +667,26 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
||||
std::cerr << " -> current remote addr = " << pitem->currentremoteaddr << std::endl;
|
||||
std::cerr << " -> clearing NODISC flag " << std::endl;
|
||||
#endif
|
||||
//mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
//mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||
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 ;
|
||||
|
||||
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3disc:: ERROR HOW DID WE GET HERE?" << std::endl;
|
||||
}
|
||||
|
||||
pqiIpAddrSet addrsFromPeer;
|
||||
addrsFromPeer.mLocal.loadTlv(pitem->localAddrList);
|
||||
addrsFromPeer.mExt.loadTlv(pitem->extAddrList);
|
||||
|
||||
addrsFromPeer.mLocal.extractFromTlv(pitem->localAddrList);
|
||||
addrsFromPeer.mExt.extractFromTlv(pitem->extAddrList);
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "Friend is already connected -> not updating" << std::endl;
|
||||
|
||||
std::cerr << "Setting address list to peer " << pitem->pid << ", to be:" << std::endl ;
|
||||
|
||||
addrsFromPeer.printAddrs(std::cerr);
|
||||
@ -636,12 +700,16 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " skipping unknown gpg id " << pitem->gpg_id << std::endl ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef P3DISC_DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << "Skipping info about own id " << pitem->pid << std::endl ;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,20 @@ bool test_addr_list()
|
||||
addr.mSeenTime = time(NULL) - i;
|
||||
|
||||
list.updateIpAddressList(addr);
|
||||
|
||||
if (i < 100 + 4)
|
||||
{
|
||||
/* check that was added to the back */
|
||||
CHECK(list.mAddrs.back().mSeenTime == addr.mSeenTime);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_port == addr.mAddr.sin_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* check that wasn't added to the back */
|
||||
CHECK(list.mAddrs.back().mSeenTime != addr.mSeenTime);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_addr.s_addr != addr.mAddr.sin_addr.s_addr);
|
||||
}
|
||||
}
|
||||
|
||||
/* print out the list */
|
||||
@ -97,19 +111,19 @@ bool test_addr_list()
|
||||
}
|
||||
|
||||
/* make sure it more recent than the previous ones */
|
||||
for(int i = 100; i > 89; i--)
|
||||
for(int i = 99; i > 89; i--)
|
||||
{
|
||||
addr.mSeenTime = time(NULL) - i;
|
||||
list.updateIpAddressList(addr);
|
||||
|
||||
/* check that was added to the back */
|
||||
CHECK(list.mAddrs.back().mSeenTime == addr.mSeenTime);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_port == addr.mAddr.sin_port);
|
||||
/* check that was added to the front */
|
||||
CHECK(list.mAddrs.front().mSeenTime == addr.mSeenTime);
|
||||
CHECK(list.mAddrs.front().mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr);
|
||||
CHECK(list.mAddrs.front().mAddr.sin_port == addr.mAddr.sin_port);
|
||||
}
|
||||
|
||||
/* print out the list */
|
||||
std::cerr << "IpAddressList (last item to be 192.168.2.200:8812)";
|
||||
std::cerr << "IpAddressList (first item to be 192.168.2.200:8812)";
|
||||
std::cerr << std::endl;
|
||||
list.printIpAddressList(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
@ -124,9 +138,9 @@ bool test_addr_list()
|
||||
list.updateIpAddressList(addr);
|
||||
|
||||
/* check that was added to the back */
|
||||
CHECK(list.mAddrs.back().mSeenTime == addr.mSeenTime);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_port == addr.mAddr.sin_port);
|
||||
CHECK(list.mAddrs.front().mSeenTime == addr.mSeenTime);
|
||||
CHECK(list.mAddrs.front().mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr);
|
||||
CHECK(list.mAddrs.front().mAddr.sin_port == addr.mAddr.sin_port);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user