2007-12-11 20:43:17 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services: p3disc.cc
|
|
|
|
*
|
|
|
|
* Services for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsiface.h"
|
|
|
|
#include "retroshare/rspeers.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
#include "services/p3disc.h"
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
#include "pqi/p3peermgr.h"
|
|
|
|
#include "pqi/p3linkmgr.h"
|
2011-11-22 08:24:42 -05:00
|
|
|
#include "pqi/p3netmgr.h"
|
2011-07-09 14:39:34 -04:00
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
#include "pqi/authssl.h"
|
2010-01-13 16:05:38 -05:00
|
|
|
#include "pqi/authgpg.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
const uint32_t AUTODISC_LDI_SUBTYPE_PING = 0x01;
|
|
|
|
const uint32_t AUTODISC_LDI_SUBTYPE_RPLY = 0x02;
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdebug.h"
|
2008-02-26 11:52:50 -05:00
|
|
|
#include "util/rsprint.h"
|
2009-06-28 16:57:02 -04:00
|
|
|
#include "util/rsversion.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
const int pqidisczone = 2482;
|
|
|
|
|
2010-02-23 16:55:29 -05:00
|
|
|
//static int convertTDeltaToTRange(double tdelta);
|
|
|
|
//static int convertTRangeToTDelta(int trange);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
// Operating System specific includes.
|
|
|
|
#include "pqi/pqinetwork.h"
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* DISC FLAGS */
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
const uint32_t P3DISC_FLAGS_USE_DISC = 0x0001;
|
|
|
|
const uint32_t P3DISC_FLAGS_USE_DHT = 0x0002;
|
2008-12-23 11:23:54 -05:00
|
|
|
const uint32_t P3DISC_FLAGS_EXTERNAL_ADDR = 0x0004;
|
2008-02-28 10:58:54 -05:00
|
|
|
const uint32_t P3DISC_FLAGS_STABLE_UDP = 0x0008;
|
|
|
|
const uint32_t P3DISC_FLAGS_PEER_ONLINE = 0x0010;
|
|
|
|
const uint32_t P3DISC_FLAGS_OWN_DETAILS = 0x0020;
|
2011-08-07 17:11:00 -04:00
|
|
|
const uint32_t P3DISC_FLAGS_PEER_TRUSTS_ME = 0x0040;
|
2009-06-28 16:57:02 -04:00
|
|
|
const uint32_t P3DISC_FLAGS_ASK_VERSION = 0x0080;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
|
2008-03-02 09:25:59 -05:00
|
|
|
/*****
|
|
|
|
* #define P3DISC_DEBUG 1
|
|
|
|
****/
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
//#define P3DISC_DEBUG 1
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/******************************************************************************************
|
|
|
|
****************************** NEW DISCOVERY *******************************************
|
|
|
|
******************************************************************************************
|
|
|
|
*****************************************************************************************/
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-11-22 08:24:42 -05:00
|
|
|
p3disc::p3disc(p3PeerMgr *pm, p3LinkMgr *lm, p3NetMgr *nm, pqipersongrp *pqih)
|
2010-02-23 16:55:29 -05:00
|
|
|
:p3Service(RS_SERVICE_TYPE_DISC),
|
|
|
|
p3Config(CONFIG_TYPE_P3DISC),
|
2011-11-22 08:24:42 -05:00
|
|
|
mPeerMgr(pm), mLinkMgr(lm), mNetMgr(nm),
|
2011-07-04 18:59:39 -04:00
|
|
|
mPqiPersonGrp(pqih), mDiscMtx("p3disc")
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
addSerialType(new RsDiscSerialiser());
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
mLastSentHeartbeatTime = time(NULL);
|
|
|
|
mDiscEnabled = true;
|
2009-07-31 14:31:26 -04:00
|
|
|
|
|
|
|
//add own version to versions map
|
2011-08-07 17:11:00 -04:00
|
|
|
versions[AuthSSL::getAuthSSL()->OwnId()] = RsUtil::retroshareVersion();
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::p3disc() setup";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int p3disc::tick()
|
|
|
|
{
|
2009-12-22 05:41:19 -05:00
|
|
|
//send a heartbeat to all connected peers
|
2011-08-07 17:11:00 -04:00
|
|
|
time_t hbTime;
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
hbTime = mLastSentHeartbeatTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time(NULL) - hbTime > HEARTBEAT_REPEAT_TIME)
|
2010-07-04 11:16:52 -04:00
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3disc::tick() sending heartbeat to all peers" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::list<std::string> peers;
|
|
|
|
std::list<std::string>::const_iterator pit;
|
|
|
|
|
|
|
|
mLinkMgr->getOnlineList(peers);
|
|
|
|
for (pit = peers.begin(); pit != peers.end(); ++pit)
|
|
|
|
{
|
|
|
|
sendHeartbeat(*pit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check our Discovery flag */
|
|
|
|
peerState detail;
|
|
|
|
mPeerMgr->getOwnNetStatus(detail);
|
|
|
|
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
mDiscEnabled = (!(detail.visState & RS_VIS_STATE_NODISC));
|
|
|
|
mLastSentHeartbeatTime = time(NULL);
|
|
|
|
}
|
2010-09-24 13:06:09 -04:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
return handleIncoming();
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
int p3disc::handleIncoming()
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
RsItem *item = NULL;
|
2008-02-03 01:29:02 -05:00
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::handleIncoming()" << std::endl;
|
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
int nhandled = 0;
|
|
|
|
// While messages read
|
|
|
|
while(NULL != (item = recvItem()))
|
|
|
|
{
|
2010-06-10 09:42:49 -04:00
|
|
|
RsDiscAskInfo *inf = NULL;
|
2007-12-11 20:43:17 -05:00
|
|
|
RsDiscReply *dri = NULL;
|
2009-06-28 16:57:02 -04:00
|
|
|
RsDiscVersion *dvi = NULL;
|
2010-06-10 09:42:49 -04:00
|
|
|
RsDiscHeartbeat *dta = NULL;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::handleIncoming() Received Message!" << std::endl;
|
|
|
|
item -> print(std::cerr);
|
|
|
|
std::cerr << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
// if discovery reply then respond if haven't already.
|
2011-08-07 17:11:00 -04:00
|
|
|
if (NULL != (dri = dynamic_cast<RsDiscReply *> (item)))
|
|
|
|
{
|
|
|
|
recvDiscReply(dri);
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
else if (NULL != (dvi = dynamic_cast<RsDiscVersion *> (item)))
|
|
|
|
{
|
2009-06-28 16:57:02 -04:00
|
|
|
recvPeerVersionMsg(dvi);
|
|
|
|
nhandled++;
|
2010-09-22 19:45:54 -04:00
|
|
|
delete item;
|
2009-06-28 16:57:02 -04:00
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *> (item))) /* Ping */
|
|
|
|
{
|
2010-06-10 09:42:49 -04:00
|
|
|
recvAskInfo(inf);
|
2009-06-23 17:36:02 -04:00
|
|
|
nhandled++;
|
2010-09-22 19:45:54 -04:00
|
|
|
delete item;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
else if (NULL != (dta = dynamic_cast<RsDiscHeartbeat *> (item)))
|
|
|
|
{
|
2010-06-10 09:42:49 -04:00
|
|
|
recvHeartbeatMsg(dta);
|
|
|
|
nhandled++ ;
|
2010-09-22 19:45:54 -04:00
|
|
|
delete item;
|
2010-06-10 09:42:49 -04:00
|
|
|
}
|
2010-07-04 11:16:52 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::handleIncoming() Unknown Received Message!" << std::endl;
|
|
|
|
item -> print(std::cerr);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2010-09-22 19:45:54 -04:00
|
|
|
delete item;
|
2010-07-04 11:16:52 -04:00
|
|
|
}
|
2010-09-22 19:45:54 -04:00
|
|
|
}
|
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::handleIncoming() finished." << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
|
|
|
|
2010-06-10 09:42:49 -04:00
|
|
|
return nhandled;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/************* from pqiMonitor *******************/
|
|
|
|
void p3disc::statusChange(const std::list<pqipeer> &plist)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2011-01-21 17:04:14 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::statusChange()" << std::endl;
|
2011-01-21 17:04:14 -05:00
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
std::list<pqipeer>::const_iterator pit;
|
|
|
|
/* if any have switched to 'connected' then we notify */
|
2011-01-21 17:04:14 -05:00
|
|
|
for(pit = plist.begin(); pit != plist.end(); pit++)
|
2010-07-04 11:16:52 -04:00
|
|
|
{
|
2011-01-21 17:04:14 -05:00
|
|
|
if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_CONNECTED))
|
2010-07-04 11:16:52 -04:00
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::statusChange() Starting Disc with: " << pit->id << std::endl;
|
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
sendOwnVersion(pit->id);
|
|
|
|
sendAllInfoToJustConnectedPeer(pit->id);
|
|
|
|
sendJustConnectedPeerInfoToAllPeer(pit->id);
|
|
|
|
}
|
|
|
|
else if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED))
|
2010-07-04 11:16:52 -04:00
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::statusChange() Removing Friend: " << pit->id << std::endl;
|
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
removeFriend(pit->id);
|
2010-07-04 11:16:52 -04:00
|
|
|
}
|
2010-06-10 09:42:49 -04:00
|
|
|
else if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_NEW))
|
2010-07-04 11:16:52 -04:00
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::statusChange() Adding Friend: " << pit->id << std::endl;
|
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
askInfoToAllPeers(pit->id);
|
2010-07-04 11:16:52 -04:00
|
|
|
}
|
|
|
|
}
|
2010-06-10 09:42:49 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::statusChange() finished." << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
return;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
void p3disc::sendAllInfoToJustConnectedPeer(const std::string &id)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2008-02-03 01:29:02 -05:00
|
|
|
/* get a peer lists */
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() id: " << id << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
|
|
|
|
2010-06-10 09:42:49 -04:00
|
|
|
std::list<std::string> friendIds;
|
2011-08-07 17:11:00 -04:00
|
|
|
std::list<std::string>::iterator it;
|
2010-09-24 13:06:09 -04:00
|
|
|
std::set<std::string> gpgIds;
|
2011-08-07 17:11:00 -04:00
|
|
|
std::set<std::string>::iterator git;
|
2008-02-03 01:29:02 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* We send our full friends list - if we have Discovery Enabled */
|
|
|
|
if (mDiscEnabled)
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() Discovery Enabled, sending Friend List" << std::endl;
|
|
|
|
#endif
|
|
|
|
mLinkMgr->getFriendList(friendIds);
|
2008-02-03 01:29:02 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* send them a list of all friend's details */
|
|
|
|
for(it = friendIds.begin(); it != friendIds.end(); it++)
|
|
|
|
{
|
|
|
|
/* get details */
|
|
|
|
peerState detail;
|
|
|
|
if (!mPeerMgr->getFriendNetStatus(*it, detail))
|
|
|
|
{
|
|
|
|
/* major error! */
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() No Info, Skipping: " << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(detail.visState & RS_VIS_STATE_NODISC))
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() Adding GPGID: " << detail.gpg_id;
|
|
|
|
std::cerr << " (SSLID: " << *it << ")";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
gpgIds.insert(detail.gpg_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() DISC OFF for GPGID: " << detail.gpg_id;
|
|
|
|
std::cerr << " (SSLID: " << *it << ")";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
2010-06-10 09:42:49 -04:00
|
|
|
}
|
2009-12-18 18:35:40 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
//add own info, this info is sent whether discovery is enabled - or not.
|
2010-06-10 09:42:49 -04:00
|
|
|
gpgIds.insert(rsPeers->getGPGOwnId());
|
2009-12-18 12:50:53 -05:00
|
|
|
|
2010-09-24 13:06:09 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* refresh with new list */
|
|
|
|
std::list<std::string> &idList = mSendIdList[id];
|
|
|
|
idList.clear();
|
|
|
|
for(git = gpgIds.begin(); git != gpgIds.end(); git++)
|
|
|
|
{
|
|
|
|
idList.push_back(*git);
|
2010-09-24 13:06:09 -04:00
|
|
|
}
|
|
|
|
}
|
2010-02-15 10:31:06 -05:00
|
|
|
|
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() finished." << std::endl;
|
2010-02-15 10:31:06 -05:00
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
void p3disc::sendJustConnectedPeerInfoToAllPeer(const std::string &connectedPeerId)
|
2010-01-13 16:34:28 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() connectedPeerId : " << connectedPeerId << std::endl;
|
2010-01-13 16:34:28 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
/* only ask info if discovery is on */
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
if (!mDiscEnabled)
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() Disc Disabled => NULL OP" << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get details */
|
|
|
|
peerState detail;
|
|
|
|
if (!mPeerMgr->getFriendNetStatus(connectedPeerId, detail))
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() No NetStatus => FAILED" << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detail.visState & RS_VIS_STATE_NODISC)
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() Peer Disc Discable => NULL OP" << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-10 09:42:49 -04:00
|
|
|
std::string gpg_connectedPeerId = rsPeers->getGPGId(connectedPeerId);
|
|
|
|
std::list<std::string> onlineIds;
|
2010-01-13 16:34:28 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* get a peer lists */
|
2010-06-10 09:42:49 -04:00
|
|
|
rsPeers->getOnlineList(onlineIds);
|
2010-01-13 16:34:28 -05:00
|
|
|
|
2010-09-24 13:06:09 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
/* append gpg id's of all friend's to the sending list */
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
for (it = onlineIds.begin(); it != onlineIds.end(); it++)
|
|
|
|
{
|
|
|
|
std::list<std::string> &idList = mSendIdList[*it];
|
|
|
|
|
|
|
|
if (std::find(idList.begin(), idList.end(), gpg_connectedPeerId) == idList.end())
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() adding to queue for: ";
|
|
|
|
std::cerr << *it << std::endl;
|
|
|
|
#endif
|
2010-09-24 13:06:09 -04:00
|
|
|
idList.push_back(gpg_connectedPeerId);
|
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendJustConnectedPeerInfoToAllPeer() already in queue for: ";
|
|
|
|
std::cerr << *it << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2010-09-24 13:06:09 -04:00
|
|
|
}
|
|
|
|
}
|
2010-01-13 16:34:28 -05:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
bool isDummyFriend(const std::string &id)
|
|
|
|
{
|
|
|
|
bool ret = (id.substr(0,5) == "dummy");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* (dest (to), source (cert)) */
|
2010-10-13 12:15:26 -04:00
|
|
|
RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &about)
|
2010-07-04 11:16:52 -04:00
|
|
|
{
|
2010-02-15 10:31:06 -05:00
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3disc::createDiscReply() called. Sending details of: " << about << " to: " << to << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-01-19 14:15:22 -05:00
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
std::string aboutGpgId = rsPeers->getGPGId(about);
|
2010-10-13 12:15:26 -04:00
|
|
|
if (aboutGpgId.empty()) {
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-10-13 12:15:26 -04:00
|
|
|
std::cerr << "p3disc::createDiscReply() no info about this id" << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-10-13 12:15:26 -04:00
|
|
|
return NULL;
|
2010-06-10 09:42:49 -04:00
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
// Construct a message
|
|
|
|
RsDiscReply *di = new RsDiscReply();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
// Fill the message
|
|
|
|
// Set Target as input cert.
|
|
|
|
di -> PeerId(to);
|
2010-07-04 11:16:52 -04:00
|
|
|
di -> aboutId = aboutGpgId;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-06-10 09:42:49 -04:00
|
|
|
// set the ip addresse list.
|
|
|
|
std::list<std::string> sslChilds;
|
2011-08-07 17:11:00 -04:00
|
|
|
rsPeers->getAssociatedSSLIds(aboutGpgId, sslChilds);
|
2010-06-10 09:42:49 -04:00
|
|
|
bool shouldWeSendGPGKey = false;//the GPG key is send only if we've got a valid friend with DISC enabled
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
if (!mDiscEnabled)
|
2010-12-14 16:56:37 -05:00
|
|
|
{
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3disc::createDiscReply() Disc Disabled, removing all friend SSL Ids";
|
2010-12-14 16:56:37 -05:00
|
|
|
std::cerr << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
sslChilds.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
for (it = sslChilds.begin(); it != sslChilds.end(); it++)
|
|
|
|
{
|
|
|
|
/* skip dummy ones - until they are removed fully */
|
|
|
|
if (isDummyFriend(*it))
|
|
|
|
{
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3disc::createDiscReply() Skipping Dummy Child SSL Id:" << *it;
|
|
|
|
std::cerr << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
continue;
|
|
|
|
}
|
2010-07-04 11:16:52 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
peerState detail;
|
|
|
|
if (!mPeerMgr->getFriendNetStatus(*it, detail)
|
|
|
|
|| detail.visState & RS_VIS_STATE_NODISC)
|
|
|
|
{
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3disc::createDiscReply() Skipping cos No Details or NODISC flag id: " << *it;
|
|
|
|
std::cerr << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
continue;
|
2010-07-04 11:16:52 -04:00
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::createDiscReply() Found Child SSL Id:" << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::createDiscReply() Adding Child SSL Id Details";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
shouldWeSendGPGKey = true;
|
|
|
|
|
|
|
|
RsPeerNetItem rsPeerNetItem ;
|
|
|
|
rsPeerNetItem.clear();
|
|
|
|
|
|
|
|
rsPeerNetItem.pid = detail.id;
|
|
|
|
rsPeerNetItem.gpg_id = detail.gpg_id;
|
|
|
|
rsPeerNetItem.location = detail.location;
|
|
|
|
rsPeerNetItem.netMode = detail.netMode;
|
|
|
|
rsPeerNetItem.visState = detail.visState;
|
|
|
|
rsPeerNetItem.lastContact = detail.lastcontact;
|
|
|
|
rsPeerNetItem.currentlocaladdr = detail.localaddr;
|
|
|
|
rsPeerNetItem.currentremoteaddr = detail.serveraddr;
|
|
|
|
rsPeerNetItem.dyndns = detail.dyndns;
|
|
|
|
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
|
|
|
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
|
|
|
|
|
|
|
|
|
|
|
di->rsPeerList.push_back(rsPeerNetItem);
|
|
|
|
}
|
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
|
2010-06-10 09:42:49 -04:00
|
|
|
//send own details
|
|
|
|
if (about == rsPeers->getGPGOwnId())
|
|
|
|
{
|
2011-08-07 17:11:00 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::createDiscReply() Adding Own Id Details";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-07-09 14:39:34 -04:00
|
|
|
peerState detail;
|
|
|
|
if (mPeerMgr->getOwnNetStatus(detail))
|
2010-06-10 09:42:49 -04:00
|
|
|
{
|
|
|
|
shouldWeSendGPGKey = true;
|
2011-01-21 17:04:14 -05:00
|
|
|
RsPeerNetItem rsPeerNetItem ;
|
|
|
|
rsPeerNetItem.clear();
|
|
|
|
rsPeerNetItem.pid = detail.id;
|
|
|
|
rsPeerNetItem.gpg_id = detail.gpg_id;
|
|
|
|
rsPeerNetItem.location = detail.location;
|
|
|
|
rsPeerNetItem.netMode = detail.netMode;
|
|
|
|
rsPeerNetItem.visState = detail.visState;
|
|
|
|
rsPeerNetItem.lastContact = time(NULL);
|
2011-07-09 14:39:34 -04:00
|
|
|
rsPeerNetItem.currentlocaladdr = detail.localaddr;
|
|
|
|
rsPeerNetItem.currentremoteaddr = detail.serveraddr;
|
2011-01-21 17:04:14 -05:00
|
|
|
rsPeerNetItem.dyndns = detail.dyndns;
|
|
|
|
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
|
|
|
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
|
|
|
|
|
|
|
di->rsPeerList.push_back(rsPeerNetItem);
|
2010-06-10 09:42:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shouldWeSendGPGKey) {
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-10-13 12:15:26 -04:00
|
|
|
std::cerr << "p3disc::createDiscReply() GPG key should not be send, no friend with disc on found about it." << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
|
|
|
// cleanup!
|
|
|
|
delete di;
|
2010-10-13 12:15:26 -04:00
|
|
|
return NULL;
|
2010-06-10 09:42:49 -04:00
|
|
|
}
|
2010-07-04 11:16:52 -04:00
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
return di;
|
2009-05-25 07:38:47 -04:00
|
|
|
}
|
|
|
|
|
2009-06-28 16:57:02 -04:00
|
|
|
void p3disc::sendOwnVersion(std::string to)
|
|
|
|
{
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-02-15 10:31:06 -05:00
|
|
|
std::cerr << "p3disc::sendOwnVersion() Sending rs version to: " << to << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2009-06-28 16:57:02 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* only ask info if discovery is on */
|
|
|
|
if (!mDiscEnabled)
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::sendOwnVersion() Disc Disabled => NULL OP" << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-28 16:57:02 -04:00
|
|
|
RsDiscVersion *di = new RsDiscVersion();
|
|
|
|
di->PeerId(to);
|
|
|
|
di->version = RsUtil::retroshareVersion();
|
|
|
|
|
|
|
|
/* send the message */
|
|
|
|
sendItem(di);
|
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-02-15 10:31:06 -05:00
|
|
|
std::cerr << "p3disc::sendOwnVersion() finished." << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2009-06-28 16:57:02 -04:00
|
|
|
}
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2009-12-22 05:41:19 -05:00
|
|
|
void p3disc::sendHeartbeat(std::string to)
|
|
|
|
{
|
2012-04-17 17:00:54 -04:00
|
|
|
{
|
|
|
|
std::string out = "p3disc::sendHeartbeat() to : " + to;
|
2011-08-06 08:27:23 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2012-04-17 17:00:54 -04:00
|
|
|
std::cerr << out << std::endl;
|
2009-12-22 05:41:19 -05:00
|
|
|
#endif
|
2012-04-17 17:00:54 -04:00
|
|
|
rslog(RSL_WARNING, pqidisczone, out);
|
2009-12-22 05:41:19 -05:00
|
|
|
}
|
|
|
|
|
2011-08-06 08:27:23 -04:00
|
|
|
|
2009-12-22 05:41:19 -05:00
|
|
|
RsDiscHeartbeat *di = new RsDiscHeartbeat();
|
|
|
|
di->PeerId(to);
|
|
|
|
|
|
|
|
/* send the message */
|
|
|
|
sendItem(di);
|
|
|
|
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "Sent tick Message" << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-01-19 14:15:22 -05:00
|
|
|
void p3disc::askInfoToAllPeers(std::string about)
|
|
|
|
{
|
2010-02-15 10:31:06 -05:00
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-02-15 10:31:06 -05:00
|
|
|
std::cerr <<"p3disc::askInfoToAllPeers() about " << about << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-02-15 10:31:06 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
// We Still Ask even if Disc isn't Enabled... if they want to give us the info ;)
|
|
|
|
|
2010-02-15 10:31:06 -05:00
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
peerState connectState;
|
2011-08-07 17:11:00 -04:00
|
|
|
if (!mPeerMgr->getFriendNetStatus(about, connectState) || (connectState.visState & RS_VIS_STATE_NODISC))
|
|
|
|
{
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-02-15 10:31:06 -05:00
|
|
|
std::cerr << "p3disc::askInfoToAllPeers() friend disc is off, don't send the request." << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-02-15 10:31:06 -05:00
|
|
|
return;
|
2010-01-19 14:15:22 -05:00
|
|
|
}
|
|
|
|
|
2010-07-04 11:16:52 -04:00
|
|
|
std::string aboutGpgId = rsPeers->getGPGId(about);
|
2011-08-07 17:11:00 -04:00
|
|
|
if (aboutGpgId == "")
|
|
|
|
{
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
|
|
|
#endif
|
2010-01-19 14:15:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::list<std::string> onlineIds;
|
2011-08-07 17:11:00 -04:00
|
|
|
std::list<std::string>::iterator it;
|
2010-01-19 14:15:22 -05:00
|
|
|
|
|
|
|
rsPeers->getOnlineList(onlineIds);
|
|
|
|
|
2010-02-15 10:31:06 -05:00
|
|
|
/* ask info to trusted friends */
|
2011-08-07 17:11:00 -04:00
|
|
|
for(it = onlineIds.begin(); it != onlineIds.end(); it++)
|
2010-07-04 11:16:52 -04:00
|
|
|
{
|
2010-01-19 14:15:22 -05:00
|
|
|
RsDiscAskInfo *di = new RsDiscAskInfo();
|
2011-08-07 17:11:00 -04:00
|
|
|
di->PeerId(*it);
|
|
|
|
di->gpg_id = aboutGpgId;
|
2010-01-19 14:15:22 -05:00
|
|
|
sendItem(di);
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3disc::askInfoToAllPeers() question sent to : " << *it << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-01-19 14:15:22 -05:00
|
|
|
}
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-02-15 10:31:06 -05:00
|
|
|
std::cerr << "p3disc::askInfoToAllPeers() finished." << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-01-19 14:15:22 -05:00
|
|
|
}
|
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId() << " About " << item->aboutId << std::endl;
|
2009-02-22 12:36:39 -05:00
|
|
|
#endif
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-01-27 08:32:14 -05:00
|
|
|
if (certGpgId.empty())
|
|
|
|
{
|
2010-07-04 11:16:52 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2012-01-27 08:32:14 -05:00
|
|
|
std::cerr << "p3disc::recvPeerFriendMsg() gpg cert Id is empty - cert not transmitted" << std::endl;
|
2010-07-04 11:16:52 -04:00
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
}
|
2012-01-27 08:32:14 -05:00
|
|
|
else if (item->aboutId == "" || item->aboutId != certGpgId)
|
|
|
|
{
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::recvPeerFriendMsg() Error : about id is not the same as gpg id." << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
bool should_notify_discovery = false ;
|
2012-03-12 17:38:41 -04:00
|
|
|
std::string item_gpg_id = rsPeers->getGPGId(item->PeerId()) ;
|
2010-11-05 18:46:40 -04:00
|
|
|
|
2012-03-12 17:38:41 -04:00
|
|
|
for (std::list<RsPeerNetItem>::iterator pit = item->rsPeerList.begin(); pit != item->rsPeerList.end(); pit++)
|
2011-08-07 17:11:00 -04:00
|
|
|
{
|
|
|
|
if(isDummyFriend(pit->pid))
|
2010-12-14 16:56:37 -05:00
|
|
|
{
|
2011-08-07 17:11:00 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool new_info = false;
|
2012-03-12 17:38:41 -04:00
|
|
|
addDiscoveryData(item->PeerId(), pit->pid,item_gpg_id,
|
|
|
|
item->aboutId, pit->currentlocaladdr, pit->currentremoteaddr, 0, time(NULL),new_info);
|
2010-11-05 18:46:40 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
if(new_info)
|
|
|
|
should_notify_discovery = true ;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-06-15 17:28:27 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "p3disc::recvPeerFriendMsg() Peer Config Item:" << std::endl;
|
|
|
|
pit->print(std::cerr, 10);
|
|
|
|
std::cerr << std::endl;
|
2010-06-10 09:42:49 -04:00
|
|
|
#endif
|
2012-01-27 08:32:14 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
if (pit->pid != rsPeers->getOwnId())
|
|
|
|
{
|
|
|
|
// Apparently, the connect manager won't add a friend if the gpg id is not
|
|
|
|
// trusted. However, this should be tested here for consistency and security
|
|
|
|
// in case of modifications in mConnMgr.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Check if already friend.
|
|
|
|
if(AuthGPG::getAuthGPG()->isGPGAccepted(pit->gpg_id) || pit->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
2010-06-10 09:42:49 -04:00
|
|
|
{
|
2011-08-07 17:11:00 -04:00
|
|
|
if (!mPeerMgr->isFriend(pit->pid))
|
2010-12-14 16:56:37 -05:00
|
|
|
{
|
|
|
|
// Add with no disc by default. If friend already exists, it will do nothing
|
2011-08-07 17:11:00 -04:00
|
|
|
// NO DISC is important - otherwise, we'll just enter a nasty loop,
|
|
|
|
// where every addition triggers requests, then they are cleaned up, and readded...
|
|
|
|
|
|
|
|
// This way we get their addresses, but don't advertise them until we get a
|
|
|
|
// connection.
|
2010-12-14 16:56:37 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "--> Adding to friends list " << pit->pid << " - " << pit->gpg_id << std::endl;
|
|
|
|
#endif
|
|
|
|
mPeerMgr->addFriend(pit->pid, pit->gpg_id, pit->netMode, RS_VIS_STATE_NODISC, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip if not one of our peers */
|
|
|
|
if (!mPeerMgr->isFriend(pit->pid))
|
|
|
|
{
|
2011-11-22 08:24:42 -05:00
|
|
|
/* THESE ARE OUR FRIEND OF FRIENDS ... pass this information along to NetMgr & DHT...
|
|
|
|
* as we can track FOF and use them as potential Proxies / Relays
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* add into NetMgr and non-search, so we can detect connect attempts */
|
|
|
|
mNetMgr->netAssistFriend(pit->pid,false);
|
2012-03-12 17:38:41 -04:00
|
|
|
|
2011-11-22 08:24:42 -05:00
|
|
|
/* inform NetMgr that we know this peer */
|
|
|
|
mNetMgr->netAssistKnownPeer(pit->pid, pit->currentremoteaddr,
|
2012-03-12 17:38:41 -04:00
|
|
|
NETASSIST_KNOWN_PEER_FOF | NETASSIST_KNOWN_PEER_OFFLINE);
|
2011-11-22 08:24:42 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->PeerId() == pit->pid)
|
|
|
|
{
|
2011-07-30 08:18:56 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "Info sent by the peer itself -> updating self info:" << std::endl;
|
|
|
|
std::cerr << " -> current local addr = " << pit->currentlocaladdr << std::endl;
|
|
|
|
std::cerr << " -> current remote addr = " << pit->currentremoteaddr << std::endl;
|
|
|
|
std::cerr << " -> visState = " << std::hex << pit->visState << std::dec;
|
|
|
|
std::cerr << " -> network mode: " << pit->netMode << std::endl;
|
|
|
|
std::cerr << " -> location: " << pit->location << std::endl;
|
|
|
|
std::cerr << std::endl;
|
2010-12-14 16:56:37 -05:00
|
|
|
#endif
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
// 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.
|
|
|
|
mPeerMgr->setNetworkMode(pit->pid, pit->netMode);
|
|
|
|
mPeerMgr->setLocation(pit->pid, pit->location);
|
|
|
|
mPeerMgr->setLocalAddress(pit->pid, pit->currentlocaladdr);
|
|
|
|
mPeerMgr->setExtAddress(pit->pid, pit->currentremoteaddr);
|
|
|
|
mPeerMgr->setVisState(pit->pid, pit->visState);
|
|
|
|
|
|
|
|
if (pit->dyndns != "")
|
|
|
|
mPeerMgr->setDynDNS(pit->pid, pit->dyndns);
|
|
|
|
}
|
2010-12-14 16:56:37 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
// always update historical address list... this should be enough to let us connect.
|
2010-12-14 16:56:37 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
pqiIpAddrSet addrsFromPeer;
|
|
|
|
addrsFromPeer.mLocal.extractFromTlv(pit->localAddrList);
|
|
|
|
addrsFromPeer.mExt.extractFromTlv(pit->extAddrList);
|
2010-12-14 16:56:37 -05:00
|
|
|
|
2010-06-10 09:42:49 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
std::cerr << "Setting address list to peer " << pit->pid << ", to be:" << std::endl ;
|
2010-06-16 16:18:46 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
addrsFromPeer.printAddrs(std::cerr);
|
|
|
|
std::cerr << std::endl;
|
2010-12-14 16:56:37 -05:00
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
mPeerMgr->updateAddressList(pit->pid, addrsFromPeer);
|
2010-07-04 11:16:52 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
}
|
2010-06-10 09:42:49 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2011-08-07 17:11:00 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Skipping info about own id " << pit->pid << std::endl ;
|
|
|
|
}
|
2010-06-10 09:42:49 -04:00
|
|
|
#endif
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
}
|
2009-12-22 13:43:04 -05:00
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
|
2009-06-28 16:57:02 -04:00
|
|
|
|
2010-11-05 18:46:40 -04:00
|
|
|
if(should_notify_discovery)
|
|
|
|
rsicontrol->getNotify().notifyDiscInfoChanged();
|
|
|
|
|
2010-06-10 09:42:49 -04:00
|
|
|
/* cleanup (handled by caller) */
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2009-06-28 16:57:02 -04:00
|
|
|
void p3disc::recvPeerVersionMsg(RsDiscVersion *item)
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
2009-12-22 05:41:19 -05:00
|
|
|
std::cerr << "p3disc::recvPeerVersionMsg() From: " << item->PeerId();
|
|
|
|
std::cerr << std::endl;
|
2009-06-28 16:57:02 -04:00
|
|
|
#endif
|
|
|
|
|
2009-12-22 05:41:19 -05:00
|
|
|
// dont need protection
|
|
|
|
versions[item->PeerId()] = item->version;
|
2009-06-28 16:57:02 -04:00
|
|
|
|
2009-12-22 05:41:19 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3disc::recvHeartbeatMsg(RsDiscHeartbeat *item)
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::recvHeartbeatMsg() From: " << item->PeerId();
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-06-25 18:13:52 -04:00
|
|
|
mPqiPersonGrp->tagHeartbeatRecvd(item->PeerId());
|
2009-12-22 05:41:19 -05:00
|
|
|
|
|
|
|
return;
|
2009-06-28 16:57:02 -04:00
|
|
|
}
|
2009-05-25 07:38:47 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
void p3disc::recvAskInfo(RsDiscAskInfo *item)
|
|
|
|
{
|
2010-01-19 14:15:22 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::recvAskInfo() From: " << item->PeerId();
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-08-07 17:11:00 -04:00
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
/* only provide info if discovery is on */
|
|
|
|
if (!mDiscEnabled)
|
|
|
|
{
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::recvAskInfo() Disc Disabled => NULL OP";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2010-01-19 14:15:22 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
std::list<std::string> &idList = mSendIdList[item->PeerId()];
|
2010-01-19 14:15:22 -05:00
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
if (std::find(idList.begin(), idList.end(), item->gpg_id) == idList.end()) {
|
|
|
|
idList.push_back(item->gpg_id);
|
|
|
|
}
|
2010-01-19 14:15:22 -05:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
void p3disc::recvDiscReply(RsDiscReply *dri)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2012-01-27 08:32:14 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::recvDiscReply() From: " << dri->PeerId() << " About: " << dri->aboutId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
/* search pending item and remove it, when already exist */
|
|
|
|
std::list<RsDiscReply*>::iterator it;
|
|
|
|
for (it = mPendingDiscReplyInList.begin(); it != mPendingDiscReplyInList.end(); it++)
|
|
|
|
{
|
|
|
|
if ((*it)->PeerId() == dri->PeerId() && (*it)->aboutId == dri->aboutId)
|
|
|
|
{
|
|
|
|
delete (*it);
|
|
|
|
mPendingDiscReplyInList.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add item to list for later process
|
2012-03-12 17:38:41 -04:00
|
|
|
|
|
|
|
if(mDiscEnabled || dri->aboutId == rsPeers->getGPGId(dri->PeerId()))
|
|
|
|
mPendingDiscReplyInList.push_back(dri); // no delete
|
|
|
|
else
|
|
|
|
delete dri ;
|
2011-08-07 17:11:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
void p3disc::removeFriend(std::string /*ssl_id*/)
|
2011-08-07 17:11:00 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
// DON'T KNOW WHY SSL IDS were saved -> the results are never used
|
|
|
|
#if 0
|
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::removeFriend() called for : " << ssl_id << std::endl;
|
2010-01-15 16:09:25 -05:00
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
//if we deleted the gpg_id, don't store the friend deletion as if we add back the gpg_id, we won't have the ssl friends back
|
|
|
|
std::string gpg_id = rsPeers->getGPGId(ssl_id);
|
2010-01-15 16:09:25 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::removeFriend() gpg_id : " << gpg_id << std::endl;
|
2010-01-15 16:09:25 -05:00
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
if (gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId() || rsPeers->isGPGAccepted(rsPeers->getGPGId(ssl_id))) {
|
2010-10-13 12:15:26 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-06-10 09:42:49 -04:00
|
|
|
std::cerr << "p3disc::removeFriend() storing the friend deletion." << ssl_id << std::endl;
|
2010-01-15 16:09:25 -05:00
|
|
|
#endif
|
2010-06-10 09:42:49 -04:00
|
|
|
deletedSSLFriendsIds[ssl_id] = time(NULL);//just keep track of the deleted time
|
|
|
|
IndicateConfigChanged();
|
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
}
|
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
/*************************************************************************************/
|
|
|
|
/* AuthGPGService */
|
|
|
|
/*************************************************************************************/
|
|
|
|
AuthGPGOperation *p3disc::getGPGOperation()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
/* process disc reply in list */
|
2011-08-07 17:11:00 -04:00
|
|
|
if (mPendingDiscReplyInList.empty() == false) {
|
|
|
|
RsDiscReply *item = mPendingDiscReplyInList.front();
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-02-15 11:44:45 -05:00
|
|
|
return new AuthGPGOperationLoadOrSave(true, item->aboutId, item->certGPG, item);
|
2010-10-13 12:15:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process disc reply out list */
|
|
|
|
|
|
|
|
std::string destId;
|
|
|
|
std::string srcId;
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
while (!mSendIdList.empty())
|
|
|
|
{
|
|
|
|
std::map<std::string, std::list<std::string> >::iterator it = mSendIdList.begin();
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
if (!it->second.empty() && mLinkMgr->isOnline(it->first)) {
|
|
|
|
std::string gpgId = it->second.front();
|
|
|
|
it->second.pop_front();
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
destId = it->first;
|
2010-10-13 12:15:26 -04:00
|
|
|
srcId = gpgId;
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* peer is not online anymore ... try next */
|
2011-08-07 17:11:00 -04:00
|
|
|
mSendIdList.erase(it);
|
2010-10-13 12:15:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!destId.empty() && !srcId.empty()) {
|
|
|
|
RsDiscReply *item = createDiscReply(destId, srcId);
|
|
|
|
if (item) {
|
2012-02-15 11:44:45 -05:00
|
|
|
return new AuthGPGOperationLoadOrSave(false, item->aboutId, "", item);
|
2010-10-13 12:15:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3disc::setGPGOperation(AuthGPGOperation *operation)
|
|
|
|
{
|
|
|
|
AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast<AuthGPGOperationLoadOrSave*>(operation);
|
|
|
|
if (loadOrSave) {
|
|
|
|
if (loadOrSave->m_load) {
|
|
|
|
/* search in pending in list */
|
|
|
|
RsDiscReply *item = NULL;
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
std::list<RsDiscReply*>::iterator it;
|
|
|
|
it = std::find(mPendingDiscReplyInList.begin(), mPendingDiscReplyInList.end(), loadOrSave->m_userdata);
|
|
|
|
if (it != mPendingDiscReplyInList.end()) {
|
2010-10-13 12:15:26 -04:00
|
|
|
item = *it;
|
2011-08-07 17:11:00 -04:00
|
|
|
mPendingDiscReplyInList.erase(it);
|
2010-10-13 12:15:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
recvPeerDetails(item, loadOrSave->m_certGpgId);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RsDiscReply *item = (RsDiscReply*) loadOrSave->m_userdata;
|
|
|
|
|
2012-01-19 20:05:46 -05:00
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
// It is okay to send an empty certificate! - This is to reduce the network load at connection time.
|
|
|
|
// Hopefully, we'll get the stripped down certificates working soon!... even then still be okay to send null.
|
|
|
|
#if 0
|
|
|
|
if (loadOrSave->m_certGpg.empty())
|
|
|
|
{
|
2010-10-13 12:15:26 -04:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::setGPGOperation() don't send details because the gpg cert is not good" << std::endl;
|
|
|
|
#endif
|
|
|
|
delete item;
|
|
|
|
return;
|
|
|
|
}
|
2012-01-19 20:05:46 -05:00
|
|
|
#endif
|
2010-10-13 12:15:26 -04:00
|
|
|
|
2012-01-20 09:41:45 -05:00
|
|
|
/* for Relay Connections (and other slow ones) we don't want to
|
|
|
|
* to waste bandwidth sending certificates. So don't add it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t linkType = mLinkMgr->getLinkType(item->PeerId());
|
|
|
|
if ((linkType & RS_NET_CONN_SPEED_TRICKLE) ||
|
|
|
|
(linkType & RS_NET_CONN_SPEED_LOW))
|
|
|
|
{
|
|
|
|
std::cerr << "p3disc::setGPGOperation() Send DiscReply Packet to: ";
|
|
|
|
std::cerr << item->PeerId();
|
|
|
|
std::cerr << " without Certificate (low bandwidth)" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Attaching Certificate.
|
|
|
|
item->certGPG = loadOrSave->m_certGpg;
|
|
|
|
}
|
2010-10-13 12:15:26 -04:00
|
|
|
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::setGPGOperation() About to Send Message:" << std::endl;
|
|
|
|
item->print(std::cerr, 5);
|
|
|
|
#endif
|
|
|
|
|
2012-01-20 09:41:45 -05:00
|
|
|
// Send off message
|
2010-10-13 12:15:26 -04:00
|
|
|
sendItem(item);
|
|
|
|
|
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::cbkGPGOperationSave() discovery reply sent." << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore other operations */
|
|
|
|
}
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/*************************************************************************************/
|
|
|
|
/* Storing Network Graph */
|
|
|
|
/*************************************************************************************/
|
2010-11-14 16:03:36 -05:00
|
|
|
int p3disc::addDiscoveryData(const std::string& fromId, const std::string& aboutId,const std::string& from_gpg_id,const std::string& about_gpg_id, const struct sockaddr_in& laddr, const struct sockaddr_in& raddr, uint32_t flags, time_t ts,bool& new_info)
|
2008-02-03 01:29:02 -05:00
|
|
|
{
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-11-05 18:46:40 -04:00
|
|
|
new_info = false ;
|
2010-11-14 16:03:36 -05:00
|
|
|
|
|
|
|
gpg_neighbors[from_gpg_id].insert(about_gpg_id) ;
|
|
|
|
|
2010-11-19 17:42:29 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-11-05 18:46:40 -04:00
|
|
|
std::cerr << "Adding discovery data " << fromId << " - " << aboutId << std::endl ;
|
2010-11-19 17:42:29 -05:00
|
|
|
#endif
|
2008-02-04 16:40:34 -05:00
|
|
|
/* Store Network information */
|
2008-02-03 01:29:02 -05:00
|
|
|
std::map<std::string, autoneighbour>::iterator it;
|
|
|
|
if (neighbours.end() == (it = neighbours.find(aboutId)))
|
|
|
|
{
|
|
|
|
/* doesn't exist */
|
|
|
|
autoneighbour an;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* an data */
|
|
|
|
an.id = aboutId;
|
|
|
|
an.validAddrs = false;
|
|
|
|
an.discFlags = 0;
|
|
|
|
an.ts = 0;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
neighbours[aboutId] = an;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
it = neighbours.find(aboutId);
|
2010-11-05 18:46:40 -04:00
|
|
|
new_info = true ;
|
2008-02-03 01:29:02 -05:00
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* it always valid */
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* just update packet */
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
autoserver as;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
as.id = fromId;
|
|
|
|
as.localAddr = laddr;
|
|
|
|
as.remoteAddr = raddr;
|
|
|
|
as.discFlags = flags;
|
|
|
|
as.ts = ts;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
bool authDetails = (as.id == it->second.id);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* KEY decision about address */
|
2009-06-28 16:57:02 -04:00
|
|
|
if ((authDetails) ||
|
2008-02-03 01:29:02 -05:00
|
|
|
((!(it->second.authoritative)) && (as.ts > it->second.ts)))
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2008-02-03 01:29:02 -05:00
|
|
|
/* copy details to an */
|
|
|
|
it->second.authoritative = authDetails;
|
|
|
|
it->second.ts = as.ts;
|
|
|
|
it->second.validAddrs = true;
|
|
|
|
it->second.localAddr = as.localAddr;
|
|
|
|
it->second.remoteAddr = as.remoteAddr;
|
|
|
|
it->second.discFlags = as.discFlags;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2010-11-05 18:46:40 -04:00
|
|
|
if(it->second.neighbour_of.find(fromId) == it->second.neighbour_of.end())
|
|
|
|
{
|
|
|
|
(it->second).neighbour_of[fromId] = as;
|
|
|
|
new_info =true ;
|
|
|
|
}
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
/* do we update network address info??? */
|
|
|
|
return 1;
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/*************************************************************************************/
|
|
|
|
/* Extracting Network Graph Details */
|
|
|
|
/*************************************************************************************/
|
2010-11-14 16:03:36 -05:00
|
|
|
bool p3disc::potentialproxies(const std::string& id, std::list<std::string> &proxyIds)
|
2008-02-03 01:29:02 -05:00
|
|
|
{
|
|
|
|
/* find id -> and extract the neighbour_of ids */
|
2008-02-04 16:40:34 -05:00
|
|
|
|
2010-11-05 18:46:40 -04:00
|
|
|
if(id == rsPeers->getOwnId()) // SSL id // This is treated appart, because otherwise we don't receive any disc info about us
|
|
|
|
return rsPeers->getFriendList(proxyIds) ;
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
std::map<std::string, autoneighbour>::iterator it;
|
|
|
|
std::map<std::string, autoserver>::iterator sit;
|
|
|
|
if (neighbours.end() == (it = neighbours.find(id)))
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2008-02-03 01:29:02 -05:00
|
|
|
return false;
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-11-14 16:03:36 -05:00
|
|
|
for(sit = it->second.neighbour_of.begin(); sit != it->second.neighbour_of.end(); sit++)
|
2008-02-03 01:29:02 -05:00
|
|
|
{
|
|
|
|
proxyIds.push_back(sit->first);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
|
2010-11-14 16:03:36 -05:00
|
|
|
bool p3disc::potentialGPGproxies(const std::string& gpg_id, std::list<std::string> &proxyGPGIds)
|
|
|
|
{
|
|
|
|
/* find id -> and extract the neighbour_of ids */
|
|
|
|
|
|
|
|
if(gpg_id == rsPeers->getGPGOwnId()) // SSL id // This is treated appart, because otherwise we don't receive any disc info about us
|
|
|
|
return rsPeers->getGPGAcceptedList(proxyGPGIds) ;
|
|
|
|
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
std::map<std::string, std::set<std::string> >::iterator it = gpg_neighbors.find(gpg_id) ;
|
|
|
|
|
|
|
|
if(it == gpg_neighbors.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for(std::set<std::string>::const_iterator sit(it->second.begin()); sit != it->second.end(); ++sit)
|
|
|
|
proxyGPGIds.push_back(*sit);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2009-06-28 16:57:02 -04:00
|
|
|
void p3disc::getversions(std::map<std::string, std::string> &versions)
|
|
|
|
{
|
|
|
|
versions = this->versions;
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-01-07 11:56:57 -05:00
|
|
|
void p3disc::getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount)
|
|
|
|
{
|
|
|
|
if (sendCount == NULL && recvCount == NULL) {
|
|
|
|
/* Nothing to do */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
if (sendCount) {
|
|
|
|
*sendCount = 0;
|
|
|
|
|
|
|
|
std::map<std::string, std::list<std::string> >::iterator it;
|
2011-08-07 17:11:00 -04:00
|
|
|
for (it = mSendIdList.begin(); it != mSendIdList.end(); it++) {
|
2011-01-07 11:56:57 -05:00
|
|
|
*sendCount += it->second.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recvCount) {
|
2011-08-07 17:11:00 -04:00
|
|
|
*recvCount = mPendingDiscReplyInList.size();
|
2011-01-07 11:56:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 17:00:54 -04:00
|
|
|
#ifdef UNUSED_CODE
|
2008-02-03 01:29:02 -05:00
|
|
|
int p3disc::idServers()
|
|
|
|
{
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
std::map<std::string, autoneighbour>::iterator nit;
|
|
|
|
std::map<std::string, autoserver>::iterator sit;
|
|
|
|
int cts = time(NULL);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2012-04-17 17:00:54 -04:00
|
|
|
std::string out = "::::AutoDiscovery Neighbours::::\n";
|
2008-02-03 01:29:02 -05:00
|
|
|
for(nit = neighbours.begin(); nit != neighbours.end(); nit++)
|
|
|
|
{
|
2012-04-17 17:00:54 -04:00
|
|
|
out += "Neighbour: " + (nit->second).id + "\n";
|
|
|
|
rs_sprintf_append(out, "-> LocalAddr: %s:%u\n", rs_inet_ntoa(nit->second.localAddr.sin_addr).c_str(), ntohs(nit->second.localAddr.sin_port));
|
|
|
|
rs_sprintf_append(out, "-> RemoteAddr: %s:%u\n", rs_inet_ntoa(nit->second.remoteAddr.sin_addr).c_str(), ntohs(nit->second.remoteAddr.sin_port));
|
|
|
|
rs_sprintf_append(out, " Last Contact: %ld sec ago\n", cts - (nit->second.ts));
|
|
|
|
|
|
|
|
rs_sprintf_append(out, " -->DiscFlags: 0x%x\n", nit->second.discFlags);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2009-06-28 16:57:02 -04:00
|
|
|
for(sit = (nit->second.neighbour_of).begin();
|
2008-02-03 01:29:02 -05:00
|
|
|
sit != (nit->second.neighbour_of).end(); sit++)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2012-04-17 17:00:54 -04:00
|
|
|
out += "\tConnected via: " + (sit->first) + "\n";
|
|
|
|
rs_sprintf_append(out, "\t\tLocalAddr: %s:%u\n", rs_inet_ntoa(sit->second.localAddr.sin_addr).c_str(), ntohs(sit->second.localAddr.sin_port));
|
|
|
|
rs_sprintf_append(out, "\t\tRemoteAddr: %s:%u\n", rs_inet_ntoa(sit->second.remoteAddr.sin_addr).c_str(), ntohs(sit->second.remoteAddr.sin_port));
|
|
|
|
|
|
|
|
rs_sprintf_append(out, "\t\tLast Contact: %ld sec ago\n", cts - (sit->second.ts));
|
|
|
|
rs_sprintf_append(out, "\t\tDiscFlags: 0x%x\n", sit->second.discFlags);
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::idServers()" << std::endl;
|
2012-04-17 17:00:54 -04:00
|
|
|
std::cerr << out;
|
2008-02-03 01:29:02 -05:00
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
return 1;
|
|
|
|
}
|
2012-04-17 17:00:54 -04:00
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
// tdelta -> trange.
|
|
|
|
// -inf...<0 0 (invalid)
|
|
|
|
// 0.. <9 1
|
|
|
|
// 9...<99 2
|
|
|
|
// 99...<999 3
|
|
|
|
// 999...<9999 4
|
|
|
|
// etc...
|
|
|
|
|
2010-02-23 16:55:29 -05:00
|
|
|
//int convertTDeltaToTRange(double tdelta)
|
|
|
|
//{
|
|
|
|
// if (tdelta < 0)
|
|
|
|
// return 0;
|
|
|
|
// int trange = 1 + (int) log10(tdelta + 1.0);
|
|
|
|
// return trange;
|
|
|
|
//
|
|
|
|
//}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
// trange -> tdelta
|
|
|
|
// -inf...0 -1 (invalid)
|
|
|
|
// 1 8
|
|
|
|
// 2 98
|
|
|
|
// 3 998
|
|
|
|
// 4 9998
|
|
|
|
// etc...
|
|
|
|
|
2010-02-23 16:55:29 -05:00
|
|
|
//int convertTRangeToTDelta(int trange)
|
|
|
|
//{
|
|
|
|
// if (trange <= 0)
|
|
|
|
// return -1;
|
|
|
|
//
|
|
|
|
// return (int) (pow(10.0, trange) - 1.5); // (int) xxx98.5 -> xxx98
|
|
|
|
//}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
// -------------------------------- Config functions ------------------------------ //
|
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
//
|
|
|
|
RsSerialiser *p3disc::setupSerialiser()
|
|
|
|
{
|
|
|
|
RsSerialiser *rss = new RsSerialiser ;
|
|
|
|
rss->addSerialType(new RsGeneralConfigSerialiser());
|
|
|
|
return rss ;
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:42:30 -04:00
|
|
|
bool p3disc::saveList(bool& cleanup, std::list<RsItem*>& /*lst*/)
|
2010-01-15 16:09:25 -05:00
|
|
|
{
|
2010-02-07 16:28:40 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
|
|
|
std::cerr << "p3disc::saveList() called" << std::endl;
|
|
|
|
#endif
|
2010-01-15 16:09:25 -05:00
|
|
|
cleanup = true ;
|
2010-12-18 14:35:07 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
// DON'T KNOW WHY SSL IDS were saved -> the results are never used
|
|
|
|
#if 0
|
2010-01-15 16:09:25 -05:00
|
|
|
// Now save config for network digging strategies
|
|
|
|
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
|
|
|
std::map<std::string, time_t>::iterator mapIt;
|
2011-08-07 17:11:00 -04:00
|
|
|
for (mapIt = deletedSSLFriendsIds.begin(); mapIt != deletedSSLFriendsIds.end(); mapIt++)
|
|
|
|
{
|
2010-01-15 16:09:25 -05:00
|
|
|
RsTlvKeyValue kv;
|
|
|
|
kv.key = mapIt->first;
|
2012-04-17 17:00:54 -04:00
|
|
|
rs_sprintf(kv.value, "%ld", mapIt->second);
|
2010-01-15 16:09:25 -05:00
|
|
|
vitem->tlvkvs.pairs.push_back(kv) ;
|
2010-02-07 16:28:40 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-01-15 16:09:25 -05:00
|
|
|
std::cerr << "p3disc::saveList() saving : " << mapIt->first << " ; " << mapIt->second << std::endl ;
|
2010-02-07 16:28:40 -05:00
|
|
|
#endif
|
2010-01-15 16:09:25 -05:00
|
|
|
}
|
|
|
|
lst.push_back(vitem);
|
2011-08-07 17:11:00 -04:00
|
|
|
#endif
|
2010-01-15 16:09:25 -05:00
|
|
|
|
2010-12-18 14:35:07 -05:00
|
|
|
return true ;
|
2010-01-15 16:09:25 -05:00
|
|
|
}
|
|
|
|
|
2010-12-18 14:35:07 -05:00
|
|
|
bool p3disc::loadList(std::list<RsItem*>& load)
|
2010-01-15 16:09:25 -05:00
|
|
|
{
|
2010-02-07 16:28:40 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-01-15 16:09:25 -05:00
|
|
|
std::cerr << "p3disc::loadList() Item Count: " << load.size() << std::endl;
|
2010-02-07 16:28:40 -05:00
|
|
|
#endif
|
2010-01-15 16:09:25 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
RsStackMutex stack(mDiscMtx); /****** STACK LOCK MUTEX *******/
|
|
|
|
|
|
|
|
/* load the list of accepted gpg keys */
|
|
|
|
std::list<RsItem *>::iterator it;
|
2011-08-07 17:11:00 -04:00
|
|
|
for(it = load.begin(); it != load.end(); it++)
|
|
|
|
{
|
|
|
|
// DON'T KNOW WHY SSL IDS were saved -> the results are never used
|
|
|
|
#if 0
|
2011-08-12 09:42:30 -04:00
|
|
|
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
if(vitem)
|
|
|
|
{
|
2010-02-07 16:28:40 -05:00
|
|
|
#ifdef P3DISC_DEBUG
|
2010-01-15 16:09:25 -05:00
|
|
|
std::cerr << "p3disc::loadList() General Variable Config Item:" << std::endl;
|
|
|
|
vitem->print(std::cerr, 10);
|
|
|
|
std::cerr << std::endl;
|
2010-02-07 16:28:40 -05:00
|
|
|
#endif
|
2010-01-15 16:09:25 -05:00
|
|
|
|
|
|
|
std::list<RsTlvKeyValue>::iterator kit;
|
2011-08-07 17:11:00 -04:00
|
|
|
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++)
|
|
|
|
{
|
2010-01-15 16:09:25 -05:00
|
|
|
std::istringstream instream(kit->value);
|
|
|
|
time_t deleted_time_t;
|
|
|
|
instream >> deleted_time_t;
|
|
|
|
deletedSSLFriendsIds[kit->key] = deleted_time_t;
|
|
|
|
}
|
|
|
|
}
|
2011-08-07 17:11:00 -04:00
|
|
|
#endif
|
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
delete (*it);
|
|
|
|
}
|
|
|
|
return true;
|
2011-08-07 17:11:00 -04:00
|
|
|
}
|